Пример #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected UnitOfWorkHelper(IActionHandler actionHandler)
		{
			if (actionHandler == null) throw new ArgumentNullException("actionHandler");

			m_actionHandler = actionHandler;
			RollBack = true;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Perform the specified task, making it an undoable task in the specified action handler, with
		/// the specified labels. The task will automatically be begun and ended if all goes well, and rolled
		/// back if an exception is thrown; the exception will then be rethrown.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static void Do(string undoText, string redoText, IActionHandler actionHandler, Action task)
		{
			using (var undoHelper = new UndoableUnitOfWorkHelper(actionHandler, undoText, redoText))
			{
				task();
				undoHelper.RollBack = false; // task ran successfully, don't roll back.
			}
		}
Пример #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Start the undo task
		/// </summary>
		/// <param name="actionHandler">The IActionHandler to start the undo task on</param>
		/// <param name="rootSite">The view (can be <c>null</c>)</param>
		/// <param name="stid">String resource id used for Undo/Redo labels</param>
		/// ------------------------------------------------------------------------------------
		public UndoTaskHelper(IActionHandler actionHandler, IVwRootSite rootSite, string stid) :
			base(actionHandler)
		{
			m_vwRootSite = rootSite;

			string stUndo, stRedo;
			ResourceHelper.MakeUndoRedoLabels(stid, out stUndo, out stRedo);
			Init(stUndo, stRedo);
		}
Пример #4
0
	public void AddHandler(IActionHandler handler)
	{
		for (int i = 0; i < actionHandlerList.Count; ++i)
		{
			if (actionHandlerList[i] == handler)
				return;
		}
		actionHandlerList.Add(handler);
	}
Пример #5
0
        public void RegisterActionHandler(IActionHandler actionHandler)
        {
            if (ActionHandlers.ContainsKey(actionHandler.ActionGroup))
            {
                throw new ActionHandlerAlreadyRegisteredException();
            }

            ActionHandlers.Add(actionHandler.ActionGroup, actionHandler);
        }
Пример #6
0
		internal int m_chvoDel; // On Do, Redo; #inserted on Undo.

		/// <summary>
		/// Make an instance and add it to the undo stack. Also, if it's the 'redo' action added after the
		/// actual changes (fForRedo is true), issue the propchanged at once to complete the original action.
		/// </summary>
		public static ExtraPropChangedAction AddAndInvokeIfRedo(IActionHandler actionHandler, ISilDataAccess sda, int hvo, int tag, int
			ihvo, int chvoIns, int chvoDel, bool fForRedo)
		{

			ExtraPropChangedAction action = new ExtraPropChangedAction(sda, hvo, tag, ihvo, chvoIns, chvoDel, fForRedo);
			actionHandler.AddAction(action);
			if (fForRedo)
				action.Redo();
			return action;
		}
Пример #7
0
        internal GameEngine(IUniverse universe, IGravitySimulator gravitySimulator, IGameObjectFactory gameObjectFactory, IKeyboardHandler keyboardHandler, IActionHandler actionHandler, IDrawingManager drawingManager)
        {
            _universe = universe;
            _drawingManager = drawingManager;
            _gravitySimulator = gravitySimulator;

            _gameObjectFactory = gameObjectFactory;

            _keyboardHandler = keyboardHandler;
            _actionHandler = actionHandler;
            _controllerFactory = new ControllerFactory(_keyboardHandler);
            actionHandler.RegisterTriggerAction(Keys.Space, () => _paused = !_paused);
        }
Пример #8
0
 public LayerListCreator(IEventAggregator eventAggregator, IAmeSession session, IActionHandler actionHandler)
 {
     this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator is null");
     this.actionHandler   = actionHandler ?? throw new ArgumentNullException("handler is null");
     this.Session         = session ?? throw new ArgumentNullException("session is null");
 }
 public CompositeRepositoryBase(IActionHandler handler, DihlDbContext dbContext, IDomainDataMapper <T, TU> mapper)
     : base(handler, dbContext, mapper)
 {
 }
Пример #10
0
 /// <summary>Member SetActionHandler</summary>
 /// <param name='actionhandler'>action handler</param>
 public void SetActionHandler(IActionHandler actionhandler)
 {
     m_baseSda.SetActionHandler(actionhandler);
 }
Пример #11
0
 /// <summary>
 /// Make one.
 /// </summary>
 public ExtraPropChangedInserter(IActionHandler actionHandler, ISilDataAccess sda, int hvo, int tag, int
                                 ihvo, int chvoIns, int chvoDel)
 {
     m_actionHandler = actionHandler;
     m_action        = ExtraPropChangedAction.AddAndInvokeIfRedo(m_actionHandler, sda, hvo, tag, ihvo, chvoIns, chvoDel, false);
 }
Пример #12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Deprecated Constructor, for tests only. Prefer to pass the Undo and Redo text separately.
		/// </summary>
		/// <param name="actionHandler"></param>
		/// <param name="message">
		/// The part of the 'Undo some change' and 'Redo some change'
		/// that comes after 'Undo ' and 'Redo '.
		/// </param>
		/// ------------------------------------------------------------------------------------
		public UndoableUnitOfWorkHelper(IActionHandler actionHandler, string message) :
			this(actionHandler, "Undo " + message, "Redo " + message)
		{
		}
Пример #13
0
		/// <summary>
		/// Two changes have been made, first on firstStack, then on secondStack. Verify that they must be Undone
		/// in the reverse order, and redone in the same order.
		/// </summary>
		/// <param name="firstStack"></param>
		/// <param name="secondStack"></param>
		private void VerifyOrderRequired(IActionHandler firstStack, IActionHandler secondStack)
		{
			Assert.That(firstStack.CanUndo(), Is.False); // can't undo the first change before the other.
			Assert.That(secondStack.CanUndo(), Is.True);
			secondStack.Undo(); // get back to where we can Undo creating it.
			Assert.That(firstStack.CanUndo(), Is.True); // now the second one is undone, we can
			firstStack.Undo(); // now both are undone.
			Assert.That(secondStack.CanRedo(), Is.False); // can't redo the second change first
			Assert.That(firstStack.CanRedo(), Is.True); // but of course we can redo the first one first
			firstStack.Redo();
			Assert.That(secondStack.CanRedo(), Is.True); // now we can redo the second change, since we already redid the first.

		}
Пример #14
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Deprecated Constructor, for tests only. Prefer to pass the Undo and Redo text separately.
 /// </summary>
 /// <param name="actionHandler"></param>
 /// <param name="message">
 /// The part of the 'Undo some change' and 'Redo some change'
 /// that comes after 'Undo ' and 'Redo '.
 /// </param>
 /// ------------------------------------------------------------------------------------
 public UndoableUnitOfWorkHelper(IActionHandler actionHandler, string message) :
     this(actionHandler, "Undo " + message, "Redo " + message)
 {
 }
Пример #15
0
 /// <summary>
 /// 执行新动作
 /// </summary>
 /// <param name="action"></param>
 public void ExcuteHandler(IActionHandler <TAction> action)
 {
     CurrHandle = action;
     EventDispatcher.Instance().OnEmitEvent(GOAPEventType.ActionMgrExcuteHandler, new object[] { agent.Context.GoalbalID, CurrHandle });
 }
 public async Task AfterHandlerAsync <TAction>(IDispatchContext <TAction> context, IActionHandler <TAction> actionHandler, CancellationToken cancellationToken) where TAction : IAction
 {
     foreach (var hook in _afterActionHooks)
     {
         await hook.AfterHandlerAsync(context, actionHandler, cancellationToken);
     }
 }
Пример #17
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Constructor.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public UndoableUnitOfWorkHelper(IActionHandler actionHandler, string undoText, string redoText) :
     base(actionHandler)
 {
     m_actionHandler.BeginUndoTask(undoText, redoText);
 }
Пример #18
0
Файл: Tree.cs Проект: JCYTop/Tmp
 public TreeNode <TAction> CreateNode(IActionHandler <TAction> handler = null)
 {
     return(new TreeNode <TAction>(handler));
 }
Пример #19
0
 public void ActionHandlerRemove(IActionHandler handler)
 {
     m_ActionHandlers.Remove(handler);
 }
Пример #20
0
 public SettingsRepository(IActionHandler handler, DihlDbContext dbContext)
 {
     _handler = handler;
     _context = dbContext;
 }
Пример #21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set the <see cref="IActionHandler"/> that is being used to record undo information.
		/// </summary>
		/// <param name="acth">The <see cref="IActionHandler"/> object. May be <c>null</c>.
		/// </param>
		/// ------------------------------------------------------------------------------------
		public void SetActionHandler(IActionHandler acth)
		{
			CheckDisposed();
			m_acth = acth;
		}
Пример #22
0
 /// <summary>
 ///
 /// </summary>
 protected void DisposeEverythingButBase()
 {
     m_cache?.Dispose();
     m_cache         = null;
     m_actionHandler = null;
 }
Пример #23
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 virtual void Dispose(bool disposing)
		{
			Debug.WriteLineIf(!disposing, "****************** CacheBase 'disposing' is false. ******************");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				Clear();
				if (m_vvnc != null)
					m_vvnc.Clear();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_htCache = null;
			m_htVirtualProps = null;
			if (m_wsf != null)
				m_wsf.Shutdown();
			m_wsf = null;
			m_mdc = null;
			m_vvnc = null;
			m_acth = null;

			m_isDisposed = true;
		}
Пример #24
0
 public void Reg(string key, IActionHandler actionHandler)
 {
     Dictionary.Add(key, actionHandler);
 }
		/// <summary>Member SetActionHandler</summary>
		/// <param name='actionhandler'>action handler</param>
		public override void SetActionHandler(IActionHandler actionhandler)
		{
			m_domainDataByFlid.SetActionHandler(actionhandler);
		}
Пример #26
0
 /// <summary>
 /// PlaylistsAdapter constructor. Set up a long click listener and the group expander helper class
 /// </summary>
 /// <param name="context"></param>
 /// <param name="parentView"></param>
 /// <param name="provider"></param>
 public PlaylistsAdapter(Context context, ExpandableListView parentView, IGroupContentsProvider <Playlist> provider, IActionHandler actionHandler) :
     base(context, parentView, provider, PlaylistsAdapterModel.BaseModel, actionHandler)
 {
 }
        public LayerListGroupViewModel(IEventAggregator eventAggregator, IAmeSession session, IActionHandler handler, LayerGroup layer)
        {
            this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator");
            this.session         = session ?? throw new ArgumentNullException("session is null");
            this.layer           = layer ?? throw new ArgumentNullException("layer");
            this.actionHandler   = handler ?? throw new ArgumentNullException("handler is null");

            this.LayerNodes = new ObservableCollection <ILayerListNodeViewModel>();
            this.isDragging = false;

            DrawingGroup drawingGroup = new DrawingGroup();
            DrawingGroup filled       = new DrawingGroup();

            using (DrawingContext context = filled.Open())
            {
                Rect drawingRect = new Rect(0, 0, layer.GetPixelWidth(), layer.GetPixelHeight());
                context.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Transparent, 0), drawingRect);
            }
            drawingGroup.Children.Add(filled);
            drawingGroup.Children.Add(layer.Group);
            this.layerPreview = new DrawingImage(drawingGroup);

            this.layer.Layers.CollectionChanged += LayersChanged;

            this.EditTextboxCommand         = new DelegateCommand(() => EditTextbox());
            this.StopEditingTextboxCommand  = new DelegateCommand(() => StopEditingTextbox());
            this.MouseLeftButtonDownCommand = new DelegateCommand <object>((point) => HandleLeftClickDown((MouseEventArgs)point));
            this.MouseMoveCommand           = new DelegateCommand <object>((point) => HandleMouseMove((MouseEventArgs)point));
            this.DropCommand      = new DelegateCommand <object>((point) => HandleDropCommand((DragEventArgs)point));
            this.DragOverCommand  = new DelegateCommand <object>((args) => HandleDragOverCommand((DragEventArgs)args));
            this.DragEnterCommand = new DelegateCommand <object>((args) => HandleDragEnterCommand((DragEventArgs)args));
            this.DragLeaveCommand = new DelegateCommand <object>((args) => HandleDragLeaveCommand((DragEventArgs)args));
        }
Пример #28
0
 /// <summary>
 /// Creates an instance of <see cref="SeasonRepository"/>
 /// </summary>
 /// <param name="handler"></param>
 /// <param name="dbContext"></param>
 /// <param name="mapper"></param>
 public SeasonRepository(IActionHandler handler, DihlDbContext dbContext, IDomainDataMapper <Season, SeasonDataModel> mapper)
     : base(handler, dbContext, mapper)
 {
 }
Пример #29
0
		private ILexReference CreateSeqRefToSense(IActionHandler stack, ILexSense ls, bool createReferringObjInSameUow)
		{
			ILexReference lr = null;
			UndoableUnitOfWorkHelper.Do("Undo create referring item on new stack", "Redo",
				stack,
				() =>
				{
					var list = Cache.LangProject.LexDbOA.ReferencesOA;
					if (list == null)
					{
						list = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().Create();
						Cache.LangProject.LexDbOA.ReferencesOA = list;
					}
					var lrt = Cache.ServiceLocator.GetInstance<ILexRefTypeFactory>().Create();
					list.PossibilitiesOS.Add(lrt);
					lr = Cache.ServiceLocator.GetInstance<ILexReferenceFactory>().Create();
					lrt.MembersOC.Add(lr);
					if (!createReferringObjInSameUow)
						stack.BreakUndoTask("undo setting ref", "redo setting ref");
					lr.TargetsRS.Add(ls);
				});
			return lr;
		}
Пример #30
0
 public Decorator(IActionHandler handler, IRequestHandler <TRequest, TResponse> inner)
 {
     ActionHandler = handler;
     _decorated    = inner;
 }
Пример #31
0
 /// <summary>
 /// Creates an instance of <see cref="LeagueRepository"/>
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="leagueMapper"></param>
 public LeagueRepository(IActionHandler handler, DihlDbContext dbContext, IDomainDataMapper <League, LeagueDataModel> mapper)
     : base(handler, dbContext, mapper)
 {
 }
Пример #32
0
 internal UndoableUOWHelperForTests(IActionHandler actionHandler)
 {
     m_actionHandler   = actionHandler;
     OriginalUndoCount = m_actionHandler.UndoableSequenceCount;
 }
Пример #33
0
        private static void RegisterHandler(IActionManager actionManager, string actionId, Lifetime lifetime, IActionHandler handler)
        {
            var action = actionManager.GetExecutableAction(actionId);

            if (action != null)
            {
                action.AddHandler(lifetime, handler);
            }
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Start the undo task
 /// </summary>
 /// <param name="actionHandler">The action handler.</param>
 /// <param name="rootSite">The view</param>
 /// <param name="stid">String resource id used for Undo/Redo labels</param>
 /// ------------------------------------------------------------------------------------
 public DummyUndoTaskHelper(IActionHandler actionHandler, RootSite rootSite, string stid)
     : base(actionHandler, rootSite, stid)
 {
 }
Пример #35
0
 /// <summary>
 /// Creates an instance of <see cref="TeamRepository"/>
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="leagueMapper"></param>
 public TeamRepository(IActionHandler handler, DihlDbContext dbContext, IDomainDataMapper <Team, TeamDataModel> mapper)
     : base(handler, dbContext, mapper)
 {
 }
Пример #36
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Start the undo task
 /// </summary>
 /// <param name="actionHandler">The IActionHandler to start the undo task on</param>
 /// <param name="rootSite">The view (can be <c>null</c>)</param>
 /// <param name="stUndo">Undo label</param>
 /// <param name="stRedo">Redo label</param>
 /// ------------------------------------------------------------------------------------
 public UndoTaskHelper(IActionHandler actionHandler, IVwRootSite rootSite, string stUndo,
                       string stRedo) : base(actionHandler)
 {
     m_vwRootSite = rootSite;
     Init(stUndo, stRedo);
 }
Пример #37
0
        ActionResult IDataController.Execute(string controller, string view, ActionArgs args)
        {
            ActionResult result = new ActionResult();

            SelectView(controller, view);
            try
            {
                IActionHandler handler = _config.CreateActionHandler();
                if (_config.PlugIn != null)
                {
                    _config.PlugIn.PreProcessArguments(args, result, CreateViewPage());
                }
                if (args.SqlCommandType != CommandConfigurationType.None)
                {
                    using (DbConnection connection = CreateConnection())
                    {
                        ExecutePreActionCommands(args, result, connection);
                        if (handler != null)
                        {
                            handler.BeforeSqlAction(args, result);
                        }
                        if ((result.Errors.Count == 0) && !(result.Canceled))
                        {
                            DbCommand command = CreateCommand(connection, args);
                            if ((args.SelectedValues != null) && (((args.LastCommandName == "BatchEdit") && (args.CommandName == "Update")) || ((args.CommandName == "Delete") && (args.SelectedValues.Length > 1))))
                            {
                                ViewPage page = CreateViewPage();
                                PopulatePageFields(page);
                                string originalCommandText = command.CommandText;
                                foreach (string sv in args.SelectedValues)
                                {
                                    string[] key      = sv.Split(',');
                                    int      keyIndex = 0;
                                    foreach (FieldValue v in args.Values)
                                    {
                                        DataField field = page.FindField(v.Name);
                                        if (field != null)
                                        {
                                            if (!(field.IsPrimaryKey))
                                            {
                                                v.Modified = true;
                                            }
                                            else
                                            if (v.Name == field.Name)
                                            {
                                                v.OldValue = key[keyIndex];
                                                v.Modified = false;
                                                keyIndex++;
                                            }
                                        }
                                    }
                                    ConfigureCommand(command, null, args.SqlCommandType, args.Values);
                                    result.RowsAffected = (result.RowsAffected + TransactionManager.ExecuteNonQuery(command));
                                    if (handler != null)
                                    {
                                        handler.AfterSqlAction(args, result);
                                    }
                                    command.CommandText = originalCommandText;
                                    command.Parameters.Clear();
                                    if (_config.PlugIn != null)
                                    {
                                        _config.PlugIn.ProcessArguments(args, result, page);
                                    }
                                }
                            }
                            else
                            {
                                if (ConfigureCommand(command, null, args.SqlCommandType, args.Values))
                                {
                                    result.RowsAffected = TransactionManager.ExecuteNonQuery(args, result, CreateViewPage(), command);
                                    if (result.RowsAffected == 0)
                                    {
                                        result.RowNotFound = true;
                                        result.Errors.Add(Localizer.Replace("RecordChangedByAnotherUser", "The record has been changed by another user."));
                                    }
                                    else
                                    {
                                        ExecutePostActionCommands(args, result, connection);
                                    }
                                }
                                if (handler != null)
                                {
                                    handler.AfterSqlAction(args, result);
                                }
                                if (_config.PlugIn != null)
                                {
                                    _config.PlugIn.ProcessArguments(args, result, CreateViewPage());
                                }
                            }
                        }
                    }
                }
                else
                if (args.CommandName.StartsWith("Export"))
                {
                    ExecuteDataExport(args, result);
                }
                else
                if (args.CommandName.Equals("PopulateDynamicLookups"))
                {
                    PopulateDynamicLookups(args, result);
                }
                else
                if (args.CommandName.Equals("ProcessImportFile"))
                {
                    ImportProcessor.Execute(args);
                }
                else
                if (args.CommandName.Equals("Execute"))
                {
                    using (DbConnection connection = CreateConnection())
                    {
                        DbCommand command = CreateCommand(connection, args);
                        TransactionManager.ExecuteNonQuery(command);
                    }
                }
                else
                if (handler != null)
                {
                    handler.ExecuteAction(args, result);
                    ((BusinessRules)(handler)).ProcessSpecialActions(args, result);
                }
                else
                {
                    CreateBusinessRules().ProcessSpecialActions(args, result);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(System.Reflection.TargetInvocationException))
                {
                    ex = ex.InnerException;
                }
                HandleException(ex, args, result);
            }
            return(result);
        }
Пример #38
0
 /// <inheritdoc />
 IButton IDialogWindow.AddButton(string label, IActionHandler actionHandler)
 {
     return(((IDialogWindow)this).AddButton(label, actionHandler, false));
 }
Пример #39
0
        /// <summary>
        /// 获取处理器
        /// </summary>
        /// <param name="pType">接口类型</param>
        /// <param name="pAction">接口请求操作</param>
        /// <param name="pVersion">接口版本号</param>
        /// <returns>接口请求处理器</returns>
        public static IActionHandler GetActionHandler(APITypes pType, string pAction)
        {
            var sections = pAction.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);

            switch (pType)
            {
            case APITypes.Product:
                #region 产品接口处理器创建
            {
                if (sections.Length < 3)
                {
                    throw new APIException(ERROR_CODES.INVALID_REQUEST_INVALID_ACTION_FORMAT, "action值的格式错误,在产品接口下,action的格式为:[模块名].[对象名].[操作名]");
                }
                var            className = string.Format("{0}.{1}.{2}.{3}AH", ActionHandlerFactory.PRODUCT_ACTION_HANDLER_BASE_NAMESPACE, sections[0], sections[1], sections[2]);
                IActionHandler handler   = null;
                try
                {
                    var oh = Activator.CreateInstance(null, className);
                    if (oh != null)
                    {
                        handler = oh.Unwrap() as  IActionHandler;
                    }
                }
                catch (Exception ex)
                {
                    throw new APIException(ERROR_CODES.INVALID_REQUEST_CAN_NOT_FIND_ACTION_HANDLER, string.Format("根据action找不到指定的ActionHandler类.原因:[{0}]", ex.Message), ex);
                }
                //
                return(handler);
            }

                #endregion
            case APITypes.Project:
                #region 项目接口处理器创建
            {
                if (sections.Length < 4)
                {
                    throw new APIException(ERROR_CODES.INVALID_REQUEST_INVALID_ACTION_FORMAT, "action值的格式错误,在产品接口下,action的格式为:[客户ID].[模块名].[对象名].[操作名]");
                }
                var            className = string.Format("{0}.{1}.{2}.{3}.{4}AH", ActionHandlerFactory.PROJECT_ACTION_HANDLER_BASE_NAMESPACE, sections[0], sections[1], sections[2], sections[3]);
                IActionHandler handler   = null;
                try
                {
                    var oh = Activator.CreateInstance(null, className);
                    if (oh != null)
                    {
                        handler = oh.Unwrap() as IActionHandler;
                    }
                }
                catch (Exception ex)
                {
                    throw new APIException(ERROR_CODES.INVALID_REQUEST_CAN_NOT_FIND_ACTION_HANDLER, string.Format("根据action找不到指定的ActionHandler类.原因:[{0}]", ex.Message), ex);
                }
                //
                return(handler);
            }

                #endregion
            default:
                throw new NotImplementedException();
            }
        }
Пример #40
0
		private void OnCommitText(string text, bool checkIfFocused)
		{
			var selHelper = SetupForTypingEventHandler(checkIfFocused, true);
			if (selHelper == null)
				return;
			try
			{
				var selectionProps = GetSelectionProps(selHelper);

				var countBackspace = TrimBeginningBackspaces(ref text);
				var bottom = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
				selHelper.IchAnchor = Math.Max(0,
					selHelper.GetIch(SelectionHelper.SelLimitType.Top) - countBackspace);
				selHelper.IchEnd = bottom;

				if (m_ActionHandler == null && m_InitialSelection != null && m_EndOfPreedit != null)
				{
					// we don't have an action handler which means we didn't roll back the
					// preedit. This means we have create a range selection that deletes the
					// preedit.
					selHelper.IchAnchor = Math.Max(0, m_InitialSelection.SelectionHelper.GetIch(
						SelectionHelper.SelLimitType.Top) - countBackspace);
					selHelper.IchEnd = m_EndOfPreedit.GetIch(SelectionHelper.SelLimitType.Bottom);
				}
				selHelper.SetSelection(true);

				// Insert 'text'
				ITsString str = CreateTsStringUsingSelectionProps(text, selectionProps, false);
				selHelper.Selection.ReplaceWithTsString(str);
			}
			finally
			{
				m_InitialSelection = null;
				m_EndOfPreedit = null;
				if (m_ActionHandler != null)
				{
					m_ActionHandler.EndUndoTask();
					m_ActionHandler = null;
				}
			}
		}
Пример #41
0
        /// <summary> Resolves all registered menus and items and tells the main window to handle it. </summary>
        /// <param name="mainWindow">Main window</param>
        public static void AddExtensionPointToolbarItems(IMainWindow mainWindow)
        {
            IConfigurationElement[] configurationElements = ExtensionService.Instance.GetConfigurationElements(ExtensionPointId);

            IConfigurationElement[] groupElements     = configurationElements.Where(x => x.Prefix == "toolbarGroup").ToArray();
            IConfigurationElement[] groupItemElements = configurationElements.Where(x => x.Prefix == "toolbarItem").ToArray();

            for (int i = -1; ++i < groupElements.Length;)
            {
                IConfigurationElement element = groupElements[i];
                string id = element["id"];
                ToolbarGroupContribution menu = new ToolbarGroupContribution(id);
                _idToMenuMap.Add(id, menu);
            }

            // Collection of all opened streams
            List <Stream> streamList = new List <Stream>(20);

            for (int i = -1; ++i < groupItemElements.Length;)
            {
                IConfigurationElement element = groupItemElements[i];
                string id      = element["id"];
                string group   = element["group"];
                string handler = element["handler"];
                string image   = element["image"];
                string label   = element["label"];

                IBundle providingBundle = ExtensionService.Instance.GetProvidingBundle(element);

                IActionHandler actionHandler = null;
                if (!string.IsNullOrEmpty(handler))
                {
                    Type handlerType = TypeLoader.TypeForName(providingBundle, handler);
                    actionHandler = handlerType.NewInstance <IActionHandler>();
                }

                Stream imageStream = null;
                if (!string.IsNullOrEmpty(image))
                {
                    imageStream = providingBundle.GetAssemblyResourceAsStream(image);
                    streamList.Add(imageStream);
                }

                // NLS support
                label = NLS.Localize(label, actionHandler);

                ToolbarItemContribution  menuItem = new ToolbarItemContribution(id, group, actionHandler, label, imageStream);
                ToolbarGroupContribution menuInstance;
                if (_idToMenuMap.TryGetValue(group, out menuInstance))
                {
                    menuInstance.GroupItems.Add(menuItem);
                }
            }

            using (IEnumerator <ToolbarGroupContribution> itr = _idToMenuMap.Values.GetEnumerator()) {
                while (itr.MoveNext())
                {
                    ToolbarGroupContribution contribution = itr.Current;
                    mainWindow.AddToolbarGroup(contribution);
                }
            }

            // Disposing all opened streams
            using (IEnumerator <Stream> itr = streamList.GetEnumerator()) {
                while (itr.MoveNext())
                {
                    Stream stream = itr.Current;
                    stream?.Dispose();
                }
            }
        }
Пример #42
0
		/// <summary>
		/// Reset the selection and optionally cancel any open compositions.
		/// </summary>
		/// <param name="cancel">Set to <c>true</c> to also cancel the open composition.</param>
		/// <returns><c>true</c> if there was an open composition that we cancelled, otherwise
		/// <c>false</c>.</returns>
		private bool Reset(bool cancel)
		{
			if (m_InReset)
				return false;

			bool retVal = false;
			m_InReset = true;
			try
			{
				if (cancel && m_ActionHandler != null)
				{
					m_ActionHandler.Rollback(m_Depth);
					retVal = true;
				}
				bool resetSelections = m_ActionHandler != null;
				m_ActionHandler = null;

				if (m_InitialSelection != null)
					m_InitialSelection.RestoreSelection();
				if (resetSelections)
				{
					m_InitialSelection = null;
					m_EndOfPreedit = null;
				}
				return retVal;
			}
			finally
			{
				m_InReset = false;
			}
		}
Пример #43
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// No need to do anything in here.
		/// </summary>
		/// <remarks>Removes all COM references to the ActionHandler and frees certain
		/// resources. This should be called before the application ends to avoid circular
		/// reference issues.</remarks>
		/// ------------------------------------------------------------------------------------
		public void Close()
		{
			CheckDisposed();
			m_acth = null;
		}
Пример #44
0
		/// <summary>Member SetActionHandler</summary>
		/// <param name='actionhandler'>action handler</param>
		public void SetActionHandler(IActionHandler actionhandler)
		{
			m_baseSda.SetActionHandler(actionhandler);
		}
Пример #45
0
		/// <summary>
		/// Make one.
		/// </summary>
		public ExtraPropChangedInserter(IActionHandler actionHandler, ISilDataAccess sda, int hvo, int tag, int
			ihvo, int chvoIns, int chvoDel)
		{
			m_actionHandler = actionHandler;
			m_action = ExtraPropChangedAction.AddAndInvokeIfRedo(m_actionHandler, sda, hvo, tag, ihvo, chvoIns, chvoDel, false);
		}
Пример #46
0
 /// <summary>
 /// Creates an instance of <see cref="GameSkaterStatisticRepository"/>
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="mapper"></param>
 public GameSkaterStatisticRepository(IActionHandler handler, DihlDbContext dbContext, IDomainDataMapper <GameSkaterStatistic, GameSkaterStatisticDataModel> mapper)
     : base(handler, dbContext, mapper)
 {
 }
		/// <summary>Member SetActionHandler</summary>
		/// <param name='actionhandler'>action handler</param>
		public virtual void SetActionHandler(IActionHandler actionhandler)
		{
			throw new NotImplementedException();
		}
Пример #48
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Perform the specified task, making it an undoable task in the action handler if
		/// necessary (using the specified labels). If an undoable action has already been
		/// started, then this task will be done as part of the existing UOW. If an undo task is
		/// created and the specified task completes normally, the UOW will be added to the undo
		/// stack; it will be rolled back if an exception is thrown. (The exception will then be
		/// rethrown.)
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static void DoUsingNewOrCurrentUOW(string undoText, string redoText,
			IActionHandler actionHandler, Action task)
		{
			if (actionHandler.CurrentDepth > 0)
				task();
			else
				Do(undoText, redoText, actionHandler, task);
		}
Пример #49
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public UndoableUnitOfWorkHelper(IActionHandler actionHandler, string undoText, string redoText) :
			base(actionHandler)
		{
			m_actionHandler.BeginUndoTask(undoText, redoText);
		}
Пример #50
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>
		private void Dispose(bool disposing)
		{
			System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				ClearAllData();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_metaDataCache = null;
			m_actionhandler = null;
			m_lgWritingSystemFactory = null;
			m_basicObjectCache = null;
			m_extendedKeyCache = null;
			m_basicITsStringCache = null;
			m_basicByteArrayCache = null;
			m_guidCache = null;
			m_guidToHvo = null;
			m_intCache = null;
			m_longCache = null;
			m_boolCache = null;
			m_vectorCache = null;
			m_timeStampCache = null;

			m_isDisposed = true;
		}
		/// <summary>
		/// Reset the selection and optionally cancel any open compositions.
		/// </summary>
		/// <param name="cancel">Set to <c>true</c> to also cancel the open composition.</param>
		/// <returns><c>true</c> if there was an open composition that we cancelled, otherwise
		/// <c>false</c>.</returns>
		private bool Reset(bool cancel)
		{
			if (m_InReset)
				return false;

			bool retVal = false;
			m_InReset = true;
			try
			{
				if (cancel)
				{
					if (m_ActionHandler != null &&
						(m_ActionHandler.get_TasksSinceMark(true) || m_Depth != m_ActionHandler.CurrentDepth))
					{
						m_ActionHandler.Rollback(m_Depth);
						retVal = true;
					}
					else if (m_InitialSelection != null && m_EndOfPreedit != null)
					{
						var selHelper = SetupForTypingEventHandler(false, true);
						if (selHelper != null)
						{
							// Update selection so that we can delete the preedit-text
							UpdateSelectionForReplacingPreeditText(selHelper, 0);
							selHelper.SetSelection(true);

							if (selHelper.IsValid && selHelper.IsRange)
							{
								var tss = CreateTsStringUsingSelectionProps(string.Empty, null, false);
								selHelper.Selection.ReplaceWithTsString(tss);
							}
						}
					}
				}
				m_ActionHandler = null;

				if (m_InitialSelection != null)
					m_InitialSelection.RestoreSelection();

				m_InitialSelection = null;
				m_EndOfPreedit = null;
				return retVal;
			}
			finally
			{
				m_InReset = false;
				OnPreeditClosed();
			}
		}
Пример #52
0
 /// <summary>
 /// Creates an instance of <see cref="GameRepository"/>
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="mapper"></param>
 public GameRepository(IActionHandler handler, DihlDbContext dbContext, IDomainDataMapper <Game, GameDataModel> mapper)
     : base(handler, dbContext, mapper)
 {
 }
Пример #53
0
		/// <summary>Member SetActionHandler</summary>
		/// <param name='actionhandler'>action handler</param>
		public void SetActionHandler(IActionHandler actionhandler)
		{
			CheckDisposed();

			m_actionhandler = actionhandler;
		}
		private SelectionHelper SetupForTypingEventHandler(bool checkIfFocused,
			bool rollBackPreviousTask)
		{
			if (AssociatedSimpleRootSite.ReadOnlyView ||
				AssociatedSimpleRootSite.RootBox == null ||
				AssociatedSimpleRootSite.RootBox.Selection == null ||
				(checkIfFocused && (!AssociatedSimpleRootSite.Focused ||
					(AssociatedSimpleRootSite.TopLevelControl != null && !AssociatedSimpleRootSite.TopLevelControl.Enabled))))
			{
				return null;
			}
			var selHelper = new SelectionHelper(AssociatedSimpleRootSite.EditingHelper.CurrentSelection);
			if (m_ActionHandler == null)
			{
				m_ActionHandler = AssociatedSimpleRootSite.DataAccess.GetActionHandler();
			}
			else if (rollBackPreviousTask)
			{
				if (m_ActionHandler.get_TasksSinceMark(true))
				{
					m_ActionHandler.Rollback(m_Depth);
					selHelper = new SelectionHelper(m_InitialSelection.SelectionHelper);
				}
				else if (m_InitialSelection.SelectionHelper.IsRange)
					return selHelper;
				else
					return new SelectionHelper(m_InitialSelection.SelectionHelper);
			}
			else
				return selHelper;

			if (m_ActionHandler != null)
			{
				m_Depth = m_ActionHandler.CurrentDepth;
				m_ActionHandler.BeginUndoTask(Resources.ksUndoTyping, Resources.ksRedoTyping);
			}
			return selHelper;
		}
Пример #55
0
		/// <summary>
		/// Member SetActionHandler
		/// </summary>
		/// <param name="actionhandler">action handler</param>
		public void SetActionHandler(IActionHandler actionhandler)
		{
			m_cache.SetActionHandler(actionhandler);
		}
		private void OnCommitText(string text, bool checkIfFocused)
		{
			var selHelper = SetupForTypingEventHandler(checkIfFocused, true);
			if (selHelper == null)
				return;
			try
			{
				var selectionProps = GetSelectionProps(selHelper);

				var countBackspace = TrimBeginningBackspaces(ref text);
				var bottom = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
				selHelper.IchAnchor = Math.Max(0,
					selHelper.GetIch(SelectionHelper.SelLimitType.Top) - countBackspace);
				selHelper.IchEnd = bottom;
				selHelper.SetSelection(true);

				UpdateSelectionForReplacingPreeditText(selHelper, countBackspace);

				// Insert 'text'
				ITsString str = CreateTsStringUsingSelectionProps(text, selectionProps, false);
				selHelper.Selection.ReplaceWithTsString(str);
			}
			finally
			{
				m_InitialSelection = null;
				m_EndOfPreedit = null;
				if (m_ActionHandler != null)
				{
					m_ActionHandler.EndUndoTask();
					m_ActionHandler = null;
				}
				OnPreeditClosed();
			}
		}
Пример #57
0
		private IWfiMorphBundle CreateAtomicRefToSense(IActionHandler stack, ILexSense ls, bool createReferringObjInSameUow)
		{
			IWfiMorphBundle mb = null;
			UndoableUnitOfWorkHelper.Do("Undo create referring item on new stack", "Redo",
				stack,
				() =>
					{
						var wf = Cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create();
						var wa = Cache.ServiceLocator.GetInstance<IWfiAnalysisFactory>().Create();
						wf.AnalysesOC.Add(wa);
						mb = Cache.ServiceLocator.GetInstance<IWfiMorphBundleFactory>().Create();
						wa.MorphBundlesOS.Add(mb);
						if (!createReferringObjInSameUow)
							stack.BreakUndoTask("undo setting ref", "redo setting ref");
						mb.SenseRA = ls;
					});
			return mb;
		}
		/// <summary>
		/// Called when the IBus DeleteSurroundingText is raised to delete surrounding
		/// characters.
		/// </summary>
		/// <param name="offset">The character offset from the cursor position of the text to be
		/// deleted. A negative value indicates a position before the cursor.</param>
		/// <param name="nChars">The number of characters to be deleted.</param>
		public void OnDeleteSurroundingText(int offset, int nChars)
		{
			if (AssociatedSimpleRootSite.InvokeRequired)
			{
				AssociatedSimpleRootSite.BeginInvoke(() => OnDeleteSurroundingText(offset, nChars));
				return;
			}

			var selHelper = SetupForTypingEventHandler(true, false);
			if (selHelper == null || nChars <= 0)
				return;

			try
			{
				var selectionStart = selHelper.GetIch(SelectionHelper.SelLimitType.Top);
				var startIndex = selectionStart + offset;
				if (startIndex + nChars <= 0)
					return;

				var selectionProps = GetSelectionProps(selHelper);

				startIndex = Math.Max(startIndex, 0);
				selHelper.IchAnchor = startIndex;
				selHelper.IchEnd = startIndex + nChars;
				selHelper.SetSelection(true);

				ITsString str = CreateTsStringUsingSelectionProps(string.Empty, selectionProps, true);
				selHelper.Selection.ReplaceWithTsString(str);

				if (startIndex < selectionStart)
					selectionStart = Math.Max(selectionStart - nChars, 0);

				selHelper.IchAnchor = selectionStart;
				selHelper.IchEnd = selectionStart;

				// make the selection visible
				var selection = selHelper.SetSelection(true);
				selection.SetSelectionProps(selectionProps.Length, selectionProps);
			}
			finally
			{
				if (m_ActionHandler != null)
				{
					m_ActionHandler.EndUndoTask();
					m_ActionHandler = null;
				}
			}
		}
		public void SetActionHandler(IActionHandler _acth)
		{
			m_actionHandler = _acth;
		}
 public OrderProcessor(IDatabase database, IActionHandler actionHandler)
 {
     _database      = database;
     _actionHandler = actionHandler;
 }