Exemplo n.º 1
0
        public List <Source> SourceProcess()
        {
            var sources = new List <Source>();

            if (extractImplementation != null)
            {
                Dictionary <string, Source> daySources;
                GenericOutput <Source>      genericOutput = null;
                try
                {
                    daySources = extractImplementation.GetDaySources();
                    var dateNow = DateTimeOffset.Now.Date.ToString(Kernel.Instance.ServiceConfiguration.DateFormat);
                    if (!Kernel.Instance.ServiceConfiguration.IncludeDateNow &&
                        daySources.ContainsKey(dateNow))
                    {
                        daySources.Remove(dateNow);
                    }
                    genericOutput = ModelData.Instance.SourceSelect(new SourcePredicate
                    {
                        Source = new Criteria <List <Source> >(new List <Source>(daySources.Values.ToList()))
                    });
                }
                catch (Exception exception)
                {
                    Kernel.Instance.Logging.Error(exception, false);
                    daySources = null;
                }
                if (daySources != null &&
                    genericOutput != null)
                {
                    foreach (var daySource in daySources)
                    {
                        try
                        {
                            var source = genericOutput.Entities.Find(item => item.Date == daySource.Value.Date);
                            if (source != null &&
                                source.Length >= daySource.Value.Length)
                            {
                                continue;
                            }
                            Kernel.Instance.Logging.Information(string.Format("Process '{0}' day...", daySource.Key));
                            extractImplementation.ExtractDaySource(daySource);
                            Transform(daySource.Value);
                            Analyse(daySource.Value);
                            sources.Add(ModelData.Instance.SourceCreate(daySource.Value));
                            Kernel.Instance.Logging.Information(string.Format("Day '{0}' processed.", daySource.Key));
                        }
                        catch (Exception exception)
                        {
                            Kernel.Instance.Logging.Error(exception, false);
                        }
                    }
                }
            }
            return(sources);
        }