private IEnumerable <Component> GetComponents()
        {
            var reader           = new ComponentReader();
            var configFilePath   = ConfigFileLocator.GetConfigFilePath();
            var componentsModels = reader.ReadAll(configFilePath);

            return(componentsModels);
        }
Example #2
0
        private bool IsConfigFileWellFormed()
        {
            var configFilePath = ConfigFileLocator.GetConfigFilePath();

            try
            {
                System.Xml.Linq.XDocument configFile = System.Xml.Linq.XDocument.Load(configFilePath);

                return(true);
            }
            catch (System.Xml.XmlException ex)
            {
                var msgService = kernel.Get <IMessageService>();
                msgService.Show(
                    ex.Message,
                    WargameModInstaller.Properties.Resources.ConfigFileErrorHeader,
                    MessageButton.OK,
                    MessageImage.Error);

                LoggerFactory.Create(this.GetType()).Error(ex);

                return(false);
            }
        }
        //Ten async i await przed Task.Run mo¿na wyrzuciæ, ale nie wiem jak to wp³ynie na mozliwosci, ponoæ tak lepiej dla wydajnoœci
        private async Task RunInstallAsync()
        {
            await Task.Run(() =>
            {
                CurrentMessage = WargameModInstaller.Properties.Resources.InstallerInitializing;

                //Czy to powinno byæ w task, czy wy¿ej...
                PathUtilities.CreateDirectoryIfNotExist(InstallLocation);

                var configFilePath = ConfigFileLocator.GetConfigFilePath();

                IEnumerable <ICmdGroup> commandGroups = null;
                if (ComponentsToInstall != null)
                {
                    commandGroups = installCommandsReader.ReadGroups(configFilePath, ComponentsToInstall);
                }
                else
                {
                    commandGroups = installCommandsReader.ReadGroups(configFilePath);
                }
                var commandGroupsExecutors = CreateCommandGroupsExecutors(commandGroups);

                var progressProvidingExecutors = GetProgressProvidingExecutors(commandGroupsExecutors);
                RegisterProgressProviders(progressProvidingExecutors);

                if (isBackupEnabled)
                {
                    //Zapamietac liste dla iteracyjnego restore?
                    var backupTargetsList = commandGroups
                                            .SelectMany(group => group.Commands)
                                            .OfType <IHasTarget>()
                                            .Select(c => c.TargetPath);

                    //The InstallerService takes control over the backup porogress notification.
                    //Tak wogole to total steps powinno byæ obliczone przed rozpoczeciem operacji zwiekszajacych progrss, zeby unikn¹æ skakania paska progressu.
                    TotalSteps     = backupTargetsList.Count();
                    CurrentStep    = 0;
                    CurrentMessage = WargameModInstaller.Properties.Resources.InstallerBackupingFiles;

                    foreach (var backupTarget in backupTargetsList)
                    {
                        var fileToBackupPath = Path.Combine(InstallLocation, backupTarget);
                        if (File.Exists(fileToBackupPath))
                        {
                            backupService.Backup(fileToBackupPath, cancellationTokenSource.Token);
                            backupedFiles.Add(fileToBackupPath);
                        }

                        CurrentStep++;

                        //Check for the cancellation
                        cancellationTokenSource.Token.ThrowIfCancellationRequested();
                    }

                    //From now, if the installation is interrupted, the installer restores backuped files.
                    hasBackupCompleted = true;
                }

                var executionContext = CreateCmdExecutionContext();
                foreach (var executor in commandGroupsExecutors)
                {
                    executor.Execute(executionContext, cancellationTokenSource.Token);

                    //Check for the cancellation
                    cancellationTokenSource.Token.ThrowIfCancellationRequested();
                }

                progressManager.SetProgressMax();
            }, cancellationTokenSource.Token);
        }