Пример #1
0
        private void NotifySuspend()
        {
            //DiagnosticsHelper.UWP.Diag.DebugPrint("in NotifySuspend");
            OutputDebugString("edetocCCTSample_Tracing:   Entering NotifySuspend");


            try
            {
                Task.Run(() =>
                {
                    if (_communicationModule != null)
                    {
                        OutputDebugString("edetocCCTSample_Tracing:   Need to reset CommModule");
                        _communicationModule.Reset();
                        _communicationModule = null;
                        OutputDebugString("edetocCCTSample_Tracing:   CommModule reset done");
                    }

                    // create communication channel
                    _communicationModule = new CommModule();
                    _communicationModule.SetupTransport(GetServerUri());
                }).Wait();
            }
            catch (Exception ex)
            {
                OutputDebugString("edetocCCTSample_Tracing:   NotifySuspend. Exception" + ex.Message);
            }

            OutputDebugString("edetocCCTSample_Tracing:   Leaving NotifySuspend");
        }
        async private void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            if (connectionState == connectionStates.notConnected)
            {
                ConnectButton.Content = "Connecting...";
                connectionState       = connectionStates.connecting;
                string serverName = GetServerName();
                string serverPort = GetServerPort();

                // Ask to be notified when network status changes.
                RegisterNetworkChangeTask();

                // Finally, initiate the connection and set up transport
                // to be RTC capable. But do this heavy lifting outside of the UI thread.
                bool result = await Task <bool> .Factory.StartNew(() =>
                {
                    return(commModule.SetupTransport(serverName, serverPort));
                });

                Diag.DebugPrint("CommModule setup result: " + result);
                if (result == true)
                {
                    ConnectButton.Content = "Disconnect";
                    connectionState       = connectionStates.connected;
                }
                else
                {
                    ConnectButton.Content = "failed to connect. click to retry";
                    connectionState       = connectionStates.notConnected;
                }
            }
            else if (connectionState == connectionStates.connected)
            {
                await ResetTransportTaskAsync();

                connectionState       = connectionStates.notConnected;
                ConnectButton.Content = "Connect";
            }
        }
Пример #3
0
        async void ConfigurePushNotifications()
        {
            try
            {
                if (connectionState == connectionStates.connected)
                {
                    await Task.Factory.StartNew(() =>
                    {
                        commModule.Dispose();
                    });

                    commModule = new CommModule();

                    SetDisconnected();
                }
                else
                {
                    SetConnecting();

                    RegisterNetworkChangeTask();
                    ConfigureToastActions();

                    bool result = await Task.Factory.StartNew(() =>
                    {
                        return(commModule.SetupTransport(socketUri));
                    });

                    Diag.DebugPrint("CommModule setup result: " + result);

                    if (result)
                    {
                        ConfigureInvocations();
                        SetConnected();
                    }
                    else
                    {
                        SetDisconnected();
                    }
                }
            }
            catch (Exception ex)
            {
                Diag.DebugPrint("ConfigurePushNotifications failed: " + ex.Message);
                SetDisconnected();
            }
        }
Пример #4
0
        async private void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            if (connectionState == ConnectionStates.NotConnected)
            {
                if (!Uri.TryCreate(ServerUri.Text.Trim(), UriKind.Absolute, out serverUri))
                {
                    Diag.DebugPrint("Please provide valid uri input.");
                    return;
                }

                ConnectButton.Content = "Connecting...";
                connectionState       = ConnectionStates.Connecting;

                // Register for network status change notification
                RegisterNetworkChangeTask();

                // Finally, initiate the connection and set up transport
                // to be CCT capable. But do this heavy lifting outside of the UI thread.
                bool result = await Task <bool> .Factory.StartNew(() =>
                {
                    return(commModule.SetupTransport(serverUri));
                });

                Diag.DebugPrint("CommModule setup result: " + result);
                if (result == true)
                {
                    ConnectButton.Content = "Disconnect";
                    connectionState       = ConnectionStates.Connected;
                }
                else
                {
                    ConnectButton.Content = "failed to connect. click to retry";
                    connectionState       = ConnectionStates.NotConnected;
                }
            }
            else if (connectionState == ConnectionStates.Connected)
            {
                await Task.Factory.StartNew(() =>
                {
                    commModule.Reset();
                });

                connectionState       = ConnectionStates.NotConnected;
                ConnectButton.Content = "Connect";
            }
        }
Пример #5
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            if (taskInstance == null)
            {
                Diag.DebugPrint("NetworkChangeTask: taskInstance was null");
                return;
            }

            // In this example, the channel name has been hardcoded to lookup the property bag
            // for any previous contexts. The channel name may be used in more sophisticated ways
            // in case an app has multiple controlchanneltrigger objects.
            string channelId = "channelOne";

            if (((IDictionary <string, object>)CoreApplication.Properties).ContainsKey(channelId))
            {
                try
                {
                    AppContext appContext = null;
                    lock (CoreApplication.Properties)
                    {
                        appContext = ((IDictionary <string, object>)CoreApplication.Properties)[channelId] as AppContext;
                    }
                    if (appContext != null && appContext.CommInstance != null)
                    {
                        CommModule commInstance = appContext.CommInstance;

                        // Clear any existing channels, sockets etc.
                        commInstance.Reset();

                        // Create CCT enabled transport.
                        commInstance.SetupTransport(commInstance.serverUri);
                    }
                }
                catch (Exception exp)
                {
                    Diag.DebugPrint("Registering with CCT failed with: " + exp.ToString());
                }
            }
            else
            {
                Diag.DebugPrint("Cannot find AppContext key channelOne");
            }

            Diag.DebugPrint("Systemtask - " + taskInstance.Task.Name + " finished.");
        }
Пример #6
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            if (taskInstance == null)
            {
                Diag.DebugPrint("KATask: taskInstance was null");
                return;
            }

            Diag.DebugPrint("KATask " + taskInstance.Task.Name + " Starting...");

            // Use the ControlChannelTriggerEventDetails object to derive the context for this background task.
            // The context happens to be the channelId that apps can use to differentiate between
            // various instances of the channel..
            var channelEventArgs = taskInstance.TriggerDetails as IControlChannelTriggerEventDetails;

            ControlChannelTrigger channel = channelEventArgs.ControlChannelTrigger;

            if (channel == null)
            {
                Diag.DebugPrint("Channel object may have been deleted.");
                return;
            }

            string channelId = channel.ControlChannelTriggerId;

            if (((IDictionary <string, object>)CoreApplication.Properties).ContainsKey(channelId))
            {
                try
                {
                    var    appContext       = ((IDictionary <string, object>)CoreApplication.Properties)[channelId] as AppContext;
                    string KeepAliveMessage = "KeepAlive Message";
                    if (appContext != null && appContext.CommInstance != null)
                    {
                        CommModule commModule = appContext.CommInstance;
                        bool       result;
                        result = commModule.SendKAMessage(KeepAliveMessage);
                        if (result == true)
                        {
                            // Call FlushTransport on the channel object to ensure
                            // the packet is out of the process and on the wire before
                            // exiting the keepalive task.
                            commModule.channel.FlushTransport();
                        }
                        else
                        {
                            // Socket has not been set up. reconnect the transport and plug in to the controlchanneltrigger object.
                            commModule.Reset();

                            // Create RTC enabled transport.
                            commModule.SetupTransport(commModule.serverName, commModule.serverPort);
                        }
                    }
                }
                catch (Exception exp)
                {
                    Diag.DebugPrint("KA Task failed with: " + exp.Message);
                }
            }
            else
            {
                Diag.DebugPrint("Cannot find AppContext key channelOne");
            }

            Diag.DebugPrint("KATask " + taskInstance.Task.Name + " finished.");
        }