public bool ConnectToSite() { try { Progress = ConnectionProgress.Connecting; sconnSite site = sconnDataShare.getSite(_siteId); Progress = ConnectionProgress.Authenticating; bool stat = _confMan.ReadSiteRunningConfig(site); //update if (stat) { Progress = ConnectionProgress.Success; Dispatcher.BeginInvoke((Action)(() => { ConnectedDel.Invoke(this, new EventArgs(), true, this._siteId); })); } else { Progress = ConnectionProgress.ConnectErr; } return(stat); } catch (Exception e) { Progress = ConnectionProgress.ConnectErr; return(false); } }
private string StatusToString(ConnectionProgress prog) { string sitename = sconnDataShare.getSite(_siteId).siteName; string resp = Properties.Resources.lblStatus_ConnectError; if (prog == ConnectionProgress.Connecting) { resp = Properties.Resources.lblStatus_Connecting + " " + sitename; return(resp); } else if (prog == ConnectionProgress.Authenticating) { resp = Properties.Resources.lblStatus_Authenticating + " " + sitename; return(resp); } else if (prog == ConnectionProgress.Authenticated) { resp = Properties.Resources.lblStatus_Authenticated + " " + sitename; return(resp); } else if (prog == ConnectionProgress.RequestingData) { resp = Properties.Resources.lblStatus_RequestingData + " " + sitename; return(resp); } else if (prog == ConnectionProgress.Recieving) { resp = Properties.Resources.lblStatus_Recieving + " " + sitename; return(resp); } else if (prog == ConnectionProgress.Success) { resp = Properties.Resources.lblStatus_Success + " " + sitename; return(resp); } else if (prog == ConnectionProgress.ConnectErr || prog == ConnectionProgress.ReadErr) { resp = Properties.Resources.lblStatus_ConnectError + " " + sitename; return(resp); } else { return(resp); } }
public override void Perform() { string pwd = ""; if (ControlService.SignCombo.Current.LoginInfomation.ConnectionPassword != null && ControlService.SignCombo.Current.LoginInfomation.ConnectionPassword != "") { pwd = ControlService.SignCombo.Current.LoginInfomation.ConnectionPassword; } else { pwd = InputDialog.GetInputValue("Enter Password"); } if (InputDialog.Result == DialogResult.Cancel) { ActionHelper.OnDisconnected(true); return; } if (pwd == null) { pwd = ""; } var sign = ControlService.SignCombo.Current; ConnectionProgress progerss = new ConnectionProgress(sign, true, pwd); progerss.ShowModalDialog(); if (!progerss.Result) { ActionHelper.OnDisconnected(true); } else { LiveImageAction liveImageAction = new LiveImageAction(); liveImageAction.Sign = sign; liveImageAction.Perform(); StatusAction statusAction = new StatusAction(false); statusAction.Sign = sign; statusAction.Perform(); GetStatusAction getStatus = new GetStatusAction(); getStatus.sign = sign; getStatus.Perform(); LogViewAction logviewAction = new LogViewAction(); logviewAction.sign = sign; logviewAction.Perform(); if (sign.IsWebCam) { this.InvokeMethod(() => ControlService.SignImage.RefreshImageCamera(sign)); } ControlService.SignCombo.Current.IsConnected = "Connected"; ControlService.DashboardTree.PopulateTree(); //#if VERSION_2 // AuthenticateService auth = new ProWriteAuthenticateService(); // if (auth.IsShowLivePage()) // ModuleManager.DisplayModule(ModuleNames.Live); //#endif } return; }
/// <summary> /// The loop used to process incoming messages. /// </summary> async void Process() { while (true) { await Task.Delay(20); string message; while ((message = Receive()) != null) { try { var doc = JObject.Parse(message); if (doc.TryGetValue("error", out var error)) { Log.LogError(error.ToString()); // handle error } else if (doc.TryGetValue("connected", out var connected) && (bool)connected) { IsConnectedToHelper = true; AppVersion = doc.Value <string>("app_version"); ConnectedToHelper?.Invoke(); } else if (doc.TryGetValue("info", out var _)) { var status = JsonConvert.DeserializeObject <StatusResult>(message); LatestStatus = status.info; StatusUpdate?.Invoke(); FullStatusUpdate?.Invoke(); } else if (doc.TryGetValue("name", out var name)) { var messageName = (string)name; var data = doc.Value <JObject>("data")?.Value <JObject>($"{messageName}Data"); if (messageName == "ServiceStateChanged") { var stateName = data.Value <string>("newstate"); if (!Enum.TryParse <State>(stateName, true, out State state)) { Log.LogError($"Unknown state in ServiceStateChanged: {stateName}"); } else { var info = LatestStatus; info.state = state; LatestStatus = info; StatusUpdate?.Invoke(); } } else if (messageName == "ConnectionProgress") { var progress = data.Value <float>("progress"); ConnectionProgress?.Invoke(progress); } else if (messageName == "SelectedLocationChanged") { var info = LatestStatus; var selectedLocation = info.selected_location; selectedLocation.id = data.Value <string>("id"); selectedLocation.name = data.Value <string>("name"); selectedLocation.is_country = data.Value <bool>("is_country"); selectedLocation.is_smart_location = data.Value <bool>("is_smart_location"); info.selected_location = selectedLocation; LatestStatus = info; StatusUpdate?.Invoke(); } else if (messageName == "WaitForNetworkReady") { // Ignore WaitForNetworkReady } else { Log.LogWarning($"Unhandled named message: {messageName}"); } } else if (doc.TryGetValue("Preferences", out var _)) { // handle preferences change } else if (doc.TryGetValue("locations", out var _)) { var result = JsonConvert.DeserializeObject <GetLocationsResult>(message); Locations = result.locations; DefaultLocationId = result.default_location.id; RecentLocationIds = result.recent_locations_ids; RecommendedLocationIds = result.recommended_location_ids; LocationsUpdated?.Invoke(); } else if (doc.TryGetValue("messages", out var _)) { // handle messages } else if (doc.TryGetValue("success", out var _)) { // Ignore useless success messages } else { Log.LogWarning($"Unhandled message: " + message); } } catch (Exception e) { Log.LogError($"Exception handling response: {e}"); } } } }
//main connection worker function private void connectionWorker_DoWork(object sender, DoWorkEventArgs e) { try { //runs through all of the computers, checking the connection BackgroundWorker worker = (BackgroundWorker)sender; int i = 0; int curIP; string octet3 = ""; if (!ipScheme) { if (type == 1) octet3 = "160."; else octet3 = "170."; } ConnectionProgress conProg = new ConnectionProgress(); while (true) { if (worker.CancellationPending) break; curIP = clientComps[i].ip; conProg.success = checkCon(baseIP + octet3 + curIP); conProg.compNumber = i; worker.ReportProgress(0, conProg); i = ++i % numComps; } } catch { throw; } }