예제 #1
0
파일: Assert.cs 프로젝트: pleasenophp/mindi
 public static void That(Func <bool> act, string message, IExceptionFactory exceptionFactory)
 {
     if (!act())
     {
         throw exceptionFactory.CreateException(message);
     }
 }
예제 #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ExpressionCheckable{T}" /> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="expression">The expression.</param>
 /// <param name="value">The value.</param>
 public ExpressionCheckable(IExceptionFactory factory, Expression <Func <T, bool> > expression, T value)
 {
     _factory    = factory;
     _expression = expression;
     _func       = expression.Compile();
     _value      = value;
 }
예제 #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BaseCheckable{T}" /> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="value">The value.</param>
 protected BaseCheckable(IExceptionFactory factory, T value)
 {
     _factory = factory;
     _value   = value;
     // TODO: Capture Stack Trace in .NET Core 2.O
     // TODO: Retrieve the variable, property etc name to produce a better message.
 }
예제 #4
0
 public Exception(ExceptionData data,
                  IExceptionDataSaver dataSaver,
                  IExceptionFactory exceptionFactory)
 {
     _data             = data;
     _dataSaver        = dataSaver;
     _exceptionFactory = exceptionFactory;
 }
예제 #5
0
 public CubicWeightService(
     ILogger <CubicWeightService> logger,
     IExceptionFactory exceptionFactory,
     IFetchService fetchService,
     IOptions <CubicWeightSettings> settings)
 {
     _logger           = logger;
     _exceptionFactory = exceptionFactory;
     _fetchService     = fetchService;
     _settings         = settings.Value;
 }
 public FetchService(
     ILogger <FetchService> logger,
     IExceptionFactory exceptionFactory,
     IRestApiService restApiService,
     IOptions <JsonConsumerSettings> settings)
 {
     _logger           = logger;
     _exceptionFactory = exceptionFactory;
     _restApiService   = restApiService;
     _settings         = settings.Value;
 }
예제 #7
0
        public async Task <IActionResult> Get([FromRoute] Guid?domainId, [FromRoute] long?id)
        {
            IActionResult result = null;

            try
            {
                if (result == null && !id.HasValue)
                {
                    result = BadRequest("Missing exception id parameter value");
                }
                if (result == null && (!domainId.HasValue || domainId.Value.Equals(Guid.Empty)))
                {
                    result = BadRequest("Missing domain id prameter value");
                }
                if (result == null)
                {
                    using ILifetimeScope scope = _container.BeginLifetimeScope();
                    SettingsFactory   settingsFactory  = scope.Resolve <SettingsFactory>();
                    CoreSettings      settings         = settingsFactory.CreateCore(_settings.Value);
                    IExceptionFactory exceptionFactory = scope.Resolve <IExceptionFactory>();
                    IException        exception        = await exceptionFactory.Get(settings, id.Value);

                    if (exception != null && !exception.DomainId.Equals(domainId.Value))
                    {
                        exception = null;
                    }
                    if (result == null && !(await VerifyDomainAccount(domainId.Value, settingsFactory, _settings.Value, scope.Resolve <IDomainService>())))
                    {
                        result = StatusCode(StatusCodes.Status401Unauthorized);
                    }
                    if (result == null && exception == null)
                    {
                        result = NotFound();
                    }
                    if (result == null && exception != null)
                    {
                        IMapper mapper = MapperConfigurationFactory.CreateMapper();
                        result = Ok(
                            await Map(exception, settings, mapper)
                            );
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                result = StatusCode(StatusCodes.Status500InternalServerError);
            }
            return(result);
        }
        public PlaceCommand(IRobot robot, string parameters, IExceptionFactory exceptionFactory) : base(robot)
        {
            var parameterArray = parameters.Trim().Split(' ');

            try
            {
                _position           = new RobotPosition();
                _position.X         = int.Parse(parameterArray[0]);
                _position.Y         = int.Parse(parameterArray[1]);
                _position.Direction = (CompassDirections)Enum.Parse(typeof(CompassDirections), parameterArray[2].ToUpper());
            }
            catch
            {
                exceptionFactory.GenerateSafeException($"invalid parameters [{parameters}] for the {Command.ToString()} command");
            }
        }
        public SendinBlueClient(string apiKey, IExceptionFactory exceptionFactory)
        {
            this.exceptionFactory = exceptionFactory;

            client = new RestClient(apiUrl);
            client.Authenticator = new ApiKeyAuthenticator(apiKey);

            var contractResolver = new DefaultContractResolver
            {
                NamingStrategy = new CamelCaseNamingStrategy()
            };

            serializerSettings = new JsonSerializerSettings
            {
                ContractResolver = contractResolver
            };
        }
예제 #10
0
        private IException Map(
            LogModels.Exception exception,
            Guid domainId,
            DateTime?timestamp,
            IExceptionFactory exceptionFactory,
            IMapper mapper,
            List <IException> allExceptions,
            IException parentException = null)
        {
            IException innerException = exceptionFactory.Create(domainId, timestamp, parentException);

            mapper.Map <LogModels.Exception, IException>(exception, innerException);
            allExceptions.Add(innerException);
            if (exception.InnerException != null)
            {
                Map(exception.InnerException, domainId, timestamp, exceptionFactory, mapper, allExceptions, innerException);
            }
            return(innerException);
        }
예제 #11
0
        public async Task <IActionResult> Search([FromRoute] Guid?domainId, [FromQuery] DateTime?maxTimestamp = null)
        {
            IActionResult result = null;

            try
            {
                if (result == null && (!domainId.HasValue || domainId.Value.Equals(Guid.Empty)))
                {
                    result = BadRequest("Missing domain id prameter value");
                }
                if (result == null && !maxTimestamp.HasValue)
                {
                    result = BadRequest("Missing max timestamp parameter value");
                }
                if (result == null)
                {
                    using ILifetimeScope scope = _container.BeginLifetimeScope();
                    SettingsFactory settingsFactory = scope.Resolve <SettingsFactory>();
                    if (!(await VerifyDomainAccount(domainId.Value, settingsFactory, _settings.Value, scope.Resolve <IDomainService>())))
                    {
                        result = StatusCode(StatusCodes.Status401Unauthorized);
                    }
                    else
                    {
                        CoreSettings      settings         = settingsFactory.CreateCore(_settings.Value);
                        IExceptionFactory exceptionFactory = scope.Resolve <IExceptionFactory>();
                        IMapper           mapper           = MapperConfigurationFactory.CreateMapper();
                        return(Ok(
                                   await Task.WhenAll <LogModels.Exception>(
                                       (await exceptionFactory.GetTopBeforeTimestamp(settings, domainId.Value, maxTimestamp.Value))
                                       .Select <IException, Task <LogModels.Exception> >(async innerException => await Map(innerException, settings, mapper))
                                       )));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                result = StatusCode(StatusCodes.Status500InternalServerError);
            }
            return(result);
        }
예제 #12
0
        public async Task <IActionResult> Create([FromBody] LogModels.Exception exception)
        {
            IActionResult result = null;

            try
            {
                if (result == null && (!exception.DomainId.HasValue || exception.DomainId.Value.Equals(Guid.Empty)))
                {
                    result = BadRequest("Missing domain guid value");
                }
                if (result == null)
                {
                    using ILifetimeScope scope = _container.BeginLifetimeScope();
                    SettingsFactory settingsFactory = scope.Resolve <SettingsFactory>();
                    if (!(await VerifyDomainAccountWriteAccess(exception.DomainId.Value, settingsFactory, _settings.Value, scope.Resolve <IDomainService>())))
                    {
                        result = StatusCode(StatusCodes.Status401Unauthorized);
                    }
                    if (result == null)
                    {
                        CoreSettings      settings       = settingsFactory.CreateCore(_settings.Value);
                        IExceptionFactory factory        = scope.Resolve <IExceptionFactory>();
                        IMapper           mapper         = MapperConfigurationFactory.CreateMapper();
                        List <IException> allExceptions  = new List <IException>();
                        IException        innerException = Map(exception, exception.DomainId.Value, exception.CreateTimestamp, factory, mapper, allExceptions);
                        IExceptionSaver   saver          = scope.Resolve <IExceptionSaver>();
                        await saver.Create(settings, allExceptions.ToArray());

                        result = Ok(
                            await Map(innerException, settings, mapper)
                            );
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                result = StatusCode(StatusCodes.Status500InternalServerError);
            }
            return(result);
        }
예제 #13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BoolCheckable" /> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="value">if set to <c>true</c> [value].</param>
 public BoolCheckable(IExceptionFactory factory, bool value)
 {
     _factory = factory;
     _value   = value;
 }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Robots.Models.ToyRobot"/> class.
 /// </summary>
 public ToyRobot(Surface surface, IExceptionFactory exceptionFactory) : base(exceptionFactory)
 {
     _exceptionFactory = exceptionFactory;
     _surface          = surface;
 }
 public void AddFactory(IExceptionFactory factory)
 {
     this.factories.Add(factory);
 }
예제 #16
0
 internal ExceptionSimulatingBin(IBin bin, IExceptionFactory exceptionFactory, ExceptionSimulatingStorage.ExceptionTriggerCondition
                                 triggerCondition) : base(bin)
 {
     _exceptionFactory = exceptionFactory;
     _triggerCondition = triggerCondition;
 }
 public ExceptionSimulatingIdSystem(LocalObjectContainer container, IExceptionFactory
                                    exceptionFactory) : base(container)
 {
     _exceptionFactory = exceptionFactory;
 }
예제 #18
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="StringCheckable" /> class.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="value"></param>
 public StringCheckable(IExceptionFactory factory, string value) :
     base(factory, value)
 {
 }
				public _IIdSystemFactory_61(ExceptionDuringTopLevelCallTestUnit _enclosing, IExceptionFactory
					 exceptionFactory)
				{
					this._enclosing = _enclosing;
					this.exceptionFactory = exceptionFactory;
				}
예제 #20
0
 public Invoker(IExceptionFactory exceptionFactory)
 {
     _exceptionFactory = exceptionFactory;
 }
예제 #21
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ObjectCheckable{T}" /> class.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="value"></param>
 public ObjectCheckable(IExceptionFactory factory, T value) : base(factory, value)
 {
 }
예제 #22
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EquatableCheckable{T}" /> class.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="value"></param>
 public EquatableCheckable(IExceptionFactory factory, IEquatable <T> value) : base(factory, value)
 {
 }
 public _IIdSystemFactory_61(ExceptionDuringTopLevelCallTestUnit _enclosing, IExceptionFactory
                             exceptionFactory)
 {
     this._enclosing       = _enclosing;
     this.exceptionFactory = exceptionFactory;
 }
예제 #24
0
 /// <summary>
 ///     Initializes the <see cref="Check" /> class.
 /// </summary>
 static Check()
 {
     _factory = new ExceptionFactory();
 }
		public ExceptionSimulatingStorage(IStorage storage, IExceptionFactory exceptionFactory
			) : base(storage)
		{
			_exceptionFactory = exceptionFactory;
		}
예제 #26
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
 protected BaseClassCheckable(IExceptionFactory factory, T value) : base(factory, value)
 {
 }
예제 #27
0
 public RobotBase(IExceptionFactory exceptionFactory)
 {
     _exceptionFactory = exceptionFactory;
 }
예제 #28
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="PropertiesCheckable{T}" /> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="value">The value.</param>
 /// <param name="options">The options.</param>
 public PropertiesCheckable(IExceptionFactory factory, T value, PropertiesComparisonOptions options)
 {
     _factory = factory;
     _value   = value;
     _options = options;
 }
예제 #29
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="DateTimeCheckable" /> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="value">The value.</param>
 public DateTimeCheckable(IExceptionFactory factory, DateTime value) :
     base(factory, value)
 {
 }
 public void AddFactory(IExceptionFactory factory)
 {
     this.factories.Add(factory);
 }
예제 #31
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TypeCheckable" /> class.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="value"></param>
 public TypeCheckable(IExceptionFactory factory, Type value) : base(factory, value)
 {
 }
예제 #32
0
 public ExceptionSimulatingIdSystem(LocalObjectContainer container, IExceptionFactory
     exceptionFactory) : base(container)
 {
     _exceptionFactory = exceptionFactory;
 }
예제 #33
0
 public ExceptionSimulatingStorage(IStorage storage, IExceptionFactory exceptionFactory
                                   ) : base(storage)
 {
     _exceptionFactory = exceptionFactory;
 }
			internal ExceptionSimulatingBin(IBin bin, IExceptionFactory exceptionFactory, ExceptionSimulatingStorage.ExceptionTriggerCondition
				 triggerCondition) : base(bin)
			{
				_exceptionFactory = exceptionFactory;
				_triggerCondition = triggerCondition;
			}
예제 #35
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="IntegerCheckable" /> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="value">The value.</param>
 public IntegerCheckable(IExceptionFactory factory, int value) : base(factory, value)
 {
 }