// POST: api/CheckFile_Keyword
        public string Post(CheckFile value)
        {
            gnSqlNomal gn = new gnSqlNomal();

            if (value == null)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
            }
            var config = gn.convertConfigToDic(value.config);
            var para   = gn.convertParaToDic(value.para);

            gnCheckFile cf = new gnCheckFile();

            if (para["istype"] == "TreeDefault")
            {
                return(cf.GetDriverDefault());
            }

            if (para["istype"] == "TreeSub")
            {
                return(cf.GetSubFolder(para["id"]));
            }

            if (para["istype"] == "XemTongQuan")
            {
                return(cf.SeartchAllFileHaveWord(para["path"], para["noidung"], para["tungay"], para["toingay"]));
            }

            if (para["istype"] == "XemChiTiet")
            {
                return(cf.ViewInFile(para["path"], para["keyword"]));
            }

            return("[]");
        }
示例#2
0
        // GET: api/Check_CheckAllProcess
        public string Get()
        {
            gnSqlNomal sqln      = new gnSqlNomal();
            general    gn        = new general();
            var        dicAppSet = gn.ReadAppseting();

            if (!dicAppSet.ContainsKey("pathcheckserver"))
            {
                return("{\"status\":\"Không chứa pathcheckserver\"}");
            }

            var strfileInfo = File.ReadAllText(dicAppSet["pathcheckserver"]);
            var dicFileInfo = sqln.convertParaToDic(strfileInfo);

            var str = "";

            foreach (Process p in Process.GetProcesses("."))
            {
                try
                {
                    var name = p.MainWindowTitle != "" ? p.MainWindowTitle : p.ProcessName;

                    str += "{\"name\":\"" + name + "\",\"status\":\"" + (p.Responding ?"Runing":"NotRespond") + "\",\"istype\":\"GetAllProcess\",\"servername\":\"" + dicFileInfo["servername"] + "\"},";
                }
                catch { }
            }
            var sum = str != "" ? str.Substring(0, str.Length - 1) : "";

            return("[" + sum + "]");
        }
示例#3
0
        // POST: api/DocTucThoi_ChecDangDoc
        public string Post(DocTucThoi value)
        {
            try
            {
                Dictionary <string, string> dicAppSet = null;
                if (dicAppSet == null || dicAppSet.Count == 0)
                {
                    general gn = new general();
                    dicAppSet = gn.ReadAppseting();
                    if (dicAppSet == null || dicAppSet.Count == 0)
                    {
                        return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Đọc appsetting lỗi\"}]}");
                    }
                }

                gnSqlNomal sqln        = new gnSqlNomal();
                var        strfileInfo = File.ReadAllText(dicAppSet["dtt_infodoctucthoi"]);
                var        dicFileInfo = sqln.convertParaToDic(strfileInfo);

                var files = Directory.GetFiles(dicFileInfo["dtt_savefiletofolder"]);

                return(files.Length > 0 ? "{\"result\":\"OK\",\"data\":\"Đang trong quá trình đọc tức thời\"}" : "{\"result\":\"OK\",\"data\":\"\"}");
            }catch (Exception ex)
            {
                return("");
            }
        }
示例#4
0
        // POST: api/BulkCopySqlRenameCol
        public string Post(paraExportXml value)
        {
            try
            {
                general gn        = new general();
                var     json      = "";
                var     dicConfig = gn.ConfigConvertToDicConfig(value.config);
                if (dicConfig == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }
                var table = JObject.Parse(value.para);
                if (table == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }

                gnSqlNomal gns  = new gnSqlNomal();
                var        para = gns.convertParaToDic(value.para);
                DataTable  dt   = new DataTable("dt");
                foreach (var val in table)
                {
                    dt = gn.ConvertJsonToDataTable(val.Value.ToString(), val.Key);
                    break;
                }

                gn.ExportTable(dt, dicConfig);
                return(json);
            }
            catch (Exception ex)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}");
            }
        }
示例#5
0
        // GET: api/Check_CheckDrives
        public string Get()
        {
            // Check Ổ đĩa
            var sum = "";

            gnSqlNomal sqln      = new gnSqlNomal();
            general    gn        = new general();
            var        dicAppSet = gn.ReadAppseting();

            if (!dicAppSet.ContainsKey("pathcheckserver"))
            {
                return("{\"status\":\"Không chứa pathcheckserver\"}");
            }

            var strfileInfo = File.ReadAllText(dicAppSet["pathcheckserver"]);
            var dicFileInfo = sqln.convertParaToDic(strfileInfo);


            DriveInfo[] allDrives = DriveInfo.GetDrives();

            var str = "";

            foreach (DriveInfo d in allDrives)
            {
                try
                {
                    str += "{\"driver\":\"" + d.Name.Substring(0, 1) + "\",\"totalfreespace\":\"" + Math.Round(Convert.ToDouble(d.TotalFreeSpace) / 1073741824) + " GB\",\"totalsize\":\"" + Math.Round(Convert.ToDouble(d.TotalSize) / 1073741824) + " GB\",\"istype\":\"CheckDrive\",\"servername\":\"" + dicFileInfo["servername"] + "\"},";
                }
                catch { }
            }

            sum = str != "" ? str.Substring(0, str.Length - 1) : "";

            return("[" + sum + "]");
        }
示例#6
0
        //get All text
        public string getResultAllTextDocTucThoi(string config, string para, Dictionary <string, string> dicAppset)
        {
            try
            {
                gnSqlNomal sqln      = new gnSqlNomal();
                general    gn        = new general();
                var        dicAppSet = gn.ReadAppseting();

                var dicConfig = sqln.convertConfigToDic(config);
                var dicPara   = sqln.convertParaToDic(para);

                var strfileInfo = File.ReadAllText(dicAppSet["dtt_infodoctucthoi"]);
                var dicFileInfo = sqln.convertParaToDic(strfileInfo);

                var fileExists = dicFileInfo["pathwritefilealltext"] + "\\" + dicConfig["namefile"];

                var lines = File.Exists(fileExists) ? File.ReadAllText(fileExists) : "[]";
                // var lines = File.ReadAllText(fileExists);
                return("{\"result\":\"OK\",\"data\":\"" + lines + "\"}");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        // POST: api/Email_SendMail
        public string Post(EmailValue value)
        {
            try
            {
                gnSqlNomal gn        = new gnSqlNomal();
                general    gns       = new general();
                var        dicAppSet = gns.ReadAppseting();

                if (value == null || value.config == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại dữ liệu đầu vào\"}]}");
                }

                var config = gn.convertConfigToDic(value.config);

                var ToEmail   = config["sendtomail"];
                var ToEmailCC = config["sendcctomail"];

                MailMessage mail = new MailMessage();
                mail.From = new MailAddress(dicAppSet["email_guithuc"], config["tenthaythe"]);

                String[] tmp = ToEmail.Split(',');

                foreach (string amail in tmp)
                {
                    if (amail.Length > 0)
                    {
                        mail.To.Add(amail);
                    }
                }
                foreach (string amail in ToEmailCC.Split(','))
                {
                    if (amail.Length > 0)
                    {
                        mail.CC.Add(amail);
                    }
                }

                mail.Subject      = config["chude"].ToString();
                mail.Priority     = MailPriority.High;
                mail.Body         = config["noidung"].ToString();
                mail.ReplyTo      = new MailAddress(dicAppSet["email_guithuc"]);
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                mail.IsBodyHtml   = true;
                SmtpClient mySmtpClient = new SmtpClient();
                mySmtpClient.Host        = dicAppSet["email_smtp"];
                mySmtpClient.Credentials = new System.Net.NetworkCredential(dicAppSet["email_emailsend"], dicAppSet["email_passsend"]);
                mySmtpClient.EnableSsl   = dicAppSet["email_ssl"] == "true" ? true : false;
                mySmtpClient.Port        = Convert.ToInt32(dicAppSet["email_port"]);
                mySmtpClient.Send(mail);

                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Gửi mail thành công\"}]}");
            }
            catch (Exception ex)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message + "\"}]}");
            }
        }
        // POST: api/BulkCopySqlRenameCol
        public string Post(paraBulkTableSqlRename value)
        {
            try
            {
                general gn        = new general();
                var     json      = "";
                var     dicConfig = gn.ConfigConvertToDicConfig(value.config);
                if (dicConfig == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }
                var table = JObject.Parse(value.table);
                if (table == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }

                gnSqlNomal gns  = new gnSqlNomal();
                var        para = gns.convertParaToDic(value.para);
                DataTable  dt   = new DataTable("dt");
                foreach (var val in table)
                {
                    dt = gn.ConvertJsonToDataTable(val.Value.ToString(), val.Key);

                    break;
                }

                // thay doi ten cot
                for (var c = 0; c < dt.Columns.Count; c++)
                {
                    dt.Columns[c].ColumnName = "Col" + c;
                }
                var nextCol = dt.Columns.Count;
                // ADD THEM COT RONG VAO BANG. CHO DU 30 COT
                for (var j = nextCol; j < 50; j++)
                {
                    try
                    {
                        DataColumn myColumn = new DataColumn();
                        myColumn.Caption      = "Col" + j;
                        myColumn.ColumnName   = "Col" + j;
                        myColumn.DefaultValue = "";
                        dt.Columns.Add(myColumn);
                    }
                    catch (Exception ex) { }
                }
                gnSql sql = new gnSql();
                json = sql.BulkCopyToSqlNoLower(dt, dicConfig, para);
                return(json);
            }
            catch (Exception ex)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}");
            }
        }
        // POST api/SqlNomalNoLower
        public string Post(ValueNomal value)
        {
            gnSqlNomal gn = new gnSqlNomal();

            if (value == null || value.config == null)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
            }
            var config = gn.convertConfigToDic(value.config);
            var para   = gn.convertParaToDic(value.para);

            return(gn.ExecuteSqlDatasetNoLower(config, para));
        }
示例#10
0
        // POST: api/TCP_OverServiceTcp
        public string Post(classTcp value)
        {
            try
            {
                gnSqlNomal gn        = new gnSqlNomal();
                general    gns       = new general();
                var        dicAppSet = gns.ReadAppseting();

                if (value == null || value.config == null)
                {
                    return(null);
                }

                var config = gn.convertConfigToDic(value.config);
                var para   = gn.convertParaToDic(value.para);


                var result = "";

                if (para["type"].ToLower() == "checkconnect" || para["type"].ToLower() == "receive")
                {
                    var pathReceive = dicAppSet["pathfoldertcpreceive"] + config["namefile"];
                    if (File.Exists(pathReceive))
                    {
                        var    resultByte = File.ReadAllText(pathReceive).Replace("\r\n", "-0D-0A-");
                        byte[] data       = Array.ConvertAll <string, byte>(resultByte.Substring(0, resultByte.Length - 1).Split('-'), s => Convert.ToByte(s, 16));
                        result = System.Text.ASCIIEncoding.ASCII.GetString(data);
                        File.Delete(pathReceive);
                    }
                    else
                    {
                        return("");
                    }
                }
                else
                {
                    var str = "";
                    foreach (var val in para)
                    {
                        str += val.Value + "\r\n";
                    }
                    File.WriteAllText(dicAppSet["pathfoldertcpsend"] + config["namefile"], str);
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        // POST: api/LayDanhSachFileTrongThuMuc
        public string Post(DanhSachFile value)
        {
            try
            {
                general    gns       = new general();
                gnSqlNomal gn        = new gnSqlNomal();
                var        dicAppSet = gns.ReadAppseting();

                var lst     = new List <string>();
                var folders = gns.GetAllFolder(dicAppSet["hddt_path_downloadfilechuaky_log"]);
                var para    = gn.convertParaToDic(value.para);

                // neu la  thang nam
                var namthangky = "";
                var loai       = "";
                if (para.ContainsKey("namthangky"))
                {
                    namthangky = para["namthangky"];
                }
                if (para.ContainsKey("loai"))
                {
                    loai = para["loai"];
                }
                foreach (var fol in folders)
                {
                    var files = Directory.GetFiles(fol);
                    foreach (var file in files)
                    {
                        if (namthangky != "" && file.ToLower().IndexOf(loai) >= 0 &&
                            file.ToLower().IndexOf(namthangky) >= 0)
                        {
                            var sp   = file.Split('\\');
                            var name = sp[sp.Length - 1];
                            lst.Add(name);
                        }
                        else
                        {
                            var sp   = file.Split('\\');
                            var name = sp[sp.Length - 1];
                            lst.Add(name);
                        }
                    }
                }

                var integers = Newtonsoft.Json.JsonConvert.SerializeObject(lst);
                return(integers);
            }
            catch (Exception ex) { return(ex.Message); }
        }
示例#12
0
        // GET api/excelsqlexcute/5
        public string Get(string id)
        {
            try
            {
                if (id == null || id == "undefind" || id == "")
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại userid\"}]}");
                }

                var     user = id;
                general gn   = new general();
                dicAppSet = gn.ReadAppseting();
                var lst            = JObject.Parse(_dicPara_exsql["StrColumnNames_SqlExcute" + user]).SelectToken("kq").ToString();
                var LstColumnNames = JsonConvert.DeserializeObject <List <ListColumnExport> >(lst);

                if (dicAppSet == null || dicAppSet.Count == 0)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Đọc appsetting lỗi\"}]}");
                }

                gnSqlNomal gns       = new gnSqlNomal();
                var        dicConfig = gns.convertConfigToDic(_dicPara_exsql["StrConfig_SqlExcute" + user]);
                var        dicPara   = gns.convertParaToDic(_dicPara_exsql["StrPara_SqlExcute" + user]);
                _dicPara_exsql.Remove("StrPara_SqlExcute" + user);
                _dicPara_exsql.Remove("StrConfig_SqlExcute" + user);
                _dicPara_exsql.Remove("StrColumnNames_SqlExcute" + user);

                gnSql   sql = new gnSql();
                gnExcel exx = new gnExcel();

                var paraSql = gn.ConvertDicToSqlPara(dicPara);

                var ds = sql.DynamicSelectDataset(dicConfig["namesql"], (paraSql == null ?null: paraSql), CommandType.StoredProcedure, dicAppSet[dicConfig["connstr"].ToLower()]);
                if (ds == null || ds.Tables.Count == 0)
                {
                    return("{\"result\":\"OK\",\"data\":[{\"status\":\"Không có dữ liệu xuất excel\"}]}");
                }
                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    ds.Tables[0].Columns[i].ColumnName = ds.Tables[0].Columns[i].ColumnName.ToLower();
                }
                exx.ExporttoExcel(new List <string>(), ds.Tables[0], LstColumnNames, dicConfig.ContainsKey("namefile") ? dicConfig["namefile"] : "" + DateTime.Now.ToString("dd-MM-yyyy"), 1, false, true);
                return("");
            }
            catch (Exception ex)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}");
            }
        }
        // GET: api/Check_PingServer
        public string Get()
        {
            gnSqlNomal sqln      = new gnSqlNomal();
            general    gn        = new general();
            var        dicAppSet = gn.ReadAppseting();

            if (!dicAppSet.ContainsKey("pathcheckserver"))
            {
                return("{\"status\":\"Không chứa pathcheckserver\"}");
            }

            var strfileInfo = File.ReadAllText(dicAppSet["pathcheckserver"]);
            var dicFileInfo = sqln.convertParaToDic(strfileInfo);

            return("{\"status\":\"OK\",\"istype\":\"PingServer\",\"servername\":\"" + dicFileInfo["servername"] + "\"}");
        }
        // GET: api/Check_CheckNotRepond
        public string Get()
        {
            gnSqlNomal sqln      = new gnSqlNomal();
            general    gn        = new general();
            var        dicAppSet = gn.ReadAppseting();

            if (!dicAppSet.ContainsKey("pathcheckserver"))
            {
                return("{\"status\":\"Không chứa pathcheckserver\"}");
            }

            var strfileInfo = File.ReadAllText(dicAppSet["pathcheckserver"]);
            var dicFileInfo = sqln.convertParaToDic(strfileInfo);

            var dicProcess = new Dictionary <string, string>();

            foreach (Process p in Process.GetProcesses("."))
            {
                try
                {
                    var name = p.MainWindowTitle != "" ? p.MainWindowTitle : p.ProcessName;

                    dicProcess.Add(name.ToLower(), p.Responding ? "Runing" : "NotRespond");
                }
                catch { }
            }

            if (!dicFileInfo.ContainsKey("checklstnotrespond"))
            {
                return("{\"status\":\"Không chứa checklstnotrespond\"}");
            }
            var lstCheck = dicFileInfo["checklstnotrespond"].Split(new string[] { "===" }, StringSplitOptions.None);
            var str      = "";

            foreach (var name in lstCheck)
            {
                if (dicProcess.ContainsKey(name.ToLower()))
                {
                    str += "{\"name\":\"" + name + "\",\"status\":\"" + dicProcess[name.ToLower()] + "\",\"istype\":\"CheckNotRespond\",\"servername\":\"" + dicFileInfo["servername"] + "\"},";
                }
            }

            var sum = str != "" ? str.Substring(0, str.Length - 1) : "";

            return("[" + sum + "]");
        }
示例#15
0
        public FileResult DownloadFileChuaKy()
        {
            var sp = Request.FilePath.Split('/');

            if (sp == null)
            {
                return(null);
            }
            var        fileName  = sp[sp.Length - 1];
            gnSqlNomal gn        = new gnSqlNomal();
            general    gns       = new general();
            var        dicAppSet = gns.ReadAppseting();
            //var filepath =  System.IO.Path.Combine(Server.MapPath("/Files/"), fileName);

            var filepath = dicAppSet["hddt_path_downloadfilechuaky_log"] + fileName;

            return(File(filepath, MimeMapping.GetMimeMapping(filepath), fileName));
        }
示例#16
0
        // GET: api/Check_CheckAllWarningInFolder
        public string Get()
        {
            gnSqlNomal sqln      = new gnSqlNomal();
            general    gn        = new general();
            var        dicAppSet = gn.ReadAppseting();

            if (!dicAppSet.ContainsKey("pathcheckserver"))
            {
                return("{\"status\":\"Không chứa pathcheckserver\"}");
            }

            var strfileInfo = File.ReadAllText(dicAppSet["pathcheckserver"]);
            var dicFileInfo = sqln.convertParaToDic(strfileInfo);

            // lay ra cac file
            var files    = Directory.GetFiles(dicAppSet["pathcontentwarning"]);
            var listFile = new List <string>();

            foreach (var file in files)
            {
                if (file.EndsWith(".json"))
                {
                    listFile.Add(file);
                }
            }

            // lay ra cac noi dung trong tung file
            string json = "";

            foreach (var file in listFile)
            {
                using (StreamReader r = new StreamReader(file))
                {
                    json += r.ReadToEnd();
                }
                json += ",";
                File.Delete(file);
            }

            var sum = json != "" ? json.Substring(0, json.Length - 1) : "";

            return("[" + sum.Replace("\r\n", string.Empty) + "]");
        }
示例#17
0
        // POST: api/Text_ReadFile
        public string Post(readfiletext value)
        {
            try
            {
                if (value == null || value.config == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }
                gnSqlNomal gn     = new gnSqlNomal();
                var        config = gn.convertConfigToDic(value.config);
                File.WriteAllText(config["pathfile"], config["content"]);

                return("{\"result\":\"OK\",\"data\":[{\"status\":\"Tạo file ok\"}]}");
            }
            catch (Exception ex)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message + "\"}]}");
            }
        }
示例#18
0
        // POST: api/BulkCopySql
        public string Post(paraBulkTableSql value)
        {
            try
            {
                general gn        = new general();
                var     dicAppSet = gn.ReadAppseting();
                var     json      = "";
                var     dicConfig = gn.ConfigConvertToDicConfig(value.config);
                if (dicConfig == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }
                var table = JObject.Parse(value.table);
                if (table == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }

                Db_Access ac    = new Db_Access();
                var       check = ac.checkRequertLienTuc(HttpContext.Current, dicAppSet, value.config, "");
                if (!check)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Không cho phép request liên tục\"}]}");
                }

                gnSqlNomal gns  = new gnSqlNomal();
                var        para = gns.convertParaToDic(value.para);

                foreach (var val in table)
                {
                    var   dt  = gn.ConvertJsonToDataTable(val.Value.ToString(), val.Key);
                    gnSql sql = new gnSql();
                    json = sql.BulkCopyToSql(dt, dicConfig, para);
                }
                return(json);
            }
            catch (Exception ex)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}");
            }
        }
        // GET: api/Check_CheckStopSoft
        public string Get()
        {
            gnSqlNomal sqln      = new gnSqlNomal();
            general    gn        = new general();
            var        dicAppSet = gn.ReadAppseting();

            if (!dicAppSet.ContainsKey("pathcheckserver"))
            {
                return("{\"status\":\"Không chứa pathcheckserver\"}");
            }

            var strfileInfo = File.ReadAllText(dicAppSet["pathcheckserver"]);
            var dicFileInfo = sqln.convertParaToDic(strfileInfo);

            List <string> lst = new List <string>();

            Process[] running_processes = Process.GetProcesses();
            foreach (Process proc in running_processes)
            {
                var name = proc.MainWindowTitle != "" ? proc.MainWindowTitle : proc.ProcessName;

                lst.Add(name.ToLower());
            }
            if (!dicFileInfo.ContainsKey("checkstoplstsoft"))
            {
                return("{\"status\":\"Không chứa checkstoplstsoft\"}");
            }
            var lstCheck = dicFileInfo["checkstoplstsoft"].Split(new string[] { "===" }, StringSplitOptions.None);
            var str      = "";

            foreach (var name in lstCheck)
            {
                str += "{\"name\":\"" + name + "\",\"status\":\"" + (lst.Contains(name.ToLower())?"Runing":"Stoped") + "\",\"istype\":\"CheckStopSoft\",\"servername\":\"" + dicFileInfo["servername"] + "\"},";
            }

            var sum = str != "" ? str.Substring(0, str.Length - 1) : "";

            return("[" + sum + "]");
        }
示例#20
0
        public string CheckSqlPing()
        {
            gnSqlNomal sqln      = new gnSqlNomal();
            general    gn        = new general();
            var        dicAppSet = gn.ReadAppseting();

            if (!dicAppSet.ContainsKey("pathcheckserver"))
            {
                return("{\"status\":\"Không chứa pathcheckserver\"}");
            }

            var strfileInfo = File.ReadAllText(dicAppSet["pathcheckserver"]);
            var dicFileInfo = sqln.convertParaToDic(strfileInfo);
            var str         = "";

            foreach (var dir in dicFileInfo)
            {
                if (dir.Key.Contains("pingsqlserver"))
                {
                    var Conn = new SqlConnection(dir.Value);
                    if (Conn.State != ConnectionState.Open)
                    {
                        string ConnGood = "";
                        try {
                            Conn.Open();
                            ConnGood = "OK";
                        }
                        catch (Exception ex) { ConnGood = ex.Message; }
                        str += "{\"pingsqlserver\":\"" + dir.Value.Substring(0, dir.Value.ToUpper().IndexOf("USER ID")) + "\",\"status\":\"" + ConnGood + "\",\"istype\":\"CheckSql\",\"servername\":\"" + dicFileInfo["servername"] + "\"},";
                    }
                }
            }
            var sum = str != "" ? str.Substring(0, str.Length - 1) : "";

            return("[" + sum + "]");
        }
示例#21
0
        // POST api/sqlnomal
        public string Post(ValueNomal value)
        {
            gnSqlNomal gn        = new gnSqlNomal();
            general    gns       = new general();
            var        dicAppSet = gns.ReadAppseting();

            if (value == null || value.config == null)
            {
                return("{\"result\":\"ERROR\",\"data\":\"Kiểm tra lại định dạng json đầu vào\"}");
            }

            Db_Access ac    = new Db_Access();
            var       check = ac.checkRequertLienTuc(HttpContext.Current, dicAppSet, value.config, value.para);

            if (!check)
            {
                return("{\"result\":\"ERROR\",\"data\":\"Không cho phép request liên tục\"}");
            }

            var config = gn.convertConfigToDic(value.config);
            var para   = gn.convertParaToDic(value.para);

            return(gn.ExecuteSqlDataset(config, para));
        }
示例#22
0
        // POST: api/ExportXmlReplaceTemplate
        public string Post(ExportXmlReplace value)
        {
            try
            {
                gnSqlNomal gn        = new gnSqlNomal();
                general    gns       = new general();
                var        dicAppSet = gns.ReadAppseting();

                if (value == null || value.config == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }
                var config = gn.convertConfigToDic(value.config);
                var para   = gn.convertParaToDic(value.para);

                var pathFile = dicAppSet["hddt_path_filetemplate"] + config["namefiletemplate"];
                var mau      = File.ReadAllText(pathFile);
                foreach (var val in para)
                {
                    mau = mau.Replace(val.Key, val.Value);
                }

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(mau);
                var pathExport = dicAppSet["path_saveonserver"] + config["namefilecreate"];
                xmlDoc.Save(pathExport);

                //if (!config.ContainsKey("savefileonserver"))
                //    File.Delete(dicAppSet["path_saveonserver"] + config["namefilecreate"]);

                return("{\"result\":\"ERROR\",\"data\":\"" + pathExport + "\"}");
            }
            catch (Exception ex) {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}");
            }
        }
        // GET: api/DocTucThoiUpdateCmd
        public string Get()
        {
            Dictionary <string, string> dicAppSet = new Dictionary <string, string>();

            try
            {
                general    gn   = new general();
                gnSqlNomal sqln = new gnSqlNomal();
                dicAppSet = gn.ReadAppseting();
                // doc file json
                var strfileInfo = File.ReadAllText(dicAppSet["dtt_infodoctucthoi"]);
                var dicFileInfo = sqln.convertParaToDic(strfileInfo);

                gnDocTucThoi dtt = new gnDocTucThoi();
                dtt.WriterToFileTxt(dicAppSet, dicFileInfo, "nameFile", "NoiDung");

                return(strfileInfo);
            }
            catch (Exception ex)
            {
                general.WriterLogTracking(ex.Message, dicAppSet);
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}");
            }
        }
        // POST: api/DocTucThoi_CheckError
        public string Post(DocTucThoi value)
        {
            try
            {
                Dictionary <string, string> dicAppSet = null;
                Dictionary <string, string> dicProce  = null;
                if (dicAppSet == null || dicAppSet.Count == 0)
                {
                    general gn = new general();
                    dicAppSet = gn.ReadAppseting();
                    if (dicAppSet == null || dicAppSet.Count == 0)
                    {
                        return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Đọc appsetting lỗi\"}]}");
                    }
                }

                if (value == null || value.config == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }
                var json = "";

                gnSqlNomal sqln = new gnSqlNomal();

                var dicConfig = sqln.convertConfigToDic(value.config);
                var dicPara   = sqln.convertParaToDic(value.para);

                var strfileInfo = File.ReadAllText(dicAppSet["dtt_infodoctucthoi"]);
                var dicFileInfo = sqln.convertParaToDic(strfileInfo);

                var fileExists = dicFileInfo["pathwritefilealltext"] + "\\" + dicPara["namefile"];

                var lines = File.Exists(fileExists) ? File.ReadAllLines(fileExists) : null;

                if (lines == null)
                {
                    return("");
                }

                foreach (var line in lines)
                {
                    var sp = line.Split(new string[] { "<==", "==>" }, StringSplitOptions.None);
                    if (line.ToLower().IndexOf("dcu0") >= 0)
                    {
                        return("{\"result\":\"DCU0\",\"data\":\"\"}");

                        break;
                    }
                    if (line.ToLower().IndexOf("stopall") >= 0)
                    {
                        return("{\"result\":\"StopAll\",\"data\":\"" + (sp.Length > 1? sp[1].Replace("(StopAll)", ""):"") + "\"}");

                        break;
                    }
                    if (line.ToLower().IndexOf("readfail") >= 0 && line.ToLower().IndexOf(dicPara["socongto"]) >= 0)
                    {
                        return("{\"result\":\"ReadFail\",\"data\":\"" + dicPara["socongto"] + "\"}");

                        break;
                    }
                    if (line.ToLower().IndexOf("read meter success") >= 0)
                    {
                        return("{\"result\":\"Read Meter Success\",\"data\":\"\"}");

                        break;
                    }
                }

                return("");
            }
            catch (Exception ex)
            {
                return("");
            }
        }
        // POST: api/TCP_SendReceiveByte232
        public string Post(classTcpConnect value)
        {
            try
            {
                Socket     sender = null;
                gnSqlNomal gn     = new gnSqlNomal();
                var        config = gn.convertConfigToDic(value.config);
                var        para   = gn.convertParaToDic(value.para);

                // Data buffer for incoming data.
                byte[] bytes = new byte[1024];

                try
                {
                    IPAddress  ipAddress = IPAddress.Parse(para["ip"]);
                    IPEndPoint remoteEP  = new IPEndPoint(ipAddress, Convert.ToInt32(para["port"]));
                    // Create a TCP/IP  socket.
                    sender = new Socket(AddressFamily.InterNetwork,
                                        SocketType.Stream, ProtocolType.Tcp);
                    // Connect the socket to the remote endpoint. Catch any errors.
                    sender.Connect(remoteEP);
                }
                catch (Exception ex)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message + "\"}]}");
                }
                var v_lenh = config["lenh"];
                try
                {
                    // Send các lệnh connect mặc định
                    sender.Send(Encoding.ASCII.GetBytes("#0000000000000009+CSQ:IFCMASTER#"));
                    Thread.Sleep(500);
                    string imei = config["keysocket"];
                    sender.Send(Encoding.ASCII.GetBytes("@READ" + imei));
                    Thread.Sleep(500);


                    // Send the data through the socket.
                    general gns       = new general();
                    var     sendbyte  = gns.HexToByteArray(config["lenh"]);
                    int     bytesSent = sender.Send(sendbyte);

                    // Tao file log de view
                    try
                    {
                        var    dicAppSet = gns.ReadAppseting();
                        string path      = dicAppSet["pathlogcommandstreetlight"];
                        string filename  = path + config["namefile"] + "_" + DateTime.Now.ToString("ddMMyyHHmmss") + ".txt";
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        if (!File.Exists(filename))
                        {
                            // Create a file to write to.
                            using (StreamWriter sw = File.CreateText(filename))
                            {
                                //sw.WriteLine(para["ip"]);
                                //sw.WriteLine(para["port"]);
                                sw.WriteLine(BitConverter.ToString(sendbyte));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                catch (Exception ex)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message + "\"}]}");
                }

                // Release the socket.
                try
                {
                    // Receive the response from the remote device.
                    var shutdown  = Encoding.ASCII.GetBytes("shutdown");
                    int bytesSent = sender.Send(shutdown);

                    //_dicSocket[config["keysocket"]].Shutdown(SocketShutdown.Both);
                    //_dicSocket[config["keysocket"]].Close();
                    return("{\"result\":\"OK\",\"data\":" + v_lenh + "}");
                }
                catch (Exception ex)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message + "\"}]}");
                }
            }
            catch (Exception ex) { return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message + "\"}]}"); }
        }
示例#26
0
        public string ExcuteDocTucThoi(DocTucThoi value)
        {
            Dictionary <string, string> dicAppSet = new Dictionary <string, string>();

            try
            {
                if (dicAppSet == null || dicAppSet.Count == 0)
                {
                    general gn = new general();
                    dicAppSet = gn.ReadAppseting();
                    if (dicAppSet == null || dicAppSet.Count == 0)
                    {
                        return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Đọc appsetting lỗi\"}]}");
                    }
                }

                if (value == null || value.config == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":\"Kiểm tra lại định dạng json đầu vào\"}");
                }
                //var json = "";

                //gnDocTucThoi orc = new gnDocTucThoi();
                //json = orc.ExcuteDocTucThoi(value.config, value.para, dicAppSet);

                //return json;
            }
            catch (Exception ex)
            { general.WriterLogTracking(ex.Message, dicAppSet); return(""); }

            try
            {
                gnSqlNomal sqln      = new gnSqlNomal();
                var        dicConfig = sqln.convertConfigToDic(value.config);
                var        dicPara   = sqln.convertParaToDic(value.para);

                // doc file json
                var strfileInfo = File.ReadAllText(dicAppSet["dtt_infodoctucthoi"]);
                var dicFileInfo = sqln.convertParaToDic(strfileInfo);

                if (dicPara == null && dicConfig == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":\"Kiểm tra lại định dạng json đầu vào\"}");
                }

                if (!dicPara.ContainsKey("v_imei"))
                {
                    return("{\"result\":\"ERROR\",\"data\":\"Kiểm tra lại định dạng json đầu vào\"}");
                }
                return(SaveFileToFolderFix(dicAppSet, dicFileInfo, dicConfig, dicPara));

                // khong xoa vi tam thoi fix ip / port
                //if (dicFileInfo["dtt_connectto"].ToUpper() == "ORACLE")
                //{
                //    return "{\"result\":\"ERROR\",\"data\":\"Hiện trưa hỗ trợ oracle\"}";
                //    var lstPara = dicParaToOracleDocTucThoi(dicPara);
                //    var oracle = new gnOracle();
                //    var json = oracle.ExcuteReturnDataSet(dicFileInfo["dtt_procedureoracle"], lstPara, CommandType.StoredProcedure, dicAppset["connectoracle"]);
                //}
                //if (dicFileInfo["dtt_connectto"].ToUpper() == "SQL")
                //{
                //    var sql = new gnSql();
                //    var gn = new general();
                //    // lay ra port tuong ung imei
                //    var conn = dicAppset[dicConfig["connstr"].ToString().ToLower()];
                //    var lstPara = gn.ConvertDicToSqlPara(dicPara);
                //    var dsPort = sql.DynamicSelectDataset(dicFileInfo["dtt_proceduresql"], lstPara, CommandType.StoredProcedure, conn);

                //    if (dsPort == null || dsPort.Tables.Count == 0)
                //        return "{\"result\":\"ERROR\",\"data\":\"Không tìm thấy thông tin ip/port\"}";
                //    // lay ra ip tuong ung o ifcsmart
                //    var lstParaPort = ConvertDatatableToSqlPara(dsPort.Tables[0]);
                //    var dsIpPort = sql.DynamicSelectDataset("DOCTUCTHOI_GetInfoIpPort", lstParaPort, CommandType.StoredProcedure, dicAppset["ifcsmart"]);

                //    if (dsIpPort == null || dsIpPort.Tables.Count == 0)
                //        return "{\"result\":\"ERROR\",\"data\":\"Không tìm thấy thông tin ip/port\"}";
                //    return SaveFileToFolder(dicAppset, dicFileInfo, dicConfig, dicPara, dsIpPort.Tables[0], dsPort.Tables[0]);
                //}

                //        v_IMEI: "8661040203522850",
                //v_SoCongTo: "001502000145",
                //v_Ip: "",
                //v_Port: ""
            }
            catch (Exception ex)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}");
            }
        }
        // POST: api/TCP_OverServiceTcp
        public string Post(classTcpByte value)
        {
            try
            {
                gnSqlNomal gn        = new gnSqlNomal();
                general    gns       = new general();
                var        dicAppSet = gns.ReadAppseting();

                if (value == null || value.config == null)
                {
                    return(null);
                }

                var config = gn.convertConfigToDic(value.config);
                var para   = gn.convertParaToDic(value.para);

                var str = "";
                foreach (var val in para)
                {
                    if (val.Key != "data" && para["type"] == "sendbyte")
                    {
                        str += val.Value + "\r\n";
                    }

                    if (val.Key == "data" && para["type"] == "sendbyte")
                    {
                        var arr   = val.Value.Replace("\r\n", "").Replace(" ", "").Replace("[", "").Replace("]", "").Replace("\"", "").Split(',');
                        var lstss = new List <byte>();
                        foreach (var dataa in arr)
                        {
                            var bytes = gns.HexToByteArray(dataa);
                            lstss.AddRange(bytes);
                        }
                        //var thu = System.Text.ASCIIEncoding.ASCII.GetBytes("#0000000000000009+CSQ:IFCMASTER#");
                        //  var thu1 = BitConverter.to "#0000000000000009+CSQ:IFCMASTER#";
                        str += BitConverter.ToString(lstss.ToArray()) + "\r\n";
                    }
                }

                File.WriteAllText(dicAppSet["pathfoldertcpsend"] + config["namefile"], str);

                var result = "";
                if (para["type"].ToLower() == "checkconnect" || para["type"].ToLower() == "receive")
                {
                    var pathReceive = dicAppSet["pathfoldertcpreceive"] + config["namefile"];
                    if (File.Exists(pathReceive))
                    {
                        result = File.ReadAllText(pathReceive);
                        //var bytes = Array.ConvertAll<string, byte>(resultByte.Substring(0, resultByte.Length-1).Split('-'), s => Convert.ToByte(s, 16));

                        //StringBuilder sb = new StringBuilder(bytes.Length * 2);
                        //foreach (byte b in bytes)
                        //{
                        //    sb.AppendFormat("{0:x2}", b);
                        //}
                        //result = sb.ToString();
                        File.Delete(pathReceive);
                    }
                    else
                    {
                        return("");
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
示例#28
0
        // POST: api/TCP_SendReceiveByte
        public string Post(classTcpConnect value)
        {
            try
            {
                gnSqlNomal gn     = new gnSqlNomal();
                var        config = gn.convertConfigToDic(value.config);
                var        para   = gn.convertParaToDic(value.para);


                // Data buffer for incoming data.
                byte[] bytes    = new byte[1024];
                var    item     = _cachSocket.GetCacheItem(config["keysocket"]);
                Socket socketCa = null;
                if (item != null)
                {
                    socketCa = item.Value as Socket;
                }
                // Connect to a remote device.
                if (config["typecommand"] == "connect")
                {
                    try
                    {
                        IPAddress  ipAddress = IPAddress.Parse(para["ip"]);
                        IPEndPoint remoteEP  = new IPEndPoint(ipAddress, Convert.ToInt32(para["port"]));
                        // Create a TCP/IP  socket.
                        Socket sender = new Socket(AddressFamily.InterNetwork,
                                                   SocketType.Stream, ProtocolType.Tcp);
                        // Connect the socket to the remote endpoint. Catch any errors.
                        sender.ReceiveTimeout = 10000;
                        sender.SendTimeout    = 10000;

                        sender.Connect(remoteEP);

                        List <string> cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList();
                        foreach (string cacheKey in cacheKeys)
                        {
                            if (cacheKey == config["keysocket"])
                            {
                                MemoryCache.Default.Remove(cacheKey);
                            }
                        }

                        _cachSocket.Add(config["keysocket"], sender, DateTime.Now.AddHours(2));
                        //  return "{\"result\":\"OK\",\"data\":[{\"status\":\"OK\"}]}";
                        // }

                        return("OK");
                    }

                    catch (Exception ex)
                    {
                        return(ex.Message);
                    }
                }

                if (config["typecommand"] == "sendbyte" && _cachSocket.Contains(config["keysocket"]))
                {
                    try
                    {
                        // Send the data through the socket.
                        general gns      = new general();
                        var     sendbyte = gns.HexToByteArray(para["lenh"]);
                        socketCa.Send(sendbyte);
                        return("OK");
                    }
                    catch (Exception ex)
                    {
                        return(ex.Message);
                    }
                }
                if (config["typecommand"] == "receivebyte")
                {
                    try
                    {
                        socketCa.ReceiveTimeout = 50;

                        int bytesRec = socketCa.Receive(bytes);
                        var data     = bytes.ToList().GetRange(0, bytesRec).ToArray();
                        return(BitConverter.ToString(data));
                    }
                    catch (Exception ex)
                    {
                        return("");
                    }
                }

                //// Release the socket.
                if (config["typecommand"] == "disconnect")
                {
                    try
                    {
                        // Receive the response from the remote device.

                        socketCa.Dispose();
                        socketCa.Close();
                        return("OK");
                    }
                    catch (Exception ex)
                    {
                        return("{\"result\":\"ERROR\",\"data\":[]}");
                    }
                }
                return("Kiểm tra lại lệnh không đúng định dạng");
            }
            catch (Exception ex) { return(ex.Message); }
        }