Esempio n. 1
0
        public virtual IEnumerable <IEnumerable <FileDesc> > ListFiles(Func <bool> stop, uint retry_times = 1)
        {
            stop.Should().NotBeNull();
            retry_times.Should().BeGreaterOrEqualTo(1);

            // 这个示例单独使用了一个Settings类,其中包含AccessKey和SecretKey
            // 实际应用中,请自行设置您的AccessKey和SecretKey
            string marker    = string.Empty; // 首次请求时marker必须为空
            string prefix    = null;         // 按文件名前缀保留搜索结果
            string delimiter = null;         // 目录分割字符(比如"/")
            var    limit     = 512;          // 单次列举数量限制(最大值为1000)
            var    bm        = new BucketManager(this._mac);
            var    retry     = Policy.Handle <Exception>().Retry((int)retry_times);

            do
            {
                var data = retry.Execute(() =>
                {
                    var res = bm.ListFiles(this._option.QiniuBucketName, prefix, marker, limit, delimiter);

                    res.ThrowIfException();

                    //获取新的游标
                    marker = res.Result.Marker;

                    return(res.Result.Items);
                });

                if (data?.Any() ?? false)
                {
                    yield return(data);
                }
            } while (!string.IsNullOrEmpty(marker) && !stop.Invoke());
        }
Esempio n. 2
0
        /// <summary>
        /// 获取空间文件列表
        /// </summary>
        public static void listFiles()
        {
            Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);

            string bucket    = "test";
            string marker    = "";   // 首次请求时marker必须为空
            string prefix    = null; // 按文件名前缀保留搜索结果
            string delimiter = null; // 目录分割字符(比如"/")
            int    limit     = 100;  // 单次列举数量限制(最大值为1000)

            BucketManager bm = new BucketManager(mac);

            List <FileDesc> items          = new List <FileDesc>();
            List <string>   commonPrefixes = new List <string>();

            do
            {
                var result = bm.ListFiles(bucket, prefix, marker, limit, delimiter);

                Console.WriteLine(result);
                marker = result.Result.Marker;
            } while (!string.IsNullOrEmpty(marker));

            //foreach (string cp in commonPrefixes)
            //{
            //    Console.WriteLine(cp);
            //}

            //foreach(var item in items)
            //{
            //    Console.WriteLine(item.Key);
            //}
        }
        public async Task ListBucketTest()
        {
            var config = new Config {
                Zone = Zone.ZoneCnEast
            };
            var mac           = new Mac(AccessKey, SecretKey);
            var bucketManager = new BucketManager(mac, config);
            var prefix        = "";
            var delimiter     = "";
            var limit         = 100;
            var marker        = "";

            do
            {
                var listRet = await bucketManager.ListFiles(Bucket, prefix, marker, limit, delimiter);

                if (listRet.Code != (int)HttpCode.OK)
                {
                    Assert.True(false, "list files error: " + listRet);
                }

                Console.WriteLine(listRet.ToString());

                marker = listRet.Result.Marker;
            } while (!string.IsNullOrEmpty(marker));
        }
        public void ListBucketTest()
        {
            Config config = new Config();

            config.Zone = Zone.ZONE_CN_East;
            //config.Region = Region.Region_CN_East;
            Mac           mac           = new Mac(AccessKey, SecretKey);
            BucketManager bucketManager = new BucketManager(mac, config);
            string        prefix        = "";
            string        delimiter     = "";
            int           limit         = 100;
            string        marker        = "";

            do
            {
                ListResult listRet = bucketManager.ListFiles(Bucket, prefix, marker, limit, delimiter);
                if (listRet.Code != (int)HttpCode.OK)
                {
                    Assert.Fail("list files error: " + listRet.ToString());
                }
                Console.WriteLine(listRet.ToString());

                marker = listRet.Result.Marker;
            } while (!string.IsNullOrEmpty(marker));
        }
        public void ListFilesTest()
        {
            Mac           mac    = new Mac(AccessKey, SecretKey);
            BucketManager target = new BucketManager(mac);

            HttpResult result = target.ListFiles(Bucket1, null, null, 100, null);

            Assert.AreEqual((int)HttpCode.OK, result.Code);
        }
Esempio n. 6
0
        //获取服务器版本名称
        private string getVersionName()
        {
            try
            {
                CdnRefresh();

                // 这个示例单独使用了一个Settings类,其中包含AccessKey和SecretKey
                // 实际应用中,请自行设置您的AccessKey和SecretKey
                Mac             mac       = new Mac(AppCode.AK, AppCode.SK);
                string          bucket    = "mydb";
                string          marker    = "";   // 首次请求时marker必须为空
                string          prefix    = null; // 按文件名前缀保留搜索结果
                string          delimiter = null; // 目录分割字符(比如"/")
                int             limit     = 100;  // 单次列举数量限制(最大值为1000)
                BucketManager   bm        = new BucketManager(mac);
                List <FileDesc> items     = new List <FileDesc>();

                ListResult result = bm.ListFiles(bucket, prefix, marker, limit, delimiter);

                JavaScriptSerializer js = new JavaScriptSerializer();

                object obj = js.DeserializeObject(result.Text);
                Dictionary <string, object> jd = (obj as Dictionary <string, object>);

                object[] dteil = (object[])jd["items"];

                for (int i = 0; i < dteil.Length; i++)
                {
                    Dictionary <string, object> li = dteil[i] as Dictionary <string, object>;

                    FileDesc fd = new FileDesc();
                    fd.Key      = li["key"].ToString();
                    fd.Fsize    = (int)li["fsize"];
                    fd.Hash     = li["hash"].ToString();
                    fd.MimeType = li["mimeType"].ToString();
                    fd.PutTime  = (long)li["putTime"];
                    items.Add(fd);
                }

                for (int i = 0; i < items.Count; i++)
                {
                    //判断名称里是否包含 Version  例:Version0
                    if (items[i].Key.IndexOf("version") >= 0)
                    {
                        return(items[i].Key);
                    }
                }

                return("");
            }
            catch (Exception ep)
            {
                return("");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 根据前缀获得文件列表
        /// </summary>
        /// <param name="prefix">指定前缀,只有资源名匹配该前缀的资源会被列出</param>
        /// <param name="marker">上一次列举返回的位置标记,作为本次列举的起点信息</param>
        /// <returns></returns>
        public static CloudFile List(string prefix = "case", string marker = "")
        {
            var model = new CloudFile();

            try
            {
                Mac mac = new Mac(Ak, Sk);
                // 设置存储区域

                Config config = new Config()
                {
                    Zone     = Zone.ZONE_CN_East,
                    UseHttps = true
                };
                //Config.SetZone(ZoneID.CN_North, false);
                BucketManager bucketManager = new BucketManager(mac, config);
                // 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)
                string delimiter = "";
                // 本次列举的条目数,范围为1-1000
                int limit = 20;
                prefix = BasePath + prefix;
                ListResult listRet = bucketManager.ListFiles(Bucket, prefix, marker, limit, delimiter);
                model.Code = listRet.Code;
                model.Page = listRet.Result.Marker;
                if (model.Code != 200)
                {
                    model.Message = listRet.Text;
                }
                if (listRet.Code == (int)HttpCode.OK)
                {
                    var list = new List <ListInfo>();
                    foreach (var item in listRet.Result.Items)
                    {
                        list.Add(new ListInfo
                        {
                            Name = domain + item.Key,
                            Size = item.Fsize,
                            Type = item.MimeType,
                            Time = Convert.ToDateTime(item.PutTime)
                        });
                    }
                    model.list = list;
                }
            }
            catch (Exception ex)
            {
                model.Code    = 500;
                model.Message = ex.Message;
            }
            return(model);
        }
Esempio n. 8
0
        /// <summary>
        /// 根据前缀获得文件列表
        /// </summary>
        /// <param name="prefix">指定前缀,只有资源名匹配该前缀的资源会被列出</param>
        /// <param name="marker">上一次列举返回的位置标记,作为本次列举的起点信息</param>
        /// <returns></returns>
        public ListResult List(string prefix = "case", string marker = "")
        {
            Mac mac = new Mac(Ak, Sk);

            // 设置存储区域
            Config.SetZone(ZoneID.CN_South, false);
            BucketManager bucketManager = new BucketManager(mac);
            // 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)
            string delimiter = "";
            // 本次列举的条目数,范围为1-1000
            int limit = 20;

            prefix = BasePath + prefix;
            ListResult listRet = bucketManager.ListFiles(Bucket, prefix, marker, limit, delimiter);

            if (listRet.Code != 200)
            {
                throw new FriendlyException(listRet.Text);
            }
            return(listRet);
        }
Esempio n. 9
0
        public static async Task <ListInfo> GetFiles(
            string bucketName,
            string marker    = null,
            string prefix    = null,
            int limit        = 100,
            string delimiter = null)
        {
#if MOCK
            var result = new ListInfo
            {
                Items = new List <ListItem>()
            };

            for (int i = 0; i < 50; i++)
            {
                var newItem = new ListItem
                {
                    FileType = 0,
                    Fsize    = 1000000 + i,
                    Key      = i + ".png",
                    MimeType = "image/png",
                    PutTime  = 1526952740
                };

                result.Items.Add(newItem);
            }

            return(result);
#else
            var bucketManager = new BucketManager(_currentMac, _config);
            var queryResult   = await Task.Factory.StartNew(() =>
                                                            bucketManager.ListFiles(bucketName, prefix, marker, limit, delimiter));

            return(queryResult.Result);
#endif
        }
Esempio n. 10
0
        //检测版本
        private string CheckVersion()
        {
            try
            {
                CdnRefresh();

                // 这个示例单独使用了一个Settings类,其中包含AccessKey和SecretKey
                // 实际应用中,请自行设置您的AccessKey和SecretKey


                Mac             mac       = new Mac(AppCode.AK, AppCode.SK);
                string          bucket    = "mydb";
                string          marker    = "";   // 首次请求时marker必须为空
                string          prefix    = null; // 按文件名前缀保留搜索结果
                string          delimiter = null; // 目录分割字符(比如"/")
                int             limit     = 100;  // 单次列举数量限制(最大值为1000)
                BucketManager   bm        = new BucketManager(mac);
                List <FileDesc> items     = new List <FileDesc>();

                ListResult result = bm.ListFiles(bucket, prefix, marker, limit, delimiter);


                JavaScriptSerializer js = new JavaScriptSerializer();

                object obj = js.DeserializeObject(result.Text);
                Dictionary <string, object> jd = (obj as Dictionary <string, object>);

                object[] dteil = (object[])jd["items"];

                for (int i = 0; i < dteil.Length; i++)
                {
                    Dictionary <string, object> li = dteil[i] as Dictionary <string, object>;

                    FileDesc fd = new FileDesc();
                    fd.Key      = li["key"].ToString();
                    fd.Fsize    = (int)li["fsize"];
                    fd.Hash     = li["hash"].ToString();
                    fd.MimeType = li["mimeType"].ToString();
                    fd.PutTime  = (long)li["putTime"];
                    items.Add(fd);
                }

                for (int i = 0; i < items.Count; i++)
                {
                    //判断名称里是否包含 Version  例:Version0
                    if (items[i].Key.IndexOf("version") >= 0)
                    {
                        string Version = items[i].Key.Substring(7);
                        Version = Version.Substring(0, Version.Length - 4);

                        int dbversion = dal.ExecuteInt("Select VersionID From Version");
                        if (Convert.ToInt32(Version) > dbversion)
                        {
                            //需更新版本
                            // DownLoadSQLite();
                            return("需更新版本");
                        }
                        else if (Convert.ToInt32(Version) == dbversion)
                        {
                            //最新版本
                            //Alert("");
                            return("最新版本");
                        }
                        else if (Convert.ToInt32(Version) < dbversion)
                        {
                            //Alert("");
                            return("请上传版本");
                        }
                    }
                }
                return("出现异常,不该访问到的代码!");
            }
            catch (Exception ep)
            {
                return(ep.Message);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 查询
        /// </summary>
        private void Search()
        {
            if (string.IsNullOrWhiteSpace(marker))
            {
                num = 1;
                btnSearch.Content = "查询";
            }
            else
            {
                btnSearch.Content = "加载更多";
            }
            bucket = SyncTargetBucketsComboBox.Text;
            ListResult listResult = bucketManager.ListFiles(bucket, txtStartWith.Text, marker, 1000, "");

            // DomainsResult domainsResult = bucketManager.Domains(SyncTargetBucketsComboBox.Text);
            domainsResult = bucketManager.Domains(bucket);

            if (listResult.Result.Items.Count >= 1000)
            {
                btnSearch.Content = "加载更多";
            }
            else
            {
                num               = 1;
                marker            = "";
                btnSearch.Content = "查询";
            }

            if (qiNiuFileInfoList == null || num == 1)
            {
                qiNiuFileInfoList = new List <QiNiuFileInfo>();
            }



            foreach (ListItem item in listResult.Result.Items)
            {
                // item.EndUser
                QiNiuFileInfo f = new QiNiuFileInfo
                {
                    Num         = num,
                    FileName    = item.Key,
                    FileType    = item.MimeType,
                    StorageType = QiNiuHelper.GetStorageType(item.FileType),
                    FileSize    = QiNiuHelper.GetFileSize(item.Fsize),
                    EndUser     = item.EndUser,
                    CreateDate  = QiNiuHelper.GetDataTime(item.PutTime)
                };
                qiNiuFileInfoList.Add(f);
                num++;
            }
            marker = listResult.Result.Marker;


            if (qiNiuFileInfoList.Count > 0)
            {
                dgResult.ItemsSource = !string.IsNullOrWhiteSpace(txtEndWith.Text)
                    ? qiNiuFileInfoList.Where(f => f.FileName.EndsWith(txtEndWith.Text.Trim()))
                    : qiNiuFileInfoList;
            }
            else
            {
                dgResult.ItemsSource = new List <QiNiuFileInfo>();
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 查询
        /// </summary>
        private void Search()
        {
            if (btnSearch.IsEnabled == false)
            {
                return;
            }

            btnSearch.IsEnabled = false;



            if (string.IsNullOrWhiteSpace(marker))
            {
                num = 1;
                qiNiuFileInfoList = new List <QiNiuFileInfo>();
            }

            bucket    = SyncTargetBucketsComboBox.Text;
            startWith = txtStartWith.Text.Trim();
            ThreadPool.QueueUserWorkItem((state) =>
            {
                ListResult listResult = bucketManager.ListFiles(bucket, startWith, marker, 5000, "");
                Dispatcher.Invoke(new Action(() =>
                {
                    if (listResult != null && listResult.Result != null && listResult.Result.Marker != null)
                    {
                        marker = listResult.Result.Marker;
                    }
                    else
                    {
                        marker = string.Empty;
                    }
                    if (listResult?.Result?.Items != null)
                    {
                        foreach (ListItem item in listResult.Result.Items)
                        {
                            // item.EndUser
                            QiNiuFileInfo f = new QiNiuFileInfo
                            {
                                FileName    = item.Key,
                                FileType    = item.MimeType,
                                StorageType = QiNiuHelper.GetStorageType(item.FileType),
                                FileSize    = QiNiuHelper.GetFileSize(item.Fsize),
                                EndUser     = item.EndUser,
                                CreateDate  = QiNiuHelper.GetDataTime(item.PutTime)
                            };
                            qiNiuFileInfoList.Add(f);
                        }

                        if (qiNiuFileInfoList.Count > 0)
                        {
                            //dgResult.ItemsSource = !string.IsNullOrWhiteSpace(txtEndWith.Text)
                            //    ? qiNiuFileInfoList.Where(f => f.FileName.EndsWith(txtEndWith.Text.Trim()))
                            //    : qiNiuFileInfoList;
                            var list = qiNiuFileInfoList;


                            if (!string.IsNullOrWhiteSpace(txtEndWith.Text))
                            {
                                list = qiNiuFileInfoList.Where(f => f.FileName.EndsWith(txtEndWith.Text.Trim())).ToList();
                            }
                            if (list.Count > 0)
                            {
                                // dgResult.ItemsSource = list.OrderBy(t => t.CreateDate).ToList();
                                num  = 1;
                                list = list.OrderByDescending(t => t.CreateDate).ToList();
                                foreach (var s in list)
                                {
                                    s.Num = num++;
                                }
                                dgResult.ItemsSource = list;
                            }
                            else
                            {
                                dgResult.ItemsSource = new List <QiNiuFileInfo>();
                            }
                            //  dgResult.ItemsSource = list;
                        }
                        else
                        {
                            dgResult.ItemsSource = new List <QiNiuFileInfo>();
                        }
                    }
                    else
                    {
                        MessageBox.Show("未能加载数据!");
                    }
                    btnSearch.IsEnabled = true;
                }));
            });
        }
Esempio n. 13
0
        /// <summary>
        /// 获取空间文件列表
        /// </summary>
        public DataTable ListFiles()
        {
            try
            {
                CdnRefresh();

                // 这个示例单独使用了一个Settings类,其中包含AccessKey和SecretKey
                // 实际应用中,请自行设置您的AccessKey和SecretKey
                Mac             mac            = new Mac(AppCode.AK, AppCode.SK);
                string          bucket         = "allfile";
                string          marker         = "";   // 首次请求时marker必须为空
                string          prefix         = null; // 按文件名前缀保留搜索结果
                string          delimiter      = null; // 目录分割字符(比如"/")
                int             limit          = 100;  // 单次列举数量限制(最大值为1000)
                BucketManager   bm             = new BucketManager(mac);
                List <FileDesc> items          = new List <FileDesc>();
                List <string>   commonPrefixes = new List <string>();
                do
                {
                    ListResult result = bm.ListFiles(bucket, prefix, marker, limit, delimiter);
                    Console.WriteLine(result);
                    marker = result.Result.Marker;
                    if (result.Result.Items != null)
                    {
                        items.AddRange(result.Result.Items);
                    }
                    if (result.Result.CommonPrefixes != null)
                    {
                        commonPrefixes.AddRange(result.Result.CommonPrefixes);
                    }
                } while (!string.IsNullOrEmpty(marker));

                foreach (string cp in commonPrefixes)
                {
                    Console.WriteLine(cp);
                }
                foreach (var item in items)
                {
                    Console.WriteLine(item.Key);
                }

                DataTable dt = new DataTable();
                dt.TableName = "Notes";
                dt.Columns.Add("FileName");
                dt.Columns.Add("FileSize");

                for (int i = 0; i < items.Count; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr["FileName"] = items[i].Key;
                    long   size = items[i].Fsize / 1000;
                    string FS   = size > 1000 ? (size / 1000).ToString() + "MB" : size + "KB";
                    dr["FileSize"] = FS;
                    dt.Rows.Add(dr);
                }
                return(dt);
            }
            catch (Exception ep)
            {
                return(null);
            }
        }