示例#1
0
        // ------------------------------------------
        // 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);
        }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <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);
        }
示例#4
0
        // 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);
        }
示例#5
0
        /// <summary>
        /// Checks this instance.
        /// </summary>
        /// <param name="optionSet">The set of options to consider.</param>
        /// <param name="optionSpecificationSet">The set of option specifications to consider.</param>
        /// <param name="allowMissingItems">Indicates whether the items can be missing.</param>
        /// <returns>Returns the log of check.</returns>
        public static IBdoLog Check(this IDataElementSet optionSet,
                                    IOptionSpecSet optionSpecificationSet,
                                    bool allowMissingItems = false)
        {
            var log = new BdoLog();

            if (optionSet?.Items != null && optionSpecificationSet != null)
            {
                if (!allowMissingItems)
                {
                    foreach (IDataSpecification optionSpecification in optionSpecificationSet.Items.Where(p => p.RequirementLevel == RequirementLevels.Required))
                    {
                        if (!optionSet.HasItem(optionSpecification.Name))
                        {
                            log.AddError("Option '" + optionSpecification.Name + "' missing");
                        }
                    }
                }

                foreach (IScalarElement option in optionSet.Items)
                {
                    if (option?.Specification != null)
                    {
                        switch (option.Specification.ItemRequirementLevel)
                        {
                        case RequirementLevels.Required:
                            if (string.IsNullOrEmpty(option.Items[0] as string))
                            {
                                log.AddError("Option '" + option.Name + "' requires value");
                            }
                            break;

                        case RequirementLevels.Forbidden:
                            if (!string.IsNullOrEmpty(option.Items[0] as string))
                            {
                                log.AddError("Option '" + option.Name + "' does not allow value");
                            }
                            break;
                        }
                    }
                }
            }

            return(log);
        }
示例#6
0
        // --------------------------------------------------
        // 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 (dataElement == null)
            {
                log.AddError("Element missing");
            }
            else if (dataElement.Items.Count == 0 || dataElement.Items[0] == null)
            {
                log.AddError("Item required").ResultCode = "ERROR_ITEMREQUIRED:" + dataElement.Key();
            }
            else if (dataElement.ValueType.IsScalar() && dataElement.Items.Count == 1 && string.IsNullOrEmpty(dataElement.GetValue().ToNotNullString()))
            {
                log.AddError("Item required").ResultCode = "ERROR_ITEMREQUIRED:" + dataElement.Key();
            }

            return(log);
        }
示例#7
0
        public void OneTimeSetUp()
        {
            var log = new BdoLog();

            for (int i = 0; i < 2; i++)
            {
                log.AddError("Error" + i);
                log.AddException("Exception" + i);
                log.AddMessage("Message" + i);
                log.AddWarning("Warning" + i);
                log.AddSubLog(new BdoLog()
                {
                    DisplayName = "Sub log" + i
                });
            }

            _testData = new
            {
                log
            };
        }