From 9cfb714322dea174044fee2ece72485443287140 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Mon, 18 Nov 2019 10:38:07 +0000 Subject: [PATCH] CA-330814: Code clean-up in the XenOvfTransport project. Signed-off-by: Konstantina Chremmou --- .../Actions/OVFActions/ApplianceAction.cs | 2 +- XenOvfTransport/Export.cs | 14 +-- XenOvfTransport/Http.cs | 16 +-- XenOvfTransport/Import.cs | 48 ++++---- XenOvfTransport/XenOvfTransportBase.cs | 50 ++------ XenOvfTransport/XenOvfTransportEvent.cs | 114 +++++------------- XenOvfTransport/iSCSI.cs | 22 ++-- 7 files changed, 86 insertions(+), 180 deletions(-) diff --git a/XenAdmin/Actions/OVFActions/ApplianceAction.cs b/XenAdmin/Actions/OVFActions/ApplianceAction.cs index b3a3f75c6..3ee387e30 100644 --- a/XenAdmin/Actions/OVFActions/ApplianceAction.cs +++ b/XenAdmin/Actions/OVFActions/ApplianceAction.cs @@ -90,7 +90,7 @@ namespace XenAdmin.Actions.OVFActions InitialiseTicker(); } - protected void UpdateHandler(XenOvfTranportEventArgs e) + protected void UpdateHandler(XenOvfTransportEventArgs e) { if (!string.IsNullOrEmpty(e.Message)) Description = e.Message; diff --git a/XenOvfTransport/Export.cs b/XenOvfTransport/Export.cs index 83fa1618e..2246d31b0 100644 --- a/XenOvfTransport/Export.cs +++ b/XenOvfTransport/Export.cs @@ -74,7 +74,7 @@ namespace XenOvfTransport string ovffilename = Path.Combine(targetPath, string.Format(@"{0}.ovf", ovfname)); OVF.SaveAs(ovfEnv, ovffilename); } - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ExportThreadComplete, "Export", Messages.COMPLETED_EXPORT)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Export, Messages.COMPLETED_EXPORT)); return ovfEnv; } @@ -127,7 +127,7 @@ namespace XenOvfTransport if (vm.power_state != vm_power_state.Halted && vm.power_state != vm_power_state.Suspended) { var message = string.Format(Messages.ERROR_VM_NOT_HALTED, vm.Name()); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ExportProgress, "Export", message)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Export, message)); log.Info($"VM {vm.Name()} ({vmRef.opaque_ref}) is neither halted nor suspended."); throw new Exception(message); } @@ -426,11 +426,11 @@ namespace XenOvfTransport label, uuid, Thread.CurrentThread.ManagedThreadId); } - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOn, "Export", string.Format(Messages.FILES_TRANSPORT_SETUP, uuid + ".vhd"))); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Export, string.Format(Messages.FILES_TRANSPORT_SETUP, uuid + ".vhd"))); using (Stream source = m_iscsi.Connect(XenSession, uuid, true)) { - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOff, "Export", "")); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Export, "")); using (FileStream fs = new FileStream(destinationFilename, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None)) { // Create a geometry to give to DiscUtils.Vhd.Disk.InitializeDynamic() just so it doesn't override capacity @@ -458,14 +458,12 @@ namespace XenOvfTransport throw; var msg = string.Format(Messages.ISCSI_COPY_ERROR, destinationFilename); log.Error($"Failed to transfer virtual disk {destinationFilename}", ex); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.Failure, "Export", msg, ex)); throw new Exception(msg, ex); } finally { - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOn, "Export", string.Format(Messages.FILES_TRANSPORT_CLEANUP, uuid + ".vhd"))); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Export, string.Format(Messages.FILES_TRANSPORT_CLEANUP, uuid + ".vhd"))); m_iscsi.Disconnect(XenSession); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOff, "Export", "")); } } } @@ -475,7 +473,7 @@ namespace XenOvfTransport } } - private void iscsi_UpdateHandler(XenOvfTranportEventArgs e) + private void iscsi_UpdateHandler(XenOvfTransportEventArgs e) { OnUpdate(e); } diff --git a/XenOvfTransport/Http.cs b/XenOvfTransport/Http.cs index 634d7698b..bfb9f354d 100644 --- a/XenOvfTransport/Http.cs +++ b/XenOvfTransport/Http.cs @@ -48,9 +48,9 @@ namespace XenOvfTransport { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public Action UpdateHandler { get; set; } + public Action UpdateHandler { get; set; } - private void OnUpdate(XenOvfTranportEventArgs e) + private void OnUpdate(XenOvfTransportEventArgs e) { if (UpdateHandler != null) UpdateHandler.Invoke(e); @@ -256,7 +256,7 @@ namespace XenOvfTransport long bytessent = offset; int i = 0; bool skipblock = false; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "SendData Start", "Disk Copy", (ulong)offset, (ulong)filesize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, "Disk Copy", (ulong)offset, (ulong)filesize)); while (true) { // Form: chunked @@ -293,7 +293,7 @@ namespace XenOvfTransport fullblock.AddRange(endblock); http.Write(fullblock.ToArray(), 0, fullblock.Count); bytessent += n; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileProgress, "SendData Start", "Disk Copy", (ulong)bytessent, (ulong)filesize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, "Disk Copy", (ulong)bytessent, (ulong)filesize)); Thread.Sleep(100); } else @@ -324,7 +324,7 @@ namespace XenOvfTransport http.Write(finalblock, 0, finalblock.Length); http.Flush(); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileComplete, "SendData Completed", "Disk Copy", (ulong)bytessent, (ulong)filesize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, "Disk Copy", (ulong)bytessent, (ulong)filesize)); log.DebugFormat("=== {0} === Total {1} : Full {2}", i, @@ -337,7 +337,7 @@ namespace XenOvfTransport byte[] block = new byte[MB]; ulong p = 0; int n = 0; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "SendData Start", "Disk Copy", 0, (ulong)filesize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, "Disk Copy", 0, (ulong)filesize)); while (true) { @@ -345,7 +345,7 @@ namespace XenOvfTransport { n = filestream.Read(block, 0, block.Length); if (n <= 0) break; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileProgress, "SendData Start", "Disk Copy", p, (ulong)filesize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, "Disk Copy", p, (ulong)filesize)); if (Cancel) { log.Warn("OVF.Tools.Http.SendData IMPORT CANCELED: resulting vm may be bad."); @@ -367,7 +367,7 @@ namespace XenOvfTransport } } http.Flush(); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileComplete, "SendData Completed", "Disk Copy", p, (ulong)filesize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, "Disk Copy", p, (ulong)filesize)); } internal string ReadLine(Stream stream) diff --git a/XenOvfTransport/Import.cs b/XenOvfTransport/Import.cs index d0ab65fa0..ea8c50549 100644 --- a/XenOvfTransport/Import.cs +++ b/XenOvfTransport/Import.cs @@ -396,8 +396,8 @@ namespace XenOvfTransport if (installSection != null && installSection.Length == 1) { - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOn, "Import", Messages.START_POST_INSTALL_INSTRUCTIONS)); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ImportProgress, "Import", Messages.START_POST_INSTALL_INSTRUCTIONS)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, Messages.START_POST_INSTALL_INSTRUCTIONS)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, Messages.START_POST_INSTALL_INSTRUCTIONS)); HandleInstallSection(xenSession, vmRef, installSection[0]); } ShowSystem(xenSession, vmRef); @@ -435,21 +435,21 @@ namespace XenOvfTransport } } - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOff, "Import", "")); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, "")); int _processId = System.Diagnostics.Process.GetCurrentProcess().Id; string _touchFile = Path.Combine(pathToOvf, "xen__" + _processId); //added check again as Delete needs write permissions and even if the file does not exist import will fail if the user has read only permissions if (File.Exists(_touchFile)) File.Delete(_touchFile); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ImportThreadComplete, "Import", Messages.COMPLETED_IMPORT)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, Messages.COMPLETED_IMPORT)); } #endregion #region PRIVATE - private void http_UpdateHandler(XenOvfTranportEventArgs e) + private void http_UpdateHandler(XenOvfTransportEventArgs e) { OnUpdate(e); } @@ -593,12 +593,12 @@ namespace XenOvfTransport if (passcode != null) { var statusMessage = string.Format(Messages.START_FILE_DECRYPTION, filename); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOn, "Security", statusMessage)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Security, statusMessage)); log.Debug($"Decrypting {filename}"); OVF.DecryptToTempFile(EncryptionClass, filename, version, passcode, encryptfilename); sourcefile = encryptfilename; statusMessage += Messages.COMPLETE; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOff, "Security", statusMessage)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Security, statusMessage)); } #endregion @@ -618,13 +618,13 @@ namespace XenOvfTransport ext = Path.GetExtension(uncompressedfilename); } var statusMessage = string.Format(Messages.START_FILE_EXPANSION, filename); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOn, "Compression", statusMessage)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Compression, statusMessage)); var ovfCompressor = new OvfCompressor(); ovfCompressor.UncompressFile(sourcefile, uncompressedfilename, compression); if (File.Exists(encryptfilename)) { File.Delete(encryptfilename); } sourcefile = uncompressedfilename; statusMessage += Messages.COMPLETE; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOff, "Compression", statusMessage)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Compression, statusMessage)); } #endregion @@ -837,7 +837,7 @@ namespace XenOvfTransport #region UPLOAD iSCSI STREAM - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "Import", string.Format(Messages.FILES_TRANSPORT_SETUP, _currentfilename))); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, string.Format(Messages.FILES_TRANSPORT_SETUP, _currentfilename))); m_iscsi = new iSCSI { UpdateHandler = iscsi_UpdateHandler, @@ -862,7 +862,7 @@ namespace XenOvfTransport } finally { - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "Import", string.Format(Messages.FILES_TRANSPORT_CLEANUP,_currentfilename))); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, string.Format(Messages.FILES_TRANSPORT_CLEANUP,_currentfilename))); m_iscsi.Disconnect(xenSession); } #endregion @@ -897,7 +897,7 @@ namespace XenOvfTransport } #region UPLOAD iSCSI STREAM - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "Import", string.Format(Messages.FILES_TRANSPORT_SETUP, _currentfilename))); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, string.Format(Messages.FILES_TRANSPORT_SETUP, _currentfilename))); m_iscsi = new iSCSI { UpdateHandler = iscsi_UpdateHandler, @@ -918,7 +918,7 @@ namespace XenOvfTransport else { log.WarnFormat("System will not be bootable, cannot find [{0}] to extract master boot record.", vhdfile); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "Import", Messages.WARNING_TARGET_NOT_BOOTABLE)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, Messages.WARNING_TARGET_NOT_BOOTABLE)); } m_iscsi.ScsiDisk.Signature = new Random().Next(); @@ -957,7 +957,7 @@ namespace XenOvfTransport } finally { - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "Import", string.Format(Messages.FILES_TRANSPORT_CLEANUP, _currentfilename))); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, string.Format(Messages.FILES_TRANSPORT_CLEANUP, _currentfilename))); m_iscsi.Disconnect(xenSession); } #endregion @@ -966,7 +966,7 @@ namespace XenOvfTransport return vdiRef; } - private void iscsi_UpdateHandler(XenOvfTranportEventArgs e) + private void iscsi_UpdateHandler(XenOvfTransportEventArgs e) { OnUpdate(e); } @@ -1134,7 +1134,7 @@ namespace XenOvfTransport headers.Add("User-Agent", "XenP2VClient/1.5"); try { - http.Put(filestream, _XenServer, p2VUri, headers, 0, capacity, false); + http.Put(filestream, _uri, p2VUri, headers, 0, capacity, false); } catch (Exception ex) { @@ -1797,14 +1797,14 @@ namespace XenOvfTransport "Import: Then attach disks with labels ending with \"+\" to the device number defined before the +." + "Import: ===========================================================", vmRef); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.Progress, "Import", Messages.WARNING_ADMIN_REQUIRED)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, Messages.WARNING_ADMIN_REQUIRED)); } } #endregion } #endregion - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ImportProgress, "CD/DVD Drive", + OnUpdate(new XenOvfTransportEventArgs(TransportStep.CdDvdDrive, string.Format(Messages.DEVICE_ATTACHED, Messages.CD_DVD_DEVICE))); log.Debug("Import.AddResourceSettingData: CD/DVD ROM Added"); @@ -2028,7 +2028,7 @@ namespace XenOvfTransport "Import: Then manually attach disks with labels with {0}_# that are not attached to {0}" + "Import: ===========================================================", vmName); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.Progress, "Import", Messages.WARNING_ADMIN_REQUIRED)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Import, Messages.WARNING_ADMIN_REQUIRED)); } } } @@ -2526,11 +2526,11 @@ namespace XenOvfTransport { downloadupdatemsg = string.Format(Messages.ISCSI_COPY_PROGRESS, tmpfilename); _downloadexception = null; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "Web Download Start", downloadupdatemsg, 0, _filedownloadsize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Download, downloadupdatemsg, 0, _filedownloadsize)); WebClient wc = new WebClient(); wc.Proxy = XenAdmin.XenAdminConfigManager.Provider.GetProxyFromSettings(null, false); - wc.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(wc_DownloadFileCompleted); - wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); + wc.DownloadFileCompleted += wc_DownloadFileCompleted; + wc.DownloadProgressChanged += wc_DownloadProgressChanged; wc.DownloadFileAsync(filetodownload, tmpfilename); uridownloadcomplete.WaitOne(); if (_downloadexception != null) @@ -2538,14 +2538,14 @@ namespace XenOvfTransport if (!Path.GetExtension(tmpfilename).Equals(".pvp")) // don't worry bout pvp files, we don't use them. throw _downloadexception; } - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileComplete, "Web Download Completed", downloadupdatemsg, _filedownloadsize, _filedownloadsize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Download, downloadupdatemsg, _filedownloadsize, _filedownloadsize)); } return tmpfilename; } private void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileProgress, "Web Download Update", downloadupdatemsg, (ulong)e.BytesReceived, (ulong)_filedownloadsize)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.Download, downloadupdatemsg, (ulong)e.BytesReceived, (ulong)_filedownloadsize)); } private void wc_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { diff --git a/XenOvfTransport/XenOvfTransportBase.cs b/XenOvfTransport/XenOvfTransportBase.cs index 149dedff0..7ad45e159 100644 --- a/XenOvfTransport/XenOvfTransportBase.cs +++ b/XenOvfTransport/XenOvfTransportBase.cs @@ -30,10 +30,6 @@ */ using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Security; -using System.Security.Cryptography.X509Certificates; using XenAPI; @@ -41,36 +37,27 @@ namespace XenOvfTransport { public class XenOvfTransportBase { - public Action UpdateHandler { get; set; } + public Action UpdateHandler { private get; set; } protected string m_networkUuid; protected bool m_isTvmIpStatic; protected string m_tvmIpAddress; protected string m_tvmSubnetMask; protected string m_tvmGateway; - - protected void OnUpdate(XenOvfTranportEventArgs e) - { - if (UpdateHandler != null) - UpdateHandler.Invoke(e); - } - protected readonly Session XenSession; - internal Uri _XenServer; - + protected readonly Uri _uri; protected iSCSI m_iscsi; private bool m_cancel; - protected XenOvfTransportBase() + protected XenOvfTransportBase(Uri uri, Session session) { - ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate; + _uri = uri; + XenSession = session; } - protected XenOvfTransportBase(Uri xenserver, Session session) - : this() + protected void OnUpdate(XenOvfTransportEventArgs e) { - _XenServer = xenserver; - XenSession = session; + UpdateHandler?.Invoke(e); } public bool Cancel @@ -92,28 +79,5 @@ namespace XenOvfTransport m_tvmSubnetMask = tvmSubnetMask; m_tvmGateway = tvmGateway; } - - public static bool ValidateServerCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors) - { - return true; - } - - public static VM FindiSCSI(XenAPI.Session xenSession) - { - Dictionary,VM> iSCSIDict = VM.get_all_records(xenSession); - - foreach (XenRef key in iSCSIDict.Keys) - { - if (iSCSIDict[key].is_a_template) - { - if (iSCSIDict[key].other_config.ContainsKey("transfervm") && - iSCSIDict[key].other_config["transfervm"] == "true") - { - return iSCSIDict[key]; - } - } - } - return null; - } } } diff --git a/XenOvfTransport/XenOvfTransportEvent.cs b/XenOvfTransport/XenOvfTransportEvent.cs index 11a08c37b..5ac9c0155 100644 --- a/XenOvfTransport/XenOvfTransportEvent.cs +++ b/XenOvfTransport/XenOvfTransportEvent.cs @@ -30,97 +30,41 @@ */ using System; -using System.Collections.Generic; -using System.Text; namespace XenOvfTransport { - public enum XenOvfTranportEventType + public class XenOvfTransportEventArgs : EventArgs { - FileStart, - FileProgress, - FileComplete, - FileCancelled, - ImportStart, - ImportProgress, - ImportThreadComplete, - ImportComplete, - ImportCancelled, - ExportStart, - ExportProgress, - ExportThreadComplete, - ExportComplete, - ExportCancelled, - Progress, - MarqueeOn, - MarqueeOff, - Failure, - Unknown + public XenOvfTransportEventArgs(TransportStep step, string message) + { + Step = step; + Message = message; + } + + public XenOvfTransportEventArgs(TransportStep step, string message, ulong transferred, ulong total) + : this(step, message) + { + Total = total; + Transferred = transferred; + } + + public TransportStep Step { get; } + + public string Message { get; } + + public ulong Total { get; } + + public ulong Transferred { get; } } - public class XenOvfTranportEventArgs : EventArgs + public enum TransportStep { - private XenOvfTranportEventType _type = XenOvfTranportEventType.Unknown; - private ulong _total; - private ulong _transfered; - private string _target; - private string _message; - private Exception _exception; - - public XenOvfTranportEventArgs(XenOvfTranportEventType type, string target, string message) - { - _type = type; - _target = target; - _message = message; - } - public XenOvfTranportEventArgs(XenOvfTranportEventType type, string target, string message, Exception exception) - { - _type = type; - _target = target; - _message = message; - _exception = exception; - } - - public XenOvfTranportEventArgs(XenOvfTranportEventType type, string target, string message, ulong transfered, ulong total) - { - _type = type; - _target = target; - _message = message; - _total = total; - _transfered = transfered; - } - - public string Target - { - get { return _target; } - } - - public string Message - { - get { return _message; } - } - - public ulong Total - { - get { return _total; } - } - - public ulong Transfered - { - get { return _transfered; } - } - - public XenOvfTranportEventType Type - { - get { return _type; } - } - - public Exception exception - { - get - { - return _exception; - } - } + Export, + Import, + Security, + Compression, + CdDvdDrive, + SendData, + Download } } diff --git a/XenOvfTransport/iSCSI.cs b/XenOvfTransport/iSCSI.cs index fa950e752..eb5d3d205 100644 --- a/XenOvfTransport/iSCSI.cs +++ b/XenOvfTransport/iSCSI.cs @@ -63,7 +63,7 @@ namespace XenOvfTransport public bool Cancel { get; set; } - public Action UpdateHandler { get; set; } + public Action UpdateHandler { get; set; } public Disk ScsiDisk { @@ -223,7 +223,7 @@ namespace XenOvfTransport _bytestotal = (ulong)source.Length; string updatemsg = string.Format(Messages.ISCSI_COPY_PROGRESS, filename); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "SendData Start", updatemsg, 0, _bytestotal)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, 0, _bytestotal)); // Create a hash algorithm to compute the hash from separate blocks during the copy. using (var hashAlgorithm = System.Security.Cryptography.HashAlgorithm.Create(_hashAlgorithmName)) @@ -264,7 +264,7 @@ namespace XenOvfTransport _bytescopied = (ulong)offset; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileProgress, "SendData Start", updatemsg, _bytescopied, _bytestotal)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, _bytescopied, _bytestotal)); } catch (Exception ex) { @@ -290,7 +290,7 @@ namespace XenOvfTransport } destination.Flush(); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileComplete, "SendData Completed", updatemsg, _bytescopied, _bytestotal)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, _bytescopied, _bytestotal)); log.InfoFormat("Finished copying {0} bytes to {1} via iSCSI.", source.Length, filename); } @@ -305,7 +305,7 @@ namespace XenOvfTransport long limit = (long)_bytescopied; string updatemsg = string.Format(Messages.ISCSI_VERIFY_PROGRESS, filename); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "SendData Start", updatemsg, 0, (ulong)limit)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, 0, (ulong)limit)); // Create a hash algorithm to compute the hash from separate blocks in the same way as Copy(). using (var hashAlgorithm = System.Security.Cryptography.HashAlgorithm.Create(_hashAlgorithmName)) @@ -337,7 +337,7 @@ namespace XenOvfTransport offset += bytesRead; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileProgress, "SendData Start", updatemsg, (ulong)offset, (ulong)limit)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, (ulong)offset, (ulong)limit)); } catch (Exception ex) { @@ -364,7 +364,7 @@ namespace XenOvfTransport } } - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileComplete, "SendData Completed", updatemsg, (ulong)offset, (ulong)limit)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, (ulong)offset, (ulong)limit)); log.InfoFormat("Finished verifying {0} bytes in {1} after copy via iSCSI.", target.Length, filename); } @@ -378,7 +378,7 @@ namespace XenOvfTransport ulong p = 0; string updatemsg = string.Format(Messages.ISCSI_WIM_PROGRESS_FORMAT, fileindex, filecount, filename); - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileStart, "SendData Start", updatemsg, 0, _bytestotal)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, 0, _bytestotal)); while (true) { @@ -405,7 +405,7 @@ namespace XenOvfTransport _bytescopied = p; if (p >= (ulong)source.Length) break; - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileProgress, "SendData Start", updatemsg, _bytescopied, _bytestotal)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, _bytescopied, _bytestotal)); } catch (Exception ex) { @@ -422,7 +422,7 @@ namespace XenOvfTransport if (source != null) source.Close(); if (destination != null) destination.Close(); } - OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.FileComplete, "SendData Completed", updatemsg, _bytescopied, _bytestotal)); + OnUpdate(new XenOvfTransportEventArgs(TransportStep.SendData, updatemsg, _bytescopied, _bytestotal)); log.Info("iSCSI.Copy done with copy."); } @@ -473,7 +473,7 @@ namespace XenOvfTransport #region PRIVATE - private void OnUpdate(XenOvfTranportEventArgs e) + private void OnUpdate(XenOvfTransportEventArgs e) { if (UpdateHandler != null) UpdateHandler.Invoke(e);