Ejemplo n.º 1
0
        private async void CheckUpgrate()
        {
            btnLogin.IsEnabled = false;

            btnLogin.Content = "检查更新中...";

            var checkResult = await UpgradeHelper.CheckUpdate();

            if (checkResult)
            {
                //启动更新程序
                Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UpgradeTools/Rainy.UpgradeTool.exe"));

                //当前运行WPF程序的进程实例
                Process process = Process.GetCurrentProcess();
                //遍历WPF程序的同名进程组
                foreach (Process p in Process.GetProcessesByName(process.ProcessName))
                {
                    //关闭全部进程
                    p.Kill();//这个地方用kill 而不用Shutdown();
                    //Application.Current.Shutdown();
                    return;
                }
            }

            btnLogin.IsEnabled = true;
            btnLogin.Content   = "登录";
        }
Ejemplo n.º 2
0
 private void BeginUpgrade()
 {
     try
     {
         if (string.IsNullOrWhiteSpace(UpgradeHelper.Instance.UpgradeUrl))
         {
             return;
         }
         if (!(UpgradeHelper.Instance.UpgradeUrl.StartsWith("http://") || UpgradeHelper.Instance.UpgradeUrl.StartsWith("https://")))
         {
             Output("错误的服务器地址,地址必须以http://或者https://开头");
             return;
         }
         //判断是否有更新
         if (UpgradeHelper.Instance.WillUpgrades.Count > 0 && UpgradeHelper.Instance.Server_UpgradeModel != null)
         {
             SetWinControl(false);
             //杀死主进程
             UpgradeHelper.KillProcess(UpgradeHelper.Instance.Server_UpgradeModel.RunMain);
             RunUpgrade();//启动更新
         }
     }
     catch (Exception ex)
     {
         Output("更新异常:" + ex.Message);
     }
 }
Ejemplo n.º 3
0
 public PlantationUpgradeManager()
 {
     _regenUpgrade  = new UpgradeHelper <PlantationRegenUpgrade>(PlantationRegenUpgrade.Upgrades);
     _healthUpgrade = new UpgradeHelper <PlantationHealthUpgrade>(PlantationHealthUpgrade.Upgrades);
     _LPSUpgrade    = new UpgradeHelper <PlantationLPSUpgrade>(PlantationLPSUpgrade.Upgrades);
     _leavesUpgrade = new UpgradeHelper <PlantationLeavesUpgrade>(PlantationLeavesUpgrade.Upgrades);
 }
Ejemplo n.º 4
0
 protected void UpgradeStat <T>(UpgradeHelper <T> upgradeManager, Action <T> onSuccess) where T : Upgrade
 {
     if (upgradeManager.CanUpgrade() && _currencyManager.Spend(upgradeManager.Next.Cost))
     {
         upgradeManager.Upgrade();
         onSuccess(upgradeManager.Current);
         ConfigureUpgrades();
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// a function to check if there is an available building to research an upgrade
        /// </summary>
        /// <param name="upgradeId">desired upgrade to be researched</param>
        /// <returns>true if an idle building is waiting, false otherwise</returns>
        public static bool TrainingBuildingAvailable(int upgradeId)
        {
            HashSet <uint> hs = UpgradeHelper.GetUpgradeBuildingTypes(upgradeId);

            if (VBot.Bot.StateManager.GetAvailableAgent(hs) != null)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        static void Main()
        {
            //在主程序中 更新替换自动升级程序
            //ReplaceAutoUpgrade();

            bool isEnterMain = false;

            try
            {
                //设置默认更新地址,如果不设置,后面会从配置文件,或界面上进行设置
                UpgradeHelper.Instance.DefaultUrl = "http://localhost:17580";
                if (UpgradeHelper.Instance.Local_UpgradeModel != null)
                {
                    UpgradeHelper.Instance.UpgradeUrl = UpgradeHelper.Instance.Local_UpgradeModel.UpgradeUrl;
                }

                if (UpgradeHelper.Instance.WillUpgrades.Count == 0 && UpgradeHelper.Instance.Local_UpgradeModel != null)
                {
                    //没有待更新,并且本地版本信息文件不为空,则直接启动主程序
                    bool isSucced = UpgradeHelper.StartRunMain(UpgradeHelper.Instance.Local_UpgradeModel.RunMain);
                    if (isSucced)
                    {
                        Application.Exit();
                    }
                    else
                    {
                        //清理版本信息 以便重新检测版本
                        UpgradeHelper.Instance.ClearUpgradeModel();
                        isEnterMain = true;
                    }
                }
                else
                {
                    isEnterMain = true;
                }
            }
            catch (Exception ex)
            {
                isEnterMain = true;
                MessageBox.Show("运行更新程序异常:\n" + ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (isEnterMain)
            {
                //进入更新主界面
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmUpdate());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 启动更新
        /// </summary>
        private void RunUpgrade()
        {
            //启动更新
            SetCaption(string.Format("共需更新文件{0}个,已更新0个。正在更新下列文件:", UpgradeHelper.Instance.WillUpgrades.Count));
            Task.Factory.StartNew(() =>
            {
                string curFile = "";
                try
                {
                    int idx = 0;
                    foreach (KeyValuePair <string, string> item in UpgradeHelper.Instance.WillUpgrades)
                    {
                        curFile         = item.Key;
                        string filePath = string.Format("{0}\\{1}", Application.StartupPath, item.Key);
                        if (item.Key.IndexOf(UpgradeHelper.Instance.Server_UpgradeModel.AutoUpgrade) >= 0)
                        {
                            //如果当前文件为更新主程序
                            filePath = string.Format("{0}\\AutoUpgradeTemp\\{1}", Application.StartupPath, item.Key);
                        }
                        string directory = Path.GetDirectoryName(filePath);
                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }
                        MyWebResquest.DownloadFile(UpgradeHelper.Instance.UpgradeUrl, item.Key, filePath);
                        idx++;
                        SetCaption(string.Format("共需更新文件{0}个,已更新{1}个。更新文件列表:", UpgradeHelper.Instance.WillUpgrades.Count, idx));
                        Output(string.Format("更新文件{0}完成", curFile));
                    }
                    //保存版本文件
                    File.WriteAllText(UpgradeHelper.Instance.Local_UpgradeXmlPath, UpgradeHelper.Instance.Server_UpgradeXml);

                    SetCaption(string.Format("更新完成,共更新文件{0}个", UpgradeHelper.Instance.WillUpgrades.Count));
                    Output(string.Format("更新完成,共更新文件{0}个", UpgradeHelper.Instance.WillUpgrades.Count));

                    //下载完成后处理
                    UpgradeHelper.StartRunMain(UpgradeHelper.Instance.Server_UpgradeModel.RunMain);

                    //退出当前程序
                    ExitCurrent();
                }
                catch (Exception ex)
                {
                    Output(string.Format("更新文件{0}异常:{1}", curFile, ex.Message));
                    SetWinControl(true);
                }
            });
        }
Ejemplo n.º 8
0
        private ContentModel Upgrade(EntryModel model, ContentModel newContentModel, ContentType targetType)
        {
            if (model.ContentType == targetType)
            {
                return(null);
            }

            ContentModel newModel = null;

            if (model.ContentType == ContentType.Note && targetType == ContentType.Webpage)
            {
                newModel = new WebpageModel();
                var nowContent = newContentModel as NoteModel;
                UpgradeHelper.WriteValues(nowContent, (WebpageModel)newModel);
            }
            if (model.ContentType == ContentType.Note && targetType == ContentType.Person)
            {
                newModel = new PersonModel();
                var nowContent = newContentModel as NoteModel;
                UpgradeHelper.WriteValues(nowContent, (PersonModel)newModel);
            }
            if (model.ContentType == ContentType.Note && targetType == ContentType.Book)
            {
                newModel = new BookModel();
                var nowContent = newContentModel as NoteModel;
                UpgradeHelper.WriteValues(nowContent, (BookModel)newModel);
            }
            if (model.ContentType == ContentType.Webpage && targetType == ContentType.CreditCard)
            {
                newModel = new CreditCardModel();
                var nowContent = newContentModel as WebpageModel;
                UpgradeHelper.WriteValues(nowContent, (CreditCardModel)newModel);
            }
            if (model.ContentType == ContentType.Webpage && targetType == ContentType.OnlineAccount)
            {
                newModel = new OnlineAccountModel();
                var nowContent = newContentModel as WebpageModel;
                UpgradeHelper.WriteValues(nowContent, (OnlineAccountModel)newModel);
            }
            if (newModel != null)
            {
                model.ContentType = newModel.GetContentType();
            }
            return(newModel);
        }
Ejemplo n.º 9
0
        private bool CheckForUpgrades()
        {
            var v = MyData.Params.Version;

            if (!UpgradeHelper.CanUseVeriom(v, MyData.Version))
            {
                MyMainForm.ShowError("Programmas versija nav savietojama ar datu bāzes versiju.");
                return(false);
            }

            if (!UpgradeHelper.HasUpgrade(v, MyData.Version))
            {
                return(true);
            }

            var ret = MyMessageBox.Show(
                "Nepieciešams veikt datu bāzes versijas aktualizāciju.\n" +
                "Pirms to darīt, ieteicams aizvērt programmu un\n" +
                "izveidot datu rezerves kopiju.\n\n" +
                "Vai sākt datu bāzes aktualizāciju?"
                , "Jauna versija!",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning,
                MessageBoxDefaultButton.Button2,
                MyMainForm);

            if (ret != DialogResult.Yes)
            {
                return(false);
            }

            var dbfilename = MyData.GetFileName(MyData.CurrentDBTag);

            DoBackUpIfNeeded(dbfilename, true);

            if (!UpgradeHelper.UpgradeThis(v, MyData.Version))
            {
                DialogResult = DialogResult.Cancel;
            }

            return(true);
        }
Ejemplo n.º 10
0
        async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            tbkCurrentVersion.Text = "当前客户端版本:" + UpgradeSettings.Instance["CurrentVersion"];

            this.MouseDown += MainWindow_MouseDown;

            tbkUpgradeInfo.Text = "检查更新中...";

            _lastestVersionInfo = await UpgradeHelper.TryGetNewVersion();

            //有更新则直接更新掉
            if (_lastestVersionInfo != null)
            {
                ExcuteUpgrade();
            }
            else
            {
                FinishUpgrade();
            }
        }
Ejemplo n.º 11
0
    protected void ConfigureUpgrade <T>(UpgradeElement element, UpgradeHelper <T> upgradeManager, Action <T> successAction) where T : Upgrade
    {
        element.CostButton.onClick.RemoveAllListeners();

        bool hasNextUpgrade = upgradeManager.Next != null;

        element.CostButton.enabled = hasNextUpgrade;

        for (int i = 0; i < element.Levels.Length; i++)
        {
            element.Levels[i].color = (i < upgradeManager.Current.Level) ? new Color(186f / 255f, 0, 0, 1f) : Color.white;
        }

        if (hasNextUpgrade)
        {
            element.CostButton.onClick.AddListener(() => UpgradeStat(upgradeManager, successAction));
            element.Name.text     = upgradeManager.Next.Title;
            element.CostText.text = "£" + upgradeManager.Next.Cost.ToString();
        }
    }
Ejemplo n.º 12
0
        /// <summary>
        ///     Checks if there the tech requirements are met to make an upgrade.
        /// </summary>
        /// <param name="upgradeId">the unit type of the desired unit</param>
        /// <returns>true if the tech is built or non-existant, false otherwise</returns>
        public static bool CheckUpgradeTechRequirements(int upgradeId)
        {
            if (UpgradeHelper.GetUpgradeTechBuildingReq(upgradeId) == 0 &&
                UpgradeHelper.GetUpgradeTechUpgradeReq(upgradeId) == 0)
            {
                return(true);
            }

            if (UpgradeHelper.GetUpgradeTechUpgradeReq(upgradeId) != 0)
            {
                if (!CheckUpgrade(UpgradeHelper.GetUpgradeTechUpgradeReq(upgradeId), onlyCompleted: true))
                {
                    return(false);
                }
            }
            if (UpgradeHelper.GetUpgradeTechBuildingReq(upgradeId) != 0)
            {
                if (GetCompletedCount(UpgradeHelper.GetUpgradeTechBuildingReq(upgradeId)) == 0)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 13
0
        public ActionResult Upgrade()
        {
            var hiveManager       = DependencyResolver.Current.GetService <IHiveManager>();
            var appContext        = DependencyResolver.Current.GetService <IRebelApplicationContext>();
            var membershipService = appContext.Security.Users;

            //----------------------------------------
            // Upgrade users
            //----------------------------------------
            if (!UpgradeHelper.UsersUpgraded())
            {
                // Create core data
                using (var coreUow = hiveManager.OpenWriter <IContentStore>())
                {
                    // Create root nodes
                    coreUow.Repositories.AddOrUpdate(FixedEntities.UserProfileVirtualRoot);
                    coreUow.Repositories.AddOrUpdate(FixedEntities.MemberVirtualRoot);
                    coreUow.Repositories.AddOrUpdate(FixedEntities.MemberProfileVirtualRoot);
                    coreUow.Repositories.AddOrUpdate(FixedEntities.MemberGroupVirtualRoot);

                    // Create new schemas (MembershipUserSchema will actually overwrite the old UserSchema)
                    coreUow.Repositories.Schemas.AddOrUpdate(
                        Rebel.Framework.Security.Model.FixedSchemas.MembershipUserSchema);
                    coreUow.Repositories.Schemas.AddOrUpdate(
                        Rebel.Framework.Security.Model.FixedSchemas.UserProfileSchema);
                    coreUow.Repositories.Schemas.AddOrUpdate(
                        Rebel.Framework.Security.Model.FixedSchemas.MemberProfileSchema);

                    coreUow.Complete();
                }

                // Update users
                using (var userUow = hiveManager.OpenReader <ISecurityStore>(new Uri("security://users")))
                    using (var userGroupUow = hiveManager.OpenReader <ISecurityStore>(new Uri("security://user-groups")))
                    {
                        var users = userUow.Repositories.Where(
                            x =>
                            x.EntitySchema.Alias == "system-user");

                        foreach (var userEntity in users)
                        {
                            MembershipCreateStatus status;
                            var newUser = new User
                            {
                                Name =
                                    userEntity.Attribute <string>(NodeNameAttributeDefinition.AliasValue),
                                Username         = userEntity.Attribute <string>("username"),
                                Email            = userEntity.Attribute <string>("email"),
                                Password         = userEntity.Attribute <string>("password"),
                                PasswordQuestion = userEntity.Attribute <string>("passwordQuestion"),
                                PasswordAnswer   = userEntity.Attribute <string>("passwordAnswer"),
                                IsApproved       = userEntity.Attribute <bool>("isApproved"),
                            };

                            foreach (var attr in userEntity.Attributes)
                            {
                                if (
                                    newUser.EntitySchema.AttributeDefinitions.Any(
                                        x => x.Alias == attr.AttributeDefinition.Alias))
                                {
                                    if (
                                        newUser.Attributes.Any(
                                            x => x.AttributeDefinition.Alias == attr.AttributeDefinition.Alias))
                                    {
                                        foreach (var key in attr.Values.Keys)
                                        {
                                            if (newUser.Attributes[attr.AttributeDefinition.Alias].Values.ContainsKey(key))
                                            {
                                                newUser.Attributes[attr.AttributeDefinition.Alias].Values[key] =
                                                    attr.Values[key];
                                            }
                                            else
                                            {
                                                newUser.Attributes[attr.AttributeDefinition.Alias].Values.Add(key,
                                                                                                              attr.Values[
                                                                                                                  key]);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        newUser.Attributes.Add(attr);
                                    }
                                }
                            }

                            newUser.Groups =
                                userGroupUow.Repositories.GetParentRelations(userEntity.Id,
                                                                             FixedRelationTypes.UserGroupRelationType)
                                .Select(x => x.SourceId).ToArray();

                            membershipService.Create(newUser, out status);
                        }
                    }

                // Cleanup old user data
                using (var coreUow = hiveManager.OpenWriter <IContentStore>())
                {
                    var users = coreUow.Repositories.Where(
                        x =>
                        x.EntitySchema.Alias == "system-user");

                    foreach (var user in users)
                    {
                        coreUow.Repositories.Delete <TypedEntity>(user.Id);
                    }

                    coreUow.Repositories.Schemas.Delete <EntitySchema>(FixedHiveIds.RTMUserSchema);
                    coreUow.Complete();
                }
            }


            //----------------------------------------
            // Move files
            //----------------------------------------

            try
            {
                // ~/Views/Rebel/MacroPartials > ~/Views/MacroPartials
                MoveDirectory(Server.MapPath("~/Views/Rebel/MacroPartials"), Server.MapPath("~/Views/MacroPartials"));
            }
            catch (IOException)
            { }

            try
            {
                // ~/Views/Rebel/Partial > ~/Views/Partials
                MoveDirectory(Server.MapPath("~/Views/Rebel/Partial"), Server.MapPath("~/Views/Partials"));
            }
            catch (IOException)
            { }

            try
            {
                // ~/Views/Rebel/*.cshtml > ~/Views
                var files = Directory.GetFiles(Server.MapPath("~/Views/Rebel"), "*.cshtml", SearchOption.TopDirectoryOnly);
                foreach (var fileInfo in files.Select(file => new FileInfo(file)))
                {
                    var newFileInfo = new FileInfo(Server.MapPath("~/Views") + "/" + fileInfo.Name);
                    if (!newFileInfo.Exists)
                    {
                        global::System.IO.File.Move(fileInfo.FullName, newFileInfo.FullName);
                    }
                }
            }
            catch (IOException)
            { }


            //----------------------------------------
            // Fix broken schemas
            //----------------------------------------

            using (var coreUow = hiveManager.OpenWriter <IContentStore>())
            {
                // Fix image schema linking to wrong uploader attribute type
                var imageSchema = coreUow.Repositories.Schemas.Get <EntitySchema>(Framework.Persistence.Model.Constants.FixedHiveIds.MediaImageSchema);
                imageSchema.AttributeDefinitions[MediaImageSchema.UploadFileAlias].AttributeType = AttributeTypeRegistry.Current.GetAttributeType("uploader");
                imageSchema.SetXmlConfigProperty("icon", "tree-media-photo");
                coreUow.Repositories.Schemas.AddOrUpdate(imageSchema);

                coreUow.Complete();
            }

            return(RedirectToAction("Success"));
        }
 public async Task <string> Process()
 {
     return($"{await UpgradeHelper.Process()} {await EmailHelper.Process()}");
 }
Ejemplo n.º 15
0
 // Methods
 /// <summary>
 /// checks if it is possible to build/research unit/upgrade, then gets an agent and orders it to complete the task.
 /// </summary>
 public override void OnFrame()
 {
     if (UnitType != 0) // make a unit
     {
         if (Controller.CanMakeUnit(UnitType) && FromAgent == null)
         {
             // set the from type and execute the task
             if (MorphHelper.MorpSteps.ContainsKey(UnitType))
             {
                 FromAgent = Controller.GetAvailableAgent(MorphHelper.GetPreMorphType(UnitType));
                 FromAgent.Order(Units.GetAbilityId(UnitType)); // acts as execute()
                 Clear();                                       // only dismissed as it is morph type and eggs are useless and don't need to be busy
             }
             else if (TrainHelper.TrainSteps.ContainsKey(UnitType))
             {
                 FromAgent      = Controller.GetAvailableAgent(TrainHelper.GetTrainingBuildingTypes(UnitType));
                 FromAgent.Busy = true;
                 FromAgent.Order(Units.GetAbilityId(UnitType)); // acts as execute()
             }
             else
             {
                 FromAgent      = Controller.GetAvailableAgent(Units.Workers);
                 FromAgent.Busy = true;
                 Controller.BuildStructure(FromAgent, UnitType); // acts as Execute()
             }
         }
         else if (FromAgent != null)
         {
             if (FromAgent.Unit.Orders.Count == 0)
             {
                 // agent is idle. clear it
                 Clear();
             }
         }
         else
         {
             Clear();
         }
     }
     else
     {
         if (Controller.CanMakeUpgrade(UpgradeType) && FromAgent == null)
         {
             FromAgent      = Controller.GetAvailableAgent(UpgradeHelper.GetUpgradeBuildingTypes(UpgradeType));
             FromAgent.Busy = true;
             FromAgent.Order(Upgrades.GetAbilityId(UpgradeType));
         }
         else if (FromAgent != null)
         {
             if (FromAgent.Unit.Orders.Count == 0)
             {
                 FromAgent.Busy = false;
                 Clear();
             }
         }
         else
         {
             Clear();
         }
     }
 }