public static (CanvasDocument, ErrorContainer) LoadFromMsapp(Stream streamToMsapp)
        {
            var errors = new ErrorContainer();
            var doc    = Wrapper(() => MsAppSerializer.Load(streamToMsapp, errors), errors);

            return(doc, errors);
        }
        public ErrorContainer SaveToMsApp(string fullPathToMsApp)
        {
            var errors = new ErrorContainer();

            Wrapper(() => MsAppSerializer.SaveAsMsApp(this, fullPathToMsApp, errors), errors);
            return(errors);
        }
Exemple #3
0
        public FileEntry ToMsAppFile()
        {
            var file = MsAppSerializer.ToFile(FileKind.Unknown, this.Value);

            file.Name = this.GetMsAppFilename();

            return(file);
        }
        // Used to validate roundtrip after unpack
        internal ErrorContainer SaveToMsAppValidation(string fullPathToMsApp)
        {
            Utilities.EnsurePathRooted(fullPathToMsApp);

            var errors = new ErrorContainer();
            Wrapper(() => MsAppSerializer.SaveAsMsApp(this, fullPathToMsApp, errors, isValidation: true), errors);
            return errors;
        }
        public ErrorContainer SaveToMsApp(string fullPathToMsApp)
        {
            Utilities.EnsurePathRooted(fullPathToMsApp);

            var errors = new ErrorContainer();
            Wrapper(() => MsAppSerializer.SaveAsMsApp(this, fullPathToMsApp, errors), errors);
            return errors;
        }
Exemple #6
0
        // Given an msapp (original source of truth), stress test the conversions
        public static bool StressTest(string pathToMsApp)
        {
            try
            {
                using (var temp1 = new TempFile())
                {
                    string outFile = temp1.FullPath;

                    var log = TextWriter.Null;

                    // MsApp --> Model
                    CanvasDocument msapp;
                    ErrorContainer errors = new ErrorContainer();
                    try
                    {
                        msapp = MsAppSerializer.Load(pathToMsApp, errors); // read
                        errors.ThrowOnErrors();
                    }
                    catch (NotSupportedException)
                    {
                        errors.FormatNotSupported($"Too old: {pathToMsApp}");
                        return(false);
                    }

                    // Model --> MsApp
                    errors = msapp.SaveToMsApp(outFile);
                    errors.ThrowOnErrors();
                    var ok = MsAppTest.Compare(pathToMsApp, outFile, log);
                    if (!ok)
                    {
                        return(false);
                    }


                    // Model --> Source
                    using (var tempDir = new TempDir())
                    {
                        string outSrcDir = tempDir.Dir;
                        errors = msapp.SaveToSources(outSrcDir);
                        errors.ThrowOnErrors();

                        // Source --> Model
                        (var msapp2, var errors2) = CanvasDocument.LoadFromSources(outSrcDir);
                        errors2.ThrowOnErrors();

                        errors2 = msapp2.SaveToMsApp(outFile); // Write out .pa files.
                        errors2.ThrowOnErrors();
                        var ok2 = MsAppTest.Compare(pathToMsApp, outFile, log);
                        return(ok2);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
Exemple #7
0
        // Given an msapp (original source of truth), stress test the conversions
        public static bool StressTest(string pathToMsApp)
        {
            try
            {
                using (var temp1 = new TempFile())
                {
                    string outFile = temp1.FullPath;

                    var log = TextWriter.Null;

                    // MsApp --> Model
                    CanvasDocument msapp;
                    ErrorContainer errors = new ErrorContainer();
                    try
                    {
                        using (var stream = new FileStream(pathToMsApp, FileMode.Open))
                        {
                            msapp = MsAppSerializer.Load(stream, errors);
                        }
                        errors.ThrowOnErrors();
                    }
                    catch (NotSupportedException)
                    {
                        errors.FormatNotSupported($"Too old: {pathToMsApp}");
                        return(false);
                    }

                    // Model --> MsApp
                    errors = msapp.SaveToMsApp(outFile);
                    errors.ThrowOnErrors();
                    var ok = MsAppTest.Compare(pathToMsApp, outFile, log);
                    if (!ok)
                    {
                        return(false);
                    }


                    // Model --> Source
                    using (var tempDir = new TempDir())
                    {
                        string outSrcDir = tempDir.Dir;
                        errors = msapp.SaveToSources(outSrcDir, verifyOriginalPath: pathToMsApp);
                        errors.ThrowOnErrors();
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
        /// <summary>
        /// Load an .msapp file for a Canvas Document.
        /// </summary>
        /// <param name="fullPathToMsApp">path to an .msapp file</param>
        /// <returns>A tuple of the document and errors and warnings. If there are errors, the document is null.  </returns>
        public static (CanvasDocument, ErrorContainer) LoadFromMsapp(string fullPathToMsApp)
        {
            var errors = new ErrorContainer();

            if (!fullPathToMsApp.EndsWith(".msapp", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException("Only works for .msapp files");
            }

            using (var stream = new FileStream(fullPathToMsApp, FileMode.Open))
            {
                var doc = Wrapper(() => MsAppSerializer.Load(stream, errors), errors);
                return(doc, errors);
            }
        }
        /// <summary>
        /// Load an .msapp file for a Canvas Document.
        /// </summary>
        /// <param name="fullPathToMsApp">path to an .msapp file</param>
        /// <returns>A tuple of the document and errors and warnings. If there are errors, the document is null.  </returns>
        public static (CanvasDocument, ErrorContainer) LoadFromMsapp(string fullPathToMsApp)
        {
            var errors = new ErrorContainer();

            Utilities.EnsurePathRooted(fullPathToMsApp);

            if (!fullPathToMsApp.EndsWith(".msapp", StringComparison.OrdinalIgnoreCase))
            {
                errors.BadParameter("Only works for .msapp files");
            }

            Utilities.VerifyFileExists(errors, fullPathToMsApp);
            if (errors.HasErrors)
            {
                return(null, errors);
            }

            using (var stream = new FileStream(fullPathToMsApp, FileMode.Open))
            {
                var doc = Wrapper(() => MsAppSerializer.Load(stream, errors), errors);
                return(doc, errors);
            }
        }
        // Given an msapp (original source of truth), stress test the conversions
        public static bool StressTest(string pathToMsApp)
        {
            try
            {
                using (var temp1 = new TempFile())
                {
                    string outFile = temp1.FullPath;

                    var log = TextWriter.Null;

                    // MsApp --> Model
                    CanvasDocument msapp;
                    ErrorContainer errors = new ErrorContainer();
                    try
                    {
                        using (var stream = new FileStream(pathToMsApp, FileMode.Open))
                        {
                            msapp = MsAppSerializer.Load(stream, errors);
                        }
                        errors.Write(log);
                        errors.ThrowOnErrors();

                        // We can still get warnings here. Commonly:
                        // - PA2001, checksum mismatch
                        // - PA2999, colliding asset names
                    }
                    catch (NotSupportedException)
                    {
                        errors.FormatNotSupported($"Too old: {pathToMsApp}");
                        return(false);
                    }

                    // Model --> MsApp
                    errors = msapp.SaveToMsApp(outFile);
                    errors.ThrowOnErrors();
                    var ok = MsAppTest.Compare(pathToMsApp, outFile, log);
                    if (!ok)
                    {
                        return(false);
                    }


                    // Model --> Source
                    using (var tempDir = new TempDir())
                    {
                        string outSrcDir = tempDir.Dir;
                        errors = msapp.SaveToSources(outSrcDir, verifyOriginalPath: pathToMsApp);
                        errors.ThrowOnErrors();
                    }
                } // end using

                if (!MsAppTest.TestClone(pathToMsApp))
                {
                    return(false);
                }

                if (!MsAppTest.DiffStressTest(pathToMsApp))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }

            return(true);
        }