private void InvokeSyncEvent(SynchronizationState state) { if (syncEvent != null) { syncEvent.Invoke(this, new SynchEventArgs(state)); } }
/// <summary> /// Perform actions that are required at the start of a synchronization. This includes resetting the properties of the /// current instance and setting the status to <see cref="SynchronizationState.SynchronizingFiles"/>. The new values are /// persisted to the data store. Throws a SynchronizationInProgressException if another synchronization is already in progress. /// </summary> /// <param name="synchId">The GUID that uniquely identifies the synchronization.</param> public void Begin(string synchId) { lock (_lockObject) { RefreshFromDataStore(); var syncInProgress = (_synchState == SynchronizationState.SynchronizingFiles || _synchState == SynchronizationState.PersistingToDataStore); if ((synchId != _synchId) && syncInProgress) { throw new Events.CustomExceptions.SynchronizationInProgressException(); } BeginTimestampUtc = DateTime.UtcNow; _synchId = synchId; _totalFileCount = 0; _currentFileIndex = 0; _synchState = SynchronizationState.SynchronizingFiles; _skippedMediaObjects.Clear(); // Save to data store. Even though it might have been valid to start the synchronizing above, by the time // we try to save to the data store, someone else may have started it (for example, from another application). // So the data provider will check one more time just before saving our data, throwing an exception if necessary. Save(); } }
/// <summary> /// Initializes a new instance of the <see cref="SynchronizationStatus"/> class with the specified properties. /// </summary> /// <param name="galleryId">The gallery ID.</param> /// <param name="synchId">The GUID that uniquely identifies the current synchronization.</param> /// <param name="synchStatus">The status of the current synchronization.</param> /// <param name="totalFileCount">The total number of files in the directory or directories that are being processed in the current /// synchronization.</param> /// <param name="currentFileName">The name of the current file being processed.</param> /// <param name="currentFileIndex">The zero-based index value of the current file being processed. This is a number from 0 to /// <see cref="TotalFileCount"/> - 1.</param> /// <param name="currentFilePath">The path to the current file being processed.</param> internal SynchronizationStatus(int galleryId, string synchId, SynchronizationState synchStatus, int totalFileCount, string currentFileName, int currentFileIndex, string currentFilePath) { this._galleryId = galleryId; this._synchId = synchId; this._synchState = synchStatus; this._totalFileCount = totalFileCount; this._currentFileName = currentFileName; this._currentFileIndex = currentFileIndex; this._currentFilePath = currentFilePath; }
private void UpdateSynchronizationStatus(SynchronizationState state, int completedPackages, int packagesToIndex) { synchronizationStatus = new SynchronizationStatus( state, completedPackages, packagesToIndex ); RaiseStatusChanged(); }
private SynchronizationModel GetResponse( string message = "", int updated = 0, SynchronizationState state = SynchronizationState.Finished, SynchronizationStatus status = SynchronizationStatus.Success) => new SynchronizationModel { Logs = { message }, ProductsUpdated = updated, Status = status, State = state, };
/// <summary> /// Completes the current synchronization by updating the status object and the Synchronize table in the /// data store. Calling this method is required before subsequent synchronizations can be performed. /// </summary> /// <param name="synchId">A GUID string that uniquely identifies the current synchronization.</param> public void Finish(string synchId) { // Updates database to show synchronization is no longer occuring. // Should be called when synchronization is finished. this._synchState = SynchronizationState.Complete; // Don't reset the file counts in case the UI wants to know how many files were processed. //this._currentFileIndex = 0; //this._totalFileCount = 0; Factory.GetDataProvider().Synchronize_SaveStatus(this); }
/// <summary> /// Update the properties of this instance with the latest data from the data store. /// </summary> private void RefreshFromDataStore() { lock (_lockObject) { ISynchronizationStatus synchFromDataStore = Factory.GetDataProvider().Synchronize_RetrieveStatus(_galleryId, new Factory()); _synchId = synchFromDataStore.SynchId; _totalFileCount = synchFromDataStore.TotalFileCount; _currentFileIndex = synchFromDataStore.CurrentFileIndex; _synchState = synchFromDataStore.Status; } }
private void InvokeSyncEvent(SynchronizationState newState) { if ((SyncState == SynchronizationState.Disabled) && (newState == SynchronizationState.Idle)) { return; } SyncState = newState; if (SyncEvent != null) { SyncEvent.Invoke(this, new SynchEventArgs(newState)); } }
/// <summary> /// Updates the current instance with the new values, persisting the changes to the data store if <paramref name="persistToDataStore"/> /// is <c>true</c>. Specify a null value for each parameter that should not be updated (the existing value will be retained). /// </summary> /// <param name="synchStatus">The status of the current synchronization.</param> /// <param name="totalFileCount">The total number of files in the directory or directories that are being processed in the current /// synchronization.</param> /// <param name="currentFileName">The name of the current file being processed.</param> /// <param name="currentFileIndex">The zero-based index value of the current file being processed. This is a number from 0 to /// <see cref="TotalFileCount"/> - 1.</param> /// <param name="currentFilePath">The path to the current file being processed.</param> /// <param name="shouldTerminate">Indicates whether the current synchronization should be terminated.</param> /// <param name="persistToDataStore">If set to <c>true</c> persist the new values to the data store.</param> public void Update(SynchronizationState synchStatus, int?totalFileCount, string currentFileName, int?currentFileIndex, string currentFilePath, bool?shouldTerminate, bool persistToDataStore) { lock (_lockObject) { if (synchStatus != SynchronizationState.NotSet) { this._synchState = synchStatus; } if (totalFileCount.HasValue) { if (totalFileCount.Value < 0) { throw new ArgumentOutOfRangeException($"TotalFileCount must be an integer greater than or equal to zero. Attempted to assign TotalFileCount = {totalFileCount.Value}."); } this._totalFileCount = totalFileCount.Value; } if (currentFileName != null) { this._currentFileName = currentFileName; } if (currentFileIndex.HasValue) { if ((currentFileIndex.Value < 0) || ((currentFileIndex.Value > 0) && (currentFileIndex.Value >= this._totalFileCount))) { throw new ArgumentOutOfRangeException($"CurrentFileIndex must be an integer between 0 and TotalFileCount - 1. Attempted to assign CurrentFileIndex = {currentFileIndex.Value}; TotalFileCount = {this._totalFileCount}."); } this._currentFileIndex = currentFileIndex.Value; } if (currentFilePath != null) { this._currentFilePath = currentFilePath; } if (shouldTerminate.HasValue) { this._shouldTerminate = shouldTerminate.Value; } if (persistToDataStore) { Save(); } } }
/// <summary> /// Updates the current instance with the new values, persisting the changes to the data store is <paramref name="persistToDataStore"/> /// is <c>true</c>. Specify a null value for each parameter that should not be updated (the existing value will be retained). /// </summary> /// <param name="synchStatus">The status of the current synchronization.</param> /// <param name="totalFileCount">The total number of files in the directory or directories that are being processed in the current /// synchronization.</param> /// <param name="currentFileName">The name of the current file being processed.</param> /// <param name="currentFileIndex">The zero-based index value of the current file being processed. This is a number from 0 to /// <see cref="TotalFileCount"/> - 1.</param> /// <param name="currentFilePath">The path to the current file being processed.</param> /// <param name="shouldTerminate">Indicates whether the current synchronization should be terminated.</param> /// <param name="persistToDataStore">If set to <c>true</c> persist the new values to the data store.</param> public void Update(SynchronizationState synchStatus, int?totalFileCount, string currentFileName, int?currentFileIndex, string currentFilePath, bool?shouldTerminate, bool persistToDataStore) { lock (_lockObject) { if (synchStatus != SynchronizationState.NotSet) { this._synchState = synchStatus; } if (totalFileCount.HasValue) { if (totalFileCount.Value < 0) { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, Resources.SynchronizationStatus_TotalFileCount_Ex_Msg, totalFileCount.Value)); } this._totalFileCount = totalFileCount.Value; } if (currentFileName != null) { this._currentFileName = currentFileName; } if (currentFileIndex.HasValue) { if ((currentFileIndex.Value < 0) || ((currentFileIndex.Value > 0) && (currentFileIndex.Value >= this._totalFileCount))) { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, Resources.SynchronizationStatus_CurrentFileIndex_Ex_Msg, currentFileIndex.Value, this._totalFileCount)); } this._currentFileIndex = currentFileIndex.Value; } if (currentFilePath != null) { this._currentFilePath = currentFilePath; } if (shouldTerminate.HasValue) { this._shouldTerminate = shouldTerminate.Value; } if (persistToDataStore) { Save(); } } }
private void UpdateNotificationIcon(SynchronizationState sstate) { switch (sstate) { case SynchronizationState.NotSynced: Owner.TrayIcon.Icon = ThemeManager.Inst.CurrentThemeSet.GetIconResource("IconYellow.ico"); break; case SynchronizationState.Syncing: Owner.TrayIcon.Icon = ThemeManager.Inst.CurrentThemeSet.GetIconResource("IconSync.ico"); break; case SynchronizationState.UpToDate: Owner.TrayIcon.Icon = ThemeManager.Inst.CurrentThemeSet.GetIconResource("IconGreen.ico"); break; case SynchronizationState.Error: Owner.TrayIcon.Icon = ThemeManager.Inst.CurrentThemeSet.GetIconResource("IconRed.ico"); break; default: throw new ArgumentOutOfRangeException(nameof(sstate), sstate, null); } }
/// <summary> /// Completes the current synchronization by updating the status instance and the Synchronize table in the /// data store. Calling this method is required before subsequent synchronizations can be performed. /// </summary> public void Finish() { lock (_lockObject) { // Updates database to show synchronization is no longer occuring. // Should be called when synchronization is finished. this._synchState = SynchronizationState.Complete; // Don't reset the file counts in case the UI wants to know how many files were processed. //this._currentFileIndex = 0; //this._totalFileCount = 0; Save(); } }
private static string GetFriendlyStatusText(SynchronizationState status) { switch (status) { case SynchronizationState.AnotherSynchronizationInProgress: return(Resources.GalleryServerPro.Task_Synch_Progress_Status_SynchInProgressException_Hdr); case SynchronizationState.Complete: return(status.ToString()); case SynchronizationState.Error: return(status.ToString()); case SynchronizationState.PersistingToDataStore: return(Resources.GalleryServerPro.Task_Synch_Progress_Status_PersistingToDataStore_Hdr); case SynchronizationState.SynchronizingFiles: return(Resources.GalleryServerPro.Task_Synch_Progress_Status_SynchInProgress_Hdr); default: throw new System.ComponentModel.InvalidEnumArgumentException("The GetFriendlyStatusText() method in synchronize.aspx encountered a SynchronizationState enum value it was not designed for. This method must be updated."); } }
/// <summary> /// Begins the process of a new synchronization by updating the status object and the Synchronize table in the /// data store. Throws an exception if another synchronization is already in process. /// </summary> /// <param name="synchId">A GUID string that uniquely identifies the current synchronization.</param> /// <param name="totalFileCount">The total number of files in the directory or directories that are being /// processed in the current synchronization.</param> /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.SynchronizationInProgressException"> /// Thrown when a synchronization with another synchId is already in progress.</exception> public void Start(string synchId, int totalFileCount) { if ((synchId != this._synchId) && (this._synchState != SynchronizationState.Complete)) { throw new GalleryServerPro.ErrorHandler.CustomExceptions.SynchronizationInProgressException(); } this._synchId = synchId; this._totalFileCount = totalFileCount; this._currentFileIndex = 0; this._synchState = SynchronizationState.SynchronizingFiles; this._skippedMediaObjects.Clear(); // Save to data store. Even though it might have been valid to start the synchronizing above, by the time // we try to save to the data store, someone else may have started. So the data provider will check one more // time just before saving our data, throwing an exception if necessary. Factory.GetDataProvider().Synchronize_SaveStatus(this); }
private void ChangeSyncValue(SynchronizationState syncState) { this.SyncInProgress.gameObject.SetActive(false); this.SyncNotDone.gameObject.SetActive(false); this.SyncDone.gameObject.SetActive(false); this.SyncError.gameObject.SetActive(false); switch (syncState) { case SynchronizationState.Waiting: case SynchronizationState.Done: { this.SyncDone.gameObject.SetActive(true); this._syncStatusLabel.text = "DATA SYNCED"; break; } case SynchronizationState.Pushing: case SynchronizationState.InProgress: case SynchronizationState.Pulling: { this.SyncInProgress.gameObject.SetActive(true); this._syncStatusLabel.text = "DATA SYNCING..."; break; } case SynchronizationState.NotPossible: { this.SyncNotDone.gameObject.SetActive(true); break; } case SynchronizationState.Error: { this.SyncError.gameObject.SetActive(true); this._syncStatusLabel.text = "DATA SYNC ERROR"; break; } } }
/// <summary> /// Retrieve the most recent synchronization information from the data store. /// </summary> /// <param name="galleryId">The gallery ID.</param> /// <param name="factory">An instance of <see cref="IFactory"/>. It is used to instantiate a <see cref="ISynchronizationStatus"/> object.</param> /// <returns> /// Returns an <see cref="ISynchronizationStatus"/> object with the most recent synchronization information from the data store. /// </returns> public static ISynchronizationStatus RetrieveStatus(int galleryId, IFactory factory) { ISynchronizationStatus updatedSynchStatus = null; using (IDataReader dr = GetDataReaderSynchronizeSelect(galleryId)) { while (dr.Read()) { string synchId = dr["SynchId"].ToString(); SynchronizationState synchState = (SynchronizationState)Enum.Parse(typeof(SynchronizationState), dr["SynchState"].ToString()); int totalFileCount = Convert.ToInt32(dr["TotalFiles"], CultureInfo.InvariantCulture); int currentFileIndex = Convert.ToInt32(dr["CurrentFileIndex"], CultureInfo.InvariantCulture); updatedSynchStatus = factory.CreateSynchronizationStatus(galleryId, synchId, synchState, totalFileCount, String.Empty, currentFileIndex, String.Empty); break; } } if (updatedSynchStatus == null) { // The gs_Synchronize table didn't have a record for this gallery. Configure the gallery, which will // insert the missing record, then call this method again. IGallery gallery = GalleryData.GetGalleries(factory.CreateGalleryCollection()).FindById(galleryId); if (gallery != null) { gallery.Configure(); } else { throw new InvalidGalleryException(galleryId); } return(RetrieveStatus(galleryId, factory)); } return(updatedSynchStatus); }
private static string GetFriendlyStatusText(SynchronizationState status) { switch (status) { case SynchronizationState.AnotherSynchronizationInProgress: return Resources.GalleryServerPro.Task_Synch_Progress_Status_SynchInProgressException_Hdr; case SynchronizationState.Complete: return status.ToString(); case SynchronizationState.Error: return status.ToString(); case SynchronizationState.PersistingToDataStore: return Resources.GalleryServerPro.Task_Synch_Progress_Status_PersistingToDataStore_Hdr; case SynchronizationState.SynchronizingFiles: return Resources.GalleryServerPro.Task_Synch_Progress_Status_SynchInProgress_Hdr; default: throw new System.ComponentModel.InvalidEnumArgumentException("The GetFriendlyStatusText() method in synchronize.aspx encountered a SynchronizationState enum value it was not designed for. This method must be updated."); } }
/// <summary> /// Initializes a new instance of the <see cref="ISynchronizationStatus"/> class with the specified properties. /// </summary> /// <param name="galleryId">The gallery ID.</param> /// <param name="synchId">The GUID that uniquely identifies the current synchronization.</param> /// <param name="synchStatus">The status of the current synchronization.</param> /// <param name="totalFileCount">The total number of files in the directory or directories that are being processed in the current /// synchronization.</param> /// <param name="currentFileName">The name of the current file being processed.</param> /// <param name="currentFileIndex">The zero-based index value of the current file being processed. This is a number from 0 to /// <see cref="ISynchronizationStatus.TotalFileCount"/> - 1.</param> /// <param name="currentFilePath">The path to the current file being processed.</param> /// <returns></returns> public ISynchronizationStatus CreateSynchronizationStatus(int galleryId, string synchId, SynchronizationState synchStatus, int totalFileCount, string currentFileName, int currentFileIndex, string currentFilePath) { return new SynchronizationStatus(galleryId, synchId, synchStatus, totalFileCount, currentFileName, currentFileIndex, currentFilePath); }
private RepositoryInfo CreateSampleStatus(SynchronizationState state = SynchronizationState.Idle) { return(new RepositoryInfo(0, new IndexingStatus(IndexingState.Idle, new SynchronizationStatus(state)))); }
/// <summary> /// Update the properties of this instance with the latest data from the data store. /// </summary> private void RefreshFromDataStore() { lock (_lockObject) { //ISynchronizationStatus synchFromDataStore = Factory.GetDataProvider().Synchronize_RetrieveStatus(_galleryId, new Factory()); ISynchronizationStatus synchFromDataStore = GetFromDataStore(_galleryId); _synchId = synchFromDataStore.SynchId; _totalFileCount = synchFromDataStore.TotalFileCount; _currentFileIndex = synchFromDataStore.CurrentFileIndex; _synchState = synchFromDataStore.Status; } }
/// <summary> /// Updates the current instance with the new values, persisting the changes to the data store if <paramref name="persistToDataStore"/> /// is <c>true</c>. Specify a null value for each parameter that should not be updated (the existing value will be retained). /// </summary> /// <param name="synchStatus">The status of the current synchronization.</param> /// <param name="totalFileCount">The total number of files in the directory or directories that are being processed in the current /// synchronization.</param> /// <param name="currentFileName">The name of the current file being processed.</param> /// <param name="currentFileIndex">The zero-based index value of the current file being processed. This is a number from 0 to /// <see cref="TotalFileCount"/> - 1.</param> /// <param name="currentFilePath">The path to the current file being processed.</param> /// <param name="shouldTerminate">Indicates whether the current synchronization should be terminated.</param> /// <param name="persistToDataStore">If set to <c>true</c> persist the new values to the data store.</param> public void Update(SynchronizationState synchStatus, int? totalFileCount, string currentFileName, int? currentFileIndex, string currentFilePath, bool? shouldTerminate, bool persistToDataStore) { lock (_lockObject) { if (synchStatus != SynchronizationState.NotSet) { this._synchState = synchStatus; } if (totalFileCount.HasValue) { if (totalFileCount.Value < 0) { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, Resources.SynchronizationStatus_TotalFileCount_Ex_Msg, totalFileCount.Value)); } this._totalFileCount = totalFileCount.Value; } if (currentFileName != null) { this._currentFileName = currentFileName; } if (currentFileIndex.HasValue) { if ((currentFileIndex.Value < 0) || ((currentFileIndex.Value > 0) && (currentFileIndex.Value >= this._totalFileCount))) { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, Resources.SynchronizationStatus_CurrentFileIndex_Ex_Msg, currentFileIndex.Value, this._totalFileCount)); } this._currentFileIndex = currentFileIndex.Value; } if (currentFilePath != null) { this._currentFilePath = currentFilePath; } if (shouldTerminate.HasValue) { this._shouldTerminate = shouldTerminate.Value; } if (persistToDataStore) { Save(); } } }
private void UpdateStatus(int currentFileIndex, string filepath = null, string filename = null, SynchronizationState syncState = SynchronizationState.NotSet, bool persistToDatabase = false) { var currentFilePath = (filepath != null ? filepath.Remove(0, _fullMediaObjectPathLength).TrimStart(new char[] { Path.DirectorySeparatorChar }) : null); _synchStatus.Update(syncState, null, filename, currentFileIndex, currentFilePath, null, persistToDatabase); }
/// <summary> /// Creates instance of this class. /// </summary> /// <param name="newState">New synchronization state.</param> public SynchEventArgs(SynchronizationState newState) { this.NewState = newState; }
public SynchronizationStatus(SynchronizationState synchronizationState, int completedPackages, int packagesToIndex) { SynchronizationState = synchronizationState; CompletedPackages = completedPackages; PackagesToIndex = packagesToIndex; }
/// <summary> /// Begins the process of a new synchronization by updating the status object and the Synchronize table in the /// data store. Throws an exception if another synchronization is already in process. /// </summary> /// <param name="synchId">A GUID string that uniquely identifies the current synchronization.</param> /// <param name="totalFileCount">The total number of files in the directory or directories that are being /// processed in the current synchronization.</param> /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.SynchronizationInProgressException"> /// Thrown when a synchronization with another synchId is already in progress.</exception> public void Start(string synchId, int totalFileCount) { if ((synchId != this._synchId) && (this._synchState != SynchronizationState.Complete)) throw new GalleryServerPro.ErrorHandler.CustomExceptions.SynchronizationInProgressException(); this._synchId = synchId; this._totalFileCount = totalFileCount; this._currentFileIndex = 0; this._synchState = SynchronizationState.SynchronizingFiles; this._skippedMediaObjects.Clear(); // Save to data store. Even though it might have been valid to start the synchronizing above, by the time // we try to save to the data store, someone else may have started. So the data provider will check one more // time just before saving our data, throwing an exception if necessary. Factory.GetDataProvider().Synchronize_SaveStatus(this); }
private void UpdateSynchronizationStatus(SynchronizationState state) { UpdateSynchronizationStatus(state, 0, 0); }
public SynchronizationStatus(SynchronizationState synchronizationState) : this(synchronizationState, 0, 0) { }
public SynchEventArgs(SynchronizationState state) { this.state = state; }