Ejemplo n.º 1
0
 /// <summary>destinationPath includes filename (Setup.exe).  destinationPath2 will create a second copy at the specified path/filename, or it will be skipped if null or empty.</summary>
 public static void DownloadInstallPatchFromURI(string downloadUri,string destinationPath,bool runSetupAfterDownload,bool showShutdownWindow,string destinationPath2)
 {
     string[] dblist=PrefC.GetString(PrefName.UpdateMultipleDatabases).Split(new string[] {","},StringSplitOptions.RemoveEmptyEntries);
     if(showShutdownWindow) {
         //Even if updating multiple databases, extra shutdown signals are not needed.
         FormShutdown FormSD=new FormShutdown();
         FormSD.IsUpdate=true;
         FormSD.ShowDialog();
         if(FormSD.DialogResult==DialogResult.OK) {
             //turn off signal reception for 5 seconds so this workstation will not shut down.
             FormOpenDental.signalLastRefreshed=MiscData.GetNowDateTime().AddSeconds(5);
             Signalod sig=new Signalod();
             sig.ITypes=((int)InvalidType.ShutDownNow).ToString();
             sig.SigType=SignalType.Invalid;
             Signalods.Insert(sig);
             Computers.ClearAllHeartBeats(Environment.MachineName);//always assume success
             //SecurityLogs.MakeLogEntry(Permissions.Setup,0,"Shutdown all workstations.");//can't do this because sometimes no user.
         }
         //continue on even if user clicked cancel
         //no other workstation will be able to start up until this value is reset.
         Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName,Environment.MachineName);
     }
     MiscData.LockWorkstationsForDbs(dblist);//lock workstations for other db's.
     File.Delete(destinationPath);
     WebRequest wr=WebRequest.Create(downloadUri);
     WebResponse webResp=null;
     try{
         webResp=wr.GetResponse();
     }
     catch(Exception ex){
         CodeBase.MsgBoxCopyPaste msgbox=new MsgBoxCopyPaste(ex.Message+"\r\nUri: "+downloadUri);
         msgbox.ShowDialog();
         MiscData.UnlockWorkstationsForDbs(dblist);//unlock workstations since nothing was actually done.
         return;
     }
     int fileSize=(int)webResp.ContentLength/1024;
     FormProgress FormP=new FormProgress();
     //start the thread that will perform the download
     System.Threading.ThreadStart downloadDelegate= delegate { DownloadInstallPatchWorker(downloadUri,destinationPath,ref FormP); };
     Thread workerThread=new System.Threading.Thread(downloadDelegate);
     workerThread.Start();
     //display the progress dialog to the user:
     FormP.MaxVal=(double)fileSize/1024;
     FormP.NumberMultiplication=100;
     FormP.DisplayText="?currentVal MB of ?maxVal MB copied";
     FormP.NumberFormat="F";
     FormP.ShowDialog();
     if(FormP.DialogResult==DialogResult.Cancel) {
         workerThread.Abort();
         MiscData.UnlockWorkstationsForDbs(dblist);//unlock workstations since nothing was actually done.
         return;
     }
     //copy to second destination directory
     if(destinationPath2!=null && destinationPath2!=""){
         if(File.Exists(destinationPath2)){
             File.Delete(destinationPath2);
         }
         File.Copy(destinationPath,destinationPath2);
     }
     //copy the Setup.exe to the AtoZ folders for the other db's.
     List<string> atozNameList=MiscData.GetAtoZforDb(dblist);
     for(int i=0;i<atozNameList.Count;i++) {
         if(destinationPath==Path.Combine(atozNameList[i],"Setup.exe")) {//if they are sharing an AtoZ folder.
             continue;
         }
         if(Directory.Exists(atozNameList[i])) {
             File.Copy(destinationPath,//copy the Setup.exe that was just downloaded to this AtoZ folder
                 Path.Combine(atozNameList[i],"Setup.exe"),//to the other atozFolder
                 true);//overwrite
         }
     }
     if(!runSetupAfterDownload) {
         return;
     }
     string msg=Lan.g("FormUpdate","Download succeeded.  Setup program will now begin.  When done, restart the program on this computer, then on the other computers.");
     if(dblist.Length > 0){
         msg="Download succeeded.  Setup file probably copied to other AtoZ folders as well.  Setup program will now begin.  When done, restart the program for each database on this computer, then on the other computers.";
     }
     if(MessageBox.Show(msg,"",MessageBoxButtons.OKCancel) !=DialogResult.OK){
         //Clicking cancel gives the user a chance to avoid running the setup program,
         Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName,"");//unlock workstations, since nothing was actually done.
         return;
     }
     try{
         Process.Start(destinationPath);
         Application.Exit();
     }
     catch{
         Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName,"");//unlock workstations, since nothing was actually done.
         MsgBox.Show(FormP,"Could not launch setup");
     }
 }
Ejemplo n.º 2
0
 private void menuItemShutdown_Click(object sender,EventArgs e)
 {
     if(!Security.IsAuthorized(Permissions.Setup)) {
         return;
     }
     FormShutdown FormS=new FormShutdown();
     FormS.ShowDialog();
     if(FormS.DialogResult!=DialogResult.OK) {
         return;
     }
     //turn off signal reception for 5 seconds so this workstation will not shut down.
     signalLastRefreshed=MiscData.GetNowDateTime().AddSeconds(5);
     Signalod sig=new Signalod();
     sig.ITypes=((int)InvalidType.ShutDownNow).ToString();
     sig.SigType=SignalType.Invalid;
     Signalods.Insert(sig);
     Computers.ClearAllHeartBeats(Environment.MachineName);//always assume success
     SecurityLogs.MakeLogEntry(Permissions.Setup,0,"Shutdown all workstations.");
 }
Ejemplo n.º 3
0
		/// <summary>destinationPath includes filename (Setup.exe).  destinationPath2 will create a second copy at the specified path/filename, or it will be skipped if null or empty.</summary>
		public static void DownloadInstallPatchFromURI(string downloadUri,string destinationPath,bool runSetupAfterDownload,bool showShutdownWindow,string destinationPath2){
			string[] dblist=PrefC.GetString(PrefName.UpdateMultipleDatabases).Split(new string[] {","},StringSplitOptions.RemoveEmptyEntries);
			if(showShutdownWindow) {
				//Even if updating multiple databases, extra shutdown signals are not needed.
				FormShutdown FormSD=new FormShutdown();
				FormSD.IsUpdate=true;
				FormSD.ShowDialog();
				if(FormSD.DialogResult==DialogResult.OK) {
					//turn off signal reception for 5 seconds so this workstation will not shut down.
					FormOpenDental.signalLastRefreshed=MiscData.GetNowDateTime().AddSeconds(5);
					Signalod sig=new Signalod();
					sig.ITypes=((int)InvalidType.ShutDownNow).ToString();
					sig.SigType=SignalType.Invalid;
					Signalods.Insert(sig);
					Computers.ClearAllHeartBeats(Environment.MachineName);//always assume success
					//SecurityLogs.MakeLogEntry(Permissions.Setup,0,"Shutdown all workstations.");//can't do this because sometimes no user.
				}
				//continue on even if user clicked cancel
				//no other workstation will be able to start up until this value is reset.
				Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName,Environment.MachineName);
			}
			MiscData.LockWorkstationsForDbs(dblist);//lock workstations for other db's.
			File.Delete(destinationPath);
			WebRequest wr=WebRequest.Create(downloadUri);
			WebResponse webResp=null;
			try{
				webResp=wr.GetResponse();
			}
			catch(Exception ex){
				CodeBase.MsgBoxCopyPaste msgbox=new MsgBoxCopyPaste(ex.Message+"\r\nUri: "+downloadUri);
				msgbox.ShowDialog();
				MiscData.UnlockWorkstationsForDbs(dblist);//unlock workstations since nothing was actually done.
				return;
			}
			int fileSize=(int)webResp.ContentLength/1024;
			FormProgress FormP=new FormProgress();
			//start the thread that will perform the download
			System.Threading.ThreadStart downloadDelegate= delegate { DownloadInstallPatchWorker(downloadUri,destinationPath,ref FormP); };
			Thread workerThread=new System.Threading.Thread(downloadDelegate);
			workerThread.Start();
			//display the progress dialog to the user:
			FormP.MaxVal=(double)fileSize/1024;
			FormP.NumberMultiplication=100;
			FormP.DisplayText="?currentVal MB of ?maxVal MB copied";
			FormP.NumberFormat="F";
			FormP.ShowDialog();
			if(FormP.DialogResult==DialogResult.Cancel) {
				workerThread.Abort();
				MiscData.UnlockWorkstationsForDbs(dblist);//unlock workstations since nothing was actually done.
				return;
			}
			//copy to second destination directory
			if(destinationPath2!=null && destinationPath2!=""){
				if(File.Exists(destinationPath2)){
					File.Delete(destinationPath2);
				}
				File.Copy(destinationPath,destinationPath2);
			}
			//copy the Setup.exe to the AtoZ folders for the other db's.
			List<string> atozNameList=MiscData.GetAtoZforDb(dblist);
			for(int i=0;i<atozNameList.Count;i++) {
				if(destinationPath==Path.Combine(atozNameList[i],"Setup.exe")) {//if they are sharing an AtoZ folder.
					continue;
				}
				if(Directory.Exists(atozNameList[i])) {
					File.Copy(destinationPath,//copy the Setup.exe that was just downloaded to this AtoZ folder
						Path.Combine(atozNameList[i],"Setup.exe"),//to the other atozFolder
						true);//overwrite
				}
			}
			if(!runSetupAfterDownload) {
				return;
			}
			string msg=Lan.g("FormUpdate","Download succeeded.  Setup program will now begin.  When done, restart the program on this computer, then on the other computers.");
			if(dblist.Length > 0){
				msg="Download succeeded.  Setup file probably copied to other AtoZ folders as well.  Setup program will now begin.  When done, restart the program for each database on this computer, then on the other computers.";
			}
			if(MessageBox.Show(msg,"",MessageBoxButtons.OKCancel) !=DialogResult.OK){
				//Clicking cancel gives the user a chance to avoid running the setup program,
				Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName,"");//unlock workstations, since nothing was actually done.
				return;
			}
			#region Stop OpenDent Services
			//If the update has been initiated from the designated update server then try and stop all "OpenDent..." services.
			//They will be automatically restarted once Open Dental has successfully upgraded.
			if(PrefC.GetString(PrefName.WebServiceServerName)!="" && ODEnvironment.IdIsThisComputer(PrefC.GetString(PrefName.WebServiceServerName))) {
				List<ServiceController> listServices=ODEnvironment.GetAllOpenDentServices();
				StringBuilder strBuilder=new StringBuilder();
				if(listServices.Count>0) {
					FormAlertSimple FormAS=new FormAlertSimple(Lan.g("FormUpdate","Stopping services..."));
					FormAS.Show();
					Application.DoEvents();//Allows the form to show up on top of FormUpdate right away.
					//Loop through all Open Dental services and stop them if they have not stopped or are not pending a stop so that their binaries can be updated.
					for(int i=0;i<listServices.Count;i++) {
						if(listServices[i].Status==ServiceControllerStatus.Stopped || listServices[i].Status==ServiceControllerStatus.StopPending) {
							continue;//Already stopped.  Calling Stop again will guarantee an exception is thrown.  Do not try calling Stop on a stopped service.
						}
						try {
							listServices[i].Stop();
							listServices[i].WaitForStatus(ServiceControllerStatus.Stopped,new TimeSpan(0,0,7));
						}
						catch {
							//An InvalidOperationException will get thrown if the service could not stop.  E.g. the user is not running Open Dental as an administrator.
							strBuilder.AppendLine(listServices[i].DisplayName);
						}
					}
					FormAS.Close();
					//Notify the user to go manually stop the services that could not automatically stop.
					if(strBuilder.ToString()!="") {
						MsgBoxCopyPaste msgBCP=new MsgBoxCopyPaste(Lan.g("FormUpdate","The following services could not be stopped.  You need to manually stop them before continuing.")
						+"\r\n"+strBuilder.ToString());
						msgBCP.ShowDialog();
					}
				}
			}
			#endregion
			try {
				Process.Start(destinationPath);
				Application.Exit();
			}
			catch{
				Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName,"");//unlock workstations, since nothing was actually done.
				MsgBox.Show(FormP,"Could not launch setup");
			}
		}