コード例 #1
0
        public Message Get(Message message)
        {
            MessageInformation information = new MessageInformation(message);

            try
            {
                string           sessionToken    = this.GetSessionToken(information);
                MessagePath      path            = new MessagePath(information);
                ISecurityManager securityManager = IoC.Get <ISecurityManager>();
                object           response;
                if (path.IsByParent)
                {
                    MessagePath parentPath = new MessagePath(information, true);
                    if (!parentPath.HasKeyParameter)
                    {
                        throw new ArgumentException("A link to a parent must have parameter key");
                    }
                    dynamic      bo     = securityManager.DynamicGetBO(parentPath.DtoType, sessionToken);
                    object       parent = bo.GetOne(string.Empty, parentPath.QueryInfo);
                    IObjectProxy proxy  = ObjectProxyFactory.Get(parent);
                    object       value  = proxy.GetValue(parent, path.ParentKeyParameter);
                    QueryInfo    query  = new QueryInfo();
                    query.Equal(path.KeyParameterName, value.ToString());
                    bo       = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    response = bo.GetOne(string.Empty, query);
                }
                else
                {
                    dynamic bo = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    if (path.HasKeyParameter)
                    {
                        response = bo.GetOne(string.Empty, path.QueryInfo);
                    }
                    else
                    {
                        response = bo.GetAll(path.QueryInfo);
                    }
                }
                IServiceConfiguration  configuration = IoC.Get <IServiceConfiguration>();
                JsonSerializerSettings settings      = IoC.Get <JsonSerializerSettings>();
                if (configuration.IsHateoas)
                {
                    response = this.ConvertToHateoas(response, configuration, path);
                }
                return(response.ToJsonMessage(settings, configuration.Indented));
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    return(ex.InnerException.Message.ToJsonMessage());
                }
                else
                {
                    return(ex.Message.ToJsonMessage());
                }
            }
        }
コード例 #2
0
ファイル: ObjectProxyFactory.cs プロジェクト: jseijas/supido
        /// <summary>
        /// Fills the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        public static void Fill(object source, object target)
        {
            IObjectProxy sourceProxy = Get(source);
            IObjectProxy targetProxy = Get(target);

            foreach (string propertyName in sourceProxy.PropertyNames)
            {
                targetProxy.SetValue(target, propertyName, sourceProxy.GetValue(source, propertyName));
            }
        }
コード例 #3
0
        /// <summary>
        /// Fills target object from source object, taking into account th fields to be avoided.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        public void FillUpdate(object source, object target)
        {
            IObjectProxy proxy = ObjectProxyFactory.GetByType(this.EntityType);

            foreach (IMetamodelField field in this.Fields)
            {
                if (!field.AvoidUpdate)
                {
                    proxy.SetValue(target, field.Name, proxy.GetValue(source, field.Name));
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets the object key.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public ObjectKey GetObjectKey(object entity)
        {
            List <KeyValuePair <string, object> > keyPairs = new List <KeyValuePair <string, object> >();
            IObjectProxy proxy = ObjectProxyFactory.GetByType(this.EntityType);

            foreach (IMetamodelField field in this.Fields)
            {
                if (field.IsPrimaryKey)
                {
                    keyPairs.Add(new KeyValuePair <string, object>(field.Name, proxy.GetValue(entity, field.Name)));
                }
            }
            return(new ObjectKey(this.EntityType.Name, keyPairs));
        }
コード例 #5
0
 /// <summary>
 /// Adds from object.
 /// </summary>
 /// <param name="instance">The instance.</param>
 public void AddFromObject(object instance)
 {
     if (instance != null)
     {
         IObjectProxy proxy = ObjectProxyFactory.Get(instance);
         foreach (string propertyName in proxy.PropertyNames)
         {
             object value = proxy.GetValue(instance, propertyName);
             if (value != null)
             {
                 this.AddAttribute(propertyName, value);
             }
         }
     }
 }
コード例 #6
0
ファイル: TypeMapper.cs プロジェクト: jseijas/supido
        /// <summary>
        /// Maps to source.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        public object MapToSource(object target)
        {
            if (target == null)
            {
                return(null);
            }
            IObjectProxy proxySource = ObjectProxyFactory.GetByType(this.SourceType);
            IObjectProxy proxyTarget = ObjectProxyFactory.GetByType(this.TargetType);
            object       result      = proxySource.CreateObject();

            foreach (KeyValuePair <string, string> entry in this.tgtToSrc)
            {
                proxySource.SetValue(result, entry.Value, proxyTarget.GetValue(target, entry.Key));
            }
            return(result);
        }
コード例 #7
0
ファイル: TypeMapper.cs プロジェクト: jseijas/supido
        /// <summary>
        /// Maps to target.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public object MapToTarget(object source)
        {
            if (source == null)
            {
                return(null);
            }
            IObjectProxy proxySource = ObjectProxyFactory.GetByType(this.SourceType);
            IObjectProxy proxyTarget = ObjectProxyFactory.GetByType(this.TargetType);
            object       result      = proxyTarget.CreateObject();

            foreach (KeyValuePair <string, string> entry in this.srcToTgt)
            {
                proxyTarget.SetValue(result, entry.Value, proxySource.GetValue(source, entry.Key));
            }
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// Gets the string key.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public string GetStringKey(object entity)
        {
            IObjectProxy  proxy = ObjectProxyFactory.GetByType(this.EntityType);
            int           i     = 0;
            StringBuilder sb    = new StringBuilder();

            foreach (IMetamodelField field in this.Fields)
            {
                if (field.IsPrimaryKey)
                {
                    if (i > 0)
                    {
                        sb.Append("!");
                    }
                    sb.Append(proxy.GetValue(entity, field.Name).ToString());
                    i++;
                }
            }
            return(sb.ToString());
        }
コード例 #9
0
ファイル: AMFWriter.cs プロジェクト: hepper/FlashAMF3
        public void WriteObject(ObjectEncoding objectEncoding, object obj)
        {
            if (obj != null)
            {
                AddAMF0ObjectReference(obj);

                WriteByte(AMF0TypeCode.CustomClass);

                Type type = obj.GetType();

                string customClass = type.FullName;

                customClass = GetCustomClass(customClass);

                WriteUTF(customClass);

                ClassDefinition classDefinition = GetClassDefinition(obj);

                IObjectProxy proxy = ObjectProxyRegistry.Instance.GetObjectProxy(type);

                for (int i = 0; i < classDefinition.MemberCount; i++)
                {
                    ClassMember classMember = classDefinition.Members[i];

                    object memberValue = proxy.GetValue(obj, classMember);

                    WriteUTF(classMember.Name);

                    WriteData(objectEncoding, memberValue);
                }

                WriteEndMarkup();
            }
            else
            {
                WriteNull();
            }
        }
コード例 #10
0
ファイル: AMFWriter.cs プロジェクト: melongroup/U3DExport
        public void WriteAMF3Object(object value)
        {
            if (!_objectReferences.ContainsKey(value))
            {
                _objectReferences.Add(value, _objectReferences.Count);

                ClassDefinition classDefinition = GetClassDefinition(value);
                if (classDefinition == null)
                {
                    Console.WriteLine("serializing:{0}", value.GetType().FullName);
                    // DebugX.LogError("serializing:{0}", value.GetType().FullName);
                    return;
                }
                if (_classDefinitionReferences.ContainsKey(classDefinition))
                {
                    //Existing class-def
                    int handle = (int)_classDefinitionReferences[classDefinition];//handle = classRef 0 1
                    handle = handle << 2;
                    handle = handle | 1;
                    WriteAMF3IntegerData(handle);
                }
                else
                {                //inline class-def
                    //classDefinition = CreateClassDefinition(value);
                    _classDefinitionReferences.Add(classDefinition, _classDefinitionReferences.Count);
                    //handle = memberCount dynamic externalizable 1 1
                    int handle = classDefinition.MemberCount;
                    handle = handle << 1;
                    handle = handle | (classDefinition.IsDynamic ? 1 : 0);
                    handle = handle << 1;
                    handle = handle | (classDefinition.IsExternalizable ? 1 : 0);
                    handle = handle << 2;
                    handle = handle | 3;
                    WriteAMF3IntegerData(handle);
                    WriteAMF3UTF(classDefinition.ClassName);
                    for (int i = 0; i < classDefinition.MemberCount; i++)
                    {
                        string key = classDefinition.Members[i].Name;
                        WriteAMF3UTF(key);
                    }
                }
                //write inline object
                if (classDefinition.IsExternalizable)
                {
                    if (value is IExternalizable)
                    {
                        IExternalizable externalizable = value as IExternalizable;
                        DataOutput      dataOutput     = new DataOutput(this);
                        externalizable.WriteExternal(dataOutput);
                    }
                    else
                    {
                        throw new NotImplementedException(classDefinition.ClassName + " must is IExternalizable");
                    }
                }
                else
                {
                    Type         type  = value.GetType();
                    IObjectProxy proxy = ObjectProxyRegistry.GetObjectProxy(type);

                    for (int i = 0; i < classDefinition.MemberCount; i++)
                    {
                        object memberValue = proxy.GetValue(value, classDefinition.Members[i]);
                        WriteAMF3Data(memberValue);
                    }

                    if (classDefinition.IsDynamic)
                    {
                        IDictionary dictionary = value as IDictionary;
                        foreach (DictionaryEntry entry in dictionary)
                        {
                            WriteAMF3UTF(entry.Key.ToString());
                            WriteAMF3Data(entry.Value);
                        }
                        WriteAMF3UTF(string.Empty);
                    }
                }
            }
            else
            {
                //handle = objectRef 0
                int handle = (int)_objectReferences[value];
                handle = handle << 1;
                WriteAMF3IntegerData(handle);
            }
        }
コード例 #11
0
ファイル: AMFWriter.cs プロジェクト: hepper/FlashAMF3
        /// <summary>
        /// 10
        /// </summary>
        /// <param name="value"></param>
        public void WriteAMF3Object(object value)
        {
            if (!amf3ObjectReferences.ContainsKey(value))
            {
                amf3ObjectReferences.Add(value, amf3ObjectReferences.Count);

                ClassDefinition classDefinition = GetClassDefinition(value);

                if (ContainsClassDefinitionReferences(classDefinition))
                {
                    int handle = GetClassDefinitionReferencesIndex(classDefinition);

                    handle = handle << 2;

                    handle = handle | 1;

                    WriteAMF3IntegerData(handle);
                }
                else
                {
                    amf3ClassReferences.Add(classDefinition, amf3ClassReferences.Count);

                    int handle = classDefinition.MemberCount;

                    handle = handle << 1;

                    handle = handle | (classDefinition.IsDynamic ? 1 : 0);

                    handle = handle << 1;

                    handle = handle | (classDefinition.IsExternalizable ? 1 : 0);

                    handle = handle << 2;

                    handle = handle | 3;

                    WriteAMF3IntegerData(handle);

                    WriteAMF3UTF(classDefinition.ClassName);

                    for (int i = 0; i < classDefinition.MemberCount; i++)
                    {
                        string key = classDefinition.Members[i].Name;

                        WriteAMF3UTF(key);
                    }
                }

                if (classDefinition.IsExternalizable)
                {
                    if (value is IExternalizable)
                    {
                        IExternalizable externalizable = value as IExternalizable;

                        DataOutput dataOutput = new DataOutput(this);

                        externalizable.writeExternal(dataOutput);
                    }
                    else
                    {
                        throw new Exception("writeExternal Fail:" + classDefinition.ClassName);
                    }
                }
                else
                {
                    Type type = value.GetType();

                    IObjectProxy proxy = ObjectProxyRegistry.Instance.GetObjectProxy(type);

                    for (int i = 0; i < classDefinition.MemberCount; i++)
                    {
                        object memberValue = proxy.GetValue(value, classDefinition.Members[i]);

                        WriteAMF3Data(memberValue);
                    }

                    if (classDefinition.IsDynamic)
                    {
                        IDictionary dictionary = value as IDictionary;

                        foreach (DictionaryEntry entry in dictionary)
                        {
                            WriteAMF3UTF(entry.Key.ToString());

                            WriteAMF3Data(entry.Value);
                        }

                        WriteAMF3UTF(string.Empty);
                    }
                }
            }
            else
            {
                int handle = amf3ObjectReferences[value];

                handle = handle << 1;

                WriteAMF3IntegerData(handle);
            }
        }