Ejemplo n.º 1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter as string == "CLOUD_CLIPBOARD")
            {
                string content = Windows.Storage.ApplicationData.Current.LocalSettings.Values["CloudClipboardText"].ToString();
                viewModel["ClipboardContent"] = content;

                //Re-register the notification
                Windows.Storage.ApplicationData.Current.LocalSettings.Values["LastToast"] = "";
                CloudClipboardHandler.ReceiveRequest(new Dictionary <string, object>
                {
                    { "Data", content },
                });

#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("CloudClipboard", "NotificationTapped").Build());
#endif
            }
            else
            {
                Guid guid = Guid.Parse(e.Parameter as string);

                await DataStorageProviders.HistoryManager.OpenAsync();

                var item = DataStorageProviders.HistoryManager.GetItem(guid);
                DataStorageProviders.HistoryManager.Close();

                if (!(item.Data is ReceivedText))
                {
                    throw new Exception("Invalid received item type.");
                }

                await DataStorageProviders.TextReceiveContentManager.OpenAsync();

                viewModel["ClipboardContent"] = DataStorageProviders.TextReceiveContentManager.GetItemContent(guid);
                DataStorageProviders.TextReceiveContentManager.Close();

#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("Clipboard", "NotificationTapped").Build());
#endif
            }

            Window.Current.Activated += Window_Activated;

            HandleClipboardChanged();

            base.OnNavigatedTo(e);
        }
Ejemplo n.º 2
0
        private async Task ParseMessage(Dictionary <string, object> reqMessage)
        {
            string receiver = reqMessage["Receiver"] as string;

            if (receiver == "ServerIPFinder")
            {
                await FileTransfer.ServerIPFinder.ReceiveRequest(reqMessage);
            }
            else if (receiver == "FileReceiver")
            {
                await FileTransfer.FileReceiver2.ReceiveRequest(reqMessage, new DownloadFolderDecider(),
                                                                async s => { return(new WinRTFolder(await StorageFolder.GetFolderFromPathAsync(s))); });
            }
            else if (receiver == "TextReceiver")
            {
                await TextTransfer.TextReceiver.ReceiveRequest(reqMessage);
            }
            else if (receiver == "CloudClipboardHandler")
            {
                CloudClipboardHandler.ReceiveRequest(reqMessage);
            }
        }
Ejemplo n.º 3
0
        private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var requestDeferral = args.GetDeferral();

            try
            {
                Debug.WriteLine("A request received");
                if (args.Request.Message.ContainsKey("Receiver"))
                {
                    string receiver = args.Request.Message["Receiver"] as string;

                    Debug.WriteLine($"Receiver is {receiver}");

                    Dictionary <string, object> reqMessage = new Dictionary <string, object>();

                    foreach (var item in args.Request.Message)
                    {
                        reqMessage.Add(item.Key, item.Value);
                    }

                    if (receiver == "ServerIPFinder")
                    {
                        await FileTransfer.ServerIPFinder.ReceiveRequest(reqMessage);
                    }
                    else if (receiver == "FileReceiver")
                    {
                        await FileTransfer.FileReceiver.ReceiveRequest(reqMessage, DownloadFolderDecider);
                    }
                    else if (receiver == "TextReceiver")
                    {
                        await TextTransfer.TextReceiver.ReceiveRequest(reqMessage);
                    }
                    else if (receiver == "CloudClipboardHandler")
                    {
                        CloudClipboardHandler.ReceiveRequest(reqMessage);

                        _appServiceconnection.Dispose();
                        _deferral?.Complete();
                        _deferral = null;
                    }
                    else if (receiver == "System")
                    {
                        if (args.Request.Message.ContainsKey("FinishService"))
                        {
                            if (_deferral != null)
                            {
                                System.Diagnostics.Debug.WriteLine("Let's say goodbye");

                                while (waitingNumSemaphore > 0)
                                {
                                    await Task.Delay(100);
                                }

                                System.Diagnostics.Debug.WriteLine("Goodbye");
                                _appServiceconnection.Dispose();
                                _deferral?.Complete();
                                _deferral = null;
                            }
                        }
                        //else if ((args.Request.Message.ContainsKey("Task")) && (args.Request.Message["Task"] as string == "MessageCarrier"))
                        //{

                        //}
                    }
                }
                //else if (args.Request.Message.ContainsKey("Test"))
                //{
                //    string s = args.Request.Message["Test"] as string;

                //    if (s == null)
                //        s = "null";

                //    ValueSet vs = new ValueSet();
                //    vs.Add("RecvSuccessful", "RecvSuccessful");
                //    await args.Request.SendResponseAsync(vs);

                //    await System.Threading.Tasks.Task.Delay(1500);

                //    SendToast(s);
                //}
                //else if (args.Request.Message.ContainsKey("TestLongRunning"))
                //{
                //    for (int i = 0; i < 10000; i++)
                //    {
                //        SendToast((i).ToString() + " seconds");
                //        await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(1));
                //    }
                //}
            }
            finally
            {
                requestDeferral?.Complete();
            }
        }
Ejemplo n.º 4
0
        private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var requestDeferral = args.GetDeferral();

            try
            {
                Debug.WriteLine("A request received");
                if (args.Request.Message.ContainsKey("Receiver"))
                {
                    string receiver = args.Request.Message["Receiver"] as string;

                    Debug.WriteLine($"Receiver is {receiver}");

                    Dictionary <string, object> reqMessage = new Dictionary <string, object>();

                    foreach (var item in args.Request.Message)
                    {
                        reqMessage.Add(item.Key, item.Value);
                    }

                    if (receiver == "ServerIPFinder")
                    {
                        await FileTransfer.ServerIPFinder.ReceiveRequest(reqMessage);
                    }
                    else if (receiver == "FileReceiver")
                    {
                        await FileTransfer.FileReceiver2.ReceiveRequest(reqMessage, new DownloadFolderDecider(),
                                                                        async s => { return(new WinRTFolder(await StorageFolder.GetFolderFromPathAsync(s))); });
                    }
                    else if (receiver == "TextReceiver")
                    {
                        await TextTransfer.TextReceiver.ReceiveRequest(reqMessage);
                    }
                    else if (receiver == "CloudClipboardHandler")
                    {
                        CloudClipboardHandler.ReceiveRequest(reqMessage);

                        _appServiceconnection.Dispose();
                        _deferral?.Complete();
                        _deferral = null;
                    }
                    else if (receiver == "System")
                    {
                        if (args.Request.Message.ContainsKey("FinishService"))
                        {
                            if (_deferral != null)
                            {
                                System.Diagnostics.Debug.WriteLine("Let's say goodbye");

                                while (waitingNumSemaphore > 0)
                                {
                                    await Task.Delay(100);
                                }

                                System.Diagnostics.Debug.WriteLine("Goodbye");
                                _appServiceconnection.Dispose();
                                _deferral?.Complete();
                                _deferral = null;
                            }
                        }
                    }
                }
            }
            finally
            {
                requestDeferral?.Complete();
            }
        }