Пример #1
0
 public static IFromJson CreateObjectFromScriptType(string scriptType, ClientRuntimeContext context)
 {
     ScriptTypeMap.EnsureInited();
     foreach (IScriptTypeFactory current in ScriptTypeMap.s_scriptTypeFactories)
     {
         IFromJson fromJson = current.CreateObjectFromScriptType(scriptType, context);
         if (fromJson != null)
         {
             IFromJson result = fromJson;
             return(result);
         }
     }
     ScriptTypeMap.ScriptTypeInfo scriptTypeInfo = null;
     if (ScriptTypeMap.s_clientProxies.TryGetValue(scriptType, out scriptTypeInfo))
     {
         IFromJson result2;
         if (scriptTypeInfo.ValueObject)
         {
             result2 = (Activator.CreateInstance(scriptTypeInfo.Type) as IFromJson);
         }
         else
         {
             Type     arg_86_0 = scriptTypeInfo.Type;
             object[] array    = new object[2];
             array[0] = context;
             result2  = (Activator.CreateInstance(arg_86_0, array) as IFromJson);
         }
         return(result2);
     }
     return(null);
 }
 private void ProcessResponseStream(Stream responseStream)
 {
     StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
     JsonReader jsonReader = new JsonReader(reader, this.m_context);
     jsonReader.ReadArrayStart();
     Dictionary<string, object> dictionary = jsonReader.ReadObject() as Dictionary<string, object>;
     if (dictionary == null)
     {
         throw new ClientRequestException(Resources.GetString("RequestUnknownResponse"));
     }
     object obj;
     if (!dictionary.TryGetValue("SchemaVersion", out obj))
     {
         throw new ClientRequestException(Resources.GetString("RequestUnknownResponse"));
     }
     string text = obj as string;
     if (string.IsNullOrEmpty(text))
     {
         throw new ClientRequestException(Resources.GetString("RequestUnknownResponse"));
     }
     this.m_context.ServerSchemaVersion = new Version(text);
     if (!dictionary.TryGetValue("LibraryVersion", out obj))
     {
         throw new ClientRequestException(Resources.GetString("RequestUnknownResponse"));
     }
     string text2 = obj as string;
     if (string.IsNullOrEmpty(text2))
     {
         throw new ClientRequestException(Resources.GetString("RequestUnknownResponse"));
     }
     this.m_context.ServerLibraryVersion = new Version(text2);
     if (dictionary.TryGetValue("TraceCorrelationId", out obj))
     {
         this.m_context.SetTraceCorrelationId(obj as string);
     }
     if (!dictionary.TryGetValue("ErrorInfo", out obj))
     {
         throw new ClientRequestException(Resources.GetString("RequestUnknownResponse"));
     }
     object obj2 = obj;
     if (obj2 != null)
     {
         Dictionary<string, object> dictionary2 = obj2 as Dictionary<string, object>;
         if (dictionary2 == null)
         {
             throw new ClientRequestException(Resources.GetString("RequestUnknownResponse"));
         }
         ServerException ex = ServerException.CreateFromErrorInfo(dictionary2);
         throw ex;
     }
     else
     {
         if (!ClientRuntimeContext.CanHandleResponseSchema(this.m_context.ServerSchemaVersion))
         {
             throw new ClientRequestException(Resources.GetString("CannotHandleServerResponseSchema", new object[]
             {
                 text
             }));
         }
         while (jsonReader.PeekTokenType() != JsonTokenType.ArrayEnd)
         {
             long num = jsonReader.ReadInt64();
             obj = null;
             if (this.m_queryIdToObjectMap.TryGetValue(num.ToString(CultureInfo.InvariantCulture), out obj) && obj != null)
             {
                 ClientObject clientObject = obj as ClientObject;
                 string scriptType = null;
                 if (clientObject != null && jsonReader.PeekTokenType() == JsonTokenType.ObjectStart && jsonReader.PeekObjectType(out scriptType))
                 {
                     Type typeFromScriptType = ScriptTypeMap.GetTypeFromScriptType(scriptType);
                     if (typeFromScriptType != null && typeFromScriptType != clientObject.GetType())
                     {
                         ClientObject clientObject2 = ScriptTypeMap.CreateObjectFromScriptType(scriptType, this.Context) as ClientObject;
                         if (clientObject2 != null)
                         {
                             clientObject.SetTypedObject(clientObject2);
                             obj = clientObject2;
                         }
                     }
                 }
                 IFromJson fromJson = obj as IFromJson;
                 if (fromJson != null && !fromJson.CustomFromJson(jsonReader))
                 {
                     fromJson.FromJson(jsonReader);
                 }
             }
             else
             {
                 jsonReader.ReadObject();
             }
         }
         return;
     }
 }