Esempio n. 1
0
        public async Task <string> GetContentDataAsync()
        {
            string data     = "";
            string MainNode = Convert.ToString(((Repository)lstRepos.Items[lstRepos.SelectedIndex]).Name);

            treeNode.Text = MainNode;
            IReadOnlyList <RepositoryContent> lstFiles = await GetChildNodeAsync();

            RepsCont <RepositoryContent> con = new RepsCont <RepositoryContent>();

            if (lstFiles != null)
            {
                label8.Visible = false;
                foreach (RepositoryContent content in lstFiles)
                {
                    if (treeView1.SelectedNode.Text == content.Name)
                    {
                        WebClient webClient = new WebClient();
                        byte[]    Fulldata  = webClient.DownloadData(content.DownloadUrl);
                        if (Fulldata.Length > 0)
                        {
                            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                            data = enc.GetString(Fulldata);
                            SaveFileDialog save = new SaveFileDialog();
                            save.FileName = content.Name;
                            save.Filter   = "Text File | *.txt";
                            if (save.ShowDialog() == DialogResult.OK)
                            {
                                StreamWriter writer = new StreamWriter(save.OpenFile());
                                writer.Write(data);
                                writer.Dispose();
                                writer.Close();
                            }
                        }
                    }
                }
            }


            return("");
        }
Esempio n. 2
0
        private async void lstRepos_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadTreeStructure();
            treeView1.Show();

            try
            {
                string MainNode = Convert.ToString(((Repository)lstRepos.Items[lstRepos.SelectedIndex]).Name);
                treeNode.Text = MainNode;
                IReadOnlyList <RepositoryContent> lstFiles = await GetChildNodeAsync();

                if (lstFiles != null)
                {
                    treeView1.ImageList = imageList1;
                    RepsCont <RepositoryContent> con = new RepsCont <RepositoryContent>();
                    label8.Visible = false;
                    treeView1.Name = (lstRepos.SelectedValue.ToString());
                    foreach (RepositoryContent content in lstFiles)
                    {
                        if (content.Type == "file")
                        {
                            treeView1.Nodes.Add(content.Name);
                            treeView1.ImageIndex = 3;
                        }
                        if (content.Type == "Dir" || content.Type == "dir")
                        {
                            Repository objRepo  = ((Repository)lstRepos.SelectedItem);
                            var        contents = await client.Repository.Content.GetAllContents(objRepo.Id, content.Path);

                            TreeNode ParentNode = new TreeNode(content.Name);
                            ParentNode.ImageIndex = 2;
                            foreach (RepositoryContent s in contents)
                            {
                                //ParentNode.ImageIndex = 1;
                                if (s.Type == "Dir" || s.Type == "dir")
                                {
                                    var Subdata = await client.Repository.Content.GetAllContents(objRepo.Id, s.Path);

                                    TreeNode SubdataNode = new TreeNode(s.Name);
                                    SubdataNode.ImageIndex = 2;
                                    foreach (RepositoryContent subContent in Subdata)
                                    {
                                        SubdataNode.Nodes.Add(subContent.Name);
                                    }
                                    ParentNode.Nodes.Add(SubdataNode);
                                }
                                else
                                {
                                    //ParentNode.Nodes.Add(s.Name);
                                    TreeNode SubdataNode = new TreeNode(s.Name);
                                    SubdataNode.ImageIndex = 3;
                                    ParentNode.Nodes.Add(SubdataNode);
                                }
                            }
                            treeView1.Nodes.Add(ParentNode);
                        }
                    }
                }
            }
            catch (Exception ece)
            {
                label8.Visible   = true;
                label8.ForeColor = Color.Red;
            }
        }