private List <object> QueryOneHopData(long from_cellid, string info, int hop_num)
        {
            List <object> ret = new List <object>();

            //Artists:Name(Performance:1&Gender:male
            string[] line          = info.Split(new char[] { '(' }, StringSplitOptions.RemoveEmptyEntries);
            string   edge_property = line[0];
            string   constrint     = (line.Count() == 2) ? line[1] : null;

            string[] edge_property_arr = edge_property.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            string   edge     = edge_property_arr[0];
            string   property = edge_property_arr[1];

            string query_path = "\"/entity1/" + edge + "/entity2\"";

            string  request_body  = "{ \"path\": " + query_path + ",  \"entity1\" : {\n\t\"match\": { \"CellId\": " + from_cellid + " }  },  \"entity2\" : {\"select\": [ \"" + property + "\" ]  },}";
            var     json_response = ExecuteRequest(request_body);
            dynamic response      = JsonConvert.DeserializeObject(json_response.Content);

            Newtonsoft.Json.Linq.JArray response_res = response.Results;
            var paths = response_res.ToObject <List <List <Dictionary <string, object> > > >();

            foreach (var ress in paths)
            {
                ret.Add(ress[hop_num]["Name"]);
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// 反序列化方式
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="json"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private static List <T> Convert <T>(string json, JsonToolType type)
        {
            List <T> list = null;

            switch (type)
            {
            case JsonToolType.Newtonsoft:
                JsonReader reader = new JsonTextReader(new StringReader(json));
                Newtonsoft.Json.Linq.JArray array = (JArray)JToken.ReadFrom(reader);
                list = array.ToObject <List <T> >();
                break;

            case JsonToolType.Swifter:
                list = JsonFormatter.DeserializeObject <List <T> >(json);
                break;

            case JsonToolType.FastJson:
                list = fastJSON.JSON.ToObject <List <T> >(json);
                break;

            default:
                break;
            }
            return(list);
        }
Example #3
0
 /// <summary> Gives a list of open private rooms.
 /// Received: ORS { "channels": [object] }
 /// e.g. "channels": [{"name":"ADH-300f8f419e0c4814c6a8","characters":0,"title":"Ariel's Fun Club"}] etc. etc.
 /// Send  As: ORS</summary>
 internal static void ORS(SystemCommand C)
 {
     Newtonsoft.Json.Linq.JArray AllChannelData = Newtonsoft.Json.Linq.JArray.Parse(C.Data["channels"].ToString());
     if (AllChannelData.Count > 0)
     {
         try{
             List <Dictionary <string, object> > _AllChannelData = AllChannelData.ToObject <List <Dictionary <string, object> > >();
             for (int l = 0; l < _AllChannelData.Count; l++)
             {
                 Dictionary <string, object> currentChannel = _AllChannelData[l];                        //removal of whole-list lookup for, uh, about 100 public channels and 1000+ privates...
                 string cTitle = currentChannel["title"].ToString();
                 if (Core.channels.Count(x => x.Name == cTitle) == 0)
                 {
                     Channel ch = new Channel(cTitle, currentChannel["name"].ToString(), int.Parse(currentChannel["characters"].ToString()));
                 }
             }
         }
         catch (Exception ex) { Core.ErrorLog.Log(String.Format("Private Channel parsing failed:\n\t{0}\n\t{1}\n\t{2}", ex.Message, ex.InnerException, ex.StackTrace)); }
     }
     new IO.SystemCommand("STA { \"status\": \"online\", \"statusmsg\": \"Running CogitoMini v" + Config.AppSettings.Version + "\" }").Send();
     foreach (string cn in Core.XMLConfig["autoJoin"].Split(';'))
     {
         if (Core.channels.Count(x => x.Name == cn) > 0)
         {
             Core.channels.First(y => y.Name == cn).Join();
         }
     }
 }
 public void OnTraceComplete(JArray myArray)
 {            
     // HACK: not sure why we have to explicitly cast the argument from a JArray, I thought Signalr should do this for us
     var e = myArray.ToObject<DaxStudioTraceEventArgs[]>();
     
     if (TraceCompleted != null)
     { TraceCompleted(this, e); }
 }
Example #5
0
        private void loadFileNames(ResponseObject obj, string path, Newtonsoft.Json.Linq.JArray objectTypes)
        {
            string[] dirs = Directory.GetDirectories(path);

            string[] files1 = Directory.GetFiles(path, "*.json", SearchOption.TopDirectoryOnly);
            string[] files2 = Directory.GetFiles(path, "*.test.jsx", SearchOption.TopDirectoryOnly);
            var      files  = files1.Union(files2).ToArray();

            if (dirs.Length > 0 || files.Length > 0)
            {
                obj.items = new List <ResponseObject>();
            }
            foreach (var dir in dirs)
            {
                var newItemName = Path.GetFileName(dir);
                if (obj.name == "root" && newItemName == "vendor")
                {
                    continue;
                }
                var newDirItem = new ResponseObject();
                newDirItem.name     = newItemName;
                newDirItem.isFolder = true;

                loadFileNames(newDirItem, dir, objectTypes);

                obj.items.Add(newDirItem);
            }
            foreach (var file in files)
            {
                //FileInfo info = new FileInfo(file);
                var newFileItem = new ResponseObject();
                newFileItem.name = Path.GetFileName(file);

                if (objectTypes.Count > 0)
                {
                    var words    = newFileItem.name.Split(".");
                    var itemType = words[words.Length - 2]; // "Заявки.table.json"
                    if (objectTypes.ToObject <string[]>().Contains(itemType))
                    {
                        obj.items.Add(newFileItem);
                    }
                }
                else
                {
                    obj.items.Add(newFileItem);
                }
            }
        }   //Newtonsoft.Json.Linq.JArray
        private static IList<object> DeserializeData(JArray data)
        {
            var list = data.ToObject<List<object>>();

            for (int i = 0; i < list.Count; i++)
            {
                var value = list[i];

                if (value is JObject)
                    list[i] = DeserializeData(value as JObject);

                if (value is JArray)
                    list[i] = DeserializeData(value as JArray);
            }
            return list;
        }
        private List <object> QueryZeroHopData(long from_cellid, string property, int hop_num)
        {
            List <object> ret = new List <object>();

            string query_path = "\"/entity1\"";

            string  request_body  = "{ \"path\": " + query_path + ",  \"entity1\" : {\n\t\"match\": { \"CellId\": " + from_cellid + " },\"select\": [ \"" + property + "\" ]  }}";
            var     json_response = ExecuteRequest(request_body);
            dynamic response      = JsonConvert.DeserializeObject(json_response.Content);

            Newtonsoft.Json.Linq.JArray response_res = response.Results;
            var paths = response_res.ToObject <List <List <Dictionary <string, object> > > >();

            foreach (var ress in paths)
            {
                ret.Add(ress[hop_num][property]);
            }
            return(ret);
        }
        private static IDictionary<WeatherChar, IDictionary<int, int>> GetIndexes(
            JArray jHeaders, IEnumerable<WeatherChar> charList, IEnumerable<int> postCodeList)
        {
            IDictionary<WeatherChar, IDictionary<int, int>> result =
                new Dictionary<WeatherChar, IDictionary<int, int>>();

            var headers = jHeaders.ToObject<List<string>>();
            foreach (WeatherChar ch in charList)
            {
                IDictionary<int, int> chResult = new Dictionary<int, int>();
                foreach (int postCode in postCodeList)
                {
                    chResult.Add(postCode,
                        headers.FindIndex(s => s.Contains(ch.ToString()) && s.Contains(postCode.ToString())));
                }
                result.Add(ch, chResult);
            }

            return result;
        }
Example #9
0
        private static void bb()
        {
            string jsonString1 = @"[{""Name"":""小苹果"",""Age"":""20""},{""Name"":""演员"",""Age"":""2""}]";

            Newtonsoft.Json.Linq.JArray userAarray1 = Newtonsoft.Json.Linq.JArray.Parse(jsonString1) as Newtonsoft.Json.Linq.JArray;
            List <User> userListModel = userAarray1.ToObject <List <User> >();

            foreach (var userModel1 in userListModel)
            {
                Console.WriteLine("Name:" + userModel1.Name);
                Console.WriteLine("Age:" + userModel1.Age);
            }

            Console.WriteLine("");
            string jsonString = @"[{""Name"":""小苹果"",""Age"":""20""}]";

            Newtonsoft.Json.Linq.JArray  userAarray = Newtonsoft.Json.Linq.JArray.Parse(jsonString) as Newtonsoft.Json.Linq.JArray;
            Newtonsoft.Json.Linq.JObject jObject    = userAarray[0] as Newtonsoft.Json.Linq.JObject;
            User userModel = jObject.ToObject <User>();

            Console.WriteLine("Name:" + userModel.Name);
            Console.WriteLine("Age:" + userModel.Age);
        }
Example #10
0
 /// <summary>Converts JObject to array.</summary>
 /// <param name="array">The array.</param>
 /// <returns>System.Object[].</returns>
 public static object[] ToArray(this JArray array)
 {
     return(array.ToObject <object[]>().Select(ProcessArrayEntry).ToArray());
 }
Example #11
0
 public async void GetStoresOfOwner()
 {
     try
     {
         if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection)
         {
             JArray result = new JArray();
             int ownerId = MediateClass.UserVM.UserInfo.UserId;
             IDictionary<string, string> param = new Dictionary<string, string>
             {
                 {"ownerId" , ownerId.ToString()}
             };
             var response = await App.MobileService.InvokeApiAsync("Stores", HttpMethod.Get, param);
             result = JArray.Parse(response.ToString());
             StoresOfOwner = result.ToObject<ObservableCollection<Kios>>();
         }
     }
     catch (Exception ex)
     {
         await new MessageDialog(ex.Message.ToString(), "Get Store").ShowAsync();
     }
 }
Example #12
0
        public async void GetSaleOfOwner(TYPEGET typeGet, TYPE type = TYPE.OLD)
        {
            try
            {
                JArray result = new JArray();
                int lastId = -1;
                if (typeGet == TYPEGET.MORE)
                {
                    if (SaleOfStoreOwner.Count != 0)
                    {
                        if (type == TYPE.OLD)
                            lastId = SaleOfStoreOwner.Min(x => x.SaleId);
                        else
                            lastId = SaleOfStoreOwner.Max(x => x.SaleId);
                    }
                }
                int ownerId = MediateClass.UserVM.UserInfo.UserId;
                SaleItem saleInfo = new SaleItem(lastId, ownerId, type);
                JToken body = JToken.FromObject(saleInfo);

                if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection)
                {
                    var response = await App.MobileService.InvokeApiAsync("SaleInfoes", body, HttpMethod.Get, null);
                    result = JArray.Parse(response.ToString());
                    ObservableCollection<AdvertiseItem> more = result.ToObject<ObservableCollection<AdvertiseItem>>();
                    if (typeGet == TYPEGET.START)
                    {
                        SaleOfStoreOwner = more;
                    }
                    else
                    {
                        if (type == TYPE.OLD)
                        {
                            foreach (var item in more)
                            {
                                SaleOfStoreOwner.Add(item);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < more.Count; i++)
                            {
                                SaleOfStoreOwner.Insert(i, more[i]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message.ToString(), "Load Sale").ShowAsync();
            }
        }
        public async void GetNewProductList(TYPEGET typeGet, TYPE type = TYPE.OLD)
        {
            try
            {
                JArray result = new JArray();
                int lastId = -1;
                if (typeGet == TYPEGET.MORE)
                {
                    if (NewProductList.Count != 0)
                    {
                        if (type == TYPE.OLD)
                            lastId = NewProductList.Min(x => x.ProductId);
                        else
                            lastId = NewProductList.Max(x => x.ProductId);
                    }
                }

                IDictionary<string, string> param = new Dictionary<string, string>
                {
                    {"typeProduct" , type.ToString()},
                    {"productId" , lastId.ToString()}
                };

                if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection)
                {
                    if (!isResponse)
                    {
                        isResponse = true;
                        var response = await App.MobileService.InvokeApiAsync("ProductStatistics", HttpMethod.Get, param);
                        result = JArray.Parse(response.ToString());
                        ObservableCollection<Product> more = result.ToObject<ObservableCollection<Product>>();
                        if (typeGet == TYPEGET.START)
                        {
                            NewProductList = more;
                        }
                        else
                        {
                            if (type == TYPE.OLD)
                            {
                                foreach (var item in more)
                                {
                                    NewProductList.Add(item);
                                }
                            }
                            else
                            {
                                for (int i = 0; i < more.Count; i++)
                                {
                                    NewProductList.Insert(i, more[i]);
                                }
                            }
                        }
                    }                    
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message.ToString(), "Load Product").ShowAsync();
            }
            finally
            {
                isResponse = false;
            }
        }
Example #14
0
 public List<MovieSearchResult> ParseResults(JToken token)
 {
     var items = new JArray(token.SelectTokens("[*].results").Cast<JArray>().SelectMany(a => a));
     var result = items.ToObject<List<MovieSearchResult>>();
     return result;
 }
Example #15
-1
 public List<Movie> ParseMovies(JToken token)
 {
     int i = 0;
     var items = new JArray(token.SelectTokens("[*].results").Cast<JArray>().SelectMany(a => a));
     var result = items.ToObject<List<Movie>>();
     result.ForEach(a => a.Source = items[i++].ToString(Formatting.Indented));
     return result;
 }