/// <summary>
        /// Queries the server until the database assignment succeeds or there is an error.
        /// </summary>
        /// <param name="context">The context upon which to perform the action</param>
        /// <param name="response">The database object.</param>
        /// <returns>Returns the response from the server</returns>
        internal static Database WaitForDatabaseOperation(PSCmdlet cmdlet, IServerDataServiceContext context, Database response, string databaseName, bool isCreate)
        {
            // Duration to sleep: 2 second
            TimeSpan sleepDuration = TimeSpan.FromSeconds(2.0);

            // Poll for a maximum of 10 minutes;
            TimeSpan maximumPollDuration = TimeSpan.FromMinutes(10.0);

            // Text to display to the user while they wait.
            string pendingText = "Pending";
            string textToDisplay = "";

            // Start the timer
            Stopwatch watch = Stopwatch.StartNew();

            while (watch.Elapsed < maximumPollDuration)
            {
                if (response == null)
                {
                    throw new Exception("An unexpected error occured. The response from the server was invalid, please try your request again.");
                }

                // Check to see if the database is ready for use.
                if ((isCreate && (response.Status != (int)DatabaseStatus.Creating)) || // The database is done being created
                    (!isCreate && (response.ServiceObjectiveAssignmentState != 0)))     // The database is done with SLO upgrade
                {
                    break;
                }

                // Wait before next poll.
                Thread.Sleep(sleepDuration);

                // Display that the status is pending and how long the operation has been waiting
                textToDisplay = string.Format("{0}: {1}", pendingText, watch.Elapsed.ToString("%s' sec.'"));
                cmdlet.WriteProgress(new ProgressRecord(0, "Waiting for database creation completion.", textToDisplay));

                // Poll the server for the database status.
                response = context.GetDatabase(databaseName);
            }

            return response;
        }
示例#2
0
 internal static MemoryStream ReadStream(Stream stream, long contentLength, PSCmdlet cmdlet)
 {
     MemoryStream stream3;
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (!stream.CanRead)
     {
         throw new ArgumentOutOfRangeException("stream");
     }
     if (0L >= contentLength)
     {
         contentLength = 0x186a0L;
     }
     int capacity = (int) Math.Min(contentLength, 0x7fffffffL);
     MemoryStream stream2 = new MemoryStream(capacity);
     try
     {
         long o = 0L;
         byte[] buffer = new byte[0x2710];
         int count = 1;
         while (0 < count)
         {
             if (cmdlet != null)
             {
                 ProgressRecord progressRecord = new ProgressRecord(0xa681412, WebCmdletStrings.ReadResponseProgressActivity, StringUtil.Format(WebCmdletStrings.ReadResponseProgressStatus, o));
                 cmdlet.WriteProgress(progressRecord);
             }
             count = stream.Read(buffer, 0, buffer.Length);
             if (0 < count)
             {
                 stream2.Write(buffer, 0, count);
             }
             o += count;
         }
         if (cmdlet != null)
         {
             ProgressRecord record2 = new ProgressRecord(0xa681412, WebCmdletStrings.ReadResponseProgressActivity, StringUtil.Format(WebCmdletStrings.ReadResponseComplete, o)) {
                 RecordType = ProgressRecordType.Completed
             };
             cmdlet.WriteProgress(record2);
         }
         stream2.SetLength(o);
         stream3 = stream2;
     }
     catch (Exception)
     {
         stream2.Close();
         throw;
     }
     return stream3;
 }
示例#3
0
 internal static void WriteToStream(Stream input, Stream output, PSCmdlet cmdlet)
 {
     byte[] buffer = new byte[0x2710];
     long length = input.Length;
     int count = 1;
     while (0 < count)
     {
         if (cmdlet != null)
         {
             ProgressRecord progressRecord = new ProgressRecord(0xa681412, WebCmdletStrings.WriteRequestProgressActivity, StringUtil.Format(WebCmdletStrings.WriteRequestProgressStatus, length));
             cmdlet.WriteProgress(progressRecord);
         }
         int num3 = (int) Math.Min(length, 0x2710L);
         count = input.Read(buffer, 0, num3);
         if (0 < count)
         {
             output.Write(buffer, 0, count);
         }
         length -= count;
     }
     if (cmdlet != null)
     {
         ProgressRecord record2 = new ProgressRecord(0xa681412, WebCmdletStrings.WriteRequestProgressActivity, StringUtil.Format(WebCmdletStrings.WriteRequestComplete, length)) {
             RecordType = ProgressRecordType.Completed
         };
         cmdlet.WriteProgress(record2);
     }
     output.Flush();
 }
 internal static void WriteToStream(Stream input, Stream output, PSCmdlet cmdlet)
 {
     byte[] buffer = new byte[0x2710];
     long length = input.Length;
     int count = 1;
     while (0 < count)
     {
         if (cmdlet != null)
         {
             ProgressRecord progressRecord = new ProgressRecord(0xa681412, "Writing web request.", string.Format("Writing request stream... (Number of bytes remaining: {0})", length));
             cmdlet.WriteProgress(progressRecord);
         }
         int num3 = (int) Math.Min(length, 0x2710L);
         count = input.Read(buffer, 0, num3);
         if (0 < count)
         {
             output.Write(buffer, 0, count);
         }
         length -= count;
     }
     if (cmdlet != null)
     {
         ProgressRecord record2 = new ProgressRecord(0xa681412, "Writing web request.", string.Format("Writing web request completed. (Number of bytes remaining: {0})", length))
         {
             RecordType = ProgressRecordType.Completed
         };
         cmdlet.WriteProgress(record2);
     }
     output.Flush();
 }
示例#5
0
        internal static void WriteToStream(Stream input, Stream output, PSCmdlet cmdlet)
        {
            byte[] data = new byte[ChunkSize];

            int read = 0;
            long totalWritten = 0;
            do
            {
                if (cmdlet != null)
                {
                    ProgressRecord record = new ProgressRecord(ActivityId,
                        WebCmdletStrings.WriteRequestProgressActivity,
                        StringUtil.Format(WebCmdletStrings.WriteRequestProgressStatus, totalWritten));
                    cmdlet.WriteProgress(record);
                }

                read = input.Read(data, 0, ChunkSize);

                if (0 < read)
                {
                    output.Write(data, 0, read);
                    totalWritten += read;
                }
            } while (read != 0);


            if (cmdlet != null)
            {
                ProgressRecord record = new ProgressRecord(ActivityId,
                    WebCmdletStrings.WriteRequestProgressActivity,
                    StringUtil.Format(WebCmdletStrings.WriteRequestComplete, totalWritten));
                record.RecordType = ProgressRecordType.Completed;
                cmdlet.WriteProgress(record);
            }

            output.Flush();
        }