示例#1
0
        static void Main(string[] args)
        {
            BandFactory factory = getBangFactory("rock");
            Band        band    = factory.createBand();

            band.play();
        }
        public IFileObjectFactory GetFileObject(string ObjectType)
        {
            IFileObjectFactory fileobject;

            switch (ObjectType)
            {
            case "Band":
                fileobject = new BandFactory(repository);
                break;

            case "Song":
                fileobject = new SongFactory(repository);
                break;

            case "MusicGenre":
                fileobject = new MusicGenreFactory(repository);
                break;

            case "BandsRecord":
                fileobject = new BandsRecordFactory(repository);
                break;

            default:
                fileobject = null;
                break;
            }

            return(fileobject);
        }
示例#3
0
        private bool ProcessGermPlasmEvent(ILambdaContext context, GermPlasmSNSRequest request, QueueGermPlasmEvent gpEvent)
        {
            long germPlasmId = gpEvent.Germplasm.GermplasmId;

            context.Logger.LogLine($"processing data keys to cache for germ Plasm Id: {germPlasmId}; key:{gpEvent.Germplasm.GetProduct()}; isMetric: {request.IsMetric}");
            if (filter == null)
            {
                filter = new FilterApplicator(gpEvent.DataFilters, this.udrList);
            }
            string   cacheReportName = gpEvent.ReportName.Replace(' ', '`');
            int      reportId        = gpEvent.ReportId;
            TimeSpan ts = context.RemainingTime.Subtract(TimeSpan.FromSeconds(20));

            if (ts.Ticks <= 0)
            {
                context.Logger.LogLine($"CreateMessageAsync for germ Plasm Id: {germPlasmId}");
                queue.CreateMessageAsync(gpEvent);
                return(true);
            }

            Dictionary <string, BaseBand> bands = new Dictionary <string, BaseBand>();

            foreach (BandDefinition bandDefintion in gpEvent.Bands)
            {
                BandFactory.Create(bands, context, this.httpClient, bandDefintion, this.productAnalyticsAPIClient, this.udrList);
            }

            CancellationTokenSource cancellationToken = new CancellationTokenSource(ts);

            if (!this.persister.GermPlasmProcessed(cacheReportName, reportId, germPlasmId))
            {
                try
                {
                    context.Logger.Log($"processing the germplasm {germPlasmId}");

                    List <string> observations = gpEvent.Observations.Select(o => o.ObsRefCd).ToList();
                    // load data, supplying API supported filters
                    List <Dictionary <string, dynamic> > data =
                        this.productAnalyticsAPIClient.GetEntryMeansAsynch(
                            context,
                            this.httpClient,
                            cancellationToken.Token,
                            gpEvent.UserId,
                            germPlasmId,
                            filter.ApiFilters,
                            observations,
                            gpEvent.Crop,
                            gpEvent.RegionName
                            ).Result;
                    // S<IP for now: then load any missing banding/observational data
                    // output to summarize valid records
                    List <ReducedEntryMeans> reportOutputs = ReportGrouperFactory.GetStandardReducedEntryMeans(
                        bands,
                        gpEvent.AnalysisType,
                        observations);

                    object cEvent;
                    foreach (Dictionary <string, dynamic> row in data)
                    {
                        if (gpEvent.Germplasm.CEvent == null && row.TryGetValue("cEvent", out cEvent) && cEvent != null && !string.IsNullOrEmpty(cEvent.ToString()))
                        {
                            gpEvent.Germplasm.CEvent = cEvent.ToString().Replace(',', '|');
                        }
                        if (filter.IsApplicable(row)) // first, see if the row should be filtered
                        {
                            context.Logger.Log($"first, see if the row should be filtered {JsonConvert.SerializeObject(row)}");
                            foreach (ReducedEntryMeans output in reportOutputs)
                            {
                                output.ProcessRecord(cancellationToken.Token, request.IsMetric, row); // apply bands and gather observations
                            }
                        }
                    }
                    context.Logger.LogLine($"persisting data to cache for germ Plasm Id: {germPlasmId}, cEvent: {gpEvent.Germplasm.CEvent}");
                    persister.PersistGermPlasmOutputAsync(context, cacheReportName, reportId, gpEvent.Germplasm, gpEvent.Category, reportOutputs).Wait();
                }
                catch (AggregateException exc)
                {
                    context.Logger.LogLine($"ProcessGermPlasmEvent : {exc.StackTrace}-ExceptionMessage:{exc.Message}-reportName:{cacheReportName}- germplasmId: {germPlasmId}");

                    //headToHeadAPIClient.ReportFailure(context, this.httpClient, request.ReportId, "AggregateException= " +exc.Message);
                    queue.CreateMessageAsync(gpEvent);
                    bool cancelled = cancellationToken.IsCancellationRequested || exc.InnerExceptions.Select(e => e is TaskCanceledException).Count() > 0;
                    if (!cancelled)
                    {
                        throw;
                    }
                    context.Logger.LogLine($"cancelled: {cancellationToken.IsCancellationRequested}");
                    return(true);
                }
            }
            else
            {
                context.Logger.Log($"skipping processing for report: {cacheReportName} and germ plasm id: {germPlasmId}");
            }

            if (AreWeFinished(context, cacheReportName, gpEvent.UserId, germPlasmId)) //when we are finished
            {
                context.Logger.Log($"starting up band generation");
                //put single SNS message to initiiate next process.
                this.notifier.SendBandProcessStartAsync(new BandNotificationMessage(
                                                            userId: request.UserId,
                                                            reportName: request.ReportName,
                                                            reportId: request.ReportId,
                                                            crop: gpEvent.Crop,
                                                            region: gpEvent.Region,
                                                            year: gpEvent.Year,
                                                            compareHeads: request.CompareHeads,
                                                            reportIdentifier: request.ReportIdentifier))
                .Wait();

                this.queue.DeleteGPQueueAsync().Wait();
                context.Logger.Log($"Delete Queue DeleteGPQueueAsync End");
                return(false);
            }
            return(true);
        }