예제 #1
0
        /// <summary>
        /// reverts to the ASC version stored in D:\\ASC_AUTO_BAK.zip
        /// </summary>
        static void revert()
        {
            Dictionary <string, bool> report = new Dictionary <string, bool>();

            report.Add("backup", false);
            report.Add("extraction", false);
            report.Add("execution", false);
            report.Add("reversion", false);
            report.Add("attention", false);

            string dest_dir     = "D:\\ASC";                //current and destination ASC directory
            string service_name = "ASC";                    //name of the service to stop and start
            string old_backup   = "D:\\ASC_AUTO_BAK.zip";   //location of the original backup
            string backup_path  = "D:\\ASC_REVERT_BAK.zip"; //location to store the backup zip

            try
            {
                if (File.Exists(old_backup) && Service_control(service_name, "STOP"))
                {
                    //------------------------------------------------------------------
                    //                  backup current ASC and verify backup
                    //------------------------------------------------------------------
                    if (Directory.Exists(dest_dir))
                    {
                        if (!Backup.backup(dest_dir, backup_path))
                        {
                            Exit(report);
                        }
                        if (!Backup.verify_backup(dest_dir, backup_path))
                        {
                            Exit(report);
                        }
                        else
                        {
                            report["backup"] = true;
                        }
                    }
                    else
                    {
                        report["backup"] = true;
                    }

                    //------------------------------------------------------------------
                    //                  Revert to old version
                    //------------------------------------------------------------------
                    if (Install.unzip(old_backup, dest_dir, true))                                                           //if install of files succeeded
                    {
                        report["extraction"] = true;
                        if (Service_control(service_name, "START"))                                                          //start the service
                        {
                            if (Install.verify(service_name))
                            {
                                log("ASC upgrade successfull"); report["execution"] = true; Exit(report, return_override: 0);
                            }                                                                                                                                  //if ASC runs for 2 minutes, success
                            else
                            {
                                log("Service failed to keep running, reverting to previous version"); report["execution"] = false;
                            }                                                                                                                      //else it crashed, revert to backup
                        }
                        else
                        {
                            log("Service failed to start, reverting to previous version"); report["execution"] = false;
                        }                                                                                                                          //service did not start, revert to backup
                    }
                    else
                    {
                        log("ASC install general failure"); report["extraction"] = false;
                    }                                                                                                      //unknown failure, revert to backup
                    log("execution: " + report["execution"]);

                    //------------------------------------------------------------------
                    //                  Revert back to new version
                    //------------------------------------------------------------------
                    if (Install.unzip(backup_path, dest_dir, true))                                                           //if re-installing old files succeeded
                    {
                        report["extraction"] = true;
                        if (Service_control(service_name, "START"))                                                         //start the service
                        {
                            if (Install.verify(service_name))
                            {
                                log("ASC reversion successfull"); report["reversion"] = true; Exit(report);
                            }                                                                                                                   //if ASC runs for 2 minutes, reversion successfull
                            else
                            {
                                log("Service failed to keep running, immediate attention required"); report["reversion"] = false; report["attention"] = true;
                            }                                                                                                                                     //else ASC crashed, immediate attention required
                        }
                        else
                        {
                            log("Service failed to start, , immediate attention required"); report["reversion"] = false; report["attention"] = true;
                        }                                                                                                                                         //service did not start, immediate attention required
                    }
                    else
                    {
                        log("ASC reverion general failure, immediate attention required"); report["reversion"] = false; report["attention"] = true;
                    }                                                                                                                                             //unknown failure, immediate attention required
                }
                else
                {
                    Exit(report);
                }

                Exit(report);
            }
            catch (Exception e) { log(e.ToString(), true); Exit(report); }
        }
예제 #2
0
        /// <summary>
        /// upgrades ASC to the packaged version
        /// </summary>
        static void upgrade()
        {
            Dictionary <string, bool> report = new Dictionary <string, bool>();

            report.Add("backup", false);
            report.Add("extraction", false);
            report.Add("execution", false);
            report.Add("reversion", false);
            report.Add("attention", false);

            string temp_path    = "D:\\ASC_NEW.zip";      //location to extract the embedded zip to
            string dest_dir     = "D:\\ASC";              //current and destination ASC directory
            string service_name = "ASC";                  //name of the service to stop and start
            string backup_path  = "D:\\ASC_AUTO_BAK.zip"; //location to store the backup zip

            //If ASC is not installed, exit without doing anything
            if (!Directory.Exists(dest_dir))
            {
                Exit(report);
            }

            try
            {
                //stop service and start the upgrade process
                if (Service_control(service_name, "STOP"))
                {
                    //------------------------------------------------------------------
                    //                  unpack embedded ASC.zip
                    //------------------------------------------------------------------
                    if (!Install.unpack(temp_path))
                    {
                        Exit(report);
                    }
                    else
                    {
                        report["extraction"] = true;
                    }

                    //------------------------------------------------------------------
                    //                  backup current ASC and verify backup
                    //------------------------------------------------------------------
                    if (Directory.Exists(dest_dir))
                    {
                        if (!Backup.backup(dest_dir, backup_path))
                        {
                            Exit(report);
                        }
                        if (!Backup.verify_backup(dest_dir, backup_path))
                        {
                            Exit(report);
                        }
                        else
                        {
                            report["backup"] = true;
                        }
                    }
                    else
                    {
                        report["backup"] = true;
                    }

                    //------------------------------------------------------------------
                    //                  install new version
                    //------------------------------------------------------------------
                    if (Install.unzip(temp_path, dest_dir, false))                                                          //if install of files succeeded
                    {
                        File.Delete(temp_path);                                                                             //delete temporary update zip
                        report["extraction"] = true;
                        if (Service_control(service_name, "START"))                                                         //start the service
                        {
                            if (Install.verify(service_name))
                            {
                                log("ASC upgrade successfull"); report["execution"] = true; Exit(report, return_override: 0);
                            }                                                                                                                                  //if ASC runs for 2 minutes, success
                            else
                            {
                                log("Service failed to keep running, reverting to previous version"); report["execution"] = false;
                            }                                                                                                                      //else it crashed, revert to backup
                        }
                        else
                        {
                            log("Service failed to start, reverting to previous version"); report["execution"] = false;
                        }                                                                                                                          //service did not start, revert to backup
                    }
                    else
                    {
                        log("ASC install general failure"); report["extraction"] = false; File.Delete(temp_path);
                    }                                                                                                                              //unknown failure, revert to backup

                    //------------------------------------------------------------------
                    //                  Revert back to old version
                    //------------------------------------------------------------------
                    if (Install.unzip(backup_path, dest_dir, true))                                                           //if re-installing old files succeeded
                    {
                        report["extraction"] = true;
                        if (Service_control(service_name, "START"))                                                         //start the service
                        {
                            if (Install.verify(service_name))
                            {
                                log("ASC reversion successfull"); report["reversion"] = true; Exit(report);
                            }                                                                                                                   //if ASC runs for 2 minutes, reversion successfull
                            else
                            {
                                log("Service failed to keep running, immediate attention required"); report["reversion"] = false; report["attention"] = true;
                            }                                                                                                                                     //else ASC crashed, immediate attention required
                        }
                        else
                        {
                            log("Service failed to start, , immediate attention required"); report["reversion"] = false; report["attention"] = true;
                        }                                                                                                                                         //service did not start, immediate attention required
                    }
                    else
                    {
                        log("ASC reverion general failure, immediate attention required"); report["reversion"] = false; report["attention"] = true;
                    }                                                                                                                                             //unknown failure, immediate attention required
                }
                //exit if the service did not stop
                else
                {
                    log("Not Stopped"); report["reversion"] = false; report["attention"] = true; Exit(report);
                }                                                                                                                                                       //service never stopped, no actions performed

                //exit with return code and output json if not done so already
                Exit(report);
            }
            catch (Exception e) { log(e.ToString(), true); Exit(report); }
        }