Пример #1
0
        public static void LoopToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int loopHeight, int loopWidth, out string ThreadLog, out string ThreadFunctions)
        {
            ThreadLog       = "";
            ThreadFunctions = "";
            string indentString = new string(' ', indentLevel * 4);

            XmlNode iterations = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//*[@Key='Iterations']");
            string  iterationsCount, dummy;

            ConditionXmlToTxt.ParseCondition(iterations, out iterationsCount, out dummy, out dummy, out dummy);

            Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1);
            string log, functions;

            PartialCanvasToTxt.Analyze(ref threadSteps, threadCol, 0, 0, indentLevel + 1, out log, out functions);

            if (canvasMatrix[0, 0].ToolName == "LoopTool")
            {
                ThreadLog = "Loop " + iterationsCount + " times";
            }
            else if (canvasMatrix[0, 0].ToolName == "ParaLoopTool")
            {
                ThreadLog = "ParaLoop " + iterationsCount + " branches";
            }
            else
            {
                ThreadLog = "LoopToTxt - unrecognized tool name: " + canvasMatrix[0, 0].ToolName;
                return;
            }

            ThreadLog      += "\r\n" + indentString + "{" + "\r\n";
            ThreadLog      += indentString + "    " + log.Trim();
            ThreadLog      += "\r\n" + indentString + "}";
            ThreadFunctions = functions;
        }
Пример #2
0
        public static void ParallelToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int pHeight, int pWidth, out string ThreadLog, out string ThreadFunctions)
        {
            ThreadLog       = "";
            ThreadFunctions = "";
            string indentString = new string(' ', indentLevel * 4);

            XmlNode     col  = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode("List[@Key='Blocks']/StepBlock");
            XmlNodeList cols = col.SelectNodes("Array[@Key='OutputConnectors']//*[@Key='Offset']/@Value");

            var logs = new string[cols.Count];

            for (int i = 0; i < cols.Count; i++)
            {
                Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1);
                string functions;
                int    column = int.Parse(cols[i].Value);
                PartialCanvasToTxt.Analyze(ref threadSteps, column, 0, 0, indentLevel + 1, out logs[i], out functions);
                ThreadFunctions += "\r\n" + functions;
            }

            for (int i = 0; i < logs.Length; i++)
            {
                ThreadLog += indentString + "Thread " + i.ToString();
                ThreadLog += "\r\n" + indentString + "{" + "\r\n";
                ThreadLog += indentString + "    " + logs[i].Trim();
                ThreadLog += "\r\n" + indentString + "}\r\n";
            }
        }
Пример #3
0
        public void Test_Matrix_Transformation_with_5X5_Matrix()
        {
            // prepare the input/test data
            int[,] source = new int[, ] {
                { 10, 20, 30, 40, 5 },
                { 20, 30, 40, 50, 7 },
                { 20, 30, 40, 50, 8 },
                { 20, 30, 40, 50, 0 },
                { 100, 200, 300, 400, 500 }
            };

            // define the expected result
            var expected = new int[, ] {
                { 100, 20, 20, 20, 10 },
                { 200, 30, 30, 30, 20 },
                { 300, 40, 40, 40, 30 },
                { 400, 50, 50, 50, 40 },
                { 500, 0, 8, 7, 5 }
            };

            // do the test
            MatrixTransformations.Transform90DegreeInPlace(source);

            // validate/verify the output of the method with the expected output
            Assert.IsTrue(MatrixComparer.AreSame(source, expected));
        }
Пример #4
0
        public static void LockToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int lockHeight, int lockWidth, out string ThreadLog, out string ThreadFunctions)
        {
            ThreadLog       = "";
            ThreadFunctions = "";
            string indentString = new string(' ', indentLevel * 4);

            XmlNode expression = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//*[@Key='LockExpression']");
            string  lockString, dummy;

            ConditionXmlToTxt.ParseCondition(expression, out lockString, out dummy, out dummy, out dummy);

            XmlNode timeoutxml = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//*[@Key='TimeoutExpression']");
            string  timeout    = "";

            if (timeoutxml != null && timeoutxml.Name != "Null")
            {
                timeout = TextfieldToTxt.Parse(timeoutxml);
            }

            Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1);
            string log, functions;

            PartialCanvasToTxt.Analyze(ref threadSteps, threadCol, 0, 0, indentLevel + 1, out log, out functions);


            ThreadLog = "lock (" + lockString + ")";
            if (timeout.Length > 0)
            {
                ThreadLog += " // Timeout: " + timeout + " seconds";
            }
            ThreadLog      += "\r\n" + indentString + "{" + "\r\n";
            ThreadLog      += indentString + "    " + log.Trim();
            ThreadLog      += "\r\n" + indentString + "}";
            ThreadFunctions = functions;
        }
        public static string BackConvert(MachineCode code)
        {
            var binary_code = code.binary_code;
            var count       = binary_code.Length - 1 - (MatrixTransformations.GetNumberFromBinary(code.displace) - 127);

            if (count > 0)
            {
                return(Displace(MatrixTransformations.GetStringNumberFromMatrix(binary_code.Reverse()), -count));
            }
            else
            {
                return(Displace("0." + MatrixTransformations.GetStringNumberFromMatrix(binary_code.Reverse()), count));
            }
        }
Пример #6
0
        private static void DemoMatrixTransformation()
        {
            //int[,] source = new int[,] {
            //        {10, 20, 30, 40},
            //        {40, 50, 60, 70},
            //        {80, 90, 100, 110},
            //        {120, 130, 140, 150}
            //    };
            int[,] source = new int[, ] {
                { 10, 20 },
                { 40, 50 }
            };

            Print(source, "Before Transformation");
            MatrixTransformations.Transform90DegreeInPlace(source);
            Print(source, "After Transformation");
        }
Пример #7
0
        public void Test_Matrix_Transformation_Should_Throw_Exception_On_Rows_And_Columns_Count_Is_Unequal()
        {
            // prepare the input/test data
            int[,] testData = new int[, ] {
                { 10, 20, 30 },
                { 40, 50, 60 },
                { 80, 90, 100 },
                { 120, 130, 140 },
                { 120, 130, 140 }
            };

            // define the expected result
            var expected = new int[, ] {
                { 120, 80, 40, 10 },
                { 130, 90, 50, 20 },
                { 140, 100, 60, 30 },
                { 150, 110, 70, 40 }
            };

            // do the test
            MatrixTransformations.Transform90DegreeInPlace(testData);
        }
Пример #8
0
        public static void WhileToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int loopHeight, int loopWidth, out string ThreadLog, out string ThreadFunctions)
        {
            ThreadLog       = "";
            ThreadFunctions = "";
            string indentString = new string(' ', indentLevel * 4);

            XmlNode conditions = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//BinaryExpression[@Key='Condition']/*");
            string  conditionString, dummy;

            ConditionXmlToTxt.ParseCondition(conditions, out conditionString, out dummy, out dummy, out dummy);

            Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1);
            string log, functions;

            PartialCanvasToTxt.Analyze(ref threadSteps, threadCol, 0, 0, indentLevel + 1, out log, out functions);

            bool isDoWhile = bool.Parse(canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//Boolean[@Key='IsDoWhile']/@Value").Value);

            if (isDoWhile)
            {
                ThreadLog = "do";
            }
            else
            {
                ThreadLog = "while (" + conditionString + ")";
            }

            ThreadLog += "\r\n" + indentString + "{" + "\r\n";
            ThreadLog += indentString + "    " + log.Trim();
            ThreadLog += "\r\n" + indentString + "}";

            if (isDoWhile)
            {
                ThreadLog += " while (" + conditionString + ")";
            }

            ThreadFunctions = functions;
        }
Пример #9
0
        public void Test_Matrix_Transformation_with_4X4_string_Matrix()
        {
            // prepare the input/test data
            string[,] testData = new string[, ] {
                { "10", "20", "30", "40" },
                { "40", "50", "60", "70" },
                { "80", "90", "100", "110" },
                { "120", "130", "140", "150" }
            };

            // define the expected result
            var expected = new string[, ] {
                { "120", "80", "40", "10" },
                { "130", "90", "50", "20" },
                { "140", "100", "60", "30" },
                { "150", "110", "70", "40" }
            };

            // do the test
            MatrixTransformations.Transform90DegreeInPlace(testData);

            // validate/verify the output of the method with the expected output
            Assert.IsTrue(MatrixComparer.AreSame(testData, expected));
        }
Пример #10
0
        public void Test_Matrix_Transformation_with_4X4_Matrix()
        {
            // prepare the input/test data
            int[,] testData = new int[, ] {
                { 10, 20, 30, 40 },
                { 40, 50, 60, 70 },
                { 80, 90, 100, 110 },
                { 120, 130, 140, 150 }
            };

            // define the expected result
            var expected = new int[, ] {
                { 120, 80, 40, 10 },
                { 130, 90, 50, 20 },
                { 140, 100, 60, 30 },
                { 150, 110, 70, 40 }
            };

            // do the test
            MatrixTransformations.Transform90DegreeInPlace(testData);

            // validate/verify the output of the method with the expected output
            Assert.IsTrue(MatrixComparer.AreSame(testData, expected));
        }
Пример #11
0
        public static void CaseToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int caseHeight, int caseWidth, out string ThreadLog, out string ThreadFunctions)
        {
            ThreadLog       = "";
            ThreadFunctions = "";
            string indentString = new string(' ', indentLevel * 4);

            XmlNodeList conditions = GetConditions(canvasMatrix[0, 0]);
            string      left, right, operatorTxt;
            var         conditionTxt = new string[conditions.Count];
            int         curcon       = 0;

            foreach (XmlNode condition in conditions)
            {
                ConditionXmlToTxt.ParseCondition(condition, out conditionTxt[curcon], out left, out operatorTxt, out right);
                curcon++;
            }

            XmlNode     col  = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode("List[@Key='Blocks']/StepBlock");
            XmlNodeList cols = col.SelectNodes("Array[@Key='OutputConnectors']//*[@Key='Offset']/@Value");

            XmlNode hasDefaultXml = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//*[@Key=\"HasDefaultBranch\"]");
            int     branches      = conditions.Count;

            if (hasDefaultXml != null)
            {
                if (hasDefaultXml.Attributes["Value"].Value == "True")
                {
                    branches++;
                }
            }
            else
            {
                //before the case tool could had 1 column
                branches++;
            }
            var logs = new string[conditions.Count + 1];

            for (curcon = 0; curcon < branches; curcon++)
            {
                Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1);
                string functions;
                int    column = int.Parse(cols[curcon].Value);
                PartialCanvasToTxt.Analyze(ref threadSteps, column, 0, 0, indentLevel + 1, out logs[curcon], out functions);
                ThreadFunctions += "\r\n" + functions;
            }
            for (curcon = 0; curcon < branches; curcon++)
            {
                if (curcon == 0)
                {
                    ThreadLog += "if " + conditionTxt[curcon];
                }
                else if (curcon < logs.Length - 1)
                {
                    ThreadLog += "\r\n" + indentString + "else if " + conditionTxt[curcon];
                }
                else
                {
                    ThreadLog += "\r\n" + indentString + "else";
                }

                ThreadLog += "\r\n" + indentString + "{" + "\r\n";
                ThreadLog += indentString + "    " + logs[curcon].Trim();
                ThreadLog += "\r\n" + indentString + "}";
            }
        }