private Target GetPlacementTarget() { Target target; var id = _adsReader.Current[AdWordsConst.KeywordIdFieldName]; // get keyword by key from keyword or placement dictionary var key = new KeywordPrimaryKey { AdgroupId = Convert.ToInt64(_adsReader.Current[AdWordsConst.AdGroupIdFieldName]), KeywordId = Convert.ToInt64(_adsReader.Current[AdWordsConst.KeywordIdFieldName]), CampaignId = Convert.ToInt64(_adsReader.Current[AdWordsConst.CampaignIdFieldName]) }; // Check if placement exists in Placement cache, if YES - take it, otherwise - null target = _placementsCache.ContainsKey(key.ToString()) ? _placementsCache[key.ToString()] : null; // otherwise - create new Placement by ID //new PlacementTarget // { // Value = id, // PlacementType = new PlacementType // { // Value = "Automatic", // TK = "Automatic", // EdgeType = GetEdgeType("PlacementType"), // }, // EdgeType = GetEdgeType("PlacementTarget"), // TK = id, // Fields = new Dictionary<EdgeField, object> { {GetExtraField("OriginalID"), id}} // }; return(target); }
private void LoadPlacements(DeliveryFile file, string[] headers, FileCompression compression = FileCompression.Gzip) { if (file == null) { throw new ArgumentException("Placement delivery file does not exist"); } _placementsCache.Clear(); using (var placementsReader = new CsvDynamicReader(file.OpenContents(compression: compression), headers)) { Mappings.OnFieldRequired = fieldName => placementsReader.Current[fieldName]; placementsReader.MatchExactColumns = false; while (placementsReader.Read()) { if (placementsReader.Current[AdWordsConst.PlacementIdFieldName] == AdWordsConst.EOF) { break; } var placementPrimaryKey = new KeywordPrimaryKey { KeywordId = Convert.ToInt64(placementsReader.Current[AdWordsConst.PlacementIdFieldName]), AdgroupId = Convert.ToInt64(placementsReader.Current[AdWordsConst.AdGroupIdFieldName]), CampaignId = Convert.ToInt64(placementsReader.Current[AdWordsConst.CampaignIdFieldName]) }; var placement = new PlacementTarget(); PlacementMappings.Apply(placement); _placementsCache.Add(placementPrimaryKey.ToString(), placement); } } }
private Target GetKeywordTarget() { Target target; var id = _adsReader.Current[AdWordsConst.KeywordIdFieldName]; // get keyword by key from keyword or placement dictionary var key = new KeywordPrimaryKey { AdgroupId = Convert.ToInt64(_adsReader.Current[AdWordsConst.AdGroupIdFieldName]), KeywordId = Convert.ToInt64(_adsReader.Current[AdWordsConst.KeywordIdFieldName]), CampaignId = Convert.ToInt64(_adsReader.Current[AdWordsConst.CampaignIdFieldName]) }; // TODO - what is it for??? key.KeywordId != Convert.ToInt64(Delivery.Parameters["KeywordContentId"]) // Check if keyword exists in Keywords cache, if YES - take it target = _keywordsCache.ContainsKey(key.ToString()) ? _keywordsCache[key.ToString()] : // check if contains in Placement cache, if YES - null (because placement exists) _placementsCache.ContainsKey(key.ToString()) ? null : // otherwise - create new Keyword by ID new KeywordTarget { Value = id, MatchType = new KeywordMatchType { Value = "Unidentified", TK = "Unidentified", EdgeType = GetEdgeType("KeywordMatchType"), }, EdgeType = GetEdgeType("KeywordTarget"), TK = id, Fields = new Dictionary <EdgeField, object> { { GetExtraField("OriginalID"), id } } }; return(target); }