Esempio n. 1
0
        private async Task LoadOneDriveFile(string p, DriveInfo driveinfo)
        {
            OneDriveFolder Ones = new OneDriveFolder(driveinfo);
            await Ones.AddFiles(p);

            Ones.ToString();
            all.Add(Ones);
        }
Esempio n. 2
0
        private async Task LoadOneDriveFile(string p, ODConnection item)
        {
            OneDriveFolder Ones = new OneDriveFolder(item);
            await Ones.AddFiles(p);

            Ones.ToString();
            folder.Add(Ones);
        }
Esempio n. 3
0
        public string GetFolderPath(OneDriveFolder folder, List <OneDriveFolder> folders)
        {
            string         path         = "";
            string         top          = folders[0].id;
            OneDriveFolder searchfolder = folder;

            while (searchfolder != null)
            {
                path         = searchfolder.name + "/" + path;
                searchfolder = GetFolder(searchfolder.parent, folders);
            }
            return("$/" + path);
        }
        public void InitTests()
        {
            connection = TestAuthenticationHelper.GetAuthenticatedClient();

            const int LINE_COUNT = 3;
            var       stream     = new System.IO.StreamWriter(TestFileFullName);

            for (int i = 0; i < LINE_COUNT; i++)
            {
                stream.Write($"{i}qwertyuiop\n");
            }
            stream.Close();

            testFolder = OneDriveUtility.CreateFolder(connection, TestData.TestFolderName, null)?.Data;
        }
Esempio n. 5
0
        public CloudFiles CreateFile(Dictionary <string, object> fileinfo)
        {
            CloudFiles files = null;

            if (driveinfo.token.Drive == "Google")
            {
                GoogleFolder folder = new GoogleFolder(driveinfo);
                files = folder.AddFiles(fileinfo);
            }
            else if (driveinfo.token.Drive == "OneDrive")
            {
                OneDriveFolder folder = new OneDriveFolder(driveinfo);
                files = folder.AddFiles(fileinfo);
            }
            else if (driveinfo.token.Drive == "DropBox")
            {
                DropBoxFolder folder = new DropBoxFolder(driveinfo);
                files = folder.AddFiles(fileinfo);
            }
            return(files);
        }
Esempio n. 6
0
        private async void NavigateToItem(CloudFiles item)
        {
            flowLayoutPanel_filecontent.Controls.Clear();
            if ((item as GoogleFile) != null)
            {
                GoogleFile file      = (GoogleFile)item;
                AllFolder  newfolder = new GoogleFolder(file.Service);
                await newfolder.AddFiles(file.GetId());

                LoadTile(newfolder);
            }
            else if ((item as OneDriveFile) != null)
            {
                OneDriveFile file      = (OneDriveFile)item;
                AllFolder    newfolder = new OneDriveFolder(file.Connect);
                await newfolder.AddFiles(file.GetId());

                LoadTile(newfolder);
            }
            else
            {
                MessageBox.Show("파일 열기 실패");
            }
        }
Esempio n. 7
0
        public async void SetOneDriveLinks()
        {
            SyncTimer.Stop();
            SetStateRunning();
            OneDriveFolder rootfolder = null;

            if (onedriveitems != null && onedriveitems.Count > 0)
            {
                int titems = onedriveitems.Count;
                sb.AppendLine("Item Count: " + titems.ToString());
                int nitems  = 0;
                int nerrors = 0;
                foreach (OneDriveItem item in onedriveitems)
                {
                    nitems++;
                    if (bstop == true)
                    {
                        bstop = false;
                        sb.AppendLine("Stopped by user");
                        richTextStatus.Text = sb.ToString();
                        richTextStatus.Refresh();
                        SetStateReady();
                        return;
                    }
                    string karaoke     = "/karaoke/";
                    string lowpath     = item.Path.Trim().ToLower();
                    string therootpath = item.Path.Trim().Replace('\\', '/');
                    string lowrootpath = therootpath.ToLower();
                    if (lowrootpath.StartsWith("http") == true || lowrootpath.StartsWith("www") == true)
                    {
                        item.Link = item.Path;
                        continue;
                    }
                    int ixi = lowrootpath.IndexOf(karaoke);
                    int ixe = therootpath.LastIndexOf('/');
                    if (!(ixi > 0 && ixi < ixe))
                    {
                        item.Link = item.Path;
                        sb.AppendLine(string.Format("Path not found: {0}", therootpath));
                        richTextStatus.Text = sb.ToString();
                        richTextStatus.Refresh();
                        if (nerrors++ < 20)
                        {
                            continue;
                        }
                        else
                        {
                            sb.AppendLine("Excessive not found errors - aborting...");
                            richTextStatus.Text = sb.ToString();
                            richTextStatus.Refresh();
                            SetStateReady();
                            return;
                        }
                    }
                    if (item.Link != null && item.Link.Trim().Length > 0)
                    {
                        signinButton.Enabled  = true;
                        signOutButton.Enabled = true;
                    }
                    else
                    {
                        string   thefile   = Path.GetFileName(therootpath);
                        string   rootpath  = therootpath.Substring(ixi + 1, ixe - ixi - 1);
                        string[] rootpaths = rootpath.Split('/');
                        rootpath = "me/skydrive";
                        foreach (string root in rootpaths)
                        {
                            if (bstop == true)
                            {
                                bstop = false;
                                sb.AppendLine("Stopped by user");
                                richTextStatus.Text = sb.ToString();
                                richTextStatus.Refresh();
                                SetStateReady();
                                return;
                            }
                            if (parents.ContainsKey(root) == true)
                            {
                                rootfolder = new OneDriveFolder("", parents[root], root, "");
                                rootpath   = parents[root];
                            }
                            else
                            {
                                richTextStatus.Text = sb.ToString() + String.Format("Finding root: {0}", root);
                                richTextStatus.Refresh();
                                LiveOperationResult   rootresult  = null;
                                List <OneDriveFolder> rootfolders = new List <OneDriveFolder>();
                                try
                                {
                                    rootresult = await this.liveConnectClient.GetAsync(string.Format("{0}/files", rootpath));

                                    if (rootresult != null && rootresult.Result != null && rootresult.Result["data"] != null)
                                    {
                                        foreach (KeyValuePair <string, object> o in rootresult.Result)
                                        {
                                            if (bstop == true)
                                            {
                                                bstop = false;
                                                sb.AppendLine("Stopped by user");
                                                richTextStatus.Text = sb.ToString();
                                                richTextStatus.Refresh();
                                                SetStateReady();
                                                return;
                                            }
                                            if (o.Key == "data")
                                            {
                                                if (o.Value != null && o.Value is List <object> )
                                                {
                                                    foreach (object obj in o.Value as List <object> )
                                                    {
                                                        string id     = "";
                                                        string name   = "";
                                                        string type   = "";
                                                        string link   = "";
                                                        string source = "";
                                                        foreach (KeyValuePair <string, object> kvp in obj as IDictionary <string, object> )
                                                        {
                                                            switch (kvp.Key)
                                                            {
                                                            case "id":
                                                                id = kvp.Value.ToString();
                                                                break;

                                                            case "name":
                                                                name = kvp.Value.ToString();
                                                                break;

                                                            case "type":
                                                                type = kvp.Value.ToString();
                                                                break;

                                                            case "link":
                                                                link = kvp.Value.ToString();
                                                                break;

                                                            case "source":
                                                                source = kvp.Value.ToString();
                                                                break;
                                                            }
                                                        }
                                                        if (type == "folder")
                                                        {
                                                            rootfolders.Add(new OneDriveFolder("root", id, name, link));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    sb.AppendLine(ex.Message);
                                    richTextStatus.Text = sb.ToString();
                                    richTextStatus.Refresh();
                                    if (nerrors++ > 20)
                                    {
                                        SetStateReady();
                                        return;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                bool found = false;
                                foreach (OneDriveFolder f in rootfolders)
                                {
                                    if (f.name == root)
                                    {
                                        parents.Add(root, f.id);
                                        rootfolder = f;
                                        rootpath   = f.id;
                                        found      = true;
                                        break;
                                    }
                                }
                                if (found == false)
                                {
                                    rootfolder = null;
                                }
                            }
                        }

                        if (rootfolder == null)
                        {
                            sb.AppendLine(string.Format("Root folder not found: {0}", rootpath));
                            richTextStatus.Text = sb.ToString();
                            richTextStatus.Refresh();
                            continue;
                        }

                        //folder.a645bfc91d3b795a.A645BFC91D3B795A!41650/files //Sample path (using id)
                        //https://onedrive.live.com/redir?resid=A645BFC91D3B795A!41650&authkey=!ABx2Nb-uPkoa7RA&ithint=folder%2ctxt //Sample link
                        try
                        {
                            LiveOperationResult result = await this.liveConnectClient.GetAsync(string.Format("{0}/files", rootfolder.id));

                            if (result != null && result.Result != null && result.Result["data"] != null)
                            {
                                foreach (KeyValuePair <string, object> o in result.Result)
                                {
                                    if (bstop == true)
                                    {
                                        bstop = false;
                                        sb.AppendLine("Stopped by user");
                                        richTextStatus.Text = sb.ToString();
                                        richTextStatus.Refresh();
                                        SetStateReady();
                                        return;
                                    }
                                    if (o.Key == "data")
                                    {
                                        if (o.Value != null && o.Value is List <object> )
                                        {
                                            foreach (object obj in o.Value as List <object> )
                                            {
                                                string id     = "";
                                                string name   = "";
                                                string type   = "";
                                                string link   = "";
                                                string source = "";
                                                foreach (KeyValuePair <string, object> kvp in obj as IDictionary <string, object> )
                                                {
                                                    switch (kvp.Key)
                                                    {
                                                    case "id":
                                                        id = kvp.Value.ToString();
                                                        break;

                                                    case "name":
                                                        name = kvp.Value.ToString();
                                                        break;

                                                    case "type":
                                                        type = kvp.Value.ToString();
                                                        break;

                                                    case "link":
                                                        link = kvp.Value.ToString();
                                                        break;

                                                    case "source":
                                                        source = kvp.Value.ToString();
                                                        break;
                                                    }
                                                }
                                                if (type == "file")
                                                {
                                                    if (name.ToLower().Trim() == thefile.ToLower().Trim())
                                                    {
                                                        string ic = string.Format("Item {0} of {1} -> {2}", nitems, titems, name);
                                                        richTextStatus.Text = sb.ToString() + ic;
                                                        richTextStatus.Refresh();
                                                        LiveOperationResult resultlink = null;
                                                        for (int i = 0; i < 3; i++)
                                                        {
                                                            try
                                                            {
                                                                resultlink = await this.liveConnectClient.GetAsync(string.Format("{0}/shared_read_link", id));

                                                                if (resultlink != null && resultlink.RawResult != null && resultlink.RawResult.Length > 0)
                                                                {
                                                                    break;
                                                                }
                                                                else
                                                                {
                                                                    Thread.Sleep(5000);
                                                                }
                                                            }
                                                            catch (Exception ex)
                                                            {
                                                                MessageBox.Show(ex.Message, "Navigation failed - will try to continue");
                                                                Thread.Sleep(5000);
                                                            }
                                                        }
                                                        if (resultlink != null && resultlink.RawResult != null && resultlink.RawResult.Length > 0)
                                                        {
                                                            string ilink = "link\": ";
                                                            string raw   = resultlink.RawResult.Trim();
                                                            int    iof   = raw.IndexOf(ilink);
                                                            if (iof > 0)
                                                            {
                                                                iof += ilink.Length + 1;
                                                                int end = raw.LastIndexOf('"');
                                                                if (end > 0 && end > iof)
                                                                {
                                                                    item.Link  = raw.Substring(iof, end - iof);
                                                                    item.isnew = true;
                                                                }
                                                                else
                                                                {
                                                                    MessageBox.Show("Operation will continue", "Unexpected start/end result");
                                                                }
                                                            }
                                                            else
                                                            {
                                                                MessageBox.Show("Operation will continue", "Unexpected parsing result");
                                                            }
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Received an error. " + ex.Message);
                        }
                        finally
                        {
                            signinButton.Enabled  = true;
                            signOutButton.Enabled = true;
                            //btnCreateMap.Enabled = true;
                            //txtRoot.Enabled = true;
                        }
                    }
                }
            }
            SetTimer(WriteLinks);
        }