/// <summary>
        /// Ajouter un filtre par URL
        /// </summary>
        /// <param name="url">Filtre d'URL (avec des * pour wildcard)</param>
        /// <param name="behavior">Comportement à associer à la nouvelle règle</param>
        /// <returns></returns>
        public UrlFilterBehaviorRule AddUrlFilterRule(string name, ResourceBehavior behavior, WorkBucket <Resource, BucketContext> targetBucket, ICollection <CrawlingCondition> conditions)
        {
            UrlFilterBehaviorRule urlFilterBehaviorRule = new UrlFilterBehaviorRule(name, behavior, targetBucket, conditions);

            Add(urlFilterBehaviorRule);
            return(urlFilterBehaviorRule);
        }
Esempio n. 2
0
 public UrlFilterBehaviorRule(string name, ResourceBehavior behavior, WorkBucket <Resource, BucketContext> targetBucket, ICollection <CrawlingCondition> conditions)
 {
     _conditions  = conditions;
     Name         = name;
     Behavior     = behavior;
     TargetBucket = targetBucket;
 }
Esempio n. 3
0
        public static Resource DeserializeResource(XElement node)
        {
            Uri url = new Uri((string)node.Attribute("Url"));
            ResourceBehavior behavior = EnumHelper <ResourceBehavior> .Parse((string)node.Attribute("Behavior"));

            Resource resource = new Resource(url, behavior);

            resource.Status = EnumHelper <ResourceStatus> .Parse((string)node.Attribute("Status"));

            resource.HttpStatus = EnumHelper <HttpStatusCode> .TryParse((string)node.Attribute("HttpStatus")) ?? (HttpStatusCode)0;

            resource.ContentType = EnumHelper <ResourceContentType> .Parse((string)node.Attribute("ContentType"));

            resource.TimeStart      = TryParseDateTime(node.Attribute("TimeStart"));
            resource.TimeLoading    = TimeSpan.Parse((string)node.Attribute("TimeLoading"));
            resource.TimeProcessing = TimeSpan.Parse((string)node.Attribute("TimeProcessing"));
            resource.Size           = (int)node.Attribute("Size");
            resource.CompressedSize = (int)node.Attribute("CompressedSize");
            resource.ViewStateSize  = (int?)node.Attribute("ViewStateSize");

            foreach (XElement header in node.Descendants("Header"))
            {
                resource.Headers.Add((string)header.Attribute("Key"), (string)header.Attribute("Value"));
            }

            foreach (XElement meta in node.Descendants("Content"))
            {
                ResourceContentKey?resourceKey = EnumHelper <ResourceContentKey> .TryParse((string)meta.Attribute("Key"));

                resource.Content.Add(new ResourceContent
                {
                    Key    = resourceKey ?? ResourceContentKey.Meta,
                    SubKey = (string)meta.Attribute(resourceKey.HasValue ? "SubKey" : "Key"),
                    Value  = (string)meta.Attribute("Value")
                });
            }

            foreach (XElement link in node.Descendants("Reference"))
            {
                resource.References.Add(
                    EnumHelper <ResourceReferenceTypes> .Parse((string)link.Attribute("Type")),
                    new Uri((string)link.Attribute("Url"), UriKind.RelativeOrAbsolute),
                    EnumHelper <ReferenceSubType> .TryParse((string)link.Attribute("SubType"), ReferenceSubType.None, true),
                    NumberHelper.TryParseInt32((string)link.Attribute("Count")) ?? 1);
            }

            foreach (XElement error in node.Descendants("Error"))
            {
                resource.Errors.Add(new ResourceError
                {
                    Type    = EnumHelper <ResourceErrorType> .Parse((string)error.Attribute("Type")),
                    Message = (string)error.Attribute("Message"),
                    Value   = (string)error.Attribute("Value"),
                    Line    = (int?)error.Attribute("Line")
                });
            }

            return(resource);
        }
Esempio n. 4
0
 public Resource(Uri url, ResourceBehavior behavior)
 {
     Url          = url;
     Behavior     = behavior;
     References   = new ResourceReferenceCollection(this);
     ReferencedBy = new List <ResourceReference>();
     Headers      = new ResourceHeaders();
     Content      = new List <ResourceContent>();
     Status       = ResourceStatus.ReadyToProcess;
     Errors       = new List <ResourceError>();
 }
        /// <summary>
        /// Creates a new dictionary with the specified behavior.
        /// </summary>
        /// <param name="behaviorType">The resource behavior type.</param>
        /// <param name="existingData">The initial dictionary data.</param>
        /// <returns>A new dictionary with the specified behavior.</returns>
        public IDictionary <string, object> NewDictionary(ResourceBehavior behaviorType, IDictionary <string, object> existingData)
        {
            var initialData = existingData ?? new Dictionary <string, object>();

            switch (behaviorType)
            {
            case ResourceBehavior.Default: return(new Dictionary <string, object>(initialData, StringComparer.OrdinalIgnoreCase));

            case ResourceBehavior.ChangeTracking: return(new DefaultChangeTrackingDictionary(initialData, StringComparer.OrdinalIgnoreCase));
            }

            throw new ArgumentException($"Unknown resource dictionary type {behaviorType}");
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Resource"/> class.
 /// </summary>
 /// <param name="dictionaryType">The dictionary type to use.</param>
 public Resource(ResourceBehavior dictionaryType)
 {
     _dictionaryType = dictionaryType;
     Initialize(null, null, null, null);
 }
Esempio n. 7
0
 public void AddBehaviorRule(string name, ResourceBehavior behavior, WorkBucket <Resource, BucketContext> targetBucket, ICollection <CrawlingCondition> conditions)
 {
     _behaviorRules.AddUrlFilterRule(name, behavior, targetBucket, conditions);
 }