Example #1
0
        void GetSettingsInformation(BGSDKSettings settings)
        {
            if (settings != null)
            {
                string message;
                EditorUtilities.ValidateSettingsModel(settings, out message);

                info = new BGSDKSettingsInfo()
                {
                    value = new GUIContent(message)
                };
            }
        }
Example #2
0
        /// <summary>
        /// <para>Tests the provided settings object for conflicts that could prevent processing.</para>
        /// </summary>
        /// <remarks>
        /// <para>Conditions tested for by this method include the following.</para>
        /// <list type="table">
        /// <listheader>
        /// <term>State</term>
        /// <term>Description</term>
        /// </listheader>
        /// <item><term>Empty Contracts</term><term>This is a contract with no tokens assigned to it.</term></item>
        /// <item><term>Orphaned Tokens</term><term>This is a token with no contract assigned to it.</term></item>
        /// <item><term>Empty Contract Names</term><term>This is a contract whoes name is empty.</term></item>
        /// <item><term>Empty Contract Description</term><term>This is a contract whoes description is empty.</term></item>
        /// <item><term>Empty Token Name</term><term>This is a token whoes name is empty.</term></item>
        /// <item><term>Empty Token Description</term><term>This is a token whoes description is empty.</term></item>
        /// <item><term>Duplicate Contract Name</term><term>This is a contract which shares a name with another contract.</term></item>
        /// <item><term>Duplicate Contract Address</term><term>This is a contract which shares an address with another contract.</term></item>
        /// <item><term>Duplicate Token Name</term><term>This is a token which shares a name with another token.</term></item>
        /// <item><term>Empty Model</term><term>This indicates that no valid contracts and tokens have been added to the tested model.</term></item>
        /// </list>
        /// </remarks>
        /// <param name="settings">The settings to be tested</param>
        /// <param name="message">The resulting messages</param>
        /// <returns>
        /// <list type="table">
        /// <listheader>
        /// <term>Type</term>
        /// <term>Description</term>
        /// </listheader>
        /// <item><term><see cref="ValidationStatus.Okay"/></term><term>No issues where found</term></item>
        /// <item><term><see cref="ValidationStatus.Warning"/></term><term>has an Empty Contract or Empty Contract Description or Empty Token Description or Duplicate Contract Name or Duplicate Token Name</term></item>
        /// <item><term><see cref="ValidationStatus.Error"/></term><term>has an Empty Model or Empty Token Name or Empty Contract Name or Orphaned Tokens or Duplicate Contract Address</term></item>
        /// </list>
        /// </returns>
        public static ValidationStatus ValidateSettingsModel(BGSDKSettings settings, out string message, bool ignoreEmptyModel = false)
        {
            bool hasEmptyContract            = false;
            bool hasOrphanedToken            = false;
            bool hasEmptyContractName        = false;
            bool hasEmptyContractDescription = false;
            bool hasEmptyTokenName           = false;
            bool hasEmptyTokenDescription    = false;
            bool hasDuplicateContractName    = false;
            bool hasDuplicateContractAddress = false;
            bool hasDuplicateTokenName       = false;
            bool hasEmptyModel = false;
            bool hasMultiToken = false;

            string TokenMultiReference      = "One or more tokens is referenced by two or more contracts.";
            string EmptyContract            = "One or more contracts have no tokens.";
            string OrphanedToken            = "One or more tokens lack a contract reference.";
            string ContractName             = "One or more contracts have no name.";
            string ContractDescription      = "One or more contracts have no description.";
            string DuplicateContractName    = "Duplicate contract names detected.";
            string DuplicateContractAddress = "Duplicate contract address detected.";
            string DuplicateTokenName       = "Duplicate token names detected.";
            string TokenName        = "One or more tokens have no name.";
            string TokenDescription = "One or more tokens have no description.";
            string EmptyModel       = "No datamodel elements detected.";
            string NoErrors         = "No errors";

            if (!ignoreEmptyModel)
            {
                if (settings.contracts == null || settings.contracts.Count < 1)
                {
                    hasEmptyModel = true;
                }
            }
            else
            {
                if (settings.contracts == null)
                {
                    settings.contracts = new List <Engine.Contract>();
                }
            }

            if (!hasEmptyModel)
            {
                foreach (var contract in settings.contracts)
                {
                    if (contract == null)
                    {
                        continue;
                    }

                    if (!hasDuplicateContractAddress && settings.contracts.Where(p => p.Address != string.Empty && p.Address == contract.Address).Count() > 1)
                    {
                        hasDuplicateContractAddress = true;
                    }

                    if (!hasEmptyContract && (contract.tokens == null || contract.tokens.Count == 0))
                    {
                        hasEmptyContract = true;
                    }

                    if (!hasDuplicateContractName && settings.contracts.Where(p => p.SystemName == contract.SystemName).Count() > 1)
                    {
                        hasDuplicateContractName = true;
                    }

                    if (!hasEmptyContractName && string.IsNullOrEmpty(contract.SystemName))
                    {
                        hasEmptyContractName = true;
                    }

                    if (!hasEmptyContractDescription && string.IsNullOrEmpty(contract.Description))
                    {
                        hasEmptyContractDescription = true;
                    }

                    foreach (var token in contract.tokens)
                    {
                        if (token == null)
                        {
                            continue;
                        }

                        if (!hasMultiToken)
                        {
                            hasMultiToken = settings.contracts.Where(p => p.tokens.Contains(token)).Count() > 1;
                        }

                        if (!hasDuplicateTokenName && contract.tokens.Where(p => p.SystemName == token.SystemName).Count() > 1)
                        {
                            hasDuplicateTokenName = true;
                        }

                        if (!hasEmptyTokenName && string.IsNullOrEmpty(token.SystemName))
                        {
                            hasEmptyTokenName = true;
                        }

                        if (!hasEmptyTokenDescription && string.IsNullOrEmpty(token.Description))
                        {
                            hasEmptyTokenDescription = true;
                        }

                        if (!hasOrphanedToken && token.contract == null)
                        {
                            hasOrphanedToken = true;
                        }

                        if (string.IsNullOrEmpty(token.SystemName))
                        {
                            hasEmptyTokenName = true;
                        }

                        if (string.IsNullOrEmpty(token.Description))
                        {
                            hasEmptyTokenDescription = true;
                        }

                        if (token.contract != contract)
                        {
                            token.contract = contract;
                        }
                    }
                }
            }



            bool hasErrors = hasEmptyContract || hasOrphanedToken || hasEmptyContractName || hasEmptyContractDescription || hasEmptyTokenName || hasEmptyTokenDescription || hasEmptyModel;

            if (hasErrors)
            {
                message = "\n";
                if (hasEmptyContract)
                {
                    message += EmptyContract + "\n";
                }
                if (hasOrphanedToken)
                {
                    message += OrphanedToken + "\n";
                }
                if (hasMultiToken)
                {
                    message += TokenMultiReference + "\n";
                }
                if (hasEmptyContractName)
                {
                    message += ContractName + "\n";
                }
                if (hasEmptyContractDescription)
                {
                    message += ContractDescription + "\n";
                }
                if (hasEmptyTokenName)
                {
                    message += TokenName + "\n";
                }
                if (hasEmptyTokenDescription)
                {
                    message += TokenDescription + "\n";
                }
                if (hasDuplicateContractName)
                {
                    message += DuplicateContractName + "\n";
                }
                if (hasDuplicateTokenName)
                {
                    message += DuplicateTokenName + "\n";
                }
                if (hasDuplicateContractAddress)
                {
                    message += DuplicateContractAddress + "\n";
                }
                if (hasEmptyModel)
                {
                    message += EmptyModel + "\n";
                }

                message.Trim();
            }
            else
            {
                message = NoErrors;
            }

            if (hasEmptyModel || hasEmptyTokenName || hasEmptyContractName || hasOrphanedToken || hasDuplicateContractAddress)
            {
                return(ValidationStatus.Error);
            }
            else if (hasEmptyContract || hasEmptyContractDescription || hasEmptyTokenDescription || hasDuplicateContractName || hasDuplicateTokenName)
            {
                return(ValidationStatus.Warning);
            }
            else
            {
                return(ValidationStatus.Okay);
            }
        }