Exemplo n.º 1
0
        protected override ServiceOutcome DoPipelineWork()
        {
            this.Delivery = this.NewDelivery(); // setup delivery
            this.Delivery.FileDirectory = Instance.Configuration.Options[Edge.Data.Pipeline.Services.Const.DeliveryServiceConfigurationOptions.FileDirectory];
            this.Delivery.Account       = new Account()
            {
                ID = 0
            };

            string fileName = string.Empty;

            //FileName
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["FileName"]))
            {
                throw new Exception("Missing Configuration Param , FileName");
            }
            else
            {
                fileName = this.Instance.Configuration.Options["FileName"];
            }

            DeliveryFile _file = new DeliveryFile()
            {
                Name = fileName
            };

            _file.SourceUrl = Instance.Configuration.Options["SourceUrl"];

            _file.Parameters.Add("XML.IsAttribute", Instance.Configuration.Options["XML.IsAttribute"]);
            _file.Parameters.Add("XML.Path", Instance.Configuration.Options["XML.Path"]);

            this.Delivery.Files.Add(_file);


            //Set Output


            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("[{0}]-[{1}]",
                                                                   this.TimePeriod.ToAbsolute(),
                                                                   Instance.Configuration.Options["SourceUrl"]
                                                                   )),
                Account = new Data.Objects.Account()
                {
                    ID = 0
                },
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            });

            this.Delivery.Save();
            return(Core.Services.ServiceOutcome.Success);
        }
Exemplo n.º 2
0
        protected override ServiceOutcome DoPipelineWork()
        {
            #region Init General
            // ...............................
            // SETUP
            this.Delivery = this.NewDelivery();

            // This is for finding conflicting services
            this.Delivery.Signature = Delivery.CreateSignature(String.Format("facebook-[{0}]-[{1}]-[{2}]",
                                                                             this.Instance.AccountID,
                                                                             this.Instance.Configuration.Options[FacebookConfigurationOptions.Account_ID].ToString(),
                                                                             this.TargetPeriod.ToAbsolute()));

            // Create an import manager that will handle rollback, if necessary
            AdMetricsImportManager importManager = new AdMetricsImportManager(this.Instance.InstanceID, new Edge.Data.Pipeline.Common.Importing.ImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Common.Importing.Consts.AppSettings.SqlRollbackCommand]
            });

            // Apply the delivery (will use ConflictBehavior configuration option to abort or rollback if any conflicts occur)
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            // ...............................

            // Now that we have a new delivery, start adding values
            this.Delivery.Account = new Data.Objects.Account()
            {
                ID         = this.Instance.AccountID,
                OriginalID = this.Instance.Configuration.Options[FacebookConfigurationOptions.Account_ID].ToString()
            };
            this.Delivery.TargetPeriod = this.TargetPeriod;
            this.Delivery.Channel      = new Data.Objects.Channel()
            {
                ID = 6
            };

            this.Delivery.TargetLocationDirectory = Instance.Configuration.Options["DeliveryFilesDir"];

            if (string.IsNullOrEmpty(this.Delivery.TargetLocationDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }
            // Copy some options as delivery parameters
            var configOptionsToCopyToDelivery = new string[] {
                FacebookConfigurationOptions.Account_ID,
                FacebookConfigurationOptions.Account_Name,
                FacebookConfigurationOptions.Auth_ApiKey,
                FacebookConfigurationOptions.Auth_AppSecret,
                FacebookConfigurationOptions.Auth_SessionKey,
                FacebookConfigurationOptions.Auth_SessionSecret,
                FacebookConfigurationOptions.Auth_RedirectUri,
                FacebookConfigurationOptions.Auth_AuthenticationUrl
            };
            foreach (string option in configOptionsToCopyToDelivery)
            {
                this.Delivery.Parameters[option] = this.Instance.Configuration.Options[option];
            }
            if (string.IsNullOrEmpty(this.Instance.Configuration.Options[FacebookConfigurationOptions.BaseServiceAddress]))
            {
                throw new Exception("facebook base url must be configured!");
            }
            _baseAddress = new Uri(this.Instance.Configuration.Options[FacebookConfigurationOptions.BaseServiceAddress]);
            this.ReportProgress(0.2);
            #endregion

            #region Init Delivery Files

            Dictionary <string, string> methodParams = new Dictionary <string, string>();
            string       methodUrl;
            DeliveryFile deliveryFile = new DeliveryFile();
            #region adgroupstats

            deliveryFile.Name = Consts.DeliveryFilesNames.AdGroupStats;
            methodParams.Add(Consts.FacebookMethodsParams.StartTime, ConvertToFacebookDateTime(TargetPeriod.Start.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.EndTime, ConvertToFacebookDateTime(TargetPeriod.End.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodParams.Add(Consts.FacebookMethodsParams.StatsMode, "with_delivery");
            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroupStats);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Enum.Parse(typeof(Consts.FileTypes), Consts.FileTypes.AdGroupStats.ToString()));
            this.Delivery.Files.Add(deliveryFile);
            #endregion

            this.ReportProgress(0.4);
            #region adgroup

            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.AdGroup;
            methodUrl         = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroups);
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.AdGroups);

            this.Delivery.Files.Add(deliveryFile);
            #endregion

            this.ReportProgress(0.6);

            #region Campaigns


            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.Campaigns;
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetCampaigns);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.Campaigns);
            this.Delivery.Files.Add(deliveryFile);

            #endregion

            #region Creatives
            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.Creatives;
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroupCreatives);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.Creatives);
            this.Delivery.Files.Add(deliveryFile);
            #endregion

            //#region AdGroupTargeting
            //deliveryFile = new DeliveryFile();
            //deliveryFile.Name = Consts.DeliveryFilesNames.AdGroupTargeting;
            //methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroupTargeting);
            //deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            //deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Data);
            //this.Delivery.Files.Add(deliveryFile);
            //#endregion



            #endregion

            this.ReportProgress(0.9);
            this.Delivery.Save();

            this.ReportProgress(1);

            return(ServiceOutcome.Success);
        }
        protected override ServiceOutcome DoPipelineWork()
        {
            this.Delivery = this.NewDelivery();             // setup delivery
            this.Delivery.FileDirectory = Instance.Configuration.Options[Edge.Data.Pipeline.Services.Const.DeliveryServiceConfigurationOptions.FileDirectory];
            this.Delivery.Account       = new Account()
            {
                ID = 0
            };



            string fileName = string.Empty;

            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["YahhoApiURL"]))
            {
                this.Delivery.Parameters.Add("YahhoApiURL", this.Instance.Configuration.Options["YahhoApiURL"]);
            }

            //FileName
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["FileName"]))
            {
                throw new Exception("Missing Configuration Param , FileName");
            }
            else
            {
                fileName = this.Instance.Configuration.Options["FileName"];
            }

            //CrossRateSymbols
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["CrossRateSymbols"]))
            {
                throw new Exception("Missing Configuration Param , CrossRateSymbols");
            }
            else
            {
                this.Delivery.Parameters.Add("CrossRateSymbols", this.Instance.Configuration.Options["CrossRateSymbols"]);
            }

            //UserName
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["UserName"]))
            {
                throw new Exception("Missing Configuration Param , UserName");
            }
            else
            {
                this.Delivery.Parameters.Add("UserName", this.Instance.Configuration.Options["UserName"]);
            }

            //UserPassword
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["UserPassword"]))
            {
                throw new Exception("Missing Configuration Param , UserPassword");
            }
            else
            {
                this.Delivery.Parameters.Add("UserPassword", this.Instance.Configuration.Options["UserPassword"]);
            }


            DeliveryFile _file = new DeliveryFile()
            {
                Name = fileName
            };

            _file.SourceUrl = Instance.Configuration.Options["SourceUrl"];            // "http://www.xignite.com/xCurrencies.asmx";
            _file.Parameters.Add("Content-Type", "text/xml; charset=utf-8");
            _file.Parameters.Add("SOAPAction", Instance.Configuration.Options["SOAPAction"]);
            _file.Parameters.Add("SoapMethod", Instance.Configuration.Options["SoapMethod"]);
            _file.Parameters.Add("Body", GetSoapEnvelope(
                                     this.Instance.Configuration.Options["UserName"].ToString(),
                                     this.Instance.Configuration.Options["UserPassword"].ToString(),
                                     this.Instance.Configuration.Options["SoapMethod"].ToString(),
                                     this.Instance.Configuration.Options["CrossRateSymbols"].ToString(),
                                     string.Empty,
                                     this.Delivery.TimePeriodStart.ToString("MM/dd/yyyy")
                                     ));

            _file.Parameters.Add("XML.IsAttribute", Instance.Configuration.Options["XML.IsAttribute"]);
            _file.Parameters.Add("XML.Path", Instance.Configuration.Options["XML.Path"]);

            this.Delivery.Files.Add(_file);


            //Set Output

            foreach (string crossRate in this.Delivery.Parameters["CrossRateSymbols"].ToString().Split(','))
            {
                this.Delivery.Outputs.Add(new DeliveryOutput()
                {
                    Signature = Delivery.CreateSignature(String.Format("[{0}]-[{1}]",
                                                                       this.TimePeriod.ToAbsolute(),
                                                                       crossRate
                                                                       )),
                    Account = new Data.Objects.Account()
                    {
                        ID = 0
                    },
                    TimePeriodStart = Delivery.TimePeriodStart,
                    TimePeriodEnd   = Delivery.TimePeriodEnd
                }
                                          );
            }

            // Create an import manager that will handle rollback, if necessary
            //CurrencyImportManager importManager = new CurrencyImportManager(this.Instance.InstanceID,null);
            //TO DO: Add rollback


            // will use ConflictBehavior configuration option to abort or rollback if any conflicts occur
            //this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);


            this.Delivery.Save();
            return(Core.Services.ServiceOutcome.Success);
        }
        protected override ServiceOutcome DoPipelineWork()
        {
            #region Init General
            // ...............................
            // SETUP
            this.Delivery = NewDelivery();
            // This is for finding conflicting services
            this.Delivery.Account = new Data.Objects.Account()
            {
                ID         = this.Instance.AccountID,
                OriginalID = this.Instance.Configuration.Options[FacebookConfigurationOptions.Account_ID].ToString()
            };
            this.Delivery.TimePeriodDefinition = this.TimePeriod;
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = 6
            };

            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("facebook-[{0}]-[{1}]-[{2}]",
                                                                   this.Instance.AccountID,
                                                                   this.Instance.Configuration.Options[FacebookConfigurationOptions.Account_ID].ToString(),
                                                                   this.Delivery.TimePeriodDefinition.ToAbsolute())),
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd,
                Account         = this.Delivery.Account,
                Channel         = this.Delivery.Channel
            });

            // Now that we have a new delivery, start adding values
            this.Delivery.FileDirectory = Instance.Configuration.Options[Const.DeliveryServiceConfigurationOptions.FileDirectory];

            // Create an import manager that will handle rollback, if necessary
            AdMetricsImportManager importManager = new AdMetricsImportManager(this.Instance.InstanceID, new MetricsImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Metrics.Consts.AppSettings.SqlRollbackCommand]
            });

            // Apply the delivery (will use ConflictBehavior configuration option to abort or rollback if any conflicts occur)
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            if (string.IsNullOrEmpty(this.Delivery.FileDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }

            if (string.IsNullOrEmpty(this.Instance.Configuration.Options[FacebookConfigurationOptions.BaseServiceAddress]))
            {
                throw new Exception("facebook base url must be configured!");
            }
            _baseAddress = new Uri(this.Instance.Configuration.Options[FacebookConfigurationOptions.BaseServiceAddress]);
            //this.ReportProgress(0.2);
            #endregion

            #region Init Delivery Files

            Dictionary <string, string> methodParams = new Dictionary <string, string>();
            string       methodUrl;
            DeliveryFile deliveryFile = new DeliveryFile();

            #region adgroupstats

            deliveryFile.Name = Consts.DeliveryFilesNames.AdGroupStats;
            methodParams.Add(Consts.FacebookMethodsParams.StartTime, ConvertToFacebookDateTime(TimePeriod.Start.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.EndTime, ConvertToFacebookDateTime(TimePeriod.End.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodParams.Add(Consts.FacebookMethodsParams.StatsMode, "with_delivery");
            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroupStats);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Enum.Parse(typeof(Consts.FileTypes), Consts.FileTypes.AdGroupStats.ToString()));
            this.Delivery.Files.Add(deliveryFile);
            #endregion

            //this.ReportProgress(0.4);


            #region Conversions
            //======================================================================================
            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.ConversionsStats;
            methodParams.Add(Consts.FacebookMethodsParams.StartTime, ConvertToFacebookDateTime(TimePeriod.Start.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.EndTime, ConvertToFacebookDateTime(TimePeriod.End.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodParams.Add(Consts.FacebookMethodsParams.StatsMode, "with_delivery");
            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetConversionStats);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Enum.Parse(typeof(Consts.FileTypes), Consts.FileTypes.ConversionsStats.ToString()));
            this.Delivery.Files.Add(deliveryFile);
            //======================================================================================
            #endregion Conversions

            //this.ReportProgress(0.4);
            #region adgroup

            /*
             * Summary
             * An ad group contains the data necessary for an ad, such as bid type, bid info,
             * targeting data, creative elements, and campaign information. Each ad group is
             * associated with a campaign and all ad groups in a campaign have the same daily
             * or lifetime budget and schedule.
             * */

            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.AdGroup;
            methodUrl         = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroups);
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            if (Instance.Configuration.Options.ContainsKey(FacebookConfigurationOptions.AdGroupFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Instance.Configuration.Options[FacebookConfigurationOptions.AdGroupFields].ToString());
            }

            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.AdGroups);

            this.Delivery.Files.Add(deliveryFile);
            #endregion

            //this.ReportProgress(0.6);

            #region AdSet- Formally Campaigns

            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.Campaigns;
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            if (Instance.Configuration.Options.ContainsKey(FacebookConfigurationOptions.CampaignFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Instance.Configuration.Options[FacebookConfigurationOptions.CampaignFields].ToString());
            }

            // methodParams.Add("redownload", "true");

            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetCampaignsAdSets);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.Campaigns);
            this.Delivery.Files.Add(deliveryFile);

            #endregion


            #region Campaigns - New Structure

            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.CampaignGroups;
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            if (Instance.Configuration.Options.ContainsKey(FacebookConfigurationOptions.CampaignGroupsFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Instance.Configuration.Options[FacebookConfigurationOptions.CampaignGroupsFields].ToString());
            }

            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetCampaignsGroups);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.CampaignGroups);
            this.Delivery.Files.Add(deliveryFile);

            #endregion

            #region Creatives
            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.Creatives;
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            if (Instance.Configuration.Options.ContainsKey(FacebookConfigurationOptions.AdGroupCreativeFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Instance.Configuration.Options[FacebookConfigurationOptions.AdGroupCreativeFields].ToString());
            }

            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroupCreatives);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.Creatives);
            this.Delivery.Files.Add(deliveryFile);
            #endregion

            //#region AdGroupTargeting
            //deliveryFile = new DeliveryFile();
            //deliveryFile.Name = Consts.DeliveryFilesNames.AdGroupTargeting;
            //methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroupTargeting);
            //deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            //deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Data);
            //this.Delivery.Files.Add(deliveryFile);

            #endregion


            //this.ReportProgress(0.9);
            this.Delivery.Save();

            this.ReportProgress(1);

            return(ServiceOutcome.Success);
        }
        protected override Core.Services.ServiceOutcome DoPipelineWork()
        {
            string baseAddress;

            #region Init General
            // ...............................
            // SETUP
            this.Delivery = this.NewDelivery();

            // This is for finding conflicting services
            this.Delivery.Signature = Delivery.CreateSignature(String.Format("BackOffice-[{0}]-[{1}]",
                                                                             this.Instance.AccountID,
                                                                             this.TargetPeriod.ToAbsolute()));

            // Create an import manager that will handle rollback, if necessary
            AdMetricsImportManager importManager = new AdMetricsImportManager(this.Instance.InstanceID, new Edge.Data.Pipeline.Common.Importing.ImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Common.Importing.Consts.AppSettings.SqlRollbackCommand]
            });

            // Apply the delivery (will use ConflictBehavior configuration option to abort or rollback if any conflicts occur)
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            // ...............................

            // Now that we have a new delivery, start adding values
            this.Delivery.Account = new Data.Objects.Account()
            {
                ID = this.Instance.AccountID,
            };
            this.Delivery.TargetPeriod = this.TargetPeriod;
            this.Delivery.Channel      = new Data.Objects.Channel()
            {
                ID = -1
            };

            this.Delivery.TargetLocationDirectory = Instance.Configuration.Options["DeliveryFilesDir"];

            if (string.IsNullOrEmpty(this.Delivery.TargetLocationDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }

            if (string.IsNullOrEmpty(this.Instance.Configuration.Options[BoConfigurationOptions.BaseServiceAddress]))
            {
                throw new Exception("base url must be configured!");
            }
            baseAddress = this.Instance.Configuration.Options[BoConfigurationOptions.BaseServiceAddress];

            if (string.IsNullOrEmpty(this.Instance.Configuration.Options[BoConfigurationOptions.UserName]))
            {
                throw new Exception("base url must be configured!");
            }
            this.Delivery.Parameters["UserName"] = this.Instance.Configuration.Options[BoConfigurationOptions.UserName];

            if (string.IsNullOrEmpty(this.Instance.Configuration.Options[BoConfigurationOptions.Password]))
            {
                throw new Exception("base url must be configured!");
            }
            this.Delivery.Parameters["Password"] = this.Instance.Configuration.Options[BoConfigurationOptions.Password];

            int utcOffset = 0;
            if (!string.IsNullOrEmpty(this.Instance.Configuration.Options[BoConfigurationOptions.UtcOffset]))
            {
                utcOffset = int.Parse(this.Instance.Configuration.Options[BoConfigurationOptions.UtcOffset]);
            }


            this.ReportProgress(0.2);
            #endregion

            #region DeliveryFile
            Dictionary <string, string> UrlParams = new Dictionary <string, string>();
            DeliveryFile boFile = new DeliveryFile();
            boFile.Parameters[BoConfigurationOptions.BO_XPath_Trackers] = Instance.Configuration.Options[BoConfigurationOptions.BO_XPath_Trackers];
            boFile.Name = BoConfigurationOptions.BoFileName;
            UrlParams.Add("from", utcOffset == 0 ? Delivery.TargetPeriod.Start.ToDateTime().ToString("yyyy-MM-ddTHH:MMZ") : ConvertToTimeZone(utcOffset, TargetPeriod.Start.ToDateTime()));
            UrlParams.Add("to", utcOffset == 0 ? Delivery.TargetPeriod.End.ToDateTime().ToString("yyyy-MM-ddTHH:MMZ") : ConvertToTimeZone(utcOffset, TargetPeriod.Start.ToDateTime()));
            UrlParams.Add("vendor", this.Delivery.Parameters["UserName"].ToString());
            UrlParams.Add("Password", this.Delivery.Parameters["Password"].ToString());
            boFile.SourceUrl = CreateUrl(UrlParams, baseAddress.ToString());

            this.Delivery.Files.Add(boFile);
            this.Delivery.Save();


            #endregion
            return(Core.Services.ServiceOutcome.Success);
        }
        protected override ServiceOutcome DoPipelineWork()
        {
            this.Delivery = this.NewDelivery(); // setup delivery


            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["FilterDeleted"]))
            {
                throw new Exception("Missing Configuration Param , FilterDeleted");
            }
            this.Delivery.Parameters["FilterDeleted"] = this.Instance.Configuration.Options["FilterDeleted"];

            if (this.Instance.Configuration.Options.ContainsKey("AppendSitelinks"))
            {
                this.Delivery.Parameters.Add("AppendSitelinks", this.Instance.Configuration.Options["AppendSitelinks"]);
            }

            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["KeywordContentId"]))
            {
                throw new Exception("Missing Configuration Param , KeywordContentId");
            }

            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["Adwords.MccEmail"]))
            {
                throw new Exception("Missing Configuration Param , Adwords.MccEmail");
            }

            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["Adwords.ClientID"]))
            {
                throw new Exception("Missing Configuration Param , Adwords.ClientID");
            }


            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["SubChannelName"]))
            {
                throw new Exception("Missing Configuration Param , SubChannelName");
            }


            //checking for conflicts
            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("{4}-[{0}]-[{1}]-[{2}]-[{3}]",//-[{4}]",//EdgeAccountID , MCC Email ,AdwordsClientID , TimePeriod
                                                                   this.Instance.AccountID,
                                                                   this.Instance.Configuration.Options["Adwords.MccEmail"].ToString(),
                                                                   this.Instance.Configuration.Options["Adwords.ClientID"].ToString(),
                                                                   this.TimePeriod.ToAbsolute(),
                                                                   this.Instance.Configuration.Options["SubChannelName"].ToString()
                                                                   )),
                Account = new Data.Objects.Account()
                {
                    ID = this.Instance.AccountID, OriginalID = this.Instance.Configuration.Options["Adwords.ClientID"]
                },
                Channel = new Data.Objects.Channel()
                {
                    ID = 1
                },
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            }
                                      );

            this.Delivery.FileDirectory = Instance.Configuration.Options[Edge.Data.Pipeline.Services.Const.DeliveryServiceConfigurationOptions.FileDirectory];
            if (string.IsNullOrEmpty(this.Delivery.FileDirectory))
            {
                throw new Exception("Delivery FileDirectory must be configured in configuration file (DeliveryFilesDir)");
            }
            this.Delivery.TimePeriodDefinition = this.TimePeriod;
            this.Delivery.Account = new Edge.Data.Objects.Account()
            {
                ID = this.Instance.AccountID, OriginalID = this.Instance.Configuration.Options["Adwords.ClientID"]
            };
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = 1
            };


            // Create an import manager that will handle rollback, if necessary
            AdMetricsImportManager importManager = new AdMetricsImportManager(this.Instance.InstanceID, new MetricsImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Consts.AppSettings.SqlRollbackCommand]
            });

            // will use ConflictBehavior configuration option to abort or rollback if any conflicts occur
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            #region Must Have Params
            this.Delivery.Parameters["IncludeStatus"] = this.Instance.Configuration.Options["IncludeStatus"];


            //Get MCC Paramerters
            this.Delivery.Parameters["DeveloperToken"] = this.Instance.Configuration.Options["DeveloperToken"];
            this.Delivery.Parameters["MccEmail"]       = this.Instance.Configuration.Options["Adwords.MccEmail"];
            //this.Delivery.Parameters["MccPass"] = Core.Utilities.Encryptor.Dec(this.Instance.Configuration.Options["Adwords.MccPass"].ToString());
            this.Delivery.Parameters["KeywordContentId"] = this.Instance.Configuration.Options["KeywordContentId"];

            // Get Report types
            string[] reportTypeNames = this.Instance.Configuration.Options["Adwords.ReportType"].Split('|');
            List <GA.ReportDefinitionReportType> reportTypes = new List <GA.ReportDefinitionReportType>();
            foreach (string reportTypeName in reportTypeNames)
            {
                if (Enum.IsDefined(typeof(GA.ReportDefinitionReportType), reportTypeName))
                {
                    reportTypes.Add((GA.ReportDefinitionReportType)Enum.Parse(typeof(GA.ReportDefinitionReportType), reportTypeName, true));
                }
                else
                {
                    throw new Exception("Undefined Google Adwords ReportType");
                }
            }
            this.Delivery.Parameters["reportTypes"] = reportTypes;

            //Get Account Client Id's
            string[] adwordsClientIds = this.Instance.Configuration.Options["Adwords.ClientID"].Split('|');
            this.Delivery.Parameters["AdwordsClientIDs"] = adwordsClientIds;

            #endregion

            #region Nice to have params

            //Check for includeZeroImpression
            string includeZeroImpression;
            if (!String.IsNullOrEmpty(includeZeroImpression = Instance.Configuration.Options["includeZeroImpression"]))
            {
                this.Delivery.Parameters["includeZeroImpression"] = includeZeroImpression;
            }
            else
            {
                this.Delivery.Parameters["includeZeroImpression"] = false;
            }

            //Check for includeConversionTypes
            string includeConversionTypes;
            if (!String.IsNullOrEmpty(includeConversionTypes = Instance.Configuration.Options["includeConversionTypes"]))
            {
                this.Delivery.Parameters["includeConversionTypes"] = includeConversionTypes;
            }
            else
            {
                this.Delivery.Parameters["includeConversionTypes"] = false; // deafult
            }
            //Check for includeDisplaytData
            string includeDisplaytData;
            if (!String.IsNullOrEmpty(includeDisplaytData = Instance.Configuration.Options["includeDisplaytData"]))
            {
                this.Delivery.Parameters["includeDisplaytData"] = includeDisplaytData;
            }
            else
            {
                this.Delivery.Parameters["includeDisplaytData"] = false; // deafult
            }
            #endregion

            //Creating Delivery files Per Client ID
            foreach (string clientId in adwordsClientIds)
            {
                foreach (GA.ReportDefinitionReportType reportType in (List <GA.ReportDefinitionReportType>) this.Delivery.Parameters["reportTypes"])
                {
                    DeliveryFile file = new DeliveryFile();
                    file.Name = GoogleStaticReportsNamesUtill._reportNames[reportType];
                    file.Parameters.Add("ReportType", reportType.ToString());
                    file.Parameters.Add("ReportFieldsType", ReportDefinitionReportFieldsType.DEFAULT);
                    file.Parameters.Add("AdwordsClientID", clientId);
                    this.Delivery.Files.Add(file);


                    //Handelling conversion
                    if (Boolean.Parse(this.Delivery.Parameters["includeConversionTypes"].ToString())) // if AD Performance With conversion type is required
                    {
                        bool         addFile        = true;
                        DeliveryFile conversionFile = new DeliveryFile();
                        conversionFile.Name = GoogleStaticReportsNamesUtill._reportNames[reportType] + "_Conv";
                        switch (reportType)
                        {
                        case GA.ReportDefinitionReportType.AD_PERFORMANCE_REPORT:
                            conversionFile.Parameters.Add("ReportType", GA.ReportDefinitionReportType.AD_PERFORMANCE_REPORT.ToString());
                            break;

                        case GA.ReportDefinitionReportType.AUTOMATIC_PLACEMENTS_PERFORMANCE_REPORT:
                            conversionFile.Parameters.Add("ReportType", GA.ReportDefinitionReportType.AUTOMATIC_PLACEMENTS_PERFORMANCE_REPORT.ToString());
                            break;

                        default: addFile = false; break;
                        }

                        if (addFile)
                        {
                            conversionFile.Parameters.Add("ReportFieldsType", ReportDefinitionReportFieldsType.CONVERSION);
                            conversionFile.Parameters.Add("AdwordsClientID", clientId);
                            this.Delivery.Files.Add(conversionFile);
                        }
                    }

                    //Add Status Reports
                    DeliveryFile AD_Camp_Adgroups_StatusFile = new DeliveryFile();
                    AD_Camp_Adgroups_StatusFile.Parameters.Add("ReportType", GA.ReportDefinitionReportType.AD_PERFORMANCE_REPORT.ToString());
                }

                if (Boolean.Parse(this.Delivery.Parameters["includeDisplaytData"].ToString())) // if AD Performance With conversion type is required
                {
                    DeliveryFile file = new DeliveryFile();
                    file.Name = GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.PLACEMENT_PERFORMANCE_REPORT];
                    file.Parameters.Add("ReportType", GA.ReportDefinitionReportType.PLACEMENT_PERFORMANCE_REPORT.ToString());
                    file.Parameters.Add("ReportFieldsType", ReportDefinitionReportFieldsType.DEFAULT);
                    file.Parameters.Add("AdwordsClientID", clientId);
                    this.Delivery.Files.Add(file);
                }

                #region Sitelinks

                if (this.Delivery.Parameters.ContainsKey("AppendSitelinks"))
                {
                    if (Boolean.Parse(this.Delivery.Parameters["AppendSitelinks"].ToString()))
                    {
                        DeliveryFile siteLinkFile = new DeliveryFile();
                        siteLinkFile.Name = GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.PLACEHOLDER_FEED_ITEM_REPORT];
                        siteLinkFile.Parameters.Add("ReportType", GA.ReportDefinitionReportType.PLACEHOLDER_FEED_ITEM_REPORT.ToString());
                        siteLinkFile.Parameters.Add("ReportFieldsType", ReportDefinitionReportFieldsType.DEFAULT);
                        siteLinkFile.Parameters.Add("AdwordsClientID", clientId);
                        this.Delivery.Files.Add(siteLinkFile);
                    }
                }

                #endregion


                #region Status Reports
                if (Boolean.Parse(this.Delivery.Parameters["IncludeStatus"].ToString())) // if AD Performance With conversion type is required
                {
                    //1. create file for **** Ad performance with status
                    DeliveryFile adPerformaceStatusfile = new DeliveryFile();
                    adPerformaceStatusfile.Name = GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.AD_PERFORMANCE_REPORT] + "_Status";
                    adPerformaceStatusfile.Parameters.Add("ReportType", GA.ReportDefinitionReportType.AD_PERFORMANCE_REPORT.ToString());
                    adPerformaceStatusfile.Parameters.Add("ReportFieldsType", ReportDefinitionReportFieldsType.STATUS);
                    adPerformaceStatusfile.Parameters.Add("AdwordsClientID", clientId);
                    this.Delivery.Files.Add(adPerformaceStatusfile);

                    //2. create file for **** KWD performance with status
                    DeliveryFile kwdPerformaceStatusfile = new DeliveryFile();
                    kwdPerformaceStatusfile.Name = GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.KEYWORDS_PERFORMANCE_REPORT] + "_Status";
                    kwdPerformaceStatusfile.Parameters.Add("ReportType", GA.ReportDefinitionReportType.KEYWORDS_PERFORMANCE_REPORT.ToString());
                    kwdPerformaceStatusfile.Parameters.Add("ReportFieldsType", ReportDefinitionReportFieldsType.STATUS);
                    kwdPerformaceStatusfile.Parameters.Add("AdwordsClientID", clientId);
                    this.Delivery.Files.Add(kwdPerformaceStatusfile);

                    //3. create file for **** Managed performance with status
                    DeliveryFile ManagedGDNStatusfile = new DeliveryFile();
                    ManagedGDNStatusfile.Name = GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.PLACEMENT_PERFORMANCE_REPORT] + "_Status";
                    ManagedGDNStatusfile.Parameters.Add("ReportType", GA.ReportDefinitionReportType.PLACEMENT_PERFORMANCE_REPORT.ToString());
                    ManagedGDNStatusfile.Parameters.Add("ReportFieldsType", ReportDefinitionReportFieldsType.STATUS);
                    ManagedGDNStatusfile.Parameters.Add("AdwordsClientID", clientId);
                    this.Delivery.Files.Add(ManagedGDNStatusfile);
                }
                #endregion
            }
            this.Delivery.Save();
            return(Core.Services.ServiceOutcome.Success);
        }
Exemplo n.º 7
0
        protected override ServiceOutcome DoPipelineWork()
        {
            #region Init General
            if (!Configuration.TimePeriod.HasValue)
            {
                throw new Exception("No time period is set for Service");
            }

            if (!Configuration.Parameters.ContainsKey("AccountID"))
            {
                throw new Exception("Missing Configuration Param: AccountID");
            }

            if (!Configuration.Parameters.ContainsKey(FacebookConfigurationOptions.Account_ID))
            {
                throw new Exception(String.Format("Missing Configuration Param: {0}", FacebookConfigurationOptions.Account_ID));
            }

            if (!Configuration.Parameters.ContainsKey(Const.DeliveryServiceConfigurationOptions.FileDirectory))
            {
                throw new Exception(String.Format("Missing Configuration Param: {0}", Const.DeliveryServiceConfigurationOptions.FileDirectory));
            }

            if (!Configuration.Parameters.ContainsKey(FacebookConfigurationOptions.BaseServiceAddress))
            {
                throw new Exception(String.Format("Missing Configuration Param: {0}", FacebookConfigurationOptions.BaseServiceAddress));
            }

            var accountId         = Configuration.Parameters.Get("AccountID", false, -1);
            var channelId         = Configuration.Parameters.Get("ChannelID", false, -1);
            var facebookAccountId = Configuration.Parameters.Get <string>(FacebookConfigurationOptions.Account_ID);

            Delivery         = NewDelivery();
            Delivery.Account = new Account {
                ID = accountId
            };
            //{
            //	ID = this.AccountID,
            //	OriginalID = this.Instance.Configuration.Options[FacebookConfigurationOptions.Account_ID].ToString()
            //};
            Delivery.Channel = new Channel {
                ID = channelId
            };
            Delivery.TimePeriodDefinition = Configuration.TimePeriod.Value;
            Delivery.FileDirectory        = Configuration.Parameters.Get <string>(Const.DeliveryServiceConfigurationOptions.FileDirectory);

            Delivery.Outputs.Add(new DeliveryOutput
            {
                Signature = Delivery.CreateSignature(String.Format("facebook-[{0}]-[{1}]-[{2}]",
                                                                   accountId,
                                                                   facebookAccountId,
                                                                   Delivery.TimePeriodDefinition.ToAbsolute())),
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd,
                Account         = Delivery.Account,
                Channel         = Delivery.Channel
            });

            // Create an import manager that will handle rollback, if necessary
            HandleConflicts(new MetricsDeliveryManager(InstanceID), DeliveryConflictBehavior.Abort);

            _baseAddress = new Uri(Configuration.Parameters.Get <string>(FacebookConfigurationOptions.BaseServiceAddress));
            Progress     = 0.2;
            #endregion

            #region Init Delivery Files

            var    methodParams = new Dictionary <string, string>();
            var    deliveryFile = new DeliveryFile();
            string methodUrl;

            #region AdGroupStats

            deliveryFile.Name = Consts.DeliveryFilesNames.AdGroupStats;
            methodParams.Add(Consts.FacebookMethodsParams.StartTime, ConvertToFacebookDateTime(Delivery.TimePeriodDefinition.Start.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.EndTime, ConvertToFacebookDateTime(Delivery.TimePeriodDefinition.End.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodParams.Add(Consts.FacebookMethodsParams.StatsMode, "with_delivery");
            methodUrl = string.Format("act_{0}/{1}", facebookAccountId, Consts.FacebookMethodsNames.GetAdGroupStats);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Enum.Parse(typeof(Consts.FileTypes), Consts.FileTypes.AdGroupStats.ToString()));
            Delivery.Files.Add(deliveryFile);

            Progress = 0.4;
            #endregion

            #region AdGroup

            deliveryFile = new DeliveryFile {
                Name = Consts.DeliveryFilesNames.AdGroup
            };
            methodUrl = string.Format("act_{0}/{1}", facebookAccountId, Consts.FacebookMethodsNames.GetAdGroups);
            if (Configuration.Parameters.ContainsKey(FacebookConfigurationOptions.AdGroupFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Configuration.Parameters.Get <string>(FacebookConfigurationOptions.AdGroupFields));
            }

            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.AdGroups);
            Delivery.Files.Add(deliveryFile);

            Progress = 0.6;
            #endregion

            #region Campaigns
            deliveryFile = new DeliveryFile {
                Name = Consts.DeliveryFilesNames.Campaigns
            };
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            if (Configuration.Parameters.ContainsKey(FacebookConfigurationOptions.CampaignFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Configuration.Parameters.Get <string>(FacebookConfigurationOptions.CampaignFields));
            }

            methodUrl = string.Format("act_{0}/{1}", facebookAccountId, Consts.FacebookMethodsNames.GetCampaigns);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.Campaigns);
            Delivery.Files.Add(deliveryFile);

            Progress = 0.7;
            #endregion

            #region Creatives
            deliveryFile = new DeliveryFile {
                Name = Consts.DeliveryFilesNames.Creatives
            };
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            if (Configuration.Parameters.ContainsKey(FacebookConfigurationOptions.AdGroupCreativeFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Configuration.Parameters.Get <string>(FacebookConfigurationOptions.AdGroupCreativeFields));
            }

            methodUrl = string.Format("act_{0}/{1}", facebookAccountId, Consts.FacebookMethodsNames.GetAdGroupCreatives);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.Creatives);
            Delivery.Files.Add(deliveryFile);
            #endregion

            Progress = 0.9;
            #endregion

            Delivery.Save();
            return(ServiceOutcome.Success);
        }
        protected override ServiceOutcome DoPipelineWork()
        {
            this.Delivery = this.NewDelivery();             // setup delivery

            //Get Ftp Url
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["FtpServer"]))
            {
                throw new Exception("Missing Configuration Param , FtpServer");
            }
            string FtpServer = this.Instance.Configuration.Options["FtpServer"];


            //Get AllowedExtensions
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["AllowedExtensions"]))
            {
                throw new Exception("Missing Configuration Param , AllowedExtensions");
            }
            string[] AllowedExtensions = this.Instance.Configuration.Options["AllowedExtensions"].Split('|');

            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["UsePassive"]))
            {
                throw new Exception("Missing Configuration Param , UsePassive");
            }
            this.Delivery.Parameters.Add("UsePassive", bool.Parse(this.Instance.Configuration.Options["UsePassive"]));

            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["UseBinary"]))
            {
                throw new Exception("Missing Configuration Param , UsePassive");
            }
            this.Delivery.Parameters.Add("UseBinary", bool.Parse(this.Instance.Configuration.Options["UseBinary"]));

            //Get Permissions
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["UserID"]))
            {
                throw new Exception("Missing Configuration Param , UserID");
            }
            string UserId = this.Instance.Configuration.Options["UserID"];


            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["Password"]))
            {
                throw new Exception("Missing Configuration Param , Password");
            }
            string Password = Core.Utilities.Encryptor.Dec(this.Instance.Configuration.Options["Password"]);


            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["DirectoryWatcherLocation"]))
            {
                throw new Exception("Missing Configuration Param , DirectoryWatcherLocation");
            }



            this.Delivery.TargetLocationDirectory = Instance.Configuration.Options["DeliveryFilesDir"];
            if (string.IsNullOrEmpty(this.Delivery.TargetLocationDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }
            this.Delivery.TargetPeriod = this.TargetPeriod;
            this.Delivery.Account      = new Edge.Data.Objects.Account()
            {
                ID = this.Instance.AccountID,
            };
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = 9999
            };

            this.Delivery.Signature = Delivery.CreateSignature(String.Format("FTP-[{0}]-[{1}]-[{2}]]",
                                                                             this.Instance.AccountID, this.Delivery.Channel.ToString(), this.TargetPeriod.ToAbsolute()));

            //Getting files in ftp directory
            FtpWebRequest request;
            List <string> files = new List <string>();

            try
            {
                request             = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpServer + "/"));
                request.UseBinary   = (bool)this.Delivery.Parameters["UseBinary"];
                request.UsePassive  = (bool)this.Delivery.Parameters["UsePassive"];
                request.Credentials = new NetworkCredential(UserId, Password);
                request.Method      = WebRequestMethods.Ftp.ListDirectory;

                //WebResponse response = request.GetResponse();
                FtpWebResponse response       = (FtpWebResponse)request.GetResponse();
                StreamReader   reader         = new StreamReader(response.GetResponseStream());
                string         file           = reader.ReadLine();
                bool           ExtensionsFlag = false;

                while (file != null)
                {
                    //Checking AllowedExtensions
                    string[] fileExtension = file.Split('.');
                    foreach (string item in AllowedExtensions)
                    {
                        if (fileExtension[fileExtension.Length - 1].ToLower().Equals(item.ToLower()))
                        {
                            continue;
                        }
                        ExtensionsFlag = true;
                    }
                    if (!ExtensionsFlag)
                    {
                        files.Add(file);                                      //Get only matched extension files
                    }
                    file = reader.ReadLine();
                }
                reader.Close();
                response.Close();

                if (files.Count == 0)
                {
                    Core.Utilities.Log.Write("No files in FTP directory for account id " + this.Instance.AccountID.ToString(), Core.Utilities.LogMessageType.Information);
                }
                else
                {
                    //creating Delivery File foreach file in ftp
                    foreach (string fileName in files)
                    {
                        FtpWebRequest sizeRequest;
                        sizeRequest             = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpServer + "/" + fileName));
                        sizeRequest.Credentials = new NetworkCredential(UserId, Password);
                        sizeRequest.Method      = WebRequestMethods.Ftp.GetFileSize;
                        FtpWebResponse sizeResponse = (FtpWebResponse)sizeRequest.GetResponse();
                        long           size         = sizeResponse.ContentLength;

                        this.Delivery.Files.Add(new Data.Pipeline.DeliveryFile()
                        {
                            Name      = "FTP_" + fileName,
                            SourceUrl = FtpServer + "/" + fileName,
                        }
                                                );

                        this.Delivery.Files["FTP_" + fileName].Parameters.Add("Size", size);
                        sizeResponse.Close();
                    }
                }
            }
            catch (Exception e)
            {
                Core.Utilities.Log.Write(
                    string.Format("Cannot connect FTP server for account ID:{0}  Exception: {1}",
                                  this.Instance.AccountID.ToString(), e.Message),
                    Core.Utilities.LogMessageType.Information);
                return(ServiceOutcome.Failure);
            }



            this.Delivery.Parameters["FtpServer"]                = FtpServer;
            this.Delivery.Parameters["AllowedExtensions"]        = AllowedExtensions;
            this.Delivery.Parameters["UserID"]                   = UserId;
            this.Delivery.Parameters["Password"]                 = Password;
            this.Delivery.Parameters["DirectoryWatcherLocation"] = this.Instance.Configuration.Options["DirectoryWatcherLocation"];
            this.Delivery.Save();
            return(Core.Services.ServiceOutcome.Success);
        }
Exemplo n.º 9
0
        protected override Core.Services.ServiceOutcome DoPipelineWork()
        {
            #region Init General
            // ...............................
            // SETUP
            this.Delivery = this.NewDelivery();

            this.Delivery.Account = new Data.Objects.Account()
            {
                ID = this.Instance.AccountID,
            };
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = -1
            };

            this.Delivery.TimePeriodDefinition = this.TimePeriod;

            this.Delivery.FileDirectory = Instance.Configuration.Options[Const.DeliveryServiceConfigurationOptions.FileDirectory];

            if (string.IsNullOrEmpty(this.Delivery.FileDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }

            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("BackOffice-[{0}]-[{1}]",
                                                                   this.Instance.AccountID,
                                                                   this.TimePeriod.ToAbsolute())),
                Account         = Delivery.Account,
                Channel         = Delivery.Channel,
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            });

            // Create an import manager that will handle rollback, if necessary
            var importManager = new GenericMetricsImportManager(this.Instance.InstanceID, new Edge.Data.Pipeline.Common.Importing.MetricsImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Metrics.Consts.AppSettings.SqlRollbackCommand]
            });


            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            this.ReportProgress(0.2);
            #endregion

            //Create File

            DeliveryFile _file = new DeliveryFile()
            {
                Name = "EasyForexBackOffice",
            };

            _file.SourceUrl = Instance.Configuration.Options["SourceUrl"];            // "https://classic.easy-forex.com/BackOffice/API/Marketing.asmx";
            //_file.Parameters.Add("SOAPAction", "http://www.easy-forex.com/GetGatewayStatistics");
            _file.Parameters.Add("Content-Type", "text/xml; charset=utf-8");
            _file.Parameters.Add("SOAPAction", Instance.Configuration.Options["SOAPAction"]);

            Delivery.Parameters.Add("User", Instance.Configuration.Options["User"]);
            Delivery.Parameters.Add("Pass", Core.Utilities.Encryptor.Dec(Instance.Configuration.Options["Pass"].ToString()));
            Delivery.Parameters.Add("SoapMethod", Instance.Configuration.Options["SoapMethod"]);
            Delivery.Parameters.Add("StartGid", Instance.Configuration.Options["StartGid"]);
            Delivery.Parameters.Add("EndGid", Instance.Configuration.Options["EndGid"]);


            //Creating  Soap Body
            string strSoapEnvelope = GetSoapEnvelope(
                Delivery.Parameters["User"].ToString(),
                Delivery.Parameters["Pass"].ToString(),
                Delivery.Parameters["SoapMethod"].ToString(),
                Delivery.Parameters["StartGid"].ToString(),
                Delivery.Parameters["EndGid"].ToString(),
                this.Delivery.TimePeriodStart.ToString("yyyy-MM-ddTHH:mm:ss"),
                this.Delivery.TimePeriodEnd.ToString("yyyy-MM-ddTHH:mm:ss.fffffff")
                );

            #region Soap 1.2
            //strSoapEnvelope += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
            //strSoapEnvelope += "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">";
            //strSoapEnvelope += " <soap12:Header>";
            //strSoapEnvelope += " <AuthHeader xmlns=\"http://www.easy-forex.com\">";
            //strSoapEnvelope += "  <Username>Seperia</Username>";
            //strSoapEnvelope += "  <Password>Seperia909</Password>";
            //strSoapEnvelope += "  </AuthHeader>";
            //strSoapEnvelope += " </soap12:Header>";
            //strSoapEnvelope += " <soap12:Body>";
            //strSoapEnvelope += "<GetGatewayStatistics xmlns=\"http://www.easy-forex.com\">";
            //strSoapEnvelope += " <startGid>1</startGid>";
            //strSoapEnvelope += " <finishGid>1000000</finishGid>";
            //strSoapEnvelope += string.Format(" <fromDateTime>{0}</fromDateTime>", _requiredDay);
            //strSoapEnvelope += string.Format(" <toDateTime>{0}</toDateTime>", _requiredDay.AddDays(1).AddTicks(-1));
            //strSoapEnvelope += "  </GetGatewayStatistics>";
            //strSoapEnvelope += "</soap12:Body>";
            //strSoapEnvelope += "</soap12:Envelope>";
            #endregion
            _file.Parameters.Add("Body", strSoapEnvelope);
            _file.Parameters.Add("Bo.IsAttribute", Instance.Configuration.Options["Bo.IsAttribute"]);
            _file.Parameters.Add("Bo.Xpath", Instance.Configuration.Options["Bo.Xpath"]);
            _file.Parameters.Add("Bo.TrackerIDField", Instance.Configuration.Options["Bo.TrackerIDField"]);

            this.Delivery.Files.Add(_file);

            // Save with success
            this.Delivery.Save();

            return(ServiceOutcome.Success);
        }
Exemplo n.º 10
0
        protected override ServiceOutcome DoPipelineWork()
        {
            if (!Configuration.TimePeriod.HasValue)
            {
                throw new Exception("No time period is set for Service");
            }

            if (!Configuration.Parameters.ContainsKey("AccountID"))
            {
                throw new Exception("Missing Configuration Param: AccountID");
            }

            var accountId = Configuration.Parameters.Get("AccountID", false, -1);
            var channelId = Configuration.Parameters.Get("ChannelID", false, -1);

            // create delivery
            if (Delivery == null)
            {
                Delivery = NewDelivery();
                Delivery.TimePeriodDefinition = Configuration.TimePeriod.Value;
                Delivery.Account = new Account {
                    ID = accountId
                };
                Delivery.FileDirectory = Configuration.Parameters.Get <string>(Const.DeliveryServiceConfigurationOptions.FileDirectory);
                if (channelId != -1)
                {
                    Delivery.Channel = new Channel {
                        ID = channelId
                    }
                }
                ;
            }

            if (string.IsNullOrEmpty(Delivery.FileDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }

            // delivery output
            Delivery.Outputs.Add(new DeliveryOutput
            {
                Signature = Delivery.CreateSignature(String.Format("BackOffice-[{0}]-[{1}]",
                                                                   Delivery.Account.ID,
                                                                   Delivery.TimePeriodDefinition.ToAbsolute())),
                Account         = Delivery.Account,
                Channel         = Delivery.Channel,
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            });

            Progress = 0.2;

            // Create an import manager that will handle rollback, if necessary
            HandleConflicts(new MetricsDeliveryManager(InstanceID), DeliveryConflictBehavior.Abort);

            Progress = 0.5;

            //Create File
            var file = new DeliveryFile
            {
                Name      = "EasyForexBackOffice",
                SourceUrl = Configuration.Parameters.Get <string>("SourceUrl")
            };

            //_file.Parameters.Add("SOAPAction", "http://www.easy-forex.com/GetGatewayStatistics");
            file.Parameters.Add("Content-Type", "text/xml; charset=utf-8");
            file.Parameters.Add("SOAPAction", Configuration.Parameters["SOAPAction"]);

            Delivery.Parameters.Add("User", Configuration.Parameters["User"]);
            Delivery.Parameters.Add("Pass", Core.Utilities.Encryptor.Dec(Configuration.Parameters["Pass"].ToString()));
            Delivery.Parameters.Add("SoapMethod", Configuration.Parameters["SoapMethod"]);
            Delivery.Parameters.Add("StartGid", Configuration.Parameters["StartGid"]);
            Delivery.Parameters.Add("EndGid", Configuration.Parameters["EndGid"]);

            //Creating  Soap Body
            var strSoapEnvelope = GetSoapEnvelope(
                Delivery.Parameters["User"].ToString(),
                Delivery.Parameters["Pass"].ToString(),
                Delivery.Parameters["SoapMethod"].ToString(),
                Delivery.Parameters["StartGid"].ToString(),
                Delivery.Parameters["EndGid"].ToString(),
                Delivery.TimePeriodStart.ToString("yyyy-MM-ddTHH:mm:ss"),
                Delivery.TimePeriodEnd.ToString("yyyy-MM-ddTHH:mm:ss.fffffff")
                );

            file.Parameters.Add("Body", strSoapEnvelope);
            file.Parameters.Add("Bo.IsAttribute", Configuration.Parameters["Bo.IsAttribute"]);
            file.Parameters.Add("Bo.Xpath", Configuration.Parameters["Bo.Xpath"]);
            file.Parameters.Add("Bo.TrackerIDField", Configuration.Parameters["Bo.TrackerIDField"]);

            Delivery.Files.Add(file);

            Progress = 0.8;

            // Save with success
            Delivery.Save();
            return(ServiceOutcome.Success);
        }
Exemplo n.º 11
0
        protected override ServiceOutcome DoPipelineWork()
        {
            #region Init General
            // ...............................
            // SETUP
            this.Delivery = NewDelivery();
            // This is for finding conflicting services
            this.Delivery.Account = new Data.Objects.Account()
            {
                ID         = this.Instance.AccountID,
                OriginalID = this.Instance.Configuration.Options[FacebookConfigurationOptions.Account_ID].ToString()
            };
            this.Delivery.TimePeriodDefinition = this.TimePeriod;
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = 6
            };

            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("facebook-[{0}]-[{1}]-[{2}]",
                                                                   this.Instance.AccountID,
                                                                   this.Instance.Configuration.Options[FacebookConfigurationOptions.Account_ID].ToString(),
                                                                   this.Delivery.TimePeriodDefinition.ToAbsolute())),
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd,
                Account         = this.Delivery.Account,
                Channel         = this.Delivery.Channel
            });

            // Now that we have a new delivery, start adding values
            this.Delivery.FileDirectory = Instance.Configuration.Options[Const.DeliveryServiceConfigurationOptions.FileDirectory];

            // Create an import manager that will handle rollback, if necessary
            AdMetricsImportManager importManager = new AdMetricsImportManager(this.Instance.InstanceID, new MetricsImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Metrics.Consts.AppSettings.SqlRollbackCommand]
            });

            // Apply the delivery (will use ConflictBehavior configuration option to abort or rollback if any conflicts occur)
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            if (string.IsNullOrEmpty(this.Delivery.FileDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }

            if (string.IsNullOrEmpty(this.Instance.Configuration.Options[FacebookConfigurationOptions.BaseServiceAddress]))
            {
                throw new Exception("facebook base url must be configured!");
            }
            _baseAddress = new Uri(this.Instance.Configuration.Options[FacebookConfigurationOptions.BaseServiceAddress]);

            if (string.IsNullOrEmpty(this.Instance.Configuration.Options["API_Purchases_Field_Name"]))
            {
                throw new Exception("facebook 'API_Purchases_Field_Name' must be configured!");
            }

            this.Delivery.Parameters.Add("API_Purchases_Field_Name", this.Instance.Configuration.Options["API_Purchases_Field_Name"]);


            #endregion

            #region Init Delivery Files

            Dictionary <string, string> methodParams = new Dictionary <string, string>();
            string       methodUrl;
            DeliveryFile deliveryFile = new DeliveryFile();

            #region adgroupstats

            deliveryFile.Name = Consts.DeliveryFilesNames.AdGroupStats;
            methodParams.Add(Consts.FacebookMethodsParams.StartTime, ConvertToFacebookDateTime(TimePeriod.Start.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.EndTime, ConvertToFacebookDateTime(TimePeriod.End.ToDateTime()));
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodParams.Add(Consts.FacebookMethodsParams.AdgroupStatus, "[%27ARCHIVED%27,%27ACTIVE%27,%27PAUSED%27]");
            methodParams.Add(Consts.FacebookMethodsParams.StatsMode, "with_delivery");
            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroupStats);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Enum.Parse(typeof(Consts.FileTypes), Consts.FileTypes.AdGroupStats.ToString()));
            this.Delivery.Files.Add(deliveryFile);

            #endregion

            //this.ReportProgress(0.4);


            #region Creating report stats for conversion data
            ///<summary>
            ///27.10.2014
            ///
            ///Ad Report Stats provides Ads API to fetch statistics at the adaccount level. You can query data per ad account,
            ///campaigns or ads. One query will always return data for one ad account only.
            ///The API is very generic and enables you to fetch data for arbitrary time ranges. You can group the data by 1-90 days, monthly or all days.
            ///You can break down the data by gender, age, placement or country. You can filter by specific values (spend > 100) and sort by most columns.
            ///By default the API returns data for all ads/campaigns that had delivery during given time range. That means you don't need to set any status
            ///filters to display ARCHIVED and DELETED adgroups/campaigns, as they are all included as far as they have delivery.
            ///method=post&async=true
            /// data_columns=['campaign_group_id','campaign_id','adgroup_id','actions']
            /// time_ranges=[{'day_start':{'day':1,'month':8,'year':2014},'day_stop':{'day':2,'month':8,'year':2014}}]
            /// access_token=CAACZAMUPZCAd0BAK5eHzaiDVgvM0tGaP8b2EPpxpzj5upCkKThsfH5eUf8TLGpsmQVHpoKbTahNBE5AcJ3XkVu0hun4Woi7ZCx5lx560FBSmfUkGOOBh7eOVbZBLsAeAfs5ojZBeiXWJkpYNF2OksZCv7qk0OYZCQ6u0xA4TgOQSMQUJRqPM0oSrJg2zJaXTO0ZD&method=post&async=true&actions_group_by=['action_type']
            ///</summary>


            //getting conversion report Id from facebook
            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetReportStats);
            methodParams.Add("time_ranges", ConvertToFacebookDateTime(TimePeriod.Start.ToDateTime(), datetimeRangeFormat: true));
            methodParams.Add("data_columns", "[%27campaign_group_id%27,%27campaign_id%27,%27adgroup_id%27,%27actions%27]");
            methodParams.Add("method", "post");
            methodParams.Add("async", "true");
            methodParams.Add("actions_group_by", "['action_type']");

            string downloadStringUrl = string.Format("{0}access_token={1}", GetMethodUrl(methodUrl, methodParams), this.Instance.Configuration.Options[FacebookConfigurationOptions.Auth_AccessToken]);
            Int64  reportId;

            try
            {
                using (var webClient = new System.Net.WebClient())
                {
                    string Id = webClient.DownloadString(downloadStringUrl);

                    reportId = Int64.Parse(Id.Trim('"'));
                }
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Error while trying to parse conversion report id , for more details {0}", downloadStringUrl), e);
            }

            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.ConversionsStats;

            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetReportStats);
            methodParams.Add("report_run_id", reportId.ToString());

            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Enum.Parse(typeof(Consts.FileTypes), Consts.FileTypes.ConversionsStats.ToString()));

            this.Delivery.Files.Add(deliveryFile);


            #endregion

            #region adgroup

            /*
             * Summary
             * An ad group contains the data necessary for an ad, such as bid type, bid info,
             * targeting data, creative elements, and campaign information. Each ad group is
             * associated with a campaign and all ad groups in a campaign have the same daily
             * or lifetime budget and schedule.
             * */

            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.AdGroup;
            methodUrl         = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroups);
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodParams.Add(Consts.FacebookMethodsParams.AdgroupStatus, "[%27ACTIVE%27,%27PAUSED%27,%27CAMPAIGN_PAUSED%27,%27CAMPAIGN_GROUP_PAUSED%27,%27PENDING_REVIEW%27,%27PREAPPROVED%27,%27DISAPPROVED%27,%27PENDING_BILLING_INFO%27,%27ARCHIVED%27]");
            if (Instance.Configuration.Options.ContainsKey(FacebookConfigurationOptions.AdGroupFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Instance.Configuration.Options[FacebookConfigurationOptions.AdGroupFields].ToString());
            }

            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.AdGroups);

            this.Delivery.Files.Add(deliveryFile);

            #endregion


            #region AdSet- Formally Campaigns

            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.Campaigns;
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            if (Instance.Configuration.Options.ContainsKey(FacebookConfigurationOptions.CampaignFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Instance.Configuration.Options[FacebookConfigurationOptions.CampaignFields].ToString());
            }

            // methodParams.Add("redownload", "true");

            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetCampaignsAdSets);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.AdSets);
            this.Delivery.Files.Add(deliveryFile);

            #endregion


            #region Campaigns - New Structure

            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.CampaignGroups;
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            methodParams.Add(Consts.FacebookMethodsParams.CampaignStatus, "[%27ARCHIVED%27,%27ACTIVE%27,%27PAUSED%27]");
            if (Instance.Configuration.Options.ContainsKey(FacebookConfigurationOptions.CampaignGroupsFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Instance.Configuration.Options[FacebookConfigurationOptions.CampaignGroupsFields].ToString());
            }

            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetCampaignsGroups);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.CampaignGroups);
            this.Delivery.Files.Add(deliveryFile);

            #endregion


            #region Creatives
            deliveryFile      = new DeliveryFile();
            deliveryFile.Name = Consts.DeliveryFilesNames.Creatives;
            methodParams.Add(Consts.FacebookMethodsParams.IncludeDeleted, "true");
            if (Instance.Configuration.Options.ContainsKey(FacebookConfigurationOptions.AdGroupCreativeFields))
            {
                methodParams.Add(Consts.FacebookMethodsParams.Fields, Instance.Configuration.Options[FacebookConfigurationOptions.AdGroupCreativeFields].ToString());
            }

            methodUrl = string.Format("act_{0}/{1}", Delivery.Account.OriginalID, Consts.FacebookMethodsNames.GetAdGroupCreatives);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.Url, GetMethodUrl(methodUrl, methodParams));
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileSubType, Consts.FileSubType.Length);
            deliveryFile.Parameters.Add(Consts.DeliveryFileParameters.FileType, Consts.FileTypes.Creatives);
            this.Delivery.Files.Add(deliveryFile);
            #endregion


            #endregion


            //this.ReportProgress(0.9);
            this.Delivery.Save();

            this.ReportProgress(1);

            return(ServiceOutcome.Success);
        }
Exemplo n.º 12
0
        protected override Core.Services.ServiceOutcome DoPipelineWork()
        {
            string baseAddress;

            #region Init General
            // ...............................
            // SETUP
            this.Delivery = this.NewDelivery();

            this.Delivery.Account = new Data.Objects.Account()
            {
                ID = this.Instance.AccountID,
            };
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = -1
            };

            this.Delivery.TimePeriodDefinition = this.TimePeriod;

            this.Delivery.FileDirectory = Instance.Configuration.Options[Const.DeliveryServiceConfigurationOptions.FileDirectory];

            if (string.IsNullOrEmpty(this.Delivery.FileDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }

            bool multibo = false;
            if (this.Instance.Configuration.Options.ContainsKey("URL.SignatureAppend"))
            {
                multibo = Convert.ToBoolean(this.Instance.Configuration.Options["URL.SignatureAppend"]);
            }

            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature       = Delivery.CreateSignature(String.Format("BackOffice-[{0}]-[{1}{2}]", this.Instance.AccountID, this.TimePeriod.ToAbsolute(), multibo?"-" + this.Instance.Configuration.Options["Bo.ServiceAdress"]:string.Empty)),
                Account         = Delivery.Account,
                Channel         = Delivery.Channel,
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            });

            // Create an import manager that will handle rollback, if necessary
            var importManager = new GenericMetricsImportManager(this.Instance.InstanceID, new Edge.Data.Pipeline.Common.Importing.MetricsImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Metrics.Consts.AppSettings.SqlRollbackCommand]
            });

            // Apply the delivery (will use ConflictBehavior configuration option to abort or rollback if any conflicts occur)
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);



            if (string.IsNullOrEmpty(this.Instance.Configuration.Options[BoConfigurationOptions.BaseServiceAddress]))
            {
                throw new Exception("base url must be configured!");
            }
            baseAddress = this.Instance.Configuration.Options[BoConfigurationOptions.BaseServiceAddress];



            int utcOffset = 0;
            if (this.Instance.Configuration.Options.ContainsKey(BoConfigurationOptions.UtcOffset))
            {
                utcOffset = int.Parse(this.Instance.Configuration.Options[BoConfigurationOptions.UtcOffset]);
            }
            Delivery.Parameters.Add(BoConfigurationOptions.UtcOffset, utcOffset);
            int timeZone = 0;
            if (Instance.Configuration.Options.ContainsKey(BoConfigurationOptions.TimeZone))
            {
                timeZone = int.Parse(Instance.Configuration.Options[BoConfigurationOptions.TimeZone]);
            }
            Delivery.Parameters.Add(BoConfigurationOptions.TimeZone, timeZone);
            this.ReportProgress(0.2);
            #endregion

            #region DeliveryFile
            Dictionary <string, string> UrlParams = new Dictionary <string, string>();
            DeliveryFile boFile = new DeliveryFile();
            DateTime     start  = TimePeriod.Start.ToDateTime();
            DateTime     end    = TimePeriod.End.ToDateTime();
            boFile.Parameters[BoConfigurationOptions.BO_XPath_Trackers] = Instance.Configuration.Options[BoConfigurationOptions.BO_XPath_Trackers];
            boFile.Name = BoConfigurationOptions.BoFileName;
            if (utcOffset != 0)
            {
                start = start.AddHours(utcOffset);
                end   = end.AddHours(utcOffset);
            }
            if (timeZone != 0)
            {
                start = start.AddHours(-timeZone);
                end   = end.AddHours(-timeZone);
            }



            boFile.SourceUrl = string.Format(baseAddress, start, end);


            boFile.Parameters.Add(BoConfigurationOptions.IsAttribute, Instance.Configuration.Options[BoConfigurationOptions.IsAttribute]);
            boFile.Parameters.Add(BoConfigurationOptions.TrackerFieldName, Instance.Configuration.Options[BoConfigurationOptions.TrackerFieldName]);


            this.Delivery.Files.Add(boFile);
            this.Delivery.Save();


            #endregion
            return(Core.Services.ServiceOutcome.Success);
        }
        protected override Core.Services.ServiceOutcome DoPipelineWork()
        {
            #region Init General

            // ...............................
            // SETUP
            this.Delivery = this.NewDelivery();
            this.Delivery.TimePeriodDefinition = this.TimePeriod;

            this.Delivery.FileDirectory = Instance.Configuration.Options[Const.DeliveryServiceConfigurationOptions.FileDirectory];
            this.Delivery.Account       = new Data.Objects.Account()
            {
                ID = this.Instance.AccountID,
            };
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = -1
            };

            if (string.IsNullOrEmpty(this.Delivery.FileDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }

            if (!this.Instance.Configuration.Options.ContainsKey("AuthenticationUrl"))
            {
                throw new Exception("AuthenticationUrl must be configured in configuration file");
            }
            this.Delivery.Parameters["AuthenticationUrl"] = this.Instance.Configuration.Options["AuthenticationUrl"];            //https://test.salesforce.com/services/oauth2/token

            if (!this.Instance.Configuration.Options.ContainsKey("ConsumerKey"))
            {
                throw new Exception("ClientID must be configured in configuration file");
            }
            this.Delivery.Parameters["SalesForceClientID"] = this.Instance.Configuration.Options["ConsumerKey"];//3MVG9GiqKapCZBwG.OqpT.DCgHmIXOlszzCpZPxbRyvzPDNlshB5LD0x94rQO5SzGOAZrWPNIPm_aGR7nBeXe

            if (!this.Instance.Configuration.Options.ContainsKey("ConsentCode"))
            {
                throw new Exception("ConsentCode must be configured in configuration file");
            }
            this.Delivery.Parameters["ConsentCode"] = this.Instance.Configuration.Options["ConsentCode"];            //(accesstoken

            if (!this.Instance.Configuration.Options.ContainsKey("ConsumerSecret"))
            {
                throw new Exception("ClientSecret must be configured in configuration file");
            }
            this.Delivery.Parameters["ClientSecret"] = this.Instance.Configuration.Options["ConsumerSecret"];//321506373515061074

            if (!this.Instance.Configuration.Options.ContainsKey("Redirect_URI"))
            {
                throw new Exception("Redirect_URI must be configured in configuration file");
            }
            this.Delivery.Parameters["Redirect_URI"] = this.Instance.Configuration.Options["Redirect_URI"];            //http://localhost:8080/RestTest/oauth/_callback

            // This is for finding conflicting services
            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("BackOffice-[{0}]-[{1}]-[{2}]",
                                                                   this.Instance.AccountID,
                                                                   this.TimePeriod.ToAbsolute(), this.Delivery.Parameters["SalesForceClientID"])),
                Account         = Delivery.Account,
                Channel         = Delivery.Channel,
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            });



            // Create an import manager that will handle rollback, if necessary
            var importManager = new GenericMetricsImportManager(this.Instance.InstanceID, new Edge.Data.Pipeline.Common.Importing.MetricsImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Metrics.Consts.AppSettings.SqlRollbackCommand]
            });

            // Apply the delivery (will use ConflictBehavior configuration option to abort or rollback if any conflicts occur)
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            // ...............................
            // Now that we have a new delivery, start adding values

            int utcOffset = 0;
            if (this.Instance.Configuration.Options.ContainsKey(BoConfigurationOptions.UtcOffset))
            {
                utcOffset = int.Parse(this.Instance.Configuration.Options[BoConfigurationOptions.UtcOffset]);
            }
            Delivery.Parameters.Add(BoConfigurationOptions.UtcOffset, utcOffset);
            int timeZone = 0;
            if (Instance.Configuration.Options.ContainsKey(BoConfigurationOptions.TimeZone))
            {
                timeZone = int.Parse(Instance.Configuration.Options[BoConfigurationOptions.TimeZone]);
            }
            Delivery.Parameters.Add(BoConfigurationOptions.TimeZone, timeZone);
            this.ReportProgress(0.2);
            //if (!Instance.Configuration.Options.ContainsKey("ServiceAddress"))
            //    throw new Exception("ServiceAddress must be configured in configuration file");
            //serviceAddress = Instance.Configuration.Options["ServiceAddress"];

            #endregion

            #region DeliveryFile
            string query = Instance.Configuration.Options["Query"];
            //@SMBLeads:SELECT  CreatedDate,Edge_BI_Tracker__c ,Company_Type__c  FROM Lead WHERE CreatedDate > 2013-06-28T00:00:00.00Z AND Edge_BI_Tracker__c != null

            string[] queries = query.Split('@');

            foreach (string qwry in queries)
            {
                DeliveryFile file = new DeliveryFile();
                string[]     q    = qwry.Split(':');
                file.Name = q[0] + "-0";
                DateTime start = TimePeriod.Start.ToDateTime();
                DateTime end   = TimePeriod.End.ToDateTime();
                if (utcOffset != 0)
                {
                    start = start.AddHours(utcOffset);
                    end   = end.AddHours(utcOffset);
                }
                if (timeZone != 0)
                {
                    start = start.AddHours(-timeZone);
                    end   = end.AddHours(-timeZone);
                }
                file.Parameters["Query"] = q[1];

                this.Delivery.Files.Add(file);
            }


            this.Delivery.Save();

            return(Core.Services.ServiceOutcome.Success);

            #endregion
        }
Exemplo n.º 14
0
        protected override ServiceOutcome DoPipelineWork()
        {
            #region Init General
            // ...............................
            // SETUP
            this.Delivery         = this.NewDelivery();
            this.Delivery.Account = new Data.Objects.Account()
            {
                ID         = this.Instance.AccountID,
                OriginalID = this.Instance.Configuration.Options["AdCenter.CustomerID"].ToString()
            };
            this.Delivery.TimePeriodDefinition = this.TimePeriod;
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = 14
            };

            this.Delivery.FileDirectory = Instance.Configuration.Options["DeliveryFilesDir"];

            if (string.IsNullOrEmpty(this.Delivery.FileDirectory))
            {
                throw new Exception("Delivery FileDirectory must be configured in configuration file (DeliveryFilesDir)");
            }
            // Copy some options as delivery parameters


            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("Microsoft-AdCenter-[{0}]-[{1}]-[{2}]",
                                                                   this.Instance.AccountID,
                                                                   this.Instance.Configuration.Options["AdCenter.CustomerID"].ToString(),
                                                                   this.TimePeriod.ToAbsolute()
                                                                   )),

                Account = new Data.Objects.Account()
                {
                    ID = this.Instance.AccountID, OriginalID = this.Instance.Configuration.Options["AdCenter.CustomerID"]
                },
                Channel = new Data.Objects.Channel()
                {
                    ID = 14
                },
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            }
                                      );

            // Create an import manager that will handle rollback, if necessary
            AdMetricsImportManager importManager = new AdMetricsImportManager(this.Instance.InstanceID, new MetricsImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Metrics.Consts.AppSettings.SqlRollbackCommand]
            });

            // Apply the delivery (will use ConflictBehavior configuration option to abort or rollback if any conflicts occur)
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            // ...............................

            // Now that we have a new delivery, start adding values

            this.ReportProgress(0.2);
            #endregion

            // Wrapper for adCenter API
            AdCenterApi adCenterApi = new AdCenterApi(this);

            // ................................
            // Campaign report
            this.Delivery.Files.Add(new DeliveryFile()
            {
                Name = Const.Files.CampaignReport
            });

            ReportProgress(0.33);

            // ................................
            // Ad report


            ReportProgress(0.33);

            // ................................
            // Keyword report
            this.Delivery.Files.Add(new DeliveryFile()
            {
                Name = Const.Files.KeywordReport
            });



            this.Delivery.Files[Const.Files.KeywordReport].Parameters.Add(Const.Parameters.TimePeriodColumnName, AdCenterApi.GetTimePeriodColumnName(WS.ReportAggregation.Daily));


            this.Delivery.Files.Add(new DeliveryFile()
            {
                Name = Const.Files.AdReport
            });
            ReportProgress(0.33);

            // Save with success
            this.Delivery.Save();

            return(ServiceOutcome.Success);
        }
        protected override Core.Services.ServiceOutcome DoPipelineWork()
        {
            #region Init General
            int backOfficeChannel = -888;
            // ...............................
            // SETUP
            this.Delivery = this.NewDelivery();

            this.Delivery.Account = new Data.Objects.Account()
            {
                ID = this.Instance.AccountID,
            };
            this.Delivery.Channel = new Data.Objects.Channel()
            {
                ID = -1
            };

            this.Delivery.TimePeriodDefinition = this.TimePeriod;

            this.Delivery.FileDirectory = Instance.Configuration.Options[Const.DeliveryServiceConfigurationOptions.FileDirectory];

            #region two profiles
            //serviceAddress = Instance.Configuration.Options["ServiceAddress"];
            //Match m=Regex.Match(serviceAddress,@"\bids=(?<profileID>[^&]+)",RegexOptions.IgnoreCase);
            //Group g=m.Groups["profileID"];
            //string profileID=g.Value;


            //**************in case amir will want to run two profiles
            //this.Delivery.Outputs.Add(new DeliveryOutput()
            //{
            //    Signature = Delivery.CreateSignature(String.Format("BackOffice-[{0}]-[{1}]-[{2}]",
            //  this.Instance.AccountID,
            //  this.TimePeriod.ToAbsolute(),
            //  profileID)),
            //    Account = Delivery.Account,
            //    Channel = Delivery.Channel,
            //    TimePeriodStart=Delivery.TimePeriodStart,
            //    TimePeriodEnd=Delivery.TimePeriodEnd


            //});
            #endregion


            // This is for finding conflicting services
            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("BackOffice-[{0}]-[{1}]",
                                                                   this.Instance.AccountID,
                                                                   this.TimePeriod.ToAbsolute())),
                Account         = Delivery.Account,
                Channel         = Delivery.Channel,
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            });



            // Create an import manager that will handle rollback, if necessary
            var importManager = new GenericMetricsImportManager(this.Instance.InstanceID, new Edge.Data.Pipeline.Common.Importing.MetricsImportManagerOptions()
            {
                SqlRollbackCommand = Instance.Configuration.Options[Edge.Data.Pipeline.Metrics.Consts.AppSettings.SqlRollbackCommand]
            });

            // Apply the delivery (will use ConflictBehavior configuration option to abort or rollback if any conflicts occur)
            this.HandleConflicts(importManager, DeliveryConflictBehavior.Abort);

            // ...............................

            // Now that we have a new delivery, start adding values



            if (string.IsNullOrEmpty(this.Delivery.FileDirectory))
            {
                throw new Exception("Delivery.TargetLocationDirectory must be configured in configuration file (DeliveryFilesDir)");
            }

            if (!this.Instance.Configuration.Options.ContainsKey("AuthenticationUrl"))
            {
                throw new Exception("AuthenticationUrl must be configured in configuration file");
            }
            this.Delivery.Parameters["AuthenticationUrl"] = this.Instance.Configuration.Options["AuthenticationUrl"];

            if (!this.Instance.Configuration.Options.ContainsKey("ClientID"))
            {
                throw new Exception("ClientID must be configured in configuration file");
            }
            this.Delivery.Parameters["ClientID"] = this.Instance.Configuration.Options["ClientID"];

            if (!this.Instance.Configuration.Options.ContainsKey("ConsentCode"))
            {
                throw new Exception("ConsentCode must be configured in configuration file");
            }
            this.Delivery.Parameters["ConsentCode"] = this.Instance.Configuration.Options["ConsentCode"];

            if (!this.Instance.Configuration.Options.ContainsKey("ClientSecret"))
            {
                throw new Exception("ClientSecret must be configured in configuration file");
            }
            this.Delivery.Parameters["ClientSecret"] = this.Instance.Configuration.Options["ClientSecret"];

            if (!this.Instance.Configuration.Options.ContainsKey("Redirect_URI"))
            {
                throw new Exception("Redirect_URI must be configured in configuration file");
            }
            this.Delivery.Parameters["Redirect_URI"] = this.Instance.Configuration.Options["Redirect_URI"];



            int utcOffset = 0;
            if (this.Instance.Configuration.Options.ContainsKey(BoConfigurationOptions.UtcOffset))
            {
                utcOffset = int.Parse(this.Instance.Configuration.Options[BoConfigurationOptions.UtcOffset]);
            }
            Delivery.Parameters.Add(BoConfigurationOptions.UtcOffset, utcOffset);
            int timeZone = 0;
            if (Instance.Configuration.Options.ContainsKey(BoConfigurationOptions.TimeZone))
            {
                timeZone = int.Parse(Instance.Configuration.Options[BoConfigurationOptions.TimeZone]);
            }
            Delivery.Parameters.Add(BoConfigurationOptions.TimeZone, timeZone);
            this.ReportProgress(0.2);
            if (!Instance.Configuration.Options.ContainsKey("ServiceAddress"))
            {
                throw new Exception("ServiceAddress must be configured in configuration file");
            }
            serviceAddress = Instance.Configuration.Options["ServiceAddress"];

            #endregion

            #region DeliveryFile

            DeliveryFile file = new DeliveryFile();
            file.Name = "GoalsByCountryAndPagePath.GZIP";
            DateTime start = TimePeriod.Start.ToDateTime();
            DateTime end   = TimePeriod.End.ToDateTime();
            if (utcOffset != 0)
            {
                start = start.AddHours(utcOffset);
                end   = end.AddHours(utcOffset);
            }
            if (timeZone != 0)
            {
                start = start.AddHours(-timeZone);
                end   = end.AddHours(-timeZone);
            }
            file.SourceUrl = string.Format(serviceAddress, this.Delivery.TimePeriodDefinition.Start.ToDateTime(), this.Delivery.TimePeriodDefinition.End.ToDateTime());


            this.Delivery.Files.Add(file);
            this.Delivery.Save();

            return(Core.Services.ServiceOutcome.Success);

            #endregion
        }
Exemplo n.º 16
0
        protected override ServiceOutcome DoPipelineWork()
        {
            this.Delivery = this.NewDelivery(); // setup delivery
            this.Delivery.FileDirectory = Instance.Configuration.Options[Edge.Data.Pipeline.Services.Const.DeliveryServiceConfigurationOptions.FileDirectory];
            this.Delivery.Account       = new Account()
            {
                ID = 0
            };

            string fileName = string.Empty;

            //FileName
            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["FileName"]))
            {
                throw new Exception("Missing Configuration Param , FileName");
            }
            else
            {
                fileName = this.Instance.Configuration.Options["FileName"];
            }

            DeliveryFile _file = new DeliveryFile()
            {
                Name = fileName
            };


            if (String.IsNullOrEmpty(this.Instance.Configuration.Options["CurrencyCodes"]))
            {
                throw new Exception("Missing Configuration Param , CurrencyCodes");
            }
            else
            {
                this.Delivery.Parameters.Add("CurrencyCodes", Instance.Configuration.Options["CurrencyCodes"]);
            }


            foreach (string currencyCode in   this.Delivery.Parameters["CurrencyCodes"].ToString().Split(';'))
            {
                //http://currencies.apps.grandtrunk.net/getrange/2013-11-25/2013-11-26/HKD/USD
                _file.SourceUrl = string.Format("{3}{0}/{1}/{2}/USD",
                                                this.Delivery.TimePeriodDefinition.Start.ToDateTime().AddDays(-1).ToString("yyyy-MM-dd"),
                                                this.Delivery.TimePeriodDefinition.Start.ToDateTime().ToString("yyyy-MM-dd"),
                                                currencyCode,
                                                Instance.Configuration.Options["SourceUrl"]
                                                );
                _file.Parameters.Add("CurrencyCode", currencyCode);

                this.Delivery.Files.Add(_file);
            }

            //Set Output
            this.Delivery.Outputs.Add(new DeliveryOutput()
            {
                Signature = Delivery.CreateSignature(String.Format("[{0}]-[{1}]",
                                                                   this.TimePeriod.ToAbsolute(),
                                                                   Instance.Configuration.Options["SourceUrl"]
                                                                   )),
                Account = new Data.Objects.Account()
                {
                    ID = 0
                },
                TimePeriodStart = Delivery.TimePeriodStart,
                TimePeriodEnd   = Delivery.TimePeriodEnd
            });

            this.Delivery.Save();
            return(Core.Services.ServiceOutcome.Success);
        }