Ejemplo n.º 1
0
        /// <summary>
        /// Checks for component update
        /// </summary>
        private void CheckForUpdate()
        {
            Log.WriteStart("Checking for component update");
            ComponentConfigElement element = AppContext.ScopeNode.Tag as ComponentConfigElement;

            string componentName = element.GetStringSetting("ComponentName");
            string componentCode = element.GetStringSetting("ComponentCode");
            string release       = element.GetStringSetting("Release");

            // call web service
            DataSet ds;

            try
            {
                Log.WriteInfo(string.Format("Checking {0} {1}", componentName, release));
                //
                var webService = ServiceProviderProxy.GetInstallerWebService();
                ds = webService.GetComponentUpdate(componentCode, release);
                //
                Log.WriteEnd("Component update checked");
                AppContext.AppForm.FinishProgress();
            }
            catch (Exception ex)
            {
                Log.WriteError("Service error", ex);
                AppContext.AppForm.FinishProgress();
                AppContext.AppForm.ShowServerError();
                return;
            }

            string appName = AppContext.AppForm.Text;

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataRow row        = ds.Tables[0].Rows[0];
                string  newVersion = row["Version"].ToString();
                Log.WriteInfo(string.Format("Version {0} is available for download", newVersion));

                string message = string.Format("{0} {1} is available now.\nWould you like to install new version?", componentName, newVersion);
                if (MessageBox.Show(AppContext.AppForm, message, appName, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    string fileToDownload = row["UpgradeFilePath"].ToString();
                    string installerPath  = row["InstallerPath"].ToString();
                    string installerType  = row["InstallerType"].ToString();
                    UpdateComponent(fileToDownload, installerPath, installerType, newVersion);
                }
            }
            else
            {
                string message = string.Format("Current version of {0} is up to date.", componentName);
                Log.WriteInfo(message);
                AppContext.AppForm.ShowInfo(message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Shows control
        /// </summary>
        /// <param name="context"></param>
        public override void ShowControl(AppContext context)
        {
            base.ShowControl(context);
            if (!IsInitialized)
            {
                ComponentConfigElement element = context.ScopeNode.Tag as ComponentConfigElement;
                if (element != null)
                {
                    txtApplication.Text = element.GetStringSetting("ApplicationName");
                    txtComponent.Text   = element.GetStringSetting("ComponentName");
                    txtVersion.Text     = element.GetStringSetting("Release");
                    lblDescription.Text = element.GetStringSetting("ComponentDescription");

                    string installer = element.GetStringSetting("Installer");
                    string path      = element.GetStringSetting("InstallerPath");
                    string type      = element.GetStringSetting("InstallerType");
                    if (string.IsNullOrEmpty(installer) ||
                        string.IsNullOrEmpty(path) ||
                        string.IsNullOrEmpty(type))
                    {
                        btnRemove.Enabled   = false;
                        btnSettings.Enabled = false;
                    }
                }
                IsInitialized = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Uninstalls component
        /// </summary>
        private void UninstallComponent()
        {
            Log.WriteStart("Uninstalling component");

            ComponentConfigElement element = AppContext.ScopeNode.Tag as ComponentConfigElement;
            string installer     = element.GetStringSetting(Global.Parameters.Installer);
            string path          = element.GetStringSetting(Global.Parameters.InstallerPath);
            string type          = element.GetStringSetting(Global.Parameters.InstallerType);
            string componentId   = element.ID;
            string componentCode = element.GetStringSetting(Global.Parameters.ComponentCode);
            string componentName = element.GetStringSetting(Global.Parameters.ComponentName);
            string release       = element.GetStringSetting(Global.Parameters.Release);

            try
            {
                Log.WriteInfo(string.Format("Uninstalling {0}", componentName));
                //download installer
                Loader       form   = new Loader(installer, componentCode, release, (e) => AppContext.AppForm.ShowError(e));
                DialogResult result = form.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    //run installer
                    string tmpFolder = FileUtils.GetTempDirectory();
                    path = Path.Combine(tmpFolder, path);
                    Update();
                    string method = "Uninstall";
                    //
                    Log.WriteStart(string.Format("Running installer {0}.{1} from {2}", type, method, path));
                    //
                    var args = new Hashtable
                    {
                        { Global.Parameters.ComponentId, componentId },
                        { Global.Parameters.ComponentCode, componentCode },
                        { Global.Parameters.ShellVersion, AppContext.AppForm.Version },
                        { Global.Parameters.BaseDirectory, FileUtils.GetCurrentDirectory() },
                        { Global.Parameters.IISVersion, Global.IISVersion },
                        { Global.Parameters.ParentForm, FindForm() },
                    };
                    //
                    result = (DialogResult)AssemblyLoader.Execute(path, type, method, new object[] { args });
                    //
                    Log.WriteInfo(string.Format("Installer returned {0}", result));
                    Log.WriteEnd("Installer finished");
                    Update();
                    ReloadApplication();
                    FileUtils.DeleteTempDirectory();
                }
                Log.WriteEnd("Uninstall completed");
            }
            catch (Exception ex)
            {
                Log.WriteError("Installer error", ex);
                AppContext.AppForm.ShowError(ex);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Setup component
        /// </summary>
        private void SetupComponent()
        {
            Log.WriteStart("Starting component setup");

            ComponentConfigElement element = AppContext.ScopeNode.Tag as ComponentConfigElement;

            string installer     = element.GetStringSetting("Installer");
            string path          = element.GetStringSetting("InstallerPath");
            string type          = element.GetStringSetting("InstallerType");
            string componentId   = element.ID;
            string componentCode = element.GetStringSetting("ComponentCode");
            string componentName = element.GetStringSetting("ComponentName");
            string release       = element.GetStringSetting("Release");

            try
            {
                Log.WriteInfo(string.Format("Setup {0} {1}", componentName, release));
                //download installer
                Loader       form   = new Loader(this.AppContext, installer, componentCode, release);
                DialogResult result = form.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    string tmpFolder = Path.Combine(AppContext.CurrentPath, "Tmp");
                    path = Path.Combine(tmpFolder, path);
                    Update();
                    string method = "Setup";
                    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["IISVersion"]    = Global.IISVersion;
                    args["ParentForm"]    = FindForm();
                    result = (DialogResult)AssemblyLoader.Execute(path, type, method, new object[] { args });
                    Log.WriteInfo(string.Format("Installer returned {0}", result));
                    Log.WriteEnd("Installer finished");

                    if (result == DialogResult.OK)
                    {
                        ReloadApplication();
                    }
                    FileUtils.DeleteTempDirectory();
                }
                Log.WriteEnd("Component setup completed");
            }
            catch (Exception ex)
            {
                Log.WriteError("Installer error", ex);
                this.AppContext.AppForm.ShowError(ex);
            }
        }
Ejemplo n.º 5
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);
                }
            }
        }