public ParameterResolverValue IntegerContent(IParameterResolverContext ctx, IList <ParameterResolverValue> args) { if (args.Count != 1) { throw new Exception("IntegerCountent declared with wrong number of arguments (must be 1)"); } ParameterResolverValue input = args[0]; if (input.Value != null) { if (long.TryParse(input.Value.ToString(), out long v)) { return(new ParameterResolverValue(v.ToString(), EResolverValueType.ContentType, (uint)EValueDataType.Text)); } else { throw new InvalidCastException("Cannot cast the input to integer!"); } } else { // This result will cause excepton if not handled in some special manner. return(new ParameterResolverValue(null, EResolverValueType.ContentType, (uint)EValueDataType.Text)); } }
public ParameterResolverValue Set(HostInteface ctx, ParameterResolverValue[] args) { if (args.Length % 2 != 0) { throw new ArgumentException("Set requires even number of arguments (varname, value, varname, value , ...."); } var count = args.Length / 2; var lastvalue = new ParameterResolverValue(); for (int i = 0; i < count; i++) { var name = args[i * 2].Value as string; var value = args[i * 2 + 1]; if (name != null) { _Variables[name] = value; lastvalue = value; } else { throw new ArgumentException($"Set - expected name of variable is not a string at argument index {i * 2}."); } } return(lastvalue); }
/// <summary> /// Check the maximum allowed file size per custom settings configuration if any. /// </summary> /// <param name="execContext">Execution context</param> /// <param name="fileRestrictions">Nullable long</param> private void CheckMaxFileSpacePerDashboard(IDataLoaderWriteContext execContext, Dictionary <string, long> fileRestrictions) { long bytes = 1048576L; if (fileRestrictions != null) { foreach (string key in fileRestrictions.Keys) { ParameterResolverValue resolverValue = execContext.Evaluate(key); long uploadedFilesSize = 0L; if (resolverValue.Value != null) { if (!long.TryParse(execContext.Evaluate(key).Value.ToString(), out uploadedFilesSize)) { throw new Exception($"Invalid configuration settings for key {key}."); } } long maxAllowedSize = bytes * (long)fileRestrictions[key]; if (maxAllowedSize < uploadedFilesSize + execContext.ProcessingContext.InputModel.Data.Values.Where(v => v is IPostedFile).Cast <IPostedFile>().Sum(pf => pf.Length)) { throw new Exception($"You cannot upload more than {fileRestrictions[key]} MB."); } } } }
private string FindValue(string name, IDataLoaderContext execContext, bool isWrite) { ParameterResolverValue parameterReolverValue = execContext.Evaluate(name); if (parameterReolverValue.Value != null && parameterReolverValue.ValueDataType == EValueDataType.Text) { return(parameterReolverValue.Value.ToString()); } else { string value = execContext.CurrentNode.Parameters.FirstOrDefault(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase))?.Expression; if (isWrite) { if (value == default(string)) { value = execContext.CurrentNode.Write?.Parameters.FirstOrDefault(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase))?.Expression; } } else { if (value == default(string)) { value = execContext.CurrentNode.Read?.Parameters.FirstOrDefault(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase))?.Expression; } } return(value); } }
//public async override Task<IPluginsSynchronizeContextScoped> GetSynchronizeContextScopedAsync() //{ // return await Task.FromResult(new ADOSynchronizeContextScopedDefault<MySqlConnection>()); //} protected override int?GetParameterType(ParameterResolverValue value) { if (int.TryParse(value.Value.ToString(), out int num)) { return((int)DbType.Int32); } return(null); }
protected override List <Dictionary <string, object> > Read(IDataLoaderReadContext execContext) { string baseUrl = execContext.DataLoaderContextScoped.CustomSettings["BaseUrl"]; ParameterResolverValue endpoint = execContext.Evaluate("endpoint"); ParameterResolverValue method = execContext.Evaluate("method"); var result = new List <Dictionary <string, object> >(); if (!(endpoint.Value is string)) { KraftLogger.LogError("HttpServiceImp endpoint parameter value must be string"); throw new Exception("endpoint value must be string"); } string url = baseUrl + endpoint.Value; var obj = this.GetHttpContent(url); result.Add(new Dictionary <string, object>() { { "key", obj } }); return(result); }
public ParameterResolverValue IntegerContent(IParameterResolverContext ctx, ParameterResolverValue input) { long v = 0; if (input.Value != null) { if (long.TryParse(input.ToString(), out v)) { return(new ParameterResolverValue(v.ToString(), EResolverValueType.ContentType, (uint)EValueDataType.Text)); } else { throw new InvalidCastException("Cannot cast the input to integer!"); } } else { // This result will cause excepton if not handled in some special manner. return(new ParameterResolverValue(null, EResolverValueType.ContentType, (uint)EValueDataType.Text)); } }
/// <summary> /// Reads uploaded file in predefined directory, /// sets the response builder of the return model of the processing context to BinaryResponseBuilder. /// </summary> /// <param name="execContext">Execution context</param> /// <returns>null</returns> protected override List <Dictionary <string, object> > Read(IDataLoaderReadContext execContext) { ReadCustomSettings settings = new ReadCustomSettings(execContext, execContext.PluginServiceManager.GetService <KraftGlobalConfigurationSettings>(typeof(KraftGlobalConfigurationSettings))); string filePreviewName = "FILE_preview.svg"; string previewName = "preview"; string file = execContext.Evaluate("path").Value.ToString(); string configuredDir = settings.UploadFolder; string defaultDir = settings.DefaultFolder; if (File.Exists(Path.Combine(configuredDir, file))) { ParameterResolverValue preview = execContext.Evaluate(previewName); if (preview.Value != null) { string previewValue = preview.Value.ToString(); if (previewValue == "1") { string previewFileName = GeneratePreviewName(file); if (File.Exists(Path.Combine(configuredDir, previewFileName))) { file = previewFileName; } else { string extension = Path.GetExtension(file); if (!string.IsNullOrWhiteSpace(extension)) { previewFileName = extension.Replace(".", string.Empty).ToUpper() + "_preview.svg"; if (File.Exists(Path.Combine(defaultDir, previewFileName))) { file = previewFileName; configuredDir = defaultDir; } else { file = filePreviewName; configuredDir = defaultDir; } } else { file = filePreviewName; configuredDir = defaultDir; } } } } } else { if (File.Exists(Path.Combine(defaultDir, settings.FileNotFoundIcon))) { configuredDir = defaultDir; file = settings.FileNotFoundIcon; } else { KraftLogger.LogError($"FileUploadImp-Read: File with name {file} was not found."); } } file = Path.Combine(configuredDir, file); string contentType; new FileExtensionContentTypeProvider().TryGetContentType(file, out contentType); execContext.ProcessingContext.ReturnModel.BinaryData = new PostedFile(contentType, 0, "currentlyNotSet", file, path => { return(File.Open(path as string, FileMode.Open)); }, file); execContext.ProcessingContext.ReturnModel.ResponseBuilder = new BinaryResponseBuilder(new ProcessingContextCollection(new List <IProcessingContext> { execContext.ProcessingContext })); return(null); }
private string FindValue(string name, IDataLoaderContext execContext) { ParameterResolverValue parameterReolverValue = execContext.Evaluate(name); return(parameterReolverValue.Value.ToString()); }
/// <summary> /// Guesses/determines appropriate database type for the value. Although this is done over a value it is usually the same /// for the corresponding field (if there is such). It is not determined in some more static manner, because we use resolvers /// and they record their result with the value. It is up to them to suggest a type dynamically or statically (the same for the /// same field, no matter what the actual data is). This way the developer can choose a resolver and pass parameters to it so /// that the desired behavior can be achieved. Lets not forget that we have this situation with DataLoaders that work with /// non-RDBMS storages - from outside the way we deal with value typing should follow the same patterns and use the same kind /// of instruments. /// </summary> /// <param name="value">The value for which to suggest type</param> /// <returns>Returns the type from the appropriate enum or set of constants casted to int in order to avoid the unneeded boxing. Int fits all! If no type can be /// suggested null should be returned and dealt appropriately in BindParameter.</returns> protected virtual int?GetParameterType(ParameterResolverValue value) { // Base behavior - say nothing, everything goes default. // In more specialized classes here is the place to perform mapping and/or type selection according to the application architectural concepts. return(null); }
public SymbolEntry(string name, ParameterResolverValue val) { Name = name; Value = val; }
public bool IsTruthyOrFalsy(ParameterResolverValue v) { return(ActionQueryHostBase.IsTruthyOrFalsy(v)); }
/// <summary> /// Converts a list/array to SQL content applicable in syntax like IN ( @here goes the list ) /// Supports numeric list and string list /// Arguments: /// - thelist - /// - null or regexp /// null - convert to numeric list /// regex - convert to string list, test each item against the regexp. /// </summary> /// <param name="ctx"></param> /// <param name="inargs"></param> /// <returns></returns> public ParameterResolverValue idlist(IParameterResolverContext ctx, IList <ParameterResolverValue> inargs) { ParameterResolverValue input = inargs[0]; ParameterResolverValue type_and_check = inargs[1]; StringBuilder sbresult = new StringBuilder(); if (!string.IsNullOrWhiteSpace(type_and_check.Value as string)) // RegExp { var re = type_and_check.Value as string; Regex rex = new Regex(re, RegexOptions.CultureInvariant | RegexOptions.Singleline); IEnumerable indata = null; if (input.Value is IDictionary) { indata = (input.Value as IDictionary).Values; } else { indata = input.Value as IEnumerable; } foreach (var v in indata) { if (v != null) { if (rex.IsMatch(v.ToString())) { if (sbresult.Length > 0) { sbresult.Append(','); } sbresult.AppendFormat("'{0}'", v.ToString()); } else { //don't stop execution when an item doesn't match? //throw new Exception("an item does not match YOUR regular expression"); } } else { throw new Exception("null item in a collection while converting to replacable idlist"); } } return(new ParameterResolverValue(sbresult.ToString(), EResolverValueType.ContentType)); } else if (type_and_check.Value == null && input.Value is IEnumerable) // Numbers { IEnumerable indata = null; if (input.Value is IDictionary) { indata = (input.Value as IDictionary).Values; } else { indata = input.Value as IEnumerable; } foreach (var v in indata) { if (sbresult.Length > 0) { sbresult.Append(','); } if (v is int || v is Int16 || v is Int32 || v is Int64) { sbresult.Append(Convert.ToInt64(v).ToString(CultureInfo.InvariantCulture)); } else if (v is uint || v is UInt16 || v is UInt32 || v is UInt64) { sbresult.Append(Convert.ToUInt64(v).ToString(CultureInfo.InvariantCulture)); } else if (v is float || v is double) { sbresult.Append(Convert.ToDouble(v).ToString(CultureInfo.InvariantCulture)); } else { throw new Exception("Non-numeric and non-null item found in the input"); } } return(new ParameterResolverValue(sbresult.ToString(), EResolverValueType.ContentType)); } else { throw new Exception("Unacceptable type parameter or the value is not enumerable"); } }