Exemple #1
0
        public void UpdateManagedClients()
        {
            try
            {
                var user = new AdWordsUser();
                // Get the ManagedCustomerService.
                ManagedCustomerService managedCustomerService =
                    (ManagedCustomerService)user.GetService(AdWordsService.v201609.ManagedCustomerService);
                managedCustomerService.RequestHeader.clientCustomerId = Settings.Default.RootMCCClientCustomerId;

                // Create selector.
                var selector = new Selector()
                {
                    fields = new string[]
                    {
                        ManagedCustomer.Fields.CanManageClients,
                        ManagedCustomer.Fields.CurrencyCode,
                        ManagedCustomer.Fields.CustomerId,
                        ManagedCustomer.Fields.DateTimeZone,
                        ManagedCustomer.Fields.Name,
                        ManagedCustomer.Fields.TestAccount,
                    },
                    paging = new Paging
                    {
                        numberResults = 5000,
                        startIndex    = 0
                    }
                };

                // list to build up all pages from api
                var managedCustomerPageList = new List <ManagedCustomerPage>();

                // holds the page between each call to the api
                ManagedCustomerPage page = null;

                // get all pages
                do
                {
                    // get current page
                    page = managedCustomerService.get(selector);

                    // add page to list
                    managedCustomerPageList.Add(page);

                    // advance paging to next page
                    selector.paging.IncreaseOffset();
                } while (selector.paging.startIndex < page.totalNumEntries);

                // serialize as xml
                var managedCustomerPageXml = managedCustomerPageList.ToArray().ToXml();

                // send to db for processing
                Repository.UploadMagagedClients(managedCustomerPageXml);
            }
            catch (Exception ex)
            {
                var newEx = new System.ApplicationException("Failed to Refresh Managed Client List", ex);
                Repository.LogError(newEx.ToString(), "ManagedClientProcessor");
            }
        }
        public void log_an_assembly_failure()
        {
            var package = new StubPackage("a");
            var exception = new ApplicationException("didn't work");
            var theFileNameOfTheAssembly = "assembly.dll";
            diagnostics.LogAssemblyFailure(package, theFileNameOfTheAssembly, exception);

            var log = diagnostics.LogFor(package);

            log.Success.ShouldBeFalse();
            log.FullTraceText().Contains(exception.ToString()).ShouldBeTrue();

            log.FullTraceText().ShouldContain("Failed to load assembly at '{0}'".ToFormat(theFileNameOfTheAssembly));
        }
		/// <summary>
		/// Overrides Package.OnSaveOptions()
		/// Invoked by the Package class when there are options to be saved to the solution file.
		/// </summary>
		/// <param name="key">The name of the option key to save.</param>
		/// <param name="stream">The stream to save the option data to.</param>
		protected override void OnSaveOptions(string key, Stream stream)
		{
			try
			{
				if (0 == string.Compare(key, CommandLineOptionKey))
				{
					Logging.WriteLine("Saving CommandLineEditor options");
					CommandLineEditor.SaveOptions(stream);
				}
				else if (0 == string.Compare(key, BatchBuildSetsOptionKey))
				{
					Logging.WriteLine("Saving BatchBuilder options");
					BatchBuilder.SaveOptions(stream);
				}
			}
			catch (Exception Ex)
			{
				// Couldn't save options
				Exception AppEx = new ApplicationException("OnSaveOptions() failed with key " + key, Ex);
				Logging.WriteLine(AppEx.ToString());
				throw AppEx;
			}
		}
		/// Called by combo control to query the text to display or to apply newly-entered text
		private void ComboHandler(object Sender, EventArgs Args)
		{
			try
			{
				var OleArgs = (OleMenuCmdEventArgs)Args;

				string InString = OleArgs.InValue as string;
				if (InString != null)
				{
					// New text set on the combo - set the command line property
					DesiredCommandLine = null;
					CommitCommandLineText(InString);
				}
				else if (OleArgs.OutValue != IntPtr.Zero)
				{
					string EditingString = null;
					if (OleArgs.InValue != null)
					{
						object[] InArray = OleArgs.InValue as object[];
						if (InArray != null && 0 < InArray.Length)
						{
							EditingString = InArray.Last() as string;
						}
					}

					string TextToDisplay = string.Empty;
					if (EditingString != null)
					{
						// The control wants to put EditingString in the box
						TextToDisplay = DesiredCommandLine = EditingString;
					}
					else
					{
						// This is always hit at the end of interaction with the combo
						if (DesiredCommandLine != null)
						{
							TextToDisplay = DesiredCommandLine;
							DesiredCommandLine = null;
							CommitCommandLineText(TextToDisplay);
						}
						else
						{
							TextToDisplay = MakeCommandLineComboText();
						}
					}

					Marshal.GetNativeVariantForObject(TextToDisplay, OleArgs.OutValue);
				}
			}
			catch (Exception ex)
			{
				Exception AppEx = new ApplicationException("CommandLineEditor threw an exception in ComboHandler()", ex);
				Logging.WriteLine(AppEx.ToString());
				throw AppEx;
			}
		}
 /// <summary>
 /// Throws RuntimeException to indicate failed assertion.
 /// The function never returns and its return type is RuntimeException
 /// only to be able to write <tt>throw EcmaScriptHelper.CodeBug()</tt> if plain
 /// <tt>EcmaScriptHelper.CodeBug()</tt> triggers unreachable code error.
 /// </summary>
 public static ApplicationException CodeBug()
 {
     ApplicationException ex = new ApplicationException ("FAILED ASSERTION");
     Console.Error.WriteLine (ex.ToString ());
     throw ex;
 }
		/// <summary>
		/// Called from the package class when there are options to be written to the solution file.
		/// </summary>
		/// <param name="Stream">The stream to save the option data to.</param>
		public void SaveOptions(Stream Stream)
		{
			try
			{
				using (BinaryWriter Writer = new BinaryWriter(Stream))
				{
					Writer.Write(_BuildJobSetsCollection.Count);
					foreach (var Set in _BuildJobSetsCollection)
					{
						Writer.Write(Set.Name);
						Writer.Write(Set.BuildJobs.Count);
						foreach (var Job in Set.BuildJobs)
						{
							Writer.Write(Job.Project.FullName);
							Writer.Write(Job.Project.Name);
							Writer.Write(Job.Config);
							Writer.Write(Job.Platform);
							Writer.Write(Enum.GetName(typeof(BuildJob.BuildJobType), Job.JobType) ?? "INVALIDJOBTYPE");
						}
					}
				}
			}
			catch (Exception ex)
			{
				Exception AppEx = new ApplicationException("BatchBuilder failed to save options to .suo", ex);
				Logging.WriteLine(AppEx.ToString());
				throw AppEx;
			}
		}
		/// <summary>
		/// Called from the package class when there are options to be read out of the solution file.
		/// </summary>
		/// <param name="Stream">The stream to load the option data from.</param>
		public void LoadOptions(Stream Stream)
		{
			try
			{
				_BuildJobSetsCollection.Clear();

				using (BinaryReader Reader = new BinaryReader(Stream))
				{
					int SetCount = Reader.ReadInt32();

					for (int SetIdx = 0; SetIdx < SetCount; SetIdx++)
					{
						BuildJobSet LoadedSet = new BuildJobSet();
						LoadedSet.Name = Reader.ReadString();
						int JobCount = Reader.ReadInt32();
						for (int JobIdx = 0; JobIdx < JobCount; JobIdx++)
						{
							Utils.SafeProjectReference ProjectRef = new Utils.SafeProjectReference { FullName = Reader.ReadString(), Name = Reader.ReadString() };

							string Config = Reader.ReadString();
							string Platform = Reader.ReadString();
							BuildJob.BuildJobType JobType;

							if (Enum.TryParse(Reader.ReadString(), out JobType))
							{
								LoadedSet.BuildJobs.Add(new BuildJob(ProjectRef, Config, Platform, JobType));
							}
						}
						_BuildJobSetsCollection.Add(LoadedSet);
					}
				}

				EnsureDefaultBuildJobSet();
				if (SetCombo.SelectedItem == null)
				{
					SetCombo.SelectedItem = _BuildJobSetsCollection[0];
				}
			}
			catch (Exception ex)
			{
				Exception AppEx = new ApplicationException("BatchBuilder failed to load options from .suo", ex);
				Logging.WriteLine(AppEx.ToString());
				throw AppEx;
			}
		}
        public void Execute()
        {
            try
            {
                // account report downloads are different than all other report types
                // we unconditionally download account data to determine if the account has impressions
                // the load for account data is conditionally executed based on the report types to download
                this._currentReportType  = ReportTypes.Account;
                this._currentReportStage = ReportStage.NotSet;
                bool hasImpressions   = false;
                bool hasVideoCampaign = false;
                LoadAccountPerformanceReport(out hasImpressions);

                if (!hasImpressions) // no impressions means we don't do anything else besides update the log appropriately
                {
                    Repository.SetReportLogZeroImpressions(this._rptlogId);
                }
                else // impressions means we may need to download other reports
                {
                    // only load if the report type is being requested
                    if (this._reportTypesToDownload.Contains(ReportTypes.Campaign))
                    {
                        this._currentReportType  = ReportTypes.Campaign;
                        this._currentReportStage = ReportStage.NotSet;
                        LoadCampaignPerformanceReport(out hasVideoCampaign);
                        //Only load if the report type is being requested and if it is a video campaign
                        if (hasVideoCampaign)
                        {
                            if (this._reportTypesToDownload.Contains(ReportTypes.Age))
                            {
                                this._currentReportType  = ReportTypes.Age;
                                this._currentReportStage = ReportStage.NotSet;
                                LoadYoutubeAgePerformanceReport();
                            }
                            if (this._reportTypesToDownload.Contains(ReportTypes.Gender))
                            {
                                this._currentReportType  = ReportTypes.Gender;
                                this._currentReportStage = ReportStage.NotSet;
                                LoadYoutubeGenderPerformanceReport();
                            }
                            if (this._reportTypesToDownload.Contains(ReportTypes.Video))
                            {
                                this._currentReportType  = ReportTypes.Video;
                                this._currentReportStage = ReportStage.NotSet;
                                LoadYoutubeVideoPerformanceReport();
                            }
                        }
                    }

                    // only load if the report type is being requested
                    if (this._reportTypesToDownload.Contains(ReportTypes.AdGroup))
                    {
                        this._currentReportType  = ReportTypes.AdGroup;
                        this._currentReportStage = ReportStage.NotSet;
                        LoadAdGroupPerformanceReport();
                    }

                    // only load if the report type is being requested
                    if (this._reportTypesToDownload.Contains(ReportTypes.Ad))
                    {
                        this._currentReportType  = ReportTypes.Ad;
                        this._currentReportStage = ReportStage.NotSet;
                        LoadAdPerformanceReport();
                    }

                    // only load if the report type is being requested
                    if (this._reportTypesToDownload.Contains(ReportTypes.Keyword))
                    {
                        this._currentReportType  = ReportTypes.Keyword;
                        this._currentReportStage = ReportStage.NotSet;
                        LoadKeywordPerformanceReport();
                    }
                }
            }
            catch (Exception ex)
            {
                // give extra execution info
                var wrappedEx = new System.ApplicationException(string.Format("Failed to process report logid:{0}", this._rptlogId), ex);
                // log exception
                var errlogId = Repository.LogError(wrappedEx.ToString(), string.Format("ReportProcessor - {0}", this._currentReportType));
                // mark log entry failed
                Repository.SetReportLogErrorId(this._rptlogId, errlogId);
            }
        }