public void StartLoadingProtocolsToServer(string ActiveUser, List <RoboSep_Protocol> tempList) { if (tempList == null) { return; } // LOG string logMSG = "Start thread for loading profile"; LogFile.AddMessage(System.Diagnostics.TraceLevel.Info, logMSG); try { RoboSep_UserConsole.strCurrentUser = ActiveUser;// textBox_UserName.Text; UserNameHeader.Text = ActiveUser; string[] sProtocols = new string[tempList.Count]; for (int i = 0; i < tempList.Count; i++) { sProtocols[i] = tempList[i].Protocol_FileName; } // save over user1.udb RoboSep_UserDB.getInstance().XML_SaveUserProfile(ActiveUser, sProtocols); protocolsToLoad = sProtocols.Length; // Reload protocols with SeparatorGateway using a thread myReloadProtocolsThread = new Thread(new ThreadStart(this.ReloadProtocolsThread)); myReloadProtocolsThread.IsBackground = true; myReloadProtocolsThread.Start(); // set sep-gateway to updating Separator Protocols // so that we can watch for when it is updated // (in timer_tick) SeparatorGateway.GetInstance().separatorUpdating = true; string sMSG = LanguageINI.GetString("msgLoadingProtocols"); string sTitle = LanguageINI.GetString("headerLoadingUserProtocols"); loading = new RoboMessagePanel5(RoboSep_UserConsole.getInstance(), sTitle, sMSG, GUI_Controls.GifAnimationMode.eUploadingMultipleFiles); RoboSep_UserConsole.showOverlay(); loading.Show(); //Thread.Sleep(SERVER_WAIT_TIME); // add loop to that polls loading status LoadUserTimer.Start(); } catch (Exception ex) { // LOG logMSG = "Failed to save user to server"; LogFile.AddMessage(System.Diagnostics.TraceLevel.Error, logMSG); } }
private void LoadUserTimer_Tick(object sender, EventArgs e) { if (loadState == 0 && RoboSep_UserConsole.getInstance().bLoadingProtocols) { loadState++; } else if (loadState == 1 && RoboSep_UserConsole.getInstance().bLoadingProtocols) { int Loaded = RoboSep_UserConsole.getInstance().ProtocolsLoaded; // calculate percent double completion = (double)Loaded * 100.00 / (double)protocolsToLoad; loading.setProgress((int)completion); } else //if (loadState == 1 && !RoboSep_UserConsole.getInstance().bLoadingProtocols) { // check if server list is updated // server delegate function will update // protocolUpdated value when completed if (!SeparatorGateway.GetInstance().protocolUpdated) { Thread.Sleep(100); } // peform completion test // check if given list matches // list returned from server else { if (isProtocolLoading) { return; } SeparatorGateway.GetInstance().protocolUpdated = false; bool ServerUpdated = true; LoadUserTimer.Stop(); if (ServerUpdated || reloadProtocolCount > 2) { loading.setProgress(90); reloadProtocolCount = 0; //RoboSep_UserConsole.getInstance().XML_getUserProtocols(); loadState = 0; // close dialog window loading.Close(); RoboSep_UserConsole.hideOverlay(); if (RoboSep_UserConsole.ctrlCurrentUserControl == this) { // run base home button click // base.btn_home_Click(sender, e); return; } else { // loading user from protocol selection window // check if current user control in UserConsole form // is protocol select control.. if so re-load page if (RoboSep_UserConsole.ctrlCurrentUserControl.GetType() == typeof(RoboSep_ProtocolSelect)) { RoboSep_UserConsole UC = RoboSep_UserConsole.getInstance(); UC.Controls.Remove(RoboSep_UserConsole.ctrlCurrentUserControl); RoboSep_ProtocolSelect PS = new RoboSep_ProtocolSelect(0, 4, null); UC.Controls.Add(PS); RoboSep_UserConsole.ctrlCurrentUserControl = PS; } return; } } else { reloadProtocolCount++; LoadUserToServer(textBox_UserName.Text); } } } }