DDay.iCal.Validator.RFC5545.RulesetValidator.Validate C# (CSharp) Method

Validate() public method

public Validate ( ) : IValidationResultCollection
return IValidationResultCollection
        public override IValidationResultCollection Validate()
        {
            if (Ruleset != null)
            {
                Debug.WriteLineWithTimestamp("Validating...");
                ValidationResultCollection results = new ValidationResultCollection(ResourceManager, "all");
                int i = 0;
                foreach (IValidationRule rule in Ruleset.Rules)
                {
                    i++;
                    var status = ((i * 1.0) / Ruleset.Rules.Length) * 100;
                    Logger.SetStatus(String.Format("{0:0}", status));
                    Logger.LogMessage(rule.ValidatorType.FullName);

                    IValidator validator = null;

                    Type validatorType = rule.ValidatorType;
                    if (validatorType != null)
                        validator = ValidatorActivator.Create(validatorType, ResourceManager, Calendars, iCalendarText);

                    if (validator != null)
                    {
                        IValidationResultCollection currentResults = validator.Validate();
                        results.Add(currentResults);

                        // Determine if there were any fatal errors in the results.
                        // If there are, then we need to abort any further processing!
                        if (results.IsFatal)
                            break;
                    }
                }
                Debug.WriteLineWithTimestamp("Done.");

                // We at least gave the validators a chance to handle the error in
                // a different manner.  If they haven't produced a more specific
                // error, then we'll fall back to the basic "parsing" error.
                if (BoolUtil.IsTrue(results.Passed))
                {
                    if (_MissingValidators.Count > 0)
                    {
                        results.Passed = false;
                        foreach (IValidationResultInfo error in _MissingValidators)
                            results.Add(error);
                    }
                }

                Debug.Flush();
                return results;
            }
            else return null;
        }

Usage Example

Exemplo n.º 1
0
        /*
        protected void SetupStream(IValidationSerializer serializer, out Stream stream, out Encoding encoding)
        {
            Response.ContentType = "text/xml";
           // stream = Response.OutputStream;
            stream = new MemoryStream();
            encoding = Response.Output.Encoding;
        }*/
        protected byte[] Validate(long byteCount, TextReader tr, string id)
        {
            byte[] bytes = new byte[0];

            try
            {
                IValidationSerializer serializer = GetSerializer();

                if (serializer != null)
                {
                    string iCalText = tr.ReadToEnd();

                    try
                    {
                        var ms = new MemoryStream(encoding.GetBytes(iCalText));
                        var ical = DDay.iCal.iCalendar.LoadFromStream(ms);
                        ms.Close();
                    }
                    catch (Exception e)
                    {
                        Utils.StoreExceptionBlob("Validate: " + e.Message + e.StackTrace);
                        bytes = ExceptionMessage(e);
                        return bytes;
                    }

                    if (SelectedRuleset != null)
                    {
                        serializer.Ruleset = SelectedRuleset;

                        RulesetValidator rulesetValidator = new RulesetValidator(ResourceManager, SelectedRuleset, iCalText);

                        if (rulesetValidator != null)
                        {
                            serializer.ValidationResults = rulesetValidator.Validate();

                            // Set the original text for the validation
                            serializer.ValidationResults.CalendarText = iCalText;
                            serializer.ValidationResults.CalendarPath = CalendarPath;
                            serializer.ValidationResults.ByteCount = byteCount;
                        }

                        Stream stream = new MemoryStream();

                        try
                        {
                            var permalink = Utils.MakePermalinkUrl(id);
                            serializer.Serialize(stream, encoding, permalink);
                            bytes = new byte[stream.Length];
                            stream.Seek(0, 0);
                            stream.Read(bytes, 0, (int)stream.Length);
                        }
                        catch (Exception e)
                        {
                            bytes = ExceptionMessage(e);
                            Utils.StoreExceptionBlob("Validate: " + e.Message + e.StackTrace);
                        }
                        finally
                        {
                            stream.Close();
                        }
                    }
                }
            }

            catch (Exception e)
            {
                bytes = ExceptionMessage(e);
                Utils.StoreExceptionBlob("Validate:" + e.Message + e.StackTrace);
            }

            finally
            {
                var results_blob = Utils.MakeResultsBlob(id);
                results_blob.UploadByteArray(bytes);
            }

            return bytes;
        }
All Usage Examples Of DDay.iCal.Validator.RFC5545.RulesetValidator::Validate