/// <summary> /// Конструктор представителя /// </summary> /// <param name="view">Представление</param> /// <param name="model">Модель</param> public Presenter(IView view, IModel model) { _currentHandler = null; _undoRedoStack = new UndoRedoStack(); _view = view; _model = model; _model.NewProject(); _saveState = SaveState.NewFile; _view.SaveType = _saveState; _view.ToolPicked += _view_ToolPicked; _view.ParametersChanged += _view_ParametersChanged; _view.CanvasCleared += _view_CanvasCleared; _view.FiguresDeleted += _view_FiguresDeleted; _view.FigureCopied += _view_FigureCopied; _view.UndoPressed += _view_UndoPressed; _view.RedoPressed += _view_RedoPressed; _view.CommandStack = _undoRedoStack; _view.FileLoaded += _view_FileLoaded; _view.NewProjectCreated += _view_NewProjectCreated; _model.RegisterObserver(this); }
private void HandleExceptionFlow(TransactionLogEntry methodLogEntry, InvocationContext invocationContext, IBaseHandler targetObject, Exception ex) { AppException exToThrow = null; if (ex is AppException) { var appEx = (AppException)ex; appEx.LogEntry = methodLogEntry; exToThrow = appEx; } else { exToThrow = new AppException(ex, methodLogEntry, this.loggingAttribute.ErrorMessage); } // LOG Log.Error(exToThrow); if (this.loggingAttribute.IsFlowBreakReuired) { invocationContext.MethodException = exToThrow; } else { invocationContext.MethodException = null; } }
protected ConversionProcessor(ProcessorSettings settings) { Settings = settings; InternalHandler = settings.InternalHandler; ExternalHandler = settings.ExternalHandler; Initialize(); }
public void Register <TRequest>(IBaseHandler requestHandler) where TRequest : IRequest { var requestTye = typeof(TRequest); if (requestHandler == null) { throw new ArgumentNullException($"{nameof(requestHandler)} is null"); } if (typeof(TRequest) != requestHandler.GetRequestType()) { throw new ArgumentException($"Handler does't implment response"); } if (Handlers.ContainsKey(requestTye)) { this.Handlers[requestTye].Add(requestHandler); } else { this.Handlers[requestTye] = new List <IBaseHandler>() { requestHandler }; } }
/// <summary> /// Подписка обработчика события создания фигуры /// </summary> /// <param name="currentHandler"></param> private void SetFigureCreatedHandler(IBaseHandler currentHandler) { var handler = currentHandler as FigureCreatingHandler; if (handler != null) { handler.FigureCreated += _currentHandler_FigureCreated; } }
private static void LoadHandlerClass() { if (_parameters == null) { throw new NullReferenceException($"{nameof(_parameters)} is not fullified. Cannot instance any class without parameters"); } Parallel.ForEach(Utils.GetTypesWithHelpAttribute <Type>(Assembly.GetExecutingAssembly(), typeof(Handler)), (loaded) => { object[] matchParameters = _parameters.Where((pa) => loaded.GetConstructors()[0].GetParameters().Any((conspa) => conspa.ParameterType.IsAssignableFrom(pa.GetType()))).ToArray(); IBaseHandler handler = (IBaseHandler)loaded.GetConstructors()[0].Invoke(matchParameters); _instance.Add(handler.HandlerName, handler.MessageType, (T)handler); }); }
public static IBaseHandler[] SplitHandlers(XmlNode xmlNode) { List <IBaseHandler> handlers = new List <IBaseHandler>(); foreach (XmlNode node in xmlNode.SelectNodes("./Handler")) { IBaseHandler temp = null; string name = node.Attributes["Name"].Value; temp = ShortcutManager.CreateHandler(name) as IBaseHandler; temp.Read(node); handlers.Add(temp); } return(handlers.ToArray()); }
private void HandlePostMethodExecution(InvocationContext invocationContext, object result, Exception ex) { _stopWatch.Stop(); IBaseHandler targetObject = invocationContext.Invocation.InvocationTarget as IBaseHandler; TransactionLogEntry methodlogEntry = new TransactionLogEntry(); if (targetObject != null) { methodlogEntry = targetObject.LogEntry; } HandleTransactionFlow(methodlogEntry, invocationContext, targetObject, result, ex); if (ex != null && !this.loggingAttribute.IsExceptionHandlingNotRequired) { HandleExceptionFlow(methodlogEntry, invocationContext, targetObject, ex); } }
/// <summary> /// Обработчик события выбора инструмента /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _view_ToolPicked(object sender, ToolType e) { switch (e) { case ToolType.Line: _currentHandler = new LineHandler(_view.Canvas, _view.FigureParameters); SetFigureCreatedHandler(_currentHandler); _view.CurrentHandler = _currentHandler; break; case ToolType.Polyline: _currentHandler = new PolylineHandler(_view.Canvas, _view.FigureParameters); SetFigureCreatedHandler(_currentHandler); _view.CurrentHandler = _currentHandler; break; case ToolType.Circle: _currentHandler = new CircleHandler(_view.Canvas, _view.FigureParameters); SetFigureCreatedHandler(_currentHandler); _view.CurrentHandler = _currentHandler; break; case ToolType.Ellipse: _currentHandler = new EllipseHandler(_view.Canvas, _view.FigureParameters); SetFigureCreatedHandler(_currentHandler); _view.CurrentHandler = _currentHandler; break; case ToolType.Polygon: _currentHandler = new PolygonHandler(_view.Canvas, _view.FigureParameters); SetFigureCreatedHandler(_currentHandler); _view.CurrentHandler = _currentHandler; break; case ToolType.Cursor: var cursorHandler = new CursorHandler(_view.Canvas, this); cursorHandler.FiguresMoved += CursorHandler_FiguresMoved; cursorHandler.PointMoved += CursorHandler_PointMoved; _currentHandler = cursorHandler; _view.CurrentHandler = _currentHandler; break; default: throw new ArgumentOutOfRangeException(nameof(e), e, null); } }
public void BeforeInvoke(InvocationContext invocationContext) { // Initialize fresh Log object for each Layer copying from Global log object _logEntry = invocationContext.ServiceProvider.GetRequiredService <TransactionLogEntry>(); IBaseHandler targetObject = invocationContext.Invocation.InvocationTarget as IBaseHandler; if (targetObject != null) { var targetLogEntry = CommonLogUtility.populateTransaction(_logEntry); targetObject.LockObject = new object(); targetObject.LogEntry = targetLogEntry; } _stopWatch.Reset(); _stopWatch.Start(); // Get the logging attribute this.loggingAttribute = invocationContext.GetAttributeFromMethod <LogMethodAttribute>(); // To DO: Customized with your code before finction call here.. }
private void HandleTransactionFlow(TransactionLogEntry methodLogEntry, InvocationContext invocationContext, IBaseHandler targetObject, object result, Exception ex) { methodLogEntry.Duration = _stopWatch.ElapsedMilliseconds; methodLogEntry.LoggingMethodName = invocationContext.GetExecutingMethodFullName(); methodLogEntry.ErrorMessage = ex == null ? (string.IsNullOrWhiteSpace(methodLogEntry.ErrorMessage) ? "None" : methodLogEntry.ErrorMessage) : !string.IsNullOrWhiteSpace(this.loggingAttribute.ErrorMessage) ? this.loggingAttribute.ErrorMessage : ex.Message; methodLogEntry.TransactionStatus = ex == null ? TransactionStatus.Success : TransactionStatus.Fail; if (this.loggingAttribute.InputLoggingReuired && invocationContext.Invocation.Arguments != null) { var serialier = JsonConvert.SerializeObject(invocationContext.Invocation.Arguments); serialier = serialier.Replace("\"", "'"); serialier = serialier.Replace(",", ";"); methodLogEntry.ExtendedProperties["inputData"] = "\"" + serialier + "\""; if (result != null) { serialier = JsonConvert.SerializeObject(result); serialier = serialier.Replace("\"", "'"); serialier = serialier.Replace(",", ";"); methodLogEntry.ExtendedProperties["outputData"] = "\"" + serialier + "\""; } } if (!this.loggingAttribute.IsFlowBreakReuired) { if (methodLogEntry.ExtendedProperties == null) { methodLogEntry.ExtendedProperties = new Dictionary <string, object>(); } methodLogEntry.ExtendedProperties["isPartialError"] = "True"; } // Log Log.Info(methodLogEntry); }
private static void ProcessHandler(IRequest request, Dictionary <string, object> Context, IBaseHandler handler, List <IResponse> responses) { try { responses.Add(handler.RequestHandle(request, Context).GetAwaiter().GetResult()); } catch (Exception ex) { responses.Add(new DefaultResponseError(ex.Message)); } }
public TicketController(ITicketHandler ticketHandler, IBaseHandler<ProductDomain> productHandler, ICurrentUser currentUser) { _ticketHandler = ticketHandler; _productHandler = productHandler; _currentUser = currentUser; }
public BaseService(IBaseHandler <TBaseModel> service, IUnitOfWork uow) { _service = service; _uow = uow; }
public TicketController(ITicketHandler ticketHandler, IBaseHandler <ProductDomain> productHandler, ICurrentUser currentUser) { _ticketHandler = ticketHandler; _productHandler = productHandler; _currentUser = currentUser; }
public ProductController(IBaseHandler <ProductDomain> productHandler, IBaseHandler <CustomerDomain> customerHandler, ITicketHandler ticketHandler) { _productHandler = productHandler; _customerHandler = customerHandler; _ticketHandler = ticketHandler; }
public CustomerController(IBaseHandler <CustomerDomain> customerHandler) { _customerHandler = customerHandler; }
public ProductController(IBaseHandler<ProductDomain> productHandler, IBaseHandler<CustomerDomain> customerHandler, ITicketHandler ticketHandler) { _productHandler = productHandler; _customerHandler = customerHandler; _ticketHandler = ticketHandler; }
public CustomerController(IBaseHandler<CustomerDomain> customerHandler) { _customerHandler = customerHandler; }