Пример #1
0
 public object defaultAdapt(ReferenceCache refCache)
 {
     if (mappedType != null)
     {
         if (typedObject is ICacheableAdaptingType)
         {
             return(((ICacheableAdaptingType)typedObject).adapt(mappedType, refCache));
         }
         else
         {
             return(typedObject.adapt(mappedType));
         }
     }
     else
     {
         if (typedObject is ICacheableAdaptingType)
         {
             return(((ICacheableAdaptingType)typedObject).defaultAdapt(refCache));
         }
         else
         {
             return(typedObject.defaultAdapt());
         }
     }
 }
 public object adapt(Type type, ReferenceCache refCache)
 {
     if (realType is ICacheableAdaptingType)
     {
         return(((ICacheableAdaptingType)realType).adapt(type, refCache));
     }
     else
     {
         return(realType.adapt(type));
     }
 }
Пример #3
0
        public void AddCommandListener <TR>(CommandReceived <TR> callback, IChannel channel)
        {
            IRTCallback rtCallback = new RTCallback <TR>(callback, result =>
            {
                try
                {
                    Command <TR> command = new Command <TR>();

                    UserInfo userInfo = new UserInfo();

                    command.UserInfo = userInfo;

                    userInfo.ConnectionId = WeborbSerializationHelper.AsString(result, "connectionId");
                    userInfo.UserId       = WeborbSerializationHelper.AsString(result, "userId");

                    command.Type = WeborbSerializationHelper.AsString(result, "type");

                    IAdaptingType data = WeborbSerializationHelper.AsAdaptingType(result, "data");

                    command.Data = (TR)data.adapt(typeof(TR));
                    callback(command);
                }
                catch (System.Exception e)
                {
                    channel.ErrorHandler?.Invoke(RTErrorType.COMMAND, new BackendlessFault(e));
                }
            }, fault =>
            {
                channel.ErrorHandler?.Invoke(RTErrorType.COMMAND, fault);
            });

            AddCommandListener(rtCallback);
        }
Пример #4
0
        private void ProcessAMFResponse <T>(IAsyncResult asyncResult)
        {
            try
            {
                AsyncStreamSetInfo <T> asyncStreamSetInfo = (AsyncStreamSetInfo <T>)asyncResult.AsyncState;

                if (asyncStreamSetInfo.responseThreadConfigurator != null)
                {
                    asyncStreamSetInfo.responseThreadConfigurator();
                }

                HttpWebRequest  request  = asyncStreamSetInfo.request;
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);

                if (Cookies != null)
                {
                    foreach (Cookie cookie in response.Cookies)
                    {
                        Cookies.Add(new Uri(GatewayUrl), cookie);
                    }
                }

                Stream        streamResponse = response.GetResponseStream();
                long          curTime        = DateTime.Now.Ticks;
                long          roundTrip      = (curTime - asyncStreamSetInfo.messageSentTime) / TimeSpan.TicksPerMillisecond;
                RequestParser parser         = new RequestParser();
                Request       responseObject = parser.readMessage(streamResponse);
                object[]      responseData   = (object[])responseObject.getRequestBodyData();
                V3Message     v3             = (V3Message)((IAdaptingType)responseData[0]).defaultAdapt();

                if (v3.isError)
                {
                    ErrMessage errorMessage = (ErrMessage)v3;
                    Fault      fault        = new Fault(errorMessage.faultString, errorMessage.faultDetail, errorMessage.faultCode);

                    if (asyncStreamSetInfo.responder != null)
                    {
                        asyncStreamSetInfo.responder.ErrorHandler(fault);
                    }

                    return;
                }

                IAdaptingType body   = (IAdaptingType)((AnonymousObject)((NamedObject)responseData[0]).TypedObject).Properties["body"];
                T             result = (T)body.adapt(typeof(T));

                if (asyncStreamSetInfo.responder != null)
                {
                    asyncStreamSetInfo.responder.ResponseHandler(result);
                }

                //  ProcessV3Message( v3, asyncStreamSetInfo.responder );
            }
            catch (Exception e)
            {
                AsyncStreamSetInfo <T> asyncStreamSetInfo = (AsyncStreamSetInfo <T>)asyncResult.AsyncState;
                ProccessException(e, asyncStreamSetInfo.responder);
            }
        }
    public object createObject( IAdaptingType argument )
    {
      if( argument is NamedObject )
        argument = ( (NamedObject) argument ).TypedObject;

      if( argument is NullType )
        return null;

      Dictionary<string, object> props = (Dictionary<string, object>) argument.adapt( typeof( Dictionary<string, object> ) );
      BackendlessUser backendlessUser = new BackendlessUser();
      backendlessUser.PutProperties( props );
      return backendlessUser;
    }
Пример #6
0
        protected void ReceivedMessage <T>(AckMessage message)
        {
            object responder = GetResponder(message.clientId.ToString());

            if (responder == null)
            {
                return;
            }
            object[] arr = (object[])((ArrayType)message.body.body).getArray();
            foreach (var o in arr)
            {
                IAdaptingType adaptingType = (IAdaptingType)o;
                GetResponder <T>(message.clientId.ToString()).ResponseHandler((T)adaptingType.adapt(typeof(T)));
            }
        }
Пример #7
0
 protected void RecieveMessages(string SubTopic, string Selector, string clientId)
 {
     try
     {
         CommandMessage message = new CommandMessage();
         message.operation = CommandMessage.POLL_OPERATION;
         Subscription.InitCommandMessage(message, SubTopic, Selector, IdInfo, clientId);
         SendRequest(message, null, null, new Responder <V3Message>(
                         result =>
         {
             if (result != null)
             {
                 if (!(result is AsyncMessage) && result.body.body is ArrayType)
                 {
                     object[] arr = (object[])((ArrayType)result.body.body).getArray();
                     foreach (object o in arr)
                     {
                         IAdaptingType adaptingType = (IAdaptingType)o;
                         base.ReceivedMessage((AsyncMessage)adaptingType.adapt(typeof(AsyncMessage)));
                     }
                 }
                 else
                 {
                     base.ReceivedMessage((AsyncMessage)result);
                 }
             }
         },
                         fault => /*(ISubscribeResponder)GetResponder(clientId).ErrorHandler(fault)*/ { }), null);
     }
     catch (Exception)
     {
         try
         {
             //GetResponder<T>().ErrorHandler(new Fault(Subscription.ReceiveMessagesError, e.Message));
         }
         catch (Exception)
         {
         }
     }
 }
Пример #8
0
        public object createObject(IAdaptingType argument)
        {
            if (argument is NamedObject)
            {
                argument = ((NamedObject)argument).TypedObject;
            }

            if (argument is NullType)
            {
                return(null);
            }

            Dictionary <string, object> props           = (Dictionary <string, object>)argument.adapt(typeof(Dictionary <string, object>));
            BackendlessUser             backendlessUser = new BackendlessUser();

            backendlessUser.PutProperties(props);
            return(backendlessUser);
        }
Пример #9
0
        internal static String AsString(AnonymousObject obj, String key)
        {
            IAdaptingType adaptingType = (IAdaptingType)obj.Properties[key];

            return(adaptingType == null ? null : (String)adaptingType.adapt(typeof(String)));
        }
Пример #10
0
 public object adapt(Type type)
 {
     return(Object != null?Object.adapt(type) : null);
 }