コード例 #1
0
        private static void VerifySerialization(CanvasAppScreen screen, string json, string file, Version docVersion)
        {
            var isJsonFormatted = json.Length > 2 && json[1] == '\r' && json[2] == '\n';
            var newJson         = screen.Serialize(isJsonFormatted
                                               ? Formatting.Indented
                                               : Formatting.None);

            newJson = FixSerializationExceptions(newJson);
            if (json != newJson)
            {
                if (docVersion < MinimumDocVersion)
                {
                    throw new Exception($"The version of the canvas app is too old!  App version {docVersion}.  Minimum Version {MinimumDocVersion}");
                }
                var jsonFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileName(file)) + ".original";
                // ReSharper disable once StringLiteralTypo
                var newJsonFile = Path.Combine(Path.GetDirectoryName(jsonFile), Path.GetFileNameWithoutExtension(jsonFile)) + ".reserialized";
                WriteJsonFileWithFormattedCopy(jsonFile, json);
                WriteJsonFileWithFormattedCopy(newJsonFile, newJson);
                var errorMsg = CreateDiffErrorMsg(json, file, newJson, jsonFile, newJsonFile, false);
                jsonFile    += ".json";
                newJsonFile += ".json";
                errorMsg    += CreateDiffErrorMsg(File.ReadAllText(jsonFile), file, File.ReadAllText(newJsonFile), jsonFile, newJsonFile, true);
                throw new
                      Exception("Unable to re-serialize json to match source!  " + errorMsg);
            }
        }
コード例 #2
0
        private static void ParseControl(CanvasAppScreen screen, IControl control, string directory, AutoValueExtractor autoValueExtractor)
        {
            autoValueExtractor.PushControl(control.Name);
            Directory.CreateDirectory(directory);
            var sb = new StringBuilder();

            // Write out all Rules
            foreach (var rule in control.Rules)
            {
                autoValueExtractor.Extract(rule);
                sb.AppendLine(rule.Property + "(){");
                sb.AppendLine("\t" + rule.InvariantScript.Replace(Environment.NewLine, Environment.NewLine + "\t"));
                sb.AppendLine(EndOfRuleCode + rule.Property + Environment.NewLine);
                rule.InvariantScript = null;
            }

            File.WriteAllText(Path.Join(directory, control.Name) + CodeFileExt, sb.ToString());

            // Create List of Children so the order can be maintained
            var childrenOrder = new List <ChildOrder>();

            // Write out all Children Rules
            foreach (var child in control.Children)
            {
                ParseControl(screen, child, Path.Combine(directory, child.Name), autoValueExtractor);
                childrenOrder.Add(new ChildOrder {
                    Name = child.Name, ChildrenOrder = child.ChildrenOrder
                });
            }

            if (control.Template?.ComponentDefinitionInfo?.Children != null)
            {
                autoValueExtractor.ExtractComponentChildren(control.Template.ComponentDefinitionInfo.Children);
            }

            control.Children      = null;
            control.ChildrenOrder = childrenOrder.Count == 0 ? null : childrenOrder;

            autoValueExtractor.Extract(control);
            File.WriteAllText(Path.Combine(directory, Path.GetFileName(directory)) + DataFileExt,
                              screen.TopParent == control
                                  ? screen.Serialize(Formatting.Indented)
                                  : control.Serialize(Formatting.Indented));

            autoValueExtractor.PopControl();
        }