コード例 #1
0
ファイル: Storage.cs プロジェクト: codedecay/SBTransfer
 protected void setJobStatusVerified(SA_JobStatus js)
 {
     if (js.TerseStatus == JobStatus.Created)
       {
     js.TerseStatus = JobStatus.VerifiedAtSource;
     js.VerboseStatus = "Job verificeret ved kilde";
       }
       if (js.TerseStatus != JobStatus.Transferred)
     return;
       js.TerseStatus = JobStatus.VerifiedAtDestination;
       js.VerboseStatus = "Job verificeret ved destination";
 }
コード例 #2
0
ファイル: Storage.cs プロジェクト: codedecay/SBTransfer
 protected void setJobStatusError(SA_JobStatus js)
 {
     if (js.TerseStatus == JobStatus.Created)
       {
     js.TerseStatus = JobStatus.SourceError;
     js.VerboseStatus = "Verificeringsfejl ved kilde";
       }
       if (js.TerseStatus != JobStatus.Transferred)
     return;
       js.TerseStatus = JobStatus.DestinationError;
       js.VerboseStatus = "Verificeringsfejl ved destination";
 }
コード例 #3
0
ファイル: Storage.cs プロジェクト: codedecay/SBTransfer
 protected void setJobStatusMD5Error(SA_JobStatus js)
 {
     if (js.TerseStatus == JobStatus.Created)
       {
     js.TerseStatus = JobStatus.SourceMD5Error;
     js.VerboseStatus = "MD5 fejl ved kilde\r\nBeregnet MD5=";
       }
       if (js.TerseStatus != JobStatus.Transferred)
     return;
       js.TerseStatus = JobStatus.DestinationMD5Error;
       js.VerboseStatus = "MD5 fejl ved destination\r\nBeregnet MD5=";
 }
コード例 #4
0
ファイル: LocalStorage.cs プロジェクト: codedecay/SBTransfer
 protected override void bw_Transfer_DoWork(object sender, DoWorkEventArgs e)
 {
     SA_StorageWorker saStorageWorker = sender as SA_StorageWorker;
     SA_JobStatus saJobStatus1 = new SA_JobStatus(saStorageWorker.job.Status);
     long num1 = 0L;
     int num2 = 0;
     int count = 10000;
     byte[] buffer = new byte[count];
     try
     {
         FileStream fileStream1 = new FileStream((saStorageWorker.job.source as LocalStorage).LocalPath + saStorageWorker.job.FileName, FileMode.Open);
         FileStream fileStream2 = new FileStream((saStorageWorker.job.destination as LocalStorage).LocalPath + saStorageWorker.job.FileName, FileMode.Create);
         long length = fileStream1.Length;
         while (fileStream1.Position < fileStream1.Length)
         {
             num1 += (long)fileStream1.Read(buffer, 0, count);
             if (saStorageWorker.CancellationPending)
             {
                 fileStream1.Close();
                 fileStream2.Close();
                 e.Result = (object)saJobStatus1;
                 return;
             }
             else
             {
                 fileStream2.Write(buffer, 0, buffer.Length);
                 int percentProgress = (int)((double)num1 * 100.0 / (double)length);
                 if (percentProgress != num2)
                 {
                     saJobStatus1.CurrentQuantity = num1;
                     saJobStatus1.VerboseStatus = "Overfører (" + (object)percentProgress + "%)";
                     saStorageWorker.ReportProgress(percentProgress, (object)saJobStatus1);
                     num2 = percentProgress;
                 }
             }
         }
         saJobStatus1.TerseStatus = JobStatus.Transferred;
         fileStream1.Close();
         fileStream2.Close();
     }
     catch (Exception ex)
     {
         if (ex is IOException && File.Exists((saStorageWorker.job.destination as LocalStorage).LocalPath + saStorageWorker.job.FileName))
         {
             saJobStatus1.TerseStatus = JobStatus.AlreadyTransferred;
             SA_JobStatus saJobStatus2 = saJobStatus1;
             string str = saJobStatus2.VerboseStatus + " (" + saStorageWorker.job.destination.Name + ")";
             saJobStatus2.VerboseStatus = str;
         }
         else
             saJobStatus1.TerseStatus = JobStatus.TransferError;
         e.Result = (object)saJobStatus1;
     }
     e.Result = (object)saJobStatus1;
 }
コード例 #5
0
ファイル: LocalStorage.cs プロジェクト: codedecay/SBTransfer
 protected override void bw_Verify_DoWork(object sender, DoWorkEventArgs e)
 {
     SA_StorageWorker saStorageWorker = sender as SA_StorageWorker;
     SA_JobStatus js = new SA_JobStatus(saStorageWorker.job.Status);
     if (File.Exists(this.LocalPath + saStorageWorker.job.FileName))
     {
         FileInfo fileInfo = new FileInfo(this.LocalPath + saStorageWorker.job.FileName);
         js.TargetQuantity = fileInfo.Length;
         if (this.VerifyMD5)
         {
             saStorageWorker.ReportProgress(0, (object)js);
             int num1 = 0;
             long num2 = 0L;
             Stream stream = (Stream)File.OpenRead(this.LocalPath + saStorageWorker.job.FileName);
             HashAlgorithm hashAlgorithm = (HashAlgorithm)MD5.Create();
             long length = stream.Length;
             byte[] buffer = new byte[4096];
             int num3 = stream.Read(buffer, 0, buffer.Length);
             long num4 = num2 + (long)num3;
             while (!saStorageWorker.CancellationPending)
             {
                 int inputCount = num3;
                 byte[] numArray = buffer;
                 buffer = new byte[4096];
                 num3 = stream.Read(buffer, 0, buffer.Length);
                 num4 += (long)num3;
                 if (num3 == 0)
                     hashAlgorithm.TransformFinalBlock(numArray, 0, inputCount);
                 else
                     hashAlgorithm.TransformBlock(numArray, 0, inputCount, numArray, 0);
                 int percentProgress = (int)((double)num4 * 100.0 / (double)length);
                 if (percentProgress != num1)
                 {
                     js.VerboseStatus = "Verificerer MD5 (" + (object)percentProgress + "%)";
                     saStorageWorker.ReportProgress(percentProgress, (object)js);
                     num1 = percentProgress;
                 }
                 if (num3 == 0)
                 {
                     js.CalculatedMD5 = BitConverter.ToString(hashAlgorithm.Hash).Replace("-", "").ToLower();
                     if (saStorageWorker.job.MD5 == js.CalculatedMD5)
                     {
                         this.setJobStatusVerified(js);
                         goto label_16;
                     }
                     else
                     {
                         this.setJobStatusMD5Error(js);
                         goto label_16;
                     }
                 }
             }
             stream.Close();
             js.VerboseStatus = "afbrudt af bruger";
             e.Result = (object)js;
             return;
         }
         else
             this.setJobStatusVerified(js);
     }
     else
         this.setJobStatusError(js);
     label_16:
     e.Result = (object)js;
 }
コード例 #6
0
ファイル: SA_JobStatus.cs プロジェクト: codedecay/SBTransfer
 public SA_JobStatus(SA_JobStatus j)
     : base((SA_ProgressStatus) j)
 {
 }
コード例 #7
0
ファイル: Job.cs プロジェクト: codedecay/SBTransfer
 private void bw_Sleep_DoWork(object sender, DoWorkEventArgs e)
 {
     SA_StorageWorker saStorageWorker = sender as SA_StorageWorker;
       SA_JobStatus saJobStatus = new SA_JobStatus(saStorageWorker.job.Status);
       string verboseStatus = saJobStatus.VerboseStatus;
       for (int percentProgress = this.Status.TerseStatus != JobStatus.SourceMD5Error && this.Status.TerseStatus != JobStatus.DestinationMD5Error ? saStorageWorker.job.GracePeriod : saStorageWorker.job.GracePeriodMD5; percentProgress > 0; --percentProgress)
       {
     saJobStatus.VerboseStatus = string.Concat(new object[4]
     {
       (object) verboseStatus,
       (object) " (Nyt forsøg om ",
       (object) percentProgress,
       (object) " s)"
     });
     saStorageWorker.ReportProgress(percentProgress, (object) saJobStatus);
     Thread.Sleep(1000);
       }
       saJobStatus.VerboseStatus = verboseStatus;
       e.Result = (object) this.Status;
 }
コード例 #8
0
 protected override void bw_Verify_DoWork(object sender, DoWorkEventArgs e)
 {
     SA_StorageWorker saStorageWorker = sender as SA_StorageWorker;
     SA_JobStatus js = new SA_JobStatus(saStorageWorker.job.Status);
     this.setJobStatusVerified(js);
     e.Result = (object)js;
 }
コード例 #9
0
        protected override void bw_Transfer_DoWork(object sender, DoWorkEventArgs e)
        {
            SA_StorageWorker saStorageWorker = sender as SA_StorageWorker;
            SA_JobStatus saJobStatus = new SA_JobStatus(saStorageWorker.job.Status);
            saJobStatus.VerboseStatus = "Overfører";
            string id = string.Empty;

            try
            {
                if (saStorageWorker.job.destination is LocalStorage) //get
                {

                    id = stub.Get(new Filename(saStorageWorker.job.FileName), new DirectoryPath((saStorageWorker.job.destination as LocalStorage).LocalPath));
                }
                if (saStorageWorker.job.source is LocalStorage) //put
                {
                    id = stub.Put(new FileInfo((saStorageWorker.job.source as LocalStorage).LocalPath + saStorageWorker.job.FileName));
                }
                AutoResetEvent ResetEvent = SetEvent(id);
                ResetEvent.WaitOne();
                IResponseEventArgs args = GetResults(id);
                if (args.RequestSucces)
                {
                    saJobStatus.TerseStatus = JobStatus.Transferred;
                    saJobStatus.VerboseStatus = "Job overført til " + saStorageWorker.job.destination.Name;
                }
                else
                {
                    saJobStatus.TerseStatus = JobStatus.TransferError;
                    saJobStatus.VerboseStatus = "Overførselsfejl " + this.Name;
                }
            }
            catch (Exception ex)
            {
                saJobStatus.TerseStatus = JobStatus.TransferError;
                saJobStatus.VerboseStatus = "Overførselsfejl " + this.Name;
                Program.Events.LogOrNotify(ex);
                e.Result = (object)saJobStatus;
            }
            e.Result = (object)saJobStatus;
        }
コード例 #10
0
 protected override void bw_Finalize_DoWork(object sender, DoWorkEventArgs e)
 {
     SA_StorageWorker saStorageWorker = sender as SA_StorageWorker;
       SA_JobStatus saJobStatus = new SA_JobStatus(saStorageWorker.job.Status);
       try
       {
     string str = this.tmpPath + "\\ApproveResult" + saStorageWorker.job.UniqueID + ".txt";
     Process process = this.Execute("approve " + saStorageWorker.job.FileName + " " + str);
     while (!process.HasExited)
     {
       Thread.Sleep(1000);
       saStorageWorker.ReportProgress(100);
       if (saStorageWorker.CancellationPending)
       {
     process.Kill();
     File.Delete(str);
     e.Result = (object) saJobStatus;
     return;
       }
     }
     Thread.Sleep(1000);
     if (this.Result(str) == "0")
     {
       saJobStatus.TerseStatus = JobStatus.Approved;
       saJobStatus.VerboseStatus = "Job godkendt på " + this.Name;
     }
     else
     {
       saJobStatus.TerseStatus = JobStatus.ApprovalError;
       saJobStatus.VerboseStatus = "Fejl ved godkendelse på " + this.Name;
     }
     File.Delete(str);
     e.Result = (object) saJobStatus;
       }
       catch (Exception ex)
       {
     saJobStatus.TerseStatus = JobStatus.ApprovalError;
     saJobStatus.VerboseStatus = "Fejl ved godkendelse på " + this.Name;
     Program.Events.LogOrNotify(ex);
     e.Result = (object) saJobStatus;
       }
 }
コード例 #11
0
 protected override void bw_Verify_DoWork(object sender, DoWorkEventArgs e)
 {
     SA_StorageWorker saStorageWorker = sender as SA_StorageWorker;
       SA_JobStatus js = new SA_JobStatus(saStorageWorker.job.Status);
       Process process1 = new Process();
       string str1 = this.tmpPath + "\\getmd5" + saStorageWorker.job.FileName + ".txt";
       string str2 = this.tmpPath + "\\getmd5_result" + saStorageWorker.job.FileName + ".txt";
       try
       {
     Process process2 = this.Execute("md5 " + saStorageWorker.job.FileName + " " + str1 + " " + str2);
     while (!process2.HasExited)
     {
       Thread.Sleep(1000);
       saStorageWorker.ReportProgress(100);
       if (saStorageWorker.CancellationPending)
       {
     process2.Kill();
     File.Delete(str2);
     File.Delete(str1);
     e.Result = (object) js;
     return;
       }
     }
     Thread.Sleep(200);
     if (this.Result(str2) == "0")
     {
       js.CalculatedMD5 = this.Result(str1);
       if (js.CalculatedMD5 == saStorageWorker.job.MD5)
     this.setJobStatusVerified(js);
       else
     this.setJobStatusMD5Error(js);
     }
     else
       this.setJobStatusError(js);
     e.Result = (object) js;
     File.Delete(str2);
     File.Delete(str1);
       }
       catch (Exception ex)
       {
     this.setJobStatusMD5Error(js);
     Program.Events.LogOrNotify(ex);
     e.Result = (object) js;
       }
 }
コード例 #12
0
 protected override void bw_Transfer_DoWork(object sender, DoWorkEventArgs e)
 {
     SA_StorageWorker saStorageWorker = sender as SA_StorageWorker;
       SA_JobStatus saJobStatus = new SA_JobStatus(saStorageWorker.job.Status);
       saJobStatus.VerboseStatus = "Overfører";
       string str1 = "";
       try
       {
     if (saStorageWorker.job.destination is LocalStorage)
     {
       str1 = this.tmpPath + "\\GetResult" + saStorageWorker.job.UniqueID + ".txt";
       Process process = this.Execute("get " + saStorageWorker.job.FileName + " " + (saStorageWorker.job.destination as LocalStorage).LocalPath + saStorageWorker.job.FileName + " " + str1);
       while (!process.HasExited)
       {
     Thread.Sleep(1000);
     saStorageWorker.ReportProgress(100, (object) saJobStatus);
     if (saStorageWorker.CancellationPending)
     {
       process.Kill();
       File.Delete(str1);
       e.Result = (object) saJobStatus;
       return;
     }
       }
       Thread.Sleep(200);
       if (File.Exists(str1))
       {
     if (this.Result(str1) == "0")
     {
       saJobStatus.TerseStatus = JobStatus.Transferred;
       saJobStatus.VerboseStatus = "Job overført til " + saStorageWorker.job.destination.Name;
     }
     else
     {
       saJobStatus.TerseStatus = JobStatus.TransferError;
       saJobStatus.VerboseStatus = "Overførselsfejl " + this.Name;
     }
       }
     }
     if (saStorageWorker.job.source is LocalStorage)
     {
       str1 = this.tmpPath + "\\SendResult" + saStorageWorker.job.UniqueID + ".txt";
       string str2 = this.tmpPath + "\\SendResultMD5" + saStorageWorker.job.UniqueID + ".txt";
       Process process = this.Execute("sendmd5 " + (saStorageWorker.job.source as LocalStorage).LocalPath + saStorageWorker.job.FileName + " " + str2 + " " + str1);
       while (!process.HasExited)
       {
     Thread.Sleep(1000);
     saStorageWorker.ReportProgress(100, (object) saJobStatus);
     if (saStorageWorker.CancellationPending)
     {
       process.Kill();
       File.Delete(str1);
       File.Delete(str2);
       e.Result = (object) saJobStatus;
       return;
     }
       }
       Thread.Sleep(200);
       if (File.Exists(str1))
       {
     if (this.Result(str1) == "0")
     {
       if (this.Result(str2).ToLower() == saStorageWorker.job.MD5.ToLower())
       {
         saJobStatus.TerseStatus = JobStatus.VerifiedAtDestination;
         saJobStatus.CurrentQuantity = saJobStatus.TargetQuantity;
         saJobStatus.VerboseStatus = "Job godkendt på " + this.Name;
       }
       else
       {
         saJobStatus.TerseStatus = JobStatus.DestinationMD5Error;
         saJobStatus.VerboseStatus = "MD5 fejl på " + this.Name;
       }
       File.Delete(str2);
     }
     else
     {
       if (this.Result(str2).Contains("was stored!"))
       {
         saJobStatus.TerseStatus = JobStatus.AlreadyTransferred;
         saJobStatus.VerboseStatus = "Allerede lagret " + this.Name;
       }
       else
       {
         saJobStatus.TerseStatus = JobStatus.TransferError;
         saJobStatus.VerboseStatus = "Overførselsfejl " + this.Name;
       }
       File.Delete(str2);
     }
       }
     }
       }
       catch (Exception ex)
       {
     saJobStatus.TerseStatus = JobStatus.TransferError;
     saJobStatus.VerboseStatus = "Overførselsfejl " + this.Name;
     Program.Events.LogOrNotify(ex);
     e.Result = (object) saJobStatus;
       }
       File.Delete(str1);
       e.Result = (object) saJobStatus;
 }