Ejemplo n.º 1
0
        public void IsNullOrEmpty()
        {
            UniValue v = null;

            Assert.True(UniValue.IsNullOrEmpty(v));

            v = "123";

            Assert.False(UniValue.IsNullOrEmpty(v));
            Assert.False(UniValue.IsNullOrEmpty(1));
            Assert.False(UniValue.IsNullOrEmpty("test"));
            Assert.True(UniValue.IsNullOrEmpty(UniValue.Empty));
            Assert.False(UniValue.IsNullOrEmpty(UniValue.Create(DateTime.Now)));
            Assert.True(UniValue.IsNullOrEmpty(UniValue.Create()));
        }
Ejemplo n.º 2
0
 internal static bool IsEmpty(object value)
 {
     if (value == DBNull.Value || value == null)
     {
         return(true);
     }
     if (value.GetType() == typeof(string))
     {
         return(String.IsNullOrEmpty(value.ToString()));
     }
     if (value.GetType() == typeof(UniValue) || value.GetType().IsSubclassOf(typeof(UniValue)))
     {
         return(UniValue.IsNullOrEmpty((UniValue)value));
     }
     return(false);
 }
Ejemplo n.º 3
0
        public void ToStringTest()
        {
            UniValue value = UniValue.ParseXml("<response><item>1</item><item>2</item><item>3</item></response>");

            Assert.Equal("{ \"response\": { \"item\": [\"1\", \"2\", \"3\"] } }", value.ToString());

            value["response"]["item"]["test"] = "123";

            Assert.Equal("{ \"response\": { \"item\": { \"0\": \"1\", \"1\": \"2\", \"2\": \"3\", \"test\": \"123\" } } }", value.ToString());

            value = UniValue.ParseJson("{\"data\": [{\"id\": 1, \"name\": \"test\"}, {\"id\": 2, \"name\": \"test2\"}, {\"id\": 3, \"name\": \"test3\", \"list\": [{\"x\":1,\"y\":\"hi\"}, {\"x\":2, \"y\":\"hello\"}] }] }");

            Assert.Equal("{ \"data\": [{ \"id\": 1, \"name\": \"test\" }, { \"id\": 2, \"name\": \"test2\" }, { \"id\": 3, \"name\": \"test3\", \"list\": [{ \"x\": 1, \"y\": \"hi\" }, { \"x\": 2, \"y\": \"hello\" }] }] }", value.ToString());
            Assert.Equal("[{ \"id\": 1, \"name\": \"test\" }, { \"id\": 2, \"name\": \"test2\" }, { \"id\": 3, \"name\": \"test3\", \"list\": [{ \"x\": 1, \"y\": \"hi\" }, { \"x\": 2, \"y\": \"hello\" }] }]", value["data"].ToString());
            Assert.Equal("test2", value["data"][1]["name"].ToString());

            value = UniValue.ParseXml("<response><item id='1' style='bold' color='white' /><item id='2' style='italic' color='red'>123</item></response>");

            Assert.True(value == "{ \"response\": { \"item\": [{ \"@id\": \"1\", \"@style\": \"bold\", \"@color\": \"white\" }, { \"value\": \"123\", \"@id\": \"2\", \"@style\": \"italic\", \"@color\": \"red\" }] } }");
            Assert.True(value["response"] == "{ \"item\": [{ \"@id\": \"1\", \"@style\": \"bold\", \"@color\": \"white\" }, { \"value\": \"123\", \"@id\": \"2\", \"@style\": \"italic\", \"@color\": \"red\" }] }");
            Assert.True(value["response"]["item"] == "[{ \"@id\": \"1\", \"@style\": \"bold\", \"@color\": \"white\" }, { \"value\": \"123\", \"@id\": \"2\", \"@style\": \"italic\", \"@color\": \"red\" }]");
            Assert.True(String.IsNullOrEmpty(value["response"]["item"][0].ToString()));
            Assert.True(value["response"]["item"][0].ToString() == "");
            Assert.False(UniValue.IsNullOrEmpty(value["response"]["item"][0]));
            Assert.True(value["response"]["item"][1] == "123");
            Assert.True(value["response"]["item"][1] == 123);
            Assert.True(value["response"]["item"][0]["@id"] == 1);
            Assert.True(value["response"]["item"][0]["style"] == "bold");

            value = UniValue.ParseXml("<response><item id='1' style='bold' color='white'><vvalue abc='test' avalue='1234567'></vvalue></item><item id='2' style='italic' color='red'><v>456</v></item></response>");

            Assert.Equal("{ \"response\": { \"item\": [{ \"value\": { \"vvalue\": { \"@abc\": \"test\", \"@avalue\": \"1234567\" } }, \"@id\": \"1\", \"@style\": \"bold\", \"@color\": \"white\" }, { \"value\": { \"v\": \"456\" }, \"@id\": \"2\", \"@style\": \"italic\", \"@color\": \"red\" }] } }", value.ToString());
            Assert.Equal("[{ \"value\": { \"vvalue\": { \"@abc\": \"test\", \"@avalue\": \"1234567\" } }, \"@id\": \"1\", \"@style\": \"bold\", \"@color\": \"white\" }, { \"value\": { \"v\": \"456\" }, \"@id\": \"2\", \"@style\": \"italic\", \"@color\": \"red\" }]", value["response"]["item"].ToString());
            Assert.Equal("{ \"vvalue\": { \"@abc\": \"test\", \"@avalue\": \"1234567\" } }", value["response"]["item"][0].ToString());

            value = UniValue.ParseJson("{data: [{id: 1, name: null}, {id: 2, name: 'test2\r\n123'}, {id: 3, name: 'test3', list: [{x:1,y:'hi'}, {x:2, y:'hello'}] }] }");

            Assert.Equal("{ \"data\": [{ \"id\": 1, \"name\": null }, { \"id\": 2, \"name\": \"test2\\r\\n123\" }, { \"id\": 3, \"name\": \"test3\", \"list\": [{ \"x\": 1, \"y\": \"hi\" }, { \"x\": 2, \"y\": \"hello\" }] }] }", value.ToString());

            value = "test\r\ntest";

            Assert.Equal("test\r\ntest", value.ToString());
        }
Ejemplo n.º 4
0
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            UniValue file = (UniValue)listBox1.SelectedItem;

            if (!UniValue.IsNullOrEmpty(file["toup"]))
            {
                this.CurrentFolderId = this.LastFolderId;
                this.LastFolderId    = "";
            }
            else
            {
                if (file["folder"].HasValue)
                {
                    this.LastFolderId    = this.CurrentFolderId;
                    this.CurrentFolderId = file["id"].ToString();
                }
                else
                {
                    // https://dev.onedrive.com/items/download.htm

                    saveFileDialog1.FileName = Path.GetFileName(file["name"].ToString());
                    if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    var web = new WebClient();
                    web.DownloadProgressChanged += DownloadProgressChanged;
                    web.Headers.Add("Authorization", String.Format("Bearer {0}", Properties.Settings.Default.AccessToken));
                    web.DownloadFileAsync(new Uri(String.Format("{0}/drive/items/{1}/content", API_BASE_URL, file["id"])), saveFileDialog1.FileName);
                }
            }

            this.GetFiles();
        }
Ejemplo n.º 5
0
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            UniValue file = (UniValue)listBox1.SelectedItem;

            if (!UniValue.IsNullOrEmpty(file["toup"]))
            {
                this.CurrentFolderId = this.LastFolderId;
                this.LastFolderId    = "";
            }
            else
            {
                if (file["mimeType"] == "application/vnd.google-apps.folder")
                {
                    this.LastFolderId    = this.CurrentFolderId;
                    this.CurrentFolderId = file["id"].ToString();
                }
                else
                {
                    saveFileDialog1.FileName = Path.GetFileName(file["title"].ToString());
                    if (saveFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }
                    var web = new WebClient();
                    web.DownloadProgressChanged += DownloadProgressChanged;
                    web.Headers.Add("Authorization", String.Format("Bearer {0}", Properties.Settings.Default.AccessToken));
                    web.DownloadFileAsync(new Uri(String.Format("https://www.googleapis.com/drive/v2/files/{0}?alt=media", file["id"])), saveFileDialog1.FileName);
                }
            }

            this.GetFiles();
        }
Ejemplo n.º 6
0
        public void UniValue_IsNullOrEmpty()
        {
            UniValue v = null;

            Console.WriteLine("null = {0}", UniValue.IsNullOrEmpty(v));
            if (UniValue.IsNullOrEmpty(v))
            {
                Console.WriteLine("OK");
            }
            else
            {
                Assert.Fail();
            }
            v = "123";
            Console.WriteLine("123 = {0}", UniValue.IsNullOrEmpty(v));
            if (!UniValue.IsNullOrEmpty(v))
            {
                Console.WriteLine("OK");
            }
            else
            {
                Assert.Fail();
            }
            Console.WriteLine("1 = {0}", UniValue.IsNullOrEmpty(1));
            if (!UniValue.IsNullOrEmpty(1))
            {
                Console.WriteLine("OK");
            }
            else
            {
                Assert.Fail();
            }
            Console.WriteLine("test = {0}", UniValue.IsNullOrEmpty("test"));
            if (!UniValue.IsNullOrEmpty("test"))
            {
                Console.WriteLine("OK");
            }
            else
            {
                Assert.Fail();
            }
            Console.WriteLine("empty = {0}", UniValue.IsNullOrEmpty(UniValue.Empty));
            if (UniValue.IsNullOrEmpty(UniValue.Empty))
            {
                Console.WriteLine("OK");
            }
            else
            {
                Assert.Fail();
            }
            Console.WriteLine("create = {0}", UniValue.IsNullOrEmpty(UniValue.Create(DateTime.Now)));
            if (!UniValue.IsNullOrEmpty(UniValue.Create(DateTime.Now)))
            {
                Console.WriteLine("OK");
            }
            else
            {
                Assert.Fail();
            }
            Console.WriteLine("create empty = {0}", UniValue.IsNullOrEmpty(UniValue.Create()));
            if (UniValue.IsNullOrEmpty(UniValue.Create()))
            {
                Console.WriteLine("OK");
            }
            else
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the user details.
        /// </summary>
        /// <param name="accessToken">May contain an access token, which will have to be used in obtaining information about the user.</param>
        /// <remarks>
        /// <para>Access token must contain the user ID in the parameter <b>xoauth_yahoo_guid</b>.</para>
        /// </remarks>
        public override UserInfo GetUserInfo(AccessToken accessToken = null)
        {
            accessToken = base.GetSpecifiedTokenOrCurrent(accessToken);

            RequestResult result;
            string        guid = null;

            if (!UniValue.IsNullOrEmpty(accessToken["xoauth_yahoo_guid"]))
            {
                guid = accessToken["xoauth_yahoo_guid"].ToString();
            }
            else
            {
                result = OAuthUtility.Get("https://social.yahooapis.com/v1/me/guid", accessToken: accessToken);
                guid   = result["guid"]["value"].ToString();
            }

            string url = String.Format("https://social.yahooapis.com/v1/user/{0}/profile?format=json", guid);

            result = OAuthUtility.Get
                     (
                endpoint: url,
                accessToken: accessToken
                     );

            var map = new ApiDataMapping();

            map.Add("guid", "UserId", typeof(string));
            map.Add("givenName", "FirstName");
            map.Add("familyName", "LastName");
            map.Add("nickname", "DisplayName");
            map.Add("profileUrl", "Url");
            map.Add("lang", "Language");
            map.Add("birthdate", "Birthday", typeof(DateTime), @"MM\/dd\/yyyy");
            map.Add
            (
                "gender", "Sex",
                delegate(UniValue value)
            {
                if (!value.HasValue)
                {
                    return(Sex.None);
                }
                if (value.Equals("M", StringComparison.OrdinalIgnoreCase))
                {
                    return(Sex.Male);
                }
                else if (value.Equals("F", StringComparison.OrdinalIgnoreCase))
                {
                    return(Sex.Female);
                }
                return(Sex.None);
            }
            );
            map.Add
            (
                "image", "Userpic",
                delegate(UniValue value)
            {
                return(Convert.ToString(value["imageUrl"]));
            }
            );
            map.Add
            (
                "phones", "Phone",
                delegate(UniValue value)
            {
                return(Convert.ToString(value["number"]));
            }
            );

            return(new UserInfo(result["profile"], map));
        }