/// <summary> /// Gets JavaScript that mobile apps need to properly display pages using Page Content Service /// </summary> /// <param name="type">Type of JavaScript bundle to fetch</param> /// <returns>DownloadableArtifact information. NULL on errors.</returns> public async Task <DownloadableArtifact> GetJavaScript(JavaScriptType type = JavaScriptType.PageLib) { StringBuilder uri = new StringBuilder(); uri.Append(ENDPOINT_BASE_URI).Append("data/javascript/mobile/") .Append(Enum.GetName(typeof(JavaScriptType), type).ToLower()); // Since we get a download, we cannot use the GET() method in the base. RestApi.RestApiClient client = new RestApi.RestApiClient(new Uri(uri.ToString())); client.RequestHeaders.Add("Accept", "text/javascript"); HttpResponseMessage responseMessage = client.Get(); if (responseMessage.IsSuccessStatusCode) { return(new DownloadableArtifact() { ContentLength = responseMessage.Content.Headers.ContentLength.Value, ContentType = responseMessage.Content.Headers.ContentType.MediaType, Stream = await responseMessage.Content.ReadAsStreamAsync() }); } return(null); }
/// <summary> /// Declares a method presentend in the automatically-generated JavaScript API for a file/object of this type. /// </summary> /// <param name="name">The method name in the JavaScript API. JavaScript does not support overloading, so use different names for variations on arguments or web methods.</param> /// <param name="webMethod">The web request method, either GET, POST, or PUT</param> /// <param name="documentation">The method's documention that's put into metadata</param> /// <param name="returnType">The kind of value returned by the method, either a value or a JSON-encoded object</param> public JavaScriptMethodAttribute(string name, WebMethod webMethod, string documentation, JavaScriptType returnType) { _Name = name; _WebMethod = webMethod; _Documentation = documentation; _ReturnType = ReturnType; }
public void ExecuteJavaScriptTest(string script, JavaScriptValue[] arguments, JavaScriptType expectedType) { var executor = new TypedJavaScriptExecutor( driver.JavaScriptExecutor()); var result = executor.ExecuteJavaScript( script, arguments); object castedResult = null; if (expectedType == JavaScriptType.Boolean) { castedResult = result.ToBool(); } else if (expectedType == JavaScriptType.BooleanArray) { castedResult = result.ToBoolArray(); } else if (expectedType == JavaScriptType.Number) { castedResult = result.ToNumber(); } else if (expectedType == JavaScriptType.NumberArray) { castedResult = result.ToNumberArray(); } else if (expectedType == JavaScriptType.String) { castedResult = result.ToString(); } else if (expectedType == JavaScriptType.StringArray) { castedResult = result.ToStringArray(); } else if (expectedType == JavaScriptType.WebElement) { castedResult = result.ToWebElement(); } else if (expectedType == JavaScriptType.WebElementArray) { castedResult = result.ToWebElementArray(); } Assert.AreEqual(result.GetArgumentType(), expectedType); if (expectedType != JavaScriptType.Null) { Assert.IsNotNull(castedResult); } else { Assert.IsNull(castedResult); } }
/// <summary> /// Initializes a new instance of the <see cref="JavaScriptValue"/> class. /// </summary> /// <param name="argument"> /// The argument. An exception will be thrown if it the type is /// supported /// </param> /// <param name="javaScriptType"> /// Type of the JavaScript value will be checked against the actual /// type of argument and will throw an exception if they don't match. /// </param> /// <exception cref="InvalidCastException"></exception> public JavaScriptValue(object argument, JavaScriptType?javaScriptType = null) { this.argument = argument; var typeOfArg = GetJavaScripType(argument); if (javaScriptType != null && typeOfArg != javaScriptType.Value) { throw new InvalidCastException($"Failed to cast the argument " + $"({argument.GetType().Name}) to the provided type."); } this.javaScriptType = typeOfArg; }
public async Task <WebConfigSetting> Save(JObject data) { dynamic dataDto = data; bool isMasterDataSetting = dataDto.IsMasterDataSetting; string value = dataDto.Value; string key = dataDto.Key; int id; JavaScriptType javaScriptType = dataDto.JavaScriptType; try { id = dataDto.MasterDataKeyValueId; } catch (Exception) { id = 0; } if (isMasterDataSetting) { var masterData = await _contentManagementContext.MasterDataKeyValues.FirstOrDefaultAsync( md => md.Id == id); if (masterData == null) { throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.SettingNotFound)); } key = masterData.Code; value = Helper.GetPropertyValueByName(masterData, Convert.ToString(dataDto.MasterDataKeyValuePropertyName)); } var setting = new WebConfigSetting() { Key = key, Value = value, InjectToJavaScript = dataDto.InjectToJavaScript, Description = dataDto.Description, MasterDataKeyValueId = id, MasterDataKeyValuePropertyName = dataDto.MasterDataKeyValuePropertyName, JavaScriptType = javaScriptType.ToString() }; var option = JsonConvert.SerializeObject(setting); _webConfigManager.AddOrUpdateSetting(key, value, option); setting.Key = key; setting.Value = value; return(setting); }
private void AssociateToServiceGlobalType(string serviceName, string providerFunctionName, IExpressionOrSpread providerExpression) { var constructedFactoryType = providerExpression.GetJsType(context, new JsCyclicFlowAccumulator()). GetConstructedType(JsUnresolvedTypeArray.NoList); // The type of the service is the return type of the $get property, if it's a function. // If it's an array literal injectable, we need to add the association later, so create // a composite type that allows us to add it later var providerGetReturnType = constructedFactoryType.GetPropertyReferenceType("$get").GetReturnType(); var providerGetGlobalType = GetProviderGetGlobalType(providerFunctionName); var serviceType = JavaScriptType.CreateCompositeType(JsCombinedTypeKind.JsDynamic, providerGetReturnType, providerGetGlobalType); var offset = context.GetDocumentStartOffset(providerExpression); AssociateToServiceGlobalType(serviceName, serviceType, offset); }
private void AssociateToProviderGlobalType(string serviceName, string providerFunctionName, IJavaScriptTypedExpression providerExpression) { var providerGlobalType = GetHiddenGlobalPropertyType(serviceName + ProviderSuffix); // The type of the injected provider is the constructed type of the provider factory // function. But the referenced expression might not be a factory function, but an // injectable array literal. Create a composite type that we can populate later, when // we see a provider-like function (e.g. a function ending in Provider) var constructedFactoryType = providerExpression.GetJsType(context, new JsCyclicFlowAccumulator()). GetConstructedType(JsUnresolvedTypeArray.NoList); var providerFunctionGlobalType = GetProviderFunctionGlobalType(providerFunctionName); var providerType = JavaScriptType.CreateCompositeType(JsCombinedTypeKind.JsDynamic, constructedFactoryType, providerFunctionGlobalType); // We can't provide a decent offset here. But do we need to? CreateAssignmentAssociation(providerGlobalType, providerType, -1); }
/// <summary> /// Declares an argument in the automatically-generated JavaScript API for a file / object /// </summary> /// <param name="name">The arugment's name</param> /// <param name="type">The argument's type</param> /// <param name="description">The argument's description that shows up in documentation for this method</param> public JavaScriptArgumentAttribute(string name, JavaScriptType type, string description) { _Name = name; _Type = type; _Description = description; }