protected override MetricsUnit GetSampleMetrics() { var headers = new[] { AdWordsConst.AdPreRequiredHeader }; // load sample keywords var file = new DeliveryFile { Location = Configuration.Parameters.Get <string>("KeywordSampleFile") }; LoadKeywords(file, headers, FileCompression.None); file = new DeliveryFile { Location = Configuration.Parameters.Get <string>("PlacementSampleFile") }; LoadPlacements(file, new[] { AdWordsConst.AutoPlacRequiredHeader }, FileCompression.None); // load ad using (_adsReader = new CsvDynamicReader(Configuration.Parameters.Get <string>("AdSampleFile"), headers)) { Mappings.OnFieldRequired = fieldName => _adsReader.Current[fieldName]; if (_adsReader.Read()) { CurrentMetricsUnit = new MetricsUnit { GetEdgeField = GetEdgeField, Output = new DeliveryOutput() }; MetricsMappings.Apply(CurrentMetricsUnit); return(CurrentMetricsUnit); } } throw new ConfigurationErrorsException(String.Format("Failed to read sample metrics from file: {0}", Configuration.Parameters.Get <string>("AdSampleFile"))); }
protected override MetricsUnit GetSampleMetrics() { LoadCampaigns(new DeliveryFile { Location = Configuration.Parameters.Get <string>("CampaignSampleFile") }); LoadCreatives(new DeliveryFile { Location = Configuration.Parameters.Get <string>("CreativeSampleFile") }); LoadAds(new DeliveryFile { Location = Configuration.Parameters.Get <string>("AdGroupSampleFile") }); using (var reader = new JsonDynamicReader(Configuration.SampleFilePath, "$.data[*].*")) { Mappings.OnFieldRequired = fieldName => reader.Current[fieldName]; if (reader.Read()) { CurrentMetricsUnit = new MetricsUnit { GetEdgeField = GetEdgeField, Output = new DeliveryOutput() }; MetricsMappings.Apply(CurrentMetricsUnit); return(CurrentMetricsUnit); } } throw new ConfigurationErrorsException(String.Format("Failed to read sample metrics from file: {0}", Configuration.SampleFilePath)); }
protected override MetricsUnit GetSampleMetrics() { using (var reader = new JsonDynamicReader(Configuration.SampleFilePath, "$.records[*].*")) { Mappings.OnFieldRequired = fieldName => reader.Current[fieldName]; if (reader.Read()) { CurrentMetricsUnit = new MetricsUnit { GetEdgeField = GetEdgeField, Output = new DeliveryOutput() }; MetricsMappings.Apply(CurrentMetricsUnit); return(CurrentMetricsUnit); } } throw new ConfigurationErrorsException(String.Format("Failed to read sample metrics from file: {0}", Configuration.SampleFilePath)); }
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); }