public static InstallerService GetInstallerWebService()
		{
			var webService = new InstallerService();

			string url = AppConfigManager.AppConfiguration.GetStringSetting(ConfigKeys.Web_Service);
			if (!String.IsNullOrEmpty(url))
			{
				webService.Url = url;
			}
			else
			{
				webService.Url = "http://www.websitepanel.net/Services/InstallerService-2.1.asmx";
			}

			// check if we need to add a proxy to access Internet
			bool useProxy = AppConfigManager.AppConfiguration.GetBooleanSetting(ConfigKeys.Web_Proxy_UseProxy);
			if (useProxy)
			{
				string proxyServer = AppConfigManager.AppConfiguration.Settings[ConfigKeys.Web_Proxy_Address].Value;
				if (!String.IsNullOrEmpty(proxyServer))
				{
					IWebProxy proxy = new WebProxy(proxyServer);
					string proxyUsername = AppConfigManager.AppConfiguration.Settings[ConfigKeys.Web_Proxy_UserName].Value;
					string proxyPassword = AppConfigManager.AppConfiguration.Settings[ConfigKeys.Web_Proxy_Password].Value;
					if (!String.IsNullOrEmpty(proxyUsername))
						proxy.Credentials = new NetworkCredential(proxyUsername, proxyPassword);
					webService.Proxy = proxy;
				}
			}

			return webService;
		}
示例#2
0
		/// <summary>
		/// Displays process progress.
		/// </summary>
		public void ShowProcess()
		{
			progressBar.Value = 0;
			try
			{
				service = appContext.AppForm.WebService;
				string dataFolder = FileUtils.GetDataDirectory();
				string tmpFolder = FileUtils.GetTempDirectory();
				
				if (!Directory.Exists(dataFolder))
				{
					Directory.CreateDirectory(dataFolder);
					Log.WriteInfo("Data directory created");
				}

				if (Directory.Exists(tmpFolder))
				{
					FileUtils.DeleteTempDirectory();
				}
				
				if (!Directory.Exists(tmpFolder))
				{
					Directory.CreateDirectory(tmpFolder);
					Log.WriteInfo("Tmp directory created");
				}

				string fileToDownload = null;
				if (!string.IsNullOrEmpty(localFile))
				{
					fileToDownload = localFile;
				}
				else
				{
					fileToDownload = Path.GetFileName(remoteFile);
				}

				string destinationFile = Path.Combine(dataFolder, fileToDownload);
				string tmpFile = Path.Combine(tmpFolder, fileToDownload);

				
				//check whether file already downloaded
				if (!File.Exists(destinationFile))
				{
					if ( string.IsNullOrEmpty(remoteFile) )
					{
						//need to get remote file name
						lblProcess.Text = "Connecting...";
						progressBar.Value = 0;
						DataSet ds = service.GetReleaseFileInfo(componentCode, version);
						progressBar.Value = 100;
						if (ds != null &&
							ds.Tables.Count > 0 &&
							ds.Tables[0].Rows.Count > 0)
						{
							DataRow row = ds.Tables[0].Rows[0];
							remoteFile = row["FullFilePath"].ToString();
							fileToDownload = Path.GetFileName(remoteFile);
							destinationFile = Path.Combine(dataFolder, fileToDownload);
							tmpFile = Path.Combine(tmpFolder, fileToDownload);
						}
						else
						{
							throw new Exception("Installer not found"); 
						}
					}
					
					// download file to tmp folder
					lblProcess.Text = "Downloading setup files...";
					progressBar.Value = 0;
					DownloadFile(remoteFile, tmpFile, progressBar);
					progressBar.Value = 100;
					
					// copy downloaded file to data folder
					lblProcess.Text = "Copying setup files...";
					progressBar.Value = 0;
					// Ensure that the target does not exist.
					if (File.Exists(destinationFile))
						FileUtils.DeleteFile(destinationFile);
					File.Move(tmpFile, destinationFile);
					progressBar.Value = 100;
				}

				// unzip file
				lblProcess.Text = "Please wait while Setup prepares the necessary files...";
				progressBar.Value = 0;
				UnzipFile(destinationFile, tmpFolder, progressBar);
				progressBar.Value = 100;

				this.DialogResult = DialogResult.OK;
				this.Close();
			}
			catch (Exception ex)
			{
				if (Utils.IsThreadAbortException(ex))
					return;

				Log.WriteError("Installer error", ex);
				appContext.AppForm.ShowError(ex);
				this.DialogResult = DialogResult.Abort;
				this.Close();
			}
		}