Exemple #1
0
        public async Task DownloadLatestVersion(ITaskProgress taskProgress)
        {
            cachedResponse ??= await InternalCheckForUpdates();

            if (cachedResponse != null)
            {
                var progress = new Progress <(long downloaded, long?totalBytes)>((v) =>
                {
                    var isDownloaded = (v.totalBytes.HasValue && v.totalBytes.Value == v.downloaded) ||
                                       v.downloaded == -1;
                    var isStatusKnown   = v.totalBytes.HasValue;
                    var currentProgress = v.totalBytes.HasValue ? (int)v.downloaded : (v.downloaded < 0 ? 1 : 0);
                    var maxProgress     = v.totalBytes ?? 1;

                    if (taskProgress.State == TaskState.InProgress)
                    {
                        taskProgress.Report(currentProgress, (int)maxProgress, isDownloaded ?
                                            "finished" :
                                            (isStatusKnown ? $"{v.downloaded / 1_000_000f:0.00}/{maxProgress / 1_000_000f:0.00}MB" : $"{v.downloaded / 1_000_000f:0.00}MB"));
                    }
                });
                var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath);
                await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, progress);

                if (cachedResponse.ChangeLog?.Length > 0)
                {
                    fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog));
                }
            }

            taskProgress.ReportFinished();
        }
Exemple #2
0
        public void ReportTaskProgress(ITaskProgress taskProgress)
        {
            var    progress       = taskProgress.GetProgress();
            var    config         = taskProgress.Config;
            string key            = config.Name + " " + config.Strategy.Type.Provider;
            bool   reportProgress = true;

            if (_progressTasks.ContainsKey(taskProgress))
            {
                progress      += _progressTasks[taskProgress];
                reportProgress = progress > _progressTasks[taskProgress];
            }

            _progressTasks[taskProgress] = progress;
            if (reportProgress && progress <= 1)
            {
                var percent = (int)(progress * 100.0);
                var r       = new[] { "|", "/", "-", "\\" };
                var x       = r[DateTime.Now.Second % 4];
                WriteProgressAsync(
                    new ProgressRecord(
                        0,
                        "Creating Azure resources",
                        percent + "% " + x)
                {
                    CurrentOperation = !taskProgress.IsDone
                            ? $"Creating resource '{taskProgress.Config.Name}' of type  '{taskProgress.Config?.Strategy?.Type?.Namespace}/{taskProgress.Config?.Strategy?.Type?.Provider}'"
                            : null,
                    PercentComplete = percent,
                });
            }
        }
 private void OnProgressUpdate(ITaskProgress progress)
 {
     Debug.Assert(SynchronizationContext.Current != null);
     MaxValue    = progress.MaxProgress;
     Progress    = progress.CurrentProgress;
     CurrentTask = progress.CurrentTask;
     State       = progress.State;
     ForgetTaskCommand.RaiseCanExecuteChanged();
 }
 public TaskViewModel(TasksViewModel parent, ITask task, ITaskProgress taskProgress)
 {
     this.taskProgress = taskProgress;
     ForgetTaskCommand = new DelegateCommand(() =>
     {
         parent.Tasks.Remove(this);
     }, () => (state == TaskState.FinishedFailed || state == TaskState.FinishedSuccess));
     TaskName = task.Name;
     OnProgressUpdate(taskProgress);
     taskProgress.Updated += OnProgressUpdate;
 }
        public async Task DownloadLatestVersion(ITaskProgress taskProgress)
        {
            cachedResponse ??= await InternalCheckForUpdates();

            if (cachedResponse != null)
            {
                var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath);
                await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, taskProgress.ToProgress());

                if (cachedResponse.ChangeLog?.Length > 0)
                {
                    fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog));
                }
            }

            taskProgress.ReportFinished();
        }
            public async Task Run(ITaskProgress progress)
            {
                int steps = 6;

                progress.Report(0, steps, "Loading creatures");
                cache.creatureTemplateCache = await cache.nonCachedDatabase.GetCreatureTemplatesAsync();

                progress.Report(1, steps, "Loading gameobjects");
                cache.gameObjectTemplateCache = await cache.nonCachedDatabase.GetGameObjectTemplatesAsync();

                progress.Report(2, steps, "Loading game events");
                cache.gameEventsCache = await cache.nonCachedDatabase.GetGameEventsAsync();

                progress.Report(3, steps, "Loading areatrigger templates");
                cache.areaTriggerTemplates = await cache.nonCachedDatabase.GetAreaTriggerTemplatesAsync();

                progress.Report(4, steps, "Loading conversation templates");
                cache.conversationTemplates = await cache.nonCachedDatabase.GetConversationTemplatesAsync();

                progress.Report(5, steps, "Loading quests");

                cache.questTemplateCache = await cache.nonCachedDatabase.GetQuestTemplatesAsync();

                Dictionary <uint, ICreatureTemplate>   creatureTemplateByEntry   = new();
                Dictionary <uint, IGameObjectTemplate> gameObjectTemplateByEntry = new();
                Dictionary <uint, IQuestTemplate>      questTemplateByEntry      = new();

                foreach (var entity in cache.creatureTemplateCache)
                {
                    creatureTemplateByEntry[entity.Entry] = entity;
                }

                foreach (var entity in cache.gameObjectTemplateCache)
                {
                    gameObjectTemplateByEntry[entity.Entry] = entity;
                }

                foreach (var entity in cache.questTemplateCache)
                {
                    questTemplateByEntry[entity.Entry] = entity;
                }

                cache.creatureTemplateByEntry   = creatureTemplateByEntry;
                cache.gameObjectTemplateByEntry = gameObjectTemplateByEntry;
                cache.questTemplateByEntry      = questTemplateByEntry;
            }
        public static Progress <(long, long?)> ToProgress(this ITaskProgress taskProgress)
        {
            return(new Progress <(long downloaded, long?totalBytes)>((v) =>
            {
                var isDownloaded = (v.totalBytes.HasValue && v.totalBytes.Value == v.downloaded) ||
                                   v.downloaded == -1;
                var isStatusKnown = v.totalBytes.HasValue;
                var currentProgress = v.totalBytes.HasValue ? (int)v.downloaded : (v.downloaded < 0 ? 1 : 0);
                var maxProgress = v.totalBytes ?? 1;

                if (taskProgress.State == TaskState.InProgress)
                {
                    taskProgress.Report(currentProgress, (int)maxProgress, isDownloaded ?
                                        "finished" :
                                        (isStatusKnown ? $"{v.downloaded / 1_000_000f:0.00}/{maxProgress / 1_000_000f:0.00}MB" : $"{v.downloaded / 1_000_000f:0.00}MB"));
                }
            }));
        }
Exemple #8
0
        private async Task DownloadUpdateTask(ITaskProgress taskProgress)
        {
            try
            {
                if (!await updateService.DownloadLatestVersion(taskProgress))
                {
                    statusBar.PublishNotification(new PlainNotification(NotificationType.Warning,
                                                                        "Failed to download the update, update file got corrupted. Please try later."));
                    return;
                }
                statusBar.PublishNotification(new PlainNotification(NotificationType.Info,
                                                                    "Update ready to install. It will be installed on the next editor restart or when you click here",
                                                                    new AsyncAutoCommand(async() =>
                {
                    if (platformService.PlatformSupportsSelfInstall)
                    {
                        await updateService.CloseForUpdate();
                    }
                    else
                    {
                        await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                           .SetTitle("Your platform doesn't support self updates")
                                                           .SetContent("Sadly, self updater is not available on your operating system yet.\n\nA new version of WoW Database Editor has been downloaded, but you have to manually copy new version to the Applications folder")
                                                           .Build());
                        var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath);

                        using Process open = new Process
                              {
                                  StartInfo =
                                  {
                                      FileName        = "open",
                                      Arguments       = "-R " + physPath.FullName,
                                      UseShellExecute = true
                                  }
                              };
                        open.Start();
                    }
                })));
            }
            catch (Exception e)
            {
                statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while checking for the updates: " + e.Message));
            }
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskHandle"/> class.
        /// </summary>
        public TaskHandle(ITaskProgress progress, CancellationToken cancellationToken, WaitHandle pauseHandle,
                          IGlobalListener callback)
        {
            if (progress == null)
            {
                throw new ArgumentNullException("progress");
            }
            if (pauseHandle == null)
            {
                throw new ArgumentNullException("pauseHandle");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            Callback           = callback;
            PauseHandle        = pauseHandle;
            Progress           = progress;
            _cancellationToken = cancellationToken;
        }
Exemple #10
0
        public async Task <bool> DownloadLatestVersion(ITaskProgress taskProgress)
        {
            cachedResponse ??= await InternalCheckForUpdates();

            if (cachedResponse != null)
            {
                var  physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath);
                bool success  = false;
                int  trial    = 0;
                do
                {
                    trial++;
                    success = true;
                    await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, taskProgress.ToProgress());

                    if (!string.IsNullOrEmpty(cachedResponse.DownloadMd5))
                    {
                        success = await updateVerifier.IsUpdateValid((FileInfo)physPath, cachedResponse.DownloadMd5);
                    }
                } while (!success && trial < 3);

                if (!success)
                {
                    physPath.Delete();
                    taskProgress.ReportFinished();
                    return(false);
                }

                if (cachedResponse.ChangeLog?.Length > 0)
                {
                    fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog));
                }

                taskProgress.ReportFinished();
                return(true);
            }

            taskProgress.ReportFinished();
            return(false);
        }
 public GUIProgressDialogHandler(ITaskProgress handler)
 {
     this.handler = handler;
 }
Exemple #12
0
 public void ReportTaskProgress(ITaskProgress taskProgress)
 => Scheduler.BeginInvoke(() => TaskProgressList.Add(taskProgress));
 public async Task Run(ITaskProgress progress)
 {
     await task(progress);
 }
Exemple #14
0
 public void ReportTaskProgress(ITaskProgress taskProgress)
 {
     throw new NotImplementedException();
 }
            public async Task Run(ITaskProgress progress)
            {
                try
                {
                    int steps = 11;

                    progress.Report(0, steps, "Loading creatures");
                    cache.creatureTemplateCache = await cache.nonCachedDatabase.GetCreatureTemplatesAsync();

                    // disabled caching for now, because it may be not needed yet
                    // cache.creatureCache = await cache.nonCachedDatabase.GetCreaturesAsync();
                    // cache.gameObjectCache = await cache.nonCachedDatabase.GetGameObjectsAsync();

                    progress.Report(1, steps, "Loading gameobjects");
                    cache.gameObjectTemplateCache = await cache.nonCachedDatabase.GetGameObjectTemplatesAsync();

                    progress.Report(2, steps, "Loading game events");
                    cache.gameEventsCache = await cache.nonCachedDatabase.GetGameEventsAsync();

                    progress.Report(3, steps, "Loading areatrigger templates");
                    cache.areaTriggerTemplates = await cache.nonCachedDatabase.GetAreaTriggerTemplatesAsync();

                    progress.Report(4, steps, "Loading conversation templates");
                    cache.conversationTemplates = await cache.nonCachedDatabase.GetConversationTemplatesAsync();

                    progress.Report(5, steps, "Loading gossip menus");
                    cache.gossipMenusCache = await cache.nonCachedDatabase.GetGossipMenusAsync();

                    progress.Report(6, steps, "Loading npc texts");
                    cache.npcTextsCache = await cache.nonCachedDatabase.GetNpcTextsAsync();

                    cache.npcTextsByIdCache = cache.npcTextsCache.ToDictionary(npcText => npcText.Id);

                    progress.Report(7, steps, "Loading quests");
                    cache.questTemplateCache = await cache.nonCachedDatabase.GetQuestTemplatesAsync();

                    progress.Report(8, steps, "Loading creature class level stats");
                    cache.creatureClassLevelStatsCache =
                        await cache.nonCachedDatabase.GetCreatureClassLevelStatsAsync();

                    progress.Report(9, steps, "Loading database spell dbc");
                    cache.databaseSpellDbcCache = await cache.nonCachedDatabase.GetSpellDbcAsync();

                    progress.Report(10, steps, "Loading broadcast texts");
                    // todo: is there any benefit of caching this?

                    /*var broadcastTexts = await cache.nonCachedDatabase.GetBroadcastTextsAsync();
                     * var cachedTrie = new StringTrie<IBroadcastText>();
                     * await Task.Run(() =>
                     * {
                     *  foreach (var text in broadcastTexts)
                     *  {
                     *      if (text.Text != null)
                     *          cachedTrie[text.Text] = text;
                     *      if (text.Text1 != null)
                     *          cachedTrie[text.Text1] = text;
                     *  }
                     * }).ConfigureAwait(true);
                     * cache.broadcastTextsCache = cachedTrie;*/

                    Dictionary <uint, ICreatureTemplate>   creatureTemplateByEntry   = new();
                    Dictionary <uint, IGameObjectTemplate> gameObjectTemplateByEntry = new();
                    Dictionary <uint, IQuestTemplate>      questTemplateByEntry      = new();

                    foreach (var entity in cache.creatureTemplateCache)
                    {
                        creatureTemplateByEntry[entity.Entry] = entity;
                    }

                    foreach (var entity in cache.gameObjectTemplateCache)
                    {
                        gameObjectTemplateByEntry[entity.Entry] = entity;
                    }

                    foreach (var entity in cache.questTemplateCache)
                    {
                        questTemplateByEntry[entity.Entry] = entity;
                    }

                    cache.creatureTemplateByEntry   = creatureTemplateByEntry;
                    cache.gameObjectTemplateByEntry = gameObjectTemplateByEntry;
                    cache.questTemplateByEntry      = questTemplateByEntry;
                }
                catch (Exception e)
                {
                    cache.nonCachedDatabase = new NullWorldDatabaseProvider();
                    cache.statusBar.PublishNotification(new PlainNotification(NotificationType.Error,
                                                                              $"Error while connecting to the database. Make sure you have correct core version in the settings: {e.Message}"));
                    throw;
                }
                finally
                {
                    cache.loadingEventAggregator.Publish <DatabaseLoadedEvent>();
                }
            }
Exemple #16
0
 public Conf_ProgressDialog(ITaskProgress handler)
 {
     InitializeComponent();
     this.handler     = handler;
     statusLabel.Text = "";
 }
Exemple #17
0
            public async Task Run(ITaskProgress progress)
            {
                try
                {
                    int steps = 9;

                    progress.Report(0, steps, "Loading creatures");
                    cache.creatureTemplateCache = await cache.nonCachedDatabase.GetCreatureTemplatesAsync();

                    progress.Report(1, steps, "Loading gameobjects");
                    cache.gameObjectTemplateCache = await cache.nonCachedDatabase.GetGameObjectTemplatesAsync();

                    progress.Report(2, steps, "Loading game events");
                    cache.gameEventsCache = await cache.nonCachedDatabase.GetGameEventsAsync();

                    progress.Report(3, steps, "Loading areatrigger templates");
                    cache.areaTriggerTemplates = await cache.nonCachedDatabase.GetAreaTriggerTemplatesAsync();

                    progress.Report(4, steps, "Loading conversation templates");
                    cache.conversationTemplates = await cache.nonCachedDatabase.GetConversationTemplatesAsync();

                    progress.Report(5, steps, "Loading gossip menus");
                    cache.gossipMenusCache = await cache.nonCachedDatabase.GetGossipMenusAsync();

                    progress.Report(6, steps, "Loading npc texts");
                    cache.npcTextsCache = await cache.nonCachedDatabase.GetNpcTextsAsync();

                    progress.Report(7, steps, "Loading quests");
                    cache.questTemplateCache = await cache.nonCachedDatabase.GetQuestTemplatesAsync();

                    progress.Report(8, steps, "Loading creature class level stats");
                    cache.creatureClassLevelStatsCache =
                        await cache.nonCachedDatabase.GetCreatureClassLevelStatsAsync();

                    Dictionary <uint, ICreatureTemplate>   creatureTemplateByEntry   = new();
                    Dictionary <uint, IGameObjectTemplate> gameObjectTemplateByEntry = new();
                    Dictionary <uint, IQuestTemplate>      questTemplateByEntry      = new();

                    foreach (var entity in cache.creatureTemplateCache)
                    {
                        creatureTemplateByEntry[entity.Entry] = entity;
                    }

                    foreach (var entity in cache.gameObjectTemplateCache)
                    {
                        gameObjectTemplateByEntry[entity.Entry] = entity;
                    }

                    foreach (var entity in cache.questTemplateCache)
                    {
                        questTemplateByEntry[entity.Entry] = entity;
                    }

                    cache.creatureTemplateByEntry   = creatureTemplateByEntry;
                    cache.gameObjectTemplateByEntry = gameObjectTemplateByEntry;
                    cache.questTemplateByEntry      = questTemplateByEntry;
                }
                catch (Exception e)
                {
                    cache.statusBar.PublishNotification(new PlainNotification(NotificationType.Error, $"Error while connecting to the database. Make sure you have correct core version in the settings: {e.Message}"));
                    throw;
                }
            }
Exemple #18
0
 public static void SetTaskProgress(ITaskProgress taskProgress)
 {
     m_TaskProgress = taskProgress;
 }