ToXmlString() 공개 메소드

public ToXmlString ( ) : string
리턴 string
        public async Task LoadSampleProgram()
        {
            using (var storage = StorageSystem.GetStorage())
            {
                await storage.DeleteDirectoryAsync("");
            }

            foreach (KeyValuePair<string, string> pair in _sampleProjectNames)
            {
                var projectFileName = pair.Key;
                var projectName = pair.Value;
                var resourcePath = string.Format("SamplePrograms/{0}", projectFileName);

                Stream resourceStream = null;

                try
                {
                    var resourceLoader = ServiceLocator.ResourceLoaderFactory.CreateResourceLoader();
                    resourceStream = await resourceLoader.OpenResourceStreamAsync(ResourceScope.Resources, resourcePath);
                    

                    if (resourceStream != null)
                    {
                        var projectFolderPath = Path.Combine(StorageConstants.ProgramsPath, projectName);

                        using (var storage = StorageSystem.GetStorage())
                        {
                            if (!await storage.DirectoryExistsAsync(projectFolderPath))
                            {
                                await ServiceLocator.ZipService.UnzipCatrobatPackageIntoIsolatedStorage(resourceStream, StorageConstants.ProgramsPath + "/" + projectName);
                            }
                        }

                        using (var storage = StorageSystem.GetStorage())
                        {
                            var textFilePath = Path.Combine(StorageConstants.ProgramsPath, projectName, StorageConstants.ProgramCodePath);
                            var xml = await storage.ReadTextFileAsync(textFilePath);

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


                            var path = Path.Combine(StorageConstants.ProgramsPath,
                                projectFileName, StorageConstants.ProgramCodePath);
                            var xmlString = xmlProgram.ToXmlString();
                            await storage.WriteTextFileAsync(path, xmlString);
                        }
                    }
                }
                catch (Exception)
                {
                    Debugger.Break(); // sample project does not exist: please remove from _sampleProjectNames or add to Core/Resources/SamplePrograms
                }
                finally
                {
                    if (resourceStream != null)
                    {
                        resourceStream.Dispose();
                    }
                }
            }
        }
예제 #2
0
        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;
            }
        }