public object Bundle(string bundleDefinitionXml, string fileName, object update, object minify) { if (String.IsNullOrEmpty(fileName)) { fileName = "bundle.txt"; } var bUpdate = JurassicHelper.GetTypedArgumentValue(Engine, update, true); var bMinify = JurassicHelper.GetTypedArgumentValue(Engine, minify, false); var doc = new XmlDocument(); doc.LoadXml(bundleDefinitionXml); var bundleText = GenerateBundleFromBundleDefinition(fileName, doc, bUpdate, bMinify); var bytes = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, Encoding.UTF8.GetBytes(bundleText)) { FileName = fileName, MimeType = StringHelper.GetMimeTypeFromFileName(fileName), }; var result = Engine.Object.Construct(); result.SetPropertyValue("lastModified", JurassicHelper.ToDateInstance(Engine, FileModifiedDates.Values.Max(v => v.Item1)), false); result.SetPropertyValue("data", bytes, false); return(result); }
public SortInstance AddSortField( [JSDoc("(string) Name of the field to sort by")] string fieldName, [JSDoc("(bool) (Optional) Indicates whether or not to reverse the sort (false is ascending, true is descending). Default is false.")] object reverse, [JSDoc("(string) (Optional) Indicates the field type to sort by. Possible values are: string, byte, double, float, int, long, short, string value, doc and score. Default is score.")] object fieldType) { if (fieldName.IsNullOrWhiteSpace()) { throw new JavaScriptException(this.Engine, "Error", "A field name must be specified as the first argument."); } var reverseValue = JurassicHelper.GetTypedArgumentValue(this.Engine, reverse, false); var fieldTypeValue = JurassicHelper.GetTypedArgumentValue(this.Engine, fieldType, "string"); SortFieldType fieldTypeEnum; if (fieldTypeValue.TryParseEnum(true, out fieldTypeEnum) == false) { fieldTypeEnum = SortFieldType.String; } Sort.SortFields.Add(new SortField { FieldName = fieldName, Reverse = reverseValue, Type = fieldTypeEnum, }); return(this); }
public NumericRangeQueryInstance <float> CreateFloatRangeQuery(string fieldName, object min, object max, bool minInclusive, bool maxInclusive) { float?floatMin; if (min == null || min == Null.Value || min == Undefined.Value) { floatMin = null; } else { floatMin = JurassicHelper.GetTypedArgumentValue(Engine, min, 0); } float?floatMax; if (max == null || max == Null.Value || max == Undefined.Value) { floatMax = null; } else { floatMax = JurassicHelper.GetTypedArgumentValue(Engine, max, 0); } var query = new FloatNumericRangeQuery { FieldName = fieldName, Min = floatMin, Max = floatMax, MinInclusive = minInclusive, MaxInclusive = maxInclusive }; return(new NumericRangeQueryInstance <float>(Engine.Object.InstancePrototype, query)); }
public SPFeatureInstance ActivateFeature(object feature, object force) { var featureId = Guid.Empty; if (feature is string) { featureId = new Guid(feature as string); } else if (feature is GuidInstance) { featureId = (feature as GuidInstance).Value; } else if (feature is SPFeatureInstance) { featureId = (feature as SPFeatureInstance).Feature.DefinitionId; } else if (feature is SPFeatureDefinitionInstance) { featureId = (feature as SPFeatureDefinitionInstance).FeatureDefinition.Id; } if (featureId == Guid.Empty) { return(null); } var forceValue = JurassicHelper.GetTypedArgumentValue(Engine, force, false); var activatedFeature = m_site.Features.Add(featureId, forceValue); return(new SPFeatureInstance(Engine.Object.InstancePrototype, activatedFeature)); }
public void LoadFromJson(object array, object hasHeader) { if (array == null || array == Null.Value || array == Undefined.Value || (array is ArrayInstance) == false || (array as ArrayInstance).Length == 0) { return; } var jsonArray = array as ArrayInstance; var bHasHeader = JurassicHelper.GetTypedArgumentValue(this.Engine, hasHeader, true); List <string> header = null; //If we have a header, populate the first row with header info. var currentRow = 1; if (bHasHeader) { var firstRecord = jsonArray[0] as ObjectInstance; if (firstRecord == null) { return; } header = firstRecord.Properties .Select(property => property.Name) .ToList(); for (int i = 1; i < header.Count + 1; i++) { m_excelWorksheet.Cells[currentRow, i].Value = header[i - 1]; } currentRow++; } foreach (var value in jsonArray.ElementValues.OfType <ObjectInstance>()) { if (header == null) { var properties = value.Properties.ToList(); for (var c = 1; c < properties.Count + 1; c++) { var propertyValue = properties[c - 1]; SetValue(currentRow, c, propertyValue.Value); } } else { for (var c = 1; c < header.Count + 1; c++) { var key = header[c - 1]; var propertyValue = value[key]; SetValue(currentRow, c, propertyValue); } } currentRow++; } }
public static double Utc(ScriptEngine engine, int year, int month, [DefaultParameterValue(1)] object dayArg, [DefaultParameterValue(0)] object hourArg, [DefaultParameterValue(0)] object minuteArg, [DefaultParameterValue(0)] object secondArg, [DefaultParameterValue(0)] object millisecondArg) { var day = JurassicHelper.GetTypedArgumentValue(engine, dayArg, 1); var hour = JurassicHelper.GetTypedArgumentValue(engine, hourArg, 0); var minute = JurassicHelper.GetTypedArgumentValue(engine, minuteArg, 0); var second = JurassicHelper.GetTypedArgumentValue(engine, secondArg, 0); var millisecond = JurassicHelper.GetTypedArgumentValue(engine, millisecondArg, 0); return(DateInstance.Utc(engine, year, month, day, hour, minute, second, millisecond)); }
public string ToFixed([DefaultParameterValue(0)] object fractionDigitsArg) { var fractionDigits = JurassicHelper.GetTypedArgumentValue(this.Engine, fractionDigitsArg, 0); // Check the parameter is within range. if (fractionDigits < 0 || fractionDigits > 20) { throw new JavaScriptException(this.Engine, "RangeError", "toFixed() argument must be between 0 and 20."); } // NumberFormatter does the hard work. return(NumberFormatter.ToString(this.m_value, 10, NumberFormatter.Style.Fixed, fractionDigits)); }
public string ToStringJS([DefaultParameterValue(10)] object radixArg) { var radix = JurassicHelper.GetTypedArgumentValue(this.Engine, radixArg, 10); // Check the parameter is in range. if (radix < 2 || radix > 36) { throw new JavaScriptException(this.Engine, "RangeError", "The radix must be between 2 and 36, inclusive."); } // NumberFormatter does the hard work. return(NumberFormatter.ToString(this.m_value, radix, NumberFormatter.Style.Regular, 0)); }
public void Compile(string pattern, [DefaultParameterValue(null)] object flagsArg) { var flags = JurassicHelper.GetTypedArgumentValue <string>(this.Engine, flagsArg, null); this.m_value = new Regex(pattern, ParseFlags(flags) | RegexOptions.Compiled); // Update the javascript properties. this.FastSetProperty("source", pattern, PropertyAttributes.Sealed, false); this.FastSetProperty("global", this.Global, PropertyAttributes.Sealed, false); this.FastSetProperty("multiline", this.Multiline, PropertyAttributes.Sealed, false); this.FastSetProperty("ignoreCase", this.IgnoreCase, PropertyAttributes.Sealed, false); this.LastIndex = 0; }
public void Time([DefaultParameterValue("")] object nameArg) { var name = JurassicHelper.GetTypedArgumentValue(this.Engine, nameArg, "") ?? string.Empty; if (this.m_timers == null) { this.m_timers = new Dictionary <string, Stopwatch>(); } if (this.m_timers.ContainsKey(name)) { return; } this.m_timers.Add(name, Stopwatch.StartNew()); }
public TermsFilterInstance CreateTermsFilter(object fieldName, object text) { var fieldNameValue = JurassicHelper.GetTypedArgumentValue(Engine, fieldName, String.Empty); var textValue = JurassicHelper.GetTypedArgumentValue(Engine, text, String.Empty); var termsFilter = new TermsFilter(); if (fieldNameValue.IsNullOrWhiteSpace() == false && textValue.IsNullOrWhiteSpace() == false) { termsFilter.Terms.Add(new Term { FieldName = fieldNameValue, Value = textValue }); } return(new TermsFilterInstance(Engine.Object.InstancePrototype, termsFilter)); }
public void TimeEnd([DefaultParameterValue("")] object nameArg) { var name = JurassicHelper.GetTypedArgumentValue(this.Engine, nameArg, "") ?? string.Empty; if (this.m_timers == null || this.m_timers.ContainsKey(name) == false) { return; } var stopwatch = this.m_timers[name]; Log(FirebugConsoleMessageStyle.Regular, string.IsNullOrEmpty(name) ? string.Format("{0}ms", stopwatch.ElapsedMilliseconds) : string.Format("{0}: {1}ms", name, stopwatch.ElapsedMilliseconds)); this.m_timers.Remove(name); }
public static double ParseInt(ScriptEngine engine, string input, [DefaultParameterValue(0.0)] object radixArg) { var radix = JurassicHelper.GetTypedArgumentValue(engine, radixArg, 0.0); // Check for a valid radix. // Note: this is the only function that uses TypeConverter.ToInt32() for parameter // conversion (as opposed to the normal method which is TypeConverter.ToInteger() so // the radix parameter must be converted to an integer in code. int radix2 = TypeConverter.ToInt32(radix); if (radix2 < 0 || radix2 == 1 || radix2 > 36) { return(double.NaN); } return(NumberParser.ParseInt(input, radix2, engine.CompatibilityMode == CompatibilityMode.ECMAScript3)); }
public static ObjectInstance Create(ScriptEngine engine, object prototype, [DefaultParameterValue(null)] object propertiesArg) { var properties = JurassicHelper.GetTypedArgumentValue <ObjectInstance>(engine, propertiesArg, null); if ((prototype is ObjectInstance) == false && prototype != Null.Value) { throw new JavaScriptException(engine, "TypeError", "object prototype must be an object or null"); } ObjectInstance result = prototype == Null.Value ? ObjectInstance.CreateRootObject(engine) : ObjectInstance.CreateRawObject((ObjectInstance)prototype); if (properties != null) { DefineProperties(result, properties); } return(result); }
public static ArrayInstance Split(ScriptEngine engine, string thisObject, object separator, [DefaultParameterValue(4294967295.0)] object limitArg) { var limit = JurassicHelper.GetTypedArgumentValue(engine, limitArg, 4294967295.0); // Limit defaults to unlimited. Note the ToUint32() conversion. uint limit2 = uint.MaxValue; if (TypeUtilities.IsUndefined(limit) == false) { limit2 = TypeConverter.ToUint32(limit); } // Call separate methods, depending on whether the separator is a regular expression. if (separator is RegExpInstance) { return(Split(thisObject, (RegExpInstance)separator, limit2)); } return(Split(engine, thisObject, TypeConverter.ToString(separator), limit2)); }
public RegExpInstance Call(object patternOrRegExp, [DefaultParameterValue(null)] object flagsArg) { var flags = JurassicHelper.GetTypedArgumentValue <string>(this.Engine, flagsArg, null); if (patternOrRegExp is RegExpInstance) { // RegExp(/abc/) if (flags != null) { throw new JavaScriptException(this.Engine, "TypeError", "Cannot supply flags when constructing one RegExp from another"); } return((RegExpInstance)patternOrRegExp); } // RegExp('abc', 'g') var pattern = string.Empty; if (TypeUtilities.IsUndefined(patternOrRegExp) == false) { pattern = TypeConverter.ToString(patternOrRegExp); } return(new RegExpInstance(this.InstancePrototype, pattern, flags)); }
/// <summary> /// Splits this string into an array of strings by separating the string into substrings. /// </summary> /// <param name="thisObject"></param> /// <param name="separator"> A string that indicates where to split the string. </param> /// <param name="limitArg"> The maximum number of array items to return. Defaults to unlimited. </param> /// <param name="engine"></param> /// <returns> An array containing the split strings. </returns> public static ArrayInstance Split(ScriptEngine engine, string thisObject, string separator, [DefaultParameterValue(uint.MaxValue)] uint limitArg) { var limit = JurassicHelper.GetTypedArgumentValue(engine, limitArg, uint.MaxValue); if (string.IsNullOrEmpty(separator)) { // If the separator is empty, split the string into individual characters. var result = engine.Array.New(); for (int i = 0; i < thisObject.Length; i++) { result[i] = thisObject[i].ToString(CultureInfo.InvariantCulture); } return(result); } var splitStrings = thisObject.Split(new[] { separator }, StringSplitOptions.None); if (limit < splitStrings.Length) { var splitStrings2 = new string[limit]; Array.Copy(splitStrings, splitStrings2, (int)limit); splitStrings = splitStrings2; } return(engine.Array.New(splitStrings)); }
/// <summary> /// Splits the given string into an array of strings by separating the string into substrings. /// </summary> /// <param name="input"> The string to split. </param> /// <param name="limitArg"> The maximum number of array items to return. Defaults to unlimited. </param> /// <returns> An array containing the split strings. </returns> public ArrayInstance Split(string input, [DefaultParameterValue(uint.MaxValue)] object limitArg) { var limit = JurassicHelper.GetTypedArgumentValue(this.Engine, limitArg, uint.MaxValue); // Return an empty array if limit = 0. if (limit == 0) { return(this.Engine.Array.New(new object[0])); } // Find the first match. Match match = this.m_value.Match(input, 0); var results = new List <object>(); int startIndex = 0; Match lastMatch = null; while (match.Success) { // Do not match the an empty substring at the start or end of the string or at the // end of the previous match. if (match.Length == 0 && (match.Index == 0 || match.Index == input.Length || match.Index == startIndex)) { // Find the next match. match = match.NextMatch(); continue; } // Add the match results to the array. results.Add(input.Substring(startIndex, match.Index - startIndex)); if (results.Count >= limit) { return(this.Engine.Array.New(results.ToArray())); } startIndex = match.Index + match.Length; for (int i = 1; i < match.Groups.Count; i++) { var group = match.Groups[i]; if (group.Captures.Count == 0) { results.Add(Undefined.Value); // Non-capturing groups return "undefined". } else { results.Add(match.Groups[i].Value); } if (results.Count >= limit) { return(this.Engine.Array.New(results.ToArray())); } } // Record the last match. lastMatch = match; // Find the next match. match = match.NextMatch(); } results.Add(input.Substring(startIndex, input.Length - startIndex)); // Set the deprecated RegExp properties. if (lastMatch != null) { this.Engine.RegExp.SetDeprecatedProperties(input, lastMatch); } return(this.Engine.Array.New(results.ToArray())); }
/// <summary> /// Splits this string into an array of strings by separating the string into substrings. /// </summary> /// <param name="thisObject"></param> /// <param name="regExp"> A regular expression that indicates where to split the string. </param> /// <param name="limitArg"> The maximum number of array items to return. Defaults to unlimited. </param> /// <returns> An array containing the split strings. </returns> public static ArrayInstance Split(string thisObject, RegExpInstance regExp, [DefaultParameterValue(uint.MaxValue)] object limitArg) { var limit = JurassicHelper.GetTypedArgumentValue(regExp.Engine, limitArg, uint.MaxValue); return(regExp.Split(thisObject, limit)); }
public void DeleteRow(int rowFrom, int rows, object shiftOtherRowsUp) { var bShiftOtherRowsUp = JurassicHelper.GetTypedArgumentValue(this.Engine, shiftOtherRowsUp, false); m_excelWorksheet.DeleteRow(rowFrom, rows, bShiftOtherRowsUp); }
public void Select(string address, object selectSheet) { var bSelectSheet = JurassicHelper.GetTypedArgumentValue(this.Engine, selectSheet, false); m_excelWorksheet.Select(address, bSelectSheet); }
private SearchArguments CoerceSearchArguments(object query, object maxResults, object groupByFields) { var args = new Barista.Search.SearchArguments(); if (query == null || query == Null.Value || query == Undefined.Value) { args.Query = new MatchAllDocsQuery(); if (maxResults != Undefined.Value && maxResults != Null.Value && maxResults != null) { args.Take = JurassicHelper.GetTypedArgumentValue(Engine, maxResults, DefaultMaxResults); } } else if (TypeUtilities.IsString(query)) { args.Query = new QueryParserQuery { Query = TypeConverter.ToString(query) }; if (maxResults != Undefined.Value && maxResults != Null.Value && maxResults != null) { args.Take = JurassicHelper.GetTypedArgumentValue(Engine, maxResults, DefaultMaxResults); } if (groupByFields != null && groupByFields != Undefined.Value && groupByFields != Null.Value && groupByFields is ArrayInstance) { args.GroupByFields = ((ArrayInstance)groupByFields) .ElementValues .Select(t => TypeConverter.ToString(t)) .ToList(); } } else { var instance = query as SearchArgumentsInstance; if (instance != null) { var searchArgumentsInstance = instance; args = searchArgumentsInstance.GetSearchArguments(); } else if (query.GetType().IsAssignableFrom(typeof(IQuery <>))) { args = new SearchArguments(); var pi = typeof(IQuery <>).GetProperty("Query"); args.Query = (Query)pi.GetValue(query, null); } else { var obj = query as ObjectInstance; if (obj != null) { var argumentsObj = obj; args = new SearchArguments(); //Duck Type for the win if (argumentsObj.HasProperty("query")) { var queryObj = argumentsObj["query"]; var queryObjType = queryObj.GetType(); var queryProperty = queryObjType.GetProperty("Query", BindingFlags.Instance | BindingFlags.Public); if (queryProperty != null && typeof(Query).IsAssignableFrom(queryProperty.PropertyType)) { args.Query = queryProperty.GetValue(queryObj, null) as Query; } } else { var queryObjType = obj.GetType(); var queryProperty = queryObjType.GetProperty("Query", BindingFlags.Instance | BindingFlags.Public); if (queryProperty != null && typeof(Query).IsAssignableFrom(queryProperty.PropertyType)) { args.Query = queryProperty.GetValue(obj, null) as Query; } if (maxResults != Undefined.Value && maxResults != Null.Value && maxResults != null) { args.Take = JurassicHelper.GetTypedArgumentValue(Engine, maxResults, DefaultMaxResults); } } if (argumentsObj.HasProperty("filter")) { var filterObj = argumentsObj["filter"]; var filterObjType = filterObj.GetType(); var filterProperty = filterObjType.GetProperty("Filter", BindingFlags.Instance | BindingFlags.Public); if (filterProperty != null && typeof(Filter).IsAssignableFrom(filterProperty.PropertyType)) { args.Filter = filterProperty.GetValue(filterObj, null) as Filter; } } if (argumentsObj.HasProperty("groupByFields")) { var groupByFieldsValue = argumentsObj["groupByFields"] as ArrayInstance; if (groupByFieldsValue != null) { args.GroupByFields = groupByFieldsValue .ElementValues .Select(t => TypeConverter.ToString(t)) .ToList(); } } if (argumentsObj.HasProperty("sort") && argumentsObj["sort"] is SortInstance) { var sortValue = (SortInstance)argumentsObj["sort"]; args.Sort = sortValue.Sort; } if (argumentsObj.HasProperty("skip")) { var skipObj = argumentsObj["skip"]; args.Skip = TypeConverter.ToInteger(skipObj); } if (argumentsObj.HasProperty("take")) { var takeObj = argumentsObj["take"]; args.Take = TypeConverter.ToInteger(takeObj); } } else { throw new JavaScriptException(Engine, "Error", "Unable to determine the search arguments."); } } } return(args); }
public BooleanInstance Construct(object valueArg) { var value = JurassicHelper.GetTypedArgumentValue(this.Engine, valueArg, false); return(new BooleanInstance(this.InstancePrototype, value)); }
public ErrorInstance Construct([DefaultParameterValue("")] object messageArg) { var message = JurassicHelper.GetTypedArgumentValue(this.Engine, messageArg, ""); return(new ErrorInstance(this.InstancePrototype, null, message)); }