/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is FormatList formatList) { var result = new InstallObjectResult { Success = true }; try { // TODO: Internal name + entry value is unique var updatedRows = 0; foreach (var entry in formatList.Items) { updatedRows += await sqlService.OpenConnection(async (c) => { return(await c.ExecuteAsync("Insert into ESS_MS_Controls_FormatList (displayname, internname, descriptiontext, entryvalue) values " + "(:displayname, :internalname, :description, :value);" , new { entry.DisplayName, formatList.InternalName, formatList.Description, entry.Value })); }); } await logService.WriteAsync($"Installed FormatList at {installableObject.Target}.", LogLevel.Info); } catch (Exception ex) { await logService.WriteAsync($"Failed to install FormatList at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is RepositoryContent repositoryContent) { var repositoryManager = RepositoryManager.Singleton; var result = new InstallObjectResult { Success = true }; try { var target = installableObject.Target.Replace("repository\\", ""); repositoryManager.WriteAllBytes(target, repositoryContent.Data); await logService.WriteAsync($"Installed repository content at {target}.", LogLevel.Info); } catch (Exception ex) { await logService.WriteAsync($"Failed to install repository content at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is SqlContent sqlContent) { var result = new InstallObjectResult { Success = true }; try { await sqlService.OpenConnection(async (c) => { var command = c.CreateCommand(); command.CommandText = sqlContent.Data; command.ExecuteNonQuery(); }); result.Success = true; await logService.WriteAsync($"Succesfully executed sqlscript: {sqlContent.Data}\n at {installableObject.Target}.", LogLevel.Info); } catch (Exception ex) { await logService.WriteAsync($"Failed to execute sqlscript:{sqlContent.Data}\n at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(""); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is Role role) { var result = new InstallObjectResult { Success = true }; try { RoleManager.Singleton.CreateRole(new Simplic.Framework.EF.Role { RoleId = role.Id, Description = role.Description, DisplayName = role.DisplayName, InternName = role.InternalName }); await logService.WriteAsync($"Installed role at {installableObject.Target}.", LogLevel.Info); } catch (Exception ex) { await logService.WriteAsync($"Failed to install role at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is Stack stack) { var result = new InstallObjectResult { Success = true }; try { var execResult = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync( "Insert into ESS_DCC_Stack (guid, displayname, stackgridname, isactive, connectwitharchiv, tablename, stackname," + " headersql, trackchanges, usefulltextindex, improveocrtext, usedce, stacksearchname)" + "on existing update values (:id, :displayname, :stackgridname, :isactive, :connectwitharchive, :tablename, :stackname," + " :headersql, :trackchanges, :usefulltextindex, :improveocrtext, :usedce, '')", new { stack.Id, stack.DisplayName, stack.StackGridName, stack.IsActive, stack.ConnectWithArchive, stack.TableName, stack.StackName, stack.HeaderSql, stack.TrackChanges, stack.FullText.UseFullTextIndex, stack.FullText.ImproveOCRText, stack.FullText.UseDCE } ); return(affectedRows > 0); }); if (execResult) { await logService.WriteAsync($"Installed stack at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Failed to install stack at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install stack at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is StackRegister stackRegister) { var result = new InstallObjectResult { Success = true }; try { var statement = ""; if (stackRegister.Configuration is SqlConfiguration sqlConfiguration) { statement = sqlConfiguration.Statement; } var success = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync( "INSERT INTO ESS_DCC_StackRegister (" + "RegisterGuid, RegisterName, StackGuid, IsActive, AssignSql) " + "ON EXISTING UPDATE VALUES (" + ":Id, :Name, :Stackid, :IsActive, :Statement)", new { stackRegister.Id, stackRegister.Name, stackRegister.StackId, stackRegister.IsActive, statement }); return(affectedRows > 0); }); if (success) { result.Success = true; await logService.WriteAsync($"Installed StackRegister at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Failed to install StackRegister at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install StackRegister at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is Grid grid) { var result = new InstallObjectResult { Success = true }; var mapConfig = new MapperConfiguration(cfg => { cfg.CreateMap <Grid, GridContainerModel>(MemberList.None) .ForMember(dest => dest.ReloadGridButtonVisibility, opt => opt.MapFrom(x => x.ReloadGridButtonVisibility)); cfg.CreateMap <GridMenuConfiguration, GridMenuConfigurationModel>(MemberList.None); cfg.CreateMap <GridCellSqlHighlight, GridCellSqlHighlightModel>(MemberList.None); cfg.CreateMap <DivergentColumnType, IDivergentColumnType>(MemberList.None); cfg.CreateMap <ColumnConfiguration, ColumnConfigurationModel>(MemberList.Source).As <GridColumnConfigurationModel>(); cfg.CreateMap <ColumnConfiguration, GridColumnConfigurationModel>(MemberList.Source); cfg.CreateMap <GridProfileConfiguration, GridProfileConfigurationModel>(MemberList.None); cfg.CreateMap <GridVirtualGroupConfiguration, Simplic.UI.GridView.GridVirtualGroupConfiguration>(MemberList.None) .IgnoreAllPropertiesWithAnInaccessibleSetter(); cfg.CreateMap <VirtualGroupDefinition, Simplic.Framework.DBUI.VirtualGroupDefinition>(MemberList.None) .ForMember(x => x.Name, opt => opt.Ignore()); }); try { mapConfig.AssertConfigurationIsValid(); var mapper = new Mapper(mapConfig); var containerModel = mapper.Map <GridContainerModel>(installableObject.Content); GridViewManager.Singleton.SaveConfiguration(containerModel); result.Success = true; await logService.WriteAsync($"Installed Grid at {installableObject.Target}.", LogLevel.Info); } catch (Exception ex) { await logService.WriteAsync($"Failed to install Grid at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is Sequence deserializedSequence) { var result = new InstallObjectResult { Success = true }; try { var sequence = new SequenceNumber { Id = deserializedSequence.Id, InternName = deserializedSequence.InternalName, DisplayName = deserializedSequence.DisplayName, Format = deserializedSequence.Format }; foreach (var counter in deserializedSequence.Counter) { sequence.Counters.Add( new SequenceNumberCounter(sequence) { Id = counter.Id, ValidFrom = counter.ValidFrom, ValidTo = counter.ValidTo, Minimum = counter.Min, Maximum = counter.Max, Step = counter.Step, FixedLength = counter.FixedLength, Format = counter.OptionalFormat, TenantId = counter.TenantId }); } SequenceNumberManager.Singleton.Save(sequence); await logService.WriteAsync($"Installed Sequence at {installableObject.Target}.", LogLevel.Info); result.Success = true; } catch (Exception ex) { await logService.WriteAsync($"Failed to install Sequence at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is RibbonTab ribbon) { var result = new InstallObjectResult { Success = true }; try { var success = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync("INSERT INTO RibbonMenu_Tab(Guid, TabHeader, OrderNr) ON EXISTING UPDATE VALUES (:Guid, :TabHeader, :OrderNr)", new { Guid = ribbon.Id, TabHeader = ribbon.Name, OrderNr = ribbon.OrderId }); if (ribbon.Groups != null) { foreach (var group in ribbon.Groups) { affectedRows += await c.ExecuteAsync("INSERT INTO RibbonMenu_Group(Guid, TabGuid, GroupHeader, OrderNr) ON EXISTING UPDATE VALUES (:Guid, :TabGuid, :GroupHeader, :OrderNr)", new { Guid = group.Id, TabGuid = ribbon.Id, GroupHeader = group.Name, OrderNr = ribbon.OrderId }); } } return(affectedRows > 0); }); if (success) { result.Success = true; await logService.WriteAsync($"Installed RibbonTab/RibbonGroup at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Failed to install RibbonTab/RibbonGroup at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install RibbonTab/RibbonGroup at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is ComboBox comboBox) { var result = new InstallObjectResult { Success = true }; try { var exists = await sqlService.OpenConnection(async (c) => { var first = await c.QueryFirstOrDefaultAsync("Select * from ESS_MS_Controls_DropDownBox where sqlstatement = :sqlstatement and boxname = :name;", new { comboBox.SqlStatement, comboBox.Name }); return(first != null); }); if (!exists) { var affectedRows = await sqlService.OpenConnection(async (c) => { return(await c.ExecuteAsync("Insert into ESS_MS_Controls_DropDownBox (sqlstatement, boxname, selectcolumn, selectcolumnbackground, fscontrolname) values " + "(:sqlstatement, :name, :selectcolumn, :selectcolumnbackground, :fscontrolname)", new { comboBox.SqlStatement, comboBox.Name, comboBox.SelectColumn, comboBox.SelectColumnBackground, comboBox.FsControlName })); }); await logService.WriteAsync($"Installed ComboBox at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Didnt install ComboBox at {installableObject.Target}, because it already existed.", LogLevel.Info); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install ComboBox at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is EplReportDesign eplReportDesign) { var result = new InstallObjectResult { Success = true }; try { var execResult = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync("Insert into EPL_ReportDesign (id, internname, displayname, reportcontent, printerheadwidth) " + "on existing update values (:id, :internalname, :displayname, :reportcontent, :printerheadwidth)", new { eplReportDesign.Id, eplReportDesign.InternalName, eplReportDesign.DisplayName, eplReportDesign.ReportContent, eplReportDesign.PrinterHeadWidth }); return(affectedRows > 0); }); if (execResult) { await logService.WriteAsync($"Installed EplReportDesign at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Failed to install EplReportDesign at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install EplReportDesign at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is StackFulltext stackFulltext) { var result = new InstallObjectResult { Success = true }; try { var sqlStatement = ""; if (stackFulltext.Configuration is SqlConfiguration sqlConfiguration) { sqlStatement = sqlConfiguration.Statement; } result.Success = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync("Insert into Stack_ContentExtractionSql (guid, stackguid, sql) on existing update values (:id, :stackid, :sqlstatement)", new { stackFulltext.Id, stackFulltext.StackId, sqlStatement }); return(affectedRows > 0); }); if (result.Success) { await logService.WriteAsync($"Installed StackFulltext at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Failed to install StackFulltext at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install StackFulltext at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is IconContent icon) { var result = new InstallObjectResult { Success = true }; try { var simplicIcon = new Simplic.Icon.Icon { Guid = icon.Guid, IconBlob = icon.Blob, Name = icon.Name }; if (iconService.Save(simplicIcon)) { await logService.WriteAsync($"Installed icon at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Failed to install icon at {installableObject.Target}.", LogLevel.Warning); result.Success = false; } } catch (Exception ex) { await logService.WriteAsync($"Failed to install icon at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is EplReport eplReport) { var result = new InstallObjectResult { Success = true }; try { var param = new StatementParam { Id = eplReport.Id, InternalName = eplReport.InternalName, IsContextlessPrintable = eplReport.IsContextlessPrintable, Printer = eplReport.Printer, ReportDesignId = eplReport.ReportDesignId }; var statement = "Insert into EPL_Report (id, reportid, internname, printername, iscontextlessprintable) " + "on existing update values (:Id, :ReportDesignId, :InternalName, :Printer, :IsContextlessPrintable)"; if (eplReport.Configuration is SqlConfiguration sqlConfiguration) { statement = "Insert into EPL_Report (id, reportid, internname, printername, iscontextlessprintable, sqldatasourcecode) " + "on existing update values (:Id, :ReportDesignId, :InternalName, :Printer, :IsContextlessPrintable, :SqlDataSourceCode)"; param.SqlDataSourceCode = sqlConfiguration.SqlDataSourceCode; } else if (eplReport.Configuration is SequenceConfiguration sequenceConfiguration) { statement = "Insert into EPL_Report (id, reportid, internname, printername, iscontextlessprintable, sequenceid) " + "on existing update values (:Id, :ReportDesignId, :InternalName, :Printer, :IsContextlessPrintable, :SequenceId)"; param.SequenceId = sequenceConfiguration.SequenceId; } else if (eplReport.Configuration is GridConfiguration gridConfiguration) { // Grid has no additional properties } var execResult = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync(statement, param); return(affectedRows > 0); }); if (execResult) { await logService.WriteAsync($"Installed EplReport at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Failed to install EplReport at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install EplReport at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is FullReport report) { var result = new InstallObjectResult { Success = true }; try { // TODO: Implement for sqlconfiguration var mapConfig = new MapperConfiguration(cfg => { cfg.CreateMap <KeyValueParameterItem, KeyValueParameterConfigurationModel>(MemberList.Source) .ForMember(dest => dest.Name, opt => opt.MapFrom(x => x.Name)) .ForMember(dest => dest.OrderId, opt => opt.MapFrom(x => x.OrderId)); cfg.CreateMap <Report, KeyValueConfigurationModel>(MemberList.Source) .ForMember(dest => dest.ConnectionString, opt => opt.MapFrom(x => x.Configuration.Connection)) .ForMember(dest => dest.PrinterName, opt => opt.MapFrom(x => x.Configuration.Provider)) .ForMember(dest => dest.IsListBased, opt => opt.MapFrom(x => ((KeyValueConfiguration)x.Configuration).IsListBased)) .ForMember(dest => dest.Parameter, opt => opt.MapFrom(x => ((KeyValueConfiguration)x.Configuration).Parameter)) .ForMember(dest => dest.PrinterName, opt => opt.MapFrom(x => x.PrinterName)) .ForMember(dest => dest.Type, opt => opt.MapFrom <EnumResolver>()) .ForSourceMember(x => x.Configuration, opt => opt.DoNotValidate()); cfg.CreateMap <Report, ParameterConfigurationModel>(MemberList.Source) .ForMember(dest => dest.ConnectionString, opt => opt.MapFrom(x => x.Configuration.Connection)) .ForMember(dest => dest.ProviderName, opt => opt.MapFrom(x => x.Configuration.Provider)) .ForMember(dest => dest.ReportParameter, opt => opt.MapFrom(x => ((ParameterConfiguration)x.Configuration).Parameter)) .ForMember(dest => dest.PrinterName, opt => opt.MapFrom(x => x.PrinterName)) .ForMember(dest => dest.Type, opt => opt.MapFrom <EnumResolver>()) .ForSourceMember(x => x.Configuration, opt => opt.DoNotValidate()); }); mapConfig.AssertConfigurationIsValid(); var mapper = new Mapper(mapConfig); IReportConfiguration mappedReportConfiguration = null; if (report.Report.Configuration is KeyValueConfiguration) { mappedReportConfiguration = mapper.Map <Report, KeyValueConfigurationModel>(report.Report); } else if (report.Report.Configuration is ParameterConfiguration) { mappedReportConfiguration = mapper.Map <Report, ParameterConfigurationModel>(report.Report); } else { throw new NotImplementedException(); } ReportManager.Singleton.SaveConfiguration(mappedReportConfiguration); ReportManager.Singleton.SaveReportFile(mappedReportConfiguration.ReportName, report.ReportData); result.Success = true; await logService.WriteAsync($"Installed Report at {installableObject.Target}.", LogLevel.Info); } catch (Exception ex) { await logService.WriteAsync($"Failed to install Report at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is StackContextArea stackContextArea) { var result = new InstallObjectResult { Success = true }; try { var statement = $"Insert into IDContext (guid, displayname, stackguid, searchname) on existing update values (:Id, :DisplayName, :StackId, :SearchName)"; var param = new StatementParam { Id = stackContextArea.Id, StackId = stackContextArea.StackId, DisplayName = stackContextArea.DisplayName, SearchName = stackContextArea.SearchName }; if (stackContextArea.Configuration is GridConfiguration gridConfiguration) { statement = $"Insert into IDContext (guid, displayname, stackguid, searchname, gridname, isstackbased, usearchiv) " + $"on existing update values (:Id, :DisplayName, :StackId, :SearchName, :GridName, :StackBased, :ConnectWithArchive)"; param.ConnectWithArchive = gridConfiguration.ConnectWithArchive; param.StackBased = gridConfiguration.StackBased; param.GridName = gridConfiguration.Grid; } var execResult = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync(statement, param); return(affectedRows > 0); }); foreach (var item in stackContextArea.ContextOfStacks) { var exists = await IdContextAssignmentExists(item.StackId, stackContextArea.Id); Console.WriteLine(exists); Console.WriteLine(item); if (!exists) { await sqlService.OpenConnection(async (c) => { await c.ExecuteAsync("Insert into IDContext_Assignment (guid, stackguid, idcontextguid) values (:newguid, :stackid, :id)", new { newGuid = Guid.NewGuid(), item.StackId, stackContextArea.Id }); }); } } if (execResult) { await logService.WriteAsync($"Installed StackContextArea at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Failed to install StackContextArea at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install StackContextArea at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is StackAutoconnector stackAutoconnector) { var result = new InstallObjectResult { Success = true }; try { Guid?xmlId = null; var xmlText = ""; var description = ""; if (stackAutoconnector.Configuration is XmlConfiguration xmlConfiguration) { xmlText = xmlConfiguration.Xml; xmlId = xmlConfiguration.Id; description = xmlConfiguration.Description; } var xmlSuccess = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync("Insert into ESS_DCC_SqlText (guid, sqltext, description) on existing update values (:xmlId, :xmlText, :description)", new { xmlId, xmlText, description }); return(affectedRows > 0); }); if (xmlSuccess) { var success = await sqlService.OpenConnection(async (c) => { var affectedRows = await c.ExecuteAsync("Insert into ESS_DCC_Stack_AutoConnect (sourcestackguid, name, tostackguid, xmlguid) " + "on existing update values (:stackid, :name, :target, :xmlid)", new { stackAutoconnector.StackId, stackAutoconnector.Name, stackAutoconnector.Target, xmlId }); return(affectedRows > 0); }); if (success) { await logService.WriteAsync($"Installed StackAutoconnector at {installableObject.Target}.", LogLevel.Info); } else { await logService.WriteAsync($"Installed xml to ESS_DCC_SqlText but failed to install StackAutoconnector at {installableObject.Target}.", LogLevel.Warning); } } else { await logService.WriteAsync($"Failed to install StackAutoconnector at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { await logService.WriteAsync($"Failed to install StackRegister at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
// TODO: Output if this fails? /// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (installableObject.Content is ItemBox itemBox) { var result = new InstallObjectResult { Success = true }; try { // Get the ident var ident = await sqlService.OpenConnection(async (c) => { var _ident = await c.QueryFirstOrDefaultAsync <int?>("Select ident from ESS_MS_Controls_ItemBox where name = :name", new { itemBox.Name, itemBox.Title, itemBox.Description }); if (_ident != null) { await logService.WriteAsync($" ItemBox already exists, update: {itemBox.Name}", LogLevel.Debug); } else { await logService.WriteAsync($" ItemBox not found, create new ItemBox: {itemBox.Name}", LogLevel.Debug); _ident = await c.QueryFirstAsync <int>("SELECT GET_IDENTITY('ESS_MS_Controls_ItemBox')"); } return(_ident); }); var totalAffectedRows = await sqlService.OpenConnection(async (c) => { return(await c.ExecuteAsync("Insert into ESS_MS_Controls_ItemBox (ident, name, title, description) on existing update values " + "(:ident, :name, :title, :description); ", new { ident, itemBox.Name, itemBox.Title, itemBox.Description })); }); foreach (var profile in itemBox.Profiles) { var statement = GetStatement(profile.Type, profile.Grid); // Attempt to update var updated = await sqlService.OpenConnection(async (c) => { var rowsAffected = await c.ExecuteAsync("Update ESS_MS_Controls_ItemBox_Profiles " + "set displayname = :displayname," + " defaultsearchstring = :defaultsearchstring," + " isactive = :isactive," + " regex = :regex" + " where selectstatement = :statement and itemboxident = :ident", new { profile.DisplayName, profile.DefaultSearchString, profile.IsActive, profile.Regex, statement, ident }); return(rowsAffected > 0); }); if (!updated) { var inserted = await sqlService.OpenConnection(async (c) => { var rowsAffected = await c.ExecuteAsync("Insert into ESS_MS_Controls_ItemBox_Profiles (selectstatement, displayname, defaultsearchstring, itemboxident, isactive, regex) " + "values (:statement, :displayname, :defaultsearchstring, :ident, :isactive, :regex)", new { statement, profile.DisplayName, profile.DefaultSearchString, ident, profile.IsActive, profile.Regex }); return(rowsAffected > 0); }); } } result.Success = true; await logService.WriteAsync($"Succesfully installed ItemBox at {installableObject.Target}.", LogLevel.Info); } catch (Exception ex) { await logService.WriteAsync($"Failed to install ItemBox at {installableObject.Target}.", LogLevel.Error, ex); result.Success = false; } return(result); } throw new InvalidContentException(); }
/// <inheritdoc/> public async Task <InstallObjectResult> InstallObject(InstallableObject installableObject) { if (!(installableObject.Content is Application application)) { throw new InvalidContentException(); } var result = new InstallObjectResult { Success = true }; try { var contentTypeGuid = GetContentTypeId(application.Type); var success = await sqlService.OpenConnection(async (c) => await c.ExecuteAsync( "INSERT INTO ESS_MS_Intern_Page" + " (Guid, IconGuid, ContentType, MenuText, DirectJump, RibbonGroupGuid, RibbonOrderNr, RibbonButtonSize)" + " ON EXISTING UPDATE VALUES" + " (:Id, :IconId, :contentTypeGuid, :Name, :ShortCut, :RibbonGroupId, :RibbonOrderNr, :RibbonButtonSize)", new { application.Id, application.IconId, contentTypeGuid, application.Name, application.Shortcut, application.RibbonGroupId, application.RibbonOrderNr, application.RibbonButtonSize }) > 0 ); if (success) { if (await SaveConfiguration(application, application.Type)) { await logService.WriteAsync($"Installed Application at {installableObject.Target}.", LogLevel.Info); } else { result.Success = false; await logService.WriteAsync( $"Installed Application but failed to install ApplicationConfiguration at {installableObject.Target}.", LogLevel.Error); } } else { await logService.WriteAsync($"Failed to install Application at {installableObject.Target}.", LogLevel.Warning); } } catch (Exception ex) { result.Success = false; await logService.WriteAsync($"Failed to install Application at {installableObject.Target}.", LogLevel.Error, ex); } return(result); }