RS Fetch
Inheritance: Qiniu.Auth.QiniuAuthClient
Example #1
0
        public static DumpRet GetUEditorFileUploadToday()
        {
            var policy = new PutPolicy(bucket, 3600);
            RSFClient client = new RSFClient(bucket);

            var picColl = client.ListPrefix(bucket, "", "");
            return picColl;
        }
Example #2
0
        public void ListPrefixTest()
        {
            RSFClient target = new RSFClient (Bucket); // TODO: 初始化为适当的值
            target.Marker = string.Empty;
            target.Prefix = "csharp";
            target.Limit = 3;
            DumpRet actual;
            actual = target.ListPrefix (Bucket);
            foreach (DumpItem item in actual.Items) {
                Console.WriteLine ("Key:{0},Hash:{1},Mime:{2},PutTime:{3},EndUser:{4}", item.Key, item.Hash, item.Mime, item.PutTime, item.EndUser);
            }

            //error params
            Assert.IsTrue (actual.Items.Count >= 3, "ListPrefixTest Failure");
        }
 void Bind()
 {
     RSFClient rsf = new RSFClient(Runtime.Bucket);
     rsf.Prefix = this.txtPrefix.Text;
     DumpRet ret = rsf.ListPrefix(Runtime.Bucket);
     Dictionary<DateTime, DumpItem> dic = new Dictionary<DateTime, DumpItem>();
     foreach(var item in ret.Items)
     {
         dic.Add(new DateTime(item.PutTime), item);
     }
     List<DumpItem> list = new List<DumpItem>();
     var temp = dic.OrderBy(item => item.Key).Reverse().ToList();
     foreach(var item in temp)
     {
         list.Add(item.Value);
     }
     lv.Bind(list);
     RenderLV();
 }
Example #4
0
        static void Main(string[] args)
        {
            while(true)
            {
                var current = Console.ReadLine();
                //list <bucket>
                //download <bucket> <key>
                string[] lineDatas = current.Split(' ');
                switch(lineDatas[0])
                {
                    case "list":
                        RSFClient rsf = new RSFClient(lineDatas[1]);
                        DumpRet ret = rsf.ListPrefix(lineDatas[1]);
                        if(ret!=null)
                            foreach (var item in ret.Items)
                            {

                            }
                        break;
                }
            }
        }
Example #5
0
        private void btnCreateFetchFile_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtSourceAK.Text) ||
                String.IsNullOrWhiteSpace(txtSourceSK.Text) ||
                String.IsNullOrWhiteSpace(txtSourceBucket.Text) ||
                String.IsNullOrWhiteSpace(txtSourceDomain.Text))
            {
                MessageBox.Show("Please fill-in source AK, SK, Bucket and Domain!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string sourceFileName = txtSourceBucket.Text.Trim() + "_files.txt";
            string logFileName = txtSourceBucket.Text.Trim() + ".log";

            try
            {
                this.Enabled = false;
                this.Cursor = Cursors.WaitCursor;
                SetQiniuSourceKeies();
                RSFClient rsfClient = new RSFClient(txtSourceBucket.Text.Trim());

                using (FileStream file = File.Create(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, sourceFileName)))
                {
                    StreamWriter logFileStream = File.CreateText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, logFileName));
                    List<DumpItem> items;

                    while ((items = rsfClient.Next()) != null)
                    {
                        items.ForEach((DumpItem item) =>
                        {
                            string fileUrl = GetPolicy.MakeBaseUrl(txtSourceDomain.Text.Trim(), item.Key);
                            string downloadUrl = chkPrivateBucket.Checked
                                ? GetPolicy.MakeRequest(fileUrl, 12 * 60 * 60)
                                : fileUrl;

                            if (item.Key.StartsWith("m3u8_") || item.Key.EndsWith(".m3u"))
                            {
                                /*
                                 * Special process for m3u8 files.
                                 * Replace domain.
                                 */
                                int m3uTryCount = 5;

                                while (m3uTryCount > 0)
                                {
                                    try
                                    {
                                        m3uTryCount--;
                                        var request = HttpWebRequest.Create(downloadUrl) as HttpWebRequest;
                                        request.Method = "GET";

                                        var response = request.GetResponse() as HttpWebResponse;
                                        string responseContent;

                                        using (Stream responseStream = response.GetResponseStream())
                                        {
                                            var streamReader = new StreamReader(responseStream);
                                            responseContent = streamReader.ReadToEnd();
                                            responseStream.Close();
                                            responseContent =
                                                responseContent.Replace("http://" + txtSourceDomain.Text.Trim(),
                                                    string.Empty);
                                        }

                                        MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(responseContent));
                                        SetQiniuDestKeies(); // Change Thread's Qiniu keies to Destination.

                                        var putPolicy = new PutPolicy(txtDestBacket.Text.Trim(), 12 * 60 * 60);
                                        string token = putPolicy.Token();
                                        var extra = new PutExtra();
                                        var ioClient = new IOClient();
                                        var putRet = ioClient.Put(token, item.Key, memoryStream, extra);
                                        memoryStream.Close();
                                        memoryStream.Dispose();

                                        if (putRet.StatusCode != HttpStatusCode.OK)
                                        {
                                            if (m3uTryCount > 0)
                                            {
                                                logFileStream.WriteLine(String.Format("Try process m3u8: {0}[{1}]", item.Key, m3uTryCount));
                                            }
                                            else
                                            {
                                                logFileStream.WriteLine("File upload failed:" + item.Key);
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }

                                SetQiniuSourceKeies(); // Change back Thread's Qiniu keys to Source.
                            }
                            else
                            {

                                byte[] fileKey =
                                    Encoding.UTF8.GetBytes(downloadUrl + "\t" + item.Key + Environment.NewLine);
                                file.Write(fileKey, 0, fileKey.Length);
                            }
                        });
                    }

                    logFileStream.Flush();
                    logFileStream.Close();
                    logFileStream.Dispose();

                    file.Flush();
                    file.Close();
                    file.Dispose();
                }
            }
            finally
            {
                MessageBox.Show(
                    "Source file [" + sourceFileName + "] created." +
                        Environment.NewLine + "\t1. Please look into the log file[" + logFileName + "] to check if all of the M3U8 files have been uploaded to destination bucket!" +
                        Environment.NewLine + "\t2. Please fill-in destination information and then to generate batch file!",
                    "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Enabled = true;
                this.ResetCursor();
            }
        }
Example #6
0
        public List<string> getFilesWithPrefix(string prefix)
        {

            List<string> filelist = new List<string>();
            RSFClient client = new RSFClient(m_qiniuconf.bucketname);
            DumpRet files = client.ListPrefix(m_qiniuconf.bucketname, prefix);
            
            foreach(var i in files.Items)
            {
                filelist.Add(i.Key);
            }
            return filelist;
        }
Example #7
0
        // 全局更新检查线程
        private void GlobalUpdateCheck()
        {
            // 检查更新
            RedrawStatusText("正在检查更新...");

            try
            {
                WebClient wb = new WebClient { Proxy = null };
                wb.Headers.Add("Cache-Control", "no-cache");
                var dict =
                    JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(
                        wb.DownloadString("https://raw.github.com/Unknwon/qiniudrive/master/VERSION.json"));
                if (UPDATE_VERSION < (int)dict["version"])
                {
                    CharmMessageBox msgbox = new CharmMessageBox();
                    DialogResult result = msgbox.Show("尊敬的用户您好:\n\n" +
                        "感谢您使用 " + APP_NAME + ",更高版本已经发布。\n\n" +
                        "为了获得更好的用户体验,建议您立即更新!\n\n" +
                        "请到 github.com/Unknwon/qiniudrive 获取最新下载地址。\n\n" +
                        "或单击 是 自动跳转到下载页面。",
                        "版本升级", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                        Process.Start(dict["download_url"]);
                }
            }
            catch (Exception e)
            {
                CharmMessageBox msgbox = new CharmMessageBox();
                msgbox.Show("检查更新失败:\n\n" +
                            e.Message,
                            "错误提示", MessageBoxButtons.OK, CharmMessageBoxIcon.Error);
            }

            // 初始化七牛服务
            mRsfClient = new RSFClient(mBucket);
            mRsClient = new RSClient();
            mServerFileList = new List<SyncFile>();
            mLocalFileList = new List<SyncFile>();
            mLocalFileCache = new List<string>();
            mChangeFileList = new List<ChangeFile>();

            // 检查授权及其它设置
            VerifyAuth();
            RedrawStatusText("正在连接服务器...");

            mIsUpdateChecked = true;

            int count = 0;

            while (true)
            {
            #if(!DEBUG)
            //内存释放
                Process proc = Process.GetCurrentProcess();
                proc.MaxWorkingSet = Process.GetCurrentProcess().MaxWorkingSet;
                proc.Dispose();
            #endif
                if (((mSyncCycle != 0 && count % mSyncCycle == 0) || mIsSyncNow) &&
                    mIsVaildKeys && mIsVaildBucket && mIsVaildSyncDir)
                {
                    count = 0;
                    mIsSyncing = true;
                    Sync();
                    mIsSyncNow = false;
                    mIsSyncing = false;
                    mServerFileList.Clear();
                    mLocalFileList.Clear();
                }

                // 检查是否需要验证授权
                if (mIsNeedVerifyAuth)
                {
                    mIsNeedVerifyAuth = false;
                    VerifyAuth();
                    RedrawStatusText("等待同步");
                }

                count++;
                Thread.Sleep(1000);
            }
            // ReSharper disable once FunctionNeverReturns
        }