public static string ServerSidePageHandler(string requestUriPath, IDBService dbProxy, IHttpContextProxy httpProxy, IViewEngine viewEngine, IActionExecuter actionExecuter, ILogger logger, Dictionary <string, dynamic> pageModel = null) { var fi = new FileInfo(requestUriPath); var data = StaticContentHandler.GetStringContent(dbProxy, logger, requestUriPath); if (data != null) { if (pageModel == null) { pageModel = new Dictionary <string, dynamic>(); } var folderPath = requestUriPath.Replace(fi.Name, ""); UpdateBaseModel(pageModel, requestUriPath, fi.Name); data = viewEngine.Compile(data, requestUriPath, ServerPageModelHelper.SetDefaultModel(dbProxy, httpProxy, logger, viewEngine, actionExecuter, pageModel, folderPath)); if (pageModel.ContainsKey(CommonConst.CommonValue.PAGE_TEMPLATE_PATH)) { FileInfo fiTemplete = new FileInfo(pageModel[CommonConst.CommonValue.PAGE_TEMPLATE_PATH]); var templateFileData = StaticContentHandler.GetStringContent(dbProxy, logger, pageModel[CommonConst.CommonValue.PAGE_TEMPLATE_PATH]); pageModel[CommonConst.CommonValue.RENDERBODY_DATA] = data; data = viewEngine.Compile(templateFileData, pageModel[CommonConst.CommonValue.PAGE_TEMPLATE_PATH], ServerPageModelHelper.SetDefaultModel(dbProxy, httpProxy, logger, viewEngine, actionExecuter, pageModel, pageModel[CommonConst.CommonValue.PAGE_TEMPLATE_PATH].Replace(fiTemplete.Name, ""))); } return(data); } else { return(string.Empty); } }
public JObject Ping() { var data = _viewEngine.Compile($"Hello-- { DateTime.Now.ToString()} @Raw((1 + 1).ToString())", "aa", null); var dataResponse = new JObject(); dataResponse["data"] = data; return(_responseBuilder.Success(dataResponse)); }
public bool Send(List <string> toEmail, string fromEmail, List <string> CC, string emailTemplate, string subject, Dictionary <string, dynamic> modelData) { var emailTemplateData = _dbService.FirstOrDefault(CommonConst.Collection.EMAIL_TEMPLATE, CommonConst.CommonField.DATA_KEY, emailTemplate); if (emailTemplateData != null && emailTemplateData[CommonConst.CommonField.BODY] != null) { ServerPageModelHelper.AddBaseData(modelData); var emailBody = _viewEngine.Compile(emailTemplateData[CommonConst.CommonField.BODY].ToString(), emailTemplate, modelData); return(Send(toEmail, fromEmail, CC, emailBody, subject)); } else { _logger.Error(string.Format("Error Unable to find Email template {0}", emailTemplate)); return(false); } }
public bool Send(string toNumber, string textTemplate, Dictionary <string, dynamic> modelData, bool putInQueue = true) { var smsTemplateData = _dbService.FirstOrDefault(CommonConst.Collection.SMS_TEMPLATE, CommonConst.CommonField.DATA_KEY, textTemplate); if (smsTemplateData != null && smsTemplateData[CommonConst.CommonField.BODY] != null) { ServerPageModelHelper.AddBaseData(modelData); modelData[CommonConst.CommonField.PHONE] = toNumber; var textSMSData = _viewEngine.Compile(smsTemplateData[CommonConst.CommonField.BODY].ToString(), textTemplate, modelData); return(Send(toNumber, textSMSData, putInQueue)); } else { _logger.Error(string.Format("Error Unable to find SMS template {0}", textTemplate)); return(false); } }
private static Dictionary <string, dynamic> SetDefaultModel(IDBService dbProxy, IHttpContextProxy httpProxy, ILogger logger, IViewEngine viewEngine, IActionExecuter actionExecuter, Dictionary <string, dynamic> model, string folderPath = null) { ISessionProvider sessionProvider = new SessionProvider(httpProxy, dbProxy, logger); if (model == null) { model = new Dictionary <string, dynamic>(); } model[CommonConst.CommonValue.METHODS] = new Dictionary <string, dynamic>(); Func <string, string, JArray> getData = (string collection, string filter) => { return(dbProxy.Get(collection, filter)); }; Func <string, string> getAppSetting = (string key) => { var response = AppSettingService.Instance.GetAppSettingData(key); if (string.IsNullOrEmpty(response)) { response = ConfigurationManager.AppSettings[key]; } return(response); }; Func <string, JObject> getSessionValue = (string key) => { return(sessionProvider.GetValue <JObject>(key)); }; Func <string, string> includeTemplete = (string templatePath) => { FileInfo fi = new FileInfo(string.Format("c:\\{0}{1}", folderPath, templatePath)); string path = fi.FullName.Replace("c:", ""); model[CommonConst.CommonValue.PAGE_TEMPLATE_PATH] = path; return(string.Empty); }; Func <string, bool> authorized = (string authGroups) => { var sessionUser = sessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); if (sessionUser == null) { return(false); } if (!authGroups.Split(',').Where(i => sessionUser.groups.Contains(i)).Any()) { return(false); } else { return(true); } }; Func <string, JObject, JObject> ActionExecute = (string actionPath, JObject data) => { var param = ActionExecuterHelper.CreateParamContainer(null, httpProxy, logger, actionExecuter); if (data != null) { foreach (var item in data) { Func <dynamic> funcValue = () => { return(item.Value); }; param.AddKey(item.Key, funcValue); } } return(actionExecuter.Exec <JObject>(actionPath, dbProxy, param)); }; Func <string, JObject, Dictionary <string, dynamic> > IncludeModel = (string includeModelPath, JObject data) => { try { var param = ActionExecuterHelper.CreateParamContainer(null, httpProxy, logger, actionExecuter); Dictionary <string, dynamic> modelData = new Dictionary <string, dynamic>(); if (data != null) { foreach (var item in data) { Func <dynamic> funcValue = () => { return(item.Value); }; param.AddKey(item.Key, funcValue); } } object response = actionExecuter.Exec(includeModelPath, dbProxy, param); if (response is Dictionary <string, dynamic> ) { return(response as Dictionary <string, dynamic>); } else { throw new InvalidCastException(string.Format("Invalid respone from {0}", includeModelPath)); } } catch (UnauthorizedAccessException ex) { logger.Error(string.Format("Error While executing Route : {0}, Error : {1}", includeModelPath, ex.Message), ex); throw; } }; model[CommonConst.CommonValue.METHODS]["IncludeModel"] = IncludeModel; model[CommonConst.CommonValue.METHODS]["ExecuteAction"] = ActionExecute; model[CommonConst.CommonValue.METHODS]["InclueTemplate"] = includeTemplete; model[CommonConst.CommonValue.METHODS]["GetData"] = getData; Func <JObject> requestBody = () => httpProxy.GetRequestBody <JObject>(); model[CommonConst.CommonValue.METHODS]["RequestBody"] = requestBody; Func <string, string> queryString = (string key) => httpProxy.GetQueryString(key); model[CommonConst.CommonValue.METHODS]["QueryString"] = queryString; model[CommonConst.CommonValue.METHODS]["AppSetting"] = getAppSetting; model[CommonConst.CommonValue.METHODS]["GetSessionData"] = getSessionValue; model[CommonConst.CommonValue.METHODS]["Authorized"] = authorized; Func <string, JObject, string> includeBlock = (string blockPath, JObject blockModel) => { var inputBlockModel = new Dictionary <string, dynamic>(); if (blockModel != null) { foreach (var item in blockModel) { inputBlockModel[item.Key] = item.Value; } } if (model != null) { foreach (var item in model) { inputBlockModel[item.Key] = item.Value; } } FileInfo fi = new FileInfo(string.Format("c:\\{0}{1}", folderPath, blockPath)); string path = fi.FullName.Replace("c:", ""); var data = StaticContentHandler.GetStringContent(dbProxy, logger, path); data = viewEngine.Compile(data, path, ServerPageModelHelper.SetDefaultModel(dbProxy, httpProxy, logger, viewEngine, actionExecuter, inputBlockModel, path.Replace(fi.Name, ""))); return(data); }; model[CommonConst.CommonValue.METHODS]["Include"] = includeBlock; Func <string> randerBody = () => { if (model.ContainsKey(CommonConst.CommonValue.RENDERBODY_DATA)) { return(model[CommonConst.CommonValue.RENDERBODY_DATA]); } else { return(string.Empty); } }; model[CommonConst.CommonValue.METHODS]["RenderBody"] = randerBody; return(model); }