Exemplo n.º 1
0
        /// <summary>
        /// Runs component update
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="path"></param>
        /// <param name="type"></param>
        private void UpdateComponent(string fileName, string path, string type, string version)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.InvokeRequired)
            {
                UpdateComponentCallback callBack = new UpdateComponentCallback(UpdateComponent);
                Invoke(callBack, new object[] { fileName, path, type, version });
            }
            else
            {
                Log.WriteStart("Updating component");

                ComponentConfigElement element = AppContext.ScopeNode.Tag as ComponentConfigElement;
                string componentId             = element.ID;
                string componentName           = element.GetStringSetting("ComponentName");

                try
                {
                    Log.WriteInfo(string.Format("Updating {0}", componentName));
                    //download installer
                    Loader       form   = new Loader(fileName, (e) => AppContext.AppForm.ShowError(e));
                    DialogResult result = form.ShowDialog(this);
                    if (result == DialogResult.OK)
                    {
                        //run installer
                        string tmpFolder     = FileUtils.GetTempDirectory();
                        string installerPath = Path.Combine(tmpFolder, path);
                        Update();
                        string method = "Update";
                        Log.WriteStart(string.Format("Running installer {0}.{1} from {2}", type, method, path));
                        Hashtable args = new Hashtable();
                        args["ComponentId"]     = componentId;
                        args["ShellVersion"]    = AppContext.AppForm.Version;
                        args["BaseDirectory"]   = FileUtils.GetCurrentDirectory();
                        args["UpdateVersion"]   = version;
                        args["Installer"]       = Path.GetFileName(fileName);
                        args["InstallerType"]   = type;
                        args["InstallerPath"]   = path;
                        args["InstallerFolder"] = tmpFolder;
                        args["IISVersion"]      = Global.IISVersion;
                        args["ParentForm"]      = FindForm();

                        result = (DialogResult)AssemblyLoader.Execute(installerPath, type, method, new object[] { args });
                        Log.WriteInfo(string.Format("Installer returned {0}", result));
                        Log.WriteEnd("Installer finished");
                        Update();
                        if (result == DialogResult.OK)
                        {
                            ReloadApplication();
                        }
                        FileUtils.DeleteTempDirectory();
                    }
                    Log.WriteEnd("Update completed");
                }
                catch (Exception ex)
                {
                    Log.WriteError("Installer error", ex);
                    AppContext.AppForm.ShowError(ex);
                }
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// Runs component update
		/// </summary>
		/// <param name="fileName"></param>
		/// <param name="path"></param>
		/// <param name="type"></param>
		private void UpdateComponent(string fileName, string path, string type, string version)
		{
			// InvokeRequired required compares the thread ID of the
			// calling thread to the thread ID of the creating thread.
			// If these threads are different, it returns true.
			if (this.InvokeRequired)
			{
				UpdateComponentCallback callBack = new UpdateComponentCallback(UpdateComponent);
				Invoke(callBack, new object[] { fileName, path, type, version });
			}
			else
			{
				Log.WriteStart("Updating component");

				ComponentConfigElement element = AppContext.ScopeNode.Tag as ComponentConfigElement;
				string componentId = element.ID;
				string componentName = element.GetStringSetting("ComponentName");

				try
				{
					Log.WriteInfo(string.Format("Updating {0}", componentName));
					//download installer
					Loader form = new Loader(this.AppContext, fileName);
					DialogResult result = form.ShowDialog(this);
					if (result == DialogResult.OK)
					{
						//run installer
						string tmpFolder = FileUtils.GetTempDirectory();
						string installerPath = Path.Combine(tmpFolder, path);
						Update();
						string method = "Update";
						Log.WriteStart(string.Format("Running installer {0}.{1} from {2}", type, method, path));
						Hashtable args = new Hashtable();
						args["ComponentId"] = componentId;
						args["ShellVersion"] = AppContext.AppForm.Version;
						args["BaseDirectory"] = FileUtils.GetCurrentDirectory();
						args["UpdateVersion"] = version;
						args["Installer"] = Path.GetFileName(fileName);
						args["InstallerType"] = type;
						args["InstallerPath"] = path;
						args["InstallerFolder"] = tmpFolder;
						args["IISVersion"] = Global.IISVersion;
						args["ParentForm"] = FindForm();

						result = (DialogResult)AssemblyLoader.Execute(installerPath, type, method, new object[] { args });
						Log.WriteInfo(string.Format("Installer returned {0}", result));
						Log.WriteEnd("Installer finished");
						Update();
						if (result == DialogResult.OK)
						{
							ReloadApplication();
						}
						FileUtils.DeleteTempDirectory();
					}
					Log.WriteEnd("Update completed");
				}
				catch (Exception ex)
				{
					Log.WriteError("Installer error", ex);
					AppContext.AppForm.ShowError(ex);
				}
			}
		}