/// <summary> /// Get Storage Operation Context for rest calls /// </summary> /// <param name="outputWriter">Ouput writer for writing logs for each rest call</param> /// <returns>Storage operation context</returns> public static OperationContext GetStorageOperationContext(Action <string> outputWriter) { if (!inited) { CmdletOperationContext.Init(); } OperationContext context = new OperationContext(); context.ClientRequestID = ClientRequestId; context.SendingRequest += (s, e) => { context.StartTime = DateTime.Now; Interlocked.Increment(ref startedRemoteCallCounter); string message = String.Format(Resources.StartRemoteCall, startedRemoteCallCounter, e.Request.Method, e.Request.RequestUri.ToString()); try { if (outputWriter != null) { outputWriter(message); } } catch { //catch the exception. If so, the storage client won't sleep and retry } }; context.ResponseReceived += (s, e) => { context.EndTime = DateTime.Now; Interlocked.Increment(ref finishedRemoteCallCounter); double elapsedTime = (context.EndTime - context.StartTime).TotalMilliseconds; string message = String.Format(Resources.FinishRemoteCall, e.Request.RequestUri.ToString(), (int)e.Response.StatusCode, e.Response.StatusCode, e.RequestInformation.ServiceRequestID, elapsedTime); try { if (outputWriter != null) { outputWriter(message); } } catch { //catch the exception. If so, the storage client won't sleep and retry } }; return(context); }
/// <summary> /// Cmdlet begin process /// </summary> protected override void BeginProcessing() { CmdletOperationContext.Init(); WriteDebugLog(String.Format(Resources.InitOperationContextLog, this.GetType().Name, CmdletOperationContext.ClientRequestId)); base.BeginProcessing(); }