Exemple #1
0
        // [Route("api/FetchEmployeeData/UpdateEmployees")]
        public int UpdateRole([FromBody] RoleAttribute role)
        {
            RoleContext context = HttpContext.RequestServices.GetService(typeof(RMG.Models.RoleContext)) as RoleContext;

            context.UpdateRole(role);
            return(1);
        }
Exemple #2
0
 protected void InitProperties()
 {
     if (propertys == null)
     {
         propertys = new Dictionary <string, Property>();
         foreach (PropertyInfo prop in this.GetType().GetProperties().Where(p => !p.PropertyType.Name.Equals("Object") && !p.Name.Equals("Item") && !p.Name.Equals("Propertys") && !p.Name.Equals("EPropertys")))
         {
             propertys[prop.Name] = new Property(prop);
         }
     }
     if (epropertys == null)
     {
         epropertys = new Dictionary <int, Property>();
         foreach (PropertyInfo prop in this.GetType().GetProperties().Where(p => !p.PropertyType.Name.Equals("Object") && !p.Name.Equals("Item") && !p.Name.Equals("Propertys") && !p.Name.Equals("EPropertys")))
         {
             if (this is RoleAttributeData)
             {
                 RoleAttribute key = (RoleAttribute)Enum.Parse(typeof(RoleAttribute), prop.Name);
                 epropertys[(int)key] = new Property(prop);
             }
             //if (this is AbilityEffects)
             //{
             //    ControlEffect key = (ControlEffect)Enum.Parse(typeof(ControlEffect), prop.Name);
             //    epropertys[(int)key] = new Property(prop);
             //}
         }
     }
 }
    private void InitAttribute()
    {
        attribute = new RoleAttribute(roleID);
        attribute.SetBaseAttribute(strength, agility, intelligent);

        maxhp       = attribute.maxHP;
        actionValue = attribute.physicAttack;
        def         = attribute.physicDefence;


        /*Debug.Log("----Name " + roleName);
         * Debug.Log("strength " + attribute.strength);
         * Debug.Log("agility " + attribute.agility);
         * Debug.Log("intelligent " + attribute.intelligent);
         * Debug.Log("maxHP " + attribute.maxHP);
         * Debug.Log("physicDefence " + attribute.physicDefence);
         * Debug.Log("critPower " + attribute.critPower);
         * Debug.Log("attackSpeed " + attribute.attackSpeed);
         * Debug.Log("physicAttack " + attribute.physicAttack);
         * Debug.Log("critRate " + attribute.critRate);
         * Debug.Log("magicAttack " + attribute.magicAttack);
         * Debug.Log("magicDefence " + attribute.magicDefence);
         * Debug.Log("maxMP " + attribute.maxMP);
         * Debug.Log("range " + attribute.range);*/
    }
Exemple #4
0
 private int GetRoleAttrValue(RoleAttribute attr)
 {
     if (attr == null)
     {
         return(0);
     }
     return((int)attr.value);
 }
Exemple #5
0
 private static float GetRoleAttrValue(RoleAttribute attr)
 {
     if (attr == null)
     {
         return(0f);
     }
     return(attr.value);
 }
    private void PushAttribute(RoleAttribute left, RoleAttribute right = null)
    {
        RoleAttributeAgent attr = attrCache.Get(contentParent);

        attr.Init(left, right);
        attr.transform.SetSiblingIndex(elementsCount);
        attributes.Add(attr);
        elementsCount++;
    }
Exemple #7
0
    public void ChangeAttrebuteMaxValue(RoleAttribute role_attr, int add_value)
    {
        // 增加本身最大数值,然后重新计算数值
        int attr = (int)role_attr;

        max_attribute[attr] += add_value;

        UpdateAttr();
    }
 public void Init(RoleAttribute _roleAttribute)
 {
     //for (int i = 0; i < _roleAttribute.attribute.Length; i++)
     //{
     //    AttributeAndText AttributeAndText1 = new AttributeAndText();
     //    AttributeAndText1.name = _roleAttribute.attribute[i].attributeName;
     //    attributeAndText.Add(AttributeAndText1);
     //}
 }
Exemple #9
0
 public void Init(RoleAttribute _roleAttribute)
 {
     for (int i = 0; i < _roleAttribute.attribute.Length; i++)
     {
         AttributeAndText AttributeAndText1 = new AttributeAndText();
         AttributeAndText1.name = _roleAttribute.attribute[i].attributeName;
         attributeAndText.Add(AttributeAndText1);
     }
 }
Exemple #10
0
        private static RoleAttribute addRoleAttrValue(RoleAttribute attr, RoleAttributeType type, float value)
        {
            if (attr == null)
            {
                attr = new RoleAttribute(type, 0);
            }

            attr.value = attr.value + value;
            return(attr);
        }
Exemple #11
0
 protected virtual float Remedy(RoleAttribute type, float force, Role from)
 {
     if (type == RoleAttribute.HP)
     {
     }
     else if (type == RoleAttribute.MP)
     {
     }
     return(0f);
 }
Exemple #12
0
    void Start()
    {
        RoleAttribute PlayerOne = new RoleAttribute();

        PlayerOne.BasePlayers();
        PlayerOne.OnApplicationQuit();
        PlayerOne.LoadPlayerData();
        PlayerOne.PlayerUpLv();
        TextPrint.text = "等级是:" + PlayerOne.LV + ",力量是:" + PlayerOne.Strong + ",智力是:"
                         + PlayerOne.Intelligence + ",敏捷是:" + PlayerOne.Agility + ",幸运是:" + PlayerOne.Luckys;
    }
Exemple #13
0
 public void Set(RoleAttribute curAttri, int add, bool ignoreAdd = false)
 {
     text_title.text = curAttri.Name;
     text_value.text = curAttri.ValueString;
     if (ignoreAdd)
     {
         text_add.text = string.Empty;
     }
     else
     {
         text_add.text = string.Format("(+{0})", add);
     }
 }
Exemple #14
0
    public int GetItemAttrbuite(int item_id, RoleAttribute attribute)
    {
        ItemData       item        = GameData.instance.all_item[item_id];
        ItemStaticData static_data = GameData.instance.item_static_data[item.static_id];

        for (int i = 0; i < static_data.attributes.Length; i++)
        {
            if (static_data.attributes[i] == RoleAttribute.max_item)
            {
                return(static_data.attr_values[i]);
            }
        }
        return(0);
    }
        public CommonReflectionInfo(OperatorDefinition def, RoleAttribute attr, MethodBase method)
        {
            this.method = method;
            this.def = def;
            this.name = attr.ComputeName(method);

            var type = method.DeclaringType;
            if (type.IsGenericType && !type.IsGenericTypeDefinition)
                type = type.GetGenericTypeDefinition();

            this.ns = TypeHelper.GetNamespaceName(type);
            parameters = new PropertyDefinitionCollection();
            parameters.AddRange(def, ns, method.GetParameters(), method.IsExtension());
        }
Exemple #16
0
    public virtual void Awake()
    {
        if (attribute == null)
        {
            attribute = new RoleAttribute();
        }

        if (buffs == null)
        {
            buffs = new List <BaseBuff>();
        }

        eventHelper = GetComponentInChildren <SimpleEventHelper>();
    }
 public void Set(RoleAttribute roleAttribute, string remark)
 {
     if (text_title != null)
     {
         text_title.text = roleAttribute.Name;
     }
     if (text_value != null)
     {
         text_value.text = roleAttribute.ValueString;
     }
     if (text_add != null)
     {
         text_add.text = string.Format("({0})", remark);
     }
 }
Exemple #18
0
    public void ChangeAttrebuteValue(RoleAttribute role_attr, int add_value)
    {
        // 恢复最终数值,然后按照比例恢复本身数值 不影响最大数值
        int attr = (int)role_attr;

        definitive_attribute[attr] = Mathf.Min(0, Mathf.Min(definitive_attribute[attr] + add_value, definitive_max_attribute[attr]));
        if (definitive_attribute[attr] == definitive_max_attribute[attr])
        {
            attribute[attr] = max_attribute[attr];
        }
        else
        {
            attribute[attr] = (int)(max_attribute[attr] * (definitive_attribute[attr] * 1f / definitive_max_attribute[attr]));
        }
        EventManager.SendEvent(EventTyp.AttrChange, this);
    }
Exemple #19
0
 public override void SetGongfaCondition()
 {
     if ((type & GongfaType.gong) == GongfaType.gong || (type & GongfaType.juan) == GongfaType.juan)
     {
         base.SetGongfaCondition();
     }
     else
     {
         attr_condition  = new RoleAttribute[1][];
         value_condition = new int[1] {
             level *level * 6 + level *color + level * 2 + color
         };                                                                                      // 等级*等级*6+等级*品质+等级*2+品质
         attr_condition[0] = new RoleAttribute[] { RoleAttribute.gongfa_knife, RoleAttribute.gongfa_spear, RoleAttribute.gongfa_sword,
                                                   RoleAttribute.gongfa_fist, RoleAttribute.gongfa_palm, RoleAttribute.gongfa_finger, };
         UnityEngine.Debug.Log("功法资质  B属性条件  " + attr_condition);
     }
 }
Exemple #20
0
    public virtual void SetGongfaCondition()
    {
        // 功法需求
        attr_condition  = new RoleAttribute[1][];
        value_condition = new int[1] {
            level *level * 6 + level *color + level * 2 + color
        };                                                                                      // 等级*等级*6+等级*品质+等级*2+品质

        int max = RoleAttribute.linggen_wood - RoleAttribute.gongfa_knife;
        for (int i = 0; i <= max; i++)
        {
            GongfaType typ = (GongfaType)(1 << i);
            if ((type & typ) == typ)
            {
                attr_condition[0] = new RoleAttribute[] { RoleAttribute.gongfa_knife + i };
                break;
            }
        }
        UnityEngine.Debug.Log("  A属性条件  " + attr_condition);
        UnityEngine.Debug.Log("  A属性条件  " + attr_condition[0][0]);
    }
 public void Init(RoleAttribute left, RoleAttribute right = null)
 {
     Clear();
     if (left)
     {
         leftName.text = left.name;
         if (!RoleAttribute.IsUsingBoolValue(left))
         {
             leftValue.text = left.Value.ToString();
         }
     }
     if (right)
     {
         rightName.text = right.name;
         if (!RoleAttribute.IsUsingBoolValue(right))
         {
             rightValue.text = right.Value.ToString();
         }
     }
     ZetanUtility.SetActive(arrow, right != null);
 }
Exemple #22
0
    /// <summary>
    /// 修改数值
    /// </summary>
    public void SetAttrebuteValue(RoleAttribute role_attr, int set_value, bool need_update = true)
    {
        // 直接修改数值
        int attr = (int)role_attr;

        if (need_update)
        {
            max_attribute[attr] = set_value;
            if (role_attr != RoleAttribute.life)
            {
                attribute[attr] = set_value;
            }
            UpdateAttr();
        }
        else
        {
            max_attribute[attr]            = set_value;
            attribute[attr]                = set_value;
            definitive_attribute[attr]     = set_value;
            definitive_max_attribute[attr] = set_value;
        }
    }
Exemple #23
0
    public void PathAI(MapGrid start, MapGrid end, RoleAttribute Attr, bool CutPath = false)
    {
        Path.PathAI(m_SceneID, start, end, m_parent.m_Attr as RoleAttribute, CurrentGS, WalkDIR);
        if (CutPath)
        {
            Role r = m_parent as Role;

#if UNITY_EDITOR_LOG
            FileLog.write(m_parent.SceneID, "PathAI");
#endif
            r.ChangeTarget(ChangeTargetReason.InGoldPath, r.RoleWalk.m_RadarAI.GetTarget(Path, Attr.AttackLike));
            //r.Target =  r.RoleWalk.m_RadarAI.GetTarget(Path,Attr.AttackLike);
        }

        if (!CheackIdlePath())
        {
            PathInit();
        }


        FirstCheckAttack();
    }
 public void Set(RoleAttribute curAttri, int add = 0, bool ignoreAdd = true)
 {
     if (text_title != null)
     {
         text_title.text = curAttri.Name;
     }
     if (text_value != null)
     {
         text_value.text = curAttri.ValueString;
     }
     if (text_add != null)
     {
         if (ignoreAdd)
         {
             text_add.text = string.Empty;
         }
         else
         {
             text_add.text = string.Format("(+{0})", add);
         }
     }
 }
Exemple #25
0
    public static bool IsUsingIntValue(RoleAttribute attr)
    {
        switch (attr.type)
        {
        case RoleAttributeType.HP:
        case RoleAttributeType.MP:
        case RoleAttributeType.SP:
        case RoleAttributeType.CutATK:
        case RoleAttributeType.PunATK:
        case RoleAttributeType.BluATK:
        case RoleAttributeType.DEF:
            return(true);

        case RoleAttributeType.Hit:
        case RoleAttributeType.Crit:
        case RoleAttributeType.ATKSpeed:
        case RoleAttributeType.MoveSpeed:
        case RoleAttributeType.TestBool:
        default:
            return(false);
        }
    }
Exemple #26
0
    static ItemConfigData()
    {
        List <ItemStaticData> item_list = new List <ItemStaticData>(GameData.instance.item_static_data);
        int item_id = item_list.Count;

        string[] list = Tools.ReadAllText("Config/itemConfig.txt").Split('\n');
        foreach (string line in list)
        {
            if (string.IsNullOrWhiteSpace(line))
            {
                break;
            }
            if (line.StartsWith("#"))
            {
                continue;
            }
            string[]    configs = line.Split('\t');
            int         idx     = 0;
            ItemType    type    = (ItemType)Enum.Parse(typeof(ItemType), configs[idx++]);
            ItemSubType subType = (ItemSubType)Enum.Parse(typeof(ItemSubType), configs[idx++]);

            int    price     = int.Parse(configs[idx++]);
            int    maxcount  = int.Parse(configs[idx++]);
            string str_param = configs[idx++];
            int[]  param;
            if (string.IsNullOrWhiteSpace(str_param))
            {
                param = new int[0];
            }
            else
            {
                string[] list_param = str_param.Split('|');
                param = new int[list_param.Length];
                for (int i = 0; i < list_param.Length; i++)
                {
                    param[i] = int.Parse(list_param[i]);
                }
            }
            string          name     = configs[idx++];
            int             icon     = int.Parse(configs[idx++]);
            int             color    = int.Parse(configs[idx++]);
            int             level    = int.Parse(configs[idx++]);
            string          des      = string.Join("\n", configs[idx++].Split('|'));
            string          attr_str = configs[idx++];
            RoleAttribute[] attributes;
            int[]           attr_values;
            if (string.IsNullOrWhiteSpace(attr_str))
            {
                attributes  = new RoleAttribute[0];
                attr_values = new int[0];
            }
            else
            {
                string[] attrs      = attr_str.Split('|');
                int      attr_count = attrs.Length;
                attributes  = new RoleAttribute[attr_count];
                attr_values = new int[attr_count];
                for (int i = 0; i < attr_count; i++)
                {
                    string[] tmp = attrs[i].Split('*');
                    attributes[i]  = (RoleAttribute)Enum.Parse(typeof(RoleAttribute), tmp[0]);
                    attr_values[i] = int.Parse(tmp[1]);
                }
            }
            item_list.Add(new ItemStaticData()
            {
                id         = item_id, param = param, type = type, sub_ype = subType, maxcount = maxcount,
                name       = name, icon = icon, color = color, level = level, des = des, price = price,
                attributes = attributes, attr_values = attr_values,
            });
        }
        dataList = item_list.ToArray();
    }
Exemple #27
0
 public void Set(RoleAttribute curAttri)
 {
     Set(curAttri, 0, true);
 }
        public override void Invoke(AMFContext context)
        {
            MessageOutput messageOutput = context.MessageOutput;

            for (int i = 0; i < context.AMFMessage.BodyCount; i++)
            {
                AMFBody      amfBody      = context.AMFMessage.GetBodyAt(i);
                ResponseBody responseBody = null;
                //Check for Flex2 messages and skip
                if (amfBody.IsEmptyTarget)
                {
                    continue;
                }

                if (amfBody.IsDebug)
                {
                    continue;
                }
                if (amfBody.IsDescribeService)
                {
                    responseBody = new ResponseBody();
                    responseBody.IgnoreResults = amfBody.IgnoreResults;
                    responseBody.Target        = amfBody.Response + AMFBody.OnResult;
                    responseBody.Response      = null;
                    DescribeService describeService = new DescribeService(amfBody);
                    responseBody.Content = describeService.GetDescription();
                    messageOutput.AddBody(responseBody);
                    continue;
                }

                //Check if response exists.
                responseBody = messageOutput.GetResponse(amfBody);
                if (responseBody != null)
                {
                    continue;
                }

                try
                {
                    MessageBroker   messageBroker   = _endpoint.GetMessageBroker();
                    RemotingService remotingService = messageBroker.GetService(RemotingService.RemotingServiceId) as RemotingService;
                    if (remotingService == null)
                    {
                        string serviceNotFound = __Res.GetString(__Res.Service_NotFound, RemotingService.RemotingServiceId);
                        responseBody = new ErrorResponseBody(amfBody, new FluorineException(serviceNotFound));
                        messageOutput.AddBody(responseBody);
                        if (log.IsErrorEnabled)
                        {
                            log.Error(serviceNotFound);
                        }
                        continue;
                    }
                    Destination destination = null;
                    if (destination == null)
                    {
                        destination = remotingService.GetDestinationWithSource(amfBody.TypeName);
                    }
                    if (destination == null)
                    {
                        destination = remotingService.DefaultDestination;
                    }
                    //At this moment we got a destination with the exact source or we have a default destination with the "*" source.
                    if (destination == null)
                    {
                        string destinationNotFound = __Res.GetString(__Res.Destination_NotFound, amfBody.TypeName);
                        responseBody = new ErrorResponseBody(amfBody, new FluorineException(destinationNotFound));
                        messageOutput.AddBody(responseBody);
                        if (log.IsErrorEnabled)
                        {
                            log.Error(destinationNotFound);
                        }
                        continue;
                    }

                    try
                    {
                        remotingService.CheckSecurity(destination);
                    }
                    catch (UnauthorizedAccessException exception)
                    {
                        responseBody = new ErrorResponseBody(amfBody, exception);
                        if (log.IsDebugEnabled)
                        {
                            log.Debug(exception.Message);
                        }
                        continue;
                    }

                    //Cache check
                    string source        = amfBody.TypeName + "." + amfBody.Method;
                    IList  parameterList = amfBody.GetParameterList();
                    string key           = FluorineFx.Configuration.CacheMap.GenerateCacheKey(source, parameterList);
                    if (FluorineConfiguration.Instance.CacheMap.ContainsValue(key))
                    {
                        object result = FluorineFx.Configuration.FluorineConfiguration.Instance.CacheMap.Get(key);
                        if (result != null)
                        {
                            if (log != null && log.IsDebugEnabled)
                            {
                                log.Debug(__Res.GetString(__Res.Cache_HitKey, source, key));
                            }
                            responseBody = new ResponseBody(amfBody, result);
                            messageOutput.AddBody(responseBody);
                            continue;
                        }
                    }

                    object          instance;
                    FactoryInstance factoryInstance = destination.GetFactoryInstance();
                    lock (factoryInstance)
                    {
                        factoryInstance.Source = amfBody.TypeName;
                        if (FluorineContext.Current.ActivationMode != null)//query string can override the activation mode
                        {
                            factoryInstance.Scope = FluorineContext.Current.ActivationMode;
                        }
                        instance = factoryInstance.Lookup();
                    }
                    if (instance != null)
                    {
                        try
                        {
                            bool isAccessible = TypeHelper.GetTypeIsAccessible(instance.GetType());
                            if (!isAccessible)
                            {
                                string msg = __Res.GetString(__Res.Type_InitError, amfBody.TypeName);
                                if (log.IsErrorEnabled)
                                {
                                    log.Error(msg);
                                }
                                responseBody = new ErrorResponseBody(amfBody, new FluorineException(msg));
                                messageOutput.AddBody(responseBody);
                                continue;
                            }

                            MethodInfo mi = null;
                            if (!amfBody.IsRecordsetDelivery)
                            {
                                mi = MethodHandler.GetMethod(instance.GetType(), amfBody.Method, parameterList);
                            }
                            else
                            {
                                //will receive recordsetid only (ignore)
                                mi = instance.GetType().GetMethod(amfBody.Method);
                            }
                            if (mi != null)
                            {
                                object[] roleAttributes = mi.GetCustomAttributes(typeof(RoleAttribute), true);
                                if (roleAttributes != null && roleAttributes.Length == 1)
                                {
                                    RoleAttribute roleAttribute = roleAttributes[0] as RoleAttribute;
                                    string[]      roles         = roleAttribute.Roles.Split(',');

                                    bool authorized = messageBroker.LoginManager.DoAuthorization(roles);
                                    if (!authorized)
                                    {
                                        throw new UnauthorizedAccessException(__Res.GetString(__Res.Security_AccessNotAllowed));
                                    }
                                }

                                #region Invocation handling
                                PageSizeAttribute pageSizeAttribute  = null;
                                MethodInfo        miCounter          = null;
                                object[]          pageSizeAttributes = mi.GetCustomAttributes(typeof(PageSizeAttribute), true);
                                if (pageSizeAttributes != null && pageSizeAttributes.Length == 1)
                                {
                                    pageSizeAttribute = pageSizeAttributes[0] as PageSizeAttribute;
                                    miCounter         = instance.GetType().GetMethod(amfBody.Method + "Count");
                                    if (miCounter != null && miCounter.ReturnType != typeof(System.Int32))
                                    {
                                        miCounter = null; //check signature
                                    }
                                }
                                ParameterInfo[] parameterInfos = mi.GetParameters();
                                //Try to handle missing/optional parameters.
                                object[] args = new object[parameterInfos.Length];
                                if (!amfBody.IsRecordsetDelivery)
                                {
                                    if (args.Length != parameterList.Count)
                                    {
                                        string msg = __Res.GetString(__Res.Arg_Mismatch, parameterList.Count, mi.Name, args.Length);
                                        if (log != null && log.IsErrorEnabled)
                                        {
                                            log.Error(msg);
                                        }
                                        responseBody = new ErrorResponseBody(amfBody, new ArgumentException(msg));
                                        messageOutput.AddBody(responseBody);
                                        continue;
                                    }
                                    parameterList.CopyTo(args, 0);
                                    if (pageSizeAttribute != null)
                                    {
                                        PagingContext pagingContext = new PagingContext(pageSizeAttribute.Offset, pageSizeAttribute.Limit);
                                        PagingContext.SetPagingContext(pagingContext);
                                    }
                                }
                                else
                                {
                                    if (amfBody.Target.EndsWith(".release"))
                                    {
                                        responseBody = new ResponseBody(amfBody, null);
                                        messageOutput.AddBody(responseBody);
                                        continue;
                                    }
                                    string recordsetId = parameterList[0] as string;
                                    string recordetDeliveryParameters = amfBody.GetRecordsetArgs();
                                    byte[] buffer = System.Convert.FromBase64String(recordetDeliveryParameters);
                                    recordetDeliveryParameters = System.Text.Encoding.UTF8.GetString(buffer);
                                    if (recordetDeliveryParameters != null && recordetDeliveryParameters != string.Empty)
                                    {
                                        string[] stringParameters = recordetDeliveryParameters.Split(new char[] { ',' });
                                        for (int j = 0; j < stringParameters.Length; j++)
                                        {
                                            if (stringParameters[j] == string.Empty)
                                            {
                                                args[j] = null;
                                            }
                                            else
                                            {
                                                args[j] = stringParameters[j];
                                            }
                                        }
                                        //TypeHelper.NarrowValues(argsStore, parameterInfos);
                                    }
                                    PagingContext pagingContext = new PagingContext(System.Convert.ToInt32(parameterList[1]), System.Convert.ToInt32(parameterList[2]));
                                    PagingContext.SetPagingContext(pagingContext);
                                }

                                TypeHelper.NarrowValues(args, parameterInfos);

                                try
                                {
                                    InvocationHandler invocationHandler = new InvocationHandler(mi);
                                    object            result            = invocationHandler.Invoke(instance, args);

                                    if (FluorineConfiguration.Instance.CacheMap != null && FluorineConfiguration.Instance.CacheMap.ContainsCacheDescriptor(source))
                                    {
                                        //The result should be cached
                                        CacheableObject cacheableObject = new CacheableObject(source, key, result);
                                        FluorineConfiguration.Instance.CacheMap.Add(cacheableObject.Source, cacheableObject.CacheKey, cacheableObject);
                                        result = cacheableObject;
                                    }
                                    responseBody = new ResponseBody(amfBody, result);

                                    if (pageSizeAttribute != null)
                                    {
                                        int    totalCount  = 0;
                                        string recordsetId = null;

                                        IList  list = amfBody.GetParameterList();
                                        string recordetDeliveryParameters = null;
                                        if (!amfBody.IsRecordsetDelivery)
                                        {
                                            //fist call paging
                                            object[] argsStore = new object[list.Count];
                                            list.CopyTo(argsStore, 0);
                                            recordsetId = System.Guid.NewGuid().ToString();
                                            if (miCounter != null)
                                            {
                                                //object[] counterArgs = new object[0];
                                                totalCount = (int)miCounter.Invoke(instance, args);
                                            }
                                            string[] stringParameters = new string[argsStore.Length];
                                            for (int j = 0; j < argsStore.Length; j++)
                                            {
                                                if (argsStore[j] != null)
                                                {
                                                    stringParameters[j] = argsStore[j].ToString();
                                                }
                                                else
                                                {
                                                    stringParameters[j] = string.Empty;
                                                }
                                            }
                                            recordetDeliveryParameters = string.Join(",", stringParameters);
                                            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(recordetDeliveryParameters);
                                            recordetDeliveryParameters = System.Convert.ToBase64String(buffer);
                                        }
                                        else
                                        {
                                            recordsetId = amfBody.GetParameterList()[0] as string;
                                        }
                                        if (result is DataTable)
                                        {
                                            DataTable dataTable = result as DataTable;
                                            dataTable.ExtendedProperties["TotalCount"]  = totalCount;
                                            dataTable.ExtendedProperties["Service"]     = recordetDeliveryParameters + "/" + amfBody.Target;
                                            dataTable.ExtendedProperties["RecordsetId"] = recordsetId;
                                            if (amfBody.IsRecordsetDelivery)
                                            {
                                                dataTable.ExtendedProperties["Cursor"]      = Convert.ToInt32(list[list.Count - 2]);
                                                dataTable.ExtendedProperties["DynamicPage"] = true;
                                            }
                                        }
                                    }
                                }
                                catch (UnauthorizedAccessException exception)
                                {
                                    responseBody = new ErrorResponseBody(amfBody, exception);
                                    if (log.IsDebugEnabled)
                                    {
                                        log.Debug(exception.Message);
                                    }
                                }
                                catch (Exception exception)
                                {
                                    if (exception is TargetInvocationException && exception.InnerException != null)
                                    {
                                        responseBody = new ErrorResponseBody(amfBody, exception.InnerException);
                                    }
                                    else
                                    {
                                        responseBody = new ErrorResponseBody(amfBody, exception);
                                    }
                                    if (log.IsDebugEnabled)
                                    {
                                        log.Debug(__Res.GetString(__Res.Invocation_Failed, mi.Name, exception.Message));
                                    }
                                }
                                #endregion Invocation handling
                            }
                            else
                            {
                                responseBody = new ErrorResponseBody(amfBody, new MissingMethodException(amfBody.TypeName, amfBody.Method));
                            }
                        }
                        finally
                        {
                            factoryInstance.OnOperationComplete(instance);
                        }
                    }
                    else
                    {
                        responseBody = new ErrorResponseBody(amfBody, new TypeInitializationException(amfBody.TypeName, null));
                    }
                }
                catch (Exception exception)
                {
                    if (log != null && log.IsErrorEnabled)
                    {
                        log.Error(exception.Message + String.Format(" (Type: {0}, Method: {1})", amfBody.TypeName, amfBody.Method), exception);
                    }
                    responseBody = new ErrorResponseBody(amfBody, exception);
                }
                messageOutput.AddBody(responseBody);
            }
        }
Exemple #29
0
    public void Set(RoleAttributeType type, int cur, int add)
    {
        RoleAttribute attri = new RoleAttribute(type, cur);

        Set(attri, add, false);
    }
        public override object Invoke(IMessage message)
        {
            object          result          = null;
            RemotingMessage remotingMessage = message as RemotingMessage;
            string          operation       = remotingMessage.operation;
            string          className       = this.DestinationDefinition.Properties.Source;

            //This property is provided for backwards compatibility. The best practice, however, is to not expose the underlying source of a
            //RemoteObject destination on the client and only one source to a destination.
            if (remotingMessage.source != null && remotingMessage.source != string.Empty)
            {
                if (className == "*")
                {
                    className = remotingMessage.source;
                }
                if (className != remotingMessage.source)
                {
                    string msg = __Res.GetString(__Res.Type_MismatchMissingSource, remotingMessage.source, this.DestinationDefinition.Properties.Source as string);
                    throw new MessageException(msg, new TypeLoadException(msg));
                }
            }

            if (className == null)
            {
                throw new TypeInitializationException("null", null);
            }

            //Service mapping obsolete for Flex Remoting

            /*
             * if (FluorineConfiguration.Instance.ServiceMap != null)
             * {
             *  string method = remotingMessage.operation;
             *  if (FluorineConfiguration.Instance.ServiceMap.Contains(className))
             *  {
             *      string serviceLocation = FluorineConfiguration.Instance.ServiceMap.GetServiceLocation(className);
             *      method = FluorineConfiguration.Instance.ServiceMap.GetMethod(className, method);
             *      if (log != null && log.IsDebugEnabled)
             *          log.Debug(__Res.GetString(__Res.Service_Mapping, className + "." + remotingMessage.operation, serviceLocation + "." + method));
             *
             *      className = serviceLocation;
             *      remotingMessage.operation = method;
             *  }
             * }
             */
            //Cache check
            string source        = className + "." + operation;
            IList  parameterList = remotingMessage.body as IList;
            string key           = dotFlex.Configuration.CacheMap.GenerateCacheKey(source, parameterList);

            if (FluorineConfiguration.Instance.CacheMap.ContainsValue(key))
            {
                result = dotFlex.Configuration.FluorineConfiguration.Instance.CacheMap.Get(key);
                if (result != null)
                {
                    if (log != null && log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Cache_HitKey, operation, key));
                    }
                    return(result);
                }
            }

            FactoryInstance factoryInstance = this.Destination.GetFactoryInstance();

            factoryInstance.Source = className;
            object instance = factoryInstance.Lookup();

            if (instance != null)
            {
                try
                {
                    Type type         = instance.GetType();
                    bool isAccessible = TypeHelper.GetTypeIsAccessible(type);
                    if (!isAccessible)
                    {
                        string msg = __Res.GetString(__Res.Type_InitError, type.FullName);
                        throw new MessageException(msg, new TypeLoadException(msg));
                    }

                    MethodInfo mi = MethodHandler.GetMethod(type, operation, parameterList);
                    if (mi != null)
                    {
                        try
                        {
                            //Messagebroker checked xml configured security, check attributes too
                            object[] roleAttributes = mi.GetCustomAttributes(typeof(RoleAttribute), true);
                            if (roleAttributes != null && roleAttributes.Length == 1)
                            {
                                RoleAttribute roleAttribute = roleAttributes[0] as RoleAttribute;
                                string[]      roles         = roleAttribute.Roles.Split(',');

                                bool authorized = this.Destination.Service.GetMessageBroker().LoginManager.DoAuthorization(roles);
                                if (!authorized)
                                {
                                    throw new UnauthorizedAccessException(__Res.GetString(__Res.Security_AccessNotAllowed));
                                }
                            }

                            ParameterInfo[] parameterInfos = mi.GetParameters();
                            object[]        args           = new object[parameterInfos.Length];
                            parameterList.CopyTo(args, 0);
                            TypeHelper.NarrowValues(args, parameterInfos);
                            InvocationHandler invocationHandler = new InvocationHandler(mi);
                            result = invocationHandler.Invoke(instance, args);
                        }
                        catch (TargetInvocationException exception)
                        {
                            MessageException messageException = null;
                            if (exception.InnerException is MessageException)
                            {
                                messageException = exception.InnerException as MessageException;//User code throws MessageException
                            }
                            else
                            {
                                messageException = new MessageException(exception.InnerException);
                            }

                            if (log.IsDebugEnabled)
                            {
                                log.Debug(__Res.GetString(__Res.Invocation_Failed, mi.Name, messageException.Message));
                            }
                            return(messageException.GetErrorMessage());
                            //Do not throw here, we do not want to log user code exceptions.
                            //throw messageException;
                        }
                    }
                    else
                    {
                        throw new MessageException(new MissingMethodException(className, operation));
                    }
                }
                catch (MessageException)
                {
                    throw;
                }
                catch (Exception exception)
                {
                    MessageException messageException = new MessageException(exception);
                    throw messageException;
                }
                finally
                {
                    factoryInstance.OnOperationComplete(instance);
                }
            }
            else
            {
                throw new MessageException(new TypeInitializationException(className, null));
            }

            if (FluorineConfiguration.Instance.CacheMap != null && FluorineConfiguration.Instance.CacheMap.ContainsCacheDescriptor(source))
            {
                //The result should be cached
                CacheableObject cacheableObject = new CacheableObject(source, key, result);
                FluorineConfiguration.Instance.CacheMap.Add(cacheableObject.Source, cacheableObject.CacheKey, cacheableObject);
                result = cacheableObject;
            }
            return(result);
        }
Exemple #31
0
    public void Set(RoleAttributeType type, int cur)
    {
        RoleAttribute attri = new RoleAttribute(type, cur);

        Set(attri, 0, true);
    }