Example #1
0
        public void TestEncryptionBoundaryFileEncryptEmptyString()
        {
            const string toEncryptFile     = "encryption_test_commonlibrary.txt";
            FileInfo     toEncryptFileInfo = ConfigFileLocator.GetFromAppConfigLocation(toEncryptFile);

            EncryptionUtil.EncryptFile(toEncryptFileInfo, "");
        }
        public void TestAppConfigPath()
        {
            FileInfo fileInfo = ConfigFileLocator.GetFromAppConfigLocation("log4net_commonlibrary.config");

            Assert.NotNull(fileInfo);
            Assert.IsTrue(fileInfo.Exists);
        }
        public Object GetConfigurationWithDefault(
            [FromBody] GetConfigurationWithDefault def,
            String appName,
            String moduleName,
            String hostName = "",
            MissingParametersAction missingParametersAction = MissingParametersAction.Throw)
        {
            var     baseDirectory        = FileSystem.Instance.GetBaseDirectory();
            JObject defaultParameters    = null;
            JObject defaultConfiguration = null;

            if (def != null)
            {
                defaultParameters    = def.DefaultParameters;
                defaultConfiguration = def.DefaultConfiguration;
            }
            ParameterManager.ReplaceResult replaceResult;

            var config = ConfigFileLocator.GetConfig(
                baseDirectory,
                appName,
                moduleName,
                hostName,
                missingParametersAction,
                defaultConfiguration,
                defaultParameters);

            return(config.Configuration);
        }
        public Object GetConfiguration(String appName, String moduleName, String hostName = "", MissingParametersAction missingParametersAction = MissingParametersAction.Throw)
        {
            var baseDirectory = FileSystem.Instance.GetBaseDirectory();
            var configuration = ConfigFileLocator.GetConfig(baseDirectory, appName, moduleName, hostName, missingParametersAction);

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

            return(componentsModels);
        }
Example #6
0
        public void Setup()
        {
            fileSystem        = new TestFileSystem();
            configFileLocator = new DefaultConfigFileLocator();
            repoPath          = DefaultRepoPath;

            ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute <TestAttribute>();
        }
        public void FindTest()
        {
            Assert.IsNull(ConfigFileLocator.Find("toto.json"));

            var fullPathToMySettings = ConfigFileLocator.Find("mysettings.json");

            Assert.IsNotNull(fullPathToMySettings);
        }
Example #8
0
        public void TestEncryptionBoundaryFileDecryptEmptyString()
        {
            const string toEncryptFile     = "encryption_test_commonlibrary.txt";
            FileInfo     toEncryptFileInfo = ConfigFileLocator.GetFromAppConfigLocation(toEncryptFile);

            const string toDecryptFile     = "post-decryption_test_commonlibrary.txt";
            FileInfo     decryptedFileInfo = new FileInfo(toEncryptFileInfo.DirectoryName + @"\" + toDecryptFile);

            EncryptionUtil.DecryptFile(decryptedFileInfo, "");
        }
        public HttpResponseMessage GetResource(String appName, String moduleName, String fileName, String hostName = "")
        {
            var baseDirectory   = FileSystem.Instance.GetBaseDirectory();
            var resourceContent = ConfigFileLocator.GetResourceFile(baseDirectory, appName, moduleName, hostName, fileName);

            return
                (new HttpResponseMessage()
            {
                Content = new StringContent(resourceContent, Encoding.UTF8, "text/html")
            });
        }
Example #10
0
        public void TestDecryptFile()
        {
            TestEncryptFile();

            const string encryptedFile     = "encryption_corrupted_test_commonlibrary.txt";
            const string toDecryptFile     = "post-encryption_corrupted_test_commonlibrary.txt";
            FileInfo     encryptedFileInfo = ConfigFileLocator.GetFromAppConfigLocation(encryptedFile);

            FileInfo decryptedFileInfo = new FileInfo(encryptedFileInfo.DirectoryName + @"\" + toDecryptFile);

            EncryptionUtil.DecryptFile(encryptedFileInfo, decryptedFileInfo.FullName);
        }
        public void TestRelativePath()
        {
            const string fileName = "log4net_commonlibrary.config";

            FileInfo fileInfo = ConfigFileLocator.GetFromAppConfigLocation(fileName);

            Assert.NotNull(fileInfo);

            //Copy the config file to the subfolder
            {
                string sourcePath = fileInfo.DirectoryName;
                string targetPath = sourcePath + @"\Config";
                // To copy a folder's contents to a new location:
                // Create a new target folder, if necessary.
                if (!Directory.Exists(targetPath))
                {
                    Directory.CreateDirectory(targetPath);
                }

                // Use Path class to manipulate file and directory paths.
                {
                    string sourceFile = Path.Combine(sourcePath, fileName);
                    string destFile   = Path.Combine(targetPath, fileName);

                    // To copy a file to another location and
                    // overwrite the destination file if it already exists.
                    File.Copy(sourceFile, destFile, true);
                }
            }

            FileInfo configInfo = ConfigFileLocator.GetFromAppConfigLocation("Config", "log4net_commonlibrary.config");

            Assert.NotNull(configInfo);
            Assert.IsTrue(configInfo.Exists);

            configInfo = ConfigFileLocator.GetFromAppConfigLocation(@"\Config", "log4net_commonlibrary.config");
            Assert.NotNull(configInfo);
            Assert.IsTrue(configInfo.Exists);

            configInfo = ConfigFileLocator.GetFromAppConfigLocation(@"Config\", "log4net_commonlibrary.config");
            Assert.NotNull(configInfo);
            Assert.IsTrue(configInfo.Exists);

            configInfo = ConfigFileLocator.GetFromAppConfigLocation(@"\Config\", "log4net_commonlibrary.config");
            Assert.NotNull(configInfo);
            Assert.IsTrue(configInfo.Exists);
            Assert.AreEqual("log4net_commonlibrary.config", configInfo.Name);

            configInfo = ConfigFileLocator.GetFromAppConfigLocation(@"NonExist\", "log4net_commonlibrary.config");
            Assert.IsFalse(configInfo.Exists);
        }
Example #12
0
        public void TestEncryptFile()
        {
            const string toEncryptFile     = "encryption_test_commonlibrary.txt";
            const string encryptedFile     = "post-encryption_test_commonlibrary.txt";
            FileInfo     toEncryptFileInfo = ConfigFileLocator.GetFromAppConfigLocation(toEncryptFile);

            Assert.NotNull(toEncryptFileInfo);

            FileInfo encryptedFileInfo = new FileInfo(toEncryptFileInfo.DirectoryName + @"\" + encryptedFile);

            EncryptionUtil.EncryptFile(toEncryptFileInfo, encryptedFileInfo.FullName);

            Assert.IsTrue(encryptedFileInfo.Exists);
        }
Example #13
0
        private bool ConfigFileExists()
        {
            if (!ConfigFileLocator.ConfigFileExists())
            {
                var msgService = kernel.Get <IMessageService>();
                msgService.Show(
                    WargameModInstaller.Properties.Resources.ConfigFileNotFoundErrorMsg,
                    WargameModInstaller.Properties.Resources.FatalErrorHeader,
                    MessageButton.OK,
                    MessageImage.Error);

                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #14
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);
            }
        }
 private static bool GetVersionVariables(GitVersionTaskBase task, out VersionVariables versionVariables)
 => new ExecuteCore(new FileSystem(), ConfigFileLocator.GetLocator(task.ConfigFilePath)).TryGetVersion(task.SolutionDirectory, out versionVariables, task.NoFetch, new Authentication());
 public void TestBoundary()
 {
     Assert.Throws <ArgumentNullException>(() => ConfigFileLocator.GetFromAppConfigLocation(""));
     Assert.Throws <ArgumentNullException>(() => ConfigFileLocator.GetFromAppConfigLocation("", "HelloWorld"));
     Assert.Throws <ArgumentNullException>(() => ConfigFileLocator.GetFromAppConfigLocation("HelloWorld", ""));
 }
        //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);
        }
        private static string GetConfigFileHash(IFileSystem fileSystem, GitPreparer gitPreparer, ConfigFileLocator configFileLocator)
        {
            // will return the same hash even when config file will be moved
            // from workingDirectory to rootProjectDirectory. It's OK. Config essentially is the same.
            var configFilePath = configFileLocator.SelectConfigFilePath(gitPreparer, fileSystem);

            if (!fileSystem.Exists(configFilePath))
            {
                return(string.Empty);
            }

            var configFileContent = fileSystem.ReadAllText(configFilePath);

            return(GetHash(configFileContent));
        }
        public static GitVersionCacheKey Create(IFileSystem fileSystem, GitPreparer gitPreparer, Config overrideConfig, ConfigFileLocator configFileLocator)
        {
            var gitSystemHash          = GetGitSystemHash(gitPreparer);
            var configFileHash         = GetConfigFileHash(fileSystem, gitPreparer, configFileLocator);
            var repositorySnapshotHash = GetRepositorySnapshotHash(gitPreparer);
            var overrideConfigHash     = GetOverrideConfigHash(overrideConfig);

            var compositeHash = GetHash(gitSystemHash, configFileHash, repositorySnapshotHash, overrideConfigHash);

            return(new GitVersionCacheKey(compositeHash));
        }