예제 #1
0
        private bool Update(ItemType requestedItemType, ItemType originalItemType, ItemType newItemType)
        {
            bool updated = false;
            // TODO: timestamps!
            Type t = requestedItemType.GetType();

            foreach (PropertyInfo pi in t.GetProperties())
            {
                object serverValue = pi.GetValue(requestedItemType, null);
                object origValue   = pi.GetValue(originalItemType, null);
                object newValue    = pi.GetValue(newItemType, null);

                // if the value has changed, process further
                if (!object.Equals(origValue, newValue))
                {
                    // if the server has the original value, make the update
                    if (object.Equals(serverValue, origValue))
                    {
                        pi.SetValue(requestedItemType, newValue, null);
                        updated = true;
                    }
                }
            }

            return(updated);
        }
        private IEnumerable <string> GetValueFromRecordField(ItemType itemType, string propertyName, string recordFieldname)
        {
            var values   = new List <String>();
            var property = this.GetPropertyByName(itemType, propertyName, itemType.GetType());

            if (property is EntityItemRecordType)
            {
                foreach (var recordField in ((EntityItemRecordType)property).field)
                {
                    if (recordField.name.Equals(recordFieldname, StringComparison.InvariantCultureIgnoreCase))
                    {
                        values.Add(recordField.Value);
                    }
                }
            }
            else if (property is EntityItemRecordType[])
            {
                foreach (var prop in (EntityItemRecordType[])property)
                {
                    foreach (var recordField in prop.field)
                    {
                        if (recordField.name.Equals(recordFieldname, StringComparison.InvariantCultureIgnoreCase))
                        {
                            values.Add(recordField.Value);
                        }
                    }
                }
            }

            return(values);
        }
        /// <summary>
        /// Gets the value from property. The property is defined by the item_ref property of ObjectComponentType.
        /// </summary>
        /// <param name="itemtype">The itemtype.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns></returns>
        private IEnumerable <string> GetValueFromProperty(ItemType itemtype, string propertyName)
        {
            var property = this.GetPropertyByName(itemtype, propertyName, itemtype.GetType());

            var values = new List <String>();

            if (property is EntityItemSimpleBaseType)
            {
                var propertyValue = GetPropertyByName(property, "Value", typeof(EntityItemSimpleBaseType));
                if (propertyValue != null)
                {
                    values.Add(propertyValue.ToString());
                }
            }
            else if (property is EntityItemSimpleBaseType[])
            {
                var propertyValues = GetValuesOfArrayProperty(property);
                if (propertyValues != null)
                {
                    values.AddRange(propertyValues);
                }
            }

            return(values);
        }
예제 #4
0
        public string GetPostUrl(ItemType IdType, int ItemId, string HashTag = "")
        {
            switch (IdType)
            {
            case ItemType.Blog:
                switch (ItemId)
                {
                case 0:
                    return(_urlHelper.Action("Suggestions", "Home") + HashTag);

                case -1:
                    return(_urlHelper.Action("Suggestions", "Home", new { pos = "Report" }) + HashTag);

                case -2:
                    return(_urlHelper.Action("History", "Ranking") + HashTag);

                default:
                    return(_urlHelper.Action("Details", "Blog", new { id = ItemId, area = "" }) + HashTag);
                }

            case ItemType.Topic:
                return(_urlHelper.Action("Details", "Topic", new { id = ItemId }) + HashTag);

            case ItemType.Bounty:
                return(_urlHelper.Action("Details", "Bounty", new { id = ItemId }) + HashTag);

            case ItemType.Answer:
                // TODO: find bounty id here
                return(_urlHelper.Action("Details", "Bounty", new { id = ItemId }) + HashTag);

            default:
                break;
            }
            throw new InvalidEnumArgumentException("IdType", (int)IdType, IdType.GetType());
        }
예제 #5
0
        public static void Serialize(XmlWriter xWrite, ItemType contents)
        {
            XmlSerializer           Writer = new XmlSerializer(contents.GetType());
            XmlSerializerNamespaces ns     = new XmlSerializerNamespaces();

            ns.Add("", "http://www.hybrasyl.com/XML/Items");
            Writer.Serialize(xWrite, contents, ns);
        }
예제 #6
0
        /// <summary>
        /// This method travels all the fields of ItemType comparing with the fields of another itemType.
        /// </summary>
        /// <param name="typeOfItemType">Type of the type of item.</param>
        /// <param name="typeOfStateType">Type of the type of other item.</param>
        /// <returns></returns>
        public bool IsEquals()
        {
            var  stateEntityNameResolver = new StateEntityNameResolver();
            Type typeOfItemType          = itemType.GetType();
            Type typeOfStateType         = stateType.GetType();

            var fiedsOfStateType = typeOfStateType.GetProperties();


            foreach (var field in fiedsOfStateType)
            {
                var valueOfState    = field.GetValue(this.stateType, null);
                var stateEntityName = stateEntityNameResolver.Resolve(field);

                if (valueOfState is EntitySimpleBaseType)
                {
                    if ((EntitySimpleBaseType)valueOfState != null)
                    {
                        var allItemEntities = typeOfItemType.GetProperties();
                        var fieldOfItemType =
                            allItemEntities
                            .FirstOrDefault(x => x.Name.Equals(stateEntityName, StringComparison.InvariantCultureIgnoreCase));
                        if (fieldOfItemType == null)
                        {
                            return(false);
                        }

                        if (!this.ProcessComparations(field, fieldOfItemType))
                        {
                            return(false);
                        }
                    }
                }
                else if (valueOfState is EntityComplexBaseType)
                {
                    if ((EntityComplexBaseType)valueOfState != null)
                    {
                        var fieldOfItemType =
                            typeOfItemType.GetProperties()
                            .FirstOrDefault(x => x.Name.Equals(field.Name, StringComparison.InvariantCultureIgnoreCase));

                        if (fieldOfItemType == null)
                        {
                            return(false);
                        }
                        else
                        {
                            return(ProcessComparisionForComplexEntityType(
                                       (EntityItemRecordType[])fieldOfItemType.GetValue(this.itemType, null),
                                       (EntityStateRecordType)valueOfState));
                        }
                    }
                }
            }
            return(true);
        }
예제 #7
0
    private void  CreateDicAddSprite()                                          //初始化资源库的文件(图片,总数)
    {
        ItemType e = new ItemType();

        string[] EItemType = System.Enum.GetNames(e.GetType());
        Sprite[] sprites   = Resources.LoadAll <Sprite>("Img");
        for (int i = 0; i < EItemType.Length - 1; i++)
        {
            dicSprite.Add((ItemType)(i + 1), sprites[i]);
            dicCount.Add((ItemType)(i + 1), 0);
        }
    }
예제 #8
0
        public static string ToDescription(this ItemType value)
        {
            FieldInfo info = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes = (DescriptionAttribute[])info.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes != null && attributes.Length > 0)
            {
                return(attributes[0].Description);
            }
            else
            {
                return(value.ToString());
            }
        }
예제 #9
0
        private void AddFolderBtn_Click(object sender, EventArgs e)
        {
            var files             = new List <string>();
            FolderBrowserDialog f = new FolderBrowserDialog();

            if (f.ShowDialog() == DialogResult.OK)
            {
                files = Directory.GetFiles(f.SelectedPath).ToList();
            }

            foreach (var item in files)
            {
                if (ItemType.GetType(item) == ItemType.Item.image)
                {
                    Holder.Controls.Add(Pb(view.Frm.data.Photos.AddUnit(item)));
                }
            }
        }
예제 #10
0
        public static void HandleDebugEchoFlags(Session session, params string[] parameters)
        {
            try
            {
                if (parameters?.Length == 2)
                {
                    var debugOutput = "";
                    switch (parameters[0].ToLower())
                    {
                    case "descriptionflags":
                        ObjectDescriptionFlag objectDescFlag = new ObjectDescriptionFlag();
                        objectDescFlag = (ObjectDescriptionFlag)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{objectDescFlag.GetType().Name} = {objectDescFlag.ToString()}" + " (" + (uint)objectDescFlag + ")";
                        break;

                    case "weenieflags":
                        WeenieHeaderFlag weenieHdr = new WeenieHeaderFlag();
                        weenieHdr = (WeenieHeaderFlag)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{weenieHdr.GetType().Name} = {weenieHdr.ToString()}" + " (" + (uint)weenieHdr + ")";
                        break;

                    case "weenieflags2":
                        WeenieHeaderFlag2 weenieHdr2 = new WeenieHeaderFlag2();
                        weenieHdr2 = (WeenieHeaderFlag2)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{weenieHdr2.GetType().Name} = {weenieHdr2.ToString()}" + " (" + (uint)weenieHdr2 + ")";
                        break;

                    case "positionflag":
                        UpdatePositionFlag posFlag = new UpdatePositionFlag();
                        posFlag = (UpdatePositionFlag)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{posFlag.GetType().Name} = {posFlag.ToString()}" + " (" + (uint)posFlag + ")";
                        break;

                    case "type":
                        ItemType objectType = new ItemType();
                        objectType = (ItemType)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{objectType.GetType().Name} = {objectType.ToString()}" + " (" + (uint)objectType + ")";
                        break;

                    case "containertype":
                        ContainerType contType = new ContainerType();
                        contType = (ContainerType)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{contType.GetType().Name} = {contType.ToString()}" + " (" + (uint)contType + ")";
                        break;

                    case "usable":
                        Usable usableType = new Usable();
                        usableType = (Usable)Convert.ToInt64(parameters[1]);

                        debugOutput = $"{usableType.GetType().Name} = {usableType.ToString()}" + " (" + (Int64)usableType + ")";
                        break;

                    case "radarbehavior":
                        RadarBehavior radarBeh = new RadarBehavior();
                        radarBeh = (RadarBehavior)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{radarBeh.GetType().Name} = {radarBeh.ToString()}" + " (" + (uint)radarBeh + ")";
                        break;

                    case "physicsdescriptionflags":
                        PhysicsDescriptionFlag physicsDescFlag = new PhysicsDescriptionFlag();
                        physicsDescFlag = (PhysicsDescriptionFlag)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{physicsDescFlag.GetType().Name} = {physicsDescFlag.ToString()}" + " (" + (uint)physicsDescFlag + ")";
                        break;

                    case "physicsstate":
                        PhysicsState physState = new PhysicsState();
                        physState = (PhysicsState)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{physState.GetType().Name} = {physState.ToString()}" + " (" + (uint)physState + ")";
                        break;

                    case "validlocations":
                        EquipMask locFlags = new EquipMask();
                        locFlags = (EquipMask)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{locFlags.GetType().Name} = {locFlags.ToString()}" + " (" + (uint)locFlags + ")";
                        break;

                    case "currentwieldedlocation":
                        EquipMask locFlags2 = new EquipMask();
                        locFlags2 = (EquipMask)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{locFlags2.GetType().Name} = {locFlags2.ToString()}" + " (" + (uint)locFlags2 + ")";
                        break;

                    case "priority":
                        CoverageMask covMask = new CoverageMask();
                        covMask = (CoverageMask)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{covMask.GetType().Name} = {covMask.ToString()}" + " (" + (uint)covMask + ")";
                        break;

                    case "radarcolor":
                        RadarColor radarBlipColor = new RadarColor();
                        radarBlipColor = (RadarColor)Convert.ToUInt32(parameters[1]);

                        debugOutput = $"{radarBlipColor.GetType().Name} = {radarBlipColor.ToString()}" + " (" + (uint)radarBlipColor + ")";
                        break;

                    default:
                        debugOutput = "No valid type to test";
                        break;
                    }

                    if (session == null)
                    {
                        Console.WriteLine(debugOutput.Replace(", ", " | "));
                    }
                    else
                    {
                        session.Network.EnqueueSend(new GameMessageSystemChat(debugOutput, ChatMessageType.System));
                    }
                }
            }
            catch (Exception)
            {
                string debugOutput = "Exception Error, check input and try again";
                if (session == null)
                {
                    Console.WriteLine(debugOutput.Replace(", ", " | "));
                }
                else
                {
                    session.Network.EnqueueSend(new GameMessageSystemChat(debugOutput, ChatMessageType.System));
                }
            }
        }
예제 #11
0
 private String GetCompleteFilepath(ItemType itemType)
 {
     if (itemType is OVAL.SystemCharacteristics.file_item)
     {
         return(((OVAL.SystemCharacteristics.file_item)itemType).GetFullFilepath());
     }
     if (itemType is OVAL.SystemCharacteristics.Unix.file_item)
     {
         return(((OVAL.SystemCharacteristics.Unix.file_item)itemType).GetFullFilepath());
     }
     else
     {
         throw new ArgumentException(String.Format("The object type '{0}' is not supported.", itemType.GetType().ToString()));
     }
 }