private static string GetConnectionString(string DataBaseKeyID)
        {
            string    cnnString  = "";
            DBManager _dbManager = DBManager.GetInstance();

            //evaluates if the key id exisit already in the connections string list
            if (!_dbManager._connectionsStringList.ContainsKey(DataBaseKeyID))
            {
                //get acces to configuration file handler
                ConfigurationFileHandler configFile = default(ConfigurationFileHandler);
                configFile = ConfigurationFileHandlerProxyServer.GetInstance().GetFileHandler();

                KeyValue configurationKey = default(KeyValue);
                configurationKey = (KeyValue)(configFile.GetValue("DATABASE_FRAMEWORK/CONNECTION_STRINGS/" + DataBaseKeyID));

                if (configurationKey == null)
                {
                    string message = "";
                    message = "Not connection string defined for DataBaseID : " + DataBaseKeyID + Constants.vbNewLine + "Or not configuration Exists in Route : DATABASE_FRAMEWORK/CONNECTION_STRINGS/";
                    throw (new Exception(message));
                }

                //adds the new connection string
                cnnString = configurationKey.Value;
                _dbManager._connectionsStringList.Add(DataBaseKeyID, configurationKey.Value);
            }
            else
            {
                cnnString = System.Convert.ToString(_dbManager._connectionsStringList[DataBaseKeyID]);
            }
            return(cnnString);
        }
 public void ShouldThrowOnNonExistingFile(string path)
 {
     Assert.Throws <FileNotFoundException>(() =>
     {
         _ = new ConfigurationFileHandler(path);
     });
 }
Beispiel #3
0
        private void SaveProject()
        {
            // Store current package if in design-mode
            var packageOverview = this.mainWindowContent.Content as Screens.PackageOverview;

            if (packageOverview != null)
            {
                packageOverview.SaveDiagram();
            }

            Type[] extraTypes = applicationInitializer.ModuleLoader.GetModuleTypeList();

            // Save the connections to disk
            ObservableCollection <ConnectionConfigurationBase> connections = this.CurrentProject.Connections;
            string serializedConnections = ConfigurationSerializer.SerializeObject(connections, extraTypes);

            ConfigurationFileHandler.SaveStringToFile(this.CurrentProject.ProjectName + "Connections.xml",
                                                      this.CurrentProject.ProjectFolder,
                                                      serializedConnections);

            // Save the project to disk
            this.CurrentProject.Connections = null;
            string serializedProject = ConfigurationSerializer.SerializeObject(this.CurrentProject, extraTypes);

            ConfigurationFileHandler.SaveStringToFile(this.CurrentProject.ProjectName + ".xml",
                                                      this.CurrentProject.ProjectFolder,
                                                      serializedProject);

            this.CurrentProject.Connections = connections;
        }
Beispiel #4
0
        /// <summary>
        /// Load all runlogs
        /// </summary>
        public void LoadRunLogs()
        {
            var    loadedLogs  = new List <RunLog>();
            string logBasePath = this.ProjectFolder.Trim(Path.DirectorySeparatorChar) + @"\logs\";

            if (Directory.Exists(logBasePath))
            {
                foreach (string runLogFileDirectory in Directory.GetDirectories(logBasePath))
                {
                    if (File.Exists(runLogFileDirectory + @"\runLog.xml") == false)
                    {
                        continue;
                    }

                    string serializedRunLog = ConfigurationFileHandler.ReadStringFromFile(runLogFileDirectory + @"\runLog.xml");
                    RunLog runLog           = (RunLog)ConfigurationSerializer.DeserializeObject(serializedRunLog, typeof(RunLog), new Type[] { });
                    loadedLogs.Add(runLog);
                }
            }

            this.RunLogs.Clear();
            foreach (var log in loadedLogs.OrderBy(t => t.StartTime))
            {
                RunLogs.Add(log);
            }
        }
Beispiel #5
0
        private static void GetUserNameAndPasswordFromConfigurationFile()
        {
            ConfigurationFileHandler configfileHndlr = default(ConfigurationFileHandler);

            configfileHndlr = ConfigurationFileHandlerProxyServer.GetInstance.GetFileHandler;
            KeyValue key = default(KeyValue);

            key = (KeyValue)(configfileHndlr.GetValue("UTILITIES_FRAMEWORK/SQLSERVER_SCRIPT_RUNNER/USER"));
            if (!(key == null))
            {
                _userName = System.Convert.ToString(key.Value);
            }
            else
            {
                throw (new Exception("No configuration found on UTILITIES_FRAMEWORK/SQLSERVER_SCRIPT_RUNNER/USER"));
            }

            key = (KeyValue)(configfileHndlr.GetValue("UTILITIES_FRAMEWORK/SQLSERVER_SCRIPT_RUNNER/PASSWORD"));
            if (!(key == null))
            {
                _password = System.Convert.ToString(key.Value);
            }
            else
            {
                throw (new Exception("No configuration found on UTILITIES_FRAMEWORK/SQLSERVER_SCRIPT_RUNNER/PASSWORD"));
            }
        }
 public void ShouldThrowOnEmptyPath(string path)
 {
     Assert.Throws <ArgumentException>(() =>
     {
         _ = new ConfigurationFileHandler(path);
     });
 }
        public void ShouldReadFromFile(List <string> fileLines, NodeState state)
        {
            string tmpFilePAth = Path.GetTempFileName();

            File.WriteAllLines(tmpFilePAth, fileLines);
            ConfigurationFileHandler cfh = new ConfigurationFileHandler(tmpFilePAth);
            NodeState resultState        = cfh.ReadCurrentState();

            resultState.Should().BeEquivalentTo(state);
        }
        public void ShouldWriteToFile(List <string> inputFile, NodeState newState, List <string> expectedLines)
        {
            string tmpFilePAth = Path.GetTempFileName();

            File.WriteAllLines(tmpFilePAth, inputFile);

            ConfigurationFileHandler cfh = new ConfigurationFileHandler(tmpFilePAth);

            cfh.WriteNewState(newState);

            List <string> resultingLines = File.ReadAllLines(tmpFilePAth).ToList();

            resultingLines.Should().ContainInOrder(expectedLines);
        }
Beispiel #9
0
        public static Project LoadFromFile(string projectPath, Type[] extraTypes)
        {
            string  serializedProject = ConfigurationFileHandler.ReadStringFromFile(projectPath);
            Project project           = (Project)ConfigurationSerializer.DeserializeObject(serializedProject, typeof(Project), extraTypes);

            project.ProjectFolder = projectPath.Replace(Path.GetFileName(projectPath), "");

            string connectionsPath = project.ProjectFolder + "\\" + project.ProjectName + "Connections.xml";

            if (File.Exists(connectionsPath))
            {
                string serializedConnections = ConfigurationFileHandler.ReadStringFromFile(connectionsPath);
                project.Connections = (ObservableCollection <ConnectionConfigurationBase>)ConfigurationSerializer.DeserializeObject(serializedConnections, typeof(ObservableCollection <ConnectionConfigurationBase>), extraTypes);
            }
            return(project);
        }
Beispiel #10
0
        /// <summary>
        /// Enables the ability for that project to be able to use NHibernate Repo migrations, automatic or manual.
        /// </summary>
        public void EnableMigrations(EnableMigrationsCriteria criteria)
        {
            MessageFilter.Register();

            var repoInfo = TypeHandler.FindSingleRepo(criteria.ProjectPath, criteria.RepoName);

            //if it is null something is wrong so drop out.
            if (repoInfo == null)
            {
                return;
            }

            AssertRepoHasEmptyConstructor(repoInfo.RepoType);
            EnsureDbAndMigrationTableExists(criteria.ProjectPath, repoInfo.RepoType, criteria.ConfigFilePath);

            var repoBase = TypeHandler.CreateRepoBase(repoInfo.Assembly.Location, repoInfo.RepoType);

            //create migration log table, if it doesn't exist.
            var updater = CreateSchemaUpdater(criteria.ProjectPath, typeof(MigrationRepo), criteria.ConfigFilePath, repoBase.ConnectionStringOrName);

            updater.Execute(true, true);

            bool multipleFound = false;
            var  configType    = TypeHandler.FindSingleConfiguration(criteria.ProjectPath, repoInfo.RepoType, out multipleFound);

            //this should not happen. should only ever have one config per repo type.
            if (multipleFound)
            {
                return;
            }

            if (configType == null)
            {
                LoggerBase.Log("Adding migration configuration");
                var filePath = new ConfigurationFileHandler().CreateConfigurationFile(criteria.ProjectPath, repoInfo.RepoType.Name, "Migrations", MigrationToUse.Manual);
                new ProjectDteHelper().AddFile(criteria.ProjectPath, "Migrations", filePath, showFile: true);
            }
            else
            {
                LoggerBase.Log("System is already configured for migrations, see class: " + configType.Name);
            }

            //clean up
            ProjectEvalutionHelper.FinishedWithProject(criteria.ProjectPath);
            MessageFilter.Revoke();
        }
Beispiel #11
0
        /// <summary>
        /// Load all runlogs
        /// </summary>
        public void LoadRunLogs()
        {
            this.RunLogs.Clear();
            string logBasePath = this.ProjectFolder.Trim('\\') + @"\logs\";

            if (Directory.Exists(logBasePath))
            {
                foreach (string runLogFileDirectory in Directory.GetDirectories(logBasePath))
                {
                    if (File.Exists(runLogFileDirectory + @"\runLog.xml") == false)
                    {
                        continue;
                    }

                    string serializedRunLog = ConfigurationFileHandler.ReadStringFromFile(runLogFileDirectory + @"\runLog.xml");
                    RunLog runLog           = (RunLog)ConfigurationSerializer.DeserializeObject(serializedRunLog, typeof(RunLog), new Type[] { });
                    this.RunLogs.Add(runLog);
                }
            }
        }
        public void ShouldThrowIfFileDissapears()
        {
            string tmpFilePAth = Path.GetTempFileName();

            File.WriteAllLines(tmpFilePAth, new List <string>
            {
                "#This is a config file",
                "IS_SIGNING=non-signing",
                "PARITY_VERSION=parity/parity:v2.4.0",
                "PARITY_CHKSUM=30b9c9852b52546e7de32832ddfaa4aba33c0c436c985ad97d3fe9c4210043d8",
                "ANOTHER_KEY=foobar",
                "KEY_2=awesomesource",
                "SESSION_MANAGER=local/yoga-markus:@/tmp/.ICE-unix/2876,unix/yoga-markus:/tmp/.ICE-unix/2876",
                "SHELL=/usr/bin/zsh",
                "This is a comment right in the middle",
                "SHLVL=2",
                "SSH_AGENT_PID=2940",
                "SSH_AUTH_SOCK=/run/user/1000/keyring/ssh",
                "TERM=screen",
                "CHAINSPEC_URL=https://example.com/chainspec-20190303.json",
                "CHAINSPEC_CHKSUM=7e40a9d4a3066f839882e0fc26acd9e2f08bdbd314b7319db7cae54cd4450ee9"
            });

            // instantiate with existing file to pass first file check
            ConfigurationFileHandler cfh = new ConfigurationFileHandler(tmpFilePAth);

            // remove file
            File.Delete(tmpFilePAth);

            // make sure it was removed
            if (File.Exists(tmpFilePAth))
            {
                throw new TestFailureException("Test file didn't get removed. Results would be wrong.");
            }

            // Should fail on a file write attempt
            Assert.Throws <FileNotFoundException>(() => { cfh.WriteNewState(new NodeState()); });

            // Should fail on a file read attempt
            Assert.Throws <FileNotFoundException>(() => { _ = cfh.ReadCurrentState(); });
        }
Beispiel #13
0
        private static void GetUserNameAndPasswordFromConfigurationFile()
        {
            try
            {
                ConfigurationFileHandler configfileHndlr = default(ConfigurationFileHandler);
                configfileHndlr = ConfigurationFileHandlerProxyServer.GetInstance().GetFileHandler();
                KeyValue key = default(KeyValue);
                key = (KeyValue)(configfileHndlr.GetValue("UTILITIES_FRAMEWORK/SQLSERVER_DB_ATTACHER/USER"));
                if (!(key == null))
                {
                    UserId = key.Value;
                }
                else
                {
                    Console.Write("User Name : ");
                    UserId = Console.ReadLine();
                }

                key = (KeyValue)(configfileHndlr.GetValue("UTILITIES_FRAMEWORK/SQLSERVER_DB_ATTACHER/PASSWORD"));
                if (!(key == null))
                {
                    password = key.Value;
                }
                else
                {
                    Console.Write("Password : "******"User Name : ");
                UserId = Console.ReadLine();
                Console.Write("Password : ");
                password = Console.ReadLine();
            }
        }
Beispiel #14
0
        private async Task RunInternal(IProgress <ProgressReport> progress)
        {
            this.progress = progress;

            await Task.Run(() =>
            {
                ItemWorker[] startDesignerItems = GetStartDesignerItems();
                ItemWorker[] endDesignerItems   = GetEndDesignerItems();

                // Start starteritems
                foreach (ItemWorker item in startDesignerItems)
                {
                    ExecuteDesignerItem(item);
                }

                while (true)
                {
                    // Continously check if all items finished already
                    List <ItemWorker> unfinishedItemWorkers = itemWorkers.Where(t => t.DesignerItem.State != ItemState.Stopped && t.DesignerItem.State != ItemState.Error && t.DesignerItem.State != ItemState.NotExecuted).ToList();
                    if (unfinishedItemWorkers.Count == 0)
                    {
                        if (RunCompleted != null)
                        {
                            RunCompleted(this, new EventArgs());
                        }
                        break;
                    }

                    // Check if a new item can be started
                    List <ItemWorker> finishedItems = itemWorkers.Where(t => t.DesignerItem.State == ItemState.Stopped || t.DesignerItem.State == ItemState.Error || t.DesignerItem.State == ItemState.NotExecuted).ToList();
                    foreach (ItemWorker itemWorker in unfinishedItemWorkers.Where(t => t.DesignerItem.State == ItemState.Initialized))
                    {
                        // Initialize
                        bool newItemCanBeStarted = true;

                        // If not all incoming connections to the item are from finished items, the item may not be started
                        IEnumerable <ConnectionBase> incomingConnections = FlowHelper.GetIncomingConnections(itemWorker.DesignerItem.ID, connectionList);
                        foreach (ConnectionBase connection in incomingConnections)
                        {
                            if (finishedItems.Where(t => t.DesignerItem.ID == connection.SourceID).Count() == 0)
                            {
                                newItemCanBeStarted = false;
                            }
                        }

                        if (newItemCanBeStarted == true)
                        {
                            // Check if all incoming connection allow an execution
                            bool allowExecution_PreviousErrorTest = FlowHelper.AllowExecution_OnPreviousErrorTest(itemWorker, this.itemWorkers, this.connectionList);
                            bool allowExecution_PreviousItemNotSuccessfulOnErrorlineTest = FlowHelper.AllowExecution_PreviousStepNotSuccessfulOnErrorlineTest(itemWorker, this.itemWorkers, this.connectionList);
                            bool allowExecution_activeItem = itemWorker.Configuration.Status == StepExecutionStatus.Active;

                            if (allowExecution_PreviousErrorTest && allowExecution_PreviousItemNotSuccessfulOnErrorlineTest && allowExecution_activeItem)
                            {
                                ExecuteDesignerItem(itemWorker);
                            }
                            else
                            {
                                DoNotExecuteDesignerItem(itemWorker);
                            }
                        }
                    }

                    System.Threading.Thread.Sleep(200);
                }

                this.runLog.EndTime = DateTime.Now;

                string serializedRunLog = ConfigurationSerializer.SerializeObject(runLog, new Type [] {});
                ConfigurationFileHandler.SaveStringToFile("runLog.xml", this.runLog.RunLogPath, serializedRunLog);
            });
        }
        public bool Call(List <string> parameters)
        {
            if (parameters == null)
            {
                Console.WriteLine("This command needs parameters");
                return(false);
            }
            bool result = false;

            if (ConfigurationFileHandler.FileExists())
            {
                ConfigurationFileHandler.LoadFile();
            }
            else
            {
                if (!ConfigurationFileHandler.CreateConfigurationFile())
                {
                    return(false);
                }
                ConfigurationFileHandler.SaveFile();
            }
            switch (parameters[0])
            {
            case "default-customUI":
                switch (parameters.Count)
                {
                case 2:
                    if (ConfigurationFileHandler.SetCustomUIDefaultName(parameters[1]))
                    {
                        ConfigurationFileHandler.SaveFile();
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                default:
                    Console.WriteLine("Not correct number of parameters");
                    break;
                }
                break;

            // Versionage as 'a.b.c.d'
            case "specify-version":
                string versionage   = null;
                string release      = null;
                string feature      = null;
                string bugfix       = null;
                string optimization = null;
                switch (parameters.Count)
                {
                case 2:
                    versionage = parameters[1];
                    // Specifying versionage 'd'
                    optimization = parameters[1];
                    break;

                case 3:
                    // Specifying versionage 'c.d'
                    bugfix       = parameters[2];
                    optimization = parameters[1];
                    break;

                case 4:
                    // Specifying versionage 'b.c.d'
                    feature      = parameters[3];
                    bugfix       = parameters[2];
                    optimization = parameters[1];
                    break;

                case 5:
                    // Specifying versionage 'a.b.c.d'
                    release      = parameters[4];
                    feature      = parameters[3];
                    bugfix       = parameters[2];
                    optimization = parameters[1];
                    break;

                default:
                    Console.WriteLine("Not valid number of parameters");
                    break;
                }
                if (ConfigurationFileHandler.SetVersion(versionage, true))
                {
                    ConfigurationFileHandler.SaveFile();
                }
                else
                {
                    if (ConfigurationFileHandler.SetVersion(release, feature, bugfix, optimization))
                    {
                        ConfigurationFileHandler.SaveFile();
                    }
                    else
                    {
                        return(false);
                    }
                }
                break;

            case "update-version":
                // Updating versionage 'a.b.c.d'
                bool a = false;
                bool b = false;
                bool c = false;
                bool d = false;
                switch (parameters.Count)
                {
                // Defuault will only update versionage of 'd'
                case 1:
                    d      = true;
                    result = true;
                    break;

                case 2:
                    switch (parameters[1])
                    {
                    case "release":
                    case "rls":
                        a = true;
                        break;

                    case "feature":
                    case "ftr":
                        b = true;
                        break;

                    case "bugfix":
                    case "bfx":
                        c = true;
                        break;

                    case "optimization":
                    case "opt":
                        d = true;
                        break;
                    }
                    result = true;
                    break;

                default:
                    Console.WriteLine("Not recognized parameters");
                    break;
                }
                ConfigurationFileHandler.UpdateVersion(a, b, c, d);
                ConfigurationFileHandler.SaveFile();
                break;

            default:
                Console.WriteLine($"Option '{parameters[0]}' is not valid");
                break;
            }
            return(result);
        }