Example #1
0
        /**
         * 读取文件
         * @param $file 文件路径(包含文件名)
         * @param $output_file 可传递文件IO数据流(默认为 null,结果返回文件内容,如设置文件数据流,将返回 true or false)
         * return 文件内容 或 null
         */
        public byte[] readFile(string path, SetProgressBar setprogressbar)
        {
            Hashtable headers = new Hashtable();

            byte[] a = null;

            HttpWebResponse resp = newWorker("GET", DL + this.bucketname + path, a, headers, null);
            StreamReader    sr   = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);
            BinaryReader    br   = new BinaryReader(sr.BaseStream);

            byte[] by = new byte[1024 * 1024 * 10];
            //byte[] by = br.ReadBytes(1024 * 1024 * 100); /// 又拍云存储最大文件限制 100Mb,对于普通用户可以改写该值,以减少内存消耗
            int DownloadNum = by.Length / 5000;

            System.Threading.Timer FileTm = new System.Threading.Timer(CalculateSpeedTime, null, 0, 1000);
            for (int i = 0; i <= DownloadNum; i++)
            {
                if (i == DownloadNum)
                {
                    by            = by.Concat(br.ReadBytes(by.Length - i * 5000)).ToArray();
                    TempDataSize += by.Length - i * 5000;
                }
                else
                {
                    by            = by.Concat(br.ReadBytes(5000)).ToArray();
                    TempDataSize += 5000;
                }
                setprogressbar(false, path.Substring(path.LastIndexOf("/") + 1), ((i * 5000) / by.Length) * 100.0, TransSpeed);
            }
            resp.Close();
            return(by);
        }
Example #2
0
 public void SetProgressBarValue(int Value)
 {
     if (this.pBar.InvokeRequired)
     {
         SetProgressBar d = new SetProgressBar(SetProgressBarValue);
         this.Invoke(d, new object[] { Value });
     }
     else
     {
         this.pBar.Value = Value;
     }
 }
Example #3
0
 private void setProgressBar(double percent)
 {
     if (txtAlreadyDown.InvokeRequired)
     {
         SetProgressBar setpb = new SetProgressBar(setProgressBar);
         txtAlreadyDown.Invoke(setpb, new object[] { percent });
     }
     else
     {
         txtAlreadyDown.Text = Convert.ToInt32(percent) + "%";
         progressBar1.Value  = (int)percent + 1;
     }
 }
Example #4
0
        private void _work_Tick(object source, UpdateEventArgs e)
        {
            int val = (int)((e.Percent * 1000) <= 1000 ? e.Percent * 1000 : 1000);

            if (InvokeRequired)
            {
                SetProgressBar spb = new SetProgressBar(UpdateProgressBar);
                Invoke
                    (spb, new object[] { val });
            }
            else
            {
                pbx_Convert.Value = val;
                Invalidate();
            }
        }
Example #5
0
        /**
         * 上传文件
         * @param $file 文件路径(包含文件名)
         * @param $datas 文件内容 或 文件IO数据流
         * return true or false
         */
        public bool writeFile(string path, byte[] data, bool auto_mkdir, SetProgressBar setprogressbar)
        {
            Hashtable headers = new Hashtable();

            this.auto_mkdir = auto_mkdir;
            HttpWebResponse resp;

            resp = newWorker("POST", DL + this.bucketname + path, data, headers, setprogressbar);
            if ((int)resp.StatusCode == 200)
            {
                resp.Close();
                return(true);
            }
            else
            {
                resp.Close();
                return(false);
            }
        }
Example #6
0
        private HttpWebResponse newWorker(string method, string Url, byte[] postData, Hashtable headers, SetProgressBar setprogressbar)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + api_domain + Url);

            //request.Timeout = 1800 * 1000;

            request.Method = method;

            if (this.auto_mkdir == true)
            {
                headers.Add("mkdir", "true");
                this.auto_mkdir = false;
            }

            if (postData != null)
            {
                request.ContentLength = postData.Length;
                request.KeepAlive = true;
                if (this.content_md5 != null)
                {
                    request.Headers.Add("Content-MD5", this.content_md5);
                    this.content_md5 = null;
                }
                if (this.file_secret != null)
                {
                    request.Headers.Add("Content-Secret", this.file_secret);
                    this.file_secret = null;
                }
            }

            if (this.upAuth)
            {
                upyunAuth(headers, method, Url, request);
            }
            else
            {
                request.Headers.Add("Authorization", "Basic " +
                    Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(this.username + ":" + this.password)));
            }
            foreach (DictionaryEntry var in headers)
            {
                request.Headers.Add(var.Key.ToString(), var.Value.ToString());
            }

            if (postData != null)
            {
                int UploadNum = 0;
                Stream dataStream = request.GetRequestStream();
                UploadNum = postData.Length / 5000;
                System.Threading.Timer FileTm = new System.Threading.Timer(CalculateSpeedTime, null, 0, 1000);
                for (int i = 0; i <= UploadNum; i++)
                {
                    if (i == UploadNum)
                    {
                        dataStream.Write(postData, i * 5000, postData.Length - i * 5000);
                        TempDataSize += postData.Length - i * 5000;
                    }
                    else
                    {
                        dataStream.Write(postData, i * 5000, 5000);
                        TempDataSize += 5000;
                    }
                    setprogressbar(true, Url.Substring(Url.LastIndexOf("/") + 1), (i * 5000.0 / postData.Length) * 100.0, TransSpeed);
                }
                //dataStream.Write(postData, 0, postData.Length);
                dataStream.Close();
            }
            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
                this.tmp_infos = new Hashtable();
                foreach (var hl in response.Headers)
                {
                    string name = (string)hl;
                    if (name.Length > 7 && name.Substring(0, 7) == "x-upyun")
                    {
                        this.tmp_infos.Add(name, response.Headers[name]);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return response;
        }
Example #7
0
 /**
 * 上传文件
 * @param $file 文件路径(包含文件名)
 * @param $datas 文件内容 或 文件IO数据流
 * return true or false
 */
 public bool writeFile(string path, byte[] data, bool auto_mkdir, SetProgressBar setprogressbar)
 {
     Hashtable headers = new Hashtable();
     this.auto_mkdir = auto_mkdir;
     HttpWebResponse resp;
     resp = newWorker("POST", DL + this.bucketname + path, data, headers, setprogressbar);
     if ((int)resp.StatusCode == 200)
     {
         resp.Close();
         return true;
     }
     else
     {
         resp.Close();
         return false;
     }
 }
Example #8
0
        /**
        * 读取文件
        * @param $file 文件路径(包含文件名)
        * @param $output_file 可传递文件IO数据流(默认为 null,结果返回文件内容,如设置文件数据流,将返回 true or false)
        * return 文件内容 或 null
        */
        public byte[] readFile(string path, SetProgressBar setprogressbar)
        {
            Hashtable headers = new Hashtable();
            byte[] a = null;

            HttpWebResponse resp = newWorker("GET", DL + this.bucketname + path, a, headers, null);
            StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);
            BinaryReader br = new BinaryReader(sr.BaseStream);
            byte[] by = new byte[1024 * 1024 * 10];
            //byte[] by = br.ReadBytes(1024 * 1024 * 100); /// 又拍云存储最大文件限制 100Mb,对于普通用户可以改写该值,以减少内存消耗
            int DownloadNum = by.Length / 5000;
            System.Threading.Timer FileTm = new System.Threading.Timer(CalculateSpeedTime, null, 0, 1000);
            for (int i = 0; i <= DownloadNum; i++)
            {
                if (i == DownloadNum)
                {
                    by = by.Concat(br.ReadBytes(by.Length - i * 5000)).ToArray();
                    TempDataSize += by.Length - i * 5000;
                }
                else
                {
                    by = by.Concat(br.ReadBytes(5000)).ToArray();
                    TempDataSize += 5000;
                }
                setprogressbar(false, path.Substring(path.LastIndexOf("/") + 1), ((i * 5000) / by.Length) * 100.0, TransSpeed);
            }
            resp.Close();
            return by;
        }
Example #9
0
        public MainVending()
        {
            InitializeComponent();
            enableButton       = new EnableButton(ShowEnableButton);
            setProgressBar     = new SetProgressBar(ShowSetProgressBar);
            setMaxProgressBar  = new SetMaxProgressBar(ShowSetmaxProgressBar);
            setHideProgressBar = new SetHideProgressBar(ShowHideProgressBar);


            bsVending            = new BindingSource();
            bsVending.DataSource = dtVending;

            Tools.AddTable(dtTranDb, dgTran);
            Tools.AddTable(dtAllCards, dgAllCards);
            Tools.AddTable(dtTransaction, dgTransactions);
            Tools.AddTable(dtVending, dgVending);
            Tools.SetDataSource(cmbVending, dtVending);

            Logbook.LogDirCheckCreate();
            Logbook.BeginThreadSaveLog();
            Logbook.FileAppend("Start Vending Service Programm", EventType.Info);

            ListSocketHelper = new List <DbHelper.SocketHelper>();
            ListVendings     = new List <DbHelper.Vending>();

            //AsyncTcpServer asyncTcpServer = new AsyncTcpServer();
            //asyncTcpServer.OnMessage += OnEventMessageServer;

            //ListAsyncTcpServer.Add(asyncTcpServer);

            //asyncTcpServer = new AsyncTcpServer();
            //asyncTcpServer.OnMessage += OnEventMessageServer;
            //asyncTcpClient = new AsyncTcpClient();
            //asyncTcpClient.OnMessage += OnEventMessageClient;

            btnGetVersion.Enabled     = true;
            btnGetProtocol.Enabled    = true;
            btnGetCardinfo.Enabled    = true;
            cmbKindOper.SelectedIndex = 0;
            ReadIni();
            WriteIni();
            Tools.SetConnectionString();

            edUserName.Text = R_Keeper_Login;
            //edVendingPort.Text = VendingPort;
            //edVendingName.Text = VendingName;

            edDbName.Text   = Tools.LocalSQLServerDBName;
            edDbServer.Text = Tools.LocalSQLServerName;
            edDbLogin.Text  = Tools.LocalSQLUserName;

            for (int i = 0; i < ListVendings.Count; i++)
            {
                DbHelper.SocketHelper socketHelper = new DbHelper.SocketHelper(ListVendings[i].Name, ListVendings[i].Port, R_Keeper_RestCode, R_Keeper_UnitNum);

                socketHelper.OnMessage += OnMessage;
                DbHelper.SocketHelper.R_Keeper_BonusTotal = R_Keeper_BonusTotal;

                ListSocketHelper.Add(socketHelper);
            }


            if (LoginWithRun)
            {
                if (RKeeper.RKeeper.InitDialog(R_Keeper_Login, R_Keeper_Password))
                {
                    AppendLog("Login to RKeeper.\n");
                }
                StartServer();
                btnInit.Enabled           = false;
                btnStartServer.Enabled    = false;
                btnGetAllAccounts.Enabled = true;
            }

            btnGetDbConnect.Enabled = false;


            dtOperDate.Value = DateTime.Now;
            dtBegin.Value    = DateTime.Now;
            dtEnd.Value      = DateTime.Now.AddDays(1);
        }
 private void setProgressBar(double percent)
 {
     if(txtAlreadyDown.InvokeRequired)
     {
         SetProgressBar setpb = new SetProgressBar(setProgressBar);
         txtAlreadyDown.Invoke(setpb, new object[] { percent });
     }
     else
     {
         txtAlreadyDown.Text = Convert.ToInt32(percent) + "%";
         progressBar1.Value = (int)percent + 1;
     }
 }
Example #11
0
        private HttpWebResponse newWorker(string method, string Url, byte[] postData, Hashtable headers, SetProgressBar setprogressbar)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + api_domain + Url);

            //request.Timeout = 1800 * 1000;

            request.Method = method;

            if (this.auto_mkdir == true)
            {
                headers.Add("mkdir", "true");
                this.auto_mkdir = false;
            }

            if (postData != null)
            {
                request.ContentLength = postData.Length;
                request.KeepAlive     = true;
                if (this.content_md5 != null)
                {
                    request.Headers.Add("Content-MD5", this.content_md5);
                    this.content_md5 = null;
                }
                if (this.file_secret != null)
                {
                    request.Headers.Add("Content-Secret", this.file_secret);
                    this.file_secret = null;
                }
            }

            if (this.upAuth)
            {
                upyunAuth(headers, method, Url, request);
            }
            else
            {
                request.Headers.Add("Authorization", "Basic " +
                                    Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(this.username + ":" + this.password)));
            }
            foreach (DictionaryEntry var in headers)
            {
                request.Headers.Add(var.Key.ToString(), var.Value.ToString());
            }

            if (postData != null)
            {
                int    UploadNum  = 0;
                Stream dataStream = request.GetRequestStream();
                UploadNum = postData.Length / 5000;
                System.Threading.Timer FileTm = new System.Threading.Timer(CalculateSpeedTime, null, 0, 1000);
                for (int i = 0; i <= UploadNum; i++)
                {
                    if (i == UploadNum)
                    {
                        dataStream.Write(postData, i * 5000, postData.Length - i * 5000);
                        TempDataSize += postData.Length - i * 5000;
                    }
                    else
                    {
                        dataStream.Write(postData, i * 5000, 5000);
                        TempDataSize += 5000;
                    }
                    setprogressbar(true, Url.Substring(Url.LastIndexOf("/") + 1), (i * 5000.0 / postData.Length) * 100.0, TransSpeed);
                }
                //dataStream.Write(postData, 0, postData.Length);
                dataStream.Close();
            }
            HttpWebResponse response;

            try
            {
                response       = (HttpWebResponse)request.GetResponse();
                this.tmp_infos = new Hashtable();
                foreach (var hl in response.Headers)
                {
                    string name = (string)hl;
                    if (name.Length > 7 && name.Substring(0, 7) == "x-upyun")
                    {
                        this.tmp_infos.Add(name, response.Headers[name]);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(response);
        }