From 319d4cb6670729708c19ad50b0146d1bcb7b4719 Mon Sep 17 00:00:00 2001 From: PliablePixels Date: Sat, 27 Jun 2015 09:52:06 -0400 Subject: Added ability to log key events to file and email (useful for release debugging) --- .../src/wp8/EmailComposer.cs | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 plugins/de.appplant.cordova.plugin.email-composer/src/wp8/EmailComposer.cs (limited to 'plugins/de.appplant.cordova.plugin.email-composer/src/wp8/EmailComposer.cs') diff --git a/plugins/de.appplant.cordova.plugin.email-composer/src/wp8/EmailComposer.cs b/plugins/de.appplant.cordova.plugin.email-composer/src/wp8/EmailComposer.cs new file mode 100644 index 00000000..db0d613e --- /dev/null +++ b/plugins/de.appplant.cordova.plugin.email-composer/src/wp8/EmailComposer.cs @@ -0,0 +1,133 @@ +/* + Copyright 2013-2015 appPlant UG + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ + +using De.APPPlant.Cordova.Plugin.EmailComposer; +using Microsoft.Phone.Tasks; +using System; +using System.Linq; +using WPCordovaClassLib.Cordova; +using WPCordovaClassLib.Cordova.Commands; +using WPCordovaClassLib.Cordova.JSON; + +namespace Cordova.Extension.Commands +{ + /// + /// Implementes access to email composer task + /// http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394003(v=vs.105).aspx + /// + public class EmailComposer : BaseCommand + { + /// + /// Überprüft, ob Emails versendet werden können. + /// + public void isAvailable(string jsonArgs) + { + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, true)); + } + + /// + /// Öffnet den Email-Kontroller mit vorausgefüllten Daten. + /// + public void open(string jsonArgs) + { + string[] args = JsonHelper.Deserialize(jsonArgs); + Options options = JsonHelper.Deserialize(args[0]); + EmailComposeTask draft = GetDraftWithProperties(options); + + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, true)); + + OpenDraft(draft); + } + + /// + /// Erstellt den Email-Composer und fügt die übergebenen Eigenschaften ein. + /// + private EmailComposeTask GetDraftWithProperties(Options options) + { + EmailComposeTask draft = new EmailComposeTask(); + + SetSubject(options.Subject, draft); + SetBody(options.Body, options.IsHtml, draft); + SetTo(options.To, draft); + SetCc(options.Cc, draft); + SetBcc(options.Bcc, draft); + SetAttachments(options.Attachments, draft); + + return draft; + } + + /// + /// Zeigt den ViewController zum Versenden/Bearbeiten der Mail an. + /// + private void OpenDraft(EmailComposeTask draft) + { + draft.Show(); + } + + /// + /// Setzt den Subject der Mail. + /// + private void SetSubject(string subject, EmailComposeTask draft) + { + draft.Subject = subject; + } + + /// + /// Setzt den Body der Mail. + /// + private void SetBody(string body, Boolean isHTML, EmailComposeTask draft) + { + draft.Body = body; + } + + /// + /// Setzt die Empfänger der Mail. + /// + private void SetTo(string[] recipients, EmailComposeTask draft) + { + draft.To = string.Join(",", recipients); + } + + /// + /// Setzt die CC-Empfänger der Mail. + /// + private void SetCc(string[] recipients, EmailComposeTask draft) + { + draft.Cc = string.Join(",", recipients); + } + + /// + /// Setzt die BCC-Empfänger der Mail. + /// + private void SetBcc(string[] recipients, EmailComposeTask draft) + { + draft.Bcc = string.Join(",", recipients); + } + + /// + /// Fügt die Anhände zur Mail hinzu. + /// + private void SetAttachments(string[] attachments, EmailComposeTask draft) + { + // Not supported on WP8.0 and WP8.1 Silverlight + } + } +} -- cgit v1.2.3