Пример #1
0
 public VariableAction()
 {
     Console.WriteLine("Variable Initiated.");
     currentDirectory = @"F:\CodeProjects\Taide\terraform";
     //currentDirectory = Directory.GetCurrentDirectory ();
     collectData = new CollectData();
     varInfo     = new NewVariable();
 }
Пример #2
0
        public new List <DatabaseObject> Read(string sTable)
        {
            int iBytesRead, iCrc24Value, iOffset = Crc24.ciCrc24Length;

            byte[]                abDecrypted;
            Crc24                 Crc24Computed;
            DatabaseObject        NewObject;
            DatabaseVariable      NewVariable;
            List <Row>            ltRows;
            List <DatabaseObject> ltReturn = new List <DatabaseObject>();

            _eState = nState.OK;

            if (sTable == "system")
            {
                ltRows = base.Read(sTable, ciIdSystemMinPropertyId, int.MaxValue);
            }
            else
            {
                ltRows = base.Read(sTable);
            }

            foreach (Row NewRow in ltRows)
            {
                if (_eState != nState.OK)
                {
                    break;
                }

                NewObject   = null;
                NewVariable = FetchEmptyDatabaseVariable();
                abDecrypted = _Cryptography.DecryptAes(NewRow.abData, _abAesKey);

                if ((abDecrypted == null) || (abDecrypted.Length < (Crc24.ciCrc24Length + 2)))
                {
                    _eState = nState.CouldNotRead;
                }
                else
                {
                    iCrc24Value   = (abDecrypted[0] << 16) | (abDecrypted[1] << 8) | abDecrypted[2];
                    Crc24Computed = new Crc24(abDecrypted, Crc24.ciCrc24Length);
                    if (iCrc24Value != Crc24Computed.iCrc24)
                    {
                        _eState = nState.CouldNotRead;
                    }
                    else
                    {
                        while ((iBytesRead = NewVariable.SetValue(abDecrypted, iOffset)) > 0)
                        {
                            _ltVariables.Add(NewVariable);
                            NewVariable = FetchEmptyDatabaseVariable();
                            iOffset    += iBytesRead;
                        }

                        switch (sTable)
                        {
                        case "system": NewObject = new Property(NewRow.iId, _ltVariables); break;
                        }

                        if (NewObject != null)
                        {
                            ltReturn.Add(NewObject);
                        }

                        _ltVariables.Add(NewVariable);
                    }
                }
                RecycleDatabaseVariables();
            }
            return(ltReturn);
        }
Пример #3
0
        public void UpsertVariable(NewVariable newVariableInfo, VarLists variableLists)
        {
            newVarInfo = newVariableInfo;
            varLists   = variableLists;
            var ad = new AggregateData();

            if (newVariableInfo.isEnvVar)
            {
                bool matchFound = false;
                ad.GlobalData = CreateVariableFileContents(varLists.GlobalList, newVarInfo.GlobalValue, out matchFound, true);
                if (matchFound)
                {
                    throw new Exception("Variable meant for environment variables already exists in global variables.");
                }
                ad.DevData  = CreateVariableFileContents(varLists.DevList, newVarInfo.DevValue, out matchFound);
                ad.QaData   = CreateVariableFileContents(varLists.QaList, newVarInfo.QaValue, out matchFound);
                ad.QtsData  = CreateVariableFileContents(varLists.QtsList, newVarInfo.QtsValue, out matchFound);
                ad.ProdData = CreateVariableFileContents(varLists.ProdList, newVarInfo.ProdValue, out matchFound);

                // Convert lists to strings
                ad.GlobalText = CreateVariableText(ad.GlobalData);
                ad.DevText    = CreateVariableText(ad.DevData);
                ad.QaText     = CreateVariableText(ad.QaData);
                ad.QtsText    = CreateVariableText(ad.QtsData);
                ad.ProdText   = CreateVariableText(ad.ProdData);

                // Generate VARS files
                ad.VariableNames = MergeAllListData(ad);
                ad.VariableText  = CreateVarsFileData(ad.VariableNames);

                fileControl.SaveFileWithContent(@"dev.tfvars", ad.DevText);
                fileControl.SaveFileWithContent(@"qa.tfvars", ad.QaText);
                fileControl.SaveFileWithContent(@"qts.tfvars", ad.QtsText);
                fileControl.SaveFileWithContent(@"prod.tfvars", ad.ProdText);
                fileControl.SaveFileWithContent(@"dev\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"qa\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"qts\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"prod\vars.tf", ad.VariableText);
            }
            else
            {
                bool matchFound = false;
                ad.DevData  = CreateVariableFileContents(varLists.DevList, newVarInfo.DevValue, out matchFound, true);
                ad.QaData   = CreateVariableFileContents(varLists.QaList, newVarInfo.QaValue, out matchFound, true);
                ad.QtsData  = CreateVariableFileContents(varLists.QtsList, newVarInfo.QtsValue, out matchFound, true);
                ad.ProdData = CreateVariableFileContents(varLists.ProdList, newVarInfo.ProdValue, out matchFound, true);
                if (matchFound)
                {
                    throw new Exception("Variable meant for global variables already exists in environment variables.");
                }
                ad.GlobalData = CreateVariableFileContents(varLists.GlobalList, newVarInfo.GlobalValue, out matchFound);

                // Convert lists to strings
                ad.GlobalText = CreateVariableText(ad.GlobalData);
                // Generate VARS files
                ad.VariableNames = MergeAllListData(ad);
                ad.VariableText  = CreateVarsFileData(ad.VariableNames);

                if (string.IsNullOrWhiteSpace(ad.GlobalText) || string.IsNullOrWhiteSpace(ad.VariableText))
                {
                    throw new Exception("Something went horribly wrong! No files saved.");
                }
                fileControl.SaveFileWithContent(@"global.tfvars", ad.GlobalText);
                fileControl.SaveFileWithContent(@"dev\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"qa\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"qts\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"prod\vars.tf", ad.VariableText);
            }
        }