Exemplo n.º 1
0
        private static bool ValidateVersion(EnvelopeType ovfEnv, ValidationFlags validationFlags, ref List <string> validationErrorMessages)
        {
            bool isValid = true;

            if ((validationFlags & ValidationFlags.Version) != 0)
            {
                if (ovfEnv.version == null)
                {
                    if (ovfEnv.AnyAttr != null && ovfEnv.AnyAttr.Length > 0)
                    {
                        foreach (XmlAttribute attr in ovfEnv.AnyAttr)
                        {
                            if (attr.Name.ToLower().Contains("version"))
                            {
                                ovfEnv.version = attr.Value;
                                break;
                            }
                        }
                    }
                    if (ovfEnv.version == null)
                    {
                        Log.Warning("Version not set, applying 1.0.0");
                        ovfEnv.version = "1.0.0";
                    }
                }
                if (!Properties.Settings.Default.Versions.Contains(ovfEnv.version))
                {
                    isValid = false;
                    var message = string.Format(Messages.VALIDATION_INVALID_VERSION, ovfEnv.version);
                    Log.Warning(message);
                    validationErrorMessages.Add(message);
                }
            }
            return(isValid);
        }
Exemplo n.º 2
0
 public void AddDetail(ValidationResult detail)
 {
     detail.Context = this;
     EnsureDetails();
     IssueType |= detail.IssueType; // adds the values of the detail
     _details.Add(detail);
 }
Exemplo n.º 3
0
    void InjectMethodReturnGuard(ValidationFlags localValidationFlags, MethodDefinition method, MethodBody body)
    {
        var returnPoints = body.Instructions
                           .Select((o, ix) => new { o, ix })
                           .Where(a => a.o.OpCode == OpCodes.Ret)
                           .Select(a => a.ix)
                           .OrderByDescending(ix => ix);

        foreach (var ret in returnPoints)
        {
            if (localValidationFlags.HasFlag(ValidationFlags.ReturnValues) &&
                method.ReturnType.IsRefType() &&
                method.ReturnType.FullName != typeof(void).FullName &&
                !method.IsGetter &&
                !nullabilityAnalyzer.AllowsNullReturnValue(method))
            {
                var errorMessage = string.Format(ReturnValueOfMethodIsNull, method.FullName);
                AddReturnNullGuard(method, ret, method.ReturnType, errorMessage, Instruction.Create(OpCodes.Throw));
            }

            if (localValidationFlags.HasFlag(ValidationFlags.Arguments))
            {
                foreach (var parameter in method.Parameters.Reverse())
                {
                    // This is no longer the return instruction location, but it is where we want to jump to.
                    var returnInstruction = body.Instructions[ret];

                    if (localValidationFlags.HasFlag(ValidationFlags.OutValues) &&
                        parameter.ParameterType.IsRefType() &&
                        parameter.ParameterType.IsByReference &&
                        !parameter.IsIn &&
                        !nullabilityAnalyzer.AllowsNullOutput(parameter, method))
                    {
                        var errorMessage = $"[NullGuard] Out parameter '{parameter.Name}' is null.";

                        var guardInstructions = new List <Instruction>();

                        if (isDebug)
                        {
                            LoadArgumentOntoStack(guardInstructions, parameter);

                            CallDebugAssertInstructions(guardInstructions, errorMessage);
                        }

                        LoadArgumentOntoStack(guardInstructions, parameter);

                        IfNull(guardInstructions, returnInstruction, i =>
                        {
                            LoadInvalidOperationException(i, errorMessage);

                            // Throw the top item off the stack
                            i.Add(Instruction.Create(OpCodes.Throw));
                        });

                        body.InsertAtMethodReturnPoint(ret, guardInstructions);
                    }
                }
            }
        }
    }
Exemplo n.º 4
0
    private void InjectMethodReturnGuard(ValidationFlags localValidationFlags, MethodDefinition method, MethodBody body)
    {
        var guardInstructions = new List <Instruction>();

        var returnPoints = body.Instructions
                           .Select((o, ix) => new { o, ix })
                           .Where(a => a.o.OpCode == OpCodes.Ret)
                           .Select(a => a.ix)
                           .OrderByDescending(ix => ix);

        foreach (var ret in returnPoints)
        {
            var returnInstruction = body.Instructions[ret];

            if (localValidationFlags.HasFlag(ValidationFlags.ReturnValues) &&
                !method.MethodReturnType.AllowsNull() &&
                method.ReturnType.IsRefType() &&
                method.ReturnType.FullName != typeof(void).FullName)
            {
                AddReturnNullGuard(body.Instructions, ret, method.ReturnType, String.Format(CultureInfo.InvariantCulture, STR_ReturnValueOfMethodIsNull, method.FullName), Instruction.Create(OpCodes.Throw));
            }

            if (localValidationFlags.HasFlag(ValidationFlags.Arguments))
            {
                foreach (var parameter in method.Parameters.Reverse())
                {
                    // This is no longer the return instruction location, but it is where we want to jump to.
                    returnInstruction = body.Instructions[ret];

                    if (localValidationFlags.HasFlag(ValidationFlags.OutValues) &&
                        parameter.IsOut &&
                        parameter.ParameterType.IsRefType())
                    {
                        guardInstructions.Clear();

                        if (isDebug)
                        {
                            InstructionPatterns.LoadArgumentOntoStack(guardInstructions, parameter);

                            InstructionPatterns.CallDebugAssertInstructions(guardInstructions, String.Format(CultureInfo.InvariantCulture, STR_OutParameterIsNull, parameter.Name));
                        }

                        InstructionPatterns.LoadArgumentOntoStack(guardInstructions, parameter);

                        InstructionPatterns.IfNull(guardInstructions, returnInstruction, i =>
                        {
                            InstructionPatterns.LoadInvalidOperationException(i, String.Format(CultureInfo.InvariantCulture, STR_OutParameterIsNull, parameter.Name));

                            // Throw the top item off the stack
                            i.Add(Instruction.Create(OpCodes.Throw));
                        });

                        body.Instructions.Insert(ret, guardInstructions);
                    }
                }
            }
        }
    }
 public ValidationResult ValidateObject(
     ValidationResult validationResult,
     object objToValidate,
     ValidationFlags validationFlags)
 {
     ValidateObject(validationResult, objToValidate, validationFlags,
                    System.Threading.Thread.CurrentThread.CurrentUICulture);
     return validationResult;
 }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="objToValidate">The object that is being validated.</param>
        /// <param name="validationFlags">Options used to decide how validation is performed</param>
        /// <returns></returns>
        public ValidationResult ValidateObject(
            object objToValidate,
            ValidationFlags validationFlags)
        {
            ValidationUnitCollection rules  = GetRules(objToValidate);
            ValidationResult         result = new ValidationResult();

            return(rules.ValidateObject(result, objToValidate, validationFlags));
        }
Exemplo n.º 7
0
        public void CheckObject(Object objToValidate, ValidationFlags validationFlags)
        {
            ValidationResult res = ValidateObject(objToValidate, validationFlags);

            if (!res)
            {
                throw new ValidationException(res.Errors);
            }
        }
Exemplo n.º 8
0
 public ValidationResult ValidateObject(
     ValidationResult validationResult,
     object objToValidate,
     ValidationFlags validationFlags)
 {
     ValidateObject(validationResult, objToValidate, validationFlags,
                    System.Threading.Thread.CurrentThread.CurrentUICulture);
     return(validationResult);
 }
Exemplo n.º 9
0
 /// <summary>
 /// this is the real function that performs validation.
 /// </summary>
 /// <param name="actualResult"></param>
 /// <param name="objToValidate"></param>
 /// <param name="validationFlag"></param>
 /// <param name="cultureInfo"></param>
 /// <returns></returns>
 public override Boolean Validate(
     ValidationResult actualResult,
     object objToValidate,
     ValidationFlags validationFlag,
     CultureInfo cultureInfo)
 {
     var res = mValidator.Validate(objToValidate, validationFlag);
     actualResult.Compose(res);
     return res.Success;
 }
Exemplo n.º 10
0
        /// <summary>
        /// this is the real function that performs validation.
        /// </summary>
        /// <param name="actualResult"></param>
        /// <param name="objToValidate"></param>
        /// <param name="validationFlag"></param>
        /// <param name="cultureInfo"></param>
        /// <returns></returns>
        public override Boolean Validate(
            ValidationResult actualResult,
            object objToValidate,
            ValidationFlags validationFlag,
            CultureInfo cultureInfo)
        {
            var res = mValidator.Validate(objToValidate, validationFlag);

            actualResult.Compose(res);
            return(res.Success);
        }
Exemplo n.º 11
0
        public IntegerValidator(int minValue, int maxValue, bool rangeIsExclusive, int resolution)
        {
            if (resolution <= 0) throw new ArgumentOutOfRangeException(nameof(resolution));

            if (minValue > maxValue)
                throw new ArgumentOutOfRangeException(nameof(minValue), SR.Validator_min_greater_than_max);

            _minValue = minValue;
            _maxValue = maxValue;
            _resolution = resolution;

            _flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
        }
Exemplo n.º 12
0
        public TimeSpanValidator(TimeSpan minValue, TimeSpan maxValue, bool rangeIsExclusive, long resolutionInSeconds)
        {
            if (resolutionInSeconds < 0) throw new ArgumentOutOfRangeException(nameof(resolutionInSeconds));

            if (minValue > maxValue)
                throw new ArgumentOutOfRangeException(nameof(minValue), SR.Validator_min_greater_than_max);

            _minValue = minValue;
            _maxValue = maxValue;
            _resolution = resolutionInSeconds;

            _flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
        }
        public TimeSpanValidator(TimeSpan minValue, TimeSpan maxValue, bool rangeIsExclusive, long resolutionInSeconds) {
            if (resolutionInSeconds < 0) {
                throw new ArgumentOutOfRangeException("resolutionInSeconds");
            }

            if (minValue > maxValue) {
                throw new ArgumentOutOfRangeException("minValue", SR.GetString(SR.Validator_min_greater_than_max));
            }

            _minValue = minValue;
            _maxValue = maxValue;
            _resolution = resolutionInSeconds;

            _flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
        }
Exemplo n.º 14
0
        /// <summary>
        /// this is the real function that performs validation.
        /// </summary>
        /// <param name="actualResult"></param>
        /// <param name="objToValidate"></param>
        /// <param name="validationFlag"></param>
        /// <param name="cultureInfo"></param>
        /// <returns></returns>
        public override Boolean Validate(
            ValidationResult actualResult,
            object objToValidate,
            ValidationFlags validationFlag,
            CultureInfo cultureInfo)
        {
            SingleValidationResult res = mValidator.Validate(objToValidate);

            if (!res)
            {
                actualResult.Success = false;
                actualResult.AddErrorMessage(GetErrorMessage(res, cultureInfo), res.SourceName);
            }
            return(res);
        }
Exemplo n.º 15
0
        public LongValidator(long minValue, long maxValue, bool rangeIsExclusive, long resolution) {
            if (resolution <= 0) {
                throw new ArgumentOutOfRangeException("resolution");
            }

            if (minValue > maxValue) {
                throw new ArgumentOutOfRangeException("minValue", SR.GetString(SR.Validator_min_greater_than_max));
            }

            _minValue = minValue;
            _maxValue = maxValue;
            _resolution = resolution;

            _flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
        }
 /// <summary>
 /// Validate an object modifying an existing Validation Result.
 /// </summary>
 /// <param name="actualResult">The result object that contains validation result, it will
 /// be populated by this function</param>
 /// <param name="objToValidate">The object to be validated.</param>
 /// <param name="validationFlags">Options for comparing objects.</param>
 /// <param name="cultureInfo">The cultureinfo used to validate the object.</param>
 public void ValidateObject(
     ValidationResult actualResult,
     object objToValidate,
     ValidationFlags validationFlags,
     CultureInfo cultureInfo)
 {
     foreach (ValidationUnit vu in mList)
     {
         if (ValdationFlagsUtils.RecursiveValidation(validationFlags) || vu.IsFirstLevelValidationUnit)
         {
             Boolean validationResult = vu.Validate(actualResult, objToValidate, validationFlags, cultureInfo);
             if (!validationResult && ValdationFlagsUtils.StopOnFirstError(validationFlags)) break;
         }
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Validate an object
        /// </summary>
        /// <param name="objectToValidate"></param>
        /// <param name="validationFlags"></param>
        /// <returns></returns>
        public override ValidationResult Validate(object objectToValidate, ValidationFlags validationFlags)
        {
            //First of all retrieve the object, if it is null validate.
            ValidationResult results = new ValidationResult();
            object obj = Extract<Object>(objectToValidate);
            if (obj != null)
            {

                if (obj is IEnumerable)
                {
                    //the object is IEnumerable, we need to validate inner objects
                    Int32 index = 0;

                    foreach (var innerObj in obj as IEnumerable)
                    {
                        var errors = ValidateSingleObject(innerObj, validationFlags);
                        foreach (var validationError in errors)
                        {
                            results.Success = false;
                            results.AddErrorMessage(
                                validationError.Message,
                                string.Format("{0}[{1}].{2}",mValueExtractor.SourceName, index, validationError.SourceName));

                        }
                        index++;
                    }
                }
                else
                {
                    //Check if this object support a validation, if we do not have a rule the object should
                    //be considered valid.
                    var errors = ValidateSingleObject(obj, validationFlags);
                    foreach (var validationError in errors)
                    {
                        results.AddErrorMessage(
                            validationError.Message,
                            mValueExtractor.SourceName + "." + validationError.SourceName);

                    }
                }
                return results;

            }

            return results;
        }
 public TimeSpanValidator(TimeSpan minValue, TimeSpan maxValue, bool rangeIsExclusive, long resolutionInSeconds)
 {
     this._minValue = TimeSpan.MinValue;
     this._maxValue = TimeSpan.MaxValue;
     if (resolutionInSeconds < 0L)
     {
         throw new ArgumentOutOfRangeException("resolutionInSeconds");
     }
     if (minValue > maxValue)
     {
         throw new ArgumentOutOfRangeException("minValue", System.Configuration.SR.GetString("Validator_min_greater_than_max"));
     }
     this._minValue   = minValue;
     this._maxValue   = maxValue;
     this._resolution = resolutionInSeconds;
     this._flags      = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
 }
 public TimeSpanValidator(TimeSpan minValue, TimeSpan maxValue, bool rangeIsExclusive, long resolutionInSeconds)
 {
     this._minValue = TimeSpan.MinValue;
     this._maxValue = TimeSpan.MaxValue;
     if (resolutionInSeconds < 0L)
     {
         throw new ArgumentOutOfRangeException("resolutionInSeconds");
     }
     if (minValue > maxValue)
     {
         throw new ArgumentOutOfRangeException("minValue", System.Configuration.SR.GetString("Validator_min_greater_than_max"));
     }
     this._minValue = minValue;
     this._maxValue = maxValue;
     this._resolution = resolutionInSeconds;
     this._flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
 }
 public IntegerValidator(int minValue, int maxValue, bool rangeIsExclusive, int resolution)
 {
     this._minValue   = -2147483648;
     this._maxValue   = 0x7fffffff;
     this._resolution = 1;
     if (resolution <= 0)
     {
         throw new ArgumentOutOfRangeException("resolution");
     }
     if (minValue > maxValue)
     {
         throw new ArgumentOutOfRangeException("minValue", System.Configuration.SR.GetString("Validator_min_greater_than_max"));
     }
     this._minValue   = minValue;
     this._maxValue   = maxValue;
     this._resolution = resolution;
     this._flags      = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
 }
        public LongValidator(long minValue, long maxValue, bool rangeIsExclusive, long resolution)
        {
            if (resolution <= 0)
            {
                throw new ArgumentOutOfRangeException("resolution");
            }

            if (minValue > maxValue)
            {
                throw new ArgumentOutOfRangeException("minValue", SR.GetString(SR.Validator_min_greater_than_max));
            }

            _minValue   = minValue;
            _maxValue   = maxValue;
            _resolution = resolution;

            _flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
        }
 public LongValidator(long minValue, long maxValue, bool rangeIsExclusive, long resolution)
 {
     this._minValue = -9223372036854775808L;
     this._maxValue = 0x7fffffffffffffffL;
     this._resolution = 1L;
     if (resolution <= 0L)
     {
         throw new ArgumentOutOfRangeException("resolution");
     }
     if (minValue > maxValue)
     {
         throw new ArgumentOutOfRangeException("minValue", System.Configuration.SR.GetString("Validator_min_greater_than_max"));
     }
     this._minValue = minValue;
     this._maxValue = maxValue;
     this._resolution = resolution;
     this._flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
 }
 public IntegerValidator(int minValue, int maxValue, bool rangeIsExclusive, int resolution)
 {
     this._minValue = -2147483648;
     this._maxValue = 0x7fffffff;
     this._resolution = 1;
     if (resolution <= 0)
     {
         throw new ArgumentOutOfRangeException("resolution");
     }
     if (minValue > maxValue)
     {
         throw new ArgumentOutOfRangeException("minValue", System.Configuration.SR.GetString("Validator_min_greater_than_max"));
     }
     this._minValue = minValue;
     this._maxValue = maxValue;
     this._resolution = resolution;
     this._flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
 }
Exemplo n.º 24
0
        public IntegerValidator(int minValue, int maxValue, bool rangeIsExclusive, int resolution)
        {
            if (resolution <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(resolution));
            }

            if (minValue > maxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(minValue), SR.Validator_min_greater_than_max);
            }

            _minValue   = minValue;
            _maxValue   = maxValue;
            _resolution = resolution;

            _flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
        }
Exemplo n.º 25
0
        public TimeSpanValidator(TimeSpan minValue, TimeSpan maxValue, bool rangeIsExclusive, long resolutionInSeconds)
        {
            if (resolutionInSeconds < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(resolutionInSeconds));
            }

            if (minValue > maxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(minValue), SR.Validator_min_greater_than_max);
            }

            _minValue   = minValue;
            _maxValue   = maxValue;
            _resolution = resolutionInSeconds;

            _flags = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
        }
 public LongValidator(long minValue, long maxValue, bool rangeIsExclusive, long resolution)
 {
     this._minValue   = -9223372036854775808L;
     this._maxValue   = 0x7fffffffffffffffL;
     this._resolution = 1L;
     if (resolution <= 0L)
     {
         throw new ArgumentOutOfRangeException("resolution");
     }
     if (minValue > maxValue)
     {
         throw new ArgumentOutOfRangeException("minValue", System.Configuration.SR.GetString("Validator_min_greater_than_max"));
     }
     this._minValue   = minValue;
     this._maxValue   = maxValue;
     this._resolution = resolution;
     this._flags      = rangeIsExclusive ? ValidationFlags.ExclusiveRange : ValidationFlags.None;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Validate an object modifying an existing Validation Result.
 /// </summary>
 /// <param name="actualResult">The result object that contains validation result, it will
 /// be populated by this function</param>
 /// <param name="objToValidate">The object to be validated.</param>
 /// <param name="validationFlags">Options for comparing objects.</param>
 /// <param name="cultureInfo">The cultureinfo used to validate the object.</param>
 public void ValidateObject(
     ValidationResult actualResult,
     object objToValidate,
     ValidationFlags validationFlags,
     CultureInfo cultureInfo)
 {
     foreach (ValidationUnit vu in mList)
     {
         if (ValdationFlagsUtils.RecursiveValidation(validationFlags) || vu.IsFirstLevelValidationUnit)
         {
             Boolean validationResult = vu.Validate(actualResult, objToValidate, validationFlags, cultureInfo);
             if (!validationResult && ValdationFlagsUtils.StopOnFirstError(validationFlags))
             {
                 break;
             }
         }
     }
 }
Exemplo n.º 28
0
    public void Execute()
    {
        var nullGuardAttribute = ModuleDefinition.GetNullGuardAttribute();

        if (nullGuardAttribute == null)
            nullGuardAttribute = ModuleDefinition.Assembly.GetNullGuardAttribute();

        if (nullGuardAttribute != null)
            ValidationFlags = (ValidationFlags)nullGuardAttribute.ConstructorArguments[0].Value;

        ReferenceFinder.FindReferences(AssemblyResolver, ModuleDefinition);
        var types = new List<TypeDefinition>(ModuleDefinition.GetTypes());

        CheckForBadAttributes(types);
        ProcessAssembly(types);
        RemoveAttributes(types);
        RemoveReference();
    }
Exemplo n.º 29
0
        Validate(object objectToValidate, ValidationFlags validationFlags)
        {
            //First of all retrieve the object, if it is null validate.
            ValidationResult results = new ValidationResult();
            object           obj     = Extract <Object>(objectToValidate);

            if (obj != null)
            {
                if (obj is IEnumerable)
                {
                    //the object is IEnumerable, we need to validate inner objects
                    Int32 index = 0;

                    foreach (var innerObj in obj as IEnumerable)
                    {
                        var errors = ValidateSingleObject(innerObj, validationFlags);
                        foreach (var validationError in errors)
                        {
                            results.Success = false;
                            results.AddErrorMessage(
                                validationError.Message,
                                string.Format("{0}[{1}].{2}", mValueExtractor.SourceName, index, validationError.SourceName));
                        }
                        index++;
                    }
                }
                else
                {
                    //Check if this object support a validation, if we do not have a rule the object should
                    //be considered valid.
                    var errors = ValidateSingleObject(obj, validationFlags);
                    foreach (var validationError in errors)
                    {
                        results.AddErrorMessage(
                            validationError.Message,
                            mValueExtractor.SourceName + "." + validationError.SourceName);
                    }
                }
                return(results);
            }

            return(results);
        }
Exemplo n.º 30
0
        protected IEnumerable <ValidationError> ValidateSingleObject(object obj, ValidationFlags validationFlags)
        {
            Type type = obj.GetType();

            if (mRuleMap.ContainsKey(type))
            {
                ValidationUnitCollection vc = mRuleMap[type];
                if (vc.Count > 0)
                {
                    ValidationResult res = new ValidationResult();

                    vc.ValidateObject(res, obj, validationFlags);
                    if (!res)
                    {
                        return(res.Errors);
                    }
                }
            }

            return(new ValidationError[] { });
        }
Exemplo n.º 31
0
        private static bool ValidateCpu(RASD_Type[] rasds, ValidationFlags validationFlags, ref List <string> validationErrorMessages)
        {
            bool isValid = true;

            if ((validationFlags & ValidationFlags.Cpu) != 0)
            {
                foreach (RASD_Type rasd in rasds)
                {
                    if (rasd.ResourceType.Value == 3)
                    {
                        if (rasd.VirtualQuantity == null || rasd.VirtualQuantity.Value <= 0)
                        {
                            var message = string.Format(Messages.VALIDATION_INVALID_CPU_QUANTITY, rasd.VirtualQuantity.Value);
                            Log.Error(message);
                            validationErrorMessages.Add(message);
                            break;
                        }
                        if (rasd.Limit != null && rasd.VirtualQuantity.Value > rasd.Limit.Value)
                        {
                            var message = string.Format(Messages.VALIDATION_INVALID_CPU_EXCEEDS_LIMIT, rasd.VirtualQuantity.Value, rasd.Limit.Value);
                            Log.Error(message);
                            validationErrorMessages.Add(message);
                            isValid = false;
                            break;
                        }
                        if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
                        {
                            Log.Info("CPU has an invalid InstanceID, creating new.");
                            validationErrorMessages.Add(Messages.VALIDATION_INVALID_INSTANCEID);
                            rasd.InstanceID = new cimString(Guid.NewGuid().ToString());
                            break;
                        }
                    }
                }
            }
            return(isValid);
        }
Exemplo n.º 32
0
        private static bool ValidateSchema(string ovffilename, ValidationFlags validationFlags, ref List <string> validationErrorMessages)
        {
            bool isValid = true;

            if ((validationFlags & ValidationFlags.Schema) != 0)
            {
                try
                {
                    isValid = Tools.ValidateXmlToSchema(ovffilename);
                }
                catch (Exception ex)
                {
                    isValid = false;
                    validationErrorMessages.Add(ex.Message);
                }
                if (!isValid)
                {
                    isValid = false;
                    Log.Error(Messages.VALIDATION_SCHEMA_FAILED);
                    validationErrorMessages.Add(Messages.VALIDATION_SCHEMA_FAILED);
                }
            }
            return(isValid);
        }
Exemplo n.º 33
0
        private static bool ValidateMemory(RASD_Type[] rasds, ValidationFlags validationFlags, ref List <string> validationErrorMessages)
        {
            bool isValid = true;

            if ((validationFlags & ValidationFlags.Memory) != 0)
            {
                foreach (RASD_Type rasd in rasds)
                {
                    if (rasd.ResourceType.Value == 4)
                    {
                        if (rasd.VirtualQuantity == null || rasd.VirtualQuantity.Value <= 0)
                        {
                            Log.Error("Memory invalid Virtual Quantity");
                            validationErrorMessages.Add(Messages.VALIDATION_INVALID_MEMORY_QUANTITY);
                            isValid = false;
                            break;
                        }
                        if (rasd.AllocationUnits == null || rasd.AllocationUnits.Value.Length <= 0)
                        {
                            Log.Error("Memory AllocationUnits not valid");
                            validationErrorMessages.Add(Messages.VALIDATION_INVALID_MEMORY_ALLOCATIONUNITS);
                            isValid = false;
                            break;
                        }
                        if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
                        {
                            Log.Info("Memory has an invalid InstanceID, creating new.");
                            validationErrorMessages.Add(Messages.VALIDATION_INVALID_INSTANCEID);
                            rasd.InstanceID = new cimString(Guid.NewGuid().ToString());
                            break;
                        }
                    }
                }
            }
            return(isValid);
        }
Exemplo n.º 34
0
        protected IEnumerable<ValidationError> ValidateSingleObject(object obj, ValidationFlags validationFlags)
        {
            Type type = obj.GetType();
            if (mRuleMap.ContainsKey(type))
            {
                ValidationUnitCollection vc = mRuleMap[type];
                if (vc.Count > 0)
                {
                    ValidationResult res = new ValidationResult();

                    vc.ValidateObject(res, obj, validationFlags);
                    if (!res)
                    {
                        return res.Errors;
                    }
                }
            }

            return new ValidationError[] { };
        }
Exemplo n.º 35
0
    private void InjectMethodReturnGuard(ValidationFlags localValidationFlags, MethodDefinition method, MethodBody body)
    {
        var guardInstructions = new List<Instruction>();

        var returnPoints = body.Instructions
                .Select((o, ix) => new { o, ix })
                .Where(a => a.o.OpCode == OpCodes.Ret)
                .Select(a => a.ix)
                .OrderByDescending(ix => ix);

        foreach (var ret in returnPoints)
        {
            var returnInstruction = body.Instructions[ret];

            if (localValidationFlags.HasFlag(ValidationFlags.ReturnValues) &&
                !method.MethodReturnType.AllowsNull() &&
                method.ReturnType.IsRefType() &&
                method.ReturnType.FullName != typeof(void).FullName)
            {
                AddReturnNullGuard(body.Instructions, ret, method.ReturnType, String.Format(CultureInfo.InvariantCulture, STR_ReturnValueOfMethodIsNull, method.FullName), Instruction.Create(OpCodes.Throw));
            }

            if (localValidationFlags.HasFlag(ValidationFlags.Arguments))
            {
                foreach (var parameter in method.Parameters.Reverse())
                {
                    // This is no longer the return instruction location, but it is where we want to jump to.
                    returnInstruction = body.Instructions[ret];

                    if (localValidationFlags.HasFlag(ValidationFlags.OutValues) &&
                        parameter.IsOut &&
                        parameter.ParameterType.IsRefType())
                    {
                        guardInstructions.Clear();

                        if (isDebug)
                        {
                            InstructionPatterns.LoadArgumentOntoStack(guardInstructions, parameter);

                            InstructionPatterns.CallDebugAssertInstructions(guardInstructions, String.Format(CultureInfo.InvariantCulture, STR_OutParameterIsNull, parameter.Name));
                        }

                        InstructionPatterns.LoadArgumentOntoStack(guardInstructions, parameter);

                        InstructionPatterns.IfNull(guardInstructions, returnInstruction, i =>
                        {
                            InstructionPatterns.LoadInvalidOperationException(i, String.Format(CultureInfo.InvariantCulture, STR_OutParameterIsNull, parameter.Name));

                            // Throw the top item off the stack
                            i.Add(Instruction.Create(OpCodes.Throw));
                        });

                        body.Instructions.Insert(ret, guardInstructions);
                    }
                }
            }
        }
    }
Exemplo n.º 36
0
 private static bool ValidateVersion(EnvelopeType ovfEnv, ValidationFlags validationFlags, ref List<string> validationErrorMessages)
 {
     bool isValid = true;
     if ((validationFlags & ValidationFlags.Version) != 0)
     {
         if (ovfEnv.version == null)
         {
             if (ovfEnv.AnyAttr != null && ovfEnv.AnyAttr.Length > 0)
             {
                 foreach (XmlAttribute attr in ovfEnv.AnyAttr)
                 {
                     if (attr.Name.ToLower().Contains("version"))
                     {
                         ovfEnv.version = attr.Value;
                         break;
                     }
                 }
             }
             if (ovfEnv.version == null)
             {
                 log.Warn("Version not set, applying 1.0.0");
                 ovfEnv.version = "1.0.0";
             }
         }
         if (!Properties.Settings.Default.Versions.Contains(ovfEnv.version))
         {
             isValid = false;
             var message = string.Format(Messages.VALIDATION_INVALID_VERSION, ovfEnv.version);
             log.Warn(message);
             validationErrorMessages.Add(message);
         }
     }
     return isValid;
 }
 public abstract ValidationResult Validate(object objectToValidate, ValidationFlags validationFlags);
Exemplo n.º 38
0
 internal static Boolean StopOnFirstError(
     ValidationFlags value)
 {
     return (value & ValidationFlags.StopOnFirstError) == ValidationFlags.StopOnFirstError;
 }
Exemplo n.º 39
0
 public MethodProcessor(ValidationFlags validationFlags, bool isDebug, Action <string> logWarn)
 {
     this.validationFlags = validationFlags;
     this.isDebug         = isDebug;
     this.logWarn         = logWarn;
 }
Exemplo n.º 40
0
 private static bool ValidateMemory(RASD_Type[] rasds, ValidationFlags validationFlags, ref List<string> validationErrorMessages)
 {
     bool isValid = true;
     if ((validationFlags & ValidationFlags.Memory) != 0)
     {
         foreach (RASD_Type rasd in rasds)
         {
             if (rasd.ResourceType.Value == 4)
             {
                 if (rasd.VirtualQuantity == null || rasd.VirtualQuantity.Value <= 0)
                 {
                     log.Error("Memory invalid Virtual Quantity");
                     validationErrorMessages.Add(Messages.VALIDATION_INVALID_MEMORY_QUANTITY);
                     isValid = false;
                     break;
                 }
                 if (rasd.AllocationUnits == null || rasd.AllocationUnits.Value.Length <= 0)
                 {
                     log.Error("Memory AllocationUnits not valid");
                     validationErrorMessages.Add(Messages.VALIDATION_INVALID_MEMORY_ALLOCATIONUNITS);
                     isValid = false;
                     break;
                 }
                 if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
                 {
                     log.Info("Memory has an invalid InstanceID, creating new.");
                     validationErrorMessages.Add(Messages.VALIDATION_INVALID_INSTANCEID);
                     rasd.InstanceID = new cimString(Guid.NewGuid().ToString());
                     break;
                 }
             }
         }
     }
     return isValid;
 }
Exemplo n.º 41
0
 public PropertyProcessor(ValidationFlags validationFlags, bool isDebug)
 {
     this.validationFlags = validationFlags;
     this.isDebug         = isDebug;
 }
Exemplo n.º 42
0
        private static bool ValidateNetworks(NetworkSection_TypeNetwork[] networks, RASD_Type[] rasds, ValidationFlags validationFlags, ref List <string> validationErrorMessages)
        {
            bool isValid = true;

            if ((validationFlags & ValidationFlags.Networks) != 0)
            {
                foreach (RASD_Type rasd in rasds)
                {
                    if (rasd.ResourceType.Value == 10)
                    {
                        bool linkage = false;
                        if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
                        {
                            Log.Info("Network has an invalid InstanceID, creating new.");
                            validationErrorMessages.Add(Messages.VALIDATION_INVALID_INSTANCEID);
                            rasd.InstanceID = new cimString(Guid.NewGuid().ToString());
                            break;
                        }
                        foreach (NetworkSection_TypeNetwork net in networks)
                        {
                            //
                            // this may only work for Citrix Created VOFs
                            // haven't looked at others, may need to use a different key to validate linkage.
                            //
                            if ((rasd.Connection != null && rasd.Connection.Length > 0 &&
                                 net.name == rasd.Connection[0].Value) ||
                                (net.Description.msgid == rasd.InstanceID.Value))
                            {
                                linkage = true;
                            }
                        }
                        if (!linkage)
                        {
                            Log.Error(Messages.VALIDATION_NETWORK_NO_DEVICE);
                            validationErrorMessages.Add(Messages.VALIDATION_NETWORK_NO_DEVICE);
                            isValid = false;
                            break;
                        }
                    }
                }
            }
            return(isValid);
        }
Exemplo n.º 43
0
 internal static Boolean RecursiveValidation(
     ValidationFlags value)
 {
     return (value & ValidationFlags.RecursiveValidation) == ValidationFlags.RecursiveValidation;
 }
Exemplo n.º 44
0
 private static bool ValidateNetworks(NetworkSection_TypeNetwork[] networks, RASD_Type[] rasds, ValidationFlags validationFlags, ref List<string> validationErrorMessages)
 {
     bool isValid = true;
     if ((validationFlags & ValidationFlags.Networks) != 0)
     {
         foreach (RASD_Type rasd in rasds)
         {
             if (rasd.ResourceType.Value == 10)
             {
                 bool linkage = false;
                 if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
                 {
                     log.Info("Network has an invalid InstanceID, creating new.");
                     validationErrorMessages.Add(Messages.VALIDATION_INVALID_INSTANCEID);
                     rasd.InstanceID = new cimString(Guid.NewGuid().ToString());
                     break;
                 }
                 foreach (NetworkSection_TypeNetwork net in networks)
                 {
                     //
                     // this may only work for Citrix Created VOFs
                     // haven't looked at others, may need to use a different key to validate linkage.
                     //
                     if ((rasd.Connection != null && rasd.Connection.Length > 0 &&
                          net.name == rasd.Connection[0].Value) ||
                         (net.Description.msgid == rasd.InstanceID.Value))
                     {
                         linkage = true;
                     }
                 }
                 if (!linkage)
                 {
                     log.Error(Messages.VALIDATION_NETWORK_NO_DEVICE);
                     validationErrorMessages.Add(Messages.VALIDATION_NETWORK_NO_DEVICE);
                     isValid = false;
                     break;
                 }
             }
         }
     }
     return isValid;
 }
Exemplo n.º 45
0
 private static bool ValidateSchema(string ovffilename, ValidationFlags validationFlags, ref List<string> validationErrorMessages)
 {
     bool isValid = true;
     if ((validationFlags & ValidationFlags.Schema) != 0)
     {
         try
         {
             isValid = Tools.ValidateXmlToSchema(ovffilename);
         }
         catch (Exception ex)
         {
             isValid = false;
             validationErrorMessages.Add(ex.Message);
         }
         if (!isValid)
         {
             isValid = false;
             log.Error(Messages.VALIDATION_SCHEMA_FAILED);
             validationErrorMessages.Add(Messages.VALIDATION_SCHEMA_FAILED);
         }
     }
     return isValid;
 }
Exemplo n.º 46
0
 public EnsureNonNullAspect(ValidationFlags validationFlags)
 {
     ValidationFlags = validationFlags;
 }
Exemplo n.º 47
0
 public MethodProcessor(ValidationFlags validationFlags, bool isDebug)
 {
     this.validationFlags = validationFlags;
     this.isDebug = isDebug;
 }
Exemplo n.º 48
0
 public PropertyProcessor(ValidationFlags validationFlags, bool isDebug)
 {
     this.validationFlags = validationFlags;
     this.isDebug = isDebug;
 }
Exemplo n.º 49
0
 /// <summary>
 /// this is the real function that performs validation.
 /// </summary>
 /// <param name="actualResult"></param>
 /// <param name="objToValidate"></param>
 /// <param name="validationFlag"></param>
 /// <param name="cultureInfo"></param>
 /// <returns></returns>
 public override Boolean Validate(
     ValidationResult actualResult,
     object objToValidate,
     ValidationFlags validationFlag,
     CultureInfo cultureInfo)
 {
     SingleValidationResult res = mValidator.Validate(objToValidate);
     if (!res)
     {
         actualResult.Success = false;
         actualResult.AddErrorMessage(GetErrorMessage(res, cultureInfo), res.SourceName);
     }
     return res;
 }
Exemplo n.º 50
0
        private static bool ValidateFiles(string ovfpath, File_Type[] files, VirtualDiskDesc_Type[] disks, RASD_Type[] rasds, ValidationFlags validationFlags, ref List<string> validationErrorMessages)
        {
            bool isValid = true;
            if ((validationFlags & ValidationFlags.Files) != 0)
            {
                if (files != null && files.Length > 0)
                {
                    foreach (File_Type file in files)
                    {
                        string ext = Path.GetExtension(file.href).ToLower();
                        if (ext == Properties.Settings.Default.manifestFileExtension || ext == Properties.Settings.Default.certificateFileExtension)
                            continue;

                        string filename = string.Format(@"{0}{1}{2}", string.IsNullOrEmpty(ovfpath) ? "" : ovfpath,
                                                                      string.IsNullOrEmpty(ovfpath) ? "" : @"\",
                                                                      file.href);
                        if (!File.Exists(filename))
                        {
                            var message = string.Format(Messages.VALIDATION_FILE_NOTFOUND, file.href);
                            validationErrorMessages.Add(message);
                            log.Error(message);
                            throw new Exception(message);
                        }
                    }
                }
                else
                {
                    log.Info("ValidateFiles: no attached files defined, continuing");
                    return isValid;
                }
                if (isValid)
                {
                    bool validlink = false;
                    foreach (File_Type file in files)
                    {
                        validlink = false;
                        foreach (VirtualDiskDesc_Type disk in disks)
                        {
                            if (file.id == disk.fileRef)
                            {
                                foreach (RASD_Type rasd in rasds)
                                {
                                    if (rasd.ResourceType.Value == 17 ||
                                        rasd.ResourceType.Value == 19 ||
                                        rasd.ResourceType.Value == 20 ||
                                        rasd.ResourceType.Value == 21)
                                    {
                                        if (rasd.HostResource != null && rasd.HostResource.Length > 0)
                                        {
                                            if (rasd.HostResource[0].Value.Contains(disk.diskId))
                                            {
                                                validlink = true;
                                                break;
                                            }
                                        }
                                        else if (disk.diskId == rasd.InstanceID.Value)
                                        {
                                            validlink = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (!validlink)
                        {
                            log.WarnFormat("Disk linkage [File to RASD] does not exist: {0}", file.href);
                            break;
                        }
                    }
                }
            }
            return isValid;
        }
Exemplo n.º 51
0
 private static bool ValidateCapability(RASD_Type[] rasds, ValidationFlags validationFlags, ref List<string> validationErrorMessages)
 {
     bool isValid = true;
     if ((validationFlags & ValidationFlags.Capability) != 0)
     {
         foreach (RASD_Type rasd in rasds)
         {
             switch (rasd.ResourceType.Value)
             {
                 // CIM SCHEMA 2.19.0
                 case 3:  // Processor
                 case 4:  // Memory
                 case 5:  // IDE Controller
                 case 6:  // Parallel SCSI HBA
                 case 7:  // FC HBA
                 case 8:  // iSCSI HBA
                 case 9:  // IB HCA
                 case 10: // Ehternet Adapter
                 case 15: // CD Drive
                 case 16: // DVD Drive
                 case 17: // Disk Drive
                 case 19: // Storage Extent
                 case 20: // Other storage Device
                 case 21: // Serial Port  // Microsoft uses this for Hard Disk Image also, based on an OLDER schema
                     {
                         if (rasd.required)
                         {
                             isValid = true;
                         }
                         break;
                     }
                 case 1:  // Other
                 case 2:  // Computer System
                 case 11: // Other Network Adapter
                 case 12: // I/O Slot
                 case 13: // I/O Device
                 case 14: // Floppy Drive
                 case 18: // Tape Drive
                 case 22: // Parallel Port
                 case 23: // USB Controller
                 case 24: // Graphics Controller
                 case 25: // IEEE 1394 Controller
                 case 26: // Partitionable Unit
                 case 27: // Base Partitionable Unit
                 case 28: // Power
                 case 29: // Cooling Capacity
                 case 30: // Ethernet Switch Port
                 case 31: // Logical Disk
                 case 32: // Storage Volume
                 case 33: // Ethernet Connection
                 default:
                     {
                         if (rasd.required)
                         {
                             var message = string.Format(Messages.VALIDATION_REQUIRED_ELEMENT_NOT_RECOGNIZED, rasd.ResourceType.Value, rasd.ElementName.Value);
                             log.Error(message);
                             validationErrorMessages.Add(message);
                             isValid = false;
                         }
                         break;
                     }
             }
             if (!isValid)
                 break;
         }
     }
     return isValid;
 }
Exemplo n.º 52
0
 private static bool ValidateCpu(RASD_Type[] rasds, ValidationFlags validationFlags, ref List<string> validationErrorMessages)
 {
     bool isValid = true;
     if ((validationFlags & ValidationFlags.Cpu) != 0)
     {
         foreach (RASD_Type rasd in rasds)
         {
             if (rasd.ResourceType.Value == 3)
             {
                 if (rasd.VirtualQuantity == null || rasd.VirtualQuantity.Value <= 0)
                 {
                     var message = string.Format(Messages.VALIDATION_INVALID_CPU_QUANTITY, rasd.VirtualQuantity.Value);
                     log.Error(message);
                     validationErrorMessages.Add(message);
                     break;
                 }
                 if (rasd.Limit != null && rasd.VirtualQuantity.Value > rasd.Limit.Value)
                 {
                     var message = string.Format(Messages.VALIDATION_INVALID_CPU_EXCEEDS_LIMIT, rasd.VirtualQuantity.Value, rasd.Limit.Value);
                     log.Error(message);
                     validationErrorMessages.Add(message);
                     isValid = false;
                     break;
                 }
                 if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
                 {
                     log.Info("CPU has an invalid InstanceID, creating new.");
                     validationErrorMessages.Add(Messages.VALIDATION_INVALID_INSTANCEID);
                     rasd.InstanceID = new cimString(Guid.NewGuid().ToString());
                     break;
                 }
             }
         }
     }
     return isValid;
 }
Exemplo n.º 53
0
        private static bool ValidateFiles(string ovfpath, File_Type[] files, VirtualDiskDesc_Type[] disks, RASD_Type[] rasds, ValidationFlags validationFlags, ref List <string> validationErrorMessages)
        {
            bool isValid = true;

            if ((validationFlags & ValidationFlags.Files) != 0)
            {
                if (files != null && files.Length > 0)
                {
                    foreach (File_Type file in files)
                    {
                        string ext = Path.GetExtension(file.href).ToLower();
                        if (ext == Properties.Settings.Default.manifestFileExtension || ext == Properties.Settings.Default.certificateFileExtension)
                        {
                            continue;
                        }

                        string filename = string.Format(@"{0}{1}{2}", string.IsNullOrEmpty(ovfpath) ? "" : ovfpath,
                                                        string.IsNullOrEmpty(ovfpath) ? "" : @"\",
                                                        file.href);
                        if (!File.Exists(filename))
                        {
                            var message = string.Format(Messages.VALIDATION_FILE_NOTFOUND, file.href);
                            validationErrorMessages.Add(message);
                            Log.Error(message);
                            throw new Exception(message);
                        }
                    }
                }
                else
                {
                    Log.Info("ValidateFiles: no attached files defined, continuing");
                    return(isValid);
                }
                if (isValid)
                {
                    bool validlink = false;
                    foreach (File_Type file in files)
                    {
                        validlink = false;
                        foreach (VirtualDiskDesc_Type disk in disks)
                        {
                            if (file.id == disk.fileRef)
                            {
                                foreach (RASD_Type rasd in rasds)
                                {
                                    if (rasd.ResourceType.Value == 17 ||
                                        rasd.ResourceType.Value == 19 ||
                                        rasd.ResourceType.Value == 20 ||
                                        rasd.ResourceType.Value == 21)
                                    {
                                        if (rasd.HostResource != null && rasd.HostResource.Length > 0)
                                        {
                                            if (rasd.HostResource[0].Value.Contains(disk.diskId))
                                            {
                                                validlink = true;
                                                break;
                                            }
                                        }
                                        else if (disk.diskId == rasd.InstanceID.Value)
                                        {
                                            validlink = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (!validlink)
                        {
                            Log.Warning("Disk linkage [File to RASD] does not exist: {0}", file.href);
                            break;
                        }
                    }
                }
            }
            return(isValid);
        }
Exemplo n.º 54
0
    public void Execute()
    {
        LoggerFactory.LogInfo = LogInfo;
        LoggerFactory.LogWarn = LogWarn;
        LoggerFactory.LogError = LogError;

        ReadConfig();

        var nullGuardAttribute = ModuleDefinition.GetNullGuardAttribute();

        if (nullGuardAttribute == null)
            nullGuardAttribute = ModuleDefinition.Assembly.GetNullGuardAttribute();

        if (nullGuardAttribute != null)
            ValidationFlags = (ValidationFlags)nullGuardAttribute.ConstructorArguments[0].Value;

        ReferenceFinder.FindReferences(AssemblyResolver, ModuleDefinition);
        var types = GetTypesToProcess();

        CheckForBadAttributes(types);
        ProcessAssembly(types);
        RemoveAttributes(types);
        RemoveReference();
    }
 public DisallowNonNullAspect(ValidationFlags validationFlags)
 {
     ValidationFlags = validationFlags;
 }
Exemplo n.º 56
0
        protected IEnumerable <ValidationResult> PerformValidation(IPersistEntity ent, bool hierarchical, ValidationFlags validateLevel = ValidationFlags.Properties)
        {
            var thisEntAdded = false;
            var hierResult   = new ValidationResult()
            {
                Item = ent, IssueType = ValidationFlags.None
            };

            if (validateLevel == ValidationFlags.None)
            {
                yield break; //nothing to do
            }
            var expType = ent.ExpressType;

            if (validateLevel.HasFlag(ValidationFlags.Properties))
            {
                foreach (var prop in expType.Properties.Values)
                {
                    var errs = GetSchemaErrors(ent, prop, validateLevel, hierarchical);
                    foreach (var validationResult in errs)
                    {
                        validationResult.IssueType |= ValidationFlags.Properties;
                        thisEntAdded = UpdateCount(thisEntAdded);

                        if (hierarchical)
                        {
                            hierResult.AddDetail(validationResult);
                        }
                        else
                        {
                            validationResult.Item = ent;
                            yield return(validationResult);
                        }
                    }
                }
            }
            if (validateLevel.HasFlag(ValidationFlags.Inverses))
            {
                foreach (var inv in expType.Inverses)
                {
                    var errs = GetSchemaErrors(ent, inv, validateLevel, hierarchical);
                    foreach (var validationResult in errs)
                    {
                        validationResult.IssueType |= ValidationFlags.Inverses;
                        thisEntAdded = UpdateCount(thisEntAdded);
                        if (hierarchical)
                        {
                            hierResult.AddDetail(validationResult);
                        }
                        else
                        {
                            validationResult.Item = ent;
                            yield return(validationResult);
                        }
                    }
                }
            }
            if (validateLevel.HasFlag(ValidationFlags.EntityWhereClauses) && ent is IExpressValidatable)
            {
                var errs = ((IExpressValidatable)ent).Validate();
                foreach (var validationResult in errs)
                {
                    thisEntAdded = UpdateCount(thisEntAdded);
                    if (hierarchical)
                    {
                        hierResult.AddDetail(validationResult);
                    }
                    else
                    {
                        yield return(validationResult);
                    }
                }
            }

            if (hierarchical && hierResult.IssueType != ValidationFlags.None)
            {
                // the IssueType is populated if any children have been added.
                hierResult.Message = string.Format("Entity #{0} ({1}) has validation failures.", ent.EntityLabel,
                                                   expType.Name);
                yield return(hierResult);
            }
        }
Exemplo n.º 57
0
        private static bool ValidateCapability(RASD_Type[] rasds, ValidationFlags validationFlags, ref List <string> validationErrorMessages)
        {
            bool isValid = true;

            if ((validationFlags & ValidationFlags.Capability) != 0)
            {
                foreach (RASD_Type rasd in rasds)
                {
                    switch (rasd.ResourceType.Value)
                    {
                    // CIM SCHEMA 2.19.0
                    case 3:      // Processor
                    case 4:      // Memory
                    case 5:      // IDE Controller
                    case 6:      // Parallel SCSI HBA
                    case 7:      // FC HBA
                    case 8:      // iSCSI HBA
                    case 9:      // IB HCA
                    case 10:     // Ehternet Adapter
                    case 15:     // CD Drive
                    case 16:     // DVD Drive
                    case 17:     // Disk Drive
                    case 19:     // Storage Extent
                    case 20:     // Other storage Device
                    case 21:     // Serial Port  // Microsoft uses this for Hard Disk Image also, based on an OLDER schema
                    {
                        if (rasd.required)
                        {
                            isValid = true;
                        }
                        break;
                    }

                    case 1:      // Other
                    case 2:      // Computer System
                    case 11:     // Other Network Adapter
                    case 12:     // I/O Slot
                    case 13:     // I/O Device
                    case 14:     // Floppy Drive
                    case 18:     // Tape Drive
                    case 22:     // Parallel Port
                    case 23:     // USB Controller
                    case 24:     // Graphics Controller
                    case 25:     // IEEE 1394 Controller
                    case 26:     // Partitionable Unit
                    case 27:     // Base Partitionable Unit
                    case 28:     // Power
                    case 29:     // Cooling Capacity
                    case 30:     // Ethernet Switch Port
                    case 31:     // Logical Disk
                    case 32:     // Storage Volume
                    case 33:     // Ethernet Connection
                    default:
                    {
                        if (rasd.required)
                        {
                            var message = string.Format(Messages.VALIDATION_REQUIRED_ELEMENT_NOT_RECOGNIZED, rasd.ResourceType.Value, rasd.ElementName.Value);
                            Log.Error(message);
                            validationErrorMessages.Add(message);
                            isValid = false;
                        }
                        break;
                    }
                    }
                    if (!isValid)
                    {
                        break;
                    }
                }
            }
            return(isValid);
        }
Exemplo n.º 58
0
 /// <summary>
 /// this is the real function that performs validation.
 /// </summary>
 /// <param name="actualResult"></param>
 /// <param name="objToValidate"></param>
 /// <param name="validationFlag"></param>
 /// <param name="cultureInfo"></param>
 /// <returns></returns>
 public abstract Boolean Validate(
     ValidationResult actualResult,
     object objToValidate,
     ValidationFlags validationFlag,
     CultureInfo cultureInfo);
Exemplo n.º 59
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NullGuardAttribute"/> with a <see cref="ValidationFlags"/>.
 /// </summary>
 /// <param name="flags">The <see cref="ValidationFlags"/> to use for the target this attribute is being applied to.</param>
 public NullGuardAttribute(ValidationFlags flags)
 {
 }
Exemplo n.º 60
0
 public MethodProcessor(ValidationFlags validationFlags, bool isDebug)
 {
     this.validationFlags = validationFlags;
     this.isDebug         = isDebug;
 }