コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: blockspacer/niveum
        private static OS.Schema Schema()
        {
            if (os != null)
            {
                return(os);
            }
            var osl = new ObjectSchemaLoader();

            foreach (var ObjectSchemaPath in c.SchemaPaths)
            {
                if (Directory.Exists(ObjectSchemaPath))
                {
                    foreach (var f in Directory.GetFiles(ObjectSchemaPath, "*.tree", SearchOption.AllDirectories).OrderBy(s => s, StringComparer.OrdinalIgnoreCase))
                    {
                        osl.LoadType(f);
                    }
                }
                else
                {
                    osl.LoadType(ObjectSchemaPath);
                }
            }
            var oslr = osl.GetResult();

            os = oslr.Schema;
            return(os);
        }
コード例 #2
0
 private static OS.ObjectSchemaLoaderResult GetObjectSchemaLoaderResult()
 {
     if (oslr != null)
     {
         return(oslr);
     }
     oslr = osl.GetResult();
     foreach (var t in oslr.Schema.Types)
     {
         if (t.OnClientCommand)
         {
             var cc = t.ClientCommand;
             if (AsyncAll || AsyncCommands.Contains(cc.FullName()))
             {
                 if (!cc.Attributes.Any(a => a.Key == "Async"))
                 {
                     cc.Attributes.Add(new KeyValuePair <String, List <String> >("Async", new List <String> {
                     }));
                 }
             }
         }
     }
     return(oslr);
 }
コード例 #3
0
        public static void GenerateTypeCompatibilityTreeFile(List <KeyValuePair <String, String> > ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion, String CompatibilityObjectSchemaFile, bool CommunicationOnly = false)
        {
            var HeadObjectSchema = GetObjectSchema();
            var HeadSchema       = HeadObjectSchema.GetSubSchema(HeadObjectSchema.Types.Where(t => (!CommunicationOnly || (t.OnPrimitive || t.OnClientCommand || t.OnServerCommand)) && (t.Version() == "")), new TypeSpec[] { });
            var Versions         = ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion.Select(p =>
            {
                var vosl = new ObjectSchemaLoader();
                if (File.Exists(p.Key))
                {
                    vosl.LoadSchema(p.Key);
                }
                else if (Directory.Exists(p.Key))
                {
                    foreach (var f in Directory.GetFiles(p.Key, "*.tree", SearchOption.AllDirectories).OrderBy(s => s, StringComparer.OrdinalIgnoreCase))
                    {
                        vosl.LoadType(f);
                    }
                }
                else
                {
                    throw new InvalidOperationException("InvalidPath: " + p.Key);
                }
                var Schema = vosl.GetResult().Schema;
                return(new KeyValuePair <String, Schema>(p.Value, Schema.GetSubSchema(Schema.Types.Where(t => (!CommunicationOnly || (t.OnPrimitive || t.OnClientCommand || t.OnServerCommand)) && (t.Version() == "")), new TypeSpec[] { })));
            }).ToList();

            var Comment = ""
                          + @"==========================================================================" + "\r\n"
                          + @"" + "\r\n"
                          + @"  Notice:      This file is automatically generated." + "\r\n"
                          + @"               Please don't modify this file." + "\r\n"
                          + @"" + "\r\n"
                          + @"  SchemaHash: Head 0x" + HeadSchema.GetNonattributed().Hash().ToString("X16") + "\r\n"
                          + String.Join("", Versions.AsEnumerable().Reverse().Select(v => @"              " + v.Key + " 0x" + v.Value.GetNonattributed().Hash().ToString("X16") + "\r\n"))
                          + @"" + "\r\n"
                          + @"==========================================================================" + "\r\n"
            ;

            var DiffGenerator = new ObjectSchemaDiffGenerator();
            var Result        = DiffGenerator.GetCompatibleTypes(Versions.Concat(new List <KeyValuePair <String, Schema> > {
                new KeyValuePair <String, Schema>("", HeadSchema)
            }).ToList());

            var osw      = new ObjectSchemaWriter();
            var Compiled = osw.Write(Result, Comment);

            if (File.Exists(CompatibilityObjectSchemaFile))
            {
                var Original = Txt.ReadFile(CompatibilityObjectSchemaFile);
                if (String.Equals(Compiled, Original, StringComparison.Ordinal))
                {
                    return;
                }
            }
            var Dir = FileNameHandling.GetFileDirectory(CompatibilityObjectSchemaFile);

            if (Dir != "" && !Directory.Exists(Dir))
            {
                Directory.CreateDirectory(Dir);
            }
            Txt.WriteFile(CompatibilityObjectSchemaFile, TextEncoding.UTF8, Compiled);
        }