public void ExtractValues(System.Collections.Specialized.IOrderedDictionary dictionary) { var conditionsJsonStr = conditions.Value; var expressionJsonStr = expression.Value; dictionary[ConditionsFieldName] = conditionsJsonStr; dictionary[ExpressionFieldName] = expressionJsonStr; if (RelexFieldName != null && !String.IsNullOrEmpty(conditionsJsonStr) && !String.IsNullOrEmpty(expressionJsonStr)) { var expressionData = JsHelper.FromJsonString <IDictionary <string, object> >(expressionJsonStr); var exprStr = Convert.ToString(expressionData["expression"]); if (String.IsNullOrEmpty(exprStr.Trim())) { dictionary[RelexFieldName] = "1=1"; } else { var fieldData = JsHelper.FromJsonString <IList <Dictionary <string, object> > >(fieldDescriptors.Value); var fieldTypeMapping = new Dictionary <string, string>(); var relexConditionMapping = new Dictionary <string, string>(); foreach (var fldData in fieldData) { fieldTypeMapping[Convert.ToString(fldData["name"])] = Convert.ToString(fldData["dataType"]); if (fldData.ContainsKey("relexcondition")) { relexConditionMapping[Convert.ToString(fldData["name"])] = Convert.ToString(fldData["relexcondition"]); } } dictionary[RelexFieldName] = QueryBuilderHelper.GenerateRelexFromQueryBuilder(JsHelper.FromJsonString <IList <IDictionary <string, object> > >(conditionsJsonStr), exprStr, fieldTypeMapping, relexConditionMapping); } } }
protected override IEnumerable GetControlSelectedIds() { var json = new JavaScriptSerializer(); var selectedList = JsHelper.FromJsonString <IList <IDictionary> >(selectedValues.Value); return(selectedList.Select(v => v["Key"]).ToArray()); }
public void ProcessRequest(HttpContext context) { var Request = context.Request; var Response = context.Response; log.Write(LogEvent.Info, "Processing FlexBox ajax request: {0}", Request.Url.ToString()); var dalcName = Request["dalc"]; var relex = Request["relex"]; var validationCode = Request["validate"]; if (!ValidateRequest(validationCode, dalcName, relex)) { log.Write(LogEvent.Error, "Validation failed for FlexBox ajax request: {0}", Request.Url.ToString()); throw new Exception("Invalid FlexBox ajax request"); } var relexByServiceName = WebManager.GetService <object>(relex); if (relexByServiceName != null) { relex = Convert.ToString(relexByServiceName); } var dalc = WebManager.GetService <IDalc>(dalcName); var labelField = Request["label"]; var filterPrvName = Request["filter"]; var relexParser = new RelExQueryParser(false); var exprResolver = WebManager.GetService <NI.Common.Expressions.IExpressionResolver>("defaultExprResolver"); var filterPrv = filterPrvName != null?WebManager.GetService <IProvider <IDictionary <string, object>, IDictionary <string, object> > >(filterPrvName) : null; var qContext = new Hashtable(); // directly passed query parameters foreach (string key in Request.Params.Keys) { if (key != null) { qContext[key] = Request.Params[key]; } } // legacy context format (left for compatibility) if (Request["context"] != null) { var deserializedCtx = JsHelper.FromJsonString <IDictionary <string, object> >(Request["context"]); foreach (var item in deserializedCtx) { qContext[item.Key] = JsHelper.FromJsonString(Convert.ToString(item.Value)); } } // actually used context if (Request["context_json"] != null) { var deserializedCtx = JsHelper.FromJsonString <IDictionary <string, object> >(Request["context_json"]); foreach (var item in deserializedCtx) { qContext[item.Key] = item.Value; } } Query q = (Query)relexParser.Parse(Convert.ToString(exprResolver.Evaluate(qContext, relex))); if (Request["action"] == "add" && Request["textfield"] != null && Request["valuefield"] != null) { var dbMgr = new DalcManager(dalc, WebManager.GetService <IDataSetProvider>("dsFactory")); var newEntryRow = dbMgr.Create(q.SourceName); newEntryRow[Request["textfield"]] = Request["value"]; dbMgr.Update(newEntryRow); Response.Write(JsHelper.ToJsonString(new Dictionary <string, object>(ConvertManager.ChangeType <IDictionary <string, object> >(newEntryRow)))); } else { if (Request["p"] != null && Request["s"] != null) { var pageSize = Convert.ToInt32(Request["s"]); q.StartRecord = (Convert.ToInt32(Request["p"]) - 1) * pageSize; q.RecordCount = pageSize; } var ds = new DataSet(); dalc.Load(ds, q); var res = new Dictionary <string, object>(); var results = new List <IDictionary <string, object> >(); foreach (DataRow r in ds.Tables[q.SourceName].Rows) { IDictionary <string, object> data = new Dictionary <string, object>(new DataRowDictionaryWrapper(r)); // process label field (if specified) if (!String.IsNullOrEmpty(labelField) && data.ContainsKey(labelField)) { data[labelField] = WebManager.GetLabel(Convert.ToString(data[labelField]), typeof(FlexBoxAjaxHandler).FullName); } // prevent security hole if (data.ContainsKey("password")) { data["password"] = null; } // filter if (filterPrv != null) { data = filterPrv.Provide(data); } if (data != null) { results.Add(data); } } res["total"] = dalc.RecordsCount(q.SourceName, q.Root); res["results"] = results; var json = new JavaScriptSerializer(); Response.Write(json.Serialize(res)); } }
protected override IEnumerable GetControlSelectedIds() { return(String.IsNullOrEmpty(selectedValues.Value) ? new object[0] : JsHelper.FromJsonString <IEnumerable>(selectedValues.Value)); }
protected void HandleUpload(HttpRequest Request, HttpResponse Response, string filesystem) { var fs = WebManager.GetService <IFileSystem>(filesystem); var result = new List <IFileObject>(); var resultFormat = Request["resultFormat"] ?? "text"; for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; // skip files with empty name; such a things happends sometimes =\ if (String.IsNullOrEmpty(file.FileName.Trim())) { continue; } var allowedExtensions = AssertHelper.IsFuzzyEmpty(Request["allowedextensions"]) ? null : JsHelper.FromJsonString <IList <string> >(HttpUtility.UrlDecode(Request["allowedextensions"])); var originalFileName = Path.GetFileName(file.FileName); var fileName = Request["dir"] != null && Request["dir"] != "" && Request["dir"] != "/" ? Path.Combine(Request["dir"], originalFileName) : originalFileName; log.Write(LogEvent.Debug, "Uploading - file name: {0}", fileName); if ((allowedExtensions != null && allowedExtensions.IndexOf(Path.GetExtension(fileName).ToLower()) < 0) || Array.IndexOf(blockedExtensions, Path.GetExtension(fileName).ToLower()) >= 0) { throw new Exception(WebManager.GetLabel(FileTreeAjaxHandler.InvalidFileTypeMessage)); } var uploadFile = fs.ResolveFile(fileName); var uploadPNGFile = fs.ResolveFile(fileName + ".png"); // additional checking of resized images if file names are similar if ((uploadFile.Exists() || uploadPNGFile.Exists()) && Request["overwrite"] != null && !Convert.ToBoolean(Request["overwrite"])) { int fileNum = 0; do { fileNum++; var extIdx = fileName.LastIndexOf('.'); var newFileName = extIdx >= 0 ? String.Format("{0}{1}{2}", fileName.Substring(0, extIdx), fileNum, fileName.Substring(extIdx)) : fileName + fileNum.ToString(); uploadFile = fs.ResolveFile(newFileName); } while (uploadFile.Exists() && fileNum < 100); if (uploadFile.Exists()) { var extIdx = fileName.LastIndexOf('.'); var uniqueSuffix = Guid.NewGuid().ToString(); uploadFile = fs.ResolveFile( extIdx >= 0 ? fileName.Substring(0, extIdx) + uniqueSuffix + fileName.Substring(extIdx) : fileName + uniqueSuffix); // 99.(9)% new file! } fileName = uploadFile.Name; } // special handling for images if (Request["image"] == "compressed" || Request["imageformat"] != null || Request["image_max_width"] != null || Request["image_max_height"] != null) { uploadFile = ImageHelper.SaveAndResizeImage( file.InputStream, fs, uploadFile, Convert.ToInt32(Request["image_max_width"] ?? "0"), Convert.ToInt32(Request["image_max_height"] ?? "0"), Request["imageformat"] != null ? ImageHelper.ResolveImageFormat(Request["imageformat"]) : null ); } else { uploadFile.CopyFrom(file.InputStream); } result.Add(uploadFile); } switch (resultFormat) { case "text": Response.Write(String.Join("\n", result.Select(f => f.Name).ToArray())); break; case "json": Response.Write(JsHelper.ToJsonString( result.Select(f => new Dictionary <string, object> { { "name", Path.GetFileName(f.Name) }, { "filepath", f.Name }, { "size", f.GetContent().Size }, { "url", VfsHelper.GetFileUrl(filesystem, f.Name) }, { "full_url", VfsHelper.GetFileFullUrl(filesystem, f.Name) } } ).ToArray())); break; } }