public static SynchStatusWebEntity GetCurrentStatus() { SynchStatusWebEntity synchStatusWeb = new SynchStatusWebEntity(); synchStatusWeb.SynchId = _synchStatus.SynchId; synchStatusWeb.TotalFileCount = _synchStatus.TotalFileCount; synchStatusWeb.CurrentFileIndex = _synchStatus.CurrentFileIndex + 1; if ((_synchStatus.CurrentFilePath != null) && (_synchStatus.CurrentFileName != null)) synchStatusWeb.CurrentFile = System.IO.Path.Combine(_synchStatus.CurrentFilePath, _synchStatus.CurrentFileName); synchStatusWeb.Status = _synchStatus.Status.ToString(); synchStatusWeb.StatusForUI = GetFriendlyStatusText(_synchStatus.Status); synchStatusWeb.PercentComplete = CalculatePercentComplete(_synchStatus); // Update the Skipped Files, but only when the synch is complete. if (_synchStatus.Status == SynchronizationState.Complete) { if (_synchStatus.SkippedMediaObjects.Count > GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch) { // We have a large number of skipped media objects. We don't want to send it all to the browsers, because it might take // too long or cause an error if it serializes to a string longer than int.MaxValue, so let's trim it down. _synchStatus.SkippedMediaObjects.RemoveRange(GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch, _synchStatus.SkippedMediaObjects.Count - GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch); } synchStatusWeb.SkippedFiles = _synchStatus.SkippedMediaObjects; } return synchStatusWeb; }
public SynchStatusWebEntity GetCurrentStatus(int galleryId) { ISynchronizationStatus synchStatus = SynchronizationStatus.GetInstance(galleryId); try { SynchStatusWebEntity synchStatusWeb = new SynchStatusWebEntity(); synchStatusWeb.SynchId = synchStatus.SynchId; synchStatusWeb.TotalFileCount = synchStatus.TotalFileCount; synchStatusWeb.CurrentFileIndex = synchStatus.CurrentFileIndex + 1; if ((synchStatus.CurrentFilePath != null) && (synchStatus.CurrentFileName != null)) synchStatusWeb.CurrentFile = System.IO.Path.Combine(synchStatus.CurrentFilePath, synchStatus.CurrentFileName); synchStatusWeb.Status = synchStatus.Status.ToString(); synchStatusWeb.StatusForUI = GetFriendlyStatusText(synchStatus.Status); synchStatusWeb.PercentComplete = CalculatePercentComplete(synchStatus); // Update the Skipped Files, but only when the synch is complete. lock (synchStatus) { if (synchStatus.Status == SynchronizationState.Complete) { if (synchStatus.SkippedMediaObjects.Count > GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch) { // We have a large number of skipped media objects. We don't want to send it all to the browsers, because it might take // too long or cause an error if it serializes to a string longer than int.MaxValue, so let's trim it down. synchStatus.SkippedMediaObjects.RemoveRange(GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch, synchStatus.SkippedMediaObjects.Count - GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch); } synchStatusWeb.SkippedFiles = synchStatus.SkippedMediaObjects; } } return synchStatusWeb; } catch (Exception ex) { AppErrorController.LogError(ex, synchStatus.GalleryId); throw; } }
/// <summary> /// Retrieves the status of a synchronization for the gallery having the ID <paramref name="galleryId" /> and the /// synchronization ID <paramref name="syncId" />. /// </summary> /// <param name="syncId">The synchronization ID.</param> /// <param name="galleryId">The gallery ID.</param> /// <returns>An instance of <see cref="SynchStatusWebEntity" />.</returns> public static SynchStatusWebEntity GetSyncStatus(string syncId, int galleryId) { var synchStatus = SynchronizationStatus.GetInstance(galleryId); var synchStatusWeb = new SynchStatusWebEntity(); try { if (!String.IsNullOrEmpty(synchStatus.SynchId) && !synchStatus.SynchId.Equals(syncId, StringComparison.OrdinalIgnoreCase)) { synchStatusWeb.SynchId = syncId; synchStatusWeb.TotalFileCount = 0; synchStatusWeb.CurrentFileIndex = 0; synchStatusWeb.CurrentFile = String.Empty; synchStatusWeb.Status = SynchronizationState.AnotherSynchronizationInProgress.ToString(); synchStatusWeb.StatusForUI = Resources.GalleryServerPro.Task_Synch_Progress_Status_SynchInProgressException_Hdr; synchStatusWeb.PercentComplete = CalculatePercentComplete(synchStatus); synchStatusWeb.SyncRate = String.Empty; return synchStatusWeb; } synchStatusWeb.SynchId = synchStatus.SynchId; synchStatusWeb.Status = synchStatus.Status.ToString(); synchStatusWeb.TotalFileCount = synchStatus.TotalFileCount; synchStatusWeb.CurrentFileIndex = (synchStatus.Status == SynchronizationState.Complete ? synchStatus.TotalFileCount : synchStatus.CurrentFileIndex); synchStatusWeb.StatusForUI = GetFriendlyStatusText(synchStatus); synchStatusWeb.PercentComplete = CalculatePercentComplete(synchStatus); synchStatusWeb.SyncRate = CalculateSyncRate(synchStatus); if ((synchStatus.CurrentFilePath != null) && (synchStatus.CurrentFileName != null)) { try { synchStatusWeb.CurrentFile = Path.Combine(synchStatus.CurrentFilePath, synchStatus.CurrentFileName); } catch (ArgumentException ex) { synchStatusWeb.CurrentFile = String.Empty; ex.Data.Add("INFO", "This error was handled and should not affect the user experience unless it occurs frequently."); ex.Data.Add("synchStatus.CurrentFilePath", synchStatus.CurrentFilePath); ex.Data.Add("synchStatus.CurrentFileName", synchStatus.CurrentFileName); AppEventController.LogError(ex, synchStatus.GalleryId); } } // Update the Skipped Files, but only when the sync is complete. lock (synchStatus) { if (synchStatus.Status == SynchronizationState.Complete) { if (synchStatus.SkippedMediaObjects.Count > GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch) { // We have a large number of skipped media objects. We don't want to send it all to the browsers, because it might take // too long or cause an error if it serializes to a string longer than int.MaxValue, so let's trim it down. synchStatus.SkippedMediaObjects.RemoveRange(GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch, synchStatus.SkippedMediaObjects.Count - GlobalConstants.MaxNumberOfSkippedObjectsToDisplayAfterSynch); } synchStatusWeb.SkippedFiles = synchStatus.SkippedMediaObjects; } } } catch (Exception ex) { AppEventController.LogError(ex, synchStatus.GalleryId); synchStatusWeb.StatusForUI = "An error occurred while retrieving the status"; } return synchStatusWeb; }