예제 #1
0
파일: Compile.cs 프로젝트: Robson10/UML-2
        public static string TransformBlockToCode(ListCanvasBlocks blocks, ListCanvasLines lines)
        {
            string code = "";

            try
            {
                blocks.Sort((x, y) => x.ID.CompareTo(y.ID));
                var indexBegin = blocks.FindIndex(x => x.Shape == Helper.Shape.Start);
                int endId      = lines.Find(x => x.BeginId == blocks[indexBegin].ID).EndId;
                StartToCode(ref code, blocks[indexBegin], endId);
                for (int i = 0; i < blocks.Count; i++)
                {
                    if (blocks[i].Shape == Helper.Shape.Decision)
                    {
                        DecisionToCode(ref code, blocks[i], ref lines);
                    }
                    else if (blocks[i].Shape != Helper.Shape.End && blocks[i].Shape != Helper.Shape.Start)
                    {
                        endId = lines.Find(x => x.BeginId == blocks[i].ID).EndId;
                        InputExecutionToCode(ref code, blocks[i], endId);
                    }
                    else if (blocks[i].Shape == Helper.Shape.End)
                    {
                        EndToCode(ref code, blocks[i].ID);
                    }
                    code += Environment.NewLine;
                }
                FinishCode(ref code);
                Results.Text = code;
            }
            catch
            {
            }
            return(code);
        }
예제 #2
0
파일: Compile.cs 프로젝트: Robson10/UML-2
 public static string Run(ListCanvasBlocks blocks, ListCanvasLines lines)
 {
     if (ValidateSchema(ref blocks, ref lines))
     {
         try
         {
             if (File.Exists(Helper.CompilePath + @"\project.cpp"))
             {
                 File.Delete(Helper.CompilePath + @"\project.cpp");
             }
             if (File.Exists(Helper.CompilePath + @"\project.exe"))
             {
                 File.Delete(Helper.CompilePath + @"\project.exe");
             }
             File.WriteAllText(Helper.CompilePath + @"\project.cpp", TransformBlockToCode(blocks, lines));
             RunCMD(false);
         }
         catch
         {
             MessageBox.Show(
                 "Odmowa dostępu! Prawdopodobnie masz uruchomione projekty w konsoli. Zamknij je i spróbuj ponownie");
         }
     }
     return("asd");
 }
예제 #3
0
파일: Compile.cs 프로젝트: Robson10/UML-2
 private static void DecisionToCode(ref string code, MyBlock block, ref ListCanvasLines lines)
 {
     code += "          case(" + block.ID + "):" + Environment.NewLine +
             "               " + block.Code + Environment.NewLine +
             //"               {" + Environment.NewLine +
             "                   ID=" + lines.Find(x => x.BeginId == block.ID && x.IsTrue).EndId + ";" +
             Environment.NewLine +
             //"               }" + Environment.NewLine +
             "               else" + Environment.NewLine +
             //"               {" + Environment.NewLine +
             "                   ID=" + lines.Find(x => x.BeginId == block.ID && !x.IsTrue).EndId + ";" +
             Environment.NewLine +
             //"               }" + Environment.NewLine +
             "              break;" + Environment.NewLine;
 }
예제 #4
0
파일: Compile.cs 프로젝트: Robson10/UML-2
        private static bool ValidateSchema(ref ListCanvasBlocks blocks, ref ListCanvasLines lines)
        {
            ///Celem owej metody jest sprawdzenie poprawności stworzonego schematu -
            /// czy istnieje początek algorytmu - START, koniec algorytmu - KONIEC, oraz czy wszystkie bloki są ze sobą połączone
            string myOutput     = "";
            bool   isStartExist = blocks.Exists(x => x.Shape == Helper.Shape.Start);
            bool   isEndExist   = blocks.Exists(x => x.Shape == Helper.Shape.End);
            bool   isCountOfLinesCorrect;

            if (!isStartExist)
            {
                myOutput += "Błąd: algorytm musi posiadać " +
                            Helper.DefaultBlocksSettings[Helper.Shape.Start].Label + Environment.NewLine;
            }
            if (!isEndExist)
            {
                myOutput += "Błąd: algorytm musi posiadać " +
                            Helper.DefaultBlocksSettings[Helper.Shape.End].Label + Environment.NewLine;
            }
            int count = 0;

            count += blocks.FindAll(x => x.Shape == Helper.Shape.Decision).Count * 2;
            count += blocks.FindAll(x => x.Shape != Helper.Shape.Decision && x.Shape != Helper.Shape.End).Count;
            isCountOfLinesCorrect = count == lines.Count;
            if (!isCountOfLinesCorrect)
            {
                myOutput += "Błąd: Brakuje połączeń między blokami" +
                            Environment.NewLine;
            }
            myOutput += (isCountOfLinesCorrect && isStartExist && isEndExist)
                ? "Twój kod wstępnie wygląda w porządku"
                : "";
            if (isCountOfLinesCorrect && isStartExist && isEndExist)
            {
                return(true);
            }
            else
            {
                MessageBox.Show(myOutput);
                return(false);
            }
        }
예제 #5
0
파일: Compile.cs 프로젝트: Robson10/UML-2
 public static void Debug(ListCanvasBlocks blocks, ListCanvasLines lines)
 {
     if (ValidateSchema(ref blocks, ref lines))
     {
         try
         {
             if (File.Exists(Helper.CompilePath + @"\project.cpp"))
             {
                 File.Delete(Helper.CompilePath + @"\project.cpp");
             }
             if (File.Exists(Helper.CompilePath + @"\project.exe"))
             {
                 File.Delete(Helper.CompilePath + @"\project.exe");
             }
             File.WriteAllText(Helper.CompilePath + @"\project.cpp", TransformBlockToCode(blocks, lines));
             RunCMD(true);
         }
         catch (UnauthorizedAccessException e)
         {
             MessageBox.Show("Nie udało się usunąc plików projektu. Prawdopodobnie masz uruchomione projekty?");
         }
     }
 }