Esempio n. 1
0
        /// <summary>
        /// 创建文件夹
        /// </summary>
        /// <param name="directory">文件夹</param>
        public void MakeDirectory(string directory)
        {
            FtpWebRequest  request  = null;
            FtpWebResponse response = null;

            try
            {
                request             = FtpWebRequest.Create(ftpSite + directory) as FtpWebRequest;
                request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
                request.KeepAlive   = false;
                request.Method      = WebRequestMethods.Ftp.MakeDirectory;

                response = request.GetResponse() as FtpWebResponse;
            }

            catch (Exception exception)
            {
                DatabaseAssistant.ReportException(exception);
            }

            finally
            {
                if (request != null)
                {
                    request.Abort();
                }
                if (response != null)
                {
                    response.Close();
                }
            }
        }
        /// <summary>
        /// 执行SQL文本
        /// </summary>
        /// <param name="resultProcess">执行结果处理</param>
        /// <param name="address">地址</param>
        /// <param name="port">端口</param>
        /// <param name="charSet">字符集</param>
        /// <param name="database">数据库</param>
        /// <param name="userId">用户</param>
        /// <param name="password">密码</param>
        /// <param name="sqlText">SQL文本</param>
        /// <param name="parameter">参数</param>
        /// <returns>是否成功</returns>
        public static bool Execute(Action <MySql.Data.MySqlClient.MySqlDataReader> resultProcess, string address, string port, string charSet, string database, string userId, string password, string sqlText, params object[] parameter)
        {
            return(DatabaseAssistant.DoExecute
                   (
                       () =>
            {
                MySql.Data.MySqlClient.MySqlDataReader reader = command.ExecuteReader();
                int n = reader.FieldCount;

                try
                {
                    resultProcess(reader);
                }

                catch (Exception exception)
                {
                    DatabaseAssistant.ReportException(exception);
                }

                reader.Close();
            },
                       string.Format(DatabaseAssistant.ConnectionText, address, port, charSet, database, userId, password),
                       sqlText,
                       parameter
                   ));
        }
        /// <summary>
        /// 发送走马灯
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="server">服务器</param>
        /// <param name="content">走马灯内容</param>
        /// <param name="reportProcess">报告处理</param>
        /// <returns>是否成功</returns>
        public static bool SendCommand(string user, Server server, string content, Action <string> reportProcess)
        {
            HttpWebRequest  request = null;
            HttpWebResponse respone = null;

            try
            {
                request = WebRequest.Create(server.GmAddress) as HttpWebRequest;
                request.Headers["svr"] = server.Id;
                request.Headers["uid"] = "0";
                request.Headers["cmd"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(content));
                request.Timeout        = 1000;

                respone = request.GetResponse() as HttpWebResponse;

                if (reportProcess != null)
                {
                    using (StreamReader reader = new StreamReader(respone.GetResponseStream()))
                    {
                        string text = reader.ReadToEnd();

                        if (text != null && text != "")
                        {
                            reportProcess(text);
                        }
                        else
                        {
                            reportProcess(TableManager.GetGMTText(391));
                        }
                    }
                }
                Log.AddRecord(user, string.Format("{0}\r\n{1}\r\n成功", server.Name, content));
                return(true);
            }

            catch (Exception exception)
            {
                DatabaseAssistant.ReportException(exception);
                Log.AddRecord(user, string.Format("{0}\r\n{1}\r\n失败", server.Name, content));
                return(false);
            }

            finally
            {
                if (request != null)
                {
                    request.Abort();
                }
                if (respone != null)
                {
                    respone.Close();
                }
            }
        }
Esempio n. 4
0
        internal static bool ExecuteGmCommand(STServerInfo server, string playerId, byte[] command, byte[] operate, bool needReturn, Action <string> reportProcess)
        {
            if (server == null)
            {
                return(false);
            }

            HttpWebRequest  request = null;
            HttpWebResponse respone = null;

            try
            {
                request                = WebRequest.Create(server.authGMHttp) as HttpWebRequest;
                request.KeepAlive      = false;
                request.Headers["svr"] = server.svrID;
                request.Headers["uid"] = playerId;
                request.Headers["cmd"] = Convert.ToBase64String(command);
                request.Headers["opt"] = Convert.ToBase64String(operate);
                request.Timeout        = 4000;

                respone = request.GetResponse() as HttpWebResponse;
                if (needReturn && reportProcess != null)
                {
                    using (StreamReader reader = new StreamReader(respone.GetResponseStream()))
                    {
                        reportProcess(reader.ReadToEnd());
                    }
                }
                return(true);
            }

            catch (Exception exception)
            {
                DatabaseAssistant.ReportException(exception);
                if (reportProcess != null)
                {
                    reportProcess(exception.Message + "\n");
                }
                return(false);
            }

            finally
            {
                if (request != null)
                {
                    request.Abort();
                }
                if (respone != null)
                {
                    respone.Close();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="file">文件名</param>
        /// <param name="buffer">缓冲区</param>
        /// <returns>是否成功</returns>
        public bool Upload(string file, byte[] buffer)
        {
            FtpWebRequest request = null;
            Stream        stream  = null;

            try
            {
                request               = FtpWebRequest.Create(ftpSite + file) as FtpWebRequest;
                request.Credentials   = new NetworkCredential(ftpUser, ftpPassword);
                request.KeepAlive     = false;
                request.Method        = WebRequestMethods.Ftp.UploadFile;
                request.UseBinary     = true;
                request.ContentLength = FTP.WriteLength;

                stream = request.GetRequestStream();

                for (int i = 0; i < buffer.Length; i += FTP.WriteLength)
                {
                    stream.Write
                    (
                        buffer,
                        i,
                        Math.Min(FTP.WriteLength, buffer.Length - i)
                    );
                }

                stream.Close();
                stream = null;

                return(true);
            }

            catch (Exception exception)
            {
                DatabaseAssistant.ReportException(exception);
                return(false);
            }

            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
                if (request != null)
                {
                    request.Abort();
                }
            }
        }
        /// <summary>
        /// 执行SQL文本
        /// </summary>
        /// <param name="executeProcess">执行处理</param>
        /// <param name="connectionText">连接文本</param>
        /// <param name="sqlText">SQL文本</param>
        /// <param name="parameter">参数</param>
        /// <returns>是否成功</returns>
        private static bool DoExecute(Action executeProcess, string connectionText, string sqlText, params object[] parameter)
        {
            lock (DatabaseAssistant.connection)
            {
                try
                {
                    if (!DatabaseAssistant.IsConnected() || DatabaseAssistant.connection.ConnectionString != connectionText)
                    {
                        if (DatabaseAssistant.IsConnected())
                        {
                            DatabaseAssistant.connection.Close();
                        }
                        DatabaseAssistant.connection.ConnectionString = connectionText;
                        DatabaseAssistant.connection.Open();
                    }

                    DatabaseAssistant.command.CommandText = parameter != null?string.Format(sqlText, parameter) : sqlText;

                    DatabaseAssistant.command.CommandTimeout = 3600;

                    executeProcess();

                    return(true);
                }

                catch (Exception exception)
                {
                    if (DatabaseAssistant.IsConnected())
                    {
                        DatabaseAssistant.ReportException(exception);
                    }

                    return(false);
                }

                finally
                {
                    if (DatabaseAssistant.IsConnected())
                    {
                        DatabaseAssistant.connection.Clone();
                    }
                }
            }
        }
        protected void rechargeButton_Click(object sender, EventArgs e)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create("http://192.168.1.26:8081/bill") as HttpWebRequest;

                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded";

                byte[] byteArray = Encoding.UTF8.GetBytes("pushInfo=order:测试orderPushInfo&receipt=eyJhcmVhTmFtZSI6IiAiLCJjaGFubmVsSWQiOiIyMDAxIiwiZ29vZHNOdW1iZXIiOiIxIiwidXNlcmlkIjoiNjkyMDAxMTA0NDQ4NDAxIiwiZ29vZHNQcmljZSI6MjQwMCwicm9sZU5hbWUiOiIgIiwiZ29vZHNSZWdpc3RlcklkIjoiNzU2NzgwMDciLCJhcHBEYXRlIjoiMjAxNTA3MjAxMTMzMzYiLCJvcmRlcklkIjoiMTAwMDAwMDE2NDE2NzMzNiIsImFyZWFJZCI6IjEtMTUtNi0xIiwicm9sZUlkIjoiMTAwMDIifQ%3D%3D&sign=38313c03b8d6e62dc7e879543e183252");
                request.ContentLength = byteArray.Length;
                Stream newStream = request.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                newStream.Close();

                HttpWebResponse respone = request.GetResponse() as HttpWebResponse;
                //using (StreamReader reader = new StreamReader(respone.GetResponseStream()))
                //{
                //	string text = reader.ReadToEnd();

                //	if (text != null && text != "")
                //	{
                //		this.errorLabel.Text += text;
                //	}
                //	else
                //	{
                //		this.errorLabel.Text += "返回的是空";
                //	}
                //}
            }

            catch (Exception exception)
            {
                DatabaseAssistant.ReportException(exception);
                this.errorLabel.Text += exception.ToString();
            }
        }
        protected void rechargeButton_Click(object sender, EventArgs e)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create("http://192.168.1.26:8081/bill") as HttpWebRequest;

                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded";

                byte[] byteArray = Encoding.UTF8.GetBytes("pushInfo=order:测试orderPushInfo&receipt=eyJhcmVhTmFtZSI6IiAiLCJjaGFubmVsSWQiOiIzMDUwIiwiZ29vZHNOdW1iZXIiOiI2MCIsInVzZXJpZCI6IjcxMzA1MDM5Mjg2OCIsImdvb2RzUHJpY2UiOjYsInJvbGVOYW1lIjoiICIsImdvb2RzUmVnaXN0ZXJJZCI6Ijg1Njc4MDAyIiwiYXBwRGF0ZSI6IjIwMTUwNDEzMDE1NzA2Iiwib3JkZXJJZCI6IjE1MDQxMzAxNTYzNzM0MjEyNyIsImFyZWFJZCI6IjUtMS02LTEiLCJyb2xlSWQiOiI0MzM2NiJ9&sign=31153d9089c07d739c6afe3900c93376");
                request.ContentLength = byteArray.Length;
                Stream newStream = request.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                newStream.Close();

                HttpWebResponse respone = request.GetResponse() as HttpWebResponse;
                using (StreamReader reader = new StreamReader(respone.GetResponseStream()))
                {
                    string text = reader.ReadToEnd();

                    if (text != null && text != "")
                    {
                        this.errorLabel.Text += text;
                    }
                    else
                    {
                        this.errorLabel.Text += TableManager.GetGMTText(391);
                    }
                }
            }

            catch (Exception exception)
            {
                DatabaseAssistant.ReportException(exception);
                this.errorLabel.Text += exception.ToString();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 下载
        /// </summary>
        /// <param name="file">文件名</param>
        /// <returns>缓冲区</returns>
        /// 返回数据长度
        //public int Download(string file, out byte[] buffer)
        //{
        //    buffer = null;
        //    int length = this.FileSize(file);
        //    if (length < 0) { return 0; }

        //    FtpWebRequest	request		= null;
        //    FtpWebResponse	response	= null;
        //    Stream			stream		= null;

        //    try
        //    {
        //        request = FtpWebRequest.Create(ftpSite + file) as FtpWebRequest;
        //        request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
        //        request.KeepAlive = false;
        //        request.Method = WebRequestMethods.Ftp.DownloadFile;
        //        request.UseBinary = true;

        //        response = request.GetResponse() as FtpWebResponse;
        //        stream = response.GetResponseStream();

        //        buffer = new byte[length];
        //        stream.Read(buffer, 0, buffer.Length);

        //        return buffer.Length;
        //    }

        //    catch (Exception exception)
        //    {
        //        DatabaseAssistant.ReportException(exception);
        //        return 0;
        //    }

        //    finally
        //    {
        //        if (stream != null) { stream.Close(); }
        //        if (response != null) { response.Close(); }
        //        if (request != null) { request.Abort(); }
        //    }
        //}

        /// <summary>
        /// 文件尺寸
        /// </summary>
        /// <param name="file">文件名</param>
        /// <returns>尺寸</returns>
        public int FileSize(string file)
        {
            FtpWebRequest  request  = null;
            FtpWebResponse response = null;

            try
            {
                request             = FtpWebRequest.Create(ftpSite + file) as FtpWebRequest;
                request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
                request.KeepAlive   = false;
                request.Method      = WebRequestMethods.Ftp.GetFileSize;
                request.UseBinary   = true;

                response = request.GetResponse() as FtpWebResponse;

                return((int)response.ContentLength);
            }

            catch (Exception exception)
            {
                DatabaseAssistant.ReportException(exception);
                return(-1);
            }

            finally
            {
                if (response != null)
                {
                    response.Close();
                }
                if (request != null)
                {
                    request.Abort();
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// 出现未处理的错误
 /// </summary>
 protected void Application_Error(object sender, EventArgs e)
 {
     DatabaseAssistant.ReportException(Server.GetLastError());
     //Server.ClearError();
 }