Example #1
0
        /// <summary>
        /// Cmdlet begin process. Write to logs, setup Http Tracing and initialize profile
        /// </summary>
        protected override void BeginProcessing()
        {
            PromptForDataCollectionProfileIfNotExists();
            InitializeQosEvent();
            if (string.IsNullOrEmpty(ParameterSetName))
            {
                WriteDebugWithTimestamp(string.Format("{0} begin processing without ParameterSet.", this.GetType().Name));
            }
            else
            {
                WriteDebugWithTimestamp(string.Format("{0} begin processing with ParameterSet '{1}'.", this.GetType().Name, ParameterSetName));
            }

            if (DefaultContext != null && DefaultContext.Account != null && DefaultContext.Account.Id != null)
            {
                WriteDebugWithTimestamp(string.Format("using account id '{0}'...", DefaultContext.Account.Id));
            }

            _httpTracingInterceptor          = _httpTracingInterceptor ?? new RecordingTracingInterceptor(_debugMessages);
            _adalListener                    = _adalListener ?? new DebugStreamTraceListener(_debugMessages);
            _serviceClientTracingInterceptor = _serviceClientTracingInterceptor ?? new ServiceClientTracingInterceptor(_debugMessages);
            RecordingTracingInterceptor.AddToContext(_httpTracingInterceptor);
            DebugStreamTraceListener.AddAdalTracing(_adalListener);
            ServiceClientTracing.AddTracingInterceptor(_serviceClientTracingInterceptor);

            ProductInfoHeaderValue userAgentValue = new ProductInfoHeaderValue(
                ModuleName, string.Format("v{0}", ModuleVersion));

            AzureSession.ClientFactory.UserAgents.Add(userAgentValue);
            AzureSession.ClientFactory.AddHandler(new CmdletInfoHandler(this.CommandRuntime.ToString(), this.ParameterSetName, this._clientRequestId));
            base.BeginProcessing();
        }
Example #2
0
        /// <summary>
        /// End processing. Flush messages in tracing interceptor and save profile and removes user agent.
        /// </summary>
        protected override void EndProcessing()
        {
            LogQosEvent();
            string message = string.Format("{0} end processing.", this.GetType().Name);

            WriteDebugWithTimestamp(message);

            RecordingTracingInterceptor.RemoveFromContext(_httpTracingInterceptor);
            DebugStreamTraceListener.RemoveAdalTracing(_adalListener);
            ServiceClientTracingInterceptor.RemoveTracingInterceptor(_serviceClientTracingInterceptor);
            FlushDebugMessages();

            AzureSession.ClientFactory.UserAgents.RemoveWhere(u => u.Product.Name == ModuleName);
            AzureSession.ClientFactory.RemoveHandler(typeof(CmdletInfoHandler));
            base.EndProcessing();
        }
Example #3
0
        /// <summary>
        /// Cmdlet begin process. Write to logs, setup Http Tracing and initialize profile
        /// </summary>
        protected override void BeginProcessing()
        {
            PromptForDataCollectionProfileIfNotExists();
            InitializeQosEvent();
            if (string.IsNullOrEmpty(ParameterSetName))
            {
                WriteDebugWithTimestamp(string.Format("{0} begin processing without ParameterSet.", this.GetType().Name));
            }
            else
            {
                WriteDebugWithTimestamp(string.Format("{0} begin processing with ParameterSet '{1}'.", this.GetType().Name, ParameterSetName));
            }

            if (DefaultContext != null && DefaultContext.Account != null && DefaultContext.Account.Id != null)
            {
                WriteDebugWithTimestamp(string.Format("using account id '{0}'...", DefaultContext.Account.Id));
            }

            _httpTracingInterceptor = _httpTracingInterceptor ?? new RecordingTracingInterceptor(_debugMessages);
            _adalListener = _adalListener ?? new DebugStreamTraceListener(_debugMessages);
            _serviceClientTracingInterceptor = _serviceClientTracingInterceptor ?? new ServiceClientTracingInterceptor(_debugMessages);
            RecordingTracingInterceptor.AddToContext(_httpTracingInterceptor);
            DebugStreamTraceListener.AddAdalTracing(_adalListener);
            ServiceClientTracing.AddTracingInterceptor(_serviceClientTracingInterceptor);

            ProductInfoHeaderValue userAgentValue = new ProductInfoHeaderValue(
                ModuleName, string.Format("v{0}", ModuleVersion));
            AzureSession.ClientFactory.UserAgents.Add(userAgentValue);
            AzureSession.ClientFactory.AddHandler(new CmdletInfoHandler(this.CommandRuntime.ToString(), this.ParameterSetName, this._clientRequestId));
            base.BeginProcessing();
        }