Example #1
0
        private string GenerateCode(XDocument _snipXml, LineData _txtLineData)
        {
            string     codeStr;
            XNamespace xns         = _snipXml.Root.Name.Namespace;
            XElement   codeElement = _snipXml.Root.Element(xns + "CodeSnippet").Element(xns + "Snippet").Element(xns + "Code");

            codeStr = codeElement.Value;

            //sanitize codeString from .snippet
            codeStr = Regex.Replace(codeStr, @"\r?\n", "\r\n");
            codeStr = codeStr.Replace("\t", "");
            codeStr = Regex.Replace(codeStr, @" {2,}", "");

            //insert values into snippet
            codeStr = codeStr.Replace("//TODO: Enter code for $FieldName$ calculation", _txtLineData.calculationTranslation);
            codeStr = codeStr.Replace("$FieldName$", _txtLineData.devFieldName);
            codeStr = codeStr.Replace("$Negative$", _txtLineData.allowNegativeString);
            codeStr = codeStr.Replace("$LineNumber$", _txtLineData.lineNumber);
            codeStr = codeStr.Replace("$InternalFieldName$", _txtLineData.InternalFieldName);
            codeStr = codeStr.Replace("$SummarySection$", _txtLineData.description);
            codeStr = codeStr.Replace("$ReferenceId$", _txtLineData.referenceId);
            codeStr = codeStr.Replace("$AttributeCategory$", _txtLineData.categoryString);
            codeStr = codeStr.Replace("$AttributeDescription$", _txtLineData.description);
            codeStr = codeStr.Replace("$Precision$", _txtLineData.precisionTypeString);
            codeStr = codeStr.Replace("$PrecisionType$", _txtLineData.precisionTypeString);
            codeStr = codeStr.Replace("$Rounding$", _txtLineData.roundingString);
            codeStr = codeStr.Replace("$RoundingType$", _txtLineData.roundingString);
            if (_txtLineData.dataType == DataType.Unknown)
            {
                codeStr = codeStr.Replace("$DataType$", _txtLineData.dataTypeString);
            }
            codeStr = codeStr.Replace("$end$", "");


            //special cases for ratio snipped because it is a snowflake
            if (_txtLineData.dataType == DataType.Ratio)
            {
                codeStr = codeStr.Replace("$Category$", _txtLineData.categoryString);
                codeStr = codeStr.Replace("$AttributeDescription$", _txtLineData.description);
            }

            return(codeStr);
        }
Example #2
0
        static void Main(string[] args)
        {
            string inputFileStr  = @"../../input.txt";
            string outputFileStr = @"../../output.txt";

            ConsoleExtensions.Initizialize();

            if (args != null && args.Length > 0)
            {
                File.WriteAllText(inputFileStr, args[0]);
            }



            string rowLines = GetAndSanitizeInputFromTxt(File.ReadAllText(inputFileStr));

            File.WriteAllText(inputFileStr, rowLines);



            List <LineData> LineDataList = new List <LineData>();

            int currentTextLine = 1;

            foreach (string line in rowLines.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
            {
                string   sanitizedLine = Regex.Replace(line, @"\t{2,}", "\t"); //remove excess tabs
                string[] lineValues    = sanitizedLine.Split('\t');            //split on tabs

                if (lineValues.Length == excelCellCount && lineValues[0] != string.Empty)
                {
                    LineData ld = new LineData(lineValues, category);
                    LineDataList.Add(ld);
                }
                else if (lineValues.Length == excelCellCount - 1 && lineValues[0] != string.Empty)   //FieldName is missing
                {
                    ConsoleExtensions.PrintConsoleWarning(currentTextLine, "No developer name");
                    //Console.WriteLine("Line {0} - Warning!... {1} has no Developer created name", currentRow, lineValues[0]);
                    LineData ld = new LineData(lineValues, category, false);
                    LineDataList.Add(ld);
                }
                else
                {
                    GetCategoryFromLine(lineValues, currentTextLine);
                    Debug.WriteLine("Could not process " + inputFileStr
                                    + " line number: " + currentTextLine
                                    + " expected cell count: " + excelCellCount
                                    + " actual cell count: " + lineValues.Length);
                }

                if (category == defaultCategory)
                {
                    ConsoleExtensions.PrintConsoleWarning(currentTextLine, "Using default category");
                }

                currentTextLine++;
            }


            //translate TA calc
            foreach (LineData outterLd in LineDataList)
            {
                string find    = outterLd.referenceId;
                string replace = outterLd.devFieldName;

                foreach (LineData innerLd in LineDataList)
                {
                    innerLd.calculationTranslation = innerLd.calculationTranslation.Replace(find, replace);
                }
            }


            //aw translation test
            string line2;

            foreach (LineData outterLd in LineDataList)
            {
                System.IO.StreamReader awFile = new System.IO.StreamReader("../../aw.txt");
                while ((line2 = awFile.ReadLine()) != null)
                {
                    string[] unit        = line2.Split(':');
                    string   findAw      = ":" + unit[0] + "]";
                    string   findPynr    = ":PYNR" + unit[0] + "]";
                    string   replaceAw   = "(" + unit[1] + ")]";
                    string   replacePynr = "(" + unit[1] + ")]";

                    //outterLd.calculationTranslation = outterLd.calculationTranslation.Replace(unit[0], unit[1]);
                    outterLd.calculationTranslation = Regex.Replace(outterLd.calculationTranslation, findAw, findAw + replaceAw);
                    outterLd.calculationTranslation = Regex.Replace(outterLd.calculationTranslation, findPynr, findPynr + replacePynr);
                }
            }

            //print warnings and errors
            foreach (LineData ld in LineDataList)
            {
                if (ld.calculationTaxAnalysisString.ToLower().Contains("direct entry") && !ld.isChangeable)
                {
                    ConsoleExtensions.PrintConsoleWarning(100, ld.devFieldName + " Contains phrase 'direct entry' ");
                }
            }


            //translate and write out to file
            StreamWriter outFile  = new StreamWriter(outputFileStr);
            StreamWriter jsonFile = new StreamWriter(jsonFileLocation);

            foreach (LineData ld in LineDataList)
            {
                DataTranslator dt = new DataTranslator(ld);
                outFile.WriteLine(dt.GetCode);
                jsonFile.WriteLine(JsonConvert.SerializeObject(ld) + ",");
            }

            outFile.Close();
            jsonFile.Close();

            Console.WriteLine("Press any key to close...");
            Console.ReadLine();
        }
Example #3
0
        public DataTranslator(LineData ld)
        {
            XDocument snippet = GetSnippet(ld.dataType, ld.isChangeable);

            codeString = GenerateCode(snippet, ld);
        }