Ejemplo n.º 1
0
        /// -------------------------------------------------------------------------------------
        /// <summary>
        /// Perform one-time initialization of a new Scripture project
        /// </summary>
        /// <returns>true if data loaded successfully; false, otherwise</returns>
        /// -------------------------------------------------------------------------------------
        protected bool Initialize(IThreadedProgress progressDlg)
        {
            if (m_scr != null)
            {
                // Preload all book, section and paragraphs if we already have Scripture
                m_cache.ServiceLocator.DataSetup.LoadDomainAsync(BackendBulkLoadDomain.Scripture);

                ILangProject lp = m_cache.LanguageProject;
                if (m_scr.BookAnnotationsOS.Count != 0 &&
                    m_scr.PublicationsOC.Count != 0 &&
                    lp.KeyTermsList.PossibilitiesOS.Count >= 1 &&
                    m_scr.NoteCategoriesOA != null && m_scr.NoteCategoriesOA.PossibilitiesOS.Count > 0)
                {
                    return(true);
                }
            }

            try
            {
                progressDlg.RunTask(InitializeScriptureProject);
            }
            catch (WorkerThreadException e)
            {
                while (m_cache.DomainDataByFlid.GetActionHandler().CanUndo())
                {
                    UndoResult ures = m_cache.DomainDataByFlid.GetActionHandler().Undo();
                    // Enhance JohnT: make use of ures?
                }
                MessageBox.Show(Form.ActiveForm, e.InnerException.Message, FwUtils.ksTeAppName,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed resources here.
                if (m_cache != null)
                {
                    UndoResult ures = 0;
                    while (m_cache.CanUndo)
                    {
                        m_cache.Undo(out ures);
                        if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                        {
                            Assert.Fail("ures should not be == " + ures.ToString());
                        }
                    }
                    m_cache.Dispose();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_cache      = null;
            m_styleSheet = null;

            base.Dispose(disposing);
        }
Ejemplo n.º 3
0
        public virtual void TearDown()
        {
            if (m_fdoCache != null)
            {
                UndoResult ures = 0;
                while (m_fdoCache.CanUndo)
                {
                    m_fdoCache.Undo(out ures);
                    if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                    {
                        Assert.Fail("ures should not be == " + ures.ToString());
                    }
                }
            }
            if (m_division != null)
            {
                m_division.m_hPagesBroken.Clear();
                m_division.Dispose();
                m_division = null;
            }

            // Make sure we close all the rootboxes
            if (m_ScrPubCtrl != null)
            {
                m_ScrPubCtrl.Dispose();
                m_ScrPubCtrl = null;
            }
        }
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed resources here.
                if (m_fdoCache != null)
                {
                    UndoResult ures = 0;
                    while (m_fdoCache.CanUndo)
                    {
                        m_fdoCache.Undo(out ures);
                    }
                    m_fdoCache.Dispose();
                }
                if (m_basicView != null)
                {
                    m_basicView.Dispose();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_fdoCache  = null;
            m_basicView = null;

            base.Dispose(disposing);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed resources here.
                UndoResult ures = 0;
                if (m_fdoCache != null)
                {
                    while (m_fdoCache.CanUndo)
                    {
                        m_fdoCache.Undo(out ures);
                    }
                    m_fdoCache.Dispose();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_fdoCache   = null;
            m_styleSheet = null;
            m_scr        = null;
            if (m_wsf != null)
            {
                Marshal.ReleaseComObject(m_wsf);
                m_wsf = null;
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 6
0
        public void CleanUp()
        {
            CheckDisposed();
            UndoResult ures = 0;

            while (m_fdoCache.CanUndo)
            {
                m_fdoCache.Undo(out ures);
                if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                {
                    Assert.Fail("ures should not be == " + ures.ToString());
                }
            }
        }
        public void Destroy()
        {
            UndoResult ures = 0;

            while (m_cache.CanUndo)
            {
                m_cache.Undo(out ures);
                if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                {
                    Assert.Fail("ures should not be == " + ures.ToString());
                }
            }
            m_cache.Dispose();
            m_cache = null;
        }
Ejemplo n.º 8
0
        public async Task CommandUndo()
        {
            var        socketId = Context.ConnectionId;
            UndoResult result   = placeShipSelection.Undo(socketId);
            List <int> buttons  = result.removedButtons;

            int[] btns = buttons.ToArray();
            if (result != null)
            {
                foreach (var coordinate in result.coordinates)
                {
                    await Clients.Caller.SendAsync("undoShip", coordinate.x, coordinate.y);
                }
                await Clients.Caller.SendAsync("undoButtons", result.activeButton, btns);
            }
        }
Ejemplo n.º 9
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Undo everything possible in the FDO cache
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected virtual void UndoEverythingPossible()
 {
     if (m_fdoCache != null)
     {
         using (new IgnorePropChanged(m_fdoCache, PropChangedHandling.SuppressAll))
         {
             UndoResult ures = 0;
             while (m_fdoCache.CanUndo)
             {
                 m_fdoCache.Undo(out ures);
                 if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                 {
                     Assert.Fail("ures should not be == " + ures.ToString());
                 }
             }
         }
     }
 }
Ejemplo n.º 10
0
        public virtual void CleanUp()
        {
            CheckDisposed();

            UndoResult ures = 0;

            while (m_fdoCache.CanUndo)
            {
                m_fdoCache.Undo(out ures);
                if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                {
                    Assert.Fail("ures should not be == " + ures.ToString());
                }
            }
            // Some tests are not at all happy to have m_basicView be disposed befroe the undoing.
            m_basicView.Dispose();
            m_basicView = null;
            m_fdoCache.Dispose();
            m_fdoCache = null;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed resources here.
                // Dispose window first, as it needs the cache to clear out its notification.
                if (m_mainWnd != null)
                {
                    m_mainWnd.Dispose();
                }
                if (m_cache != null)
                {
                    UndoResult ures = 0;
                    while (m_cache.CanUndo)
                    {
                        m_cache.Undo(out ures);
                        if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                        {
                            Assert.Fail("ures should not be == " + ures.ToString());
                        }
                    }
                    m_cache.Dispose();                     // Yes, since the window isn't supposed to do it.
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_cache   = null;
            m_mainWnd = null;
            m_scr     = null;
            // Restore prompt setting
            Options.ShowEmptyParagraphPromptsSetting = m_saveShowPrompts;             // Options is some kind of Registry gizmo.

            base.Dispose(disposing);
        }
Ejemplo n.º 12
0
        public void FDOCompetingTransactions()
        {
            CheckDisposed();

            FdoCache a = FdoCache.Create("TestlangProj");

            AddWord(a);

            UndoResult ures_a = 0;

            while (a.CanUndo)
            {
                a.Undo(out ures_a);
                if (ures_a == UndoResult.kuresFailed || ures_a == UndoResult.kuresError)
                {
                    Assert.Fail("ures should not be == " + ures_a.ToString());
                }
            }
            a.Dispose();


            FdoCache b = FdoCache.Create("TestlangProj");

            AddWord(b);

            UndoResult ures_b = 0;

            while (b.CanUndo)
            {
                b.Undo(out ures_b);
                if (ures_b == UndoResult.kuresFailed || ures_b == UndoResult.kuresError)
                {
                    Assert.Fail("ures should not be == " + ures_b.ToString());
                }
            }
            b.Dispose();
        }
Ejemplo n.º 13
0
        public void CleanUp()
        {
            CheckDisposed();

            UndoResult ures = 0;

            while (m_cache.CanUndo)
            {
                m_cache.Undo(out ures);
                if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                {
                    Assert.Fail("ures should not be == " + ures.ToString());
                }
            }
            // Don't dispose the cache, until after the window closes, as it needs it
            // to clear its notification from the cache.
            // m_mainWnd.Hide();
            m_mainWnd.Close();
            // m_mainWnd.Dispose(); // Not needed, since Close calls Dispose.
            m_mainWnd = null;

            m_cache.Dispose();
            m_cache = null;
        }
Ejemplo n.º 14
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Undo the action(s) in this object.
        /// </summary>
        /// <returns>
        /// Cumulative result of undoing all the actions. If we succeeded, then this will
        /// be kuresSuccess.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        protected UndoResult UndoRollbackCommon()
        {
            // Because of the complexities of our undo/redo system, we need to do the undo
            // in multiple passes:
            // 1) Restores any deleted objects.
            // 2) Undo any actions that are data change actions.
            // 3) Fire any PropChanges.
            // 4) Undo any actions that are not data change actions (e.g., selection change actions)

            m_uowService.SuppressSelections = true;
            UndoResult result = UndoResult.kuresSuccess;

            try
            {
                // Do the first pass (Restores any deleted objects)
                for (int i = m_changes.Count - 1; i >= 0; i--)
                {
                    IUndoAction undoAction = m_changes[i];
                    if (undoAction is IFirstPassUndo)
                    {
                        ((IFirstPassUndo)undoAction).FirstPassUndo();
                    }
                }

                // Do the second pass (Undo any actions that are data change actions)
                for (int i = m_changes.Count - 1; i >= 0; i--)
                {
                    if (m_changes[i].IsDataChange && !m_changes[i].Undo())
                    {
                        // TODO: Redo any changes that have been undone
                        return(UndoResult.kuresFailed);
                    }
                }

                // Do the third pass (Fire any PropChanges)
                // swap cvIns and cvDel fields for each change notification, because we are doing the
                // reverse of the original change
                IEnumerable <ChangeInformation> changes = from change in GetPropChangeInformation(true).Reverse()
                                                          select change.ChangeForUndo;
                // Fire PropChanged calls so display is updated.
                try
                {
                    m_uowService.SendPropChangedNotifications(changes);
                }
                catch (Exception e)
                {
                    Logger.WriteEvent("Exception during PropChanges in Undo");
                    Logger.WriteError(e);
                    result = UndoResult.kuresRefresh;
                }
            }
            finally
            {
                m_uowService.SuppressSelections = false;
            }

            // Do the fourth pass (Undo any actions that are not data change actions)
            for (int i = m_changes.Count - 1; i >= 0; i--)
            {
                if (!m_changes[i].IsDataChange && !m_changes[i].Undo())
                {
                    // TODO: Redo any changes that have been undone
                    return(UndoResult.kuresFailed);
                }
            }

            return(result);
        }
Ejemplo n.º 15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Redo the action(s) in this object. This is overridden to do nothing in
        /// non-undoable unit of work, but may be called even from there in one special case.
        /// </summary>
        /// <returns>
        /// Cumulative result of redoing all the actions. If we succeeded, then this will
        /// be kuresSuccess.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Redo the action(s) in this object.
        /// </summary>
        internal virtual UndoResult Redo()
        {
            // Because of the complexities of our undo/redo system, we need to do the redo
            // in multiple passes:
            // 1) Restores any created objects.
            // 2) Redo any actions that are data change actions.
            // 3) Fire any PropChanges.
            // 4) Redo any actions that are not data change actions (e.g., selection change actions)

            m_uowService.SuppressSelections = true;
            UndoResult result = UndoResult.kuresSuccess;

            try
            {
                // Do the first pass (Restores any created objects)
                foreach (IUndoAction undoAction in m_changes)
                {
                    if (undoAction is IFirstPassRedo)
                    {
                        ((IFirstPassRedo)undoAction).FirstPassRedo();
                    }
                }

                // Do the second pass (Redo any actions that are data change actions)
                foreach (IUndoAction undoAction in m_changes)
                {
                    if (undoAction.IsDataChange && !undoAction.Redo())
                    {
                        // TODO: Undo any changes that have been redone
                        return(UndoResult.kuresFailed);
                    }
                }

                try
                {
                    // Do the third pass (Fire any PropChanges)
                    m_uowService.SendPropChangedNotifications(GetPropChangeInformation(false));
                }
                catch (Exception e)
                {
                    Logger.WriteEvent("Exception during PropChanges in Redo");
                    Logger.WriteError(e);
                    result = UndoResult.kuresRefresh;
                }
            }
            finally
            {
                m_uowService.SuppressSelections = false;
            }

            // Do the fourth pass (Redo any actions that are not data change actions)
            foreach (IUndoAction undoAction in m_changes)
            {
                if (!undoAction.IsDataChange && !undoAction.Redo())
                {
                    // TODO: Undo any changes that have been redone
                    return(UndoResult.kuresFailed);
                }
            }

            return(result);
        }
Ejemplo n.º 16
0
		private void HandleUndoResult(UndoResult ures, bool fPrivate)
		{
			// Enhance JohnT: may want to display messages for kuresFailed, kuresError
			if (ures != UndoResult.kuresSuccess)
			{

				if (!fPrivate && m_app != null)
				{
					// currently implemented, this will cause this app to do a master refresh,
					m_app.Synchronize(SyncMsg.ksyncUndoRedo);
				}
				else
				{
					// EricP/JohnT -- this path will probably never be called in a production
					// context, since we'll have an FwApp. And even in the case of tests
					// taking this path, we wonder if we should issue a "MasterRefresh" instead
					m_mediator.SendMessage("Refresh", this);
				}
			}
		}
Ejemplo n.º 17
0
			internal void OnUndo(out UndoResult ures)
			{
				TextSelInfo tsiBeforeUndo;
				OnUndo(out tsiBeforeUndo, out ures);
			}
Ejemplo n.º 18
0
			internal void OnRedo(out TextSelInfo tsiBeforeRedo, out UndoResult ures)
			{
				using (new StateTransitionHelper(this, m_expectedTextAnnotationsDefnsAfterUndo, m_expectedTextAnnotationsDefnsAfterRedo))
				{
					tsiBeforeRedo = this.CurrentSelectionInfo;
					Cache.Redo(out ures);
					if (ures == UndoResult.kuresRefresh)
						ResyncAllParaContents();
				}
			}
Ejemplo n.º 19
0
			internal void ValidateUndoRedo(UndoResult uresExpected, UndoResult uresActual,
				TextSelInfo tsiExpectedAfterUndoRedo)
			{
				Assert.AreEqual(uresExpected, uresActual, "UndoResult");
				ValidateUndoRedo(tsiExpectedAfterUndoRedo);
			}