コード例 #1
0
 public DbTransactionCommandHandlerDecorator(DecoratorContext decoratorContext, ITransactionFactory <TDbContext> transactionFactory, ICommandHandler <TCommand, TResult> decoratee)
 {
     _decoratee          = decoratee;
     _transactionFactory = transactionFactory;
     _transactionType    = decoratorContext.ImplementationType
                           .GetCustomAttribute <TransactionAttribute>(true)?.TransactionType;
 }
コード例 #2
0
ファイル: CommandDraw.cs プロジェクト: dannypas00/DrawingApp
        public CommandDraw(int x1, int y1, Shape shape, DecoratorContext context = null)
        {
            //Set starting location for drawing the shape
            this.x1      = x1;
            this.y1      = y1;
            this.invoker = CommandInvoker.GetInstance();
            this.shape   = shape;
            this.context = context;
            //Get the group that is selected in the group sidebar
            Group selected = invoker.MainWindow.groups.SelectedItem != null ? (Group)invoker.GroupMap[(ListBoxItem)invoker.MainWindow.groups.SelectedItem] : (Group)invoker.MainWindow.groups.Items[0];

            //Make a new CanvasShape for calling functions on the new shape
            canvShape = new CanvasShape(shape, selected);
            //Setup the parent-child relationship of the new shape
            Group parent = selected;

            parent.AddChild(canvShape);
            //Map the CanvasShape that owns the Shape to it for easy correlation
            invoker.Map.Add(shape, canvShape);
            //New event handler for selecting the shape
            shape.MouseDown += Select;
            //Setup visuals
            shape.Stroke          = shape.Fill = CommandInvoker.RandomColor();
            shape.StrokeThickness = 3;
            if (context != null)
            {
                context.shape = canvShape;
                capDecorator  = new CaptionDecorator(context);
            }
            canvShape.decorator = capDecorator;
            invoker.MainWindow.canvas.Children.Add(shape);
            invoker.MainWindow.AddOrnament.Background = Brushes.DimGray;
        }
コード例 #3
0
        /// <summary>
        /// Decoration request
        /// </summary>
        /// <param name="context">Context info</param>
        /// <remarks>do not have to decorate, but may if it wants to. sorta..</remarks>
        public void Decorate(DecoratorContext context)
        {
            if (!CanDecorate(context))
                return;

            var options = new ProxyGenerationOptions();

            var services = context.Services;
            if (IgnoreClassAsService && services.Length > 1)
                services = services.Where(x => !x.IsClass).ToArray();

            var generator = new ProxyGenerator();
            if (services.Any(x => x.IsClass))
            {
                if (services.Length > 1)
                    throw new InvalidOperationException(
                        "A class that register itself as a service may not also be registered with interfaces. See the remarks in the IgnoreClassAsService property.");

                var clazz = context.Services.Single(x => x.IsClass);
                context.Instance = generator.CreateClassProxyWithTarget(clazz, context.Instance,
                                                                        CreateInterceptor(context));
            }
            else
            {
                var others = services.Where(x => x.IsInterface).Skip(1);
                var first = services.First();
                context.Instance = generator.CreateInterfaceProxyWithTarget
                    (first, others.ToArray(), context.Instance,
                     CreateInterceptor(context));
            }

        }
コード例 #4
0
        public void ConditionDefaultsToTrueWhenNotProvided()
        {
            var service = new DecoratorService(typeof(string));

            var context = DecoratorContext.Create(typeof(string), typeof(string), "A");

            Assert.True(service.Condition(context));
        }
コード例 #5
0
 public void Decorate(DecoratorContext context, HttpRequest request)
 {
     Update(context, request);
     foreach (var decorator in decorators)
     {
         decorator.Decorate(context, request);
     }
 }
コード例 #6
0
        //This region handles all the drawing commands called on the invoker

        /// <summary>
        /// Start the drawing process,
        /// it is run once when the mouse button is pressed,
        /// and has to be finished with the Draw function.
        /// </summary>
        /// <param name="x1">The x axis of the drawing's first point</param>
        /// <param name="y1">The y axis of the drawing's first point</param>
        /// <param name="shape">The Shape object to draw with</param>
        public void StartDraw(double x1, double y1, Shape shape)
        {
            //Rounding positions to int to comply with mandatory saving grammar
            ICommand cmd = new CommandDraw((int)Math.Round(x1), (int)Math.Round(y1), shape, decoratorContext);

            decoratorContext = null;
            actionsDone.Push(cmd);
        }
コード例 #7
0
        public override void Update(DecoratorContext context, HttpRequest request)
        {
            string pullRequestId  = request.Query["pullRequestId"];
            string commitId       = request.Query["commitId"];
            string pullRequestUrl = request.Query["pullRequestUrl"];

            context.PullRequestId = pullRequestId;
            context.CommitId      = commitId;
            context.Url           = new Uri(pullRequestUrl);
        }
コード例 #8
0
        public void CreateSetsContextToPreDecoratedState()
        {
            const string implementationInstance = "Initial";

            var context = DecoratorContext.Create(typeof(string), typeof(string), implementationInstance);

            Assert.Equal(typeof(string), context.ServiceType);
            Assert.Equal(typeof(string), context.ImplementationType);
            Assert.Equal(implementationInstance, context.CurrentInstance);
            Assert.Empty(context.AppliedDecoratorTypes);
            Assert.Empty(context.AppliedDecorators);
        }
コード例 #9
0
        private byte[] Decorate <T>(byte[] workbookBytes, ExportOption <T> exportOption)
            where T : class, new()
        {
            DecoratorContext context = new DecoratorContext()
            {
                TypeDecoratorInfo = TypeDecoratorInfoFactory.CreateInstance(typeof(T))
            };

            GetDecorators <T>().ForEach(d =>
            {
                workbookBytes = d.Decorate(workbookBytes, exportOption, context, _excelExportProvider);
            });

            return(workbookBytes);
        }
コード例 #10
0
        public async Task <IActionResult> CIHook(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            [OrchestrationClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            var context = new DecoratorContext();

            new DecoratorRegistry().GetDecorator().Decorate(context, req);

            var instanceId = await starter.StartNewAsync(nameof(DecorationOrchestrator), context);

            DurableOrchestrationStatus status = await starter.GetStatusAsync(instanceId, false, false);

            return((ActionResult) new OkObjectResult(status));
        }
コード例 #11
0
        public void RegisterScannerDecoratorNormalCase()
        {
            BotConfiguration.ScannerProviders = new List <string>()
            {
                "Bar", "Buz"
            };
            var registry  = new DecoratorRegistry();
            var decorator = registry.GetScannerDecorator();
            var context   = new DecoratorContext();
            var request   = new Mock <HttpRequest>().Object;

            decorator.Decorate(context, request);
            Assert.Equal("BarValue", context.Tag.GetValueOrDefault("Bar"));
            Assert.Equal("BuzValue", context.Tag.GetValueOrDefault("Buz"));
            Assert.Null(context.PullRequestId);
        }
コード例 #12
0
        public void UpdateAddsDecoratorStateToContext()
        {
            const string implementationInstance = "Initial";
            var          context = DecoratorContext.Create(typeof(string), typeof(string), implementationInstance);

            const string decoratorA = "DecoratorA";

            context = context.UpdateContext(decoratorA);

            Assert.Equal(decoratorA, context.CurrentInstance);
            Assert.Equal(context.AppliedDecoratorTypes, new[] { typeof(string) });
            Assert.Equal(context.AppliedDecorators, new[] { decoratorA });

            const string decoratorB = "DecoratorB";

            context = context.UpdateContext(decoratorB);

            Assert.Equal(decoratorB, context.CurrentInstance);
            Assert.Equal(context.AppliedDecoratorTypes, new[] { typeof(string), typeof(string) });
            Assert.Equal(context.AppliedDecorators, new[] { decoratorA, decoratorB });
        }
コード例 #13
0
        /// <summary>
        /// Decoration request
        /// </summary>
        /// <param name="context">Context info</param>
        /// <remarks>do not have to decorate, but may if it wants to. sorta..</remarks>
        public void Decorate(DecoratorContext context)
        {
            if (!CanDecorate(context))
            {
                return;
            }

            var options = new ProxyGenerationOptions();

            var services = context.Services;

            if (IgnoreClassAsService && services.Length > 1)
            {
                services = services.Where(x => !x.IsClass).ToArray();
            }

            var generator = new ProxyGenerator();

            if (services.Any(x => x.IsClass))
            {
                if (services.Length > 1)
                {
                    throw new InvalidOperationException(
                              "A class that register itself as a service may not also be registered with interfaces. See the remarks in the IgnoreClassAsService property.");
                }

                var clazz = context.Services.Single(x => x.IsClass);
                context.Instance = generator.CreateClassProxyWithTarget(clazz, context.Instance,
                                                                        CreateInterceptor(context));
            }
            else
            {
                var others = services.Where(x => x.IsInterface).Skip(1);
                var first  = services.First();
                context.Instance = generator.CreateInterfaceProxyWithTarget
                                       (first, others.ToArray(), context.Instance,
                                       CreateInterceptor(context));
            }
        }
コード例 #14
0
 public ContextualHandlerDecorator(ICommandHandler <T> decorated, DecoratorContext context)
 {
     this.Decorated = decorated;
     this.Context   = context;
 }
コード例 #15
0
 public abstract void Update(DecoratorContext context, HttpRequest request);
コード例 #16
0
 public byte[] WrapText <T>(byte[] workbookBytes, ExportOption <T> exportOption, DecoratorContext context) where T : class, new()
 {
     throw new NotImplementedException();
 }
コード例 #17
0
 /// <summary>
 /// Determins if an instance should be decorated or not.
 /// </summary>
 /// <param name="context">Context</param>
 /// <returns>
 ///   <c>true</c> if we should attach a decorator; otherwise <c>false</c>.
 /// </returns>
 public bool CanDecorate(DecoratorContext context)
 {
     return _filter(context);
 }
コード例 #18
0
 /// <summary>
 /// Determins if an instance should be decorated or not.
 /// </summary>
 /// <param name="context">Context</param>
 /// <returns>
 ///   <c>true</c> if we should attach a decorator; otherwise <c>false</c>.
 /// </returns>
 public bool CanDecorate(DecoratorContext context)
 {
     return(_filter(context));
 }
コード例 #19
0
 public TransactionEventHandlerDecorator(IEventHandler <TEvent> decorated, ITransactionAccessor transactionAccessor, DecoratorContext decoratorContext) : base(decorated)
 {
     _transactionType     = decoratorContext.ImplementationType.GetCustomAttribute <TransactionAttribute>()?.TransactionType;
     _transactionAccessor = transactionAccessor;
 }
コード例 #20
0
 /// <summary>
 /// Create a new interceptor
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>Created interceptor (which will be used to handle the instance)</returns>
 protected abstract IInterceptor CreateInterceptor(DecoratorContext context);
コード例 #21
0
 public SomethingLoggerDecorator(ISomething decoratee, DecoratorContext context)
 {
     this.decoratee = decoratee;
     this.context   = context;
 }
コード例 #22
0
        public override void Update(DecoratorContext context, HttpRequest request)
        {
            string projectKey = request.Query[SonarCloudConfiguration.ProjectKey];

            context.AddTag(SonarCloudConfiguration.ProjectKey, projectKey);
        }
コード例 #23
0
 public void Ornament()
 {
     this.decoratorContext = new DecoratorContext();
 }
コード例 #24
0
        public byte[] WrapText <T>(byte[] workbookBytes, ExportOption <T> exportOption, DecoratorContext context)
            where T : class, new()
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var attr = context.TypeDecoratorInfo.GetDecorateAttr <WrapTextAttribute>();

            if (attr == null)
            {
                return(workbookBytes);
            }

            IWorkbook workbook = workbookBytes.ToWorkbook();

            ISheet sheet = workbook.GetSheet(exportOption.SheetName);
            IRow   row;

            if (sheet.PhysicalNumberOfRows > 0)
            {
                for (int i = 0; i < sheet.PhysicalNumberOfRows; i++)
                {
                    row = sheet.GetRow(i);
                    for (int colIndex = 0; colIndex < row.PhysicalNumberOfCells; colIndex++)
                    {
                        row.GetCell(colIndex).CellStyle.WrapText = true;
                    }
                }
            }

            return(workbook.ToBytes());
        }
コード例 #25
0
 public TransactionHandlerDecorator(DecoratorContext decoratorContext, IHandler <TIn, Task <Result <TOut> > > decorated, ITransactionAccessor transactionAccessor) : base(decorated)
 {
     _transactionAccessor = transactionAccessor;
     _transactionType     = decoratorContext.ImplementationType
                            .GetCustomAttribute <TransactionAttribute>()?.TransactionType;
 }
コード例 #26
0
 public override void Update(DecoratorContext context, HttpRequest request)
 {
     context.PullRequestId = "3";
 }
コード例 #27
0
 /// <summary>
 /// Determins if an instance should be decorated or not.
 /// </summary>
 /// <param name="context">Context</param>
 /// <returns><c>true</c> if we should attach a decorator; otherwise <c>false</c>.</returns>
 protected virtual bool CanDecorate(DecoratorContext context)
 {
     return _filter == null || _filter.CanDecorate(context);
 }
コード例 #28
0
 public ContextualMessageHandlerDecorator(DecoratorContext context,
                                          IMessageHandler <T> decoratee)
 {
     this.context   = context;
     this.decoratee = decoratee;
 }
コード例 #29
0
	public DecoratorContext decorator() {
		DecoratorContext _localctx = new DecoratorContext(Context, State);
		EnterRule(_localctx, 6, RULE_decorator);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 193; Match(AT);
			State = 194; dotted_name();
			State = 200;
			_la = TokenStream.La(1);
			if (_la==OPEN_PAREN) {
				{
				State = 195; Match(OPEN_PAREN);
				State = 197;
				_la = TokenStream.La(1);
				if (((((_la - 20)) & ~0x3f) == 0 && ((1L << (_la - 20)) & ((1L << (LAMBDA - 20)) | (1L << (NOT - 20)) | (1L << (NONE - 20)) | (1L << (TRUE - 20)) | (1L << (FALSE - 20)) | (1L << (NAME - 20)) | (1L << (STRING_LITERAL - 20)) | (1L << (BYTES_LITERAL - 20)) | (1L << (DECIMAL_INTEGER - 20)) | (1L << (OCT_INTEGER - 20)) | (1L << (HEX_INTEGER - 20)) | (1L << (BIN_INTEGER - 20)) | (1L << (FLOAT_NUMBER - 20)) | (1L << (IMAG_NUMBER - 20)) | (1L << (ELLIPSIS - 20)) | (1L << (STAR - 20)) | (1L << (OPEN_PAREN - 20)) | (1L << (POWER - 20)) | (1L << (OPEN_BRACK - 20)) | (1L << (ADD - 20)) | (1L << (MINUS - 20)) | (1L << (NOT_OP - 20)) | (1L << (OPEN_BRACE - 20)))) != 0)) {
					{
					State = 196; arglist();
					}
				}

				State = 199; Match(CLOSE_PAREN);
				}
			}

			State = 202; Match(NEWLINE);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}
コード例 #30
0
 /// <summary>
 /// Create a new interceptor
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>
 /// Created interceptor (which will be used to handle the instance)
 /// </returns>
 protected override IInterceptor CreateInterceptor(DecoratorContext context)
 {
     return new ExceptionInterceptor(_logger);
 }
コード例 #31
0
 protected override IInterceptor CreateInterceptor(DecoratorContext context) => new GriffinInterceptionLogger();
コード例 #32
0
 public override void Update(DecoratorContext context, HttpRequest request)
 {
     context.AddTag("Buz", "BuzValue");
 }
コード例 #33
0
        public byte[] MergeCols <T>(byte[] workbookBytes, ExportOption <T> exportOption, DecoratorContext context)
            where T : class, new()
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var    propertyDecoratorInfos = context.TypeDecoratorInfo.PropertyDecoratorInfos;
            var    workbook = workbookBytes.ToWorkbook();
            ISheet sheet    = workbook.GetSheet(exportOption.SheetName);

            foreach (var item in propertyDecoratorInfos)
            {
                if (item.DecoratorAttrs.SingleOrDefault(a => a.GetType() == typeof(MergeColsAttribute)) != null)
                {
                    MergeCols(sheet, item.ColIndex, exportOption);
                }
            }

            return(workbook.ToBytes());
        }
コード例 #34
0
 /// <summary>
 /// Create a new interceptor
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>Created interceptor (which will be used to handle the instance)</returns>
 protected abstract IInterceptor CreateInterceptor(DecoratorContext context);
コード例 #35
0
        public byte[] DecorateHeader <T>(byte[] workbookBytes, ExportOption <T> exportOption, DecoratorContext context)
            where T : class, new()
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var attr = (HeaderAttribute)context.TypeDecoratorInfo?.TypeDecoratorAttrs?.SingleOrDefault(a => a.GetType() == typeof(HeaderAttribute));

            if (attr == null)
            {
                return(workbookBytes);
            }

            IWorkbook workbook = workbookBytes.ToWorkbook();

            IRow headerRow = workbook?.GetSheet(exportOption.SheetName)?.GetRow(exportOption.HeaderRowIndex);

            if (headerRow == null)
            {
                return(workbookBytes);
            }

            ICellStyle style = workbook.CreateCellStyle();
            IFont      font  = workbook.CreateFont();

            font.FontName           = attr.FontName;
            font.Color              = (short)attr.Color.GetHashCode();
            font.FontHeightInPoints = (short)attr.FontSize;
            if (attr.IsBold)
            {
                font.Boldweight = short.MaxValue;
            }

            style.SetFont(font);

            for (int i = 0; i < headerRow.PhysicalNumberOfCells; i++)
            {
                headerRow.GetCell(i).CellStyle = style;
            }

            return(workbook.ToBytes());
        }
コード例 #36
0
 /// <summary>
 /// Determins if an instance should be decorated or not.
 /// </summary>
 /// <param name="context">Context</param>
 /// <returns><c>true</c> if we should attach a decorator; otherwise <c>false</c>.</returns>
 protected virtual bool CanDecorate(DecoratorContext context)
 {
     return(_filter == null || _filter.CanDecorate(context));
 }