Esempio n. 1
0
    void BindInfo(ETask t)
    {
        if (ProjectStepList.Count > 0)
        {
            EProjectTaskStep step = ProjectStepList.FirstOrDefault(c => c.Value == t.State);
            if (step != null)
            {
                int index = ProjectStepList.IndexOf(step);
                TaskState.captionText.text = step.Name;
                TaskState.value            = index;
            }
        }

        TaskPriority.captionText.text = EnumMapping.GetText <TaskPriority>((int)t.Priority);

        TaskPriority.value = (int)t.Priority - 1;

        TaskName.text    = t.Title;
        TaskContent.text = t.Content;
        TaskBeginTime.SetTime(t.BeginTime);
        TaskEndTime.SetTime(t.EndTime);
        HeadPersonID   = t.TaskHeadID;
        ExcuterID      = t.ExecutorID;
        SelectFilePath = t.Attachment;

        BindHeadName(HeadPersonID, t.TaskHeadName);
        BindExcuterName(ExcuterID, t.ExecutorName);
        BindAttachment();
        BindRemindTime(t.Remind);
    }
Esempio n. 2
0
        public INoKeyConfirmation GetInstance(INoKeyConfirmationParameters parameters)
        {
            switch (parameters.KeyAgreementMacType)
            {
            case KeyAgreementMacType.AesCcm:
                return(new NoKeyConfirmationAesCcm(_macDataCreator, parameters, new CcmBlockCipher(new AesEngine(), new ModeBlockCipherFactory(), new AES_CCMInternals())));

            case KeyAgreementMacType.CmacAes:
                return(new NoKeyConfirmationCmac(_macDataCreator, parameters, _cmacFactory.GetCmacInstance(CmacTypes.AES128)));    // doesn't matter as long as aea

            case KeyAgreementMacType.HmacSha1:
            case KeyAgreementMacType.HmacSha2D224:
            case KeyAgreementMacType.HmacSha2D256:
            case KeyAgreementMacType.HmacSha2D384:
            case KeyAgreementMacType.HmacSha2D512:
            case KeyAgreementMacType.HmacSha2D512_T224:
            case KeyAgreementMacType.HmacSha2D512_T256:
            case KeyAgreementMacType.HmacSha3D224:
            case KeyAgreementMacType.HmacSha3D256:
            case KeyAgreementMacType.HmacSha3D384:
            case KeyAgreementMacType.HmacSha3D512:
                ModeValues  modeValue  = ModeValues.SHA2;
                DigestSizes digestSize = DigestSizes.NONE;
                EnumMapping.GetHashFunctionOptions(parameters.KeyAgreementMacType, ref modeValue, ref digestSize);
                return(new NoKeyConfirmationHmac(_macDataCreator, parameters, _hmacFactory.GetHmacInstance(new HashFunction(modeValue, digestSize))));

            default:
                throw new ArgumentException($"{GetType().Name}, {nameof(parameters.KeyAgreementMacType)}");
            }
        }
Esempio n. 3
0
        public void ShouldThrowArgumentExceptionOnInvalidMacType(KeyAgreementMacType keyAgreementMacType)
        {
            ModeValues  mode       = ModeValues.SHA1;
            DigestSizes digestSize = DigestSizes.NONE;

            Assert.Throws(typeof(ArgumentException), () => EnumMapping.GetHashFunctionOptions(keyAgreementMacType, ref mode, ref digestSize));
        }
Esempio n. 4
0
    void OnAddTask(GameObject g)
    {
        if (string.IsNullOrEmpty(TaskName.text))
        {
            return;
        }
        ETask p = new ETask();

        p.Title      = TaskName.text;
        p.Content    = TaskContent.text;
        p.ProjectID  = ProjectID;
        p.PlanID     = PlanID;
        p.CreaterID  = Session.UserID;
        p.CreateTime = System.DateTime.Now;
        p.BeginTime  = TaskBeginTime.GetTime();
        p.EndTime    = TaskEndTime.GetTime();
        p.State      = ProjectStepList.FirstOrDefault(c => c.Name == TaskState.captionText.text).Value;
        p.Priority   = (TaskPriority)EnumMapping.GetValue <TaskPriority>(TaskPriority.captionText.text);
        p.TaskHeadID = HeadPersonID;
        p.ExecutorID = ExcuterID;
        p.Attachment = SelectFilePath;
        BaseOperation_Service.Create <ETask>(p, t =>
        {
            App.Instance.HintBox.Show("操作成功!");
            App.Instance.PageGroup.ClosePage();
        });
    }
        private string WriteEnumMethod(EnumMapping mapping, object v)
        {
            string returnString = null;

            if (mapping != null)
            {
                ConstantMapping[] constants = mapping.Constants;
                if (constants.Length > 0)
                {
                    bool foundValue = false;
                    var  enumValue  = Convert.ToInt64(v);
                    for (int i = 0; i < constants.Length; i++)
                    {
                        ConstantMapping c = constants[i];
                        if (enumValue == c.Value)
                        {
                            returnString = c.XmlName;
                            foundValue   = true;
                            break;
                        }
                    }

                    if (!foundValue)
                    {
                        if (mapping.IsFlags)
                        {
                            string[] xmlNames = new string[constants.Length];
                            long[]   valueIds = new long[constants.Length];

                            for (int i = 0; i < constants.Length; i++)
                            {
                                xmlNames[i] = constants[i].XmlName;
                                valueIds[i] = constants[i].Value;
                            }

                            returnString = FromEnum(enumValue, xmlNames, valueIds);
                        }
                        else
                        {
                            throw CreateInvalidEnumValueException(v, mapping.TypeDesc.FullName);
                        }
                    }
                }
            }
            else
            {
                returnString = v.ToString();
            }

            if (mapping.IsSoap)
            {
                WriteXsiType(mapping.TypeName, mapping.Namespace);
                Writer.WriteString(returnString);
                return(null);
            }
            else
            {
                return(returnString);
            }
        }
Esempio n. 6
0
        private string getEnumLiteral(Enum item)
        {
            Type        type    = item.GetType();
            EnumMapping mapping = EnumMapping.Create(type);
            //todo: Chaching these mappings should probably optimize performance. But for now load seems managable.
            string literal = mapping.GetLiteral(item);

            return(literal);
        }
Esempio n. 7
0
        public override string RenderTd(T entity)
        {
            Check.NotNull(entity, nameof(entity));

            Enum   value   = this.expression.Compile()(entity);
            string display = EnumMapping.ToString(value);

            return(this.RenderTd(display));
        }
Esempio n. 8
0
        public void ShouldSetCorrectHashFunctionAttributesFromHmac(KeyAgreementMacType keyAgreementMacType, ModeValues expectedModeValue, DigestSizes expectedDigestSize)
        {
            ModeValues  mode       = ModeValues.SHA1;
            DigestSizes digestSize = DigestSizes.NONE;

            EnumMapping.GetHashFunctionOptions(keyAgreementMacType, ref mode, ref digestSize);

            Assert.AreEqual(expectedModeValue, mode, nameof(expectedModeValue));
            Assert.AreEqual(expectedDigestSize, digestSize, nameof(expectedDigestSize));
        }
Esempio n. 9
0
    void OnSaveTask(GameObject g)
    {
        if (string.IsNullOrEmpty(TaskName.text))
        {
            return;
        }
        TheTask.Title      = TaskName.text;
        TheTask.Content    = TaskContent.text;
        TheTask.ProjectID  = ProjectID;
        TheTask.PlanID     = PlanID;
        TheTask.CreaterID  = Session.UserID;
        TheTask.CreateTime = System.DateTime.Now;
        TheTask.BeginTime  = TaskBeginTime.GetTime();
        TheTask.EndTime    = TaskEndTime.GetTime();
        TheTask.State      = ProjectStepList.FirstOrDefault(c => c.Name == TaskState.captionText.text).Value;
        TheTask.Priority   = (TaskPriority)EnumMapping.GetValue <TaskPriority>(TaskPriority.captionText.text);
        TheTask.TaskHeadID = HeadPersonID;
        TheTask.ExecutorID = ExcuterID;
        string fz = "";

        switch (RemindTime.captionText.text)
        {
        case "不提醒":
            fz = "";
            break;

        case "早上9点":
            fz = "9";
            break;

        case "中午12点":
            fz = "12";
            break;

        case "下午3点":
            fz = "15";
            break;

        case "下午6点":
            fz = "18";
            break;

        case "晚上9点":
            fz = "21";
            break;
        }
        TheTask.Remind     = fz;
        TheTask.IsReminded = false;
        BaseOperation_Service.Change <ETask>(TheTask, t =>
        {
            App.Instance.HintBox.Show("操作成功!");
            App.Instance.PageGroup.ClosePage();
        });
    }
        private bool WriteEnumAndArrayTypes(StructMapping structMapping, object o, string n, string ns, XmlMapping parentMapping)
        {
            if (o is Enum)
            {
                Writer.WriteStartElement(n, ns);

                EnumMapping enumMapping = null;
                Type        enumType    = o.GetType();
                foreach (var m in parentMapping.Scope.TypeMappings)
                {
                    var em = m as EnumMapping;
                    if (em != null && em.TypeDesc.Type == enumType)
                    {
                        enumMapping = em;
                        break;
                    }
                }

                Debug.Assert(enumMapping != null);

                WriteXsiType(enumMapping.TypeName, ns);
                Writer.WriteString(WriteEnumMethod(enumMapping, o));
                Writer.WriteEndElement();
                return(true);
            }

            if (o is Array)
            {
                Debug.Assert(parentMapping != null);
                Writer.WriteStartElement(n, ns);
                ArrayMapping arrayMapping = null;
                Type         arrayType    = o.GetType();
                foreach (var m in parentMapping.Scope.TypeMappings)
                {
                    var am = m as ArrayMapping;
                    if (am != null && am.TypeDesc.Type == arrayType)
                    {
                        arrayMapping = am;
                        break;
                    }
                }

                Debug.Assert(arrayMapping != null);
                WriteXsiType(arrayMapping.TypeName, ns);
                WriteMember(o, null, arrayMapping.ElementsSortedByDerivation, null, null, arrayMapping.TypeDesc, true);
                Writer.WriteEndElement();

                return(true);
            }

            return(false);
        }
Esempio n. 11
0
    private void BindTaskPriority()
    {
        List <string> pList = EnumMapping.ListAll <TaskPriority>();

        pList.Insert(0, "全部");
        YXJList.Clear();
        YXJList.OnItemClicked = YXJItem_OnClicked;
        YXJList.BindData <string>("TextItem", pList, (i, e) =>
        {
            i.name = "TextItem_" + e;
            i.transform.Find("Name").GetComponent <Text>().text = e;
        }, true, true);
    }
Esempio n. 12
0
    void YXJItem_OnClicked(GameObject g)
    {
        SubmitBtn.interactable = true;
        string str = g.name.Split('_')[1];

        if (str == "全部")
        {
            NewSearch.TaskPriority = 0;
        }
        else
        {
            NewSearch.TaskPriority = EnumMapping.GetValue <TaskPriority>(str);
        }
    }
Esempio n. 13
0
    void InitUI()
    {
        TaskState.options.Clear();
        foreach (var item in ProjectStepList)
        {
            TaskState.options.Add(new Dropdown.OptionData(item.Name));
        }

        TaskPriority.options.Clear();
        foreach (string item in EnumMapping.ListAll <TaskPriority>())
        {
            TaskPriority.options.Add(new Dropdown.OptionData(item));
        }
    }
Esempio n. 14
0
    void BindInfo()
    {
        ETask t = TheTask;

        TaskState.text     = t.StepName;
        TaskPriority.text  = EnumMapping.GetText <TaskPriority>((int)t.Priority);
        TaskName.text      = t.Title;
        TaskContent.text   = t.Content;
        TaskBeginTime.text = t.BeginTime.ToString("yyyy-MM-dd hh:mm:ss");
        TaskEndTime.text   = t.EndTime.ToString("yyyy-MM-dd hh:mm:ss");
        BindHeadName(t.TaskHeadID);
        BindExcuterName(t.ExecutorID);
        BindAttachment(t.Attachment);
        BindRemindTime(t.Remind);
    }
Esempio n. 15
0
        public FhirModel(Dictionary <Type, string> csTypeToFhirTypeNameMapping, IEnumerable <SearchParamDefinition> searchParameters, List <Type> enums)
        {
            LoadSearchParameters(searchParameters);
            _csTypeToFhirTypeName = csTypeToFhirTypeNameMapping;
            _fhirTypeNameToCsType = _csTypeToFhirTypeName.ToLookup(pair => pair.Value, pair => pair.Key).ToDictionary(group => group.Key, group => group.FirstOrDefault());

            _enumMappings = new List <EnumMapping>();
            foreach (var enumType in enums)
            {
                if (EnumMapping.IsMappableEnum(enumType))
                {
                    _enumMappings.Add(EnumMapping.Create(enumType));
                }
            }
        }
Esempio n. 16
0
        private static EnumMapping GetEnumMapping(Type enumType)
        {
            EnumMapping fieldInfo = null;

            lock ( _cacheLock )
            {
                if (!_cache.TryGetValue(enumType, out fieldInfo))
                {
                    fieldInfo = EnumMapping.Create(enumType);
                    _cache.Add(enumType, fieldInfo);
                }
            }

            return(fieldInfo);
        }
        public void TestCreation()
        {
            EnumMapping mapping = EnumMapping.Create(typeof(TestEnum));

            Assert.AreEqual("Testee", mapping.Name);
            Assert.AreEqual(typeof(TestEnum), mapping.EnumType);
            Assert.IsTrue(mapping.ContainsLiteral("Item1"));
            Assert.IsFalse(mapping.ContainsLiteral("Item2"));
            Assert.IsFalse(mapping.ContainsLiteral("iTeM1"));
            Assert.IsTrue(mapping.ContainsLiteral("ItemTwo"));

            Assert.AreEqual(TestEnum.Item2, mapping.ParseLiteral("ItemTwo"));
            Assert.AreEqual(TestEnum.Item1, mapping.ParseLiteral("Item1"));
            Assert.AreEqual("ItemTwo", mapping.GetLiteral(TestEnum.Item2));
            Assert.AreEqual("Item1", mapping.GetLiteral(TestEnum.Item1));
        }
        public IKeyConfirmation GetInstance(IKeyConfirmationParameters parameters)
        {
            switch (parameters.MacType)
            {
            case KeyAgreementMacType.AesCcm:
                ConfirmKeyLengthAesCcm(parameters.KeyLength);
                return(new KeyConfirmationAesCcm(
                           _macDataCreator,
                           parameters,
                           new CcmBlockCipher(new AesEngine(), new ModeBlockCipherFactory(), new AES_CCMInternals())));

            case KeyAgreementMacType.CmacAes:
                var cmacEnum = MapCmacEnum(parameters.KeyLength);

                return(new KeyConfirmationCmac(
                           _macDataCreator, parameters, _cmacFactory.GetCmacInstance(cmacEnum)));

            case KeyAgreementMacType.HmacSha1:
            case KeyAgreementMacType.HmacSha2D224:
            case KeyAgreementMacType.HmacSha2D256:
            case KeyAgreementMacType.HmacSha2D384:
            case KeyAgreementMacType.HmacSha2D512:
            case KeyAgreementMacType.HmacSha2D512_T224:
            case KeyAgreementMacType.HmacSha2D512_T256:
            case KeyAgreementMacType.HmacSha3D224:
            case KeyAgreementMacType.HmacSha3D256:
            case KeyAgreementMacType.HmacSha3D384:
            case KeyAgreementMacType.HmacSha3D512:
                ModeValues  modeValue  = ModeValues.SHA2;
                DigestSizes digestSize = DigestSizes.NONE;
                EnumMapping.GetHashFunctionOptions(parameters.MacType, ref modeValue, ref digestSize);

                return(new KeyConfirmationHmac(
                           _macDataCreator, parameters, _hmacFactory.GetHmacInstance(new HashFunction(modeValue, digestSize))));

            case KeyAgreementMacType.Kmac_128:
                return(new KeyConfirmationKmac(_macDataCreator, parameters, _kmacFactory, 256));

            case KeyAgreementMacType.Kmac_256:
                return(new KeyConfirmationKmac(_macDataCreator, parameters, _kmacFactory, 512));

            default:
                throw new ArgumentException($"{GetType().Name}, {nameof(parameters.MacType)}");
            }
        }
        public void ShouldMacCorrectly(int keyLength, int macLength, KeyAgreementMacType keyAgreementMacType, BitString dkm, BitString nonce, BitString expectedMacData, BitString expectedMac)
        {
            ModeValues  modeValue  = ModeValues.SHA2;
            DigestSizes digestSize = DigestSizes.NONE;

            EnumMapping.GetHashFunctionOptions(keyAgreementMacType, ref modeValue, ref digestSize);

            NoKeyConfirmationParameters p =
                new NoKeyConfirmationParameters(keyAgreementMacType, macLength, dkm, nonce);

            _subject = new NoKeyConfirmationHmac(new NoKeyConfirmationMacDataCreator(), p, _algoFactory.GetHmacInstance(new HashFunction(modeValue, digestSize)));

            var result = _subject.ComputeMac();

            Assert.That(result.Success, nameof(result.Success));
            Assert.AreEqual(expectedMacData.ToHex(), result.MacData.ToHex(), nameof(result.MacData));
            Assert.AreEqual(expectedMac.ToHex(), result.Mac.ToHex(), nameof(result.Mac));
        }
Esempio n. 20
0
        private EnumMapping ImportEnumMapping(EnumModel model)
        {
            SoapAttributes a      = GetAttributes(model.Type);
            string         typeNs = _defaultNs;

            if (a.SoapType != null && a.SoapType.Namespace != null)
            {
                typeNs = a.SoapType.Namespace;
            }
            string typeName = XsdTypeName(model.Type, a, model.TypeDesc.Name);

            typeName = XmlConvert.EncodeLocalName(typeName);

            EnumMapping mapping = (EnumMapping)GetTypeMapping(typeName, typeNs, model.TypeDesc);

            if (mapping == null)
            {
                mapping           = new EnumMapping();
                mapping.IsSoap    = true;
                mapping.TypeDesc  = model.TypeDesc;
                mapping.TypeName  = typeName;
                mapping.Namespace = typeNs;
                mapping.IsFlags   = model.Type.IsDefined(typeof(FlagsAttribute), false);
                _typeScope.AddTypeMapping(mapping);
                _types.Add(typeName, typeNs, mapping);
                ArrayList constants = new ArrayList();
                for (int i = 0; i < model.Constants.Length; i++)
                {
                    ConstantMapping constant = ImportConstantMapping(model.Constants[i]);
                    if (constant != null)
                    {
                        constants.Add(constant);
                    }
                }
                if (constants.Count == 0)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlNoSerializableMembers, model.TypeDesc.FullName));
                }
                mapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping));
            }
            return(mapping);
        }
Esempio n. 21
0
 void BindTaskListView()
 {
     Task_Service.ListByPlanID(EPlan.ID, selectPeopleID, t =>
     {
         List <ETask> plist         = t.GetData() as List <ETask>;
         TaskListView.OnItemClicked = OnTaskClicked;
         TaskListView.BindData <ETask>("PlanTaskItem", plist, (i, e) =>
         {
             i.name = "PlanTaskItem_" + e.ID.ToString();
             i.transform.Find("TIState").GetComponent <Text>().text    = e.StepName;
             i.transform.Find("TIPriority").GetComponent <Text>().text = EnumMapping.GetText <TaskPriority>((int)e.Priority);
             if (e.Priority == TaskPriority.First)
             {
                 i.transform.Find("TIPriority").GetComponent <Text>().color = new Color(156 / 255f, 93 / 255f, 0 / 255f);
             }
             else if (e.Priority == TaskPriority.Hurry)
             {
                 i.transform.Find("TIPriority").GetComponent <Text>().color = new Color(223 / 255f, 60 / 255f, 0 / 255f);
             }
             else if (e.Priority == TaskPriority.Urgent)
             {
                 i.transform.Find("TIPriority").GetComponent <Text>().color = Color.red;
             }
             else
             {
                 i.transform.Find("TIPriority").GetComponent <Text>().color = new Color(139 / 255f, 139 / 255f, 139 / 255f);
             }
             i.transform.Find("TIContent").GetComponent <Text>().text   = e.Title;
             i.transform.Find("TIBeginTime").GetComponent <Text>().text = e.BeginTime.ToString("yyyy-MM-dd");
             i.transform.Find("TIEndTime").GetComponent <Text>().text   = e.EndTime.ToString("yyyy-MM-dd");
             if (e.TaskHeadID == 0)
             {
                 i.transform.Find("TIPerson").GetComponent <Text>().text = "";
             }
             else
             {
                 i.transform.Find("TIPerson").GetComponent <Text>().text = e.TaskHeadName;
             }
         });
     });
 }
Esempio n. 22
0
            public static EnumMapping Create(Type enumType)
            {
                if (enumType == null)
                {
                    throw Error.ArgumentNull("enumType");
                }
                if (!enumType.IsEnum())
                {
                    throw Error.Argument("enumType", "Type {0} is not an enumerated type".FormatWith(enumType.Name));
                }

                var result = new EnumMapping()
                {
                    Name                    = getEnumName(enumType),
                    EnumType                = enumType,
                    _enumToLiteral          = new Dictionary <Enum, string>(),
                    _literalToEnum          = new Dictionary <string, Enum>(),
                    _lowercaseLiteralToEnum = new Dictionary <string, Enum>()
                };

                foreach (var enumValue in ReflectionHelper.FindEnumFields(enumType))
                {
                    var attr = ReflectionHelper.GetAttribute <EnumLiteralAttribute>(enumValue);

                    string literal = enumValue.Name;
                    if (attr != null)
                    {
                        literal = attr.Literal;
                    }

                    Enum value = (Enum)enumValue.GetValue(null);

                    result._enumToLiteral.Add(value, literal);
                    result._literalToEnum.Add(literal, value);
                    result._lowercaseLiteralToEnum.Add(literal.ToLowerInvariant(), value);
                }

                return(result);
            }
Esempio n. 23
0
        public void LoadAssembly(Assembly fhirAssembly)
        {
            _csTypeToFhirTypeName = new Dictionary <Type, string>();
            _fhirTypeNameToCsType = new Dictionary <string, Type>();
            _enumMappings         = new List <EnumMapping>();

            foreach (Type fhirType in fhirAssembly.GetTypes())
            {
                if (typeof(Resource).IsAssignableFrom(fhirType)) //It is derived of Resource, so it is a Resource type.
                {
                    var fhirTypeAtt = fhirType.GetCustomAttribute <FhirTypeAttribute>();
                    var obsoleteAtt = fhirType.GetCustomAttribute <ObsoleteAttribute>();
                    //CK: Also check for obsolete. Example was Query, which was derived from Parameters, and therefore had the same name ("Parameters").
                    if (fhirTypeAtt != null && fhirTypeAtt.IsResource && (obsoleteAtt == null || !obsoleteAtt.IsError))
                    {
                        if (_csTypeToFhirTypeName.Keys.Contains(fhirType))
                        {
                            Debug.WriteLine("Double import: " + fhirType.FullName);
                        }
                        else
                        {
                            _csTypeToFhirTypeName.Add(fhirType, fhirTypeAtt.Name);
                        }
                        if (_fhirTypeNameToCsType.Keys.Contains(fhirTypeAtt.Name))
                        {
                            Debug.WriteLine("Double import: " + fhirType.FullName);
                        }
                        else
                        {
                            _fhirTypeNameToCsType.Add(fhirTypeAtt.Name, fhirType);
                        }
                    }
                }
                else if (EnumMapping.IsMappableEnum(fhirType))
                {
                    _enumMappings.Add(EnumMapping.Create(fhirType));
                }
            }
        }
Esempio n. 24
0
 public XmlRpcEnumMappingAttribute(EnumMapping mapping)
 {
     _mapping = mapping;
 }
Esempio n. 25
0
 private static EnumMapping getEnumMapping(Type enumType)
 => _cache.GetOrAdd(enumType, t => EnumMapping.Create(t));
Esempio n. 26
0
        static void BuildMethod(
            TypeBuilder tb,
            string methodName,
            string rpcMethodName,
            string[] paramNames,
            Type[] argTypes,
            bool paramsMethod,
            Type returnType,
            bool structParams,
            EnumMapping enumMapping)
        {
            MethodBuilder mthdBldr = tb.DefineMethod(
                methodName,
                MethodAttributes.Public | MethodAttributes.Virtual,
                returnType, argTypes);

            // add attribute to method
            Type[] oneString = new Type[1] {
                typeof(string)
            };
            Type            methodAttr = typeof(XmlRpcMethodAttribute);
            ConstructorInfo ci         = methodAttr.GetConstructor(oneString);

            PropertyInfo[] pis
                = new PropertyInfo[] { methodAttr.GetProperty("StructParams") };
            object[] structParam       = new object[] { structParams };
            CustomAttributeBuilder cab =
                new CustomAttributeBuilder(ci, new object[] { rpcMethodName },
                                           pis, structParam);

            mthdBldr.SetCustomAttribute(cab);

            // add EnumMapingAttribute to method if not default
            if (enumMapping != EnumMapping.Number)
            {
                Type[] oneEnumMapping = new Type[1] {
                    typeof(EnumMapping)
                };
                Type                   enMapAttr = typeof(XmlRpcEnumMappingAttribute);
                ConstructorInfo        enMapCi   = enMapAttr.GetConstructor(oneEnumMapping);
                CustomAttributeBuilder enMapCab  =
                    new CustomAttributeBuilder(enMapCi, new object[] { enumMapping });
                mthdBldr.SetCustomAttribute(enMapCab);
            }

            for (int i = 0; i < paramNames.Length; i++)
            {
                ParameterBuilder paramBldr = mthdBldr.DefineParameter(i + 1,
                                                                      ParameterAttributes.In, paramNames[i]);
                // possibly add ParamArrayAttribute to final parameter
                if (i == paramNames.Length - 1 && paramsMethod)
                {
                    ConstructorInfo ctorInfo = typeof(ParamArrayAttribute).GetConstructor(
                        new Type[0]);
                    CustomAttributeBuilder attrBldr =
                        new CustomAttributeBuilder(ctorInfo, new object[0]);
                    paramBldr.SetCustomAttribute(attrBldr);
                }
            }
            // generate IL
            ILGenerator ilgen = mthdBldr.GetILGenerator();
            // if non-void return, declared locals for processing return value
            LocalBuilder retVal     = null;
            LocalBuilder tempRetVal = null;

            if (typeof(void) != returnType)
            {
                tempRetVal = ilgen.DeclareLocal(typeof(System.Object));
                retVal     = ilgen.DeclareLocal(returnType);
            }
            // declare variable to store method args and emit code to populate ut
            LocalBuilder argValues = ilgen.DeclareLocal(typeof(System.Object[]));

            ilgen.Emit(OpCodes.Ldc_I4, argTypes.Length);
            ilgen.Emit(OpCodes.Newarr, typeof(System.Object));
            ilgen.Emit(OpCodes.Stloc, argValues);
            for (int argLoad = 0; argLoad < argTypes.Length; argLoad++)
            {
                ilgen.Emit(OpCodes.Ldloc, argValues);
                ilgen.Emit(OpCodes.Ldc_I4, argLoad);
                ilgen.Emit(OpCodes.Ldarg, argLoad + 1);
                if (argTypes[argLoad].IsValueType)
                {
                    ilgen.Emit(OpCodes.Box, argTypes[argLoad]);
                }
                ilgen.Emit(OpCodes.Stelem_Ref);
            }
            // call Invoke on base class
            Type[]     invokeTypes = new Type[] { typeof(MethodInfo), typeof(object[]) };
            MethodInfo invokeMethod
                = typeof(XmlRpcClientProtocol).GetMethod("Invoke", invokeTypes);

            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Call, typeof(MethodBase).GetMethod("GetCurrentMethod"));
            ilgen.Emit(OpCodes.Castclass, typeof(System.Reflection.MethodInfo));
            ilgen.Emit(OpCodes.Ldloc, argValues);
            ilgen.Emit(OpCodes.Call, invokeMethod);
            //  if non-void return prepare return value, otherwise pop to discard
            if (typeof(void) != returnType)
            {
                // if return value is null, don't cast it to required type
                Label retIsNull = ilgen.DefineLabel();
                ilgen.Emit(OpCodes.Stloc, tempRetVal);
                ilgen.Emit(OpCodes.Ldloc, tempRetVal);
                ilgen.Emit(OpCodes.Brfalse, retIsNull);
                ilgen.Emit(OpCodes.Ldloc, tempRetVal);
                if (true == returnType.IsValueType)
                {
                    ilgen.Emit(OpCodes.Unbox, returnType);
                    ilgen.Emit(OpCodes.Ldobj, returnType);
                }
                else
                {
                    ilgen.Emit(OpCodes.Castclass, returnType);
                }
                ilgen.Emit(OpCodes.Stloc, retVal);
                ilgen.MarkLabel(retIsNull);
                ilgen.Emit(OpCodes.Ldloc, retVal);
            }
            else
            {
                ilgen.Emit(OpCodes.Pop);
            }
            ilgen.Emit(OpCodes.Ret);
        }
 public XmlRpcEnumMappingAttribute(EnumMapping mapping)
 {
     _mapping = mapping;
 }
Esempio n. 28
0
    private void BindData()
    {
        int taskState = 0;

        if (UserSearch != null && UserSearch.TaskState != 0)
        {
            taskState = UserSearch.TaskState;
        }
        TaskPriority?taskPriority = null;

        if (UserSearch != null && UserSearch.TaskPriority != 0)
        {
            taskPriority = (TaskPriority)UserSearch.TaskPriority;
        }
        string pp = ((UserSearch == null || UserSearch.ProjectID == 0) ? "全部项目" : UserSearch.ProjectName) + " > " + ((UserSearch == null || UserSearch.PlanID == 0) ? "全部计划" : UserSearch.PlanName);

        if (!string.IsNullOrEmpty(UserSearch.StepName))
        {
            pp += "[" + UserSearch.StepName + "]";
        }
        if (UserSearch.TaskPriority > 0)
        {
            pp += "[" + EnumMapping.GetText <TaskPriority>(UserSearch.TaskPriority) + "]";
        }

        txtPosition.text = pp;

        Task_Service.ListMyHomeTask(UserSearch == null ? 0 : UserSearch.ProjectID, UserSearch == null ? 0 : UserSearch.PlanID, taskState, taskPriority, t =>
        {
            List <ETask> plist = t.GetData() as List <ETask>;
            if (!ShowComplatedTask.isOn)
            {
                plist = plist.Where(c => !c.IsComplated).ToList();
            }
            plist = plist.OrderBy(c => c.IsComplated).ToList();
            PlanListView.BindData <ETask>("MainTaskItem", plist, (i, e) =>
            {
                i.name = "TaskItem_" + e.ID.ToString();
                i.transform.Find("TIState").GetComponent <Text>().text = e.StepName;
                //i.transform.Find("TIPriority").GetComponent<Text>().text = EnumMapping.GetText<TaskPriority>((int)e.Priority);
                //if (e.Priority == TaskPriority.First)
                //    i.transform.Find("TIPriority").GetComponent<Text>().color = new Color(156 / 255f, 93 / 255f, 0 / 255f);
                //else if (e.Priority == TaskPriority.Hurry)
                //    i.transform.Find("TIPriority").GetComponent<Text>().color = new Color(223 / 255f, 60 / 255f, 0 / 255f);
                //else if (e.Priority == TaskPriority.Urgent)
                //    i.transform.Find("TIPriority").GetComponent<Text>().color = Color.red;
                //else
                //    i.transform.Find("TIPriority").GetComponent<Text>().color = new Color(139 / 255f, 139 / 255f, 139 / 255f);
                if (e.Priority == TaskPriority.First)
                {
                    i.transform.Find("PP").GetComponent <Image>().color = new Color(156 / 255f, 93 / 255f, 0 / 255f);
                }
                else if (e.Priority == TaskPriority.Hurry)
                {
                    i.transform.Find("PP").GetComponent <Image>().color = new Color(223 / 255f, 60 / 255f, 0 / 255f);
                }
                else if (e.Priority == TaskPriority.Urgent)
                {
                    i.transform.Find("PP").GetComponent <Image>().color = Color.red;
                }
                else
                {
                    i.transform.Find("PP").GetComponent <Image>().color = new Color(139 / 255f, 139 / 255f, 139 / 255f);
                }

                i.transform.Find("TIContent").GetComponent <Text>().text = e.Title;

                i.transform.Find("TIBeginTime").GetComponent <Text>().text = e.BeginTime.ToString("yyyy-MM-dd");
                i.transform.Find("TIEndTime").GetComponent <Text>().text   = e.EndTime.ToString("yyyy-MM-dd");
                if (e.ExecutorID == 0)
                {
                    i.transform.Find("TIPerson").GetComponent <Text>().text = "";
                }
                else
                {
                    i.transform.Find("TIPerson").GetComponent <Text>().text = e.TaskHeadName;
                }
                i.transform.Find("TIBtnDo").gameObject.SetActive(true);
                if (e.IsComplated)
                {
                    i.transform.Find("TIBtnDo").GetComponent <Toggle>().isOn = true;
                }
                else
                {
                    i.transform.Find("TIBtnDo").GetComponent <Toggle>().isOn = false;
                }
                EventListener.Get(i.transform.Find("TIBtnDo").gameObject).onClick = OnQuickTaskProcess;
                if (!e.IsComplated)
                {
                    i.transform.Find("ToUser").gameObject.SetActive(true);
                    EventListener.Get(i.transform.Find("ToUser").gameObject).onClick = OnGotoOther;
                }
                else
                {
                    i.transform.Find("ToUser").gameObject.SetActive(false);
                }
            });
        });
    }