Пример #1
0
        public ExecutionElement VisitExecution(XDocument document)
        {
            var item = new ExecutionElement();

            var root = document.Root;

            if (root == null || !root.HasElements)
            {
                return(item);
            }

            var metaElement = root.Element("Meta");

            if (metaElement != null)
            {
                VisitMeta(metaElement);
            }

            var executionElement = root.Element("Execution");

            if (executionElement != null)
            {
                VisitExecution(item, executionElement);
            }

            return(item);
        }
Пример #2
0
        public void VisitExecution(ExecutionElement item, XContainer container)
        {
            foreach (var element in container.Elements())
            {
                var name = element.Name.LocalName;

                ElementTypes type;
                if (!Enum.TryParse(name, out type))
                {
                    continue;
                }

                switch (type)
                {
                case ElementTypes.PerClient:
                    VisitPerClientSchedule(item, element);
                    break;

                case ElementTypes.Continuous:
                    VisitContinuous(item, element);
                    break;

                case ElementTypes.Scheduled:
                    VisitScheduled(item, element);
                    break;
                }
            }
        }
Пример #3
0
        internal static Execution GetExecution(ExecutionElement executionConfiguration, Crawler crawler)
        {
            IQueryable <Execution> executions = DataContext.Instance.ExecutionSet
                                                .Where(e => e.Crawler.CrawlerId == crawler.CrawlerId &&
                                                       e.LanguageCode == executionConfiguration.LanguageCode &&
                                                       e.Parameters.Count == executionConfiguration.Parameters.Count &&
                                                       e.Parameters.All(p => executionConfiguration.Parameters.AllKeys.Contains(p.Name)));

            Execution execution = null;

            foreach (Execution dbExecution in executions)
            {
                if (dbExecution.Parameters.All(p => executionConfiguration.Parameters[p.Name].Value == p.Value))
                {
                    execution = dbExecution;
                    break;
                }
            }

            bool pendingChanges = false;

            if (execution == null)
            {
                execution = DataContext.Instance.ExecutionSet.Add(new Execution
                {
                    Crawler      = crawler,
                    LanguageCode = executionConfiguration.LanguageCode,
                    Description  = executionConfiguration.Description
                });

                foreach (NameValueConfigurationElement parameter in executionConfiguration.Parameters)
                {
                    execution.Parameters.Add(new Parameter {
                        Name = parameter.Name, Value = parameter.Value
                    });
                }

                pendingChanges = true;
            }
            else if (execution.Description != executionConfiguration.Description)
            {
                execution.Description = executionConfiguration.Description;
                pendingChanges        = true;
            }

            if (pendingChanges)
            {
                DataContext.Instance.SaveChanges();
            }

            return(execution);
        }
Пример #4
0
        public void VisitScheduled(ExecutionElement parent, XElement element)
        {
            var item = new ScheduledElement
            {
                Id                = (string)element.Attribute("taskId"),
                ClientId          = (int?)element.Attribute("clientId"),
                DaysConsidered    = Enumerable.Range(0, 7).ToArray(),
                HoursConsidered   = Enumerable.Range(0, 24).ToArray(),
                MinutesConsidered = new[] { 0 },
            };

            parent.AddExecutionType(item);

            if (item.ClientId.HasValue)
            {
                item.Id = string.Format("client.{0}.{1}", item.ClientId, item.Id);
            }
            else
            {
                if (!item.ClientId.HasValue && metaData.HasEntries)
                {
                    string metaClientId;
                    if (!metaData.TryGetEntry("ClientId", out metaClientId))
                    {
                        int clientId;
                        if (int.TryParse(metaClientId, out clientId))
                        {
                            item.ClientId = clientId;
                        }
                    }
                }
            }

            if (!element.HasElements)
            {
                return;
            }

            VisitScheduled(item, element);
            VisitExecutionOrder(item, element);
        }
Пример #5
0
        private void ValidateConfiguration(ExecutionElement executionConfiguration)
        {
            if (string.IsNullOrWhiteSpace(executionConfiguration.LanguageCode))
            {
                throw new ConfigurationErrorsException("The language code cannot be null ot white space.");
            }

            CultureInfo selectedLang = CultureInfo.GetCultures(CultureTypes.NeutralCultures)
                                       .FirstOrDefault(x => x.Name.Equals(executionConfiguration.LanguageCode,
                                                                          StringComparison.InvariantCultureIgnoreCase));

            if (selectedLang == null)
            {
                throw new ConfigurationErrorsException(String.Format("The language code \"{0}\" is not defined as a neutral culture in the framework.",
                                                                     selectedLang.Name));
            }
            if (selectedLang.Equals(CultureInfo.InvariantCulture))
            {
                throw new ConfigurationErrorsException("The language code specified cannot be the Invariant culture.");
            }
        }
Пример #6
0
        public void VisitContinuous(ExecutionElement parent, XElement element)
        {
            var item = new ContinuousElement
            {
                Id             = (string)element.Attribute("taskId"),
                IdlePeriod     = (int)element.Attribute("idlePeriod"),
                IdlePeriodType = (string)element.Attribute("idlePeriodType"),
                ClientId       = (int?)element.Attribute("clientId"),
            };

            parent.AddExecutionType(item);

            if (item.ClientId.HasValue)
            {
                item.Id = string.Format("client.{0}.{1}", item.ClientId, item.Id);
            }
            else
            {
                if (!item.ClientId.HasValue && metaData.HasEntries)
                {
                    string metaClientId;
                    if (!metaData.TryGetEntry("ClientId", out metaClientId))
                    {
                        int clientId;
                        if (int.TryParse(metaClientId, out clientId))
                        {
                            item.ClientId = clientId;
                        }
                    }
                }
            }

            if (!element.HasElements)
            {
                return;
            }

            VisitExecutionOrder(item, element);
        }
Пример #7
0
        public void VisitPerClientSchedule(ExecutionElement parent, XElement element)
        {
            if (!element.HasElements)
            {
                return;
            }

            if (!metaData.HasEntries)
            {
                VisitExecution(parent, element);
                return;
            }

            string metaClientIdentifiers;

            if (!metaData.TryGetEntry("ClientIdentifiers", out metaClientIdentifiers))
            {
                VisitExecution(parent, element);
                return;
            }

            var clientIdentifiers = metaClientIdentifiers.Split(',')
                                    .Where(x => !string.IsNullOrWhiteSpace(x))
                                    .Select(x => x.Trim())
                                    .ToArray();

            foreach (var clientIdentifier in clientIdentifiers)
            {
                var clientElement = new XElement(element);
                clientElement.Descendants()
                .Where(x => x.Attribute("taskId") != null)
                .ToList()
                .ForEach(x => x.Add(new XAttribute("clientId", clientIdentifier)));

                VisitExecution(parent, clientElement);
            }
        }
Пример #8
0
 protected override void AssertServiceParameters(ServiceSettings s, JResult r, ExecutionElement ee)
 {
 }
Пример #9
0
 protected abstract void AssertServiceParameters(ServiceSettings s,
     JResult r,
     ExecutionElement ee);
Пример #10
0
        public IMiramarScheduleProvider CreateScheduleProvider(IMiramarPublisher publisher, ExecutionElement element)
        {
            if (element == null)
            {
                return(new MiramarScheduleProvider(publisher, new TaskScheduleModel[0]));
            }

            var collection = element.ExecutionTypes
                             .Select(CreateModel)
                             .ToArray();

            return(new MiramarScheduleProvider(publisher, collection));
        }