Example #1
0
 public KeePassQiniu.KeePassQiniuExt.UploadError UploadLocal(string name, string dbfile, out string tips) {
     Init();
     System.Net.IWebProxy webProxy = null;
     if(KeePassQiniu.KeePassQiniuConfig.Default.UseProxy) {
         webProxy = new System.Net.WebProxy(KeePassQiniu.KeePassQiniuConfig.Default.ProxyUrl, true);
     }
     // bak first
     if(KeePassQiniu.KeePassQiniuConfig.Default.AutoBackup) {
         MyRSClient moveclient = new MyRSClient();
         CallRet moveret = moveclient.Move(new EntryPathPair(KeePassQiniu.KeePassQiniuConfig.Default.QiniuBucket, name, "backup_" + System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ffff") + "_" + name));
         if(!moveret.OK) {
             tips = moveret.Response;
             return KeePassQiniuExt.UploadError.AUTOBAK_ERROR;
         }
     }
     // upload
     var policy = new PutPolicy(KeePassQiniu.KeePassQiniuConfig.Default.QiniuBucket);
     string upToken = policy.Token();
     PutExtra extra = new PutExtra();
     IOClient client = new IOClient();
     client.Proxy = webProxy;
     PutRet uploadret = client.PutFile(upToken, name, dbfile, extra);
     if(!uploadret.OK) {
         tips = uploadret.Response;
         return KeePassQiniuExt.UploadError.UPLOAD_ERROR;
     }
     tips = string.Empty;
     return KeePassQiniuExt.UploadError.OK;
 }
Example #2
0
        public void PutFileTest()
        {
            IOClient target = new IOClient();
            string key = NewKey;
            PrintLn (key);
            PutExtra extra = new PutExtra (); // TODO: 初始化为适当的值
            extra.MimeType = "text/plain";
            extra.Crc32 = 123;
            extra.CheckCrc = CheckCrcType.CHECK;
            extra.Params = new System.Collections.Generic.Dictionary<string, string> ();
            PutPolicy put = new PutPolicy (Bucket);
            TmpFIle file = new TmpFIle (1024 * 10);
            target.PutFinished += new EventHandler<PutRet> ((o,e) => {
                file.Del ();
                if (e.OK) {
                    RSHelper.RSDel (Bucket, file.FileName);
                }
            });

            PutRet ret = target.PutFile (put.Token (), file.FileName, file.FileName, extra);

            //error params
            //target.PutFile("error", "error", "error", null);
            Assert.IsTrue (ret.OK, "PutFileTest Failure");
        }
Example #3
0
 /// <summary>
 /// 普通上传文件
 /// </summary>
 /// <param name="bucket"></param>
 /// <param name="key">utf-8 编码</param>
 /// <param name="fname"></param>
 public static void PutFile(string bucket, string key, string fname)
 {
     var policy = new PutPolicy(bucket, 3600);
     string upToken = policy.Token();
     PutExtra extra = new PutExtra();
     IOClient client = new IOClient();
     client.PutFile(upToken, key, fname, extra);
 }
Example #4
0
 public static bool PutFile(string key, string fname)
 {
     var policy = new PutPolicy(bucket, 3600);
     string upToken = policy.Token();
     PutExtra extra = new PutExtra();
     IOClient client = new IOClient();
     var putFile = client.PutFile(upToken, key, fname, extra);
     return putFile.OK;
 }
Example #5
0
 /// <summary>
 ///     普通上传
 /// </summary>
 /// <param name="fname">文件本地路径</param>
 /// <param name="bucket">空间名称</param>
 /// <param name="key">文件key</param>
 /// <returns>key</returns>
 public string PutFile(string fname, string bucket = "", string key = "")
 {
     if (bucket == "")
     {
         bucket = BUCKET;
     }
     var policy = new PutPolicy(bucket, 3600);
     var upToken = policy.Token();
     var extra = new PutExtra();
     var client = new IOClient();
     var ret = client.PutFile(upToken, key, fname, extra);
     if (ret != null)
     {
         return ret.key;
     }
     return "";
 }
        public static void Backup()
        {
            var policy = new PutPolicy(Bucket, 3600);
             string upToken = policy.Token();
             PutExtra extra = new PutExtra();
             IOClient client = new IOClient();

             string name = "db_" + System.Environment.MachineName + "_" +
                 Roo.Utils.StringBuilderHelper.GenerateStringID() + ".dbb";

             PutRet ret = client.PutFile(upToken, name, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "/CleanerData/db.db", extra);

             //WebRequest request = WebRequest.Create(Server + "/DataBackup/Backup?store=" + System.Environment.MachineName + "&name=" + name);
             //WebResponse response = request.GetResponse();
             //StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
             //string json = reader.ReadToEnd();
             //BackUpInfo info = Roo.Data.DataConverter.JsonToObject<BackUpInfo>(json);
             //response.Close();
        }
Example #7
0
        /// <summary>
        /// 上传文件,普通上传(PutFile)
        /// </summary>
        /// <param name="bucket_name">设置上传的空间</param>
        /// <param name="local_file_path">上传文件的路径</param>
        /// <param name="ext"></param>
        public static string Upload(string bucket_name, string local_file_path, string ext)
        {
            IOClient iOClient = new IOClient();
            PutExtra extra = new PutExtra();

            //普通上传,只需要设置上传的空间名就可以了,第二个参数可以设定token过期时间
            PutPolicy putPolicy = new PutPolicy(bucket_name, 3600);

            //设置上传的文件的key值
            string key = Guid.NewGuid().ToString("N") + "." + ext;

            //调用Token()方法生成上传的Token
            string upToken = putPolicy.Token();

            //调用PutFile()方法上传
            PutRet putRet = iOClient.PutFile(upToken, key, local_file_path, extra);

            //打印出相应的信息
            string result;
            if (putRet == null)
            {
                result = null;
            }
            else
            {
                if (putRet.OK)
                {
                    result = key;
                }
                else
                {
                    result = null;
                }
            }
            return result;
        }
Example #8
0
 /// <summary>
 /// 上传本地文件
 /// </summary>
 /// <param name="bucket"></param>
 /// <param name="key"></param>
 /// <param name="fname"></param>
 /// <param name="putFinished">上传完成事件</param>
 public static void PutFile(string bucket, string key, string fname, EventHandler<PutRet> putFinished = null)
 {
     var policy = new PutPolicy(bucket, 3600);
     string upToken = policy.Token();
     PutExtra extra = new PutExtra();
     IOClient client = new IOClient();
     if (putFinished != null)
         client.PutFinished += putFinished;
     client.PutFile(upToken, key, fname, extra);
 }
        private void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                open.FileName = "";
                open.ShowDialog();
                if (string.IsNullOrEmpty(open.FileName) || !File.Exists(open.FileName))
                    return;
                var policy = new PutPolicy(Runtime.Bucket, 3600);
                string upToken = policy.Token();
                PutExtra extra = new PutExtra();
                IOClient client = new IOClient();

                string name = "db_" + System.Environment.MachineName + "_" +
                    Roo.Utils.StringBuilderHelper.GenerateStringID() + ".dbb";

                PutRet ret = client.PutFile(upToken, name, open.FileName, extra);
            }
            catch(Exception ex)
            {
                MessageBox.Show("操作失败!" + ex.Message + ex.StackTrace);
            }
        }
Example #10
0
        public bool UploadAttachment(string key)
        {
            Config.Init();
            IOClient target = new IOClient();
            PutExtra extra = new PutExtra();
            //设置上传的空间
            String bucket = System.Configuration.ConfigurationManager.AppSettings["QN-Bucket"] ?? "zngc-intfactory";

            //普通上传,只需要设置上传的空间名就可以了,第二个参数可以设定token过期时间
            PutPolicy put = new PutPolicy(bucket, 3600);

            //调用Token()方法生成上传的Token
            string upToken = put.Token();
            //上传文件的路径
            String filePath = "";

            //调用PutFile()方法上传
            PutRet ret = target.PutFile(upToken, key, filePath, extra);


            return ret.OK;
        }
Example #11
0
        public FileStat Upload(string filepath, bool isOverlay = false, string newname = "")
        {
            // 由外部检查获取成功与否
            filepath.Trim();

            if (false == File.Exists(filepath))
                throw new Exception("Error: Upload failed. File not Exists");

            if (newname == "")
                newname = getFilenameFromPath(filepath);

            PutPolicy put;
            IOClient target = new IOClient();
            PutExtra extra = new PutExtra();
            Entry entry = null;

            // 判断是否覆盖上传
            if(isOverlay && GetFileInfo(newname, out entry))
            {
                //覆盖上传,<bucket>:<key>,表示只允许用户上传指定key的文件。在这种格式下文件默认允许“修改”,已存在同名资源则会被本次覆盖。
                put = new PutPolicy(m_qiniuconf.bucketname + ":" + newname, 3600);
            }
            else if(!GetFileInfo(newname, out entry))
            {
                put = new PutPolicy(m_qiniuconf.bucketname, 3600);
            }
            else
            {
                return null;
            }

            // 调用Token()方法生成上传的Token
            string upToken = put.Token();

            // 调用PutFile()方法上传
            PutRet ret = target.PutFile(upToken, newname, filepath, extra);

            // 获取文件上传信息
            GetFileInfo(newname, out entry);

            FileStat file_stat;
            ConverEntryToFileStat(ref entry, out file_stat);

            file_stat.name = newname;

            return file_stat;
        }
Example #12
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="key">文件名称</param>
        /// <param name="fname">本地文件名称</param>
        /// <param name="rewrite">是否覆盖</param>
        private void PutFile(string key, string fname, bool rewrite = false)
        {
            string scope = mBucket;
            if (rewrite)
                scope += ":" + key;

            string upToken = new PutPolicy(scope).Token();
            IOClient client = new IOClient();
            client.PutFinished += (o, ret) =>
            {
                mPutRet = ret;
                mIsDonePut = true;
            };
            client.PutFile(upToken, key, fname, null);
        }
Example #13
0
 public bool PutFile(string key, string file)
 {
     PutPolicy policy = new PutPolicy(Bucket);
     string upToken = policy.Token();
     PutExtra extra = new PutExtra();
     IOClient client = new IOClient();
     PutRet ret = client.PutFile(upToken, key, file, extra);
     if(ret.OK)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #14
0
        /// <summary>
        /// 上传文件测试
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="key"></param>
        /// <param name="fname"></param>
        public static void PutFile(string bucket, string key, string fname)
        {
            PutPolicy policy = new PutPolicy(bucket);
            string upToken = policy.Token();
            PutExtra extra = new PutExtra();
            IOClient client = new IOClient();
            PutRet ret = client.PutFile(upToken, key, fname, extra);
            if(ret.OK)
            {

            }
        }
        public bool UploadAttachment(string key,string filePath)
        {
            IOClient target = new IOClient();
            PutExtra extra = new PutExtra();
            //设置上传的空间
            String bucket = "zngc-intfactory";

            //普通上传,只需要设置上传的空间名就可以了,第二个参数可以设定token过期时间
            PutPolicy put = new PutPolicy(bucket + ":" + key, 3600);

            //调用Token()方法生成上传的Token
            string upToken = put.Token();

            filePath = Server.MapPath(filePath);
            //调用PutFile()方法上传
            PutRet ret = target.PutFile(upToken, key, filePath, extra);


            return ret.OK;
        }