示例#1
0
        public byte[] DownloadFile(SkydriveContent skydriveContent)
        {
            var uri  = new Uri(string.Format("https://apis.live.net/v5.0/{0}/content?access_token={1}", skydriveContent.Id, AccessToken));
            var json = GetResponse(uri);

            return(GetResponseBytes(uri, skydriveContent.Size));
        }
示例#2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (listViewFiles.SelectedItems.Count < 1)
            {
                return;
            }

            SkydriveContent sc = (SkydriveContent)listViewFiles.SelectedItems[0].Tag;

            try
            {
                if (listViewFiles.SelectedItems[0].Text == "..")
                {
                    labelInfo.Text = "Loading files...";
                    Cursor         = Cursors.WaitCursor;
                    _roots.Pop();
                    LoadFiles(sc.ParentId);
                    Cursor = Cursors.Default;
                }
                else if (sc.IsFolder)
                {
                    labelInfo.Text = "Loading files...";
                    Cursor         = Cursors.WaitCursor;
                    _roots.Push(sc.ParentId);
                    LoadFiles(sc.Id);
                    Cursor = Cursors.Default;
                }
                else if (sc.IsFile)
                {
                    labelInfo.Text = "Downloading...";
                    this.Refresh();
                    Cursor = Cursors.WaitCursor;
                    var fileDown = _api.DownloadFile(sc);
                    LoadedSubtitle = Encoding.UTF8.GetString(fileDown).Trim();
                    DialogResult   = DialogResult.OK;
                }
                Cursor         = Cursors.Default;
                labelInfo.Text = string.Empty;
                this.Refresh();
            }
            catch (Exception exception)
            {
                labelInfo.Text = string.Empty;
                Cursor         = Cursors.Default;
                MessageBox.Show(exception.Message);
            }
        }
示例#3
0
        private void LoadFiles(string path)
        {
            listViewFiles.Items.Clear();
            if (_roots.Count > 0)
            {
                ListViewItem    item = new ListViewItem("..");
                SkydriveContent sc   = new SkydriveContent();
                sc.ParentId     = _roots.Peek();
                item.Tag        = sc;
                item.ImageIndex = 1;
                listViewFiles.Items.Add(item);
            }

            foreach (SkydriveContent f in _api.GetFiles(path))
            {
                if (f.IsFile || f.IsFolder)
                {
                    ListViewItem item = new ListViewItem(f.Name)
                    {
                        Tag = f
                    };
                    item.SubItems.Add(f.UpdatedTime.ToShortDateString() + " " + f.UpdatedTime.ToShortTimeString());
                    item.SubItems.Add(FormatBytesToDisplayFileSize(f.Size));
                    if (f.IsFile)
                    {
                        item.ImageIndex = 0;
                    }
                    else
                    {
                        item.ImageIndex = 1;
                    }
                    listViewFiles.Items.Add(item);
                }
            }
            if (listViewFiles.Items.Count > 0)
            {
                listViewFiles.Items[0].Selected = true;
            }
        }
示例#4
0
        public List <SkydriveContent> GetFiles(string path)
        {
            var uri  = new Uri(string.Format("https://apis.live.net/v5.0/{0}/files?access_token={1}", path, AccessToken));
            var json = GetResponse(uri);

            Hashtable o = (Hashtable)Nikse.Json.JSON.JsonDecode(json);
            List <SkydriveContent> list = new List <SkydriveContent>();

            foreach (Hashtable ht in (o["data"] as System.Collections.ArrayList))
            {
                SkydriveContent file = new SkydriveContent();
                if (ht.ContainsKey("id"))
                {
                    file.Id          = ht["id"].ToString();
                    file.Name        = ht["name"].ToString();
                    file.Size        = Convert.ToInt64(ht["size"].ToString());
                    file.UpdatedTime = Convert.ToDateTime(ht["updated_time"].ToString());
                    file.ParentId    = ht["parent_id"].ToString();
                    file.Type        = ht["type"].ToString();
                    list.Add(file);
                }
            }
            return(list);
        }