public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath == Url)
            {
                ThreadStore.UpdateThreadStoreStats();
                ThreadStoreStats stats = ThreadStore.StoreStats;

                JsonArray ja = new JsonArray();

                IEnumerable<string> boards = Program.ValidBoards.Keys;

                for (int i = 0, j = boards.Count(); i < j; i++)
                {
                    string boardName = boards.ElementAt(i);
                    int threadCount = stats[boardName];

                    if (threadCount > 0)
                    {
                        JsonArray inner = new JsonArray();

                        inner.Add(boardName);
                        inner.Add(threadCount);

                        ja.Add(inner);
                    }
                }

                WriteJsonResponse(response, ja.ToString());
                return true;
            }

            return false;
        }
Beispiel #2
0
        public override string GetString(IEnumerable<IFreeDocument> datas)
        {
            var nodeGroup = new JsonArray();

            foreach (IFreeDocument data in datas)
            {

                nodeGroup.Add(GetJsonObject(data));
            }
            return nodeGroup.ToString();
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath.StartsWith(Url))
            {
                string day_number = request.QueryString[UrlParameters.DayNumber].Value;

                int dayNumber = 0;

                DateTime day = DateTime.Now;

                if (Int32.TryParse(day_number, out dayNumber))
                {
                    day = new DateTime(day.Year, 1, 1);

                    dayNumber--;

                    if (!DateTime.IsLeapYear(day.Year) && dayNumber == 365)
                    {
                        dayNumber--;
                    }

                    day = day.AddDays(dayNumber);
                }

                var sdata = NetworkUsageCounter.GetDayStats(day);

                JsonArray ja = new JsonArray();

                for (int i = 0; i < sdata.Length; i++)
                {
                    double t = sdata[i].Value / 1024 / 1024;

                    JsonArray inner = new JsonArray();

                    inner.Add(sdata[i].Key);
                    inner.Add(Math.Round(t, 2, MidpointRounding.AwayFromZero));

                    ja.Add(inner);
                }

                WriteJsonResponse(response, ja.ToString());
                return true;
            }

            return false;
        }
 public void SaveListViewProperties(ListView listView)
 {
     JsonArray widths = new JsonArray();
     JsonArray indexes = new JsonArray();
     foreach (ColumnHeader column in listView.Columns)
     {
         widths.Add(column.Width);
         indexes.Add(column.DisplayIndex);
     }
     LocalSettings settings = Program.Settings;
     settings.SetObject(CONFKEYPREFIX_LISTVIEW_WIDTHS + listView.Name, widths.ToString());
     settings.SetObject(CONFKEYPREFIX_LISTVIEW_INDEXES + listView.Name, indexes.ToString());
     lock (listView)
     {
         IListViewItemSorter listViewItemSorter = (IListViewItemSorter)listView.ListViewItemSorter;
         settings.SetObject(CONFKEYPREFIX_LISTVIEW_SORTINDEX + listView.Name, listViewItemSorter.Order == SortOrder.Descending ? -listViewItemSorter.SortColumn : listViewItemSorter.SortColumn);
     }
 }
Beispiel #5
0
 public virtual object InvokeArray(Type returnType, string[] method, object[] args)
 {
     if (method == null)
         throw new ArgumentNullException("method");
     if (method.Length == 0)
         throw new ArgumentException(null, "method");
     if (returnType == null)
         throw new ArgumentNullException("returnType");
     try
     {
         var request = GetWebRequest(new Uri(Url));
         request.Method = "POST";
         var utf8EmitBom = new UTF8Encoding(false);
         using (var stream = request.GetRequestStream())
         using (var writer = new StreamWriter(stream, utf8EmitBom))
         {
             var calls = new JsonArray();
             var i = 0;
             foreach (var meth in method)
             {
                 var call = new JsonObject();
                 call["id"] = ++_id;
                 call["jsonrpc"] = "2.0";
                 call["method"] = method[i];
                 if (args[i] != null)
                     call["params"] = args[i];
                 calls.Add(call);
                 i++;
             }
             Logger.Instance().Log("RPC",calls.ToString());
             JsonConvert.Export(calls, writer);
         }
         object ret;
         using (var response = GetWebResponse(request))
         using (var stream = response.GetResponseStream())
         using (var reader = new StreamReader(stream, Encoding.UTF8))
             ret = OnResponseArray(JsonText.CreateReader(reader), returnType);
         return ret;
     }
     catch (WebException ex)
     {
         throw new JsonException("Invalid JSON-RPC response. It contains neither a result nor error : " + ex.Message);
     }
 }
 public void AddDestinationPath(string path)
 {
     if (profileConfMap.ContainsKey(REGKEY_DESTINATION_PATH_HISTORY))
     {
         try
         {
             JsonArray oldArray = (JsonArray)JsonConvert.Import((string)profileConfMap[REGKEY_DESTINATION_PATH_HISTORY]);
             JsonArray newArray = new JsonArray();
             newArray.Add(path);
             for (int i = 0; i < oldArray.Length && newArray.Length < 5; i++)
             {
                 string oldString = (string)oldArray[i];
                 if (oldString != path)
                     newArray.Add(oldString);
             }
             profileConfMap[REGKEY_DESTINATION_PATH_HISTORY] = newArray.ToString();
         }
         catch
         {
             profileConfMap[REGKEY_DESTINATION_PATH_HISTORY] = (new JsonArray(new string[] { path })).ToString();
         }
     }
     else
     {
         profileConfMap.Add(REGKEY_DESTINATION_PATH_HISTORY, (new JsonArray(new string[] { path })).ToString());
     }
 }
Beispiel #7
0
        /**
        * Creates a proxy request by fetching pipelined data and adding it to an existing request.
        *
        */
        private sRequest createPipelinedProxyRequest(Gadget gadget, sRequest original) 
        {
            sRequest request = new sRequest(original);
            request.setIgnoreCache(true);
            GadgetSpec spec = gadget.getSpec();
            GadgetContext context = gadget.getContext();
            IPreloads proxyPreloads = preloader.preload(context, spec,
                                PreloaderService.PreloadPhase.PROXY_FETCH);
            // TODO: Add current url to GadgetContext to support transitive proxying.

            // POST any preloaded content
            if ((proxyPreloads != null) && proxyPreloads.getData().Count != 0) 
            {
                JsonArray array = new JsonArray();

                foreach(PreloadedData preload in proxyPreloads.getData()) 
                {
                    Dictionary<String, Object> dataMap = preload.toJson();
                    foreach(var entry in dataMap) 
                    {
                        // TODO: the existing, supported content is JSONObjects that contain the
                        // key already.  Discarding the key is odd.
                        array.Put(entry.Value);
                    }
                }

                String postContent = array.ToString();
                // POST the preloaded content, with a method override of GET
                // to enable caching
                request.setMethod("POST")
                  .setPostBody(Encoding.UTF8.GetBytes(postContent))
                  .setHeader("Content-Type", "text/json;charset=utf-8");
            }
            return request;
        }
Beispiel #8
0
        /// <summary>
        /// Gets the current city.
        /// </summary>
        public void InitClientObjects()
        {
            PlaceManager pm = new PlaceManager();
            string defaultCity = ConfigurationOptions.Current.GetString("system_default_city");

            if (QueryStringContains("city"))
                defaultCity = GetFromQueryString("city");

            _currentCity = pm.LoadPlaceByRewritedName(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(defaultCity));

            if (_currentCity != null)
            {

            }
            else
            {
                _currentCity = pm.LoadPlace(ConfigurationOptions.Current.GetString("system_default_city"));

                RegisterDocumentReadyFunction("notExistingCity", JsUtils.CreateJsFunction("showNotExistingCityDialog", false, defaultCity));
            }

            JsonObject o = new JsonObject();
            o["name"] = _currentCity.Name;
            o["link"] = _currentCity.Link;
            o["id"] = _currentCity.PlaceID;
            o["lat"] = _currentCity.GeolocationInfo.Location.Latitude;
            o["lng"] = _currentCity.GeolocationInfo.Location.Longitude;
            o["zoom"] = _currentCity.MapZoom;

            ClientScript.RegisterClientScriptBlock(this.GetType(), "clientPageObjects", "var currentCity = " + o.ToString() + ";", true);

            //if (SessionContains("CurrentCity"))
            //{
            //    _currentCity = (Place)GetFromSession("CurrentCity");
            //    if (QueryStringContains("city") && GetFromQueryString("city") != _currentCity.Name)
            //    {

            //        _currentCity = pm.LoadPlace(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(defaultCity));
            //        AddToSession("CurrentCity", _currentCity);
            //    }
            //}
            //else
            //{
            //    _currentCity = pm.LoadPlace(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(defaultCity));

            //    if (_currentCity != null)
            //        AddToSession("CurrentCity", _currentCity);
            //    else
            //    {
            //        _currentCity = pm.LoadPlace(ConfigurationOptions.Current.GetString("system_default_city"));
            //        RegisterDocumentReadyFunction("notExistingCity", JsUtils.CreateJsFunction("showNotExistingCityDialog", false, defaultCity));
            //    }
            //}

            List<Place> places = pm.GetActivePlaces();

            JsonArray citiesArr = new JsonArray();
            foreach (Place p in places)
            {
                JsonObject c = new JsonObject();
                c["label"] = p.Name;
                c["link"] = p.Link;
                citiesArr.Add(c);
            }

            ClientScript.RegisterClientScriptBlock(this.GetType(), "cities", "var places = " + citiesArr.ToString() + ";", true);
        }
 private void SaveSettings()
 {
     using (FileStream outFile = new FileStream(STORAGE_MANAGER_SETTINGS, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter writer = new StreamWriter(outFile))
         {
             var json = new JsonArray(StorageAliases);
             writer.Write(json.ToString());
         }
     }
 }