private static Stream GenerateErrorResponse(string errorDetails, string errorMessage, System.Net.HttpStatusCode errorCode) { Connector.QueryResult queryResult = new Connector.QueryResult(); queryResult.Success = false; queryResult.Message = errorMessage; queryResult.AddOutputParam("code", errorCode); if (!string.IsNullOrEmpty(errorDetails)) { queryResult.AddOutputParam("details", string.Format("[message:\"{0}\"]", errorDetails)); } return(queryResult.ToStream()); }
protected Connector.QueryResult GetSystemPermission(string userid) { if (userid == "999999999") { return(GetPrivatePermission()); } Connector.IDatabaseConnector dbConnector = new Connector.DatabaseConnectorClass(); Connector.QueryResult permissionResult = null; permissionResult = dbConnector.ExecuteStoredProcedure("APP_Q_CONFIG", new Connector.QueryParameter(new Dictionary <string, object>() { { "USER_ID", userid } })); Dictionary <string, object> session = new Dictionary <string, object>(); foreach (string sKey in Session.Keys) { if (!sKey.StartsWith("DVS_")) { continue; } session.Add(sKey.Replace("DVS_", ""), Session[sKey]); } permissionResult.AddOutputParam("session", session); return(permissionResult); }
protected Connector.QueryResult GetPrivatePermission() { System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer() { MaxJsonLength = int.MaxValue }; var jsonConfig = serializer.Deserialize <Dictionary <string, object> >(System.IO.File.ReadAllText(Server.MapPath("~/cfg/-json-config-.private"))); var jsonSession = serializer.Deserialize <Dictionary <string, object> >(System.IO.File.ReadAllText(Server.MapPath("~/cfg/-json-session-.private"))); Connector.QueryResult permissionResult = new Connector.QueryResult(); foreach (var index in jsonConfig) { permissionResult.AddOutputParam(index.Key, index.Value); } foreach (var index in jsonSession) { permissionResult.AddOutputParam(index.Key, index.Value); } return(permissionResult); }
public void ReadXmlFileLogin() { Setting overview = new Setting(); string data; Connector.QueryResult qResult = new Connector.QueryResult(); Dictionary <string, string> dataDic = new Dictionary <string, string>(); try { System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(Setting)); //System.IO.StreamReader file = new System.IO.StreamReader("D:\\ProjectCode\\NHA\\NHAE145027\\xml\\configLog.xml"); System.IO.StreamReader file = new System.IO.StreamReader(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configLog.xml")); overview = (Setting)reader.Deserialize(file); file.Close(); file.Dispose(); dataDic.Add("keeplog", overview.keeplog); dataDic.Add("strLogpath", string.Join("|", overview.logpath)); } catch (Exception ex) { //System.IO.Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName string startupPath = System.IO.Path.GetFullPath(".\\"); dataDic.Add("keeplog", "90"); string defaultLogPath = System.IO.Path.Combine(System.IO.Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName, "logs"); dataDic.Add("strLogpath", string.Join("|", defaultLogPath)); qResult.Success = true; qResult.Message = "{}"; } qResult.AddOutputParam("data", dataDic); Response.ContentType = "application/json"; Response.Write(qResult.ToJson()); Response.End(); }
public void WriteXmlFile(string keepLog, string logPath) { Connector.QueryResult qResult = new Connector.QueryResult(); System.Xml.Serialization.XmlSerializer writer; System.IO.FileStream file; Setting overview = new Setting(); List <string> listlogPath = new List <string>(); List <string> arr = new List <string>(); try { for (int i = 0; i <= logPath.Split(',').Length - 1; i++) { if (logPath.Split(',')[i] != "") { arr.Add(logPath.Split(',')[i]); } } overview.keeplog = keepLog; overview.logpath = arr.ToArray(); writer = new System.Xml.Serialization.XmlSerializer(typeof(Setting)); file = new System.IO.FileStream(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configLog.xml"), FileMode.Truncate, FileAccess.Write); writer.Serialize(file, overview); file.Close(); file.Dispose(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("keeplog", keepLog); dic.Add("strLogpath", string.Join("|", arr)); qResult.AddOutputParam("data", dic); } catch (Exception ex) { writer = new System.Xml.Serialization.XmlSerializer(typeof(Setting)); file = new System.IO.FileStream(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configLog.xml"), FileMode.CreateNew, FileAccess.Write); writer.Serialize(file, overview); file.Close(); file.Dispose(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("keeplog", keepLog); dic.Add("strLogpath", string.Join("|", arr)); qResult.AddOutputParam("data", dic); qResult.Success = false; qResult.Message = ex.Message; } Response.ContentType = "application/json"; Response.Write(qResult.ToJson()); Response.End(); }
private void searchFile(string[] logFilter, string age, string strDateAge, string startTime, string endTime, string source, string machine, string search) { Connector.QueryResult connect = new Connector.QueryResult(); Dictionary <string, object> objList = new Dictionary <string, object>(); try { string[] filterType = new string[4] { "ERROR", "WARN", "INFO", "DEBUG" }; System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(System.IO.Path.Combine(machine)); // System.IO.Path.Combine(machine); // System.IO.StreamReader file = new System.IO.StreamReader(); DateTime dateAge = new DateTime(); DateTime startDateObj = startDate(age, strDateAge); DateTime endDateObj = endDate(age, strDateAge); int startT = int.Parse(startTime); int endT = int.Parse(endTime); string strHr = ""; int hr = 0; foreach (DirectoryInfo direct in downloadedMessageInfo.GetDirectories()) { Dictionary <string, List <string> > resultDic = new Dictionary <string, List <string> >(); if ((startDateObj.Month <= direct.CreationTime.Month && startDateObj.Year <= direct.CreationTime.Year) && (endDateObj.Month >= direct.CreationTime.Month && endDateObj.Year >= direct.CreationTime.Year)) { foreach (FileInfo file in direct.GetFiles()) { List <string> resultList = new List <string>(); try { if (startDateObj.Date <= file.CreationTime.Date && endDateObj.Date >= file.CreationTime.Date) { if ((file.Name.ToUpper().IndexOf(source.ToUpper()) >= 0) || source == "all") { // System.IO.StreamReader StrRead = new System.IO.StreamReader(file.FullName, Encoding.Default); using (FileStream fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader StrRead = new StreamReader(fileStream, Encoding.Default)) { string txtRead = ""; int i = 0; // string json = StrRead.ReadToEnd(); while (!(StrRead.EndOfStream)) { string txt = StrRead.ReadLine().ToString(); if (Array.IndexOf(filterType, txt.Split(' ')[0].Trim()) < 0 || i == 0) { txtRead += txt + "<br/>"; } else { if (Array.IndexOf(logFilter, txtRead.Split(' ')[0].Trim()) >= 0) { strHr = txtRead.Split(':')[0].Trim(); hr = int.Parse(strHr.Substring(strHr.Length - 2, 2)); if (hr >= startT && hr <= endT) { resultList.Add(txtRead); } } txtRead = txt + "<br/>";; } i++; } StrRead.Close(); StrRead.Dispose(); if (Array.IndexOf(logFilter, txtRead.Split(' ')[0].Trim()) >= 0) { strHr = txtRead.Split(':')[0].Trim(); hr = int.Parse(strHr.Substring(strHr.Length - 2, 2)); if (hr >= startT && hr <= endT) { resultList.Add(txtRead); } } if (resultList.Count > 0) { resultDic.Add(file.Name, resultList); } } } } } } catch (Exception ex) { } } } objList.Add(direct.Name.ToString(), resultDic); } connect.AddOutputParam("data", objList); connect.AddOutputParam("search", search); } catch (Exception ex) { connect.Message = ex.Message; connect.Success = false; } Response.ContentType = "application/json"; Response.Write(connect.ToJson()); Response.End(); }
public QueryResult ExecuteStatement(string statement, QueryParameter queryParam) { StringBuilder logString = null; QueryResult qResult = null; IDbCommand dbCommand = null; IDataReader dbReader = null; IDbDataParameter dbParam = null; DataTable dt = null; string paramName = string.Empty; int cursorNum = 1; try { logString = new StringBuilder(); if (_dbConnection == null) { throw new Exception(string.Format("ไม่สามารถโหลด assembly {0} ได้เนื่องจาก\r\n{1}", _assemblyName, _exceptionTemporary.GetBaseException().Message)); } _dbConnection.ConnectionString = _connectionString; qResult = new QueryResult(); if (_dbConnection.State != ConnectionState.Open) { _dbConnection.Open(); } dbCommand = CreateCommand(statement); if (queryParam != null) { for (int i = 0; i < dbCommand.Parameters.Count; i++) { if (queryParam.Parameter.Count >= i) { dbParam = dbCommand.Parameters[i] as IDbDataParameter; dbParam.Value = queryParam.Parameter[queryParam.Parameter.Keys.ElementAt(i)]; } else { break; } } } dbReader = dbCommand.ExecuteReader(); while (!dbReader.IsClosed) { dt = new DataTable(); dt.Load(dbReader); if (cursorNum == 1) { qResult.DataTable = dt; } else { qResult.AddOutputParam("data" + cursorNum, Util.DataTableToDictionary(dt, _dateTimeFormat, _cultureInfo)); } cursorNum++; } for (int i = 0; i < dbCommand.Parameters.Count; i++) { dbParam = dbCommand.Parameters[i] as IDbDataParameter; if (!dbParam.Direction.Equals(ParameterDirection.Output)) { continue; } paramName = dbParam.ParameterName; if (_paramNamePrefix.Length > 0) { paramName = paramName.Replace(_paramNamePrefix, string.Empty); } if (!_reservedOutputName.Contains(paramName.ToUpper())) { paramName = paramName.Replace(_outputReplace, string.Empty); if (dbParam.Value == null || System.DBNull.Value.Equals(dbParam.Value)) { qResult.AddOutputParam(paramName, dbParam.Value); } else if (dbParam.Value is DateTime) { qResult.AddOutputParam(paramName, Util.DateTimeToString((dbParam.Value as DateTime?))); } else if (dbParam.Value is IDataReader) { dt = new DataTable(); dt.Load(dbParam.Value as IDataReader); qResult.AddOutputParam(paramName.ToLower(), Util.DataTableToDictionary(dt, _dateTimeFormat, _cultureInfo)); } else { qResult.AddOutputParam(paramName, dbParam.Value); } } else if (paramName.Equals("PO_DATA")) { dt = new DataTable(); dt.Load(dbParam.Value as IDataReader); qResult.DataTable = dt; } else if (paramName.Equals("PO_TOTAL")) { if (!string.IsNullOrEmpty(dbParam.Value.ToString())) { qResult.Total = int.Parse(dbParam.Value.ToString()); } } else if (paramName.Equals("PO_STATUS")) { if (dbParam.Value.ToString().Equals("1")) { qResult.Success = true; } else { qResult.Success = false; } } else if (paramName.Equals("PO_STATUS_MSG")) { qResult.Message = dbParam.Value.ToString(); } } logString.AppendLine(string.Format("<LOGFUNCTION>")); if (queryParam.Parameter.ContainsKey("FN_ID") == true) { logString.AppendLine(string.Format("{0}", queryParam.Parameter["FN_ID"])); } logString.AppendLine(string.Format("</LOGFUNCTION>")); if (qResult.Success != true) { logString.AppendLine(string.Format("{0}", qResult.Message)); logString.AppendLine(string.Format("<LOGSESSION>")); logString.Append(LogSession()); logString.AppendLine(string.Format("</LOGSESSION>")); logString.AppendLine("!!! Error !!!"); Util.WriteLogError(logString.ToString()); } else { logString.AppendLine(string.Format("<LOGSESSION>")); logString.Append(LogSession()); logString.AppendLine(string.Format("</LOGSESSION>")); logString.AppendLine("!!! Completed !!!"); Util.WriteLogInfo(logString.ToString()); //Util.WriteLogDebug(qResult.ToJson()); } } catch (Exception ex) { qResult = new QueryResult(ex); logString.AppendLine(string.Format("{0}", qResult.Message)); logString.AppendLine(string.Format("<LOGFUNCTION>")); if (queryParam.Parameter.ContainsKey("FN_ID") == true) { logString.AppendLine(string.Format("{0}", queryParam.Parameter["FN_ID"])); } logString.AppendLine(string.Format("</LOGFUNCTION>")); logString.AppendLine(string.Format("<LOGSESSION>")); logString.Append(LogSession()); logString.AppendLine(string.Format("</LOGSESSION>")); logString.AppendLine("!!! Error !!!"); Util.WriteLogError(logString.ToString(), ex); } finally { if (_dbConnection != null && _dbConnection.State == ConnectionState.Open) { _dbConnection.Close(); } } return(qResult); }
public QueryResult ExecuteStoredProcedure(string storeName, QueryParameter queryParam) { StringBuilder logString = null; QueryResult qResult = null; IDbCommand dbCommand = null; IDataReader dbReader = null; IDbDataParameter dbParam = null; //IDbTransaction dbTrans = null; DataTable dt = null; string paramName = string.Empty; int cursorNum = 1; try { logString = new StringBuilder(); logString.AppendLine(string.Format("\tSP: {0}", storeName)); if (_dbConnection == null) { if (_exceptionTemporary != null) { throw new Exception(string.Format("ไม่สามารถโหลด assembly {0} ได้เนื่องจาก\r\n{1}", _assemblyName, _exceptionTemporary.GetBaseException().Message)); } else { throw new Exception(string.Format("ไม่สามารถโหลด assembly {0} ได้", _assemblyName)); } } _dbConnection.ConnectionString = _connectionString; if (_provider.Equals(ProviderFactory.MySQL)) { throw new Exception("Provider ไม่รองรับการ Execute โดยใช้ StoredProcedure"); } if (_dbConnection.State != ConnectionState.Open) { _dbConnection.Open(); } qResult = new QueryResult(); dbCommand = CreateCommand(storeName, queryParam, ref logString); //dbTrans = _dbConnection.BeginTransaction(); switch (_provider) { case ProviderFactory.MSSQL: dbReader = dbCommand.ExecuteReader(); while (!dbReader.IsClosed) { dt = new DataTable(); dt.Load(dbReader); if (cursorNum == 1) { qResult.DataTable = dt; } else { qResult.AddOutputParam("data" + cursorNum, Util.DataTableToDictionary(dt, _dateTimeFormat, _cultureInfo)); } cursorNum++; } break; default: dbCommand.ExecuteNonQuery(); break; } for (int i = 0; i < dbCommand.Parameters.Count; i++) { dbParam = dbCommand.Parameters[i] as IDbDataParameter; if (!dbParam.Direction.Equals(ParameterDirection.Output)) { continue; } paramName = dbParam.ParameterName; if (_paramNamePrefix.Length > 0) { paramName = paramName.Replace(_paramNamePrefix, string.Empty); } if (!_reservedOutputName.Contains(paramName.ToUpper())) { paramName = paramName.Replace(_outputReplace, string.Empty); if (dbParam.Value == null || System.DBNull.Value.Equals(dbParam.Value)) { qResult.AddOutputParam(paramName, dbParam.Value); } else if (dbParam.Value is DateTime) { qResult.AddOutputParam(paramName, Util.DateTimeToString((dbParam.Value as DateTime?))); } else if (dbParam.Value is IDataReader) { dt = new DataTable(); if (dbParam.Value != System.DBNull.Value) { dt.Load(dbParam.Value as IDataReader); } qResult.AddOutputParam(paramName.ToLower(), Util.DataTableToDictionary(dt, _dateTimeFormat, _cultureInfo)); } else { if (paramName.IndexOf("NT_") == 0) { qResult.AddNTParam(paramName, dbParam.Value); } else { qResult.AddOutputParam(paramName, dbParam.Value); } } } else if (paramName.Equals("PO_DATA")) { dt = new DataTable(); if (dbParam.Value != System.DBNull.Value) { dt.Load(dbParam.Value as IDataReader); } qResult.DataTable = dt; } else if (paramName.Equals("PO_TOTAL")) { if (!string.IsNullOrEmpty(dbParam.Value.ToString())) { qResult.Total = int.Parse(dbParam.Value.ToString()); } } else if (paramName.Equals("PO_STATUS")) { if (dbParam.Value.ToString().Equals("1")) { qResult.Success = true; } else { qResult.Success = false; } } else if (paramName.Equals("PO_STATUS_MSG")) { qResult.Message = dbParam.Value.ToString(); } } logString.AppendLine(string.Format("<LOGFUNCTION>")); if (queryParam.Parameter.ContainsKey("FN_ID") == true) { logString.AppendLine(string.Format("{0}", queryParam.Parameter["FN_ID"])); } logString.AppendLine(string.Format("</LOGFUNCTION>")); if (qResult.Success != true) { logString.AppendLine(string.Format("{0}", qResult.Message)); logString.AppendLine(string.Format("<LOGSESSION>")); logString.Append(LogSession()); logString.AppendLine(string.Format("</LOGSESSION>")); logString.AppendLine("!!! Error !!!"); Util.WriteLogError(logString.ToString()); } else { logString.AppendLine(string.Format("<LOGSESSION>")); logString.Append(LogSession()); logString.AppendLine(string.Format("</LOGSESSION>")); logString.AppendLine("!!! Completed !!!"); Util.WriteLogInfo(logString.ToString()); //Util.WriteLogDebug(qResult.ToJson()); } //try //{ // dbTrans.Commit(); //} //catch { } } catch (Exception ex) { //try //{ // dbTrans.Rollback(); //} //catch { } qResult = new QueryResult(ex); logString.AppendLine(string.Format("{0}", qResult.Message)); logString.AppendLine(string.Format("<LOGFUNCTION>")); if (queryParam.Parameter.ContainsKey("FN_ID") == true) { logString.AppendLine(string.Format("{0}", queryParam.Parameter["FN_ID"])); } logString.AppendLine(string.Format("</LOGFUNCTION>")); logString.AppendLine(string.Format("<LOGSESSION>")); logString.Append(LogSession()); logString.AppendLine(string.Format("</LOGSESSION>")); logString.AppendLine("!!! Error !!!"); Util.WriteLogError(logString.ToString()); } finally { //try //{ // dbTrans.Dispose(); // dbTrans = null; //} //catch { } if (_dbConnection != null && _dbConnection.State == ConnectionState.Open) { _dbConnection.Close(); _dbConnection.Dispose(); } } return(qResult); }