async void ClientInit() { commModule = new CommModule(); if (lockScreenAdded == false) { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); Diag.DebugPrint("Lock screen status " + status); switch (status) { case BackgroundAccessStatus.AlwaysAllowed: case BackgroundAccessStatus.AllowedSubjectToSystemPolicy: lockScreenAdded = true; break; case BackgroundAccessStatus.DeniedBySystemPolicy: case BackgroundAccessStatus.DeniedByUser: Diag.DebugPrint("As lockscreen status was Denied, app should switch to polling mode such as email based on time triggers"); break; } } btnConnection.Visibility = Visibility.Visible; return; }
public void Start() { AgentStatus = AgentStatus.Running; CommModule.Start(); while (AgentStatus == AgentStatus.Running) { CheckKillConditions(); if (CommModule.RecvData(out AgentMessage incoming)) { if (incoming != null) { HandleC2Data(incoming); } } foreach (var tcpClient in TcpClients) { if (tcpClient.ModuleStatus == ModuleStatus.Running && tcpClient.RecvData(out AgentMessage outgoing)) { CommModule.SendData(outgoing); } } } }
protected BinaryCommClient(string iniFile, string commonSectonName = null, string connSectonName = null, bool crypto = false) { this.connSectonName = connSectonName; commClient = new CommModule(crypto); ThrowIfFail(commClient.Start(iniFile, commonSectonName)); }
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"); }
public void Dispose() { if (commModule != null) { commModule.Dispose(); commModule = null; } }
public void Dispose() { if (commModule != null) { commModule.Dispose(); commModule = null; } UnregisterBackgroundTasks(); }
private void CheckKillConditions() { if (CommModule.GetStatus() == ModuleStatus.Stopped) { Stop(); return; } if ((DateTime)Config.GetOption(ConfigSetting.KillDate) < DateTime.UtcNow) { Stop(); return; } }
public CommDeviceEditDialog(MachineDevice device, CommModule module) { InitializeComponent(); this.Module = new CommModule() { Id = module.Id, Name = module.Name, Interval = module.Interval, IoTCommands = new List <IoTCommand>(), IPAddress = module.IPAddress, Port = module.Port, }; InitUI(); BindEvents(); }
async void ClientInit() { Diag.DebugPrint("Initializing client"); commModule = new CommModule(); // Lock screen is required to let in-process RealTimeCommunication related // background code to execute. if (!lockScreenAdded) { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); Diag.DebugPrint("Lock screen status" + status); switch (status) { case BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity: // App is allowed to use RealTimeConnection // functionality even in low power mode. lockScreenAdded = true; break; case BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity: // App is allowed to use RealTimeConnection // functionality but not in low power mode. lockScreenAdded = true; break; case BackgroundAccessStatus.Denied: // App should switch to polling mode (example: poll for email based on time triggers) Diag.DebugPrint("As Lockscreen status was Denied, App should switch to polling mode such as email based on time triggers."); break; } } if (lockScreenAdded) { // Now, enable the client settings. ClientSettings.Visibility = Visibility.Visible; ConnectButton.Visibility = Visibility.Visible; } Diag.DebugPrint("Initializing client done"); return; }
public void Start() { AgentStatus = AgentStatus.Running; CommModule.SetMetadata(AgentMetadata); CommModule.Start(); P2P.Start(); while (AgentStatus == AgentStatus.Running) { if (CommModule.RecvData(out AgentMessage message)) { HandleMessage(message); } } }
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(); } }
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."); }
async void ClientInit() { commModule = new CommModule(AppRole.ClientRole); // In the client role, we require the application to be on lock screen. // Lock screen is required to let in-process RealTimeCommunication related // background code to execute. if (lockScreenAdded == false) { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); Diag.DebugPrint("Lock screen status" + status); switch (status) { case BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity: // App is allowed to use RealTimeConnection broker // functionality even in low power mode. lockScreenAdded = true; break; case BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity: // App is allowed to use RealTimeConnection broker // functionality but not in low power mode. lockScreenAdded = true; break; case BackgroundAccessStatus.Denied: // App should switch to polling mode (example: poll for email based on time triggers) Diag.DebugPrint("As Lockscreen status was Denied, App should switch to polling mode such as email based on time triggers."); break; } } // Now, enable the client settings if the role hasn't changed. if (appRole == appRoles.clientRole) { ClientSettings.Visibility = Visibility.Visible; } ConnectButton.Visibility = Visibility.Visible; return; }
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."); }
private void SendData(AgentMessage message) { CommModule.SendData(message); }
void ServerInit() { commModule = new CommModule(AppRole.ServerRole); }