private ResponseMessageFcUnSync GetListOfFilesFromFranchiseServer(UnSyncListModel syncListModel) { using (var client = new SyncFranchiseClient(new BasicHttpBinding(), new EndpointAddress(syncListModel.WsAddress + SettingsData.Constants.Franchise.WS_SYNC_FILES))) { WcfExt.SetMtomEncodingAndSize(client.Endpoint); var res = client.GetUnSyncListOfFiles(syncListModel.FranchiseDataVersionUid); return(res); } }
private void DownloadFilesToSyncWithServer(CancellationToken token) { List <UnSyncListModel> lstDataVersions; _eventLog.WriteEntry("Se inicia la descarga de los archivos", EventLogEntryType.Information); using (var repository = new FranchiseRepository()) { lstDataVersions = repository.GetDataVersionsIdsReadyToDownload(); } if (lstDataVersions == null || lstDataVersions.Any() == false) { _eventLog.WriteEntry("No existen archivos para descargar", EventLogEntryType.Information); return; } foreach (var syncListModel in lstDataVersions) { _eventLog.WriteEntry("Descargando version con UID: " + syncListModel.FranchiseDataVersionUid, EventLogEntryType.Information); try { var syncListModelCs = syncListModel; using (var client = new SyncFranchiseClient(new BasicHttpBinding(BasicHttpSecurityMode.None), new EndpointAddress(syncListModel.WsAddress + SettingsData.Constants.Franchise.WS_SYNC_FILES))) { WcfExt.SetMtomEncodingAndSize(client.Endpoint); var tasks = new List <Task>(); using (var repository = new FranchiseRepository()) { var inClient = client; var query = repository.GetFilesToSyncByVersionId(syncListModel.FranchiseDataVersionId); var subscribe = query.ToObservable().Subscribe(fileModel => tasks.Add(DownloadFileAndVerifyCheckSum(syncListModelCs.FranchiseDataVersionUid, fileModel, token, inClient))); Task.WaitAll(tasks.ToArray(), token); subscribe.Dispose(); repository.TrySetFranchiseSyncFilesCompleted(syncListModelCs.FranchiseDataVersionId); } } _eventLog.WriteEntry("Se terminó la descarga de la version con UID: " + syncListModel.FranchiseDataVersionUid, EventLogEntryType.Information); } catch (Exception ex) { _eventLog.WriteEntry(ex.Message + " -ST- " + ex.StackTrace, EventLogEntryType.Error); } } }
private int FranchiseQueryForFiles(FranchiseDataVersion model, ResponseMessageModel response, string wsUrl) { using (var client = new SyncFranchiseClient(new BasicHttpBinding(), new EndpointAddress(wsUrl + SettingsData.Constants.Franchise.WS_SYNC_FILES))) { WcfExt.SetMtomEncodingAndSize(client.Endpoint); var res = client.QueryForFiles(model.FranchiseDataVersionUid); if (res.HasError == false) { response.HasError = false; return(res.TotalFiles); } response.Message = res.Message; response.HasError = true; return(EntityConstants.NO_VALUE); } }
private Task DownloadFileAndVerifyCheckSum(Guid franchiseDataVersionUid, SyncFileModel fileModel, CancellationToken token, SyncFranchiseClient client) { var sfranchiseDataVersionUid = franchiseDataVersionUid.ToString(); return(Task.Run(() => { try { Stream stream; String sMsg; var hasError = client.GetFileByName(fileModel.FileName, franchiseDataVersionUid, out sMsg, out stream); if (hasError) { _eventLog.WriteEntry("Se sucitó el siguiente error: " + sMsg, EventLogEntryType.Error); return; } SaveSyncFileAndVerifyCheckSum(sfranchiseDataVersionUid, fileModel, stream); } catch (Exception ex) { _eventLog.WriteEntry(ex.Message + " -ST- " + ex.StackTrace, EventLogEntryType.Error); } }, token)); }