public void UploadBlobAsync(CloudBlockBlob blob, string localFile, object state) { TransferType = TransferTypeEnum.Upload; //attempt to open the file first so that we throw an exception before getting into the async work using (FileStream fs = new FileStream(localFile, FileMode.Open, FileAccess.Read)) { } m_Blob = blob; m_FileName = localFile; BlobTransferWorkerDelegate worker = new BlobTransferWorkerDelegate(UploadBlobWorker); AsyncCallback completedCallback = new AsyncCallback(TaskCompletedCallback); lock (_sync) { if (TaskIsRunning) { throw new InvalidOperationException("The control is currently busy."); } AsyncOperation async = AsyncOperationManager.CreateOperation(state); MyAsyncContext context = new MyAsyncContext(); bool cancelled; worker.BeginInvoke(context, out cancelled, async, completedCallback, async); TaskIsRunning = true; TaskContext = context; } }
/// <summary> /// Uploads a file to an Azure blob asynchronously. /// </summary> /// <param name="localFile">The local file.</param> /// <exception cref="System.Exception">BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer.</exception> public ICancellableAsyncResult UploadBlobAsync(string localFile) { lock (workingLock) { if (!working) { working = true; } else { throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer."); } } // Attempt to open the file first so that we throw an exception before getting into the async work using (var fstemp = new FileStream(localFile, FileMode.Open, FileAccess.Read)) { } // Create an async op in order to raise the events back to the client on the correct thread. asyncOp = AsyncOperationManager.CreateOperation(this.blob); TransferType = TransferTypeEnum.Upload; fileName = localFile; var file = new FileInfo(fileName); long fileSize = file.Length; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); ProgressStream pstream = new ProgressStream(fs); pstream.ProgressChanged += pstream_ProgressChanged; pstream.SetLength(fileSize); this.blob.ServiceClient.ParallelOperationThreadCount = 10; asyncresult = this.blob.BeginUploadFromStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(this.blob, pstream)); return(asyncresult); }
public ProgressChangedEventArgs(long bytesRead, long totalLength, int fileId, TransferTypeEnum transferType) { this.bytesRead = bytesRead; this.totalLength = totalLength; this.fileId = fileId; this.transferType = transferType; }
public void DownloadBlobAsync(ICloudBlob blob, string LocalFile) { // The class currently stores state in class level variables so calling UploadBlobAsync or DownloadBlobAsync a second time will cause problems. // A better long term solution would be to better encapsulate the state, but the current solution works for the needs of my primary client. // Throw an exception if UploadBlobAsync or DownloadBlobAsync has already been called. lock (WorkingLock) { if (!Working) { Working = true; } else { throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer."); } } // Create an async op in order to raise the events back to the client on the correct thread. asyncOp = AsyncOperationManager.CreateOperation(blob); TransferType = TransferTypeEnum.Download; m_Blob = blob; m_FileName = LocalFile; m_Blob.FetchAttributes(); FileStream fs = new FileStream(m_FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); ProgressStream pstream = new ProgressStream(fs); pstream.ProgressChanged += pstream_ProgressChanged; pstream.SetLength(m_Blob.Properties.Length); m_Blob.ServiceClient.DefaultRequestOptions.ParallelOperationThreadCount = 10; asyncresult = m_Blob.BeginDownloadToStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(m_Blob, pstream)); }
/// <summary> /// Downloads a blob to a local file asynchronously. /// </summary> /// <param name="localFile">The local file.</param> /// <exception cref="System.Exception">BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer.</exception> public ICancellableAsyncResult DownloadBlobAsync(string localFile) { lock (workingLock) { if (!working) { working = true; } else { throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer."); } } // Create an async op in order to raise the events back to the client on the correct thread. asyncOp = AsyncOperationManager.CreateOperation(blob); TransferType = TransferTypeEnum.Download; fileName = localFile; this.blob.FetchAttributes(); FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); ProgressStream pstream = new ProgressStream(fs); pstream.ProgressChanged += pstream_ProgressChanged; pstream.SetLength(this.blob.Properties.Length); this.blob.ServiceClient.ParallelOperationThreadCount = 10; asyncresult = this.blob.BeginDownloadToStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(this.blob, pstream)); return(asyncresult); }
/// <summary> /// Initializes a new instance of the <see cref="KapiDialplanTransfer" /> class. /// </summary> /// <param name="applicationName">applicationName (required).</param> /// <param name="attendedTransferKeys">attendedTransferKeys.</param> /// <param name="callID">callID (required).</param> /// <param name="callerIDName">callerIDName.</param> /// <param name="callerIDNumber">callerIDNumber.</param> /// <param name="customChannelVars">customChannelVars.</param> /// <param name="eventCategory">eventCategory.</param> /// <param name="eventName">eventName.</param> /// <param name="insertAt">insertAt.</param> /// <param name="transferContext">transferContext.</param> /// <param name="transferLeg">transferLeg.</param> /// <param name="transferTo">transferTo (required).</param> /// <param name="transferType">transferType (required).</param> public KapiDialplanTransfer(ApplicationNameEnum applicationName = default(ApplicationNameEnum), string attendedTransferKeys = default(string), string callID = default(string), string callerIDName = default(string), string callerIDNumber = default(string), Object customChannelVars = default(Object), EventCategoryEnum?eventCategory = default(EventCategoryEnum?), EventNameEnum?eventName = default(EventNameEnum?), InsertAtEnum?insertAt = default(InsertAtEnum?), string transferContext = default(string), TransferLegEnum?transferLeg = default(TransferLegEnum?), string transferTo = default(string), TransferTypeEnum transferType = default(TransferTypeEnum)) { // to ensure "applicationName" is required (not null) if (applicationName == null) { throw new InvalidDataException("applicationName is a required property for KapiDialplanTransfer and cannot be null"); } else { this.ApplicationName = applicationName; } // to ensure "callID" is required (not null) if (callID == null) { throw new InvalidDataException("callID is a required property for KapiDialplanTransfer and cannot be null"); } else { this.CallID = callID; } // to ensure "transferTo" is required (not null) if (transferTo == null) { throw new InvalidDataException("transferTo is a required property for KapiDialplanTransfer and cannot be null"); } else { this.TransferTo = transferTo; } // to ensure "transferType" is required (not null) if (transferType == null) { throw new InvalidDataException("transferType is a required property for KapiDialplanTransfer and cannot be null"); } else { this.TransferType = transferType; } this.AttendedTransferKeys = attendedTransferKeys; this.CallerIDName = callerIDName; this.CallerIDNumber = callerIDNumber; this.CustomChannelVars = customChannelVars; this.EventCategory = eventCategory; this.EventName = eventName; this.InsertAt = insertAt; this.TransferContext = transferContext; this.TransferLeg = transferLeg; }
public void UploadBlobAsync(ICloudBlob blob, string LocalFile) { // The class currently stores state in class level variables so calling UploadBlobAsync or DownloadBlobAsync a second time will cause problems. // A better long term solution would be to better encapsulate the state, but the current solution works for the needs of my primary client. // Throw an exception if UploadBlobAsync or DownloadBlobAsync has already been called. lock (WorkingLock) { if (!Working) { Working = true; } else { throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer."); } } // Attempt to open the file first so that we throw an exception before getting into the async work using (FileStream fstemp = new FileStream(LocalFile, FileMode.Open, FileAccess.Read)) { } // Create an async op in order to raise the events back to the client on the correct thread. asyncOp = AsyncOperationManager.CreateOperation(blob); TransferType = TransferTypeEnum.Upload; m_Blob = blob; m_FileName = LocalFile; var file = new FileInfo(m_FileName); long fileSize = file.Length; FileStream fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read, FileShare.Read); ProgressStream pstream = new ProgressStream(fs); pstream.ProgressChanged += pstream_ProgressChanged; pstream.SetLength(fileSize); m_Blob.ServiceClient.DefaultRequestOptions.ParallelOperationThreadCount = 10; m_Blob.StreamWriteSizeInBytes = GetBlockSize(fileSize); asyncresult = m_Blob.BeginUploadFromStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(m_Blob, pstream)); }
public CashTransferDetails(String key, DataSet ds, int rowIdx, TransferTypeEnum transferTypeEnum) { InitializeComponent(); _transferTypeEnum = transferTypeEnum; #region DATABINDING _theData = ds; try { String tableName = ""; switch (_transferTypeEnum) { case TransferTypeEnum.SHOP: tableName = "CASH_XFER_DETAILS"; lblTransferType.Text = "Shop to Shop"; panelShopToShop.Visible = true; panelInternal.Visible = false; panelTransferToBank.Visible = false; panelTransferFromBank.Visible = false; panelShopToShop.BringToFront(); break; case TransferTypeEnum.INTERNAL: // SAFE is a special case of INTERNAL tableName = "CASH_XFER_DETAILS"; lblTransferType.Text = "Internal"; panelShopToShop.Visible = false; panelInternal.Visible = true; panelTransferToBank.Visible = false; panelTransferFromBank.Visible = false; this.panelInternal.BringToFront(); break; case TransferTypeEnum.BANK: tableName = "CASH_XFER_DETAILS"; panelShopToShop.Visible = false; panelInternal.Visible = false; panelTransferToBank.Visible = false; panelTransferFromBank.Visible = false; this.panelTransferToBank.BringToFront(); break; default: System.Diagnostics.Debug.Assert(false, "Unhandled case. Forget to add handler?"); break; } if (_theData.DefaultViewManager.DataViewSettings[tableName] != null) { //_theData.DefaultViewManager.DataViewSettings[tableName].RowFilter = "TRANSFERNUMBER='" + key + "'"; _selectedData = _theData.DefaultViewManager.CreateDataView(_theData.Tables[tableName]); lblTransferStatus.Text = _selectedData[0]["TRANSFERSTATUS"].ToString(); lblTransferNumber.Text = _selectedData[0]["TRANSFERNUMBER"].ToString(); switch (transferTypeEnum) { case TransferTypeEnum.SHOP: { lblSourceShopName.Text = _selectedData[0]["SOURCE_NAME"].ToString(); lblDestShopName.Text = _selectedData[0]["DEST_NAME"].ToString(); lblTransferDate.Text = string.Format("{0:d}", _selectedData[0]["TRANSERDATE"].ToString()); lblStatusDate.Text = string.Format("{0:d}", _selectedData[0]["STATUSDATE"].ToString()); if (_selectedData[0]["SOURCE_ADDR1"].ToString().Length != 0 && _selectedData[0]["SOURCE_ADDR2"].ToString().Length != 0) { lblSourceAddr1.Text = _selectedData[0]["SOURCE_ADDR1"].ToString(); lblSourceAddr2.Text = _selectedData[0]["SOURCE_ADDR2"].ToString(); } else { lblSourceAddr1.Text = ""; lblSourceAddr2.Text = _selectedData[0]["SOURCE_ADDR1"].ToString(); } lblSourceCSZ.Text = _selectedData[0]["SOURCE_CSZ"].ToString(); lblSourcePhone.Text = _selectedData[0]["SOURCE_PHONE"].ToString(); // in certain scenarios, we can have multiple records, use the first non-blank value String sourceMgr = _selectedData[0]["SOURCE_MGR"].ToString(); for (int rowIndex = 0; rowIndex < _selectedData.Table.Rows.Count && sourceMgr.Length == 0; rowIndex++) { sourceMgr = _selectedData[rowIndex]["SOURCE_MGR"].ToString(); } lblSourceMgr.Text = sourceMgr; if (_selectedData[0]["DEST_ADDR1"].ToString().Length != 0 && _selectedData[0]["DEST_ADDR2"].ToString().Length != 0) { lblDestAddr1.Text = _selectedData[0]["DEST_ADDR1"].ToString(); lblDestAddr2.Text = _selectedData[0]["DEST_ADDR2"].ToString(); } else { lblDestAddr1.Text = ""; lblDestAddr2.Text = _selectedData[0]["DEST_ADDR1"].ToString(); } lblDestCSZ.Text = _selectedData[0]["DEST_CSZ"].ToString(); lblDestPhone.Text = _selectedData[0]["DEST_PHONE"].ToString(); // in certain scenarios, we can have multiple records, use the first non-blank value String destMgr = _selectedData[0]["DEST_MGR"].ToString(); for (int rowIndex = 0; rowIndex < _selectedData.Table.Rows.Count && destMgr.Length == 0; rowIndex++) { destMgr = _selectedData[rowIndex]["DEST_MGR"].ToString(); } lblDestMgr.Text = destMgr; double amount = 0.0; double.TryParse(_selectedData[0]["transferamount"].ToString(), out amount); lblSourceTransferAmount.Text = string.Format("{0:C}", amount); lblTransportedBy.Text = _selectedData[0]["TRANSPORTEDBY"].ToString(); lblBagNumber.Text = _selectedData[0]["DEPOSITBAGNUMBER"].ToString(); lblSourceComments.Text = _selectedData[0]["SOURCECOMMENT"].ToString(); lblDestComments.Text = _selectedData[0]["DESTINATIONCOMMENT"].ToString(); } break; case TransferTypeEnum.INTERNAL: { // SAFE is a special case of INTERNAL lblSourceTransferFrom.Text = _selectedData[0]["source"].ToString(); double amount = 0.0; double.TryParse(_selectedData[0]["transferamount"].ToString(), out amount); lbInternallSourceTransferAmount.Text = string.Format("{0:C}", amount); lblSourceUserId.Text = _selectedData[0]["userid"].ToString(); lblDestinationTransferTo.Text = _selectedData[0]["destination"].ToString(); lblDestinationAcceptedBy.Text = _selectedData[0]["acceptedby"].ToString(); DateTime dt = DateTime.MinValue; DateTime.TryParse(_selectedData[0]["transferdate"].ToString(), out dt); lblInternalTransferDateTime.Text = dt.ToShortDateString() + " " + dt.ToShortTimeString(); } break; case TransferTypeEnum.BANK: { if ("SHOPTOBANK" == _selectedData[0]["transfertype"].ToString()) { lblTransferType.Text = "Transfer To Bank"; panelTransferToBank.Visible = true; panelTransferToBank.BringToFront(); lblToBankSourceTransferFrom.Text = _selectedData[0]["source"].ToString(); double amount = 0.0; double.TryParse(_selectedData[0]["transferamount"].ToString(), out amount); lblToBankSourceTransferAmount.Text = string.Format("{0:C}", amount); lblToBankSourceUserId.Text = _selectedData[0]["userid"].ToString(); lblToBankDestBankName.Text = _selectedData[0]["destination"].ToString(); lblToBankDestAccountNumber.Text = _selectedData[0]["routingnumber"].ToString(); lblToBankDestBagNumber.Text = _selectedData[0]["depositbagnumber"].ToString(); DateTime dt = DateTime.MinValue; DateTime.TryParse(_selectedData[0]["transferdate"].ToString(), out dt); lblToBankTransferDateTime.Text = dt.ToShortDateString() + " " + dt.ToShortTimeString(); } else { lblTransferType.Text = "Transfer From Bank"; panelTransferFromBank.Visible = true; panelTransferFromBank.BringToFront(); lblFromBankTransferFrom.Text = _selectedData[0]["source"].ToString(); double amount = 0.0; double.TryParse(_selectedData[0]["transferamount"].ToString(), out amount); lblFromBankTransferAmount.Text = string.Format("{0:C}", amount); lblFromBankUserId.Text = _selectedData[0]["userid"].ToString(); lblFromBankTransferTo.Text = _selectedData[0]["destination"].ToString(); lblFromBankAccountNumber.Text = _selectedData[0]["routingnumber"].ToString(); lblFromBankCheckNumber.Text = _selectedData[0]["checknumber"].ToString(); DateTime dt = DateTime.MinValue; DateTime.TryParse(_selectedData[0]["transferdate"].ToString(), out dt); lblFromBankTransferDateTime.Text = dt.ToShortDateString() + " " + dt.ToShortTimeString(); } } break; default: System.Diagnostics.Debug.Assert(false, "Unhandled case. Forget to add handler?"); break; } } } catch (Exception) { MessageBox.Show("An Error Occurred on the Pawn Loan Extensions Detail Screen"); } #endregion }
public void UploadBlobAsync(ICloudBlob blob, string LocalFile) { // The class currently stores state in class level variables so calling UploadBlobAsync or DownloadBlobAsync a second time will cause problems. // A better long term solution would be to better encapsulate the state, but the current solution works for the needs of my primary client. // Throw an exception if UploadBlobAsync or DownloadBlobAsync has already been called. lock (WorkingLock) { if (!Working) Working = true; else throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer."); } // Attempt to open the file first so that we throw an exception before getting into the async work using (FileStream fstemp = new FileStream(LocalFile, FileMode.Open, FileAccess.Read)) { } // Create an async op in order to raise the events back to the client on the correct thread. asyncOp = AsyncOperationManager.CreateOperation(blob); TransferType = TransferTypeEnum.Upload; m_Blob = blob; m_FileName = LocalFile; var file = new FileInfo(m_FileName); long fileSize = file.Length; FileStream fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read, FileShare.Read); ProgressStream pstream = new ProgressStream(fs); pstream.ProgressChanged += pstream_ProgressChanged; pstream.SetLength(fileSize); m_Blob.ServiceClient.ParallelOperationThreadCount = 10; asyncresult = m_Blob.BeginUploadFromStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(m_Blob, pstream)); }
public void UploadBlobAsync(CloudBlockBlob blob, string localFile, object state) { TransferType = TransferTypeEnum.Upload; //attempt to open the file first so that we throw an exception before getting into the async work using (FileStream fs = new FileStream(localFile, FileMode.Open, FileAccess.Read)) { } m_Blob = blob; m_FileName = localFile; BlobTransferWorkerDelegate worker = new BlobTransferWorkerDelegate(UploadBlobWorker); AsyncCallback completedCallback = new AsyncCallback(TaskCompletedCallback); lock (_sync) { if (TaskIsRunning) throw new InvalidOperationException("The control is currently busy."); AsyncOperation async = AsyncOperationManager.CreateOperation(state); MyAsyncContext context = new MyAsyncContext(); bool cancelled; worker.BeginInvoke(context, out cancelled, async, completedCallback, async); TaskIsRunning = true; TaskContext = context; } }
/// <summary> /// Downloads a blob to a local file asynchronously. /// </summary> /// <param name="localFile">The local file.</param> /// <exception cref="System.Exception">BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer.</exception> public ICancellableAsyncResult DownloadBlobAsync(string localFile) { lock (workingLock) { if (!working) working = true; else throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer."); } // Create an async op in order to raise the events back to the client on the correct thread. asyncOp = AsyncOperationManager.CreateOperation(blob); TransferType = TransferTypeEnum.Download; fileName = localFile; this.blob.FetchAttributes(); FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); ProgressStream pstream = new ProgressStream(fs); pstream.ProgressChanged += pstream_ProgressChanged; pstream.SetLength(this.blob.Properties.Length); this.blob.ServiceClient.ParallelOperationThreadCount = 10; asyncresult = this.blob.BeginDownloadToStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(this.blob, pstream)); return asyncresult; }
/// <summary> /// Uploads a file to an Azure blob asynchronously. /// </summary> /// <param name="localFile">The local file.</param> /// <exception cref="System.Exception">BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer.</exception> public ICancellableAsyncResult UploadBlobAsync(string localFile) { lock (workingLock) { if (!working) working = true; else throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer."); } // Attempt to open the file first so that we throw an exception before getting into the async work using (var fstemp = new FileStream(localFile, FileMode.Open, FileAccess.Read)) { } // Create an async op in order to raise the events back to the client on the correct thread. asyncOp = AsyncOperationManager.CreateOperation(this.blob); TransferType = TransferTypeEnum.Upload; fileName = localFile; var file = new FileInfo(fileName); long fileSize = file.Length; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); ProgressStream pstream = new ProgressStream(fs); pstream.ProgressChanged += pstream_ProgressChanged; pstream.SetLength(fileSize); this.blob.ServiceClient.ParallelOperationThreadCount = 10; asyncresult = this.blob.BeginUploadFromStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(this.blob, pstream)); return asyncresult; }