Exemplo n.º 1
0
        void getDirInfo(string remoteDir, string localDir)
        {
            //Console.WriteLine(remoteDir);
            ArrayList     remoteFile = yunfile.readDir(remoteDir);
            DirectoryInfo localFile  = new DirectoryInfo(localDir);

            checkDir.Text = remoteDir;
            checkDir.Refresh();
            TaskbarManager.Instance.SetProgressValue(progressBar1.Value, progressBar1.Maximum);
            if (!localFile.Exists)
            {
                Directory.CreateDirectory(localFile.FullName);
            }
            foreach (FolderItem file in remoteFile)
            {
                switch (file.filetype)
                {
                case "F":
                {
                    getDirInfo(remoteDir + "/" + file.filename, localDir + "\\" + file.filename);
                    break;
                }

                case "N":
                {
                    checkFile.Text = file.filename;
                    checkFile.Refresh();
                    if (File.Exists(localDir + "\\" + file.filename))
                    {
                        if (file.size != (new FileInfo(localDir + "\\" + file.filename).Length))
                        {
                            downFile.Text = "正在下载" + file.filename;
                            downFile.Refresh();
                            byte[]     newfile    = yunfile.readFile(remoteDir + "/" + file.filename);
                            FileStream filewriter = new FileStream(localDir + "\\" + file.filename, FileMode.Create);
                            filewriter.Write(newfile, 0, newfile.Length);
                            filewriter.Close();
                            downFile.Text = "";

                            //Console.WriteLine(remoteDir + "/" + file.filename + " " + file.number);
                        }
                        //Console.WriteLine(remoteDir + "/" + file.filename + " " + file.number);
                    }
                    else
                    {
                        downFile.Text = "正在下载" + file.filename;
                        downFile.Refresh();
                        byte[]     newfile    = yunfile.readFile(remoteDir + "/" + file.filename);
                        FileStream filewriter = new FileStream(localDir + "\\" + file.filename, FileMode.Create);
                        filewriter.Write(newfile, 0, newfile.Length);
                        filewriter.Close();
                        downFile.Text = "";
                    }
                    progressBar1.Value += 1;
                    TaskbarManager.Instance.SetProgressValue(progressBar1.Value, progressBar1.Maximum);
                    break;
                }
                }
            }
        }
Exemplo n.º 2
0
        public void LoadListView(ListView listView, ImageList imageList, string remotePath)
        {
            if (upYun == null)
            {
                return;
            }
            Cursor.Current = Cursors.WaitCursor;
            List <FolderItem> itemsArray = new List <FolderItem>();

            try { itemsArray = upYun.readDir(remotePath).Cast <FolderItem>().ToList(); }
            catch { } // UpYun SDK BUG: 调用readDir方法时,如果该目录下没有任何文件或目录,会有数组越界的问题
            try
            {
                ListView.ListViewItemCollection listViewItems = listView.Items;
                int    imageIndex  = 0;
                string programPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                ImageList.ImageCollection imageItems = imageList.Images;
                listViewItems.Clear(); imageItems.Clear();
                if (!remotePath.Equals("/"))
                {
                    string[] itemInfo = new string[4];
                    itemInfo[0] = "上级目录";
                    itemInfo[3] = "ParentDir";
                    ListViewItem parentDirItem = new ListViewItem(itemInfo, 0);
                    listViewItems.Add(parentDirItem);
                    imageItems.Add(StaticFileUpload.Business.Properties.Resources.up_16x16);
                    imageIndex++;
                }
                imageItems.Add(IconUtil.GetDirectoryIcon(programPath));
                imageIndex++;
                foreach (FolderItem item in itemsArray)
                {
                    ListViewItem listViewItem = null;
                    string[]     itemInfo     = new string[4];
                    itemInfo[0] = item.filename;
                    itemInfo[1] = SFUCommon.GetCommonSize(item.size);
                    itemInfo[2] = SFUCommon.GetCommonTime(item.number).ToString();
                    if (item.filetype.Equals("N"))
                    {
                        itemInfo[3]  = "N";
                        listViewItem = new ListViewItem(itemInfo, imageIndex);
                        imageItems.Add(IconUtil.GetFileIcon(item.filename, false));
                        imageIndex++;
                    }
                    else
                    {
                        itemInfo[3]  = "F";
                        listViewItem = new ListViewItem(itemInfo, remotePath.Equals("/") ? 0 : 1);
                    }
                    listViewItems.Add(listViewItem);
                }
            }
            catch (Exception ex)
            {
                SFULogger.DEFAULT.Error(ex);
                throw;
            }
            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 3
0
        public void UpYunTest()
        {
            WebSiteConfig postgreSQLConfig = ConfigManager.GetPostgreSQLConfig();
            UpYun         upyun            = new UpYun(postgreSQLConfig.upyunBucket, postgreSQLConfig.upyunUsername, postgreSQLConfig.upyunPassword);
            ArrayList     str = upyun.readDir("/");

            foreach (var item in str)
            {
                Console.WriteLine(item);
            }
        }