public async Task <Program> CopyProgramPart2(string sourceProgramName,
                                                     string newProgramName)
        {
            using (var storage = StorageSystem.GetStorage())
            {
                var sourcePath      = Path.Combine(StorageConstants.ProgramsPath, sourceProgramName);
                var destinationPath = Path.Combine(StorageConstants.ProgramsPath, newProgramName);

                await storage.CopyDirectoryAsync(sourcePath, destinationPath);

                var tempXmlPath = Path.Combine(destinationPath, StorageConstants.ProgramCodePath);
                var xml         = await storage.ReadTextFileAsync(tempXmlPath);

                var xmlProgram = new XmlProgram(xml)
                {
                    ProgramHeader = { ProgramName = newProgramName }
                };

                var path = Path.Combine(StorageConstants.ProgramsPath,
                                        newProgramName, StorageConstants.ProgramCodePath);
                var programConverter = new ProgramConverter();
                var program          = programConverter.Convert(xmlProgram);

                var xmlString = xmlProgram.ToXmlString();
                await storage.WriteTextFileAsync(path, xmlString);

                return(program);
            }
        }
        public void Calculate(object obj)
        {
            try
            {
                var programConverters = new ProgramConverter[ConvertersCount];

                for (var i = 0; i < programConverters.Length / 2; i++)
                {
                    programConverters[i] = new ProgramConverter();
                }
                for (var i = programConverters.Length / 2; i < programConverters.Length; i++)
                {
                    programConverters[i] = new ProgramHelper();
                }
                OutputWriteLine($"[0 - {-1 + programConverters.Length / 2}] elements is {nameof(ProgramConverter)}");
                OutputWriteLine(
                    $"[{programConverters.Length / 2} - {programConverters.Length - 1}] elements is {nameof(ProgramHelper)}");
                OutputWriteLine(string.Empty);

                const string vbCode = "var";

                for (var i = 0; i < programConverters.Length; i++)
                {
                    var converter = programConverters[i];
                    if (converter is ICodeChecker)
                    {
                        var codeChecker = converter as ICodeChecker;

                        OutputWriteLine($"[{i}] is ICodeChecker");

                        if (codeChecker.CheckCodeSyntax(vbCode, Language.CSharp_Code))
                        {
                            OutputWriteLine($"\t{vbCode} -> {converter.ConvertToVB(vbCode)}");
                        }
                        else if (codeChecker.CheckCodeSyntax(vbCode, Language.VB_Code))
                        {
                            OutputWriteLine($"\t{vbCode} -> {converter.ConvertToCSharp(vbCode)}");
                        }
                        else
                        {
                            OutputWriteLine("\t{str} - Unknown language");
                        }
                    }
                    else
                    {
                        OutputWriteLine($"[{i}] is not ICodeChecker");
                        OutputWriteLine($"\t{programConverters[i].ConvertToCSharp(vbCode)}");
                        OutputWriteLine($"\t{programConverters[i].ConvertToVB(vbCode)}");
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            OnPropertyChanged(nameof(Output));
        }
示例#3
0
        private static IConvertible[] CreateArray()
        {
            IConvertible[] convertibles = new IConvertible[8];
            for (int i = 0; i < convertibles.Length; i++)
            {
                if (i < 4)
                {
                    convertibles[i] = new ProgramConverter();
                }
                else
                {
                    convertibles[i] = new ProgramHelper();
                }
            }

            return(convertibles);
        }
示例#4
0
        public async Task Save(string path = null)
        {
            if (path == null)
            {
                path = Path.Combine(BasePath, StorageConstants.ProgramCodePath);
            }

            var programConverter = new ProgramConverter();
            var xmlProgram       = programConverter.Convert(this);

            var xmlString = xmlProgram.ToXmlString();

            using (var storage = StorageSystem.GetStorage())
            {
                await storage.WriteTextFileAsync(path, xmlString);
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            ProgramConverter[] pc = new ProgramConverter[3];

            pc[0] = new ProgramHelper();
            pc[1] = new ProgramConverter();
            pc[2] = new ProgramConverter();


            string language;
            string str;

            Console.Write("Choose the language (C# or VB): ");
            language = Console.ReadLine();

            Console.WriteLine();

            Console.Write("Input data: ");
            str = Console.ReadLine();

            Console.WriteLine();

            for (int i = 0; i < pc.Length; i++)
            {
                try
                {
                    ((ProgramHelper)pc[i]).CheckCodeSyntax(str, language);

                    if (language == "C#")
                    {
                        Console.WriteLine(pc[i].ConvertToCSharp("Hello"));
                    }

                    else if (language == "VB")
                    {
                        Console.WriteLine(pc[i].ConvertToVB("Hello"));
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine(pc[i].ConvertToCSharp("Hello"));
                    Console.WriteLine(pc[i].ConvertToVB("Hello"));
                }
            }
        }
示例#6
0
        static ProgramConverter[] ProgramConverterGenerator(int length)
        {
            ProgramConverter[] programConverters = new ProgramConverter[length];

            for (int i = 0; i < length; i++)
            {
                if (i % 3 == 0 && i != 0)
                {
                    programConverters[i] = new ProgramHelper();
                }
                else
                {
                    programConverters[i] = new ProgramConverter();
                }
            }

            return(programConverters);
        }
        public async Task <Program> LoadProgramByName(string programName)
        {
            Program program = null;

            try
            {
                ProgramConverter programConverter = new ProgramConverter();
                program = programConverter.Convert(await LoadXmlProgramByName(programName));
            }
            catch (Exception)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            return(program);
        }
示例#8
0
        static void Main(string[] args)
        {
            string someCode = "code ;";

            Console.WriteLine($"Code to perform tests with : {someCode}");
            int size = 2;

            ProgramConverter[] array = new ProgramConverter[size];
            array[0] = new ProgramHelper();
            array[1] = new ProgramConverter();
            for (int i = 0; i < size; i++)
            {
                Console.WriteLine($"\nCurrent index of array is [{i}] : ");
                if (array[i] is ICodeChecker)
                {
                    Console.WriteLine("This object realize ICodeChecker");

                    _IConvertible.IConvertible convertible = array[i];
                    Console.WriteLine(convertible.ConvertToCSharp(someCode) + "\n\t : Converted to CSharp");
                    Console.WriteLine(convertible.ConvertToVB(someCode) + "\n\t : Converted to VB");

                    ICodeChecker codeChecker = (ICodeChecker)array[i];
                    string       result      = codeChecker.CheckCodeSyntax(someCode, "CSharp") switch {
                        true => "Correct code",
                        _ => "Invalid code",
                    };
                    Console.WriteLine(result + " for CSharp");
                    result = codeChecker.CheckCodeSyntax(someCode, "VB") switch {
                        true => "Correct code",
                        _ => "Invalid code",
                    };
                    Console.WriteLine(result + " for VB");
                }
                else
                {
                    Console.WriteLine("This object realize IConvertible");

                    _IConvertible.IConvertible convertible = array[i];
                    Console.WriteLine(convertible.ConvertToCSharp(someCode) + "\n\t : Converted to CSharp");
                    Console.WriteLine(convertible.ConvertToVB(someCode) + "\n\t : Converted to VB");
                }
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            ProgramConverter[] pc = new ProgramConverter[4];

            pc[0] = new ProgramConverter();
            pc[1] = new ProgramConverter();
            pc[2] = new ProgramHelper();
            pc[3] = new ProgramHelper();

            foreach (ProgramConverter item in pc)
            {
                Console.WriteLine(item.ConvertToCSharp("aaa"));
            }


            ProgramHelper ph1 = pc[2] as ProgramHelper;
            ProgramHelper ph2 = pc[0] as ProgramHelper;

            if (ph1 != null)
            {
                ph1.CodeCheckSyntax(pc[0].ConvertToCSharp("aaa"), pc[2].ConvertToCSharp("aaa"));
                Console.WriteLine("PH");
            }
            else
            {
                Console.WriteLine("no PH");
            }
            if (ph2 != null)
            {
                ph2.CodeCheckSyntax(pc[0].ConvertToCSharp("aaa"), pc[2].ConvertToCSharp("aaa"));
                Console.WriteLine("PH");
            }
            else
            {
                Console.WriteLine("no PH");
            }

            Console.ReadLine();
        }
示例#10
0
        static void Main(string[] args)
        {
            const int lengthExample = 4;
            var       programs      = new ProgramConverter[lengthExample];

            programs[0] = new ProgramConverter();
            programs[1] = new ProgramHelper();
            programs[2] = new ProgramConverter();
            programs[3] = new ProgramHelper();

            foreach (var program in programs)
            {
                if (program is ICodeChecker codeChecker)
                {
                    codeChecker.CheckCodeSyntax("string for convert", "C#");
                    program.ConvertToCSharp("string for convert");
                }
                else
                {
                    program.ConvertToCSharp("string for convert to C#");
                    program.ConvertToVB("string for convert to VB");
                }
            }
        }
        public async Task <CheckProgramResult> CheckProgram(string pathToProgramDirectory)
        {
            var pathToProgramCodeFile = Path.Combine(pathToProgramDirectory, StorageConstants.ProgramCodePath);

            XmlProgram    convertedProgram  = null;
            var           checkResult       = new CheckProgramResult();
            PortableImage programScreenshot = null;
            string        programName       = null;
            string        programCode       = null;

            using (var storage = StorageSystem.GetStorage())
            {
                programScreenshot =
                    await storage.LoadImageAsync(Path.Combine(
                                                     pathToProgramDirectory,
                                                     StorageConstants.ProgramManualScreenshotPath)) ??
                    await storage.LoadImageAsync(Path.Combine(
                                                     pathToProgramDirectory,
                                                     StorageConstants.ProgramAutomaticScreenshotPath));

                if (!await storage.FileExistsAsync(pathToProgramCodeFile))
                {
                    checkResult.State = ProgramState.FilesMissing;
                    return(checkResult);
                }
                programCode = await storage.ReadTextFileAsync(pathToProgramCodeFile);
            }

            var converterResult = await CatrobatVersionConverter.
                                  ConvertToXmlVersion(programCode, XmlConstants.TargetIDEVersion);

            if (converterResult.Error != CatrobatVersionConverter.VersionConverterStatus.NoError)
            {
                switch (converterResult.Error)
                {
                case CatrobatVersionConverter.VersionConverterStatus.VersionTooNew:
                    checkResult.State = ProgramState.VersionTooNew;
                    break;

                case CatrobatVersionConverter.VersionConverterStatus.VersionTooOld:
                    checkResult.State = ProgramState.VersionTooOld;
                    break;

                default:
                    checkResult.State = ProgramState.Damaged;
                    break;
                }
                return(checkResult);
            }

            try
            {
                convertedProgram = new XmlProgram(converterResult.Xml);
                programName      = convertedProgram.ProgramHeader.ProgramName;
            }
            catch (Exception)
            {
                checkResult.State         = ProgramState.Damaged;
                checkResult.ProgramHeader = null;
                checkResult.Program       = null;
                return(checkResult);
            }

            try
            {
                ProgramConverter programConverter = new ProgramConverter();
                checkResult.Program = programConverter.Convert(convertedProgram);
                NativeWrapper.SetProject(convertedProgram);
            }
            catch (Exception)
            {
                checkResult.State         = ProgramState.ErrorInThisApp;
                checkResult.ProgramHeader = null;
                checkResult.Program       = null;
                return(checkResult);
            }

            if (programName == null)
            {
                programName = XmlProgramHelper.GetProgramName(converterResult.Xml);
            }

            checkResult.ProgramHeader = new LocalProgramHeader
            {
                Screenshot  = programScreenshot,
                ProjectName = programName,
            };

            checkResult.State = ProgramState.Valid;
            return(checkResult);
        }
示例#12
0
 public void Init()
 {
     _programConverter = new ProgramConverter();
 }
        public async Task<Program> CopyProgram(string sourceProgramName,
            string newProgramName)
        {
            using (var storage = StorageSystem.GetStorage())
            {
                var sourcePath = Path.Combine(StorageConstants.ProgramsPath, sourceProgramName);
                var destinationPath = Path.Combine(StorageConstants.ProgramsPath, newProgramName);

                var counter = 1;
                while (await storage.DirectoryExistsAsync(destinationPath))
                {
                    newProgramName = newProgramName + counter;
                    destinationPath = Path.Combine(StorageConstants.ProgramsPath, newProgramName);
                    counter++;
                }

                await storage.CopyDirectoryAsync(sourcePath, destinationPath);

                var tempXmlPath = Path.Combine(destinationPath, StorageConstants.ProgramCodePath);
                var xml = await storage.ReadTextFileAsync(tempXmlPath);
                var xmlProgram = new XmlProgram(xml)
                {
                    ProgramHeader = {ProgramName = newProgramName}
                };

                var path = Path.Combine(StorageConstants.ProgramsPath, 
                    newProgramName, StorageConstants.ProgramCodePath);
                var programConverter = new ProgramConverter();
                var program = programConverter.Convert(xmlProgram);

                var xmlString = xmlProgram.ToXmlString();
                await storage.WriteTextFileAsync(path, xmlString);
                
                return program;
            }
        }
 public async Task<Program> LoadProgramByName(string programName)
 {
     Program program = null;
     try
     {
         ProgramConverter programConverter = new ProgramConverter();
         program = programConverter.Convert(await LoadXmlProgramByName(programName));
     }
     catch (Exception)
     {
         if (Debugger.IsAttached)
             Debugger.Break();
     }
     return program;
 }
        public async Task<CheckProgramResult> CheckProgram(string pathToProgramDirectory)
        {
            var pathToProgramCodeFile = Path.Combine(pathToProgramDirectory, StorageConstants.ProgramCodePath);

            XmlProgram convertedProgram = null;
            var checkResult = new CheckProgramResult();
            PortableImage programScreenshot = null;
            string programName = null;
            string programCode = null;

            using (var storage = StorageSystem.GetStorage())
            {
                programScreenshot =
                    await storage.LoadImageAsync(Path.Combine(
                    pathToProgramDirectory,
                    StorageConstants.ProgramManualScreenshotPath)) ??
                    await storage.LoadImageAsync(Path.Combine(
                    pathToProgramDirectory,
                    StorageConstants.ProgramAutomaticScreenshotPath));

                if (!await storage.FileExistsAsync(pathToProgramCodeFile))
                {
                    checkResult.State = ProgramState.FilesMissing;
                    return checkResult;
                }
                programCode = await storage.ReadTextFileAsync(pathToProgramCodeFile);                
            }

            var converterResult = await CatrobatVersionConverter.
                ConvertToXmlVersion(programCode, XmlConstants.TargetIDEVersion);

            if (converterResult.Error != CatrobatVersionConverter.VersionConverterStatus.NoError)
            {
                switch (converterResult.Error)
                {
                    case CatrobatVersionConverter.VersionConverterStatus.VersionTooNew:
                        checkResult.State = ProgramState.VersionTooNew;
                        break;
                    case CatrobatVersionConverter.VersionConverterStatus.VersionTooOld:
                        checkResult.State = ProgramState.VersionTooOld;
                        break;
                    default:
                        checkResult.State = ProgramState.Damaged;
                        break;
                }
                return checkResult;
            }

            try
            {
                convertedProgram = new XmlProgram(converterResult.Xml);
                programName = convertedProgram.ProgramHeader.ProgramName;
            }
            catch (Exception)
            {
                checkResult.State = ProgramState.Damaged;
                checkResult.ProgramHeader = null;
                checkResult.Program = null;
                return checkResult;
            }

            try
            {
                ProgramConverter programConverter = new ProgramConverter();
                checkResult.Program = programConverter.Convert(convertedProgram);
                NativeWrapper.SetProject(convertedProgram);
            }
            catch (Exception)
            {
                checkResult.State = ProgramState.ErrorInThisApp;
                checkResult.ProgramHeader = null;
                checkResult.Program = null;
                return checkResult;
            }

            if(programName == null)
                programName = XmlProgramHelper.GetProgramName(converterResult.Xml);

            checkResult.ProgramHeader = new LocalProgramHeader
            {
                Screenshot = programScreenshot,
                ProjectName = programName,
            };

            checkResult.State = ProgramState.Valid;
            return checkResult;
        }