protected override MetricsUnit GetSampleMetrics()
        {
            try
            {
                // load sample file, read only one row in order to create metrics table by sample metric unit
                ReaderAdapter.Init(FileManager.Open(Configuration.SampleFilePath), Configuration);
                ReaderAdapter.Reader.Read();

                CurrentMetricsUnit = new MetricsUnit {
                    GetEdgeField = GetEdgeField, Output = new DeliveryOutput()
                };
                MetricsMappings.Apply(CurrentMetricsUnit);
                return(CurrentMetricsUnit);
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException(String.Format("Failed to create metrics by sample file '{0}', ex: {1}", Configuration.SampleFilePath, ex.Message));
            }
        }
        protected override ServiceOutcome DoPipelineWork()
        {
            InitMappings();

            LoadConfiguration();

            // Import data
            using (ReaderAdapter)
            {
                using (ImportManager = new MetricsDeliveryManager(InstanceID, EdgeTypes, _importManagerOptions)
                {
                    OnLog = Log
                })
                {
                    // create objects tables and metrics table according to sample metrics
                    ImportManager.BeginImport(Delivery, GetSampleMetrics());
                    Log("ImportManager.BeginImport() executed successfully", LogMessageType.Debug);

                    // open delivery file
                    using (var stream = _deliveryFile.OpenContents(compression: _compression))
                    {
                        ReaderAdapter.Init(stream, Configuration);

                        // for each row in file read and import into metrics table
                        var readSuccess = false;
                        while (CheckEndOfFile())
                        {
                            readSuccess = true;
                            ProcessMetrics();
                        }

                        if (!readSuccess)
                        {
                            Log("Could Not read data from file!, check file mapping and configuration", Core.Utilities.LogMessageType.Warning);
                        }

                        ImportManager.EndImport();
                        Log("ImportManager.EndImport() executed successfully", LogMessageType.Debug);
                    }
                }
            }
            return(ServiceOutcome.Success);
        }
Beispiel #3
0
        protected override ServiceOutcome DoPipelineWork()
        {
            // init mapping and load configuration
            Log("Starting Google.AdWords.CampaignCriterionProcessorService", LogMessageType.Debug);
            InitMappings();

            Mappings.OnMappingApplied = SetEdgeType;

            if (!Mappings.Objects.TryGetValue(typeof(MetricsUnit), out MetricsMappings))
            {
                throw new MappingConfigurationException("Missing mapping definition for MetricsUnit.", "Object");
            }

            LoadConfiguration();
            Progress = 0.1;

            // get nessesary EdgeFields
            var relationField           = GetEdgeFieldByName("Relation");
            var locationField           = GetEdgeFieldByName("Location");
            var languageField           = GetEdgeFieldByName("Language");
            var isLocationNegativeField = GetEdgeFieldByName("IsLocationNegative");
            var isLanguageNegativeField = GetEdgeFieldByName("IsLanguageNegative");

            using (ReaderAdapter)
            {
                using (var stream = _deliveryFile.OpenContents(compression: _compression))
                {
                    ReaderAdapter.Init(stream, Configuration);
                    while (ReaderAdapter.Reader.Read())
                    {
                        // load metrics unit which contains Relation object of Campaign-Language or Campaign-Location
                        CurrentMetricsUnit = new MetricsUnit {
                            GetEdgeField = GetEdgeField, Output = new DeliveryOutput()
                        };
                        MetricsMappings.Apply(CurrentMetricsUnit);

                        // insert loaded relation to List per Campaign
                        var relation = CurrentMetricsUnit.Dimensions[relationField] as RelationObject;
                        if (relation != null)
                        {
                            var campaign = relation.Object1 as Campaign;
                            if (campaign != null)
                            {
                                if (!_campaignRelationMap.ContainsKey(campaign.OriginalID))
                                {
                                    _campaignRelationMap.Add(campaign.OriginalID, new List <RelationObject>());
                                }

                                _campaignRelationMap[campaign.OriginalID].Add(relation);
                            }
                        }
                    }
                }
            }
            Progress = 0.5;

            using (ImportManager = new MetricsDeliveryManager(InstanceID, EdgeTypes, _importManagerOptions)
            {
                OnLog = Log
            })
            {
                // create object tables
                ImportManager.BeginImport(Delivery, null);

                // add objects to EdgeObjectsManager cache
                PrepareImportObjects(x => x is Location, locationField, isLocationNegativeField);
                PrepareImportObjects(x => x is Language, languageField, isLanguageNegativeField);

                // import objects
                ImportManager.EndImport();
            }
            return(ServiceOutcome.Success);
        }