Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            JsonWsp.Client cli = new JsonWsp.Client("http://10.1.5.160/service/AccessService/jsonwsp/description");
            cli.SetViaProxy(true);
            if (args.Length==0) {
                Console.WriteLine("Usage: jsontest.exe <session_id>");
                return;
            }
            Console.WriteLine("Call listPermissions");
            Console.WriteLine("--------------------");
            // Build arguments
            JsonObject args_dict = new JsonObject();
            args_dict.Add("session_id",args[0]);
            // Call method
            JsonObject result = CommonCall(cli,"listPermissions",args_dict);
            if (result != null) {
                Jayrock.Json.JsonArray perm = (Jayrock.Json.JsonArray) result["access_identifiers"];
                foreach (string i in perm) {
                    Console.WriteLine(i);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Call hasPermissions");
            Console.WriteLine("-------------------");
            // Build arguments
            JsonObject args_dict2 = new JsonObject();
            args_dict2.Add("session_id",args[0]);
            args_dict2.Add("access_identifier","product.web.10finger");
            // Call method
            result = CommonCall(cli,"hasPermission",args_dict2);
            // Print
            if (result != null) {
                bool access = (bool) result["has_permission"];
                if (access) {
                    Console.WriteLine("Access Granted");
                }
                else {
                    Console.WriteLine("Access Denied");
                }
            }

            Console.WriteLine();
            Console.WriteLine("Call getUserInfo");
            Console.WriteLine("----------------");
            cli = new JsonWsp.Client("http://10.1.5.160/service/UserService/jsonwsp/description");
            result = CommonCall(cli,"getUserInfo",args_dict);

            if (result != null) {
                JsonObject user_info = (JsonObject) result["user_info"];
                Console.WriteLine("Org-name:    " + user_info["org_name"]);
                Console.WriteLine("Org-domain:  " + user_info["org_domain"]);
                Console.WriteLine("Org-code:    " + user_info["org_code"]);
                Console.WriteLine("Org-type:    " + user_info["org_type"]);
                Console.WriteLine("Given Name:  " + user_info["given_name"]);
                Console.WriteLine("Surname:     " + user_info["surname"]);
                Console.WriteLine("Uid:         " + user_info["uid"]);
                Console.WriteLine("Common-name: " + user_info["common_name"]);
            }
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath.StartsWith(Url))
            {
                string hash = request.QueryString["hash"].Value;

                if (string.IsNullOrEmpty(hash))
                {
                    ThreadServerModule._404(response);
                }
                else
                {

                    if (Program.queued_files.ContainsKey(hash))
                    {
                        FileQueueStateInfo f = Program.queued_files[hash];

                        JsonObject ob = new JsonObject();

                        ob.Add("p", f.Percent().ToString());
                        ob.Add("s", string.Format("{0} / {1}", Program.format_size_string(f.Downloaded), Program.format_size_string(f.Length)));
                        ob.Add("c", f.Status == FileQueueStateInfo.DownloadStatus.Complete);

                        WriteJsonResponse(response, ob.ToString());
                    }
                    else
                    {
                        ThreadServerModule._404(response);
                    }
                }
                return true;
            }

            return false;
        }
Ejemplo n.º 3
0
 public void Add()
 {
     JsonObject o = new JsonObject();
     o.Add("foo", "bar");
     Assert.AreEqual("bar", o["foo"]);
     ICollection names = o.Names;
     Assert.AreEqual(1, names.Count);
     Assert.AreEqual(new string[] { "foo" }, CollectionHelper.ToArray(names, typeof(string)));
 }
Ejemplo n.º 4
0
    public Collection<ApiTvEpisode> GetTvEpisodesRefresh()
    {
        var episodes = new Collection<ApiTvEpisode>();

        var properties = new JsonArray(new[] { "title", "plot", "season", "episode", "showtitle", "tvshowid", "fanart", "thumbnail", "rating", "playcount", "firstaired" });
        var param = new JsonObject();
        param["properties"] = properties;
        // First 100 Date sorted
        var param2 = new JsonObject();
        param2.Add("start", 0);
        param2.Add("end", 100);
        var param3 = new JsonObject();
        param3.Add("order", "descending");
        param3.Add("method", "dateadded");
        param.Add("sort", param3);
        param.Add("limits", param2);
        var result = (JsonObject)_parent.JsonCommand("VideoLibrary.GetEpisodes", param);

        if (result != null)
        {
            if (result.Contains("episodes"))
            {
                foreach (JsonObject genre in (JsonArray)result["episodes"])
                {
                    try
                    {
                        var tvShow = new ApiTvEpisode
                        {
                            Title = genre["title"].ToString(),
                            Plot = genre["plot"].ToString(),
                            Rating = genre["rating"].ToString(),
                            Mpaa = "",
                            Date = genre["firstaired"].ToString(),
                            Director = "",
                            PlayCount = 0,
                            Studio = "",
                            IdEpisode = (long)(JsonNumber)genre["episodeid"],
                            IdShow = (long)(JsonNumber)genre["tvshowid"],
                            Season = (long)(JsonNumber)genre["season"],
                            Episode = (long)(JsonNumber)genre["episode"],
                            Path = "",
                            ShowTitle = genre["showtitle"].ToString(),
                            Thumb = genre["thumbnail"].ToString(),
                            Fanart = genre["fanart"].ToString(),
                            Hash = Xbmc.Hash(genre["thumbnail"].ToString())
                        };
                        episodes.Add(tvShow);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        return episodes;
    }
Ejemplo n.º 5
0
 public void CannotCopyToViaGenericCollectionWithTooSmallArray()
 {
     ICollection<KeyValuePair<string, object>> obj = new JsonObject();
     obj.Add(new KeyValuePair<string, object>("foo", "bar"));
     obj.CopyTo(new KeyValuePair<string, object>[1], 1);
 }
Ejemplo n.º 6
0
 public void ContainsNonExistingViaGenericCollection()
 {
     ICollection<KeyValuePair<string, object>> obj = new JsonObject();
     obj.Add(new KeyValuePair<string, object>("first", 123));
     Assert.IsFalse(obj.Contains(new KeyValuePair<string, object>("second", 456)));
 }
Ejemplo n.º 7
0
 public void AddViaGenericDictionary()
 {
     IDictionary<string, object> obj = new JsonObject();
     Assert.AreEqual(0, obj.Count);
     obj.Add("one", 1);
     Assert.AreEqual(1, obj.Count);
     obj.Add("two", 2);
     Assert.AreEqual(2, obj.Count);
 }
Ejemplo n.º 8
0
 public void CannotAddDuplicateKeyViaGenericCollection()
 {
     IDictionary<string, object> obj = new JsonObject();
     obj.Add(new KeyValuePair<string, object>("foo", "bar"));
     obj.Add(new KeyValuePair<string, object>("foo", "baz"));
 }
Ejemplo n.º 9
0
 public void ValuesViaGenericDictionary()
 {
     IDictionary<string, object> obj = new JsonObject();
     obj.Add("first", 123);
     Assert.AreEqual(new object[] { 123 }, obj.Values);
     obj.Add("second", 456);
     Assert.AreEqual(new object[] { 123, 456 }, obj.Values);
 }
Ejemplo n.º 10
0
    public Collection<ApiTvShow> GetTvShowsRefresh()
    {
        var shows = new Collection<ApiTvShow>();

        var properties = new JsonArray(new[] { "title", "art","plot", "genre", "fanart", "thumbnail", "rating", "mpaa", "studio", "playcount", "premiered", "episode", "file" });
        var param = new JsonObject();
        param["properties"] = properties;

        // First 100 Date sorted
        var param2 = new JsonObject();
        param2.Add("start", 0);
        param2.Add("end", 10);   //Number of TV Shows Quick Refresh Gets
        var param3 = new JsonObject();
        param3.Add("order", "descending");
        param3.Add("method", "dateadded");
        param.Add("sort", param3);
        param.Add("limits", param2);


        var result = (JsonObject)_parent.JsonCommand("VideoLibrary.GetTVShows", param);
        if (result != null)
        {
            if (result.Contains("tvshows"))
            {
                foreach (JsonObject genre in (JsonArray)result["tvshows"])
                {
                    try
                    {
                        var clearlogo = "NONE";
                        var banner = "NONE";
                            // go through art and see.

                        JsonObject results = (JsonObject)genre["art"];

                        if (results != null)
                        {
                                if (results["clearlogo"] != null)
                                {
                                    clearlogo = results["clearlogo"].ToString();
                                }
                                if (results["banner"] != null)
                                {
                                    banner = results["banner"].ToString();
                                }

                         }


                        var tvShow = new ApiTvShow
                        {
                            Title = genre["title"].ToString(),
                            Plot = genre["plot"].ToString(),
                            Rating = genre["rating"].ToString(),
                            IdScraper = "",
                            Mpaa = genre["mpaa"].ToString(),
                            Genre = _parent.JsonArrayToString((JsonArray)genre["genre"]),
                            Studio = _parent.JsonArrayToString((JsonArray)genre["studio"]),
                            IdShow = (long)(JsonNumber)genre["tvshowid"],
                            TotalCount = (long)(JsonNumber)genre["episode"],
                            Path = genre["file"].ToString(),
                            Premiered = genre["premiered"].ToString(),
                            Thumb = genre["thumbnail"].ToString(),
                            Fanart = genre["fanart"].ToString(),
                            Logo = clearlogo,
                            Banner = banner,
                            Hash = Xbmc.Hash(genre["thumbnail"].ToString())
                        };
                        shows.Add(tvShow);
                    }
                    catch (Exception ex)
                    {
                            _parent.Log("GetTVShowsRefresh : Exception Caught: Json seems to equal :" + ex);
                     }
                }
            }
        }
        return shows;
    }
Ejemplo n.º 11
0
 public void KeysViaGenericDictionary()
 {
     IDictionary<string, object> obj = new JsonObject();
     obj.Add("first", 123);
     Assert.AreEqual(new string[] { "first" }, obj.Keys);
     obj.Add("second", 456);
     Assert.AreEqual(new string[] { "first", "second" }, obj.Keys);
 }
Ejemplo n.º 12
0
 public void RemoveNonExistingViaGenericCollection()
 {
     ICollection<KeyValuePair<string, object>> obj = new JsonObject();
     obj.Add(new KeyValuePair<string, object>("first", 123));
     Assert.AreEqual(1, obj.Count);
     Assert.IsFalse(obj.Remove(new KeyValuePair<string, object>("second", 456)));
     Assert.AreEqual(1, obj.Count);
 }
Ejemplo n.º 13
0
    public Collection<ApiMovie> GetMoviesRefresh()
    {
        var movies = new Collection<ApiMovie>();

        var properties = new JsonArray(new[] { "title", "plot", "dateadded", "genre", "year", "fanart", "thumbnail", "playcount", "studio", "rating", "runtime", "mpaa", "originaltitle", "director", "votes" });
        var param = new JsonObject();
        param["properties"] = properties;
        // First 100 Date sorted
        var param2 = new JsonObject();
        param2.Add("start", 0);
        param2.Add("end", 100);
        var param3 = new JsonObject();
        param3.Add("order", "descending");
        param3.Add("method", "dateadded");
        param.Add("sort", param3);
        param.Add("limits", param2);


        var result = (JsonObject)_parent.JsonCommand("VideoLibrary.GetMovies", param);
        if (result != null)
        {
            if (result.Contains("movies"))
            {
                foreach (JsonObject genre in (JsonArray)result["movies"])
                {
                    try
                    {
                        var t = TimeSpan.FromSeconds((long)(JsonNumber)genre["runtime"]);
                        var duration = string.Format("{0:D2}:{1:D2}", t.Hours, t.Minutes);
                        var movie = new ApiMovie
                        {

                            Title = genre["title"].ToString(),
                            Plot = genre["plot"].ToString(),
                            Votes = genre["votes"].ToString(),
                            Rating = genre["rating"].ToString(),
                            Year = (long)(JsonNumber)genre["year"],
                            IdScraper = "",
                            Length = duration,
                            Mpaa = genre["mpaa"].ToString(),
                            Genre = _parent.JsonArrayToString((JsonArray)genre["genre"]),
                            Director = _parent.JsonArrayToString((JsonArray)genre["director"]),
                            OriginalTitle = genre["originaltitle"].ToString(),
                            Studio = _parent.JsonArrayToString((JsonArray)genre["studio"]),
                            IdFile = 0,
                            IdMovie = (long)(JsonNumber)genre["movieid"],
                            FileName = "",
                            Path = "",
                            PlayCount = 0,
                            Thumb = genre["thumbnail"].ToString(),
                            Fanart = genre["fanart"].ToString(),
                            Hash = Xbmc.Hash(genre["thumbnail"].ToString()),
                            DateAdded = genre["dateadded"].ToString()
                        };
                        movies.Add(movie);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }

        return movies;

    }
Ejemplo n.º 14
0
 public void CopyToViaGenericCollection()
 {
     ICollection<KeyValuePair<string, object>> obj = new JsonObject();
     KeyValuePair<string, object> first = new KeyValuePair<string, object>("first", 123);
     obj.Add(first);
     KeyValuePair<string, object> second = new KeyValuePair<string, object>("second", 456);
     obj.Add(second);
     KeyValuePair<string, object>[] pairs = new KeyValuePair<string, object>[2];
     obj.CopyTo(pairs, 0);
     Assert.AreEqual(first, pairs[0]);
     Assert.AreEqual(second, pairs[1]);
 }
Ejemplo n.º 15
0
    public Collection<ApiTvShow> GetTvShowsRefresh()
    {
        var shows = new Collection<ApiTvShow>();

        var properties = new JsonArray(new[] { "title", "plot", "genre", "fanart", "thumbnail", "rating", "mpaa", "studio", "playcount", "premiered", "episode" });
        var param = new JsonObject();
        param["properties"] = properties;

        // First 100 Date sorted
        var param2 = new JsonObject();
        param2.Add("start", 0);
        param2.Add("end", 10);
        var param3 = new JsonObject();
        param3.Add("order", "descending");
        param3.Add("method", "dateadded");
        param.Add("sort", param3);
        param.Add("limits", param2);


        var result = (JsonObject)_parent.JsonCommand("VideoLibrary.GetTVShows", param);
        if (result != null)
        {
            if (result.Contains("tvshows"))
            {
                foreach (JsonObject genre in (JsonArray)result["tvshows"])
                {
                    try
                    {
                        var tvShow = new ApiTvShow
                        {
                            Title = genre["title"].ToString(),
                            Plot = genre["plot"].ToString(),
                            Rating = genre["rating"].ToString(),
                            IdScraper = "",
                            Mpaa = genre["mpaa"].ToString(),
                            Genre = _parent.JsonArrayToString((JsonArray)genre["genre"]),
                            Studio = _parent.JsonArrayToString((JsonArray)genre["studio"]),
                            IdShow = (long)(JsonNumber)genre["tvshowid"],
                            TotalCount = (long)(JsonNumber)genre["episode"],
                            Path = "",
                            Premiered = genre["premiered"].ToString(),
                            Thumb = genre["thumbnail"].ToString(),
                            Fanart = genre["fanart"].ToString(),
                            Hash = Xbmc.Hash(genre["thumbnail"].ToString())
                        };
                        shows.Add(tvShow);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        return shows;
    }   
Ejemplo n.º 16
0
        public void SaveState(bool is_shuttingdown = false)
        {
            Directory.CreateDirectory(StateSaveDirectory);

            File.WriteAllBytes(this.LtSessionFilePath, this.LibtorrentSession.SaveState());

            for (int index = 0; index < this.Torrents.Count; index++)
            {
                try
                {
                    TorrentInfo ti = this.Torrents[index];
                    Ragnar.TorrentHandle handle = ti.Torrent;
                    if (!handle.HasMetadata) { continue; }

                    if (handle.NeedSaveResumeData())
                    {
                        handle.SaveResumeData();
                    }

                    if (is_shuttingdown)
                    {
                        //save misc settings

                        JsonObject jo = new JsonObject();
                        jo.Add("SavePath", handle.QueryStatus().SavePath);

                        //jo.Add("PickedMovieData", ti.PickedMovieData.ToString());

                        jo.Add("RanCommand", ti.RanCommand);

                        jo.Add("RatioLimit", ti.RatioLimit);

                        jo.Add("CompletionCommand", ti.CompletionCommand);

                        jo.Add("CustomName", ti.Name);

                        jo.Add("OriginalTorrentFilePath", ti.OriginalTorrentFilePath);

                        jo.Add("IsStopped", ti.IsStopped);

                        jo.Add("Labels", this.LabelManager.GetLabelsForTorrent(ti));

                        using (TextWriter tw = File.CreateText(
                            Path.Combine(State.TorrentsStateSaveDirectory, ti.InfoHash + ".tjson")))
                        {
                            JsonConvert.Export(jo, tw);
                        }
                    }
                }
                catch (System.IndexOutOfRangeException)
                {
                    break;
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }
Ejemplo n.º 17
0
        public JsonWsp.Response CallMethod(string methodname, JsonObject args, Dictionary<String, String> cookies = null, Dictionary<String, String> headers = null)
        {
            JsonObject req_dict = new JsonObject();
            req_dict.Add("methodname",methodname);
            req_dict.Add("type","jsonwsp/request");
            req_dict.Add("args",args);
            JsonWriter json_req_writer = new JsonTextWriter();
            req_dict.Export(json_req_writer);

            Dictionary<String, String> cookieList = m_cookieList;
            if (cookies != null)
            {
                foreach (String key in cookies.Keys)
                {
                    cookieList[key] = cookies[key];
                }
            }

            Dictionary<String, String> headerList = m_headerList;
            if (headers != null)
            {
                foreach (String key in headers.Keys)
                {
                    headerList[key] = headers[key];
                }
            }

            string content_type = "application/json; charset=utf-8";
            JsonWsp.Response jsonwsp_response = SendRequest(m_service_url, json_req_writer.ToString(),content_type, cookieList, headerList);
            // Convert response text
            return jsonwsp_response;
        }
Ejemplo n.º 18
0
    public Collection<ApiTvSeason> GetTvSeasonsRefresh()
    {
        var seasons = new Collection<ApiTvSeason>();

        var properties = new JsonArray(new[] { "title" });
        var param = new JsonObject();
        param["properties"] = properties;

        // First 100 Date sorted
        var param2 = new JsonObject();
        param2.Add("start", 0);
        param2.Add("end", 10);
        var param3 = new JsonObject();
        param3.Add("order", "descending");
        param3.Add("method", "dateadded");
        param.Add("sort", param3);
        param.Add("limits", param2);

        var result = (JsonObject)_parent.JsonCommand("VideoLibrary.GetTVShows", param);
        if (result != null)
        {
            if (result.Contains("tvshows"))
            {
                foreach (JsonObject show in (JsonArray)result["tvshows"])
                {
                    var properties2 =
                      new JsonArray(new[] { "tvshowid", "fanart", "thumbnail", "season", "showtitle", "episode" });
                    var param22 = new JsonObject();
                    param22["properties"] = properties2;
                    param22["tvshowid"] = (long)(JsonNumber)show["tvshowid"];

                    var result2 = (JsonObject)_parent.JsonCommand("VideoLibrary.GetSeasons", param22);
                    if (result2 == null) continue;
                    if (!result2.Contains("seasons")) continue;
                    foreach (JsonObject genre in (JsonArray)result2["seasons"])
                    {
                        try
                        {

                            _parent.Trace("Kodi QuickRefresh Seasons:  SeasonNumber:" + (long)(JsonNumber)genre["season"]);
                            _parent.Trace("Kodi QuickRefresh Seasons:  IdShow:" + (long)(JsonNumber)genre["tvshowid"]);
                            _parent.Trace("Kodi QuickRefresh Seasons:  Show:" + genre["showtitle"].ToString());
                            _parent.Trace("Kodi QuickRefresh Seasons:  Thumb:" + genre["thumbnail"].ToString());
                            _parent.Trace("Kodi QuickRefresh Seasons:  EpisodeCount:" + (long)(JsonNumber)genre["episode"]);
                            _parent.Trace("Kodi QuickRefresh Seasons:  Fanart:" + genre["fanart"].ToString());
                            _parent.Trace("Kodi QuickRefresh Seasons:  Hash:" + genre["thumbnail"].ToString());

                            var tvShow = new ApiTvSeason
                            {
                                SeasonNumber = (long)(JsonNumber)genre["season"],
                                IdShow = (long)(JsonNumber)genre["tvshowid"],
                                Show = genre["showtitle"].ToString(),
                                Thumb = genre["thumbnail"].ToString(),
                                EpisodeCount = (long)(JsonNumber)genre["episode"],
                                Fanart = genre["fanart"].ToString(),
                                Hash = Xbmc.Hash(genre["thumbnail"].ToString())
                            };
                            seasons.Add(tvShow);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }
        return seasons;
    }
Ejemplo n.º 19
0
        public Collection<ApiMovie> GetMoviesRefresh()
        {
            var movies = new Collection<ApiMovie>();

            var properties = new JsonArray(new[] { "title", "art", "streamdetails", "plot", "dateadded", "genre", "year", "fanart", "thumbnail", "playcount", "studio", "rating", "runtime", "mpaa", "originaltitle", "director", "votes", "file" });
            var param = new JsonObject();
            param["properties"] = properties;
            // First 100 Date sorted
            var param2 = new JsonObject();
            param2.Add("start", 0);
            param2.Add("end", 30);  //Number of Movies Quick refresh gets
            var param3 = new JsonObject();
            param3.Add("order", "descending");
            param3.Add("method", "dateadded");
            param.Add("sort", param3);
            param.Add("limits", param2);


            var result = (JsonObject)_parent.JsonCommand("VideoLibrary.GetMovies", param);

            if (result != null)
            {
                if (result.Contains("movies"))
                {
                    foreach (JsonObject genre in (JsonArray)result["movies"])
                    {
                        try
                        {
                            var t = TimeSpan.FromSeconds((long)(JsonNumber)genre["runtime"]);
                            var duration = string.Format("{0:D2}:{1:D2}", t.Hours, t.Minutes);
                            var clearlogo = "NONE";
                            var banner = "NONE";
                            // go through art and see.

                            JsonObject results = (JsonObject)genre["art"];
                                                        
                            if (results != null)
                            {
                                if (results["clearlogo"] != null)
                                {
                                    clearlogo = results["clearlogo"].ToString();
                                }
                                if (results["banner"] != null)
                                {
                                    banner = results["banner"].ToString();
                                }

                            }

                            JsonObject streamdetails = (JsonObject)genre["streamdetails"];
                            List<string> MovieIcons = new List<string>();
                            MovieIcons = GetMovieIcons(streamdetails);
              
                                                 




                            var movie = new ApiMovie
                            {

                                Title = genre["title"].ToString(),
                                Plot = genre["plot"].ToString(),
                                Votes = genre["votes"].ToString(),
                                Rating = genre["rating"].ToString(),
                                Year = (long)(JsonNumber)genre["year"],
                                IdScraper = "",
                                Length = duration,
                                Mpaa = genre["mpaa"].ToString(),
                                Genre = _parent.JsonArrayToString((JsonArray)genre["genre"]),
                                Director = _parent.JsonArrayToString((JsonArray)genre["director"]),
                                OriginalTitle = genre["originaltitle"].ToString(),
                                Studio = _parent.JsonArrayToString((JsonArray)genre["studio"]),
                                IdFile = 0,
                                IdMovie = (long)(JsonNumber)genre["movieid"],
                                FileName = genre["file"].ToString(),
                                Path = "",
                                PlayCount = 0,
                                Thumb = genre["thumbnail"].ToString(),
                                Fanart = genre["fanart"].ToString(),
                                Logo = clearlogo,
                                Banner = banner,
                                Hash = Xbmc.Hash(genre["thumbnail"].ToString()),
                                DateAdded = genre["dateadded"].ToString(),
                                MovieIcons = String.Join(",", MovieIcons)
                            };
                            movies.Add(movie);
                        }
                        catch (Exception ex)
                        {
                            _parent.Log("Exception Caught: Json seems to equal :" + ex);
                        }
                    }

                }
                return movies;

                
            }
            return movies;
        }
Ejemplo n.º 20
0
 public void KeyContainmentViaGenericDictionary()
 {
     IDictionary<string, object> obj = new JsonObject();
     Assert.IsFalse(obj.ContainsKey("foo"));
     obj.Add(new KeyValuePair<string, object>("foo", "bar"));
     Assert.IsTrue(obj.ContainsKey("foo"));
 }
Ejemplo n.º 21
0
        private object Node2Item(object dic)
        {
            JsonObject js = new JsonObject();
            if (dic is IFreeDocument)
            {
                var res = (dic as IFreeDocument).DictSerialize();
                js.AddRange(res);
                var fre = dic as FreeDocument;
                if (fre != null)
                {
                    if (fre.Children != null)
                    {
                        JsonArray array = new JsonArray();
                        foreach (var child in fre.Children)
                        {
                            array.Add(Node2Item(child));
                        }
                        if (!js.HasMembers)
                            return array;
                        js.Add("Children", array);
                    }
                }
            }
            else
            {
                return dic;
            }

            return js;
        }
Ejemplo n.º 22
0
        public void KeyValuePairEnumeration()
        {
            ICollection<KeyValuePair<string, object>> obj = new JsonObject();

            KeyValuePair<string, object> first = new KeyValuePair<string, object>("first", 123);
            obj.Add(first);

            KeyValuePair<string, object> second = new KeyValuePair<string, object>("second", 456);
            obj.Add(second);

            using (IEnumerator<KeyValuePair<string, object>> e = obj.GetEnumerator())
            {
                Assert.IsNotNull(e);
                Assert.IsTrue(e.MoveNext());
                Assert.AreEqual(first, e.Current);
                Assert.IsTrue(e.MoveNext());
                Assert.AreEqual(second, e.Current);
                Assert.IsFalse(e.MoveNext());
            }
        }
Ejemplo n.º 23
0
        public void Enumeration()
        {
            JsonObject o = new JsonObject();
            o.Add("one", 1);
            o.Add("two", 2);
            o.Add("three", 3);
            o.Add("four", 4);

            JsonObject.JsonMemberEnumerator e = o.GetEnumerator();

            Assert.IsNotNull(e);

            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("one", e.Current.Name);
            Assert.AreEqual(1, e.Current.Value);

            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("two", e.Current.Name);
            Assert.AreEqual(2, e.Current.Value);

            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("three", e.Current.Name);
            Assert.AreEqual(3, e.Current.Value);

            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("four", e.Current.Name);
            Assert.AreEqual(4, e.Current.Value);

            Assert.IsFalse(e.MoveNext());
        }
Ejemplo n.º 24
0
 public void RemoveNonExistingViaGenericDictionary()
 {
     IDictionary<string, object> obj = new JsonObject();
     obj.Add("first", 123);
     Assert.AreEqual(1, obj.Count);
     Assert.IsFalse(obj.Remove("second"));
     Assert.AreEqual(1, obj.Count);
 }
Ejemplo n.º 25
0
 public void AddViaGenericCollection()
 {
     ICollection<KeyValuePair<string, object>> obj = new JsonObject();
     Assert.AreEqual(0, obj.Count);
     obj.Add(new KeyValuePair<string, object>("one", 1));
     Assert.AreEqual(1, obj.Count);
     obj.Add(new KeyValuePair<string, object>("two", 2));
     Assert.AreEqual(2, obj.Count);
 }
Ejemplo n.º 26
0
 public void CannotAddMemberNameDuplicates()
 {
     JsonObject o = new JsonObject();
     o.Add("foo", "bar");
     o.Add("foo", "baz");
 }
Ejemplo n.º 27
0
        protected override void OnStartup(StartupEventArgs e)
        {
            Environment.CurrentDirectory =
                new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName;
            if (e.Args.Length != 0)
            {
                try
                {
                    TcpClient tcp = new TcpClient();
                    tcp.Connect("127.0.0.1", 65432);
                    NetworkStream ns = tcp.GetStream();
                    Random rnd = new Random();
                    StreamWriter sw = new StreamWriter(ns);
                    foreach (string str in e.Args)
                    {
                        JsonObject jo = new JsonObject();
                        jo.Add("id", rnd.Next());
                        jo.Add("method", "addtorrentbypath");
                        jo.Add("params", new JsonArray() { str });
                        sw.WriteLine(jo.ToString());
                        sw.Flush();
                    }
                    tcp.Close();
                    Environment.Exit(0);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    to_add = e.Args;
                }
            }
            else
                to_add = new string[0];

            base.OnStartup(e);

            Settings = Settings.Load("./config.xml");

            CurrentLanguage = LanguageEngine.LoadDefault();

            LoadTheme(Settings.Theme);
        }