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); }
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; }