/// <summary> /// Creates the instance of the specified extension object instance type. /// </summary> /// <param name="fullyQualifiedName">The type fully qualified name to consider.</param> /// <param name="object1">The object to consider.</param> /// <param name="attributes">The attributes to consider.</param> public static IBdoLog CreateInstance( string fullyQualifiedName, out object object1, params object[] attributes) { var log = new BdoLog(); object1 = null; try { Type type = Type.GetType(fullyQualifiedName); if (type == null) { log.AddError("Unknown type '" + fullyQualifiedName + "'"); } else { object1 = Activator.CreateInstance(type); } } catch (Exception ex) { log.AddException(ex); } return(log); }
// Create ------------------------------------- /// <summary> /// Creates a connector. /// </summary> /// <param name="scope">The scope to consider.</param> /// <param name="dataSource">The data source to consider.</param> /// <param name="connectorDefinitionUniqueId">The connector definition name to consider.</param> /// <param name="log">The log of execution to consider.</param> /// <returns>Returns True if the connector has been opened. False otherwise.</returns> public static T Open <T>( this IBdoScope scope, IDatasource dataSource, string connectorDefinitionUniqueId, IBdoLog log = null) where T : class, IBdoConnection { if (log == null) { log = new BdoLog(); } if (dataSource == null) { log.AddError("Data source missing"); } else if (!string.IsNullOrEmpty(connectorDefinitionUniqueId) && dataSource.HasConfiguration(connectorDefinitionUniqueId)) { log.AddError("Connection not defined in data source", description: "No connector is defined in the specified data source."); } else if (!string.IsNullOrEmpty(connectorDefinitionUniqueId)) { return(scope.Open <T>(dataSource.GetConfiguration(connectorDefinitionUniqueId), log)); } else if (dataSource.Configurations.Count > 0) { return(scope.Open <T>(dataSource.Configurations[0], log)); } return(default);
// ------------------------------------------ // ACCESSORS // ------------------------------------------ #region Accessors // SQL commands /// <summary> /// Gets the SQL text of the specified query. /// </summary> /// <param name="query">The query to consider.</param> /// <param name="parameterMode">Indicates whether parameters are replaced.</param> /// <param name="parameterSet">The parameter set to consider.</param> /// <param name="scriptVariableSet">The script variable set to consider.</param> /// <param name="log">The log to consider.</param> /// <returns>Returns the SQL text of the specified query.</returns> public string CreateCommandText( IDbQuery query, DbQueryParameterMode parameterMode = DbQueryParameterMode.ValueInjected, IDataElementSet parameterSet = null, IScriptVariableSet scriptVariableSet = null, IBdoLog log = null) { string sqlText = ""; if (QueryBuilder == null) { log?.AddError("Data builder missing"); } else { var subLog = new BdoLog(); sqlText = QueryBuilder.BuildQuery(query, parameterMode, parameterSet, scriptVariableSet, subLog); log?.AddEvents(subLog); if (subLog.HasErrorsOrExceptions()) { return(StringHelper.__NoneString); } } return(sqlText); }
public void InterpreteScript6Test() { var log = new BdoLog(); var scriptVariableSet = BdoScript.CreateVariableSet(); var resultScript = GlobalVariables.Scope.Interpreter.Evaluate <string>( _script6, default, scriptVariableSet, log)?.ToString();
/// <summary> /// Loads the specified extensions into the specified scope. /// </summary> /// <param name="references">The library references to consider.</param> public IBdoLog LoadExtensionsInStore(params IBdoAssemblyReference[] references) { var log = new BdoLog(); if (_store == null) { return(log); } // we load libraries foreach (IBdoAssemblyReference reference in references) { if (reference != null) { IBdoLog subLog = LoadLibrary(reference); if (subLog.HasErrorsOrExceptionsOrWarnings()) { log.AddSubLog(subLog, title: "Loading extension '" + (reference?.Name ?? "?") + "'"); } else { log.AddMessage("Extension '" + (reference?.Name ?? "?") + "' loaded"); } } } return(log); }
public void TestSqlLike() { var expression = DbFluent.Like( DbFluent.Table("MyTable"), DbFluent.Concat("%", DbFluent.Parameter("myText").AsExp(), "%")); var log = new BdoLog(); string expectedResult = @"$sqlLike($sqlTable('MyTable'), $sqlConcat($sqlText('%'), $sqlParameter('myText'), $sqlText('%')))"; string result = (string)expression; string xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); // scripted result = _appHost.Interpreter.Evaluate <string>( expression, new ScriptVariableSet().SetDbBuilder(new DbQueryBuilder_PostgreSql()), log: log); expectedResult = @"(""MyTable"" like concat('%', |*|p:myText|*|, '%'))"; xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
/// <summary> /// Gets the result of the serialization of the specified object. /// </summary> /// <param name="elementSet">The element set to consider.</param> /// <param name="object1">The object to serialize.</param> /// <typeparam name="T">The data element attribute to consider.</typeparam> /// <returns>The Xml string serializing the specified object.</returns> public static IBdoLog UpdateFromObject <T>( this IDataElementSet elementSet, object object1) where T : DataElementAttribute { var log = new BdoLog(); if (elementSet != null && object1 != null) { foreach (PropertyInfo propertyInfo in object1.GetType().GetProperties()) { if (propertyInfo.GetCustomAttribute(typeof(DetailPropertyAttribute)) is DetailPropertyAttribute attribute) { string name = attribute.Name; if (string.IsNullOrEmpty(name)) { name = propertyInfo.Name; } elementSet.Add( ElementFactory.Create( name, propertyInfo.PropertyType.GetValueType(), propertyInfo.GetValue(object1))); } } } return(log); }
public void SimpleUpdate1() { var log = new BdoLog(); string code = "codeC"; string expectedResult = @"update ""Mdm"".""Employee"" set " + @"""Code""='" + code + "'" + @", ""ByteArrayField""='" + _employee.ByteArrayField.ToString(DataValueTypes.ByteArray).Replace("'", "''") + "'" + @", ""DoubleField""=" + _employee.DoubleField.ToString(DataValueTypes.Number) + @", ""DateTimeField""='" + _employee.DateTimeField.ToString(DataValueTypes.Date) + "'" + @", ""LongField""=" + _employee.LongField.ToString(DataValueTypes.Long) + @" from ""Mdm"".""Employee"" " + @"left join ""Mdm"".""RegionalDirectorate"" on (""Mdm"".""Employee"".""EmployeeId""=""Mdm"".""RegionalDirectorate"".""RegionalDirectorateId"")" + @" returning ""Mdm"".""Employee"".""Code"""; string result = _dbConnector.CreateCommandText(_model.UpdateEmployee1(code, true, _employee), log: log); string xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
public void ConnectorUsingConnectionTest() { BdoLog log = new BdoLog(); // check bad connection _connector?.UsingConnection((p, l) => { }, log); string xml = string.Empty; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml() + "'"; } Assert.That(!log.HasErrorsOrExceptions(), "Connection creation failed" + xml); // check bad connection try { _connector?.UsingConnection((p, l) => { string toto = null; int i = toto.Length; }, log); } catch (NullReferenceException ex) { log.AddException(ex); } xml = string.Empty; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml() + "'"; } Assert.That(log.HasErrorsOrExceptions(), "Connection creation failed" + xml); }
// ------------------------------------------ // ACCESSORS // ------------------------------------------ #region Accessors /// <summary> /// Check the specified item. /// </summary> /// <param name="isExtensionStoreChecked">Indicates whether the extension item definition store extistence is chekced.</param> /// <param name="isScriptInterpreterChecked">Indicates whether the script interpreter extistence is chekced.</param> /// <param name="isDataContextChecked">Indicates whether the data context extistence is chekced.</param> /// <param name="isDataStoreChecked">Indicates whether the data store extistence is chekced.</param> /// <returns>The log of check log.</returns> public IBdoLog Check( bool isExtensionStoreChecked = false, bool isScriptInterpreterChecked = false, bool isDataContextChecked = false, bool isDataStoreChecked = false) { var log = new BdoLog(); if (isExtensionStoreChecked && ExtensionStore == null) { log.AddError(title: "Application extension missing", description: "No extension item definition store specified."); } if (isScriptInterpreterChecked && Interpreter == null) { log.AddError(title: "Script interpreter missing", description: "No script interpreter specified."); } if (isDataContextChecked && Context == null) { log.AddError(title: "Data context missing", description: "No data context specified."); } if (isDataStoreChecked && DataStore == null) { log.AddError(title: "Depot set missing", description: "No depot set specified."); } return(log); }
public void CreateCarrierElementSetTest() { var log = new BdoLog(); var carrierElement1 = ElementFactory.CreateCarrier( "carrier1", "tests.core$testCarrier", BdoExtensionFactory.CreateCarrierConfiguration( "tests.core$testCarrier", ElementFactory.CreateScalar("path", _testData.path1))); var carrierElement2 = ElementFactory.CreateCarrier("carrier2", "tests.core$testCarrier") .WithConfiguration(ElementFactory.CreateSetFromObject <BdoCarrierConfiguration>(new { path = _testData.path2 })); var carrierElement3 = new CarrierFake(_testData.path3, _testData.folderPath3)?.AsElement(); var carrierElement4 = GlobalVariables.Scope.CreateCarrier( BdoExtensionFactory.CreateCarrierConfiguration("tests.core$testCarrier") .WithItems(ElementFactory.CreateSetFromObject(new { path = _testData.path4 })?.ToArray()), "carrier4", log)?.AsElement(); _carrierElementSet = ElementFactory.CreateSet( carrierElement1, carrierElement2, carrierElement3, carrierElement4); Test(_carrierElementSet); }
// -------------------------------------------------- // EXECUTION // -------------------------------------------------- #region Execution /// <summary> /// Executes customly this instance. /// </summary> /// <param name="scope">The scope to consider.</param> /// <param name="scriptVariableSet">The script variable set to use.</param> /// <param name="item">The item to use.</param> /// <param name="dataElement">The element to use.</param> /// <param name="objects">The objects to use.</param> /// <returns>The log of check log.</returns> protected override IBdoLog CustomExecute( IBdoScope scope = null, IScriptVariableSet scriptVariableSet = null, Object item = null, IDataElement dataElement = null, params object[] objects) { var log = new BdoLog(); //if (item!=null && ParameterDetail!=null) //{ // String aFormat = (ParameterDetail.GetElementItem() as string ?? string.Empty); // String aString = ((item as string) ?? string.Empty); // if (!string.IsNullOrEmpty(aFormat)) // { // if (!String.Format(aString, aFormat).KeyEquals(aString)) // { // log.AddError("Bad format").ResultCode = "ERROR_FORMAT:" + (dataElement != null ? dataElement.Key() : string.Empty); // } // } //} return(log); }
public void SimpleInsertWithSelectWithSubQuery() { var log = new BdoLog(); string expectedResult = @"insert into ""Mdm"".""Employee"" (""Code"", ""ByteArrayField"", ""DoubleField"", ""DateTimeField"", ""LongField"") " + @"(select " + "'" + _employee.Code.Replace("'", "''") + "'" + ", '" + _employee.ByteArrayField.ToString(DataValueTypes.ByteArray).Replace("'", "''") + "'" + ", " + _employee.DoubleField.ToString(DataValueTypes.Number) + ", '" + _employee.DateTimeField.ToString(DataValueTypes.Date) + "'" + ", " + _employee.LongField.ToString(DataValueTypes.Long) + @", (select ""Mdm"".""Contact"".""ContactId"" from ""Mdm"".""Contact"" where ""Code""='contactCodeA' limit 1)" + @" from ""Mdm"".""Employee"" where ""Code""='oldCode' )" + @" returning ""Mdm"".""Employee"".""EmployeeId"""; string result = _dbConnector.CreateCommandText(_model.InsertEmployee3(_employee), log: log); string xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
// Open ------------------------------------- /// <summary> /// Creates a connector. /// </summary> /// <param name="scope">The scope to consider.</param> /// <param name="depot">The data source depot to consider.</param> /// <param name="dataSourceName">The data source name to consider.</param> /// <param name="connectorDefinitionUniqueId">The connector definition name to consider.</param> /// <param name="log">The log of execution to consider.</param> /// <returns>Returns True if the connector has been opened. False otherwise.</returns> public static T Open <T>( this IBdoScope scope, IBdoDatasourceDepot depot, string dataSourceName, string connectorDefinitionUniqueId, IBdoLog log = null) where T : class, IBdoConnection { if (log == null) { log = new BdoLog(); } if (depot == null) { depot = scope?.DataStore?.Get <IBdoDatasourceDepot>(); } if (depot == null) { log.AddError("Data source depot missing"); } else if (!depot.HasItem(dataSourceName)) { log.AddError("Data source '" + dataSourceName + "' missing in depot"); } else { return(scope.Open <T>(depot.Get(dataSourceName), connectorDefinitionUniqueId, log)); } return(default);
public void TestInterprete_Fun_SqlEq() { var log = new BdoLog(); string value = null; string fluentScript = DbFluent.Eq( DbFluent.Field("RegionalDirectorateId"), DbFluent.IfNull(value, DbFluent.Field("RegionalDirectorateId"))); string expectedScript = "$sqlEq($sqlField('RegionalDirectorateId'), $sqlIfNull($sqlNull(), $sqlField('RegionalDirectorateId')))"; string xml = ""; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(expectedScript.Equals(fluentScript, StringComparison.OrdinalIgnoreCase), "Bad fluent interpretation. Result was '" + xml); var scriptVariableSet = new ScriptVariableSet(); scriptVariableSet.SetValue(VarSetDb.__DbBuilder, DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost)); string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString(); string expectedResult = @"""RegionalDirectorateId""=COALESCE(NULL, ""RegionalDirectorateId"")"; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml(); } Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
// Deserialiaze ---------------------------- /// <summary> /// Loads a data item from the specified file path. /// </summary> /// <param name="filePath">The path of the Xml file to load.</param> /// <param name="scope">The scope to consider.</param> /// <param name="scriptVariableSet">The set of script variables to consider.</param> /// <param name="log">The output log of the method.</param> /// <param name="xmlSchemaSet">The XML schema set to consider for checking.</param> /// <param name="mustFileExist">Indicates whether the file must exist.</param> /// <param name="isRuntimeUpdated">Indicates whether it is updated in runtime.</param> /// <returns>The loaded log.</returns> /// <remarks>If the XML schema set is null then the schema is not checked.</remarks> public static T Load <T>( String filePath, IBdoScope scope = null, IScriptVariableSet scriptVariableSet = null, IBdoLog log = null, XmlSchemaSet xmlSchemaSet = null, bool mustFileExist = true, bool isRuntimeUpdated = true) where T : class, IDataItem { T dataItem = default; StreamReader streamReader = null; if (!File.Exists(filePath)) { if (mustFileExist) { log?.AddError("File not found ('" + filePath + "'). Could not load '" + typeof(T).Name + "' object"); } } else { try { IBdoLog checkLog = new BdoLog(); if (xmlSchemaSet != null) { XDocument xDocument = XDocument.Load(filePath); xDocument.Validate(xmlSchemaSet, (o, e) => checkLog.AddError("File not valid ('" + filePath + "'). Could not load '" + typeof(T).Name + "' object")); log?.AddEvents(checkLog); } if (!checkLog.HasErrorsOrExceptions()) { // then we load XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); streamReader = new StreamReader(filePath); dataItem = xmlSerializer.Deserialize(XmlReader.Create(streamReader)) as T; if (isRuntimeUpdated) { dataItem?.UpdateRuntimeInfo(scope, scriptVariableSet, log); } } } catch (Exception ex) { log?.AddException(ex); } finally { streamReader?.Close(); } } return(dataItem); }
// -------------------------------------------------- // CHECKING // -------------------------------------------------- #region Checking /// <summary> /// Check value. /// </summary> /// <param name="item">The item to consider.</param> /// <param name="dataElement">The element to consider.</param> /// <param name="isDeepCheck">Indicates whether other rules than allowed and forbidden values are checked.</param> /// <returns>The log of check log.</returns> public IBdoLog CheckItem( object item, IDataElement dataElement, bool isDeepCheck = false) { var log = new BdoLog(); return(log); }
public void LoadUsableConfigurationTest() { var log = new BdoLog(); if (_usableConfiguration1 == null || !File.Exists(_filePath1)) { SaveUsableConfigurationTest(); } _ = ConfigurationFactory.Load <BdoUsableConfiguration>(_filePath1, null, null, log); }
public void CreateDatasourceTest() { IBdoLog log = new BdoLog(); var datasource = ItemFactory.CreateDatasource("name", DatasourceKind.Database) .WithConfiguration( (GlobalVariables.Scope?.CreateConnectorConfiguration("tests.core$test", log) as BdoConnectorConfiguration)?.WithConnectionString("connectionString")); Assert.That( datasource != null, "Bad data source creation"); }
/// <summary> /// Updates this instance. /// </summary> /// <param name="item">The item to consider.</param> /// <param name="specificationAreas">The specification areas to consider.</param> /// <param name="updateModes">The update modes to consider.</param> /// <returns>Log of the operation.</returns> /// <remarks>Put reference collections as null if you do not want to repair this instance.</remarks> public override IBdoLog Update<T>( T item = default, string[] specificationAreas = null, UpdateModes[] updateModes = null) { var log = new BdoLog(); if (item is BdoConnectorConfiguration configuration) { log.AddEvents(Update(configuration, specificationAreas, updateModes)); } return log; }
/// <summary> /// Checks this instance. /// </summary> /// <param name="isExistenceChecked">Indicates whether the carrier existence is checked.</param> /// <param name="item">The item to consider.</param> /// <param name="specificationAreas">The specification areas to consider.</param> /// <returns>Returns the check log.</returns> public override IBdoLog Check<T>( bool isExistenceChecked = true, T item = default, string[] specificationAreas = null) { var log = new BdoLog(); if (item is BdoConnectorConfiguration configuration) { log.AddEvents(Check(isExistenceChecked, configuration, specificationAreas)); } return log; }
/// <summary> /// Checks this instance. /// </summary> /// <param name="isExistenceChecked">Indicates whether the carrier existence is checked.</param> /// <param name="item">The item to consider.</param> /// <param name="specificationAreas">The specification areas to consider.</param> /// <returns>Returns the check log.</returns> public override IBdoLog Check <T1>( bool isExistenceChecked = true, T1 item = default, string[] specificationAreas = null) { var log = new BdoLog(); if (item is BdoCarrierConfiguration configuration) { log.AddEvents(base.Check(isExistenceChecked, configuration, specificationAreas)); } return(log); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="item"></param> /// <param name="specificationAreas"></param> /// <param name="updateModes"></param> /// <returns></returns> public override IBdoLog Update <T>(T item = default, string[] specificationAreas = null, UpdateModes[] updateModes = null) { var log = new BdoLog(); if (item is ExtensionLoadOptions options) { WithLibraryFolderPath(options.LibraryFolderPath); WithRemoteServerUri(options.RemoteServerUri); WithSourceKinds(options.SourceKinds?.ToArray()); } return(log); }
public void AddFields() { var log = new BdoLog(); var tuple = DbFluent.Tuple( DbFluent.Field("field1", DbFluent.Table("Table1")), DbFluent.Field("field2", DbFluent.Table("Table1")), DbFluent.Field("field3", DbFluent.Table("Table1")).WithAlias("f3")) .AddFields( DbFluent.FieldAsLiteral("field1", 1), DbFluent.FieldAsLiteral("field2", DbFluent.Table("Table2"), 2).WithAlias("f3")); Assert.That(tuple.Fields.Count == 3, "Bad script interpretation"); }
// -------------------------------------------------- // CHECK, UPDATE, REPAIR // -------------------------------------------------- #region Check_Update_Repair /// <summary> /// Updates this instance. /// </summary> /// <param name="item">The item to consider.</param> /// <param name="specificationAreas">The specification areas to consider.</param> /// <param name="updateModes">The update modes to consider.</param> /// <returns>Log of the operation.</returns> /// <remarks>Put reference collections as null if you do not want to repair this instance.</remarks> public override IBdoLog Update <T1>( T1 item = default, string[] specificationAreas = null, UpdateModes[] updateModes = null) { var log = new BdoLog(); if (item is BdoCarrierConfiguration configuration) { log.AddEvents(base.Update(configuration, specificationAreas, updateModes)); } return(log); }
/// <summary> /// Loads the data item from the specified file path. /// </summary> /// <typeparam name="T">The data item class to consider.</typeparam> /// <param name="xmlString">The Xml string to load.</param> /// <param name="scope">The scope to consider.</param> /// <param name="scriptVariableSet">The set of script variables to consider.</param> /// <param name="log">The output log of the load method.</param> /// <param name="xmlSchemaSet">The XML schema set to consider for checking.</param> /// <returns>The loaded log.</returns> /// <remarks>If the XML schema set is null then the schema is not checked.</remarks> public static T LoadFromString <T>( String xmlString, IBdoScope scope = null, IScriptVariableSet scriptVariableSet = null, IBdoLog log = null, XmlSchemaSet xmlSchemaSet = null) where T : DataItem { T dataItem = null; if (xmlString != null) { StreamReader streamReader = null; try { IBdoLog checkLog = new BdoLog(); if (xmlSchemaSet != null) { XDocument xDocument = XDocument.Parse(xmlString); xDocument.Validate(xmlSchemaSet, (o, e) => { log?.AddError( title: "Xml string not valid", description: e.Message); }); log?.AddEvents(checkLog); } if (!checkLog.HasErrorsOrExceptions()) { // then we load XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); StringReader stringReader = new StringReader(xmlString); dataItem = xmlSerializer.Deserialize(XmlReader.Create(stringReader)) as T; dataItem?.UpdateRuntimeInfo(scope, scriptVariableSet, log); } } catch (Exception ex) { log?.AddException(ex); } finally { streamReader?.Close(); } } return(dataItem); }
public void TestRepositoryUsingConnection() { Assert.That(_repository?.Connector?.ConnectionString != StringHelper.__NoneString, "Could not retrieve the string connection of connector"); var log = new BdoLog(); _repository.UsingConnection( (p, l) => { }, log); Assert.That(log.HasErrorsOrExceptions(), "Using connection method not working"); }
public void WordToStringTest() { var log = new BdoLog(); var script = _scriptword1?.ToString(); string xml = string.Empty; if (log.HasErrorsOrExceptions()) { xml = ". Result was '" + log.ToXml() + "'"; } Assert.That(_script1.Equals(script, StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml); }
// -------------------------------------------------- // UPDATE, CHECK, REPAIR // -------------------------------------------------- #region Update_Check_Repair /// <summary> /// Updates this instance. /// </summary> /// <param name="item">The item to consider.</param> /// <param name="specificationAreas">The specification areas to consider.</param> /// <param name="updateModes">The update modes to consider.</param> /// <returns>Log of the operation.</returns> /// <remarks>Put reference collections as null if you do not want to repair this instance.</remarks> public override IBdoLog Update <T1>( T1 item = default, string[] specificationAreas = null, UpdateModes[] updateModes = null) { var log = new BdoLog(); if (specificationAreas == null) { specificationAreas = new[] { nameof(DataAreaKind.Any) } } ; if (updateModes == null) { updateModes = new[] { UpdateModes.Incremental_AddItemsMissingInTarget } } ; base.Update <T1>(item, specificationAreas, updateModes); if (item is ITDataItemSet <DataElementSpec> referenceItem) { // we repair this instance if needed Repair(referenceItem, specificationAreas, updateModes.Excluding(UpdateModes.Incremental_UpdateCommonItems)); // we update the common element values if ((specificationAreas.Contains(nameof(DataAreaKind.Any))) || (specificationAreas.Contains(nameof(DataAreaKind.Items)))) { if (Items != null) { foreach (var subItem in Items) { if (subItem != null) { var referenceSubItem = referenceItem.Get(subItem.Key()); if (referenceSubItem != null) { subItem.Update(referenceSubItem, new[] { nameof(DataAreaKind.Items) }); } } } } } } return(log); }
/// <summary> /// Checks this instance. /// </summary> /// <param name="isExistenceChecked">Indicates whether the carrier existence is checked.</param> /// <param name="item">The item to consider.</param> /// <param name="specificationAreas">The specification areas to consider.</param> /// <returns>Returns the check log.</returns> public override IBdoLog Check <T1>( bool isExistenceChecked = true, T1 item = default, string[] specificationAreas = null) { var log = new BdoLog(); if (specificationAreas == null) { specificationAreas = new[] { nameof(DataAreaKind.Any) } } ; base.Check <T1>(isExistenceChecked, item, specificationAreas); if (item is ITDataItemSet <DataElementSpec> referenceItem) { // we check that all the elements in this instance are in the specified item if (Items != null) { foreach (var currentSubItem in Items) { if (!referenceItem.Items.Any(p => p.KeyEquals(currentSubItem))) { log.AddError(string.Empty).ResultCode = "additionalItem:" + currentSubItem.Key(); } } } // we check that all the elements in specified collections are in this instance foreach (var referenceSubItem in referenceItem.Items) { var currentSubItem = Items.Find(p => p.KeyEquals(referenceSubItem)); if (currentSubItem == null) { log.AddError(string.Empty).ResultCode = "MISSINGATTRIBUTE:" + referenceSubItem.Key(); } else { log.AddEvents(currentSubItem.Check(isExistenceChecked, referenceSubItem, specificationAreas)); } } } return(log); }