protected virtual bool ExecutePerInterface(InterfaceWithAttributeResult a) { // Load Macro var macroname = GetMacroName(a.TypeName, a.Attribute, out var args, out var outputname); var macro = MacroFactory.GetMacro <MacroTypeVariables>(macroname, a.FsPath, out var errores); // Check for errors in macro if (macro == null) { OutputEngine.LogConsoleErrorWrite($"{a.TypeName} : {macroname}"); foreach (var e in errores) { OutputEngine.LogConsoleErrorWrite(e); } return(false); } // Execute macro var refinterface = args[0].StartsWith("I") ? args[0] : ""; var refdata = Engine.GetRecordForSymbol(refinterface); var variables = CreateVariables(a, outputname, a.AttributeList, refdata); var res = macro.Execute(variables, out var error); // Check for errors if (!res) { OutputEngine.LogConsoleErrorWrite(error); } // Write Results CurrentProject.WriteResults(variables); return(res); }
protected override void PersistUpdatedItem(IMacro entity) { ((Entity)entity).UpdatingEntity(); var factory = new MacroFactory(); var dto = factory.BuildDto(entity); Database.Update(dto); //update the properties if they've changed var macro = (Macro)entity; if (macro.IsPropertyDirty("Properties") || macro.Properties.Any(x => x.IsDirty())) { //now we need to delete any props that have been removed foreach (var propAlias in macro.RemovedProperties) { //delete the property Database.Delete <MacroPropertyDto>("WHERE macro=@macroId AND macroPropertyAlias=@propAlias", new { macroId = macro.Id, propAlias = propAlias }); } //for any that exist on the object, we need to determine if we need to update or insert foreach (var propDto in dto.MacroPropertyDtos) { if (macro.AddedProperties.Contains(propDto.Alias)) { //we need to insert since this was added and re-assign the new id var propId = Convert.ToInt32(Database.Insert(propDto)); macro.Properties[propDto.Alias].Id = propId; } else { //This will only work if the Alias hasn't been changed if (macro.Properties.ContainsKey(propDto.Alias)) { //only update if it's dirty if (macro.Properties[propDto.Alias].IsDirty()) { Database.Update(propDto); } } else { var property = macro.Properties.FirstOrDefault(x => x.Id == propDto.Id); if (property != null && property.IsDirty()) { Database.Update(propDto); } } } } } entity.ResetDirtyProperties(); }
private IEnumerable <IMacro> ConvertFromDtos(IEnumerable <MacroDto> dtos) { foreach (var entity in dtos.Select(x => MacroFactory.BuildEntity(_shortStringHelper, x))) { // reset dirty initial properties (U4-1946) ((BeingDirtyBase)entity).ResetDirtyProperties(false); yield return(entity); } }
private IEnumerable <IMacro> ConvertFromDtos(IEnumerable <MacroDto> dtos) { var factory = new MacroFactory(); foreach (var entity in dtos.Select(factory.BuildEntity)) { //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); yield return(entity); } }
private IMacro GetBySql(Sql sql) { var macroDto = Database .FetchOneToMany <MacroDto>(x => x.MacroPropertyDtos, sql) .FirstOrDefault(); if (macroDto == null) { return(null); } var entity = MacroFactory.BuildEntity(_shortStringHelper, macroDto); // reset dirty initial properties (U4-1946) ((BeingDirtyBase)entity).ResetDirtyProperties(false); return(entity); }
protected override void PersistNewItem(IMacro entity) { entity.AddingEntity(); var dto = MacroFactory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; foreach (var propDto in dto.MacroPropertyDtos) { //need to set the id explicitly here propDto.Macro = id; var propId = Convert.ToInt32(Database.Insert(propDto)); entity.Properties[propDto.Alias].Id = propId; } entity.ResetDirtyProperties(); }
protected override void PersistUpdatedItem(IMacro entity) { entity.UpdatingEntity(); MacroDto dto = MacroFactory.BuildDto(entity); Database.Update(dto); // update the properties if they've changed var macro = (Macro)entity; if (macro.IsPropertyDirty("Properties") || macro.Properties.Values.Any(x => x.IsDirty())) { var ids = dto.MacroPropertyDtos?.Where(x => x.Id > 0).Select(x => x.Id).ToArray(); if (ids?.Length > 0) { Database.Delete <MacroPropertyDto>("WHERE macro=@macro AND id NOT IN (@ids)", new { macro = dto.Id, ids }); } else { Database.Delete <MacroPropertyDto>("WHERE macro=@macro", new { macro = dto.Id }); } // detect new aliases, replace with temp aliases // this ensures that we don't have collisions, ever var aliases = new Dictionary <string, string>(); if (dto.MacroPropertyDtos is null) { return; } foreach (MacroPropertyDto propDto in dto.MacroPropertyDtos) { IMacroProperty?prop = macro.Properties.Values.FirstOrDefault(x => x.Id == propDto.Id); if (prop == null) { throw new Exception("oops: property."); } if (propDto.Id == 0 || prop.IsPropertyDirty("Alias")) { var tempAlias = Guid.NewGuid().ToString("N")[..8];
private IMacro GetBySql(Sql sql) { //must be sorted this way for the relator to work sql.OrderBy <MacroDto>(x => x.Id, SqlSyntax); var macroDto = Database.Fetch <MacroDto, MacroPropertyDto, MacroDto>(new MacroPropertyRelator().Map, sql).FirstOrDefault(); if (macroDto == null) { return(null); } var factory = new MacroFactory(); var entity = factory.BuildEntity(macroDto); //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); return(entity); }
private bool ExecutePerClass(ClassWithAttributeResult a) { // Load Macro var macroname = GetMacroName(a.ClassName, a.Attribute, out var args, out var outputname); var macro = MacroFactory.GetMacro <MacroTypeVariables>(macroname, a.FsPath, out var errores); // Check for errors in macro if (macro == null) { OutputEngine.LogConsoleErrorWrite($"{a.ClassName} : {macroname}"); foreach (var e in errores) { OutputEngine.LogConsoleErrorWrite(e); } return(false); } // Execute macro //var refinterface = args[0].StartsWith("I") ? args[0] : ""; var reftype = args[0] ?? ""; var refdata = Engine.GetRecordForSymbol(reftype); if (refdata == null) { OutputEngine.ConsoleWrite($"{reftype} is defined outside project. @REFINTERFACE/@REFCLASS will be null."); } var variables = CreateVariables(a, outputname, a.AttributeList, refdata); var res = macro.Execute(variables, out var error); // Check for errors if (!res) { OutputEngine.LogConsoleErrorWrite(error); } // Write Results CurrentProject.WriteResults(variables); return(res); }
protected override IMacro PerformGet(int id) { var sql = GetBaseQuery(false); sql.Where(GetBaseWhereClause(), new { Id = id }); var macroDto = Database.Fetch <MacroDto, MacroPropertyDto, MacroDto>(new MacroPropertyRelator().Map, sql).FirstOrDefault(); if (macroDto == null) { return(null); } var factory = new MacroFactory(); var entity = factory.BuildEntity(macroDto); //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); return(entity); }
protected override void PersistUpdatedItem(IMacro entity) { entity.UpdatingEntity(); var dto = MacroFactory.BuildDto(entity); Database.Update(dto); //update the properties if they've changed var macro = (Macro)entity; if (macro.IsPropertyDirty("Properties") || macro.Properties.Values.Any(x => x.IsDirty())) { var ids = dto.MacroPropertyDtos.Where(x => x.Id > 0).Select(x => x.Id).ToArray(); if (ids.Length > 0) { Database.Delete <MacroPropertyDto>("WHERE macro=@macro AND id NOT IN (@ids)", new { macro = dto.Id, ids }); } else { Database.Delete <MacroPropertyDto>("WHERE macro=@macro", new { macro = dto.Id }); } // detect new aliases, replace with temp aliases // this ensures that we don't have collisions, ever var aliases = new Dictionary <string, string>(); foreach (var propDto in dto.MacroPropertyDtos) { var prop = macro.Properties.Values.FirstOrDefault(x => x.Id == propDto.Id); if (prop == null) { throw new Exception("oops: property."); } if (propDto.Id == 0 || prop.IsPropertyDirty("Alias")) { var tempAlias = Guid.NewGuid().ToString("N").Substring(0, 8); aliases[tempAlias] = propDto.Alias; propDto.Alias = tempAlias; } } // insert or update existing properties, with temp aliases foreach (var propDto in dto.MacroPropertyDtos) { if (propDto.Id == 0) { // insert propDto.Id = Convert.ToInt32(Database.Insert(propDto)); macro.Properties[aliases[propDto.Alias]].Id = propDto.Id; } else { // update var property = macro.Properties.Values.FirstOrDefault(x => x.Id == propDto.Id); if (property == null) { throw new Exception("oops: property."); } if (property.IsDirty()) { Database.Update(propDto); } } } // replace the temp aliases with the real ones foreach (var propDto in dto.MacroPropertyDtos) { if (aliases.ContainsKey(propDto.Alias) == false) { continue; } propDto.Alias = aliases[propDto.Alias]; Database.Update(propDto); } } entity.ResetDirtyProperties(); }