public object Exec(RoutingModel route, ParamContainer helper) { if (route.auth_users.FirstOrDefault(f => f.Trim() == "*") == null) { ISessionProvider sessionProvider = helper.GetKey(CommonConst.CommonValue.PARAM_SESSION_PROVIDER); IHttpContextProxy httpProxy = helper.GetKey(CommonConst.CommonValue.PARAM_HTTPREQUESTPROXY); if (sessionProvider == null || httpProxy == null) { string error = "ActionExecuter.Exec sessionProvider is null or HttpContextProxy is null on ParamContainer"; _logger.Error(error); throw new UnauthorizedAccessException(error); } var authToken = httpProxy.GetHeaders().FirstOrDefault(f => f.Key.ToLower() == ""); var sessionUser = sessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); // add auth here. if (sessionUser == null) { throw new UnauthorizedAccessException("No session user found"); } if (!route.auth_users.Where(i => sessionUser.groups.Contains(i)).Any()) { throw new UnauthorizedAccessException("Unauthorized"); } return(Exec(route.ExecultAssembly, route.ExecuteType, route.ExecuteMethod, helper)); } else { return(Exec(route.ExecultAssembly, route.ExecuteType, route.ExecuteMethod, helper)); } }
public ApiBaseService(ParamContainer paramContainer) : base(paramContainer) { HttpProxy = paramContainer.GetKey(CommonConst.CommonValue.PARAM_HTTPREQUESTPROXY); Route = paramContainer.GetKey(CommonConst.CommonValue.PARAM_ROUTE); SessionProvider = paramContainer.GetKey(CommonConst.CommonValue.PARAM_SESSION_PROVIDER); }
public JObject Upload() { try { if (_fileUploader.GetFiles().Count == 0) { Logger.Error("No File Found for upload"); return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } string uploadCollection = _paramContainer.GetKey(CommonConst.CommonValue.COLLECTION); if (string.IsNullOrEmpty(uploadCollection)) { uploadCollection = CommonConst.Collection.STATIC_CONTECT; } string storegeType = _paramContainer.GetKey("storege_type"); string baseFolder = _paramContainer.GetKey(CommonConst.CommonValue.BASE_PATH); if (storegeType.Trim().ToLower() == "file") { var fileName = _fileUploader.GetFiles()[0]; string filePath = string.Format("{0}\\{1}", baseFolder, fileName); var reponse = _fileUploader.Save(fileName, filePath); if (!string.IsNullOrEmpty(reponse)) { return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS)); } else { Logger.Error("_fileUploader.Save fail"); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } } else { if (string.IsNullOrEmpty(baseFolder)) { baseFolder = "/"; } JObject fileResonse = _fileUploader.SaveToDB(DBProxy, _fileUploader.GetFiles()[0], baseFolder, uploadCollection); if (fileResonse[CommonConst.CommonField.DATA] != null) { fileResonse.Remove(CommonConst.CommonField.DATA); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, fileResonse)); } else { Logger.Error("_fileUploader.SaveToDB fail"); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR, fileResonse)); } } } catch (Exception ex) { Logger.Error(string.Format("Error in FileUploadController.Upload : {0} ", ex.Message), ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
private static void ExecEvent(IActionExecuter actionExecuter, RoutingModel route, ParamContainer paramContainer, Models.ExecutionEventType eventType) { IDBService dbProxy = paramContainer.GetKey(CommonConst.CommonValue.PARAM_DBPROXY); ILogger logger = paramContainer.GetKey(CommonConst.CommonValue.PARAM_LOGGER); foreach (var eventSubscriber in EventSubscription.GetInstance(dbProxy, logger).GetSubscriptions(route.GetEventName(), eventType)) { actionExecuter.Exec(eventSubscriber.ExecultAssembly, eventSubscriber.ExecuteType, eventSubscriber.ExecuteMethod, paramContainer); } }
public JObject GetGallery() { try { var id = HttpProxy.GetQueryString(CommonConst.CommonField.DISPLAY_ID); if (_paramContainer.GetKey(CommonConst.CommonField.DISPLAY_ID) != null) { id = (string)_paramContainer.GetKey(CommonConst.CommonField.DISPLAY_ID); Logger.Debug(string.Format("Filter on Gallery {0}", id)); ; } if (string.IsNullOrEmpty(id)) { return(GetAllGalleries()); } else { return(GetGalleryImages(id)); } } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject GetBlocks() { try { JObject filter = new JObject(); filter[CommonConst.CommonField.IS_ENABLED] = true; string filterPage = string.Empty; var page = _paramContainer.GetKey(PAGE); if (page != null) { filterPage = page.ToString(); } var data = DBProxy.Get(ZBLOCK_COLLECTION, filter.ToString(), new List <string>() { CommonConst.CommonField.DATA_KEY, PAGES, INDEX, BLOCK_PATH, DISPLAY_AREA }); data = new JArray(data.Where(f => f[PAGES] != null && (f[PAGES] as JArray).Where(f1 => f1.ToString() == filterPage).Count() != 0).OrderBy(f => (int)f[INDEX])); Logger.Debug("Enter to Get Blocks"); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, data)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public bool Send() { Logger.Info("Start TextLocalSMSController.Send"); string sms_id = _paramContainer.GetKey(TextLocalConsts.SMS_QUEUE_ID); if (string.IsNullOrEmpty(sms_id)) { Logger.Error("sms_id is null"); ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR); } var smsData = DBProxy.FirstOrDefault(CommonConst.Collection.SMS_QUEUE, CommonConst.CommonField.DISPLAY_ID, sms_id); if (smsData == null) { Logger.Error("sms_data is null"); ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR); } var phone = smsData[CommonConst.CommonField.PHONE].ToString(); var textSMSData = smsData[CommonConst.CommonField.BODY].ToString(); string apiKey = AppSettingService.GetAppSettingData(TextLocalConsts.TEXT_LOCAL_SMS_GATEWAY_KEY); string endPoint = AppSettingService.GetAppSettingData(TextLocalConsts.TEXT_LOCAL_SMS_GATEWAY_ENDPOINT); string fromPhone = AppSettingService.GetAppSettingData(TextLocalConsts.SMS_FROM); return(TextLocalSMSHelper.SendSMS(textSMSData, phone, apiKey, endPoint, fromPhone, Logger)); }
internal void Exec(JObject cronJob) { try { IActionExecuter actionExecuter = new ActionExecuter(_logger); ParamContainer pamamContainer = CreateParamContainer(_logger, actionExecuter); pamamContainer.AddKey(CommonConst.CommonValue.PARAM_CRON_JOB_OBJ, () => { return(cronJob); }); IDBService dbProxy = pamamContainer.GetKey(CommonConst.CommonValue.PARAM_DBPROXY); var filter = new JObject(); filter[CommonConst.CommonField.DISPLAY_ID] = cronJob[CommonConst.CommonField.DISPLAY_ID]; cronJob[CommonConst.CommonField.STATUS] = CommonConst.CommonValue.INPROGRESS; cronJob[CommonConst.CommonField.TRANSACTION_ID] = _logger.TransactionId; var startDatetime = DateTime.Now; cronJob[CommonConst.CommonField.LAST_EXEC_ON] = startDatetime.ToString(); cronJob[CommonConst.CommonField.ERR_MESSAGE] = string.Empty; if (cronJob[CommonConst.CommonField.HISTORY] == null) { cronJob[CommonConst.CommonField.HISTORY] = new JArray(); } else { while ((cronJob[CommonConst.CommonField.HISTORY] as JArray).Count >= 10) { (cronJob[CommonConst.CommonField.HISTORY] as JArray).Remove((cronJob[CommonConst.CommonField.HISTORY] as JArray)[0]); } } dbProxy.Update(CommonConst.Collection.CRON_JOB, filter.ToString(), cronJob, false, MergeArrayHandling.Replace); try { object resonse = actionExecuter.Exec(cronJob[CommonConst.CommonField.EXECULT_ASSEMBLY].ToString(), cronJob[CommonConst.CommonField.EXECUTE_TYPE].ToString(), cronJob[CommonConst.CommonField.EXECUTE_METHOD].ToString(), pamamContainer); cronJob[CommonConst.CommonField.STATUS] = CommonConst.CommonValue.FINISH; } catch (Exception ex) { cronJob[CommonConst.CommonField.ERR_MESSAGE] = ex.Message; cronJob[CommonConst.CommonField.STATUS] = CommonConst.CommonValue.FINISH_WITH_ERROR; } finally { cronJob[CommonConst.CommonField.DURATION] = (DateTime.Now - startDatetime).TotalMilliseconds; JObject history = new JObject(); history[CommonConst.CommonField.START_ON] = startDatetime.ToString(); history[CommonConst.CommonField.DURATION] = cronJob[CommonConst.CommonField.DURATION]; history[CommonConst.CommonField.STATUS] = cronJob[CommonConst.CommonField.STATUS]; if (cronJob[CommonConst.CommonField.ERR_MESSAGE] != null) { history[CommonConst.CommonField.ERR_MESSAGE] = cronJob[CommonConst.CommonField.ERR_MESSAGE]; } history[CommonConst.CommonField.TRANSACTION_ID] = _logger.TransactionId; (cronJob[CommonConst.CommonField.HISTORY] as JArray).Add(history); } dbProxy.Update(CommonConst.Collection.CRON_JOB, filter.ToString(), cronJob, false, MergeArrayHandling.Replace); } catch (Exception ex) { _logger.Error(ex.Message, ex); } }
public int Sync() { try { return(0); Logger.Debug("Calling CronJob ImageBackgroundSync"); JObject crobJob = _paramContainer.GetKey(CRON_JOB); var file_path = AppSettingService.GetAppSettingData("my_photo_path"); Logger.Debug("Calling CronJob ImageBackgroundSync FilePath " + file_path); if (string.IsNullOrEmpty(file_path)) { Logger.Error("No file path from App setting"); return(0); } ImageProcessor ip = new ImageProcessor(); ip.Scan(file_path, string.Empty, DBProxy, KeyValueStorage, (string mesage) => { Logger.Debug(string.Format("ImageBackgroundSync: {0}", mesage)); return(true); }); return(1); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(0); } }
public bool Send() { try { string emailQueueId = _paramContainer.GetKey(CommonConst.CommonValue.EMAIL_QUEUE_ID); if (string.IsNullOrEmpty(emailQueueId)) { Logger.Error("Error : emailQueueId not found"); return(false); } var emailData = DBProxy.FirstOrDefault(CommonConst.Collection.EMAIL_QUEUE, CommonConst.CommonField.DISPLAY_ID, emailQueueId); if (emailData == null) { Logger.Error(string.Format("Error : emailData not found for id : {0}", emailQueueId)); return(false); } MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(AppSettingService.GetAppSettingData(CommonConst.CommonField.SMTP_SERVER)); mail.From = new MailAddress(emailData[CommonConst.CommonField.FROM].ToString()); foreach (var item in emailData[CommonConst.CommonField.TO]) { mail.To.Add(item.ToString()); } mail.Subject = emailData[CommonConst.CommonField.SUBJECT].ToString(); mail.Body = emailData[CommonConst.CommonField.BODY].ToString(); mail.IsBodyHtml = true; int port = 587; int.TryParse(AppSettingService.GetAppSettingData(CommonConst.CommonField.SMTP_SERVER_PORT), out port); SmtpServer.Port = port; var user = AppSettingService.GetAppSettingData(CommonConst.CommonField.SMTP_SERVER_USER); var password = AppSettingService.GetAppSettingData(CommonConst.CommonField.SMTP_SERVER_PASSWORD); SmtpServer.Credentials = new System.Net.NetworkCredential(user, password); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); return(true); } catch (Exception ex) { Logger.Error(string.Format("Error sending email : {0}", ex.Message), ex); return(false); } }
public CronServiceBase(ParamContainer paramContainer) : base(paramContainer) { Routings = (IRouting)paramContainer.GetKey(CommonConst.CommonValue.PARAM_ROUTING_OBJECT); }
public AlbumCtrl(ParamContainer paramContainer) : base(paramContainer) { _fileUploader = paramContainer.GetKey(CommonConst.CommonValue.PARAM_HTTPREQUESTPROXY); }
public ViewBaseService(ParamContainer paramContainer) : base(paramContainer) { ContentHandler = paramContainer.GetKey(CommonConst.CommonValue.PARAM_CONTENT_HANDLER); }
public BaseService(ParamContainer paramContainer) { DBProxy = paramContainer.GetKey(CommonConst.CommonValue.PARAM_DBPROXY); Logger = paramContainer.GetKey(CommonConst.CommonValue.PARAM_LOGGER); ActionExecuter = paramContainer.GetKey(CommonConst.CommonValue.PARAM_ACTIONEXECUTER); PingService = paramContainer.GetKey(CommonConst.CommonValue.PARAM_PING_SERVICE); ResponseBuilder = paramContainer.GetKey(CommonConst.CommonValue.PARAM_RESPONBUILDER); ViewEngine = paramContainer.GetKey(CommonConst.CommonValue.PARAM_VIEW_ENGINE); AppSettingService = paramContainer.GetKey(CommonConst.CommonValue.PARAM_APP_SETTING); OTPService = paramContainer.GetKey(CommonConst.CommonValue.PARAM_OTP_SERVICE); SMSService = paramContainer.GetKey(CommonConst.CommonValue.PARAM_SMS_SERVICE); EmailService = paramContainer.GetKey(CommonConst.CommonValue.PARAM_EMAIL_SERVICE); EncryptionService = paramContainer.GetKey(CommonConst.CommonValue.PARAM_ENCRYPTION_SERVICE); KeyValueStorage = paramContainer.GetKey(CommonConst.CommonValue.PARAM_KEY_VALUE_STORAGE); HttpClient = paramContainer.GetKey(CommonConst.CommonValue.PARAM_HTTP_CLIENT); }
public void Exec(RoutingModel route, IHttpContextProxy httpProxy) { ILogger loggerController = Logger.GetLogger(route.ExecuteType, httpProxy.TransactionId); RouteEventHandler routeEventHandler = new RouteEventHandler(); try { loggerController.Info(string.Format("{0}:: Route: [{1}]", "RouteExecuter.Exec", route.ToString())); IActionExecuter actionExecuter = new ActionExecuter(loggerController); ParamContainer paramContainer = ActionExecuterHelper.CreateParamContainer(route, httpProxy, loggerController, actionExecuter); WriteStartTransaction(loggerController, httpProxy, route); (paramContainer.GetKey(CommonConst.CommonValue.PARAM_SESSION_PROVIDER) as ISessionProvider).SetValue(CommonConst.CommonField.UPDATED_DATE_TIME, CommonUtility.GetUnixTimestamp(DateTime.Now)); // Execute before Events routeEventHandler.ExecBeforeEvent(actionExecuter, route, paramContainer); var objResult = actionExecuter.Exec(route, paramContainer); httpProxy.ContentType = route.ContentType; // Add response in param paramContainer.AddKey(CommonConst.CommonValue.PARAM_API_RESPONSE, () => { return(objResult); }); if (objResult == null) { httpProxy.SetResponse(CommonConst._500_SERVER_ERROR); } else if (objResult is byte[]) { WriteEndTransaction(loggerController, "*** Binary Data ***"); httpProxy.SetResponse(CommonConst._200_OK, (byte[])objResult); } else if (objResult is string) { WriteEndTransaction(loggerController, (objResult as string)); httpProxy.SetResponse(CommonConst._200_OK, objResult as string); } else { var responseData = (objResult as JObject).ToString(); WriteEndTransaction(loggerController, responseData); httpProxy.SetResponse(CommonConst._200_OK, responseData); } // Execute after Events routeEventHandler.ExecAfterEvent(actionExecuter, route, paramContainer, objResult); // List<string> userGroups = _httpProxy.GetSessionUserGroups(); // if (route.auth_users.Count == 0 || userGroups.Intersect(route.auth_users).Any()) // { // var objResult = routeExecuter.Exec(route, helper); // if (objResult == null) // { // SetInternalServerError(); // return null; // } // else if (objResult is byte[]) // { // return (byte[])objResult; // } // else // { // return Encoding.UTF8.GetBytes((objResult as JObject).ToString()); // } // } // else // { // SetUnauthorized(); // return Encoding.UTF8.GetBytes((ZApp.Common.HttpUtility.GetFullResponse((int)ResponseCodes.Unauthorized, ResponseCodes.Unauthorized.ToString(), null)).ToString()); // } } catch (UnauthorizedAccessException ex) { loggerController.Error(string.Format("Error While executing Route : {0}, Error : {1}", route.ToString(), ex.Message), ex); httpProxy.SetResponse(CommonConst._401_UNAUTHORIZED); } catch (Exception ex) { httpProxy.SetResponse(CommonConst._500_SERVER_ERROR); loggerController.Error(string.Format("Error While executing Route : {0}, Error : {1}", route.ToString(), ex.Message), ex); } }
public FileUploadController(ParamContainer paramContainer) : base(paramContainer) { _fileUploader = paramContainer.GetKey(CommonConst.CommonValue.PARAM_HTTPREQUESTPROXY); _paramContainer = paramContainer; }
public EventSubscriberCompletedBaseService(ParamContainer paramContainer) : base(paramContainer) { APIRsponse = paramContainer.GetKey(CommonConst.CommonValue.PARAM_API_RESPONSE); }
public UpdateUserInfo(ParamContainer paramContainer) : base(paramContainer) { _fileUploader = paramContainer.GetKey(CommonConst.CommonValue.PARAM_HTTPREQUESTPROXY); _paramContainer = paramContainer; }