Пример #1
0
        public ResultStatus CreateLogging(LoggingObject log)
        {
            ResultStatus rs = new ResultStatus();

            try
            {
                DateTime createdTime = CurrentUser.GetCurrentDateTime();
                string   path        = HttpContext.Current.Server.MapPath("~/Log");
                string   fileName    = "TourismLog_" + createdTime.ToShortDateString().Replace("/", "-") + ".txt";
                string   pathFile    = Path.Combine(path, fileName);

                StreamWriter sw = new StreamWriter(pathFile, true);
                sw.WriteLine("===================================================" + createdTime.ToString() + "===================================================");
                sw.WriteLine("URL\t\t\t\t\t = " + log.Url);
                sw.WriteLine("Request\t\t\t\t\t = " + log.Request);
                sw.WriteLine("Respon\t\t\t\t\t = " + log.Respon);
                sw.WriteLine("Message\t\t\t\t\t = " + log.ExceptionMessage);
                sw.WriteLine("Stack\t\t\t\t\t = " + log.ExceptionStack);
                sw.WriteLine("=========================================================================================================================");
                sw.Close();

                rs.SetSuccessStatus();
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
            }

            return(rs);
        }
Пример #2
0
        /// <summary>
        /// use for retrived data one record
        /// </summary>
        /// <param name="param"></param>
        /// <param name="controller"></param>
        /// <param name="function"></param>
        /// <returns></returns>
        public static string RequestData(this object param, string controller, string method, string httpMethod)
        {
            LoggingObject log      = new LoggingObject();
            ResultStatus  rs       = new ResultStatus();
            string        pathApi  = Common.GetPathApi() + controller + "/" + method;
            Logging       logging  = new Logging();
            string        response = "";

            try
            {
                InvokeUrl url       = new InvokeUrl();
                string    qryString = "";

                if (httpMethod == EnumList.IHttpMethod.Post.ToString())
                {
                    qryString = ObjectToDictionaryHelper.GenericObjectToString(param);
                }

                if (httpMethod == EnumList.IHttpMethod.Put.ToString())
                {
                    qryString = param.ToString();
                }

                JObject jsonDes = JObject.Parse(url.ReturnJson(pathApi, httpMethod, qryString));
                response = jsonDes["Body"]["Data"][0].ToString();

                log.Url     = pathApi;
                log.Request = qryString;
                log.Respon  = response;
            }
            catch (Exception ex)
            {
                log.ExceptionMessage = ex.Message;
                log.ExceptionStack   = ex.StackTrace;
            }

            rs = logging.CreateLogging(log);

            return(response);
        }