Exemple #1
0
 public UObject(BinaryReader data, FPackageFileSummary summary, bool pad = true, FObjectExport export = null)
 {
     while (true)
     {
         long  position = data.BaseStream.Position;
         FName fName    = LSerializer.Deserialize <FName>(data);
         fName.Ref(summary);
         if ((string)fName == "None")
         {
             break;
         }
         data.BaseStream.Position = position;
         FPropertyTag fPropertyTag = LSerializer.Deserialize <FPropertyTag>(data);
         data.BaseStream.Position = position;
         fPropertyTag.Ref(summary);
         fPropertyTag = VisitorFactory.Visit(data, fPropertyTag, summary);
         fPropertyTag.Ref(summary);
         Add(fPropertyTag);
     }
     if (pad)
     {
         data.BaseStream.Position += 4L;
     }
     if (export != null)
     {
         ObjectData = VisitorFactory.VisitSubtype(data, export, summary);
     }
 }
Exemple #2
0
        public UObject(BinaryReader data, FPackageFileSummary summary, bool pad = true, FObjectExport export = null)
        {
            while (true)
            {
                var start = data.BaseStream.Position;
#if DEBUG
                CachedPos.Add(start);
#endif

                var name = LSerializer.Deserialize <FName>(data);
                name.Ref(summary);
                if (name == "None")
                {
                    break;
                }
                data.BaseStream.Position = start;

                var tag = LSerializer.Deserialize <FPropertyTag>(data);
                data.BaseStream.Position = start;
                tag.Ref(summary);

                tag = VisitorFactory.Visit(data, tag, summary);
                tag.Ref(summary);
                Add(tag);
            }

            if (pad)
            {
                data.BaseStream.Position += 4;
            }
            if (export != null)
            {
                ObjectData = VisitorFactory.VisitSubtype(data, export, summary);
            }
        }
Exemple #3
0
        private static Dictionary <string, DbUtility> LoadDatabaseList()
        {
            DatabaseList list =
                SerializerProvider.SerializerHelper <DatabaseList> .LoadFromXmlFile(Configer.ServerListFileLocation);

            if (list == null || list.Databases == null || list.Databases.Length == 0)
            {
                throw new DatabaseNotSpecifiedException();
            }

            var hashtable = new Dictionary <string, DbUtility>(list.Databases.Length);

            foreach (DatabaseMajor instance in list.Databases)
            {
                DbUtility database = VisitorFactory.CreateComDataVisitor(instance.Connection.DataProvider.Value);
                database.Provider   = instance.Connection.DataProvider.Value;
                database.DataServer = instance.Connection.DataServer.Value;
                database.DataSource = instance.Connection.DataSource.Value;
                database.UserID     = instance.Connection.DataUserID.Value;
                database.Password   = instance.Connection.DataPassword.Value;
                database.Initialize();
                //TODO:此处应解析Password
                hashtable.Add(instance.Name.ToUpper(), database);
            }

            return(hashtable);
        }
        public static FPropertyTag PropertyVisitor(BinaryReader reader, FPropertyTag baseTag, FPackageFileSummary summary)
        {
            UStructProperty uStructProperty = LSerializer.Deserialize <UStructProperty>(reader);

            uStructProperty.Ref(summary);
            uStructProperty.Struct = (((object)VisitorFactory.VisitStruct(reader, uStructProperty.StructName.Name, summary)) ?? ((object)new UObject(reader, summary, pad: false)));
            return(uStructProperty);
        }
Exemple #5
0
 public EasySpecify()
 {
     ComDataVisitor = VisitorFactory.CreateComDataVisitor();
     if (ComDataVisitor == null || !ComDataVisitor.Initialize())
     {
         throw new Exception("业务实体创建失败");
     }
 }
Exemple #6
0
 private static void ExportDir(string[] actions, string[] files)
 {
     VisitorFactory.LoadVisitors();
     foreach (string filepath in files)
     {
         ProcessFile(actions, filepath);
     }
 }
        public static FPropertyTag PropertyVisitor(BinaryReader reader, FPropertyTag baseTag, FPackageFileSummary summary)
        {
            var instance = LSerializer.Deserialize <UStructProperty>(reader);

            instance.Ref(summary);
            instance.Struct = (object)VisitorFactory.VisitStruct(reader, instance.StructName, summary) ?? new UObject(reader, summary, false, null);
            return(instance);
        }
Exemple #8
0
        public static void TraversePreOrderVisitors()
        {
            var tree = Tree.MakeInner(10, new[] {
                Tree.MakeInner(5, new [] {
                    Tree.MakeLeaf(2),
                    Tree.MakeLeaf(7)
                }),
                Tree.MakeInner(15, new [] {
                    Tree.MakeInner(12, new[] {
                        Tree.MakeLeaf(11)
                    }),
                    Tree.MakeLeaf(14),
                    Tree.MakeLeaf(17)
                })
            });

            var visitorResultsExpected = new[] {
                "visit 10",
                "down 10 0",
                "visit 5",
                "down 5 0",
                "visit 2",
                "up 2",
                "down 5 1",
                "visit 7",
                "up 7",
                "up 5",
                "down 10 1",
                "visit 15",
                "down 15 0",
                "visit 12",
                "down 12 0",
                "visit 11",
                "up 11",
                "up 12",
                "down 15 1",
                "visit 14",
                "up 14",
                "down 15 2",
                "visit 17",
                "up 17",
                "up 15",
                "up 10"
            };

            var visitorResultsActual = new List <string>();

            tree.VisitBidirectional(VisitorFactory.MakeVisitor <Tree <int>, Tree <int>, int>(
                                        t => visitorResultsActual.Add($"visit {t.Key}"),
                                        (t, i) => visitorResultsActual.Add($"down {t.Key} {i}"),
                                        t => visitorResultsActual.Add($"up {t.Key}"))).ToList();

            Assert.Equal(visitorResultsExpected, visitorResultsActual);
        }
Exemple #9
0
        private static void Export(string path)
        {
            Console.WriteLine(path);
            using var assetStream = File.OpenRead(Path.ChangeExtension(path, "uasset"));
            using var expStream   = File.OpenRead(Path.ChangeExtension(path, "uexp"));

            VisitorFactory.LoadVisitors();
            VisitorFactory.SetEnumAsByte();
            var asset = new UAsset(assetStream, expStream);
            var arr   = asset.Summary.Exports.SelectMany(x => x.Objects).Select(x => x.ToDictionary()).ToArray();

            File.WriteAllText(Path.ChangeExtension(path, "json"), JsonConvert.SerializeObject(arr.Length < 2 ? (asset.Summary.Exports.FirstOrDefault()?.Objects.FirstOrDefault()?.ObjectData?.Serialize() ?? arr) : arr, Formatting.Indented, new JsonSerializerSettings
            {
                ContractResolver = new IgnoreDataBinding()
            }));
        }
        public static List <object> GetEntries(int arraySize, FName arrayType, BinaryReader reader, FPackageFileSummary summary)
        {
            var entries = new List <object>();

            if (arrayType == "StructProperty")
            {
                entries.Add(VisitorFactory.VisitEnumerable(reader, arrayType, summary, arraySize));
            }
            else
            {
                for (int i = 0; i < arraySize; ++i)
                {
                    entries.Add(VisitorFactory.VisitEnumerable(reader, arrayType, summary, 1));
                }
            }
            return(entries);
        }
Exemple #11
0
        public static List <object> GetEntries(int arraySize, FName arrayType, BinaryReader reader, FPackageFileSummary summary)
        {
            List <object> list = new List <object>();

            if ((string)arrayType == "StructProperty")
            {
                list.Add(VisitorFactory.VisitEnumerable(reader, arrayType, summary, arraySize));
            }
            else
            {
                for (int i = 0; i < arraySize; i++)
                {
                    list.Add(VisitorFactory.VisitEnumerable(reader, arrayType, summary, 1));
                }
            }
            return(list);
        }
Exemple #12
0
        private static IEnumerable <IGeneratableTypeVisitor> FindVisitors(GeneratorExecutionContext context, AdditionalText additionalText)
        {
            context.AnalyzerConfigOptions
            .GetOptions(additionalText)
            .TryGetValue("build_metadata.graphql.visitors", out string?commaSeparatedVisitors);

            if (string.IsNullOrWhiteSpace(commaSeparatedVisitors))
            {
                return(VisitorFactory.CreateAll());
            }

            var userDefinedVisitors = commaSeparatedVisitors !
                                      .Trim()
                                      .Split(',')
                                      .Select(visitorName => visitorName.Trim());

            return(userDefinedVisitors.Select(VisitorFactory.Create));
        }
Exemple #13
0
 public override void BSerialize(BinaryWriter writer, FPackageFileSummary summary)
 {
     if ((string)ArrayType == "StructProperty")
     {
         VisitorFactory.WriteEnumerable(writer, ArrayType, summary, Entries.First(), ArraySize);
     }
     else
     {
         if (Entries.Count <= 0)
         {
             return;
         }
         foreach (object entry in Entries)
         {
             VisitorFactory.WriteEnumerable(writer, ArrayType, summary, entry, ArraySize);
         }
     }
 }
Exemple #14
0
        public HomeController(VisitorFactory visitorBuilderFactory, IMapper mapper, MongoComponentStrategy mongoComponentStrategy, RedisComponentStrategy redisComponentStrategy, MongoConfigConditStrategy mongoConfigConditsStrategy, RedisConfigConditStrategy redisConfigConditStrategy, MongoComponentHistoryStrategy componentHistoryStrategy, MongoConditionHistoryStrategy conditionHistoryStrategy)
        {
            _visitorFactory             = visitorBuilderFactory;
            _mapper                     = mapper;
            _mongoComponentStrategy     = mongoComponentStrategy;
            _redisComponentStrategy     = redisComponentStrategy;
            _mongoConfigConditsStrategy = mongoConfigConditsStrategy;
            _redisConfigConditsStrategy = redisConfigConditStrategy;
            _componentHistoryStrategy   = componentHistoryStrategy;
            _conditionHistoryStrategy   = conditionHistoryStrategy;

            _componentHome = new MongoStrategyParams {
                Database = "Component", Collection = "Home"
            };
            _conditionDefined = new MongoStrategyParams {
                Database = "Condition", Collection = "Defined"
            };
            _componentHistoryHomeUndo = new MongoStrategyParams {
                Database = "ComponentHistory", Collection = "HomeUndo", StackSize = 10
            };
            _componentHistoryHomeRedo = new MongoStrategyParams {
                Database = "ComponentHistory", Collection = "HomeRedo", StackSize = 10
            };
            _conditionHistoryHomeUndo = new MongoStrategyParams {
                Database = "ConditionHistory", Collection = "DefinedUndo", StackSize = 10
            };
            _conditionHistoryHomeRedo = new MongoStrategyParams {
                Database = "ConditionHistory", Collection = "DefinedRedo", StackSize = 10
            };
            _cacheHome = new RedisStrategyParams {
                Cachekey = "Home"
            };
            _cacheCondit = new RedisStrategyParams {
                Cachekey = "DefinedCondition"
            };
        }
Exemple #15
0
 void Awake()
 {
     m_instance = this;
 }
Exemple #16
0
        static void Main(string[] args)
        {
            var people = new List <Person>();

            people.Add(new Employee()
            {
                Name = "Frank"
            });
            people.Add(new Employee()
            {
                Name = "Rob"
            });
            people.Add(new Employee()
            {
                Name = "Joe"
            });
            people.Add(new Director()
            {
                Name = "Andy"
            });
            people.Add(new Director()
            {
                Name = "Barry", GolfPartner = "Fabio"
            });
            people.Add(new Employee()
            {
                Name = "Stuart"
            });


            int employeeCountByVisitor = 0;

            // Since ConcreteVisitor already implements IPersonVisitor, these statements should generate the same IL
            var concreteVisitor = VisitorFactory <IPersonVisitor> .Create(new ConcreteVisitor());

            concreteVisitor = new ConcreteVisitor();

            // Anonymous classes provide their implementations by way of Action<> delegates
            // The name of the properties is not important
            var anonymousVisitor = VisitorFactory <IPersonVisitor> .Create(new
            {
                Employee = new Action <Employee>(e => employeeCountByVisitor++),
                Director = new Action <Director>(d =>
                {
                    d.PlayGolf();
                })
            }, ActionOnMissing.NoOp);

            // Concrete classes can also provide implementations by way of Action<> delegates
            // Use caution, as any properties of type Action<> that match a Visit method in the given interface will be wired up as implementation
            var concreteDelegate = VisitorFactory <IPersonVisitor> .Create(new ConcreteDelegate()
            {
                Employee = new Action <Employee>(e => employeeCountByVisitor++)
            });

            // If for some reason you want to, you can use VisitorFactory to inject visitor interfaces into concrete classes with methods
            // At the moment, this will take the first method that matches the required signature, regardless of name.
            // This will probably change in future.
            var concreteDuck = VisitorFactory <IPersonVisitor> .Create(new ConcreteDuck());

            // In the case where a concrete class has a method and a Action<> delegate that both match, the method trumps the delegate
            var delegateDuck = VisitorFactory <IPersonVisitor> .Create(new DelegateDuck()
            {
                Employee = new Action <Employee>(e => employeeCountByVisitor++),
                Director = new Action <Director>(director =>
                {
                    director.PlayGolf();
                })
            });

            foreach (var person in people)
            {
                person.Accept(delegateDuck);
            }

            Console.WriteLine($"There are {employeeCountByVisitor} employees.");
            Console.Read();
        }
 public MongoComponentStrategy(IMongoClient mongoClient, VisitorFactory visitorFactory)
 {
     MongoClient     = mongoClient;
     _visitorFactory = visitorFactory;
 }
 public ListSerializer(VisitorFactory <Stream> visitorFactory)
 {
     this.visitorFactory = visitorFactory;
 }
 private void InitializeUassetWriteMode()
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
     VisitorFactory.LoadVisitors();
     UAsset.Options = new UAParserOptions(forceArrays: true, newEntries: true);
 }
Exemple #20
0
        public void GetterSetter()
        {
            VisitorFactory <StringBuilder> visitorFactory =
                new VisitorFactory <StringBuilder>(
                    type =>
            {
                if (typeof(Rectangle).IsAssignableFrom(type))
                {
                    return(new ProcessObject <StringBuilder, Rectangle>(
                               (sb, rectangle) =>
                    {
                        sb.Append("Rectangle;");
                        return VisitStatus.Continue;
                    }));
                }
                if (typeof(string).IsAssignableFrom(type))
                {
                    return(new ProcessObject <StringBuilder, string>(
                               (sb, @string) =>
                    {
                        sb.Append($"string:{@string};");
                        return VisitStatus.Continue;
                    }));
                }
                if (typeof(int).IsAssignableFrom(type))
                {
                    return(new ProcessObject <StringBuilder, int>(
                               (sb, @int) =>
                    {
                        sb.Append($"int:{@int};");
                        return VisitStatus.Continue;
                    }));
                }
                return(MustVisitStatus.No);
            },
                    property =>
            {
                if (typeof(string).IsAssignableFrom(property.GetMethod.ReturnType))
                {
                    return(new StringFieldProcessor(property).Call(property.DeclaringType));
                }
                if (typeof(int).IsAssignableFrom(property.GetMethod.ReturnType))
                {
                    return(new IntFieldProcessor(property).Call(property.DeclaringType));
                }
                return(MustVisitStatus.No);
            });

            var visitor = visitorFactory.GetClassVisitor <Pair <Pair <Rectangle, Circle>, string> >();
            Pair <Pair <Rectangle, Circle>, string> data =
                new Pair <Pair <Rectangle, Circle>, string>(
                    new Pair <Rectangle, Circle>(
                        new Rectangle {
                Length = 1, Width = 2
            },
                        new Circle {
                center = new Pair <int, int>(1, 2), radius = 4
            }),
                    "abcdef");
            var sb = new StringBuilder();

            visitor.Visit(sb, data);
            Assert.Equal(
                "Rectangle;Rectangle.Length=int:1;int:1;Rectangle.Width=int:2;int:2;Pair`2.Second=string:abcdef;string:abcdef;",
                sb.ToString());
        }
 public ListDeserializer(VisitorFactory <DeserializeContext> visitorFactory)
 {
     this.visitorFactory = visitorFactory;
 }
Exemple #22
0
        public void add(string name, DateTime dob, string email, string phoneNumber)
        {
            Visitor v = VisitorFactory.create(name, dob, email, phoneNumber);

            VisitorRepository.add(v);
        }