Пример #1
0
        /// <summary>
        /// 2015-05-04 14:41:33 ngocta2
        /// chi can read 1 dong
        /// </summary>
        /// <param name="strFullPathTemplate"></param>
        /// <returns></returns>
        public static string ReadFile(string strFullPathTemplate)
        {
            try
            {
                // C:\Log\5G_QuoteFeeder_HOSE\SQL\2014_12_04.txt
                string strPath = strFullPathTemplate
                                 .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                 .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                 .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                 .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                ;

                // check folder
                CheckDirectory(strPath);

                // read
                string strBody = "";
                using (StreamReader sr = new StreamReader(strPath))
                {
                    strBody = sr.ReadToEnd();
                }

                return(strBody);
            }
            catch (Exception)
            {
                // do nothing
                return("");
            }
            finally
            {
            }
        }
Пример #2
0
        ///// <summary>
        ///// Send Msg to monitor
        ///// </summary>
        ///// <param name="AppName"></param>
        ///// <param name="Mgs"></param>
        //public static void Monitor_SendMsg(string AppName, string Msg)
        //{
        //    try
        //    {
        //        var pairs = new List<KeyValuePair<string, string>>
        //    {
        //        new KeyValuePair<string, string>("type", "msg"),
        //        new KeyValuePair<string, string>("msg", Msg),
        //    };
        //        Monitor_Send(AppName, pairs);
        //    }
        //    catch (Exception ex)
        //    {
        //        CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
        //    }
        //}
        ///// <summary>
        ///// Send Progress to monitor
        ///// </summary>
        ///// <param name="AppName"></param>
        ///// <param name="Current"></param>
        ///// <param name="Max"></param>
        //public static void Monitor_SendProgress(string AppName, string Current, string Max)
        //{
        //    try
        //    {
        //        var pairs = new List<KeyValuePair<string, string>>
        //    {
        //        new KeyValuePair<string, string>("type", "progress"),
        //        new KeyValuePair<string, string>("current", Current),
        //        new KeyValuePair<string, string>("max", Max),
        //    };
        //        Monitor_Send(AppName, pairs);
        //    }
        //    catch (Exception ex)
        //    {
        //        CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
        //    }
        //}
        ///// <summary>
        ///// Send Status to monitor
        ///// </summary>
        ///// <param name="AppName"></param>
        ///// <param name="Current"></param>
        ///// <param name="Max"></param>
        ///// <param name="Msg"></param>
        ///// <param name="Note"></param>
        //public static void Monitor_SendStatus(string AppName, string Current, string Max, string Msg, string Note)
        //{
        //    try
        //    {
        //        List<KeyValuePair<string, string>> pairs = new List<KeyValuePair<string, string>>
        //    {
        //        new KeyValuePair<string, string>("type", "status"),
        //        new KeyValuePair<string, string>("current", Current),
        //        new KeyValuePair<string, string>("max", Max),
        //        new KeyValuePair<string, string>("msg", Msg),
        //        new KeyValuePair<string, string>("note", Note),
        //    };
        //        Monitor_Send(AppName, pairs);
        //    }
        //    catch (Exception ex)
        //    {
        //        CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
        //    }
        //}

        //private static void Monitor_Send(string AppName, List<KeyValuePair<string, string>> pairs)
        //{
        //    try
        //    {
        //        HttpClient client = new HttpClient();

        //        FormUrlEncodedContent content = new FormUrlEncodedContent(pairs);

        //        var response = client.PostAsync(CConfig.MONITOR_URL.Replace("<!AppName>", AppName), content).Result;

        //        if (response.IsSuccessStatusCode)
        //        {

        //        }
        //        response.Dispose();
        //    }
        //    catch (Exception ex)
        //    {
        //        CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
        //    }
        //}

        //public static void Send_Test(string AppName, string Current, string Max, string Msg, string Note)
        //{
        //    using (WebClient client = new WebClient())
        //    {
        //        System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
        //        reqparm.Add("type", "status");
        //        reqparm.Add("current", Current);
        //        reqparm.Add("max", Max);
        //        reqparm.Add("msg", Msg);
        //        reqparm.Add("note", Note);
        //        byte[] responsebytes = client.UploadValues(CConfig.MONITOR_URL.Replace("<!AppName>", AppName), "POST", reqparm);
        //        string responsebody = Encoding.UTF8.GetString(responsebytes);
        //    }
        //}

        /// <summary>
        /// 2015-05-04 11:11:26 ngocta2
        /// convert char array => string
        /// </summary>
        /// <param name="objValue"></param>
        /// <returns></returns>
        public static string Char2String(object objValue)
        {
            try
            {
                if (objValue == null)
                {
                    return("null");
                }

                string strValue = "";
                if (objValue.GetType().ToString() == "System.Char[]")
                {
                    char[] arrchrData = (char[])objValue;
                    string strTemp    = new string(arrchrData);
                    strValue = strTemp.Trim();
                }
                else
                {
                    strValue = objValue.ToString();
                }

                return(strValue);
            }
            catch (Exception ex)
            {
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// 2015-05-04 14:32:33 ngocta2
        /// </summary>
        /// <param name="strFullPathTemplate"></param>
        /// <param name="strBody"></param>
        /// <param name="blnIsAppend"></param>
        public static void WriteFile(string strFullPathTemplate, string strBody, bool blnIsAppend)
        {
            try
            {
                // C:\Log\5G_QuoteFeeder_HOSE\SQL\2014_12_04.txt
                string strPath = strFullPathTemplate
                                 .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                 .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                 .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                 .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                ;

                // check folder
                CheckDirectory(strPath);

                // write
                StreamWriter fs = new StreamWriter(strPath, blnIsAppend); // append
                fs.WriteLine(strBody);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Пример #4
0
        /// <summary>
        /// log cao cap, chi tiet hon: thuong dung de log cac du lieu big, phai chia nho file nhu log SQL (single file = 800MB)
        /// 1 file chi ghi 1 lan, ko ghi nhieu lan (nhieu line) trong 1 file
        /// <add key="BASE_LOG_PATH_EX"       value="C:\Log\(AppName)\(Type)\(yyyy)\(MM)\(dd)\(FileName).txt" />
        /// <add key="BASE_TEMPLATE_LOG_EX_FILENAME"      value="(thread)__(type)__(hh)_(mm)_(ss)__(random).txt" />
        /// </summary>
        /// <param name="strFolder">SQL/ERROR/TEXT</param>
        /// <param name="strFileNameEx">1_security_14_33_59_afj43laf</param>
        /// <param name="strBody">SQL script</param>
        public static void LogEx(string strFileNameEx, string strBody)
        {
            try
            {
                // C:\Log\5G_QuoteFeeder_HOSE\SQL\2014\12\04\1__security__14_34_59__afj43laf.txt
                string strPath = CConfig.BASE_LOG_PATH_EX
                                 .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                 .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                 .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                 .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                                 .Replace("(FileName)", strFileNameEx)
                ;

                // check folder
                CheckDirectory(strPath);

                // write
                StreamWriter fs = new StreamWriter(strPath, true); // append
                fs.WriteLine(DateTime.Now.ToString("HH:mm:ss.") + DateTime.Now.Millisecond.ToString("000") + " => " + strBody);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="strTo"></param>
 /// <param name="strSubject"></param>
 /// <param name="strBody"></param>
 /// <returns></returns>
 public static bool SendEmail(string strTo, string strSubject, string strBody)
 {
     try
     {
         System.Net.Mail.MailMessage mail      = new System.Net.Mail.MailMessage();
         System.Net.Mail.SmtpClient  VSmtpMail = new System.Net.Mail.SmtpClient();
         mail.From = new System.Net.Mail.MailAddress(SMTP_FROM);
         mail.To.Add(new System.Net.Mail.MailAddress(strTo));
         mail.BodyEncoding     = System.Text.Encoding.UTF8;
         mail.Subject          = strSubject;
         mail.Body             = strBody;
         mail.IsBodyHtml       = true;
         VSmtpMail             = new System.Net.Mail.SmtpClient();
         VSmtpMail.Host        = SMTP_SERVER;
         VSmtpMail.Port        = Convert.ToInt32(SMTP_PORT);
         VSmtpMail.Credentials = new System.Net.NetworkCredential(SMTP_USER, SMTP_PASS);
         VSmtpMail.Send(mail);
         return(true);
     }
     catch (Exception ex)
     {
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return(false);
     }
 }
Пример #6
0
 /// <summary>
 /// Write Data to the INI File
 /// </summary>
 /// <PARAM name="Section"></PARAM>
 /// Section name
 /// <PARAM name="Key"></PARAM>
 /// Key Name
 /// <PARAM name="Value"></PARAM>
 /// Value Name
 public void IniWriteValue(string Section, string Key, string Value)
 {
     try
     {
         WritePrivateProfileString(Section, Key, Value, this.path);
     }
     catch (Exception ex)
     {
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
     }
 }
Пример #7
0
        /// <summary>
        /// ghi log file
        /// </summary>
        /// <param name="strPathTemplate"></param>
        /// <param name="str1"></param>
        /// <param name="str2"></param>
        private static void Log(string strPathTemplate, string str1, string str2)
        {
            try
            {
                string strPath = strPathTemplate.Replace("(AppName)", CConfig.BASE_APP_NAME);
                string strLine = "";

                if (CConfig.BASE_LOG_MULTI_THREAD != CConfig.SINGLE_THREAD)
                {
                    // multi - ko duoc write chung 1 file - error "file locked by other process"
                    strPath = strPath
                              .Replace("(yyyy)", DateTime.Now.Year.ToString())
                              .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                              .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2));
                    strPath += Path.GetRandomFileName();
                }
                else
                {
                    // single
                    strPath = strPath.Replace("(yyyy)\\(MM)\\(dd)\\", "(yyyy)-(MM)-(dd)");
                    strPath = strPath
                              .Replace("(yyyy)", DateTime.Now.Year.ToString())
                              .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                              .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2));
                    strPath += CConfig.LOG_EXT;
                }


                // data
                strLine = CConfig.TEMPLATE_LOG_DATA
                          .Replace("(Time)", DateTime.Now.ToString("HH:mm:ss.") + DateTime.Now.Millisecond.ToString("000"))
                          .Replace("(Title)", str1)
                          .Replace("(Detail)", str2);

                // check folder
                CheckDirectory(strPath);

                // write
                StreamWriter fs = new StreamWriter(strPath, true); // append
                fs.WriteLine(strLine);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Пример #8
0
 /// <summary>
 /// Read Data Value From the Ini File
 /// </summary>
 /// <PARAM name="Section"></PARAM>
 /// <PARAM name="Key"></PARAM>
 /// <PARAM name="Path"></PARAM>
 /// <returns></returns>
 public string IniReadValue(string Section, string Key)
 {
     try
     {
         StringBuilder temp = new StringBuilder(VALUE_LENGTH_MAX);
         int           i    = GetPrivateProfileString(Section, Key, "", temp, VALUE_LENGTH_MAX, this.path);
         return(temp.ToString());
     }
     catch (Exception ex)
     {
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return("");
     }
 }
Пример #9
0
        /// <summary>
        /// su dung de log big string vao file log
        /// </summary>
        /// <param name="strVarName"></param>
        /// <param name="strLongString"></param>
        /// <returns></returns>
        public static string LongString2LogFile(string strVarName, string strLongString)
        {
            try
            {
                string strFileName = strVarName + "___" + DateTime.Now.ToString(FORMAT_TIME) + FILE_EXT;  // "dd/MM/yyyy HH:mm";// (24/10/2012 15:36)
                CLog.LogEx(strFileName, strLongString);

                return(strFileName);
            }
            catch (Exception ex)
            {
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return("");
            }
        }
Пример #10
0
        public const int DURATION_IN_SECONDS = 100; // token chi valid trong 100s tu khi tao ra

        // tao random token
        // token chi valid trong 1 khoang thoi gian nhat dinh
        // hacker ko the copy token nay de su dung trai phep (connect vao Hub get data)
        public static string CreateToken()
        {
            try
            {
                byte[] time  = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
                byte[] key   = Guid.NewGuid().ToByteArray();
                string token = Convert.ToBase64String(time.Concat(key).ToArray());
                return(token);
            }
            catch (Exception ex)
            {
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return("");
            }
        }
Пример #11
0
        /// <summary>
        /// bo ky tu ko hop le
        /// C:\Log\Monitor\ERROR\2016-04-08\103843__System.Threading.QueueUserWorkItemCallback_WaitCallback_Context_Monitor.Hubs.CMonitor5G_<InitPubSubData>b__0___xgbmys1i.5tx
        /// Illegal characters in path.
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public static string FixPath(string strPath)
        {
            try
            {
                strPath = strPath.Replace("<", "(");
                strPath = strPath.Replace(">", ")");
                strPath = strPath.Replace("`", "_");

                return(strPath);
            }
            catch (Exception ex)
            {
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return(strPath);
            }
        }
Пример #12
0
        /// <summary>
        /// lay gia tri cua field, gom cac kieu: string, bool, int, long, array, dic
        //+		obj	{QuoteBaseLib.BLL.CReaderBaseMQ}	object {QuoteBaseLib.BLL.CReaderBaseMQ}
        //+		field	{System.Collections.Generic.Dictionary`2[System.Int32,System.String] m_dicI}	object {System.Reflection.RtFieldInfo}
        //+		((FieldInfo)field).GetValue(obj)	Count = 22	object {System.Collections.Generic.Dictionary<int,string>}
        //+		(Dictionary<int,string>)((FieldInfo)field).GetValue(obj)	Count = 22	System.Collections.Generic.Dictionary<int,string>
        //        ((Dictionary<int,string>)((FieldInfo)field).GetValue(obj))[8]	"BeginString"	string
        //        ((FieldInfo)field).GetValue(obj).GetType().IsGenericType	true	bool
        //        ((FieldInfo)field).GetValue(obj).GetType().GetGenericTypeDefinition()== typeof(Dictionary<,>)	true	bool
        //+		((FieldInfo)field).GetValue(obj).GetType().GetGenericArguments()[0];	{Name = "Int32" FullName = "System.Int32"}	System.Type {System.RuntimeType}
        //+		((FieldInfo)field).GetValue(obj).GetType().GetGenericArguments()[1];	{Name = "String" FullName = "System.String"}	System.Type {System.RuntimeType}
        //        ((FieldInfo)field).GetValue(obj).GetType().GetGenericArguments()[0].Name	"Int32"	string
        //        ((FieldInfo)field).GetValue(obj).GetType().GetGenericArguments()[1].Name	"String"	string
        //		valueType.Name	"Int64"	string
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="field"></param>
        /// <param name="strFieldName"></param>
        /// <returns></returns>
        private static string GetValueOfField(object objClass, FieldInfo FI, string strFieldName)
        {
            try
            {
                object objField = FI.GetValue(objClass);
                if (objField == null)
                {
                    return("null");
                }
                else
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    string jsonString = "";
                    //==========================================
                    var iDict = objField as IDictionary;
                    if (iDict != null)
                    {
                        // My object is an IDictionary
                        StringBuilder sb = new StringBuilder("");
                        sb.Append("[");
                        foreach (System.Collections.DictionaryEntry o in iDict)
                        {
                            sb.Append(TEMPLATE_DIC_ELE
                                      .Replace("(key)", RemoveTrash(o.Key.ToString()))
                                      .Replace("(val)", RemoveTrash(o.Value.ToString()))
                                      ).Append(",");
                        }
                        sb.Length--;
                        sb.Append("]");
                        jsonString = sb.ToString();
                    }
                    else
                    {
                        // My object is not an IDictionary
                        jsonString = serializer.Serialize((object)objField);
                    }
                    //==========================================

                    return(jsonString);
                }
            }
            catch (Exception ex)
            {
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return("");
            }
        }
Пример #13
0
 //truy van URL dung WebClient
 public static string GetURLResponseHTTP2(string strURL)
 {
     try
     {
         using (WebClient client = new WebClient())
         {
             string responseFromServer = client.DownloadString(strURL);
             return(responseFromServer);
         }
     }
     catch (Exception ex)
     {
         // log error
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return("");
     }
 }
Пример #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="strListTo"></param>
 /// <param name="strSubject"></param>
 /// <param name="strBody"></param>
 /// <returns></returns>
 public static bool SendEmails(string strListTo, string strSubject, string strBody)
 {
     try
     {
         string[] arrTo = strListTo.Split(CHAR_SPLITOR);
         foreach (string strTo in arrTo)
         {
             SendEmail(strTo, strSubject, strBody);
         }
         return(true);
     }
     catch (Exception ex)
     {
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return(false);
     }
 }
Пример #15
0
 public static void ResizeArray <T>(ref T[] arr)
 {
     try
     {
         if (arr == null)
         {
             Array.Resize(ref arr, 1); // tang size array
         }
         else
         {
             Array.Resize(ref arr, arr.Length + 1); // tang size array
         }
     }
     catch (Exception ex)
     {
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
     }
 }
Пример #16
0
 //truy van URL dung WebRequest
 public static string GetURLResponseHTTP(string strURL)
 {
     try
     {
         WebRequest   request            = WebRequest.Create(strURL);
         WebResponse  response           = request.GetResponse();
         Stream       dataStream         = response.GetResponseStream();
         StreamReader reader             = new StreamReader(dataStream);
         string       responseFromServer = reader.ReadToEnd();
         return(responseFromServer);
     }
     catch (Exception ex)
     {
         // log error
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return("");
     }
 }
Пример #17
0
        /// <summary>
        /// tuong tu LogEx
        /// </summary>
        /// <param name="strFileNameEx"></param>
        /// <param name="strBody"></param>
        /// <param name="arrHeader"></param>
        public static void LogCSV(string strFileNameEx, string strBody, string[] arrHeader)
        {
            try
            {
                // C:\Log\5G_QuoteFeeder_HOSE\SQL\2014\12\04\1__security__14_34_59__afj43laf.txt
                string strPath = CConfig.BASE_LOG_PATH_EX
                                 .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                 .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                 .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                 .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                                 .Replace("(FileName)", strFileNameEx)
                ;

                // check folder
                CheckDirectory(strPath);

                // tao row header neu file chua ton tai
                string strHeader = "";
                if (!File.Exists(strPath))
                {
                    strHeader = "Time";
                    foreach (string str in arrHeader)
                    {
                        strHeader += "," + str;
                    }
                }

                // write
                StreamWriter fs = new StreamWriter(strPath, true); // append
                if (strHeader != "")
                {
                    fs.WriteLine(strHeader);
                }
                fs.WriteLine(DateTime.Now.ToString("HH:mm:ss.") + DateTime.Now.Millisecond.ToString("000") + "," + strBody);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Пример #18
0
 /// <summary>
 /// 2016-03-02 14:28:28 ngocta2
 /// send email cho nhieu nguoi , voi chu ky
 /// VD: interval=3 >>> co the call function nay lien tuc nhung that su chi co 3 phut moi send mail 1 lan
 /// </summary>
 /// <param name="strListTo">[email protected],[email protected],[email protected],[email protected]</param>
 /// <param name="strSubject">string subject</param>
 /// <param name="strBody">string body</param>
 /// <param name="intIntervalInMinute">3</param>
 /// <returns></returns>
 public static bool SendEmails(string strListTo, string strSubject, string strBody, int intIntervalInMinute)
 {
     try
     {
         int intMinuteCountNow = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
         if (intMinuteCountNow - m_intMinuteCountBegin >= intIntervalInMinute || m_blnFirst)
         {
             m_blnFirst            = false;
             m_intMinuteCountBegin = intMinuteCountNow;
             CEMail.SendEmails(strListTo, strSubject, strBody);
         }
         return(true);
     }
     catch (Exception ex)
     {
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return(false);
     }
 }
Пример #19
0
        /// <summary>
        /// CBase.Right("QuoteFeederHOSELib.BLL.CQuoteFeederHOSELib->Thread_PRS_SECURITY","QuoteFeederHOSELib.BLL.CQuoteFeederHOSELib->Thread_PRS_SECURITY".Length -42-2)
        ///"Thread_PRS_SECURITY"
        ///"QuoteFeederHOSELib.BLL.CQuoteFeederHOSELib->Thread_PRS_SECURITY".IndexOf ("->")
        ///42
        ///CBase.GetCaller(1)
        ///"QuoteFeederHOSELib.BLL.CQuoteFeederHOSELib->Thread_PRS_SECURITY"
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentFunctionName(string strDeepCaller)
        {
            try
            {
                //return System.Reflection.MethodBase.GetCurrentMethod().Name;

                //StackTrace st = new StackTrace();
                //StackFrame sf = st.GetFrame(0);
                //MethodBase currentMethodName = sf.GetMethod();
                //string ssss = currentMethodName.ToString();

                strDeepCaller = CBase.Right(strDeepCaller, strDeepCaller.Length - strDeepCaller.IndexOf("->") - 2);
                return(strDeepCaller);
            }
            catch (Exception ex)
            {
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return("");
            }
        }
Пример #20
0
 //<add key="BASE_TEMPLATE_LOG_EX_FILENAME"      value="(thread)__(type)__(hh)_(mm)_(ss)__(random).(ext)" />
 //"1__security__14_33_55__abcd7890"
 //CLog.LogEx("TEST", "1__security__14_33_55__abcd7890", "Tạm ứng cổ tức năm đợt 2 năm 2014 bằng tiền mặt, 2.000đồng/cổ phiếu");
 public static string GetLogExFileName(int intThread, string strType, string strExt)
 {
     try
     {
         string strFileName = CConfig.BASE_TEMPLATE_LOG_EX_FILENAME;
         strFileName = strFileName
                       .Replace("(thread)", intThread.ToString())
                       .Replace("(type)", strType)
                       .Replace("(hh)", CBase.Right("00" + DateTime.Now.Hour.ToString(), 2))
                       .Replace("(mm)", CBase.Right("00" + DateTime.Now.Minute.ToString(), 2))
                       .Replace("(ss)", CBase.Right("00" + DateTime.Now.Second.ToString(), 2))
                       .Replace("(random)", System.IO.Path.GetRandomFileName())
                       .Replace("(ext)", strExt);
         return(strFileName);
     }
     catch (Exception ex)
     {
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return("");
     }
 }
Пример #21
0
        /*
         * http://stackoverflow.com/questions/3685732/c-sharp-serialize-dictionaryulong-ulong-to-json
         * I am trying to serialize a Dictionary to JSON, and get the following exception:
         * Type 'System.Collections.Generic.Dictionary2
         * [
         * [System.UInt64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],
         * [System.Nullable1[[System.UInt64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]
         * ]
         * , mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'
         * is not supported for serialization/deserialization of a dictionary, keys must be strings or objects.
         * ==================================
         * var dict = mapping.ToDictionary(item => item.Key.ToString(), item => item.Value.ToString());
         * that will convert any Dictionary<K,V> to Dictionary<string,string> and serialization then works.
         * https://dukelupus.wordpress.com/2011/05/04/asp-net-mvc-json-and-a-generic-dictionary/
         */
        //public static Dictionary<string, object> ToJsonDictionary<TKey, TValue>(this Dictionary<TKey, TValue> input)
        //{
        //    var output = new Dictionary<string, object>(input.Count);
        //    foreach (KeyValuePair<TKey, TValue> pair in input)
        //        output.Add(pair.Key.ToString(), pair.Value);
        //    return output;
        //}


        // <f55>k__BackingField => f55
        private static string RemoveTrash(string strInput)
        {
            try
            {
                Match MatchResults = null;
                MatchResults = Regex.Match(strInput, REGEX_REMOVE_TRASH);
                if (MatchResults.Success)
                {
                    return(MatchResults.Groups[1].Value);
                }
                else
                {
                    return(strInput);
                }
            }
            catch (Exception ex)
            {
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return("");
            }
        }
Пример #22
0
 //truy van URL
 // strURL = http://liveprice.fpts.com.vn/monitor.asp?k=MW2_SRV_HTML_STOCK_INFO_1_ABT
 // strURL = https://172.16.0.11/mw/4g/monitor.asp?k=MW2_SRV_HTML_STOCK_INFO_1_ABT
 public static string GetURLResponse(string strURL)
 {
     try
     {
         string s = strURL.ToLower();
         if (s.Substring(0, 8) == "https://")
         {
             return(GetURLResponseHTTPS(strURL));
         }
         if (s.Substring(0, 7) == "http://")
         {
             return(GetURLResponseHTTP(strURL));
         }
         return("");
     }
     catch (Exception ex)
     {
         // log error
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return("");
     }
 }
Пример #23
0
        public static string GetURLResponseHTTPS(string strURL)
        {
            try
            {
                WebRequest request = WebRequest.Create(strURL);
                request.Proxy       = null;
                request.Credentials = CredentialCache.DefaultCredentials;

                //allows for validation of SSL certificates
                ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);

                HttpWebResponse response           = (HttpWebResponse)request.GetResponse();
                Stream          dataStream         = response.GetResponseStream();
                StreamReader    reader             = new StreamReader(dataStream);
                string          responseFromServer = reader.ReadToEnd();
                return(responseFromServer);
            }
            catch (System.Exception ex)
            {
                // log error
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return("");
            }
        }
Пример #24
0
        /// <summary>
        /// 11:01 AM Wednesday, March 16, 2016
        /// log all var to file text de debug nguyen nhan error
        /// http://stackoverflow.com/questions/6536163/how-to-list-all-variables-of-class
        /// </summary>
        /// <param name="objAny"></param>
        public static string AllFields2LogFile(string strVarName, object objAny)
        {
            try
            {
                if (objAny == null)
                {
                    return("null");
                }

                BindingFlags bindingFlags = BindingFlags.Public |
                                            BindingFlags.NonPublic |
                                            BindingFlags.Instance |
                                            BindingFlags.Static;

                StringBuilder sbBody = new StringBuilder("");
                foreach (FieldInfo field in objAny.GetType().GetFields(bindingFlags))
                {
                    string strFieldName  = field.Name;
                    string strFieldValue = GetValueOfField(objAny, field, strFieldName);

                    sbBody.Append("" + strFieldName + " = " + strFieldValue + ""
                                  + Environment.NewLine
                                  + SEPARATOR
                                  + Environment.NewLine);
                }
                string strFileName = strVarName + "___" + DateTime.Now.ToString(FORMAT_TIME) + FILE_EXT;  // "dd/MM/yyyy HH:mm";// (24/10/2012 15:36)
                CLog.LogEx(strFileName, sbBody.ToString());

                return(strFileName);
            }
            catch (Exception ex)
            {
                CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
                return("");
            }
        }