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); }
public Object createObject(IAdaptingType iAdaptingType) { if (iAdaptingType is NamedObject) { iAdaptingType = ((NamedObject)iAdaptingType).TypedObject; } if (iAdaptingType.GetType() == typeof(NullType)) { return(null); } if (iAdaptingType is AnonymousObject) { Dictionary <object, object> properties = (Dictionary <object, object>)iAdaptingType.defaultAdapt(); String geoJson = (String)properties["geoJson"]; if (geoJson == null) { return(null); } String geomClass = (String)properties["geomClass"]; int srsId = (int)properties["srsId"]; Geometry geometry = new GeometryDTO(geomClass, srsId, geoJson).ToGeometry <Geometry>(); return(geometry); } else { throw new System.Exception("Unknown type"); } }
public void AddObject( IAdaptingType key, Type type, Object value ) { if (!cache.ContainsKey(key)) cache[key] = new Dictionary<Type, object>(); cache[key][type] = value; }
public static object FromBytes(byte[] bytes, int type, bool doNotAdapt) { switch (type) { case AMF0: case AMF3: using (MemoryStream stream = new MemoryStream(bytes)) { using (FlashorbBinaryReader reader = new FlashorbBinaryReader(stream)) { IAdaptingType adpatingType = Weborb.Protocols.Amf.RequestParser.readData(reader, type == AMF0 ? 0 : 3); if (doNotAdapt) { return(adpatingType); } else { return(adpatingType.defaultAdapt()); } } } case JSON: using (MemoryStream stream = new MemoryStream(bytes)) { StreamReader streamReader = new StreamReader(stream, Encoding.UTF8); using (JsonTextReader jsonReader = new JsonTextReader(streamReader)) { jsonReader.Read(); IAdaptingType jsonType = Weborb.Protocols.JsonRPC.RequestParser.Read(jsonReader); if (doNotAdapt) { return(jsonType); } else { return(jsonType.defaultAdapt()); } } } #if (!UNIVERSALW8 && !SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8) case WOLF: using (MemoryStream stream = new MemoryStream(bytes)) { Weborb.Protocols.Wolf.RequestParser parser = Weborb.Protocols.Wolf.RequestParser.GetInstance(); Request requestObj = parser.Parse(stream); return(requestObj.getRequestBodyData()); } break; #endif default: throw new Exception("Unknown formatting type"); } }
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 void AddObject(IAdaptingType key, Type type, Object value) { if (!cache.ContainsKey(key)) { cache[key] = new Dictionary <Type, object>(); } cache[key][type] = value; }
public void addReference(IAdaptingType type) { if (ignore) { return; } references.Add(type); }
public Object GetObject( IAdaptingType key ) { return GetObject( key, key.getDefaultType() ); /* foreach (Object item in cache[key].Values) return item; throw new Exception("Object not exists in reference cache"); */ }
public void addReference(IAdaptingType adaptingType, int index) { if (ignore) { return; } references.Capacity = index + 1; references[index] = adaptingType; }
public IAdaptingType read(FlashorbBinaryReader reader, ParseContext parseContext) { int refId = reader.ReadVarInteger(); if ((refId & 0x1) == 0) { return(parseContext.getReference(refId >> 1)); } int arraySize = refId >> 1; IAdaptingType adaptingType = null; object container = null; while (true) { string str = ReaderUtils.readString(reader, parseContext); if (str == null || str.Length == 0) { break; } if (container == null) { container = new Dictionary <object, object>(); adaptingType = new AnonymousObject((IDictionary)container); parseContext.addReference(adaptingType); } object obj = RequestParser.readData(reader, parseContext); ((IDictionary)container)[str] = obj; } if (adaptingType == null) { container = new object[arraySize]; adaptingType = new ArrayType((object[])container); parseContext.addReference(adaptingType); for (int i = 0; i < arraySize; i++) { ((object[])container)[i] = RequestParser.readData(reader, parseContext); } } else { for (int i = 0; i < arraySize; i++) { object obj = RequestParser.readData(reader, parseContext); ((IDictionary)container)[i.ToString()] = obj; } } return(adaptingType); }
public Object GetObject(IAdaptingType key) { return(GetObject(key, key.getDefaultType())); /* * foreach (Object item in cache[key].Values) * return item; * * throw new Exception("Object not exists in reference cache"); */ }
public object createObject( IAdaptingType argument ) { BodyHolder bodyObj = new BodyHolder(); Object arg = argument; if( argument is ArrayType ) arg = ((ArrayType) argument).getArray(); bodyObj.body = new Object[] { arg }; return bodyObj; }
public Object GetObject( IAdaptingType key, Type type ) { if (cache[key].ContainsKey(type)) return cache[key][type]; foreach (Type item in cache[key].Keys) if (type.IsAssignableFrom(item)) return cache[key][item]; throw new Exception("Object not exists in reference cache"); }
public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext ) { int length = reader.ReadInteger(); IAdaptingType[] array = new IAdaptingType[ length ]; ArrayType arrayType = new ArrayType( array ); parseContext.addReference( arrayType ); for( int i = 0; i < length; i++ ) array[ i ] = RequestParser.readData( reader, parseContext ); return arrayType; }
internal static void ReportObjectUnderFlow(object obj, System.Collections.IDictionary props) { IDictionary <string, object> properties = new Dictionary <string, object>(); foreach (object key in props.Keys) { IAdaptingType adaptingType = (IAdaptingType)props[key]; properties[(string)key] = adaptingType.defaultAdapt(); } objectStore.Add(obj, properties); }
internal static IAdaptingType Deserialize(byte[] arg) { IAdaptingType adaptingType = (IAdaptingType)Serializer.FromBytes(arg, Serializer.JSON, true); if (adaptingType is CacheableAdaptingTypeWrapper) { return(((CacheableAdaptingTypeWrapper)adaptingType).getType()); } else { return(adaptingType); } }
public object createObject(IAdaptingType argument) { BodyHolder bodyObj = new BodyHolder(); Object arg = argument; if (argument is ArrayType) { arg = ((ArrayType)argument).getArray(); } bodyObj.body = new Object[] { arg }; return(bodyObj); }
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; }
public bool HasObject(IAdaptingType key, Type type) { if( cache.ContainsKey(key) ) { if (cache[key].ContainsKey(type)) return true; foreach (Type item in cache[key].Keys) if (type.IsAssignableFrom(item)) return true; } return false; }
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))); } }
public bool Equals(object _obj, Dictionary <DictionaryEntry, bool> visitedPairs) { IAdaptingType obj = _obj as IAdaptingType; if (obj == null) { return(false); } if (Object.ReferenceEquals(this, _obj)) { return(true); } return(obj.Equals(realType, visitedPairs)); }
public IAdaptingType read(FlashorbBinaryReader reader, ParseContext parseContext) { int length = reader.ReadInteger(); IAdaptingType[] array = new IAdaptingType[length]; ArrayType arrayType = new ArrayType(array); parseContext.addReference(arrayType); for (int i = 0; i < length; i++) { array[i] = RequestParser.readData(reader, parseContext); } return(arrayType); }
public object adapt(Type type, ReferenceCache refCache) { if (Object != null) { bool isCachable = Object is ICacheableAdaptingType; IAdaptingType cacheKey = isCachable ? (Object as ICacheableAdaptingType).getCacheKey() : Object; if (refCache.HasObject(cacheKey, type)) { return(refCache.GetObject(cacheKey, type)); } return(isCachable ? (Object as ICacheableAdaptingType).adapt(type, refCache) : Object.adapt(type)); } return(null); }
public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext ) { int refId = reader.ReadVarInteger(); if( (refId & 0x1) == 0 ) return (ArrayType) parseContext.getReference( refId >> 1 ); byte[] bytes = reader.ReadBytes( refId >> 1 ); IAdaptingType[] objArray = new IAdaptingType[bytes.Length]; for (int i = 0; i < bytes.Length; i++) objArray[i] = new NumberObject( bytes[i] ); ArrayType arrayType = new ArrayType( objArray ); parseContext.addReference( arrayType ); return arrayType; }
public Object GetObject(IAdaptingType key, Type type) { if (cache[key].ContainsKey(type)) { return(cache[key][type]); } foreach (Type item in cache[key].Keys) { if (type.IsAssignableFrom(item)) { return(cache[key][item]); } } throw new Exception("Object not exists in reference cache"); }
public object defaultAdapt(ReferenceCache refCache) { if (Object != null) { bool isCachable = Object is ICacheableAdaptingType; IAdaptingType cacheKey = isCachable ? (Object as ICacheableAdaptingType).getCacheKey() : Object; if (refCache.HasObject(cacheKey)) { return(refCache.GetObject(cacheKey)); } return(isCachable? (Object as ICacheableAdaptingType).defaultAdapt(refCache) : Object.defaultAdapt()); } return(null); }
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); }
public new void ResponseHandler(AsyncMessage asyncMessage) { IAdaptingType[] bodys = asyncMessage.GetBody(); foreach (IAdaptingType adaptingType in bodys) { object message = adaptingType.defaultAdapt(); base.ResponseHandler(message); } return; #if !(FULL_BUILD) IAdaptingType body = (IAdaptingType)asyncMessage.body; #else IAdaptingType body = (IAdaptingType)((object[])(asyncMessage.body.body))[0]; #endif object adaptedMessage = body.defaultAdapt(); base.ResponseHandler(adaptedMessage); }
internal static AnonymousObject Cast(IAdaptingType obj) { AnonymousObject anonymousObject; if (obj is AnonymousObject) { anonymousObject = (AnonymousObject)obj; } else if (obj is CacheableAdaptingTypeWrapper) { anonymousObject = (AnonymousObject)((CacheableAdaptingTypeWrapper)obj).getType(); } else { throw new System.Exception("Object must be of or contain the AnonymousObject type"); } return(anonymousObject); }
public bool HasObject(IAdaptingType key, Type type) { if (cache.ContainsKey(key)) { if (cache[key].ContainsKey(type)) { return(true); } foreach (Type item in cache[key].Keys) { if (type.IsAssignableFrom(item)) { return(true); } } } return(false); }
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) { } } }
public IAdaptingType read(FlashorbBinaryReader reader, ParseContext parseContext) { int refId = reader.ReadVarInteger(); if ((refId & 0x1) == 0) { return((ArrayType)parseContext.getReference(refId >> 1)); } byte[] bytes = reader.ReadBytes(refId >> 1); IAdaptingType[] objArray = new IAdaptingType[bytes.Length]; for (int i = 0; i < bytes.Length; i++) { objArray[i] = new NumberObject(bytes[i]); } ArrayType arrayType = new ArrayType(objArray); parseContext.addReference(arrayType); return(arrayType); }
public Body(string serviceURI, string responseURI, int length, object dataObject) { this.serviceURI = serviceURI; this.responseURI = responseURI; if (dataObject is IAdaptingType) { IAdaptingType adaptingType = (IAdaptingType)dataObject; if (adaptingType is ArrayType) { this.dataObject = ((ArrayType)adaptingType).getArray(); } else { this.dataObject = new Object[] { dataObject } }; } else { this.dataObject = dataObject; } }
private IRTRequest HandleResult <T>(Object[] args, IDictionary <String, T> requestMap, String resultKey) where T : IRTRequest { if (args == null || args.Length < 1) { Log.log(Backendless.BACKENDLESSLOG, "subscription result is null or empty"); return(null); } AnonymousObject result = (AnonymousObject)WeborbSerializationHelper.Deserialize((byte[])args[0]); String id = WeborbSerializationHelper.AsString(result, "id"); Log.log(Backendless.BACKENDLESSLOG, String.Format("Got result for subscription {0}", id)); IRTRequest request = requestMap[id]; if (request == null) { Log.log(Backendless.BACKENDLESSLOG, String.Format("There is no handler for subscription {0}", id)); return(null); } Object error = WeborbSerializationHelper.AsObject(result, "error"); if (error != null) { Log.log(Backendless.BACKENDLESSLOG, String.Format("got error {0}", error)); BackendlessFault fault = new BackendlessFault(error.ToString()); request.Callback.errorHandler(fault); return(request); } IAdaptingType data = WeborbSerializationHelper.AsAdaptingType(result, resultKey); request.Callback.responseHandler(data); return(request); }
public object _CreateArgumentObject(Type type, IAdaptingType argument) { String typeName = type.FullName; if (Log.isLogging(LoggingConstants.DEBUG)) { Log.log(LoggingConstants.DEBUG, "checking argument factory for " + typeName); } if (!argumentObjectFactories.ContainsKey(typeName)) { /* * if( type.IsInterface || type.IsAbstract ) * { * if( Log.isLogging( LoggingConstants.DEBUG ) ) * Log.log( LoggingConstants.DEBUG, "type is an interface or abstract/static" ); * * Type mappedType = Weborb.Types.Types.GetAbstractClassMapping( type ); * * if( mappedType != null ) * return ObjectFactories.CreateServiceObject( mappedType ); * }*/ return(null); } IArgumentObjectFactory objectFactory; argumentObjectFactories.TryGetValue(typeName, out objectFactory); if (Log.isLogging(LoggingConstants.DEBUG)) { Log.log(LoggingConstants.DEBUG, "will use argument factory " + objectFactory.ToString()); } return(objectFactory.createObject(argument)); }
public static object FromBytes(byte[] bytes, int type, bool doNotAdapt) { #if (!UNIVERSALW8 && !SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8) if (type == AMF0 || type == AMF3) { #endif using (MemoryStream stream = new MemoryStream(bytes)) { using (FlashorbBinaryReader reader = new FlashorbBinaryReader(stream)) { IAdaptingType adpatingType = Weborb.Protocols.Amf.RequestParser.readData(reader, type == AMF0 ? 0 : 3); if (doNotAdapt) { return(adpatingType); } else { return(adpatingType.defaultAdapt()); } } } #if (!UNIVERSALW8 && !SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8) } else { using (MemoryStream stream = new MemoryStream(bytes)) { Weborb.Protocols.Wolf.RequestParser parser = Weborb.Protocols.Wolf.RequestParser.GetInstance(); Request requestObj = parser.Parse(stream); return(requestObj.getRequestBodyData()); } } #endif }
public object _CreateArgumentObject( Type type, IAdaptingType argument ) { String typeName = type.FullName; if( Log.isLogging( LoggingConstants.DEBUG ) ) Log.log( LoggingConstants.DEBUG, "checking argument factory for " + typeName ); if( !argumentObjectFactories.ContainsKey( typeName ) ) { /* if( type.IsInterface || type.IsAbstract ) { if( Log.isLogging( LoggingConstants.DEBUG ) ) Log.log( LoggingConstants.DEBUG, "type is an interface or abstract/static" ); Type mappedType = Weborb.Types.Types.GetAbstractClassMapping( type ); if( mappedType != null ) return ObjectFactories.CreateServiceObject( mappedType ); }*/ return null; } IArgumentObjectFactory objectFactory; argumentObjectFactories.TryGetValue( typeName, out objectFactory ); if( Log.isLogging( LoggingConstants.DEBUG ) ) Log.log( LoggingConstants.DEBUG, "will use argument factory " + objectFactory.ToString() ); return objectFactory.createObject( argument ); }
public void addReference( IAdaptingType adaptingType, int index ) { references.Capacity = index + 1; references[ index ] = adaptingType; }
public void addReference( IAdaptingType type ) { references.Add( type ); }
public void setType( IAdaptingType type ) { this.realType = type; }
public Header( String headerName, bool mustUnderstand, int length, IAdaptingType dataObject ) { this.headerName = headerName; this.mustUnderstand = mustUnderstand; this.headerValue = dataObject; }
public RefObject( int refId, IAdaptingType refObject ) { Id = refId; Object = refObject; }
public bool HasObject(IAdaptingType key) { return HasObject( key, key.getDefaultType() ); //return cache.ContainsKey(key) && cache.Count > 0; }
public NamedObject( string objectName, IAdaptingType typedObject ) { this.objectName = objectName; this.typedObject = typedObject; this.mappedType = Types.Types.getServerTypeForClientClass( objectName ); }
public static object CreateArgumentObject(Type type, IAdaptingType argument) { return(ORBConfig.GetInstance().getObjectFactories()._CreateArgumentObject(type, argument)); }
public static object CreateArgumentObject( string typeName, IAdaptingType argument ) { Type type = TypeLoader.LoadType( typeName ); return ORBConfig.GetInstance().getObjectFactories()._CreateArgumentObject( type, argument ); }
public static object CreateArgumentObject( Type type, IAdaptingType argument ) { return ORBConfig.GetInstance().getObjectFactories()._CreateArgumentObject( type, argument ); }
public static object CreateArgumentObject(String typeName, IAdaptingType argument) { Type type = TypeLoader.LoadType(typeName); return(ORBConfig.GetInstance().getObjectFactories()._CreateArgumentObject(type, argument)); }
public void AddObject(IAdaptingType adapter, Object value) { AddObject(adapter, adapter.getDefaultType(), value); }
public void setParsedObject( int index, IAdaptingType obj ) { parsedObjects[ index ] = obj; }
public int addParsedObject( IAdaptingType obj ) { parsedObjects.Add( obj ); return parsedObjects.Count - 1; }