Example #1
0
        public static void ThrowOnErrorResponse(this JsonValue jsonValue)
        {
            if (jsonValue.ContainsKey("error")) //pas error
            {
                throw new CDOException(jsonValue.Get("error"), jsonValue.Get("error_description"))
                      {
                          Scope = jsonValue.Get("scope")
                      };
            }

            if (jsonValue.ContainsKey("_errors")) //progress error
            {
                string code    = "";
                string message = jsonValue.Get("_retVal");

                var errors = (JsonArray)jsonValue.Get("_errors");
                foreach (var error in errors)
                {
                    code = error.Get("_errorNum").ToString();
                    if (string.IsNullOrEmpty(message))
                    {
                        message = error.Get("_errorMsg");
                    }
                    break;
                }

                throw new CDOException(code, message);
            }
        }
Example #2
0
 public static bool GetBoolean(JsonValue jsonData, string key, bool defaultVal)
 {
     if (IsNull(jsonData) || jsonData.Get(key).IsNull())
     {
         return(defaultVal);
     }
     return(jsonData.Get(key).GetBoolean());
 }
Example #3
0
 public static string GetString(JsonValue jsonData, string key, string defaultVal)
 {
     if (IsNull(jsonData) || jsonData.Get(key).IsNull())
     {
         return(defaultVal);
     }
     return(jsonData.Get(key).GetString());
 }
Example #4
0
 public static double GetDouble(JsonValue jsonData, string key, double defaultVal)
 {
     if (IsNull(jsonData) || jsonData.Get(key).IsNull())
     {
         return(defaultVal);
     }
     return(jsonData.Get(key).GetDouble());
 }
Example #5
0
 public static float GetFloat(JsonValue jsonData, string key, float defaultVal)
 {
     if (IsNull(jsonData) || jsonData.Get(key).IsNull())
     {
         return(defaultVal);
     }
     return(jsonData.Get(key).GetFloat());
 }
Example #6
0
 public bool Receive(JsonValue aMessage)
 {
     if (!aMessage.IsObject) return false;
     var type = aMessage.Get("type");
     if (!type.IsString || type.AsString() != "xf-event") return false;
     var ev = aMessage.Get("event");
     if (!ev.IsString) return false;
     EventHandler handler;
     if (!iEventHandlers.TryGetValue(ev.AsString(), out handler)) return false;
     handler(this, EventArgs.Empty);
     return true;
 }
Example #7
0
        private static IQuery[] GetBoolQueries(JsonValue jv)
        {
            if (jv.Type == JsonType.Object)
            {
                return(new IQuery[] { jv.Get <JsonObject>().ToQuery() });
            }
            else if (jv.Type == JsonType.Array)
            {
                return(jv.Get <JsonArray>()
                       .Select(e => e.Get <JsonObject>().ToQuery())
                       .ToArray());
            }

            return(null);
        }
        static MobileServiceClient()
        {
            // Try to get the AppInstallationId from settings
            object setting = null;

            if (ApplicationData.Current.LocalSettings.Values.TryGetValue(ConfigureAsyncInstallationConfigPath, out setting))
            {
                JsonValue config = null;
                if (JsonValue.TryParse(setting as string, out config))
                {
                    applicationInstallationId = config.Get(ConfigureAsyncApplicationIdKey).AsString();
                }
            }

            // Generate a new AppInstallationId if we failed to find one
            if (applicationInstallationId == null)
            {
                applicationInstallationId = Guid.NewGuid().ToString();
                string configText =
                    new JsonObject()
                    .Set(ConfigureAsyncApplicationIdKey, applicationInstallationId)
                    .Stringify();
                ApplicationData.Current.LocalSettings.Values[ConfigureAsyncInstallationConfigPath] = configText;
            }
        }
Example #9
0
        protected virtual void ImportTables(JsonValue value)
        {
            //Import tables
            if (value != null)
            {
                var taskList = new List <Task>();
                foreach (var key in ((JsonObject)value).Keys)
                {
                    if (!key.StartsWith("prods:"))
                    {
                        taskList.Add(Task.Factory.StartNew(() =>
                        {
                            if (value.Get(key) is IEnumerable <JsonValue> tTable)
                            {
                                Add <CDO_Record>(key, new CDO_Table <CDO_Record>(tTable.Cast <JsonObject>()));
                            }
                            else
                            {
                                Add <CDO_Record>(key, new CDO_Table <CDO_Record>());
                            }
                        }));
                    }
                }

                Task.WaitAll(taskList.ToArray());
            }
        }
Example #10
0
 private void ProcessCatalogObject(JsonValue catalogObject, CancellationToken cancellationToken = default(CancellationToken))
 {
     cancellationToken.ThrowIfCancellationRequested();
     if (catalogObject == null)
     {
         throw new InvalidDataException("Could not parse catalog data.");
     }
     catalogObject.ThrowOnErrorResponse();
     //init catalog from response
     Version      = catalogObject.Get("version");
     LastModified = catalogObject.Get("lastModified");
     foreach (JsonValue serviceDefinition in catalogObject.Get("services"))
     {
         Services.Add(new Service(serviceDefinition));
     }
 }
Example #11
0
        public SearchSort(JsonValue jv)
        {
            if (jv == null)
            {
                return;
            }

            if (jv.Type == JsonType.String)
            {
                Field = jv.Get <string>();
            }
            else if (jv.Type == JsonType.Object)
            {
                var jp = jv.Get <JsonObject>().Properties()[0];

                Field = jp.Name;

                var sort = jp.Value;

                if (sort.Type == JsonType.String)
                {
                    IsDescending = sort.Get <string>() == "desc";
                }
                else if (sort.Type == JsonType.Object)
                {
                    var jo = sort.Get <JsonObject>();

                    string order = jo.Property <string>("order");
                    IsDescending = !string.IsNullOrWhiteSpace(order) && order == "desc";

                    string mode = jo.Property <string>("mode");
                    switch (mode)
                    {
                    case "min": Mode = SortMode.Min; break;

                    case "max": Mode = SortMode.Max; break;

                    case "sum": Mode = SortMode.Sum; break;

                    case "avg": Mode = SortMode.Avg; break;

                    case "median": Mode = SortMode.Median; break;
                    }
                }
            }
        }
Example #12
0
        public Operation(JsonValue operation)
        {
            _operation = operation;

            if (_operation.ContainsKey("verb"))
            {
                Verb = (HttpVerbs)Enum.Parse(typeof(HttpVerbs), _operation.Get("verb"), true);
            }
        }
Example #13
0
    public static void CopyJsonToIntList(JsonValue jsonData, List <int> intList)
    {
        intList.Clear();
        if (IsNull(jsonData) || jsonData.IsNull())
        {
            return;
        }

        for (int index = 0; index < jsonData.GetLength(); index++)
        {
            intList.Add(jsonData.Get(index).GetInt());
        }
    }
Example #14
0
    public static void CopyJsonToStrList(JsonValue jsonData, List <string> strList)
    {
        strList.Clear();
        if (IsNull(jsonData) || jsonData.IsNull())
        {
            return;
        }

        for (int index = 0; index < jsonData.GetLength(); index++)
        {
            strList.Add(jsonData.Get(index).GetString());
        }
    }
Example #15
0
        public SearchSource(JsonValue jv)
        {
            if (jv == null)
            {
                return;
            }

            if (jv.Type == JsonType.Boolean && !jv.Get <bool>())
            {
                IsHidden = true;
                return;
            }

            if (jv.Type == JsonType.String)
            {
                Includes = new string[] { jv.Get <string>() };
            }
            else if (jv.Type == JsonType.Array)
            {
                Includes = jv.Get <JsonArray>().Select(e => e.Get <string>()).ToArray();
            }
            else if (jv.Type == JsonType.Object)
            {
                var source = jv.Get <JsonObject>();

                var fields = source.Property <JsonArray>("includes");
                if (fields != null && fields.Length > 0)
                {
                    Includes = fields.Select(e => e.Get <string>()).ToArray();
                }

                fields = source.Property <JsonArray>("excludes");
                if (fields != null && fields.Length > 0)
                {
                    Excludes = fields.Select(e => e.Get <string>()).ToArray();
                }
            }
        }
Example #16
0
        /// <summary>
        /// Creates a new instance of the MobileServiceApplication.
        /// </summary>
        private MobileServiceApplication()
        {
            // Try to get the AppInstallationId from settings
            object setting = null;

            if (ApplicationData.Current.LocalSettings.Values.TryGetValue(ConfigureAsyncInstallationConfigPath, out setting))
            {
                JsonValue config = null;
                if (JsonValue.TryParse(setting as string, out config))
                {
                    this.InstallationId = config.Get(ConfigureAsyncApplicationIdKey).AsString();
                }
            }

            // Generate a new AppInstallationId if we failed to find one
            if (this.InstallationId == null)
            {
                this.InstallationId = Guid.NewGuid().ToString();
                string configText =
                    new JsonObject()
                    .Set(ConfigureAsyncApplicationIdKey, this.InstallationId)
                    .Stringify();
                ApplicationData.Current.LocalSettings.Values[ConfigureAsyncInstallationConfigPath] = configText;
            }

            // Set the architecture
            this.OperatingSystemArchitecture = Package.Current.Id.Architecture.ToString();

            // Use hardcoded values for the OS and OS version as the Windows Store APIs don't provide the OS and OS version
            this.OperatingSystemName    = Windows8OperatingSystemName;
            this.OperatingSystemVersion = UnknownValue;

            // Set the SDK values; no way to read the SdkVersion so use UnknownValue
            this.SdkName     = ZumoSdkName;
            this.SdkVersion  = UnknownValue;
            this.SdkLanguage = ZumoSdkManaged;

            this.UserAgentHeaderValue = GetUserAgentHeaderValue();
        }
Example #17
0
 public void Receive(JsonValue aJsonValue)
 {
     if (aJsonValue.IsObject)
     {
         JsonValue aType = aJsonValue.Get("type");
         if (!aType.IsString)
         {
             Console.WriteLine("Bad message from client: {0}", aJsonValue);
             return;
         }
         string userid;
         switch (aType.AsString())
         {
             case "message":
                 lock (iLock)
                 {
                     userid = iUserId;
                 }
                 iTestApp.NewMessage(userid, aJsonValue.Get("content").AsString());
                 break;
         }
     } else if (aJsonValue.IsString)
     {
         // Legacy.
         iTestApp.NewMessage(iUserId, aJsonValue.AsString());
     }
 }
Example #18
0
        public void WriteValue(JsonValue value)
        {
            if (value.IsNull())
            {
                return;
            }
            if (value.GetValueType() == typeof(List <object>))
            {
                document_.Append('[');
                int size = value.GetLength();
                for (int ArrayIndex = 0; ArrayIndex < size; ++ArrayIndex)
                {
                    if (ArrayIndex > 0)
                    {
                        document_.Append(',');
                    }

                    WriteValue((value.Get(ArrayIndex)));
                }
                document_.Append(']');
            }
            else if (value.GetValueType() == typeof(Dictionary <String, object>))
            {
                string[] keys = value.GetKeys();

                document_.Append('{');

                for (int DicIndex = 0; DicIndex != keys.Length; ++DicIndex)
                {
                    if (DicIndex != 0)
                    {
                        document_.Append(',');
                    }

                    document_.Append(QuoteString(keys[DicIndex]));
                    document_.Append(':');

                    WriteValue((value.Get(keys[DicIndex])));
                }
                document_.Append('}');
            }
            else if (value.GetValueType() == typeof(string))
            {
                document_.Append(QuoteString(value.GetString()));
            }
            else if (value.GetValueType() == typeof(bool))
            {
                if (value.GetBoolean())
                {
                    document_.Append("true");
                }
                else
                {
                    document_.Append("false");
                }
            }
            else
            {
                document_.Append(value.ToString());
            }
        }
Example #19
0
 public void Receive(JsonValue aJsonValue)
 {
     if (aJsonValue.IsObject)
     {
         JsonValue type = aJsonValue.Get("type");
         if (!type.IsString)
         {
             Console.WriteLine("Bad message from client: {0}", aJsonValue);
             return;
         }
         switch (type.AsString())
         {
             case "user":
                 string userid = aJsonValue.Get("id").AsString();
                 iBrowserTabProxy.SwitchUser(userid);
                 break;
         }
     }
 }
Example #20
0
 public void Receive(JsonValue aJsonValue)
 {
     if (aJsonValue.IsObject)
     {
         JsonValue aType = aJsonValue.Get("type");
         if (!aType.IsString)
         {
             Console.WriteLine("Bad message from client: {0}", aJsonValue);
             return;
         }
         string userid;
         switch (aType.AsString())
         {
             case "message":
                 lock (iLock)
                 {
                     userid = iUserId;
                 }
                 iChatApp.NewMessage(userid, aJsonValue.Get("content").AsString());
                 break;
             case "changeuser":
                 iBrowserTabProxy.SwitchUser(null);
                 break;
             case "user":
                 userid = aJsonValue.Get("id").AsString();
                 Console.WriteLine("SHOULD NOT GET HERE.");
                 iBrowserTabProxy.SetCookie("xappuser", userid, null);
                 iBrowserTabProxy.ReloadPage();
                 iBrowserTabProxy.SwitchUser(userid);
                 /*
                 User user;
                 if (!iUserList.TryGetUserById(userid, out user))
                 {
                     Console.WriteLine("Bad user id from client: {0}", userid);
                 }*/
                 //ChangeUser(userid);
                 break;
         }
     } else if (aJsonValue.IsString)
     {
         // Legacy.
         iChatApp.NewMessage(iUserId, aJsonValue.AsString());
     }
 }