コード例 #1
0
        /// <summary>
        /// Tries to log the user in with the given credentials.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The <see cref="PasswordBox"/> containing the password.</param>
        public async Task Login(string username, PasswordBox password)
        {
            try
            {
                EnableControls = false;
                var response = await _lastAuth.GetSessionTokenAsync(username, password.Password);

                if (response.Success && _lastAuth.Authenticated)
                {
                    _messageBoxService.ShowDialog("Successfully logged in and authenticated!");
                    TryClose(true);
                }
                else
                {
                    _messageBoxService.ShowDialog("Failed to log in or authenticate!");
                }
            }
            catch (Exception ex)
            {
                _messageBoxService.ShowDialog("Fatal error while trying to log in: " + ex.Message);
            }
            finally
            {
                EnableControls = true;
            }
        }
コード例 #2
0
        public async Task SaveCurrent()
        {
            if (!SessionService.IsOpened)
            {
                return;
            }

            var fileName = await windowManager.ShowSaveFileDialog("Sql file|sql", SessionService.CurrentSession !.Name + ".sql");

            if (!string.IsNullOrEmpty(fileName))
            {
                SessionService.Finalize(fileName);

                if (SessionService.DeleteOnSave == false)
                {
                    return;
                }

                if (SessionService.DeleteOnSave == true ||
                    await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                       .SetIcon(MessageBoxIcon.Information)
                                                       .SetTitle("Removing session")
                                                       .SetMainInstruction("Do you want to forget current session?")
                                                       .SetContent(
                                                           "Do you want to delete recently saved session?\n\nTip: You can configure in the settings if you always/never want to forget the session")
                                                       .WithYesButton(true)
                                                       .WithNoButton(false)
                                                       .Build()))
                {
                    SessionService.ForgetCurrent();
                }
            }
        }
コード例 #3
0
        private async Task LoadSniff()
        {
            LoadingInProgress   = true;
            FilteringInProgress = true;

            AssertNoOnGoingTask();
            currentActionToken = new CancellationTokenSource();

            try
            {
                var packets = await sniffLoader.LoadSniff(solutionItem.File, currentActionToken.Token, this);

                if (currentActionToken.IsCancellationRequested)
                {
                    LoadingInProgress  = false;
                    currentActionToken = null;
                    return;
                }

                using (AllPackets.SuspendNotifications())
                {
                    foreach (var packet in packets.Packets_)
                    {
                        AllPackets.Add(packetViewModelCreator.Process(packet) !);
                    }
                }
            }
            catch (ParserException e)
            {
                await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                   .SetIcon(MessageBoxIcon.Error)
                                                   .SetTitle("Error with parser")
                                                   .SetMainInstruction("Parser error")
                                                   .SetContent(e.Message)
                                                   .WithOkButton(false)
                                                   .Build());

                if (CloseCommand != null)
                {
                    await CloseCommand.ExecuteAsync();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            FilteringProgress = -1;
            await SplitPacketsIfNeededAsync().ConfigureAwait(true);

            LoadingInProgress   = false;
            FilteringInProgress = false;
            currentActionToken  = null;
            await ApplyFilterCommand.ExecuteAsync();
        }
コード例 #4
0
    private async Task AskIfSave(bool cancel)
    {
        if (baseViewModel.IsModified)
        {
            var result = await messageBoxService.ShowDialog(new MessageBoxFactory <int>()
                                                            .SetTitle("Save changes")
                                                            .SetMainInstruction($"{Title} has unsaved changes")
                                                            .SetContent("Do you want to save them before picking the row?")
                                                            .WithNoButton(1)
                                                            .WithYesButton(2)
                                                            .WithCancelButton(0)
                                                            .Build());

            if (result == 0)
            {
                return;
            }
            if (result == 2)
            {
                ExecuteChangedCommand.Execute(null);
            }
        }
        if (cancel)
        {
            CloseCancel?.Invoke();
        }
        else
        {
            CloseOk?.Invoke();
        }
    }
コード例 #5
0
        public CurrentCoreVersionService(IEnumerable <ICoreVersion> coreVersions,
                                         ICurrentCoreSettings settings,
                                         IMessageBoxService messageBoxService)
        {
            this.settings = settings;
            AllVersions   = coreVersions.ToList();
            Current       = AllVersions.First();

            var savedVersion = settings.CurrentCore;

            if (savedVersion != null)
            {
                var found = AllVersions.FirstOrDefault(v => v.Tag == savedVersion);
                if (found != null)
                {
                    Current = found;
                }
                else
                {
                    messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetIcon(MessageBoxIcon.Error)
                                                 .SetTitle("Error while loading core version")
                                                 .SetMainInstruction("Unknown core version")
                                                 .SetContent($"You have set core version to {savedVersion} in settings, however such core is not found in modules. Switching back to default: {Current.FriendlyName}")
                                                 .WithOkButton(true)
                                                 .Build());
                    UpdateCurrentVersion(Current);
                }
            }
            else
            {
                UpdateCurrentVersion(Current);
            }
        }
コード例 #6
0
        private void SubmitCrowdRename(object state)
        {
            if (this.OriginalName != null)
            {
                string updatedName = Helper.GetTextFromControlObject(state);


                bool duplicateName = false;
                if (updatedName != this.OriginalName)
                {
                    duplicateName = charExpVM.CrowdCollection.ContainsKey(updatedName);
                }

                if (!duplicateName)
                {
                    RenameCrowd(updatedName);
                    OnEditModeLeave(state, null);
                }
                else
                {
                    messageBoxService.ShowDialog(Messages.DUPLICATE_NAME_MESSAGE, Messages.DUPLICATE_NAME_CAPTION, MessageBoxButton.OK, MessageBoxImage.Error);
                    this.CancelEditMode(state);
                }
            }
        }
コード例 #7
0
 public DatabaseProvider(CachedDatabaseProvider cachedDatabase,
                         NullDatabaseProvider nullDatabaseProvider,
                         IConnectionSettingsProvider settings,
                         IMessageBoxService messageBoxService)
 {
     if (settings.GetSettings().IsEmpty)
     {
         impl = nullDatabaseProvider;
     }
     else
     {
         try
         {
             cachedDatabase.TryConnect();
             impl = cachedDatabase;
         }
         catch (Exception e)
         {
             impl = nullDatabaseProvider;
             messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Database error")
                                          .SetIcon(MessageBoxIcon.Error)
                                          .SetMainInstruction("Couldn't connect to the database")
                                          .SetContent(e.Message)
                                          .WithOkButton(true)
                                          .Build());
         }
     }
 }
コード例 #8
0
        private async Task SaveDataToFile()
        {
            string infoSourceName = "";

            switch (dataSourceMode)
            {
            case SmartDataSourceMode.SD_SOURCE_EVENTS:
                await smartDataProvider.SaveEvents(DefinesItems.ToList());

                smartDataManager.Reload(SmartType.SmartEvent);
                infoSourceName = "Events";
                break;

            case SmartDataSourceMode.SD_SOURCE_ACTIONS:
                await smartDataProvider.SaveActions(DefinesItems.ToList());

                smartDataManager.Reload(SmartType.SmartAction);
                infoSourceName = "Actions";
                break;

            case SmartDataSourceMode.SD_SOURCE_TARGETS:
                await smartDataProvider.SaveTargets(DefinesItems.ToList());

                smartDataManager.Reload(SmartType.SmartTarget);
                infoSourceName = "Targets";
                break;
            }
            History.MarkAsSaved();
            messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Success!")
                                         .SetMainInstruction($"Editor successfully saved definitions of Smart {infoSourceName}! Also remember to modify SmartData Group file via Editor if you modified list!")
                                         .SetIcon(MessageBoxIcon.Information)
                                         .WithOkButton(true)
                                         .Build());
        }
コード例 #9
0
        protected async Task <bool> InternalLoadData()
        {
            if (!await BeforeLoadData())
            {
                IsLoading = false;
                return(false);
            }
            var data = await LoadData();

            if (data == null)
            {
                await messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Error!")
                                                   .SetMainInstruction($"Editor failed to load data from database!")
                                                   .SetIcon(MessageBoxIcon.Error)
                                                   .WithOkButton(true)
                                                   .Build());

                IsLoading = false;
                return(false);
            }

            solutionItem.UpdateEntitiesWithOriginalValues(data.Entities);

            Entities.RemoveAll();
            await InternalLoadData(data);

            IsLoading = false;
            return(true);
        }
コード例 #10
0
        public WorldDatabaseProvider(DatabaseResolver databaseResolver,
                                     NullWorldDatabaseProvider nullWorldDatabaseProvider,
                                     IWorldDatabaseSettingsProvider settingsProvider,
                                     IMessageBoxService messageBoxService,
                                     ILoadingEventAggregator loadingEventAggregator,
                                     IEventAggregator eventAggregator,
                                     IContainerProvider containerProvider) : base(nullWorldDatabaseProvider)
        {
            if (settingsProvider.Settings.IsEmpty)
            {
                eventAggregator.GetEvent <AllModulesLoaded>().Subscribe(loadingEventAggregator.Publish <DatabaseLoadedEvent>, true);
                return;
            }

            try
            {
                var cachedDatabase = containerProvider.Resolve <CachedDatabaseProvider>((typeof(IAsyncDatabaseProvider), databaseResolver.ResolveWorld()));
                cachedDatabase.TryConnect();
                impl = cachedDatabase;
            }
            catch (Exception e)
            {
                impl = nullWorldDatabaseProvider;
                messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Database error")
                                             .SetIcon(MessageBoxIcon.Error)
                                             .SetMainInstruction("Couldn't connect to the database")
                                             .SetContent(e.Message)
                                             .WithOkButton(true)
                                             .Build());
            }
        }
コード例 #11
0
        public AuthDatabaseProvider(TrinityMySqlDatabaseProvider trinityDatabase,
                                    NullAuthDatabaseProvider nullAuthDatabaseProvider,
                                    IAuthDatabaseSettingsProvider settingsProvider,
                                    IMessageBoxService messageBoxService
                                    ) : base(nullAuthDatabaseProvider)
        {
            if (settingsProvider.Settings.IsEmpty)
            {
                return;
            }

            try
            {
                using var db = new TrinityAuthDatabase();
                if (db.Connection.State != ConnectionState.Open)
                {
                    db.Connection.Open();
                    db.Connection.Close();
                }
                impl = trinityDatabase;
            }
            catch (Exception e)
            {
                impl = nullAuthDatabaseProvider;
                messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Database error")
                                             .SetIcon(MessageBoxIcon.Error)
                                             .SetMainInstruction("Couldn't connect to the auth database")
                                             .SetContent(e.Message)
                                             .WithOkButton(true)
                                             .Build());
            }
        }
コード例 #12
0
        public DatabaseProvider(TrinityMySqlDatabaseProvider trinityDatabase,
                                NullDatabaseProvider nullDatabaseProvider,
                                IDatabaseSettingsProvider settingsProvider,
                                IMessageBoxService messageBoxService,
                                ITaskRunner taskRunner) : base(nullDatabaseProvider)
        {
            if (settingsProvider.Settings.IsEmpty)
            {
                return;
            }

            try
            {
                var cachedDatabase = new CachedDatabaseProvider(trinityDatabase, taskRunner);
                cachedDatabase.TryConnect();
                impl = cachedDatabase;
            }
            catch (Exception e)
            {
                impl = nullDatabaseProvider;
                messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Database error")
                                             .SetIcon(MessageBoxIcon.Error)
                                             .SetMainInstruction("Couldn't connect to the database")
                                             .SetContent(e.Message)
                                             .WithOkButton(true)
                                             .Build());
            }
        }
コード例 #13
0
        protected override void OnInitialized()
        {
            var loadedModules = Container.Resolve <IEnumerable <ModuleBase> >();

            foreach (var module in loadedModules)
            {
                module.FinalizeRegistration((IContainerRegistry)Container);
            }

            IMessageBoxService messageBoxService = Container.Resolve <IMessageBoxService>();
            IClipboardService  clipboardService  = Container.Resolve <IClipboardService>();

            ViewBind.AppViewLocator = Container.Resolve <IViewLocator>();
            // have no idea if it makes sense, but works
            MainWindow?mainWindow = Container.Resolve <MainWindow>();

            mainWindow.DataContext = Container.Resolve <MainWindowViewModel>();

            IEventAggregator?eventAggregator = Container.Resolve <IEventAggregator>();

            eventAggregator.GetEvent <AllModulesLoaded>().Publish();

            mainWindow.ContentRendered += MainWindowOnContentRendered;

            #if DEBUG
            mainWindow.ShowDialog();
            #else
            try
            {
                mainWindow.ShowDialog();
            }
            catch (Exception e)
            {
                var deploymentVersion = File.Exists("app.ini") ? File.ReadAllText("app.ini") : "unknown app data";
                Console.WriteLine(e.ToString());
                var logPath = Path.GetTempFileName() + ".WDE.log.txt";
                File.WriteAllText(logPath, deploymentVersion + "\n\n" + e.ToString());

                var choice = messageBoxService.ShowDialog(new MessageBoxFactory <int>().SetIcon(MessageBoxIcon.Error)
                                                          .SetTitle("Fatal error")
                                                          .SetMainInstruction("Sorry, fatal error has occured and the program had to stop")
                                                          .SetContent("You are welcome to report the bug at github. Reason: " + e.Message)
                                                          .SetFooter("Log file saved at: " + logPath)
                                                          .WithButton("Copy log path to clipboard", 2)
                                                          .WithButton("Open log file", 1)
                                                          .WithButton("Close", 0)
                                                          .Build()).Result; // in WPF in fact this is sync, so this is legal
                if (choice == 2)
                {
                    clipboardService.SetText(logPath);
                }
                else if (choice == 1)
                {
                    Process.Start("explorer", logPath);
                }
            }
            #endif

            Current.Shutdown();
        }
コード例 #14
0
        private void OpenNameEditingWindow(string source, out string name)
        {
            var vm = new SmartDataGroupsInputViewModel(source);

            name = "";
            if (windowManager.ShowDialog(vm))
            {
                if (!string.IsNullOrWhiteSpace(vm.Name))
                {
                    name = vm.Name;
                }
                else
                {
                    messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Error!")
                                                 .SetMainInstruction($"Group name cannot be empty!")
                                                 .SetIcon(MessageBoxIcon.Error)
                                                 .WithOkButton(true)
                                                 .Build());
                }
            }
        }
コード例 #15
0
        private async Task UpdatesCheck()
        {
            try
            {
                string?newUpdateUrl = await updateService.CheckForUpdates();

                if (newUpdateUrl != null)
                {
                    if (settingsProvider.Settings.EnableSilentUpdates)
                    {
                        DownloadUpdate();
                        statusBar.PublishNotification(new PlainNotification(NotificationType.Info, "Downloading update..."));
                    }
                    else
                    {
                        if (await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                               .SetTitle("New update")
                                                               .SetMainInstruction("A new update is ready to be downloaded")
                                                               .SetContent("Do you want to download the update now?")
                                                               .WithYesButton(true)
                                                               .WithNoButton(false)
                                                               .SetIcon(MessageBoxIcon.Information)
                                                               .Build()))
                        {
                            DownloadUpdate();
                        }
                        else
                        {
                            statusBar.PublishNotification(new PlainNotification(NotificationType.Info,
                                                                                "New updates are ready to download. Click to download.",
                                                                                new DelegateCommand(DownloadUpdate)));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while checking for the updates: " + e.Message));
            }
        }
コード例 #16
0
ファイル: App.xaml.cs プロジェクト: BenjiAU/WoWDatabaseEditor
        protected override void OnInitialized()
        {
            IMessageBoxService messageBoxService = Container.Resolve <IMessageBoxService>();
            IClipboardService  clipboardService  = Container.Resolve <IClipboardService>();

            ViewBind.AppViewLocator = Container.Resolve <IViewLocator>();
            // have no idea if it makes sense, but works
            MainWindow?mainWindow = Container.Resolve <MainWindow>();

            IEventAggregator?eventAggregator = Container.Resolve <IEventAggregator>();

            eventAggregator.GetEvent <AllModulesLoaded>().Publish();

            mainWindow.ContentRendered += MainWindowOnContentRendered;

            #if DEBUG
            mainWindow.ShowDialog();
            #else
            try
            {
                mainWindow.ShowDialog();
            }
            catch (Exception e)
            {
                var commitHash = File.Exists("COMMIT_HASH") ? File.ReadAllText("COMMIT_HASH") : "unknown";
                Console.WriteLine(e.ToString());
                var logPath = Path.GetTempFileName() + ".WDE.log.txt";
                File.WriteAllText(logPath, "Commit: " + commitHash + "\n\n" + e.ToString());

                var choice = messageBoxService.ShowDialog(new MessageBoxFactory <int>().SetIcon(MessageBoxIcon.Error)
                                                          .SetTitle("Fatal error")
                                                          .SetMainInstruction("Sorry, fatal error has occured and the program had to stop")
                                                          .SetContent("You are welcome to report the bug at github. Reason: " + e.Message)
                                                          .SetFooter("Log file saved at: " + logPath)
                                                          .WithButton("Copy log path to clipboard", 2)
                                                          .WithButton("Open log file", 1)
                                                          .WithButton("Close", 0)
                                                          .Build());
                if (choice == 2)
                {
                    clipboardService.SetText(logPath);
                }
                else if (choice == 1)
                {
                    Process.Start("explorer", logPath);
                }
            }
            #endif

            Current.Shutdown();
        }
コード例 #17
0
    private async Task <bool> CheckIfItemIsOpened(DatabaseTableSolutionItem fakeSolutionItem,
                                                  DatabaseTableDefinitionJson definition)
    {
        bool openIsNoSaveMode = false;

        if (IsItemAlreadyOpened(fakeSolutionItem, out var openedDocument))
        {
            var result = await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                            .SetTitle("Document is already opened")
                                                            .SetMainInstruction($"{definition.Id} is already opened")
                                                            .SetContent(
                                                                "This table is already being edited and you have an active session.\n Editing the same table in a new window would cause a session data loss.\n\nTherefore you can either close the current document or open the table without save feature enabled (you can still generate sql).")
                                                            .WithButton("Close document", true)
                                                            .WithButton("Open table without save", false)
                                                            .Build());

            if (result)
            {
                await openedDocument.CloseCommand !.ExecuteAsync();
                openIsNoSaveMode = documentManager.Value.OpenedDocuments.Contains(openedDocument);
                if (openIsNoSaveMode)
                {
                    await messageBoxService.ShowDialog(new MessageBoxFactory <Unit>()
                                                       .SetTitle("Document is still opened")
                                                       .SetMainInstruction("Document is still opened")
                                                       .SetContent("You didn't close the document. Opening the table without the save feature.")
                                                       .Build());
                }
            }
            else
            {
                openIsNoSaveMode = true;
            }
        }

        return(openIsNoSaveMode);
    }
コード例 #18
0
        public async Task <ISolutionItem?> CreateSolutionItem()
        {
            var parameter = parameterFactory.Factory(definition.Picker);
            var key       = await itemFromListProvider.GetItemFromList(parameter.HasItems?parameter.Items !: new Dictionary <long, SelectOption>(), false);

            if (key.HasValue)
            {
                var data = await tableDataProvider.Load(definition.Id, (uint)key.Value);

                if (data == null)
                {
                    return(null);
                }

                if (data.TableDefinition.IsMultiRecord)
                {
                    return(new DatabaseTableSolutionItem((uint)key.Value, false, definition.Id));
                }
                else
                {
                    if (data.Entities.Count == 0)
                    {
                        return(null);
                    }

                    if (!data.Entities[0].ExistInDatabase)
                    {
                        if (!await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                                .SetTitle("Entity doesn't exist in database")
                                                                .SetMainInstruction($"Entity {data.Entities[0].Key} doesn't exist in the database")
                                                                .SetContent(
                                                                    "WoW Database Editor will be generating DELETE/INSERT query instead of UPDATE. Do you want to continue?")
                                                                .WithYesButton(true)
                                                                .WithNoButton(false).Build()))
                        {
                            return(null);
                        }
                    }
                    return(new DatabaseTableSolutionItem(data.Entities[0].Key, data.Entities[0].ExistInDatabase, definition.Id));
                }
            }

            return(null);
        }
 private void SubmitRename(object state)
 {
     if (this.OriginalName != null)
     {
         string updatedName   = Helper.GetTextFromControlObject(state);
         bool   duplicateName = CheckDuplicateName(updatedName);
         if (!duplicateName)
         {
             RenameOptionGroup(updatedName);
             OnEditModeLeave(state, null);
             this.SaveOptionGroup();
         }
         else
         {
             messageBoxService.ShowDialog(Messages.DUPLICATE_NAME_MESSAGE, Messages.DUPLICATE_NAME_CAPTION, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
             this.CancelEditMode(state);
         }
     }
 }
コード例 #20
0
 private bool TryOpenMpq(out IMpqArchive m)
 {
     try
     {
         m = mpqService.Open();
         return(true);
     }
     catch (Exception e)
     {
         messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                      .SetTitle("Invalid MPQ")
                                      .SetMainInstruction("Couldn't parse game MPQ.")
                                      .SetContent(e.Message + "\n\nAre you using modified game files?")
                                      .WithButton("Ok", false)
                                      .Build());
         m = null;
         return(false);
     }
 }
コード例 #21
0
        private async Task <string?> OpenNameEditingWindow(string source)
        {
            var vm = new ConditionGroupsInputViewModel(source);

            if (await windowManager.ShowDialog(vm))
            {
                if (!string.IsNullOrWhiteSpace(vm.Name))
                {
                    return(vm.Name);
                }
                else
                {
                    await messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Error!")
                                                       .SetMainInstruction($"Group name cannot be empty!")
                                                       .SetIcon(MessageBoxIcon.Error)
                                                       .WithOkButton(true)
                                                       .Build());
                }
            }
            return(null);
        }
コード例 #22
0
        private async Task DownloadUpdateTask(ITaskProgress taskProgress)
        {
            try
            {
                await updateService.DownloadLatestVersion(taskProgress);

                statusBar.PublishNotification(new PlainNotification(NotificationType.Info,
                                                                    "Update ready to install. Click here to install",
                                                                    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));
            }
        }
コード例 #23
0
        private async Task LoadTableDefinition()
        {
            var data = await databaseTableDataProvider.Load(solutionItem.DefinitionId, solutionItem.Entries.Select(e => e.Key).ToArray()) as DatabaseTableData;

            if (data == null)
            {
                await messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Error!")
                                                   .SetMainInstruction($"Editor failed to load data from database!")
                                                   .SetIcon(MessageBoxIcon.Error)
                                                   .WithOkButton(true)
                                                   .Build());

                return;
            }

            solutionItem.UpdateEntitiesWithOriginalValues(data.Entities);

            Entities.Clear();
            await InternalLoadData(data);

            IsLoading = false;
        }
コード例 #24
0
    public async Task <ISolutionItem?> Create(DatabaseTableDefinitionJson definition, DatabaseKey key)
    {
        if (definition.RecordMode == RecordMode.MultiRecord)
        {
            return(new DatabaseTableSolutionItem(key, false, definition.Id, definition.IgnoreEquality));
        }
        if (definition.RecordMode == RecordMode.SingleRow)
        {
            return(new DatabaseTableSolutionItem(definition.Id, definition.IgnoreEquality));
        }
        else
        {
            var data = await tableDataProvider.Load(definition.Id, null, null, null, new [] { key });

            if (data == null)
            {
                return(null);
            }
            if (data.Entities.Count == 0)
            {
                return(null);
            }

            if (!data.Entities[0].ExistInDatabase)
            {
                if (!await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                        .SetTitle("Entity doesn't exist in database")
                                                        .SetMainInstruction($"Entity {data.Entities[0].Key} doesn't exist in the database")
                                                        .SetContent(
                                                            "WoW Database Editor will be generating DELETE/INSERT query instead of UPDATE. Do you want to continue?")
                                                        .WithYesButton(true)
                                                        .WithNoButton(false).Build()))
                {
                    return(null);
                }
            }
            return(new DatabaseTableSolutionItem(data.Entities[0].Key, data.Entities[0].ExistInDatabase, definition.Id, definition.IgnoreEquality));
        }
    }
コード例 #25
0
        public static async Task WrapError(this IMessageBoxService service, Func <Task> task)
        {
            try
            {
                await task();
            }
            catch (Exception e)
            {
                var msg = e.Message;
                if (e.InnerException != null)
                {
                    msg += "\n\n --> " + e.InnerException.Message;
                }

                await service.ShowDialog(new MessageBoxFactory <bool>()
                                         .SetTitle("Error")
                                         .SetMainInstruction("Error while executing the task")
                                         .SetContent(msg)
                                         .WithOkButton(true)
                                         .Build());
            }
        }
コード例 #26
0
        public ParameterDefinitionProvider(IMessageBoxService service)
        {
            var allParameters = new Dictionary <string, ParameterSpecModel>();

            var files = Directory
                        .GetFiles("Parameters/", "*.json", SearchOption.AllDirectories)
                        .OrderBy(t => t, Compare.CreateComparer <string>((a, b) =>
            {
                if (Path.GetFileName(a) == "parameters.json")
                {
                    return(-1);
                }
                return(1);
            })).ToList();

            foreach (var source in files)
            {
                string data = File.ReadAllText(source);
                try {
                    var parameters = JsonConvert.DeserializeObject <Dictionary <string, ParameterSpecModel> >(data);
                    foreach (var keyPair in parameters)
                    {
                        allParameters[keyPair.Key] = keyPair.Value;
                    }
                }
                catch (Exception e)
                {
                    service.ShowDialog(new MessageBoxFactory <bool>()
                                       .SetTitle("Error while loading parameters")
                                       .SetMainInstruction("Parameters file is corrupted")
                                       .SetContent("File " + source +
                                                   " is corrupted, either this is a faulty update or you have made a faulty change.\n\n" + e.Message)
                                       .WithOkButton(true)
                                       .Build()).ListenErrors();
                }
            }

            Parameters = allParameters;
        }
コード例 #27
0
        private bool TryLaunch(string file)
        {
            if (File.Exists(file))
            {
                try
                {
                    Process.Start(file);
                    return(true);
                }
                catch (Exception e)
                {
                    messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                 .SetTitle("Updater")
                                                 .SetMainInstruction("Error while starting the updater")
                                                 .SetContent("While trying to start the updater, following error occured: " + e.Message +
                                                             ".\n\nYou can try to run the Updater.exe (Updater on Linux) manually")
                                                 .WithOkButton(true)
                                                 .Build()).ListenErrors();
                }
            }

            return(false);
        }
コード例 #28
0
        private void SaveAll()
        {
            bool restartRequired = false;

            foreach (var tab in ContainerTabItems)
            {
                if (tab.IsModified)
                {
                    tab.Save.Execute(null);
                    restartRequired |= tab.IsRestartRequired;
                }
            }

            if (restartRequired)
            {
                messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Settings updated")
                                             .SetMainInstruction("Restart is required")
                                             .SetContent("To apply new settings, you have to restart the application")
                                             .SetIcon(MessageBoxIcon.Information)
                                             .WithOkButton(true)
                                             .Build());
            }
        }
コード例 #29
0
        private void SubmitMovementRename(object state)
        {
            if (this.OriginalName != null)
            {
                string updatedName = Helper.GetTextFromControlObject(state);

                bool duplicateName = false;
                if (updatedName != this.OriginalName)
                {
                    duplicateName = this.defaultCharacter.Movements.FirstOrDefault(m => m.Name == updatedName) != null; //this.CurrentCharacterMovement.Character.Movements.ContainsKey(updatedName);
                }
                if (!duplicateName)
                {
                    RenameMovement(updatedName);
                    OnEditModeLeave(state, null);
                    this.SaveMovement(null);
                }
                else
                {
                    messageBoxService.ShowDialog(Messages.DUPLICATE_NAME_MESSAGE, "Rename Movement", MessageBoxButton.OK, MessageBoxImage.Error);
                    this.CancelMovementEditMode(state);
                }
            }
        }
        private void SubmitIdentityRename(object state)
        {
            if (this.OriginalName != null)
            {
                string updatedName = Helper.GetTextFromControlObject(state);

                bool duplicateName = false;
                if (updatedName != this.OriginalName)
                {
                    duplicateName = this.Owner.AvailableIdentities.ContainsKey(updatedName);
                }

                if (!duplicateName)
                {
                    RenameIdentity(updatedName);
                    OnEditModeLeave(state, null);
                }
                else
                {
                    messageBoxService.ShowDialog(Messages.DUPLICATE_NAME_MESSAGE, "Rename Identity", MessageBoxButton.OK, MessageBoxImage.Error);
                    this.CancelEditMode(state);
                }
            }
        }