/// <summary> /// Compiles a lambda expression to JavaScript code. /// </summary> /// <param name="expr">Expression to compile to JavaScript.</param> /// <param name="options"> /// Conversion options: /// whether to include only the body of the lambda, /// whether to use a single scope parameter, /// what extensions to use (i.e. StaticStringMethods, StaticMathMethods, or any other custom extensions). /// </param> /// <returns>JavaScript code represented as a string.</returns> public static string CompileToJavascript( [NotNull] this LambdaExpression expr, ScriptVersion scriptVersion, params JavascriptConversionExtension[] extensions) { return(expr.CompileToJavascript(new JavascriptCompilationOptions(scriptVersion, extensions))); }
public ScriptVersion New(int scriptId, [FromBody] string body) { int?maxScriptVersion = _dbContext.ScriptVersion .Where(p => p.ScriptId.Equals(scriptId)) .OrderByDescending(p => p.Version) .Select(p => p.Version) .FirstOrDefault(); var userId = _ephItUser.Register().UserId; var scriptVersion = new ScriptVersion { CreatedByUserId = userId, Created = DateTime.UtcNow, Body = body, ScriptId = scriptId, Version = 1 }; if (maxScriptVersion.HasValue) { scriptVersion.Version = maxScriptVersion.Value + 1; } _dbContext.Add(scriptVersion); _dbContext.SaveChanges(); return(scriptVersion); }
public Result PostScriptVersion([FromBody] ScriptVersion scriptVersion) { var wId = scriptVersion.WorkshopId; var names = new List <string> { scriptVersion.Name }; if (ScriptVersionHelper.GetHaveSame(wId, names)) { return(Result.GenError <Result>(Error.ScriptVersionIsExist)); } var createUserId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; scriptVersion.CreateUserId = createUserId; scriptVersion.MarkedDateTime = markedDateTime; var valN = scriptVersion.ValueNumber == 0 ? 300 : scriptVersion.ValueNumber; var inN = scriptVersion.InputNumber == 0 ? 255 : scriptVersion.InputNumber; var outN = scriptVersion.OutputNumber == 0 ? 255 : scriptVersion.OutputNumber; var msg = new DeviceInfoMessagePacket(valN, inN, outN); scriptVersion.HeartPacket = msg.Serialize(); scriptVersion.ScriptFile = scriptVersion.ScriptFile ?? ""; ScriptVersionHelper.Add(scriptVersion); RedisHelper.PublishToTable(ScriptVersionHelper.Instance.Table); return(Result.GenError <Result>(Error.Success)); }
/// <summary> /// Creates an instance of the <see cref="JavascriptCompilationOptions"/> object. /// </summary> /// <param name="flags">JavaScript compilation flags.</param> /// <param name="scriptVersion">Target version of the compiled JavaScript.</param> /// <param name="extensions">Extensions to the compilation.</param> public JavascriptCompilationOptions( JsCompilationFlags flags, ScriptVersion scriptVersion, params JavascriptConversionExtension[] extensions) : this(flags, extensions, scriptVersion) { }
/// <summary> /// Creates a new ScriptVersion with the given parameters. /// </summary> /// <param name="spec">The specification to use, or 0 (zero) to use ECMA standard.</param> /// <param name="specVersion">The specification version. Pass 0 if using ECMA standard.</param> /// <param name="ecmaVersion"></param> /// <param name="allowDeprecated"></param> /// <param name="allowProposals"></param> /// <returns></returns> public static ScriptVersion Create(ScriptVersion spec, int specVersion, int ecmaVersion, bool allowDeprecated, bool allowProposals) { if (spec.GetSpecification() != spec) { throw new ArgumentException("Pure specification expected in parameter.", nameof(spec)); } if (spec == 0 && specVersion != 0) { throw new ArgumentException("Specification version must be zero when no specification is passed.", nameof(specVersion)); } var specVerFld = specVersion * Consts.VerFld; if (specVerFld >= Consts.VerLim) { throw new ArgumentException("Specification version overflow.", nameof(specVersion)); } var ecmaVerFld = ecmaVersion * Consts.Fld; if (ecmaVerFld >= Consts.Lim) { throw new ArgumentException("ECMAScript version overflow.", nameof(ecmaVersion)); } var flags = (allowProposals ? 1 : 0) + (allowDeprecated ? 2 : 0); return(spec + specVerFld + ecmaVerFld + flags * Consts.FlagFld); }
/// <summary> /// Indicates whether the specified version of JavaScript supports the given syntax. /// </summary> /// <param name="scriptVersion"></param> /// <param name="api"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static bool Supports(this ScriptVersion scriptVersion, JavascriptApiFeature api) { switch (api) { case JavascriptApiFeature.String_prototype_substring: case JavascriptApiFeature.String_prototype_toUpperCase: case JavascriptApiFeature.String_prototype_toLowerCase: case JavascriptApiFeature.String_prototype_indexOf: case JavascriptApiFeature.String_prototype_lastIndexOf: return(true); case JavascriptApiFeature.String_prototype_trimLeft: case JavascriptApiFeature.String_prototype_trimRight: if (scriptVersion.IsSupersetOf(ScriptVersion.Js181)) { return(true); } throw new ArgumentOutOfRangeException(nameof(api)); case JavascriptApiFeature.String_prototype_trim: return(scriptVersion.IsSupersetOf(ScriptVersion.Es51)); case JavascriptApiFeature.String_prototype_startsWith: case JavascriptApiFeature.String_prototype_endsWith: case JavascriptApiFeature.String_prototype_includes: return(scriptVersion.IsSupersetOf(ScriptVersion.Es60)); case JavascriptApiFeature.String_prototype_padStart: case JavascriptApiFeature.String_prototype_padEnd: return(scriptVersion.IsSupersetOf(ScriptVersion.Es80)); default: throw new ArgumentOutOfRangeException(nameof(api)); } }
public async Task <int> NewVersionAsync(int scriptId, string scriptBody, short scriptLanguageId) { int?maxVersionId = _dbContext.ScriptVersion .Where(p => p.ScriptId == scriptId) .OrderByDescending(p => p.Version) .Select(p => p.Version) .FirstOrDefault(); var userId = _ephItUser.Register().UserId; var newVersion = new ScriptVersion(); newVersion.Body = scriptBody; newVersion.Created = DateTime.UtcNow; newVersion.CreatedByUserId = userId; newVersion.ScriptId = scriptId; newVersion.ScriptLanguageId = scriptLanguageId; newVersion.Version = maxVersionId.HasValue ? maxVersionId.Value + 1 : 1; _dbContext.Add(newVersion); try { await _dbContext.SaveChangesAsync(); } catch { await _auditLogger.AuditLog(AuditObject.ScriptVersion, AuditAction.Create, AuditStatus.Error, newVersion.ScriptVersionId); throw; } await _auditLogger.AuditLog(AuditObject.ScriptVersion, AuditAction.Create, AuditStatus.Success, newVersion.ScriptVersionId); return(newVersion.ScriptVersionId); }
public Result PutScriptVersion([FromRoute] int id, [FromBody] ScriptVersion scriptVersion) { var data = ServerConfig.ApiDb.Query <ScriptVersion>("SELECT * FROM `script_version` WHERE Id = @id AND MarkedDelete = 0;", new { id }).FirstOrDefault(); if (data == null) { return(Result.GenError <Result>(Error.ScriptVersionNotExist)); } var cnt = ServerConfig.ApiDb.Query <int>("SELECT COUNT(1) FROM `script_version` WHERE `Name` = @Name AND MarkedDelete = 0;", new { scriptVersion.Name }).FirstOrDefault(); if (cnt > 0) { if (!scriptVersion.Name.IsNullOrEmpty() && data.Name != scriptVersion.Name) { return(Result.GenError <Result>(Error.ScriptVersionIsExist)); } } scriptVersion.Id = id; var time = DateTime.Now; scriptVersion.ScriptFile = scriptVersion.ScriptFile ?? ""; scriptVersion.MarkedDateTime = time; ServerConfig.ApiDb.Execute( "UPDATE script_version SET `MarkedDateTime` = @MarkedDateTime, `ModelId` = @ModelId, `Name` = @Name, `ScriptFile` = @ScriptFile WHERE `Id` = @Id;", scriptVersion); RedisHelper.PublishToTable(ScriptVersionHelper.Instance.Table); return(Result.GenError <Result>(Error.Success)); }
/// <summary> /// Adds the resources for all InstallerActions to the zip package. /// </summary> public virtual void AddInstallerActionResources(ScriptPackage package, ScriptVersion version) { BasePath sourcePath = new BasePath(ScriptManifestTokens.Replace(package.SourcePath.AbsolutePath, package.Manifest, version)); foreach (InstallerAction action in package.InstallerConfiguration.Actions) { action.PackResources(_currentZipFile, PackageBuilder.ResourcesArchivePath, sourcePath); } }
/// <summary> /// Changes the script version to accept deprecated features. /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static ScriptVersion Deprecated(this ScriptVersion scriptVersion) { return(Create( scriptVersion.GetSpecification(), scriptVersion.GetSpecificationVersion(), scriptVersion.GetStandardVersion(), true, scriptVersion.IsProposals())); }
/// <summary> /// Changes the script version to accept proposed features. /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static ScriptVersion Proposals(this ScriptVersion scriptVersion, bool value) { return(Create( scriptVersion.GetSpecification(), scriptVersion.GetSpecificationVersion(), scriptVersion.GetStandardVersion(), scriptVersion.IsDeprecated(), value)); }
/// <summary> /// Changes the script version to accept only ECMAScript standard features. /// Won't change deprecated nor proposals flags. /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static ScriptVersion ToStandard(this ScriptVersion scriptVersion) { return(Create( 0, 0, scriptVersion.GetStandardVersion(), scriptVersion.IsDeprecated(), scriptVersion.IsProposals())); }
public Result PostScriptVersion([FromBody] ScriptVersion scriptVersion) { scriptVersion.CreateUserId = Request.GetIdentityInformation(); scriptVersion.MarkedDateTime = DateTime.Now; ServerConfig.DictionaryDb.Execute( "INSERT INTO script_version (`CreateUserId`, `MarkedDateTime`, `MarkedDelete`, `ModifyId`, `DeviceModelId`, `ScriptName`) " + "VALUES (@CreateUserId, @MarkedDateTime, @MarkedDelete, @ModifyId, @DeviceModelId, @ScriptName);", scriptVersion); return(Result.GenError <Result>(Error.Success)); }
public Guid?New([FromBody] JobPostParameters postParams) { //this DB call should be in a BL eventually. ScriptVersion ver = _dbContext.ScriptVersion.Where(v => v.ScriptVersionId == postParams.ScriptVersionID).FirstOrDefault(); if (ver != null) { return(_jobManager.QueueJob(ver, postParams.Parameters, _ephItUser.Register().UserId, postParams.ScheduleID, postParams.AutomationID)); } return(null); }
private ListViewItem addVersionToListView(ScriptVersion version) { ListViewItem item = new ListViewItem(); item.SubItems.Add(new ListViewItem.ListViewSubItem()); item.Tag = version; setVersionListViewItemText(version, item); this.versionsListView.Items.Add(item); return item; }
// See: ECMAScript 5/6/7 compatibility tables // https://github.com/kangax/compat-table // http://kangax.github.io/compat-table // See: Ecma International, Technical Committee 39 - ECMAScript // https://github.com/tc39 /// <summary> /// Indicates whether the specified version of JavaScript supports the given syntax. /// </summary> /// <param name="scriptVersion"></param> /// <param name="syntax"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static bool Supports(this ScriptVersion scriptVersion, JavascriptSyntaxFeature syntax) { switch (syntax) { case JavascriptSyntaxFeature.ArrowFunction: case JavascriptSyntaxFeature.ArraySpread: return(scriptVersion.IsSupersetOf(ScriptVersion.Es60)); default: throw new ArgumentOutOfRangeException(nameof(syntax)); } }
/// <summary> /// Creates an instance of the <see cref="JavascriptCompilationOptions"/> object. /// </summary> /// <param name="flags">JavaScript compilation flags.</param> /// <param name="scriptVersion">Target version of the compiled JavaScript.</param> /// <param name="extensions">Extensions to the compilation.</param> public JavascriptCompilationOptions( JsCompilationFlags flags, IEnumerable<JavascriptConversionExtension> extensions = null, ScriptVersion scriptVersion = ScriptVersion.Es50) { this.ScriptVersion = scriptVersion; this.BodyOnly = (flags & JsCompilationFlags.BodyOnly) != 0; this.ScopeParameter = (flags & JsCompilationFlags.ScopeParameter) != 0; this.Extensions = extensions == null ? Enumerable.Empty<JavascriptConversionExtension>() : new ReadOnlyCollection<JavascriptConversionExtension>(extensions.ToArray()); }
/// <summary> /// Changes the script version to accept Javascript (Mozilla) features. /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static ScriptVersion Javascript(this ScriptVersion scriptVersion, int specVersion) { if (scriptVersion.GetSpecification() != 0) { throw new ArgumentException("Script version must have no assigned specification.", nameof(scriptVersion)); } return(Create( ScriptVersion.Js, specVersion, scriptVersion.GetStandardVersion(), scriptVersion.IsDeprecated(), scriptVersion.IsProposals())); }
/// <summary> /// Adds the ScriptManifest to the zip package. /// Only includes the supplied ScriptVersion in the package manifest versions list. /// </summary> /// <param name="manifest">The ScriptManifest instance to add.</param> /// <param name="version">The ScriptVersion to filter out from the manifest. All other versions will not be included.</param> public virtual void AddManifest(ScriptManifest manifest, ScriptVersion version) { ScriptManifest manifestCopy = manifest.Copy(); ScriptVersion versionCopy = version.Copy(); versionCopy.ScriptPath = ScriptManifestTokens.Replace(versionCopy.ScriptPath, manifest, version); manifestCopy.Versions = new List<ScriptVersion>() { versionCopy }; using (StringWriter stringWriter = new StringWriter()) { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); handler.Write(stringWriter, manifestCopy); //TODO: change this to work with multiple manifests? _currentZipFile.AddEntry(PackageBuilder.InstallerArchivePath + "script" + ScriptManifest.DefaultExtension, stringWriter.ToString()); } }
public void SetClassInfo(string className, ScriptVersion version, FieldInfo[] infos) { list.Clear(); foreach (var key in list) { if (key.className == className) { key.fieldInfos = null; key.fieldInfos = infos; return; } } list.Add(new ClassInfo { className = className, version = version, fieldInfos = infos }); }
private void addVersionButton_Click(object sender, EventArgs e) { ScriptVersion version = null; if (manifest.LatestVersion != null) { version = manifest.LatestVersion.Copy(); version.VersionNumber.Minor += 1; } else version = new ScriptVersion(); this.manifest.Versions.Add(version); ListViewItem item = this.addVersionToListView(version); item.Selected = true; }
public Result PostScriptVersion([FromBody] ScriptVersion scriptVersion) { scriptVersion.CreateUserId = Request.GetIdentityInformation(); scriptVersion.MarkedDateTime = DateTime.Now; var valN = scriptVersion.ValueNumber == 0 ? 300 : scriptVersion.ValueNumber; var inN = scriptVersion.InputNumber == 0 ? 255 : scriptVersion.InputNumber; var outN = scriptVersion.OutputNumber == 0 ? 255 : scriptVersion.OutputNumber; var msg = new DeviceInfoMessagePacket(valN, inN, outN); scriptVersion.HeartPacket = msg.Serialize(); ServerConfig.DeviceDb.Execute( "INSERT INTO script_version (`CreateUserId`, `MarkedDateTime`, `MarkedDelete`, `ModifyId`, `DeviceModelId`, `ScriptName`, `ValueNumber`, `InputNumber`, `OutputNumber`, `HeartPacket`) " + "VALUES (@CreateUserId, @MarkedDateTime, @MarkedDelete, @ModifyId, @DeviceModelId, @ScriptName, @ValueNumber, @InputNumber, @OutputNumber, @HeartPacket);", scriptVersion); ServerConfig.RedisHelper.PublishToTable(); return(Result.GenError <Result>(Error.Success)); }
public Result PutScriptVersion([FromRoute] int id, [FromBody] ScriptVersion scriptVersion) { var cnt = ServerConfig.DeviceDb.Query <int>("SELECT COUNT(1) FROM `script_version` WHERE Id = @id AND `MarkedDelete` = 0;", new { id }).FirstOrDefault(); if (cnt == 0) { return(Result.GenError <Result>(Error.ScriptVersionNotExist)); } scriptVersion.Id = id; scriptVersion.CreateUserId = Request.GetIdentityInformation(); scriptVersion.MarkedDateTime = DateTime.Now; ServerConfig.DeviceDb.Execute( "UPDATE script_version SET `CreateUserId` = @CreateUserId, `MarkedDateTime` = @MarkedDateTime, `MarkedDelete` = @MarkedDelete, `ModifyId` = @ModifyId, `DeviceModelId` = @DeviceModelId, `ScriptName` = @ScriptName, " + "`ValueNumber` = @ValueNumber, `InputNumber` = @InputNumber, `OutputNumber` = @OutputNumber, `HeartPacket` = @HeartPacket WHERE `Id` = @Id;", scriptVersion); return(Result.GenError <Result>(Error.Success)); }
/// <summary> /// Replaces any tokens in the string with values taken from the manifest. /// </summary> /// <param name="str">The string to replace tokens in.</param> /// <param name="manifest">The manifest to take values from.</param> /// <param name="version">The version to use for version-related tokens.</param> /// <returns>Returns the new string.</returns> internal static String Replace(String str, ScriptManifest manifest, ScriptVersion version) { if (str == null || manifest == null || version == null) return String.Empty; StringBuilder newString = new StringBuilder(str); newString.Replace(Id_Token, manifest.Id.ToString()); newString.Replace(Name_Token, manifest.Name); newString.Replace(Author_Token, manifest.Author); newString.Replace(Version_Token, version.VersionNumber.ToString()); newString.Replace(Version_Underscores_Token, version.VersionNumber.ToString(true)); newString.Replace(VersionMajor_Token, version.VersionNumber.Major.ToString()); newString.Replace(VersionMinor_Token, version.VersionNumber.Minor.ToString()); newString.Replace(VersionRevision_Token, version.VersionNumber.Revision.ToString()); newString.Replace(VersionStage_Token, version.VersionNumber.ReleaseStage.ToString().ToLower()); newString.Replace(Date_Token, DateTime.Today.ToString("yyyy'-'MM'-'dd")); return newString.ToString(); }
public override Task <ScriptVersion> PostAsync(ScriptVersion obj) { ThrowIfScriptNotExist(obj.ScriptId); int?maxScriptVersion = _dbContext.ScriptVersion .Where(p => p.ScriptId == obj.ScriptId) .OrderByDescending(desc => desc.Version) .Select(p => p.Version) .FirstOrDefault(); if (!maxScriptVersion.HasValue) { obj.Version = 1; } else { obj.Version = maxScriptVersion.Value + 1; } obj.Created = DateTime.UtcNow; obj.CreatedByUserId = _ephItUser.Register().UserId; return(base.PostAsync(obj)); }
public static bool SystemEligibleForRootfsUpdate() { bool eligibleForUpdate = false; try { string scriptVersion = ScriptVersion.Substring(ScriptVersion.IndexOf('v') + 1); scriptVersion = scriptVersion.Substring(0, scriptVersion.LastIndexOf('(')); var scriptElems = scriptVersion.Split(new char[] { '-' }); if (!Shared.IsVersionGreaterOrEqual(scriptElems[0], hakchi.CurrentHakchiScriptVersion) || !(int.Parse(scriptElems[1]) >= int.Parse(hakchi.CurrentHakchiScriptRevision))) { eligibleForUpdate = true; } } catch { eligibleForUpdate = true; } return(eligibleForUpdate); }
/// <summary> /// Indicates whether the specified version of JavaScript supports the given syntax or syntax. /// </summary> /// <param name="scriptVersion"></param> /// <param name="syntax"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static bool Supports(this ScriptVersion scriptVersion, JavascriptSyntax syntax) { switch (syntax) { case JavascriptSyntax.ArrowFunction: switch (scriptVersion) { case ScriptVersion.Es30: case ScriptVersion.Es50: return(false); case ScriptVersion.Es60: case ScriptVersion.Es70: return(true); default: throw new ArgumentOutOfRangeException(nameof(scriptVersion)); } case JavascriptSyntax.ArraySpread: switch (scriptVersion) { case ScriptVersion.Es30: case ScriptVersion.Es50: return(false); case ScriptVersion.Es60: case ScriptVersion.Es70: return(true); default: throw new ArgumentOutOfRangeException(nameof(scriptVersion)); } ; default: throw new ArgumentOutOfRangeException(nameof(syntax)); } }
/// <summary> /// Whether a specific version of the script is a superset of another version. /// This can be used as a rather general feature indicator, but there may be exceptions, such as deprecated features. /// </summary> /// <param name="scriptVersion"></param> /// <param name="baseScriptVersion"></param> /// <returns></returns> public static bool IsSupersetOf(this ScriptVersion scriptVersion, ScriptVersion baseScriptVersion) { var specOther = baseScriptVersion.GetSpecification(); if (specOther == 0) { return(scriptVersion.GetStandardVersion() >= baseScriptVersion.GetStandardVersion()); } var specThis = scriptVersion.GetSpecification(); if (specThis == ScriptVersion.NonStandard) { return(scriptVersion.GetStandardVersion() >= baseScriptVersion.GetStandardVersion()); } if (specThis == specOther) { return(scriptVersion.GetSpecificationVersion() >= baseScriptVersion.GetSpecificationVersion()); } return(false); }
private void setVersionListViewItemText(ScriptVersion version, ListViewItem item) { if (version == null || item == null) return; item.Text = version.VersionNumber.ToString(); item.SubItems[1].Text = version.ScriptPath; this.versionsListView.Sort(); }
/// <summary> /// Adds the MZP files (readme, mzp.run, install.ms) to the zip package. /// </summary> /// <param name="manifest">The ScriptManifest to use to replace tokens in the mzp files.</param> /// <param name="version">The ScriptVersion to use to replace tokens in the mzp files.</param> public virtual void AddMzpFiles(ScriptManifest manifest, ScriptVersion version) { //Add mzp.run _currentZipFile.AddEntry("mzp.run", ScriptManifestTokens.Replace(PackageResources.mzp, manifest, version), Encoding.ASCII); //Add readme.txt _currentZipFile.AddEntry("README.txt", ScriptManifestTokens.Replace(PackageResources.README, manifest, version), Encoding.UTF8); //Add install.ms _currentZipFile.AddEntry(PackageBuilder.InstallerArchivePath + "install.ms", ScriptManifestTokens.Replace(PackageResources.install, manifest, version), Encoding.ASCII); }
private void WhenDatabaseIsUpgradedToVersion(ScriptVersion scriptVersion) { upgradeEngine = upgradeEngineBuilder.SetTargetVersion(scriptVersion).Build(); upgradeResult = upgradeEngine.PerformUpgrade(); }
private void AndShouldHaveRunScriptsUpToSpecifiedVersionInOrder(ScriptVersion maxVersion) { IList<SqlScript> expectedScripts = new List<SqlScript>(); // Check both results and journal foreach (var sqlScript in scripts) { ScriptVersion scriptVersion; if (!ScriptVersion.TryGetVersion(sqlScript.Name, out scriptVersion)) { throw new Exception($"Cannot extract version from script name '{sqlScript.Name}'"); } if (scriptVersion <= maxVersion) { expectedScripts.Add(sqlScript); } } Assert.AreEqual(expectedScripts.Count, upgradeResult.Scripts.Count()); Assert.That(expectedScripts.Select(x=>x.Name), Is.EquivalentTo(upgradeResult.Scripts.Select(x=>x.Name))); Assert.AreEqual(expectedScripts.Count, GetJournal().GetExecutedScripts().Count()); }
/// <summary> /// Creates an instance of the <see cref="JavascriptCompilationOptions"/> object. /// </summary> /// <param name="scriptVersion">Target version of the compiled JavaScript.</param> /// <param name="extensions">Extensions to the compilation.</param> public JavascriptCompilationOptions( ScriptVersion scriptVersion, params JavascriptConversionExtension[] extensions) : this(JsCompilationFlags.BodyOnly | JsCompilationFlags.ScopeParameter, extensions, scriptVersion) { }
public void Apply(string content, ScriptVersion version) { database.ExecuteNonQuery(content); CurrentVersion = version; }
public Result PostDataNameDictionary([FromBody] AddDataNameDictionariey data) { var cnt = ServerConfig.DeviceDb.Query <int>("SELECT COUNT(1) FROM `device_model` WHERE Id = @id AND `MarkedDelete` = 0;", new { id = data.DeviceModelId }).FirstOrDefault(); if (cnt == 0) { return(Result.GenError <Result>(Error.DeviceModelNotExist)); } cnt = ServerConfig.DeviceDb.Query <int>("SELECT COUNT(1) FROM `variable_type` WHERE Id = @id AND `MarkedDelete` = 0;", new { id = data.VariableType }).FirstOrDefault(); if (cnt == 0) { return(Result.GenError <Result>(Error.VariableTypeNotExist)); } switch (data.Type) { case 0: cnt = ServerConfig.DeviceDb.Query <int>("SELECT COUNT(1) FROM `script_version` WHERE Id = @id AND `MarkedDelete` = 0;", new { id = data.ScriptId }).FirstOrDefault(); if (cnt == 0) { return(Result.GenError <Result>(Error.ScriptVersionNotExist)); } foreach (var dataNameDictionary in data.DataNameDictionaries) { dataNameDictionary.ScriptId = data.ScriptId; dataNameDictionary.VariableTypeId = data.VariableType; } break; case 1: if (data.ScriptName.IsNullOrEmpty()) { return(Result.GenError <Result>(Error.ParamError)); } var scv = ServerConfig.DeviceDb.Query <ScriptVersion>("SELECT * FROM `script_version` WHERE ScriptName = @ScriptName AND `MarkedDelete` = 0;", new { data.ScriptName }).FirstOrDefault(); int index; if (scv == null) { var scriptVersion = new ScriptVersion { CreateUserId = Request.GetIdentityInformation(), MarkedDateTime = DateTime.Now, DeviceModelId = data.DeviceModelId, ScriptName = data.ScriptName }; index = ServerConfig.DeviceDb.Query <int>( "INSERT INTO script_version (`CreateUserId`, `MarkedDateTime`, `MarkedDelete`, `ModifyId`, `DeviceModelId`, `ScriptName`, `ValueNumber`, `InputNumber`, `OutputNumber`, `HeartPacket`) " + "VALUES (@CreateUserId, @MarkedDateTime, @MarkedDelete, @ModifyId, @DeviceModelId, @ScriptName, @ValueNumber, @InputNumber, @OutputNumber, @HeartPacket);SELECT LAST_INSERT_ID();", scriptVersion).FirstOrDefault(); } else { index = scv.Id; } if (index == 0) { return(Result.GenError <Result>(Error.ParamError)); } data.ScriptId = index; break; case 2: break; case 3: break; default: return(Result.GenError <Result>(Error.Fail)); } var dataNameDictionaries = data.DataNameDictionaries; var createUserId = Request.GetIdentityInformation(); foreach (var dataNameDictionary in dataNameDictionaries) { dataNameDictionary.CreateUserId = createUserId; dataNameDictionary.MarkedDateTime = DateTime.Now; dataNameDictionary.ScriptId = data.ScriptId; dataNameDictionary.VariableTypeId = data.VariableType; } var doublePa = dataNameDictionaries.GroupBy(x => x.PointerAddress).Count(x => x.Count() > 1); if (doublePa > 0) { return(Result.GenError <Result>(Error.PointerAddressIsExist)); } cnt = ServerConfig.DeviceDb.Query <int>( "SELECT COUNT(1) FROM `data_name_dictionary` WHERE ScriptId = @ScriptId AND VariableTypeId = @VariableTypeId AND PointerAddress IN @PointerAddress;", new { ScriptId = data.ScriptId, VariableTypeId = data.VariableType, PointerAddress = dataNameDictionaries.Select(x => x.PointerAddress) }).FirstOrDefault(); if (cnt > 0) { return(Result.GenError <Result>(Error.PointerAddressIsExist)); } ServerConfig.DeviceDb.Execute( "INSERT INTO data_name_dictionary (`CreateUserId`, `MarkedDateTime`, `MarkedDelete`, `ModifyId`, `ScriptId`, `VariableTypeId`, `PointerAddress`, `VariableName`, `Remark`) " + "VALUES (@CreateUserId, @MarkedDateTime, @MarkedDelete, @ModifyId, @ScriptId, @VariableTypeId, @PointerAddress, @VariableName, @Remark);", dataNameDictionaries); CheckScriptVersion(data.ScriptId); return(Result.GenError <Result>(Error.Success)); }
private void newPackageButton_Click(object sender, EventArgs e) { this.switchNewButtonImageText(sender, newPackageButton_Click); ScriptPackage p = new ScriptPackage("New Package"); ScriptVersion v = new ScriptVersion(); v.ScriptPath = p.PackageFile.RelativePathComponent; p.Manifest.Versions.Add(v); TreeNode tn = addPackageToTree(p, String.Empty); tn.Expand(); this.filesTree.SelectedNode = tn; }
/// <summary> /// Gets the version of the non-standard specification, if one is present. /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static int GetSpecificationVersion(this ScriptVersion scriptVersion) { return(((int)scriptVersion % Consts.SVerLim) / Consts.SVerFld); }
public void ScriptVersionCopyTest() { ScriptVersion version = new ScriptVersion(2, 1, 3, ScriptReleaseStage.Alpha); ScriptVersion newVersion = (ScriptVersion)version.Copy(); Assert.AreEqual(version.VersionNumber, newVersion.VersionNumber, "Version numbers are equal"); Assert.AreEqual(version.SupportedMaxVersions, newVersion.SupportedMaxVersions, "SupportedMaxVersions are equal."); Assert.AreEqual(version.ScriptPath, newVersion.ScriptPath, "Scriptpaths are equal"); }
/// <summary> /// Set the target script version to apply to the database. Any scripts with a higher version will not be run. /// </summary> /// <param name="builder"></param> /// <param name="scriptVersion"></param> /// <returns></returns> public static UpgradeEngineBuilder SetTargetVersion(this UpgradeEngineBuilder builder, ScriptVersion scriptVersion) { builder.Configure(c => c.TargetScriptVersion = scriptVersion); return builder; }
/// <summary> /// Gets a value indicating whether the script version supports deprecated features /// (i.e. features excluded from the standard, but present in one of Js or MsJ specification). /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static bool IsDeprecated(this ScriptVersion scriptVersion) { return((((int)scriptVersion / (int)ScriptVersion.Deprecated) & 1) == 1); }
/// <summary> /// Gets a value indicating whether the script version supports proposals /// (i.e. next ECMAScript proposed features). /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static bool IsProposals(this ScriptVersion scriptVersion) { return((((int)scriptVersion / (int)ScriptVersion.Proposals) & 1) == 1); }
/// <summary> /// Gets the version of the non-standard specification. /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static ScriptVersion GetSpecification(this ScriptVersion scriptVersion) { return((ScriptVersion)(((int)scriptVersion / Consts.SpecFld) * Consts.SpecFld)); }
/// <summary> /// Gets the version of the ECMAScript standard. /// </summary> /// <param name="scriptVersion"></param> /// <returns></returns> public static int GetStandardVersion(this ScriptVersion scriptVersion) { return(((int)scriptVersion % Consts.EcmaLim) / Consts.EcmaFld); }