コード例 #1
0
ファイル: DryadLinqUtil.cs プロジェクト: xyuan/Dryad
        private static byte[] ObjectToByteArray(Object objectToSerialize)
        {
            MemoryStream    fs        = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                formatter.Serialize(fs, objectToSerialize);
                return(fs.ToArray());
            }
            catch (SerializationException se)
            {
                DryadLinqClientLog.Add("Error occured during serialization. Message: " + se.Message);
                throw;
            }
            finally
            {
                fs.Close();
            }
        }
コード例 #2
0
        /// <summary>
        /// Wait for job completion.
        /// </summary>
        /// <returns>The status of the job.</returns>
        public JobStatus WaitForCompletion()
        {
            JobStatus status;

            int sleep    = 2000;
            int maxSleep = 20000;
            int retries  = 0;

            while (true)
            {
                try
                {
                    string msg = null;
                    switch (status = this.GetStatus())
                    {
                    case JobStatus.Success:
                    case JobStatus.Failure:
                    case JobStatus.Cancelled:
                        return(status);

                    case JobStatus.NotSubmitted:
                        msg = "The job to create this table has not been submitted yet.  Waiting ...";
                        break;

                    case JobStatus.Running:
                        msg = "The job to create this table is still running. Waiting ...";
                        break;

                    case JobStatus.Waiting:
                        msg = "The job to create this table is still queued. Waiting ...";
                        break;

                    default:
                        throw new DryadLinqException(DryadLinqErrorCode.UnexpectedJobStatus,
                                                     String.Format(SR.UnexpectedJobStatus, status.ToString()));
                    }

                    retries = 0;
                    DryadLinqClientLog.Add(msg);
                }
                catch (System.Net.WebException)
                {
                    retries++;
                    sleep = maxSleep;
                    DryadLinqClientLog.Add("Error contacting web server while querying job status. Waiting ...");
                }

                if (retries > 5)
                {
                    throw new DryadLinqException(DryadLinqErrorCode.JobStatusQueryError,
                                                 SR.JobStatusQueryError);
                }

                // Sleep for a bit before checking the state again
                if (sleep < maxSleep)
                {
                    sleep = Math.Min(maxSleep, (int)(sleep * 1.05));
                }
                System.Threading.Thread.Sleep(sleep);
            }
        }