Exemple #1
0
        public void ClassProxyGeneratorForNestedClasses()
        {
            var nestedClassDescription = new ClassDescription(
                "NestedClass",
                null,
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription>(),
                new List <string>(),
                new List <ClassDescription>(),
                isNested: true);

            var mainClassDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription>(),
                new List <string>(),
                new List <ClassDescription> {
                nestedClassDescription
            },
                isNested: false);

            var libraryDescripton = new LibraryDescription("MyLibrary", new Dictionary <string, ClassDescription>());

            libraryDescripton.AddClassDescription(mainClassDescription,
                                                  "packageName.MyClass");

            libraryDescripton.AddClassDescription(nestedClassDescription, "packageName.MyClass$NestedClass");

            var classProxyGenerator = new MockClassProxyGenerator();

            new LibraryProxyGenerator(classProxyGenerator).Generate(libraryDescripton);
        }
Exemple #2
0
        public void CallClassProxyGeneratorForDependencies()
        {
            var dependenciesClasses   = new List <ClassDescription>();
            var dependenciesFullNames = new List <string>
            {
                "packageName.DependenceClass0",
                "packageName.DependenceClass1",
                "packageName.DependenceClass2"
            };

            for (int i = 0; i < 3; i++)
            {
                var dependence = new ClassDescription(
                    $"DependenceClass{i}",
                    "packageName",
                    new List <ModifierDescription>(),
                    new List <FieldDescription>(),
                    new List <MethodDescription>(),
                    new List <string>(),
                    new List <ClassDescription>(),
                    isNested: false);

                dependenciesClasses.Add(dependence);
            }

            var mainClassDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription>(),
                dependenciesFullNames,
                new List <ClassDescription>(),
                isNested: false);

            var libraryDescripton = new LibraryDescription("MyLibrary", new Dictionary <string, ClassDescription>());

            libraryDescripton.AddClassDescription(mainClassDescription,
                                                  "packageName.MyClass");
            for (int i = 0; i < 3; i++)
            {
                libraryDescripton.AddClassDescription(dependenciesClasses[i], dependenciesFullNames[i]);
            }

            var classProxyGenerator = new MockClassProxyGenerator();

            new LibraryProxyGenerator(classProxyGenerator).Generate(libraryDescripton);

            Assert.AreEqual(4, classProxyGenerator.CallsArguments.Count, "A lot of classes was proxy");
            Assert.AreEqual(
                "packageName.MyClass",
                libraryDescripton.GetFullName(classProxyGenerator.CallsArguments[0]),
                "ClassProxyGenerator call order incorrect");

            for (int i = 1; i < 4; i++)
            {
                var name = libraryDescripton.GetFullName(classProxyGenerator.CallsArguments[i]);
                Assert.AreEqual(dependenciesFullNames[i - 1], name, "ClassProxyGenerator call order incorrect");
            }
        }
Exemple #3
0
        private void AddClassToNamespaceUnits(
            LibraryDescription libraryDescription,
            MemberDeclarationSyntax classProxy,
            ClassDescription classDescription,
            IDictionary <string, NamespaceUnit> namespaceUnits)
        {
            var packageName = classDescription.PackageName;

            if (!namespaceUnits.ContainsKey(packageName))
            {
                namespaceUnits[packageName] = new NamespaceUnit(packageName);
            }

            var newDeclaration = namespaceUnits[packageName]
                                 .NamespaceDeclaration
                                 .AddMembers(classProxy);

            namespaceUnits[packageName].NamespaceDeclaration = newDeclaration;

            var serviceUsings = new[]
            {
                "J4Net.Core",
                "J4Net.Core.JNICore.Interface"
            };

            var usings = classDescription
                         .DependenciesNames
                         .Select(libraryDescription.GetClassDescription)
                         .Select(el => el.PackageName)
                         .Where(el => el != classDescription.PackageName)
                         .Concat(serviceUsings)
                         .Select(el => SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName(el)));

            namespaceUnits[packageName].Usings.AddRange(usings);
        }
        public void GenerateClassWithNested()
        {
            var nestedClassDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription>(),
                new List <string>(),
                new List <ClassDescription>(),
                isNested: true);

            var classDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription>(),
                new List <string>(),
                new List <ClassDescription> {
                nestedClassDescription
            },
                isNested: false);

            var classDeclaration = classProxyGenerator.Generate(classDescription);

            TestBase.CheckNestedClasses(new HashSet <string>(), classDeclaration);
        }
Exemple #5
0
        ClassDescription ReadClassDescription()
        {
            ClassDescription desc     = default(ClassDescription);
            byte             typeCode = reader.ReadByte();

            if (typeCode == TC_NULL)
            {
                return(desc);
            }
            if (typeCode != TC_CLASSDESC)
            {
                ParseError(TC_CLASSDESC, typeCode);
            }

            desc.ClassName = ReadString();
            reader.ReadUInt64();           // serial version UID
            reader.ReadByte();             // flags
            FieldDescription[] fields = new FieldDescription[ReadInt16()];
            for (int i = 0; i < fields.Length; i++)
            {
                fields[i] = ReadFieldDescription();
            }
            desc.Fields = fields;

            typeCode = reader.ReadByte();
            if (typeCode != TC_ENDBLOCKDATA)
            {
                ParseError(TC_ENDBLOCKDATA, typeCode);
            }
            ReadClassDescription();             // super class description
            return(desc);
        }
Exemple #6
0
        // If we keep the library as a global variable, we can
        // cache data like property descriptions and column headings
        public void BindToLib(IObjectStore oNewLib, Collection pColHeadings, string sClass)
        {
            string[] sClasses = new string[2];

            sClasses[0] = sClass;
            oQueryLib   = oNewLib;
            //oPropDescs = (IDMObjects.PropertyDescriptions)oQueryLib.FilterPropertyDescriptions(IDMObjects.idmObjectType.idmObjTypeDocument, sClasses);
            IClassDescription objClassDesc = ClassDescription.FetchInstance(oNewLib, sClass, null); //(IDMObjects.idmObjectType.idmObjTypeDocument, sClasses);

            oPropDescs = objClassDesc.PropertyDescriptions;
            int oTmp = 0;
            //for (int oTmp = 0 To oPropDescs.Count )
            //foreach (object oTmp in pColHeadings.Count)
            {
                // Weed out any bogus labels the caller passed us
                //FSQ20070509. Changed by try..catch
                //On Error Resume Next;
                try
                {
                    //Microsoft.VisualBasic.Collection.KeyValuePair otemp2 =((Microsoft.VisualBasic.Collection.KeyValuePair)oTmp);
                    if (oPropDescs[oTmp] != null)
                    {
                        cColHeadings.Add(oTmp, null, null, null);
                    }
                }
                catch
                {
                    try
                    {
                        cColHeadings.Add(oTmp, null, null, null);
                    }
                    catch { }
                }
            }
        }
Exemple #7
0
        /// <summary>
        ///     获取值的类型
        /// </summary>
        /// <param name="type">值类型</param>
        /// <param name="id">如果是列表页面需要传入ID,编辑页面不需要传入</param>
        public object GetValue(Type type, Guid id)
        {
            var report = GetReport(type.FullName);
            var values = new List <object>();
            var data   = Activator.CreateInstance(type);

            if (report != null)
            {
                var reportDescription = new ClassDescription(data.GetType());
                if (reportDescription.ClassPropertyAttribute.PageType == ViewPageType.List)
                {
                    var request = JsonConvert.DeserializeObject <List <JObject> >(report.Value);
                    foreach (var item in request)
                    {
                        PropertyDescription.SetValue(data, item);
                        if (data.GetType().GetProperty("Id").GetValue(data).ToString() == id.ToString())
                        {
                            return(data);
                        }
                    }
                }
                else
                {
                    var request = JsonConvert.DeserializeObject <JObject>(report.Value);
                    PropertyDescription.SetValue(data, request);
                    return(data);
                }

                return(Activator.CreateInstance(type));
            }

            return(Activator.CreateInstance(type));
        }
        public void GenerateMethodWithArgs()
        {
            var methodDescription = new MethodDescription(
                "myMethod",
                new List <ModifierDescription> {
                ModifierDescription.PUBLIC,
                ModifierDescription.STATIC
            },
                new List <ParameterDescription>
            {
                new ParameterDescription("arg0", "string[]"),
                new ParameterDescription("arg1", "int"),
                new ParameterDescription("arg31", "MyType")
            },
                "void"
                );

            var classDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription> {
                methodDescription
            },
                new List <string>(),
                new List <ClassDescription>(),
                isNested: false);

            var classDeclaration = classProxyGenerator.Generate(classDescription);
            var method           = classDeclaration.Members[0] as MethodDeclarationSyntax;

            TestBase.CheckParameters(methodDescription.Name, methodDescription.ParametersDescription,
                                     method.ParameterList.Parameters);
        }
Exemple #9
0
        /// <summary>
        ///     HttpContext表单数据,转换成扩展数据
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="type">The 类型.</param>
        /// <param name="value">The HTTP context.</param>
        public static object HttpContextToExtension(object instance, Type type, string value)
        {
            // Json
            var classDescription = new ClassDescription(type);
            //获取有枚举的属性
            var propertys    = classDescription.Propertys.Where(r => !r.FieldAttribute.ExtensionJson.IsNullOrEmpty());
            var propertyInfo = type.GetPropertiesFromCache();

            foreach (var item in propertyInfo)
            {
                var property = propertys.FirstOrDefault(r => r.Name == item.Name);

                if (property != null)
                {
                    if (!value.IsNullOrEmpty())
                    {
                        var extesionName   = property.FieldAttribute.ExtensionJson;
                        var extensionField = propertyInfo.FirstOrDefault(r => r.Name == extesionName);
                        if (!extensionField.IsNullOrEmpty())
                        {
                            if (extensionField != null)
                            {
                                //设置值
                                var extesionValue = JsonConvert.DeserializeObject(value, extensionField.PropertyType);
                                extensionField.SetValue(instance, extesionValue);
                            }
                        }
                    }
                }
            }

            return(instance);
        }
        public void MarkVirtualNotPublicStaticFinalMethods()
        {
            var methodDescription = new MethodDescription(
                "myMethod",
                new List <ModifierDescription> {
                ModifierDescription.PROTECTED
            },
                new List <ParameterDescription>(),
                "void"
                );

            var classDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription> {
                methodDescription
            },
                new List <string>(),
                new List <ClassDescription>(),
                isNested: false);

            var classDeclaration = classProxyGenerator.Generate(classDescription);
            var method           = classDeclaration.Members[0] as MethodDeclarationSyntax;

            TestBase.CheckModifiers(new HashSet <string> {
                "protected", "virtual"
            }, method.Modifiers);
        }
        public void MethodBodyGetterCall()
        {
            var methodDescription = new MethodDescription(
                "myMethod",
                new List <ModifierDescription> {
                ModifierDescription.PUBLIC
            },
                new List <ParameterDescription>(),
                "void"
                );

            var classDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription> {
                methodDescription
            },
                new List <string>(),
                new List <ClassDescription>(),
                isNested: false);

            var methodBodyGetter    = new MockMethodBodyGetter();
            var classProxyGenerator = new ClassProxyGenerator(methodBodyGetter);

            classProxyGenerator.Generate(classDescription);

            Assert.AreEqual(1, methodBodyGetter.CallsCount);
            Assert.AreEqual("myMethod", methodBodyGetter.CallArgumentName);
        }
        public void SetUp()
        {
            string namespaceStr = "Namespace.SubNamespace";
            string nameStr      = "ClassName";
            List <PropertyDescription> properties = new List <PropertyDescription>
            {
                new PropertyDescription("Property1", "long", false),
                new PropertyDescription("Property2", "string", true),
                new PropertyDescription("Property3", "bool", true)
            };

            List <FunctionDescription> functions = new List <FunctionDescription>
            {
                new FunctionDescription("Method1", "Object", new List <string>()),
                new FunctionDescription("Method2", "void", new List <string>
                {
                    "string",
                    "int",
                    "bool"
                }),
            };

            ClassDescription cd = new ClassDescription(
                nameStr,
                namespaceStr,
                properties,
                functions);

            _classGenerator = new ClassGenerator(cd);
        }
Exemple #13
0
        public void MarkVirtualNotPublicStaticFinalMethods()
        {
            var methodDescription = new MethodDescription(
                "myMethod",
                new List <ModifierDescription> {
                ModifierDescription.PROTECTED
            },
                new List <ParameterDescription>(),
                "void",
                isConstructor: false
                );

            var classDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription> {
                methodDescription
            },
                new List <string>(),
                new List <ClassDescription>(),
                isNested: false);

            var classDeclaration = classProxyGenerator.Generate(classDescription);
            var method           = GetFirstMethod(classDeclaration);

            Assert.AreNotEqual(null, method, "Class doesn't exist any methods");
            TestBase.CheckModifiers(new HashSet <string> {
                "protected", "virtual"
            }, method.Modifiers);
        }
Exemple #14
0
        internal IPropertyDescriptionList getPropertiesDescriptions(IObjectStore oLibrary, string[] asClasses)
        {
            IClassDescription objClassDesc = ClassDescription.FetchInstance(oLibrary, asClasses[0], null);

            //IClassDescription objClassDesc = ClassDescription.FetchInstance(oLibrary, "Document", null);
            return(objClassDesc.PropertyDescriptions);
        }
        public void GenerateClassWithMethod()
        {
            var methodDescription = new MethodDescription(
                "myMethod",
                new List <ModifierDescription> {
                ModifierDescription.PUBLIC
            },
                new List <ParameterDescription>(),
                "void"
                );

            var classDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription> {
                methodDescription
            },
                new List <string>(),
                new List <ClassDescription>(),
                isNested: false);

            var classDeclaration = classProxyGenerator.Generate(classDescription);

            TestBase.CheckMethods(classDeclaration, new List <MethodDescription> {
                methodDescription
            });
        }
Exemple #16
0
        public byte[] Load(Stream stream, Game game, out int width, out int height, out int length)
        {
            byte[] map = null;
            width  = 0;
            height = 0;
            length = 0;
            LocalPlayer p = game.LocalPlayer;

            p.Spawn = Vector3.Zero;
            GZipHeaderReader gsHeader = new GZipHeaderReader();

            while (!gsHeader.ReadHeader(stream))
            {
            }

            using (DeflateStream s = new DeflateStream(stream)) {
                reader = new BinaryReader(s);
                if (ReadInt32() != 0x271BB788 || reader.ReadByte() != 0x02)
                {
                    throw new InvalidDataException("Unexpected constant in .dat file");
                }

                ClassDescription obj = ReadData();
                for (int i = 0; i < obj.Fields.Length; i++)
                {
                    FieldDescription field = obj.Fields[i];
                    if (field.FieldName == "width")
                    {
                        width = (int)field.Value;
                    }
                    else if (field.FieldName == "height")
                    {
                        length = (int)field.Value;
                    }
                    else if (field.FieldName == "depth")
                    {
                        height = (int)field.Value;
                    }
                    else if (field.FieldName == "blocks")
                    {
                        map = (byte[])field.Value;
                    }
                    else if (field.FieldName == "xSpawn")
                    {
                        p.Spawn.X = (int)field.Value;
                    }
                    else if (field.FieldName == "ySpawn")
                    {
                        p.Spawn.Y = (int)field.Value;
                    }
                    else if (field.FieldName == "zSpawn")
                    {
                        p.Spawn.Z = (int)field.Value;
                    }
                }
            }
            return(map);
        }
        private static CSharpCompilation CompileEmptyClass(SyntaxTree tree, string namespaceName, string className)
        {
            var description    = new ClassDescription(className, namespaceName, new PropertyDescription[] { }, new FunctionDescription[] { });
            var generator      = new ClassGenerator(description);
            var emptyClassStub = generator.GenerateClass();
            var stubTree       = CSharpSyntaxTree.ParseText(emptyClassStub);

            return(new[] { tree, stubTree }.Compile());
        }
Exemple #18
0
        /// <summary>
        ///     获取值的类型
        /// </summary>
        /// <param name="type">值类型</param>
        /// <param name="id">如果是列表页面需要传入ID,编辑页面不需要传入</param>
        public object GetValue(Type type, Guid id)
        {
            var config = GetConfig(type.FullName);
            var data   = Activator.CreateInstance(type);

            // 如果包含Id的字段
            var idField = type.GetProperty("Id");

            if (idField != null)
            {
                if (id.IsGuidNullOrEmpty())
                {
                    return(data);
                }
            }

            if (config != null)
            {
                var configDescription = new ClassDescription(data.GetType());
                var classDescription  = new ClassDescription(type);
                //获取  Json有扩展的属性
                var propertys = classDescription.Propertys.Where(r => !r.FieldAttribute.ExtensionJson.IsNullOrEmpty())
                                .ToList();

                if (configDescription.ClassPropertyAttribute.PageType == ViewPageType.List)
                {
                    var request = JsonConvert.DeserializeObject <List <JObject> >(config.Value);
                    foreach (var item in request)
                    {
                        PropertyDescription.SetValue(data, item);
                        if (data.GetType().GetProperty("Id").GetValue(data).ToString() == id.ToString())
                        {
                            if (propertys.Any())
                            {
                                // json 格式数据处理
                                data = item.ToObject(type);
                                return(data);
                            }

                            return(data);
                        }
                    }
                }
                else
                {
                    var request = JsonConvert.DeserializeObject <JObject>(config.Value);
                    PropertyDescription.SetValue(data, request);
                    //  data = JsonMapping.HttpContextToExtension(data, type, HttpContext);
                    return(data);
                }

                return(Activator.CreateInstance(type));
            }

            return(Activator.CreateInstance(type));
        }
Exemple #19
0
 /// <summary>
 ///     通过完整的命名空间获取属性值
 /// </summary>
 /// <param name="fullName">输入完整的命名空间</param>
 public IEnumerable <PropertyDescription> GetAllPropertys(string fullName)
 {
     try {
         var t = fullName.GetTypeByFullName();
         var configDescription = new ClassDescription(t);
         return(configDescription.Propertys.ToList());
     } catch {
         return(null);
     }
 }
        public static ClassDescription GenerateDescriptionForMethod()
        {
            var methods = new List <MethodDescription>()
            {
                new MethodDescription(
                    "getName",
                    new List <ModifierDescription>()
                {
                    ModifierDescription.PUBLIC
                },
                    new List <ParameterDescription>(),
                    "java.lang.String"),
                new MethodDescription(
                    "getReturnType",
                    new List <ModifierDescription>()
                {
                    ModifierDescription.PUBLIC
                },
                    new List <ParameterDescription>(),
                    "java.lang.Class"),
                new MethodDescription(
                    "getModifiers",
                    new List <ModifierDescription>()
                {
                    ModifierDescription.PUBLIC
                },
                    new List <ParameterDescription>(),
                    "int"),
                new MethodDescription(
                    "getParameters",
                    new List <ModifierDescription>()
                {
                    ModifierDescription.PUBLIC
                },
                    new List <ParameterDescription>(),
                    "java.lang.reflect.Parameter[]")
            };
            var description = new ClassDescription(
                "Method",
                libName,
                new List <ModifierDescription>()
            {
                ModifierDescription.PUBLIC, ModifierDescription.FINAL
            },
                new List <FieldDescription>(),
                methods,
                new List <string>()
            {
            },
                new List <ClassDescription>(),
                false);

            return(description);
        }
 public static IEnumerable <FieldDeclarationSyntax> Build(
     ClassDescription classDescription,
     string classRefName,
     string jObjectName,
     string lockObjectName)
 {
     return(ClassServiceFieldsBuilder
            .Build(classRefName, jObjectName, lockObjectName)
            .Concat(MethodRefFieldsBuilder.Build(classDescription.MethodsDescriptions))
            .ToArray());
 }
        public byte[] Load(Stream stream, Game game, out int width, out int height, out int length)
        {
            byte[] map = null;
            width  = 0;
            height = 0;
            length = 0;
            LocalPlayer p = game.LocalPlayer;

            p.Spawn = Vector3.Zero;
            GZipHeaderReader gsHeader = new GZipHeaderReader();

            while (!gsHeader.ReadHeader(stream))
            {
            }

            using (DeflateStream gs = new DeflateStream(stream, CompressionMode.Decompress)) {
                reader = new BinaryReader(gs);
                ClassDescription obj = ReadData();
                for (int i = 0; i < obj.Fields.Length; i++)
                {
                    FieldDescription field = obj.Fields[i];
                    if (field.FieldName == "width")
                    {
                        width = (int)field.Value;
                    }
                    else if (field.FieldName == "height")
                    {
                        length = (int)field.Value;
                    }
                    else if (field.FieldName == "depth")
                    {
                        height = (int)field.Value;
                    }
                    else if (field.FieldName == "blocks")
                    {
                        map = (byte[])field.Value;
                    }
                    else if (field.FieldName == "xSpawn")
                    {
                        p.Spawn.X = (int)field.Value;
                    }
                    else if (field.FieldName == "ySpawn")
                    {
                        p.Spawn.Y = (int)field.Value;
                    }
                    else if (field.FieldName == "zSpawn")
                    {
                        p.Spawn.Z = (int)field.Value;
                    }
                }
            }
            return(map);
        }
Exemple #23
0
        /// <summary>
        ///     将Json数据转换成实体类型
        ///     Converts to extension.
        /// </summary>
        /// <param name="instance">The instance.</param>
        public static T ConvertToExtension <T>(T instance) where T : class, IEntity
        {
            if (instance == null)
            {
                return(instance);
            }

            var type             = typeof(T);
            var classDescription = new ClassDescription(type);

            if (classDescription.Propertys == null)
            {
                return(instance);
            }
            //获取有枚举的属性
            var propertys = classDescription.Propertys.Where(r => !r.FieldAttribute.ExtensionJson.IsNullOrEmpty());

            if (propertys == null || !propertys.Any())
            {
                return(instance);
            }

            var propertyInfo = type.GetPropertiesFromCache();

            foreach (var item in propertyInfo)
            {
                var property = propertys.FirstOrDefault(r => r.Name == item.Name);

                if (property != null)
                {
                    var value = item.GetValue(instance);
                    if (value != null && !value.ToStr().IsNullOrEmpty())
                    {
                        var extesionName = property.FieldAttribute.ExtensionJson;
                        // 获取扩展字段
                        var extensionType  = extesionName.GetTypeByName();
                        var extensionField = propertyInfo.FirstOrDefault(r => r.Name == extensionType?.Name);
                        if (extensionField != null && extensionType != null)
                        {
                            try {
                                var extesionValue = JsonConvert.DeserializeObject(value.ToString(), extensionType);
                                extensionField.SetValue(instance, extesionValue);
                            } catch (Exception ex) {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }

            return(instance);
        }
Exemple #24
0
        public static ClassDeclarationSyntax AddServiceProperties(
            this ClassDeclarationSyntax classDeclaration,
            ClassDescription classDescription)
        {
            var refProperties = PropertiesBuilder.Build(
                classDescription,
                CLASS_REF_NAME,
                LOCK_OBJECT_NAME)
                                .ToArray();

            return(classDeclaration
                   .AddMembers(refProperties));
        }
Exemple #25
0
        public static ClassDeclarationSyntax AddServiceFields(
            this ClassDeclarationSyntax classDeclaration,
            ClassDescription classDescription)
        {
            var fields = ServiceFieldsBuilder.Build(
                classDescription,
                CLASS_REF_NAME,
                J_OBJECT_NAME,
                LOCK_OBJECT_NAME
                ).ToArray();

            return(classDeclaration
                   .AddMembers(fields));
        }
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>A hash code for the current <see cref="T:System.Object"/>.</returns>
 public override int GetHashCode()
 {
     return(BootCritical.GetHashCode()
            ^ InBox.GetHashCode()
            ^ (String.IsNullOrEmpty(CatalogFile) ? 0 : CatalogFile.GetHashCode())
            ^ (String.IsNullOrEmpty(ClassDescription) ? 0 : ClassDescription.GetHashCode())
            ^ (String.IsNullOrEmpty(ClassGuid) ? 0 : ClassGuid.GetHashCode())
            ^ (String.IsNullOrEmpty(ClassName) ? 0 : ClassName.GetHashCode())
            ^ Date.GetHashCode()
            ^ DriverSignature.GetHashCode()
            ^ (String.IsNullOrEmpty(OriginalFileName) ? 0 : OriginalFileName.GetHashCode())
            ^ (String.IsNullOrEmpty(ProviderName) ? 0 : ProviderName.GetHashCode())
            ^ (String.IsNullOrEmpty(PublishedName) ? 0 : PublishedName.GetHashCode()));
 }
Exemple #27
0
 public static IEnumerable <PropertyDeclarationSyntax> Build(
     ClassDescription classDescription,
     string classRefName,
     string lockObjectName)
 {
     return(JvmPropertyBuilder
            .Build()
            .Concat(
                RefPropertyBuilder
                .Build(
                    classDescription.MethodsDescriptions,
                    classRefName,
                    lockObjectName)
                ));
 }
Exemple #28
0
        /// <summary>
        ///     实体数据转换成扩展数据
        ///     将Json数据转换成实体类型
        ///     如:GetSingle或GetList会自动转换成Json
        ///     Converts to extension.
        /// </summary>
        /// <param name="instance">The instance.</param>
        public static T EntityToExtension <T>(T instance) where T : class, IEntity
        {
            if (instance == null)
            {
                return(instance);
            }

            var type             = typeof(T);
            var classDescription = new ClassDescription(type);
            //获取有枚举的属性
            var propertys = classDescription.Propertys.Where(r => !r.FieldAttribute.ExtensionJson.IsNullOrEmpty());

            if (propertys == null || propertys.Count() == 0)
            {
                return(instance);
            }

            var propertyInfo = type.GetPropertiesFromCache();

            foreach (var item in propertyInfo)
            {
                var property = propertys.FirstOrDefault(r => r.Name == item.Name);

                if (property != null)
                {
                    var value = item.GetValue(instance);
                    if (!value.IsNullOrEmpty())
                    {
                        var extesionName   = property.FieldAttribute.ExtensionJson;
                        var extensionField = propertyInfo.FirstOrDefault(r => r.Name == extesionName);
                        if (!extensionField.IsNullOrEmpty())
                        {
                            if (extensionField != null)
                            {
                                //设置值
                                var extesionValue =
                                    JsonConvert.DeserializeObject(value.ToString(), extensionField.PropertyType);
                                extensionField.SetValue(instance, extesionValue);
                            }
                        }
                    }
                }
            }

            return(instance);
        }
Exemple #29
0
        void ReadArray(ref FieldDescription field)
        {
            byte typeCode = reader.ReadByte();

            if (typeCode == TC_NULL)
            {
                return;
            }
            if (typeCode != TC_ARRAY)
            {
                ParseError(TC_ARRAY, typeCode);
            }

            ClassDescription desc = ReadClassDescription();

            field.Value = reader.ReadBytes(ReadInt32());
        }
Exemple #30
0
        ClassDescription ReadData()
        {
            if ((ushort)ReadInt16() != 0xACED || ReadInt16() != 0x0005)
            {
                throw new InvalidDataException("Unexpected java serialisation constant(s).");
            }

            byte typeCode = reader.ReadByte();

            if (typeCode != TC_OBJECT)
            {
                ParseError(TC_OBJECT, typeCode);
            }
            ClassDescription desc = ReadClassDescription();

            ReadClassData(desc.Fields);
            return(desc);
        }
Exemple #31
0
        public override void Enter(Dictionary<string, object> data)
        {
            Storage.NetworkSession.GamerJoined += GamerJoined;
            Storage.NetworkSession.GamerLeft += GamerLeft;

            var netPlayer = Storage.NetworkSession.LocalGamers[0];
            var player = netPlayer.Tag as Player;

            if(player == null)
            {
                throw new Exception("Player not inited!?");
            }

            var logoSprite = Storage.Sprite("SandLogo");
            var sandLogoOrigin = new Vector2(Game.BaseScreenSize.X * 0.5f - (logoSprite.Width * 0.5f), 30);

            _sandLogo = data.ContainsKey("SandLogo")
                            ? data["SandLogo"] as Billboard
                            : new Billboard(Game, sandLogoOrigin, logoSprite);

            Storage.AnimationController.Add(new Animation(_sandLogo, "Y", sandLogoOrigin.Y), 750);

            var readyButtonRect = new Rectangle(0, 0, 200, 50);
            readyButtonRect.X = (int)Game.BaseScreenSize.X - readyButtonRect.Width - 50;
            readyButtonRect.Y = (int)Game.BaseScreenSize.Y - readyButtonRect.Height - 50;
            _readyButton = new Button(Game, readyButtonRect, "Ready", new Color(0.1f, 0.7f, 0.1f));
            _readyButton.SetAction(ReadyButtonAction,
                null);

            var playerClassOrigin = new Vector2((Game.BaseScreenSize.X / 2.0f) - 128,
                                                sandLogoOrigin.Y + logoSprite.Height + 32);

            // TODO: this code needs to be cleaned up a lot
            // TODO: make sure we aren't clicking on a taken combination

            _redDefenseButton = new PlayerClassButton(Game, new Vector2(playerClassOrigin.X - 256, playerClassOrigin.Y),
                                                      Class.Defense, Team.Red);
            _redDefenseButton.Button.SetAction((a, userInfo) =>
                                               {
                                                   player.Team = Team.Red;
                                                   player.Class = Class.Defense;
                                                   Sound.OneShot(AddRandomSuffix("DefenseClass"), false);
                                               }, null);
            Game.Components.Add(_redDefenseButton);
            _redOffenseButton = new PlayerClassButton(Game,
                                                      new Vector2(playerClassOrigin.X - 256,
                                                                  playerClassOrigin.Y + 256 + 64), Class.Offense,
                                                      Team.Red);
            _redOffenseButton.Button.SetAction((a, userInfo) =>
                                               {
                                                   player.Team = Team.Red;
                                                   player.Class = Class.Offense;
                                                   Sound.OneShot(AddRandomSuffix("OffenseClass"), false);
                                               }, null);
            Game.Components.Add(_redOffenseButton);
            _redSupportButton = new PlayerClassButton(Game,
                                                      new Vector2(playerClassOrigin.X - 256,
                                                                  playerClassOrigin.Y + 512 + 128), Class.Support,
                                                      Team.Red);
            _redSupportButton.Button.SetAction((a, userInfo) =>
                                               {
                                                   player.Team = Team.Red;
                                                   player.Class = Class.Support;
                                                   Sound.OneShot(AddRandomSuffix("SupportClass"), false);
                                               }, null);
            Game.Components.Add(_redSupportButton);

            _blueDefenseButton = new PlayerClassButton(Game, new Vector2(playerClassOrigin.X + 256, playerClassOrigin.Y),
                                                       Class.Defense, Team.Blue);
            _blueDefenseButton.Button.SetAction((a, userInfo) =>
                                                {
                                                    player.Team = Team.Blue;
                                                    player.Class = Class.Defense;
                                                    Sound.OneShot(AddRandomSuffix("DefenseClass"), false);
                                                }, null);
            Game.Components.Add(_blueDefenseButton);
            _blueOffenseButton = new PlayerClassButton(Game,
                                                       new Vector2(playerClassOrigin.X + 256,
                                                                   playerClassOrigin.Y + 256 + 64), Class.Offense,
                                                       Team.Blue);
            _blueOffenseButton.Button.SetAction((a, userInfo) =>
                                                {
                                                    player.Team = Team.Blue;
                                                    player.Class = Class.Offense;
                                                    Sound.OneShot(AddRandomSuffix("OffenseClass"), false);
                                                }, null);
            Game.Components.Add(_blueOffenseButton);
            _blueSupportButton = new PlayerClassButton(Game,
                                                       new Vector2(playerClassOrigin.X + 256,
                                                                   playerClassOrigin.Y + 512 + 128), Class.Support,
                                                       Team.Blue);
            _blueSupportButton.Button.SetAction((a, userInfo) =>
                                                {
                                                    player.Team = Team.Blue;
                                                    player.Class = Class.Support;
                                                    Sound.OneShot(AddRandomSuffix("SupportClass"), false);
                                                }, null);
            Game.Components.Add(_blueSupportButton);

            _classDescriptions = new ClassDescription[3];

            _classDescriptions[0] = new ClassDescription(Game, Class.Defense)
                                    {
                                        X =
                                            (_blueSupportButton.Button.X + _redSupportButton.Button.X +
                                             _redSupportButton.Button.Width) / 2,
                                        Y = _redDefenseButton.Button.Y
                                    };

            _classDescriptions[1] = new ClassDescription(Game, Class.Offense)
                                    {
                                        X = _classDescriptions[0].X,
                                        Y = _redOffenseButton.Button.Y
                                    };

            _classDescriptions[2] = new ClassDescription(Game, Class.Support)
                                    {
                                        X = _classDescriptions[0].X,
                                        Y = _redSupportButton.Button.Y
                                    };

            _tutorialButton = new Button(Game, new Rectangle(50, readyButtonRect.Y, 200, 50), "Tutorial");
            _tutorialButton.SetAction((a, b) => DoTutorial(), null);

            Game.Components.Add(_sandLogo);
            Game.Components.Add(_readyButton);
            Game.Components.Add(_classDescriptions[0]);
            Game.Components.Add(_classDescriptions[1]);
            Game.Components.Add(_classDescriptions[2]);

            if(Storage.NetworkSession.IsHost)
            {
                Game.Components.Add(_tutorialButton);
            }
        }