Example #1
0
        private double FindPrioityIndex(OptionBase option)
        {
            DatabaseOptionStatusLine line = _optionStatus.GetDatabaseOptionStatusLineOnOption(option);

            double priority = 1;

            if (line?.Fail10Minute > 0)
            {
                priority *= 0.5;
            }
            else if (line?.Fail1Hour > 0)
            {
                priority *= 0.75;
            }
            else if (line?.Fail24Hour > 0)
            {
                priority *= 0.85;
            }

            int?failsOnCurrentOption = option?.DatabaseOption?.Schedule?.Fails;

            if (failsOnCurrentOption != null)
            {
                priority *= 0.5;
            }

            return(priority);
        }
        public static void TestAddNullOptionToCollectionThrows()
        {
            OptionSetCollection options = new OptionSetCollection();
            OptionBase          nullOb  = null;

            Assert.Throws <ArgumentNullException>(() => options.Add(nullOb));
        }
Example #3
0
		public void BeginOption(OptionBase currentOption, DatabaseWorker databaseWorker)
		{
			lock (_statusLock)
			{
				_databaseOptionStatus.ActiveOptionsAdd(currentOption.DatabaseOption, databaseWorker);
			}
		}
 public static void AddHttpClients(this IServiceCollection services, OptionBase opts)
 {
     services.AddHttpClient(API.CORE, httpClient => ConfigureClient(API.CORE, opts.OrganizationURL, opts.PAT, httpClient));
     services.AddHttpClient(API.VSAEX, httpClient => ConfigureClient(API.VSAEX, opts.OrganizationURL, opts.PAT, httpClient));
     services.AddHttpClient(API.VSSPS, httpClient => ConfigureClient(API.VSSPS, opts.OrganizationURL, opts.PAT, httpClient));
     services.AddHttpClient(API.VSRM, httpClient => ConfigureClient(API.VSRM, opts.OrganizationURL, opts.PAT, httpClient));
 }
Example #5
0
        protected override void AfterParsed(OptionBase opt, Program app)
        {
            base.AfterParsed(opt, app);
            var chatroom = app.Client.GetChatroom(ChatroomId);
            var ropt     = (RoomOptionBase)opt;

            ropt.ChatroomId = ChatroomId;
            ropt.Chatroom   = chatroom;
        }
        public static void TestOptionBaseGetPrototype()
        {
            int i = 0;
            OptionSetCollection options = new OptionSetCollection()
            {
                { "x|y", v => ++ i },
            };
            OptionBase ob = options["x"];

            Assert.That(ob.Prototype, Is.EqualTo("x|y"));
        }
        public static void TestOptionBaseToString()
        {
            int i = 0;
            OptionSetCollection options = new OptionSetCollection()
            {
                { "x|y", v => ++ i },
            };
            OptionBase ob = options["x"];

            Assert.That(ob.ToString(), Is.EqualTo("x|y"));
        }
        public static void TestOptionBaseGetDescription()
        {
            int i = 0;
            OptionSetCollection options = new OptionSetCollection()
            {
                { "x|y", "X or Y", v => ++ i },
            };
            OptionBase ob = options["x"];

            Assert.That(ob.Description, Is.EqualTo("X or Y"));
        }
        public static void TestOptionBaseGetValueSeparatorsWhenNone()
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();
            OptionSetCollection          options    = new OptionSetCollection()
            {
                { "a={}", (key, value) => dictionary.Add(key, value) },
            };
            OptionBase ob = options["a"];

            string[] separators = ob.GetValueSeparators();
            Assert.That(separators.Length, Is.EqualTo(0));
        }
        public static void TestOptionBaseGetValueSeparators()
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();
            OptionSetCollection          options    = new OptionSetCollection()
            {
                { "a=-+", (key, value) => dictionary.Add(key, value) },
            };
            OptionBase ob = options["a"];

            string[] separators = ob.GetValueSeparators();
            Assert.That(separators[0], Is.EqualTo("-"));
            Assert.That(separators[1], Is.EqualTo("+"));
        }
        public static void TestOptionBaseGetNames()
        {
            int i = 0;
            OptionSetCollection options = new OptionSetCollection()
            {
                { "x|y", v => ++ i },
            };
            OptionBase ob = options["x"];

            string[] names = ob.GetNames();
            Assert.That(names[0], Is.EqualTo("x"));
            Assert.That(names[1], Is.EqualTo("y"));
        }
Example #12
0
        public void ActiveOptionsRemove(OptionBase option)
        {
            if (option == null)
            {
                return;
            }

            if (ActiveOptions.ContainsKey(option.Id) == false)
            {
                return;
            }

            ActiveOptions.Remove(option.Id);
        }
Example #13
0
		public DatabaseOptionStatusLine GetDatabaseOptionStatusLineOnOption(OptionBase option)
		{
			lock (_statusLock)
			{
				string optionName = option.GetType().Name;

				if (_databaseOptionStatus.options.ContainsKey(optionName))
				{
					DatabaseOptionStatusLine line = _databaseOptionStatus.options[optionName];
					return line;
				}
			}

			return null;
		}
Example #14
0
        public OptionBase GetOption(DatabaseOptionBase databaseOption)
        {
            List <Type> optionTypes = ReflectionHelper.GetChildTypes(typeof(OptionBase));

            Type matchingOptionType = optionTypes.SingleOrDefault(optionType => optionType.Name == databaseOption.GetType().Name);

            if (matchingOptionType == null)
            {
                Log.Write(_mongoConnection, $"Unknown option type {matchingOptionType}", typeof(OptionHandler), Config.LogLevelEnum.OptionError);
                return(null);
            }

            OptionBase option = (OptionBase)Activator.CreateInstance(matchingOptionType, _mongoConnection, databaseOption);

            return(option);
        }
Example #15
0
        public void AssignWorkerAssignsWorkerToAll()
        {
            SumIndbetaling option1 = SumIndbetaling.Create(_mongoConnection, "test", "test", CreateSchedule());
            SumIndbetaling option2 = SumIndbetaling.Create(_mongoConnection, "test", "test", CreateSchedule());
            SumIndbetaling option3 = SumIndbetaling.Create(_mongoConnection, "test", "test", CreateSchedule());

            Worker worker = new Worker();

            worker.Create(_mongoConnection);

            OptionBase.AssignWorkerToAllUnassigned <SumIndbetaling>(worker, _mongoConnection);

            List <SumIndbetaling> optionsRead = OptionBase.ReadAllowed <SumIndbetaling>(_mongoConnection, null);

            Assert.IsTrue(optionsRead.All(option => option.Schedule.WorkerId == worker._id));
        }
Example #16
0
        public static void AddTelemetryServices(this IServiceCollection services, OptionBase opts)
        {
            services.AddSingleton(new TelemetryConfiguration
            {
                ConnectionString = opts.AppInsightConnectionString,
                TelemetryChannel = new ServerTelemetryChannel()
            });
            var configuration = new TelemetryConfiguration
            {
                ConnectionString = opts.AppInsightConnectionString,
                TelemetryChannel = new ServerTelemetryChannel()
            };

            configuration.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());

            services.AddSingleton(configuration);
            services.AddSingleton <InstrumentationClient>();
        }
        public static void TestOptionBaseConstructorExceptions()
        {
            string nullString = null;

            OptionBase option = null;

            Assert.Throws <ArgumentNullException>(() => option       = new TestOptionsForConstructorExceptions(nullString, "Description", 0));
            Assert.Throws <ArgumentException>(() => option           = new TestOptionsForConstructorExceptions("", "Description", 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => option = new TestOptionsForConstructorExceptions("prototype", "Description", -1));

            Assert.Throws <ArgumentException>(() => option = new TestOptionsForConstructorExceptions("x=", "Description", 0));
            Assert.Throws <ArgumentException>(() => option = new TestOptionsForConstructorExceptions("x:", "Description", 0));
            Assert.DoesNotThrow(() => option = new TestOptionsForConstructorExceptions("x:", "Description", 1));

            Assert.Throws <ArgumentException>(() => option = new TestOptionsForConstructorExceptions("x", "Description", 2));
            Assert.Throws <ArgumentException>(() => option = new TestOptionsForConstructorExceptions("x=|<>", "Description", 2));

            Assert.That(option, Is.Not.Null, "Should not reach here. Only here to make FxCop believe we're using the instantiated object.");
        }
        internal static (Action <TRunInfo, object> Setter, Type Type) CreateSetter(OptionBase <TRunInfo> option)
        {
            dynamic      opt          = option;
            PropertyInfo propertyInfo = ReflectionHelper <TRunInfo> .GetPropertyInfoFromExpression(opt.Property);

            Type valueType = propertyInfo.PropertyType;

            Action <TRunInfo, object> setter = (runInfo, value) =>
            {
                if (value.GetType() != valueType)
                {
                    throw new InvalidOperationException($"'{value}' is not a valid '{valueType}' type.");
                }

                propertyInfo.SetValue(runInfo, value);
            };

            return(setter, valueType);
        }
Example #19
0
        public void ReadAllowedTest()
        {
            Email emailCreatedAllowedIn2Days = CreateEmail();

            emailCreatedAllowedIn2Days.Schedule.NextAllowedExecution = emailCreatedAllowedIn2Days.Schedule.NextAllowedExecution.AddDays(2);
            emailCreatedAllowedIn2Days.Update(_connection);

            Email emailCreatedAllowed = CreateEmail();

            emailCreatedAllowed.Schedule.NextAllowedExecution = emailCreatedAllowed.Schedule.NextAllowedExecution.AddDays(-1);
            emailCreatedAllowed.Update(_connection);

            Email emailCreatedAllowedTomorrow = CreateEmail();

            emailCreatedAllowedTomorrow.Schedule.NextAllowedExecution = emailCreatedAllowedTomorrow.Schedule.NextAllowedExecution.AddDays(1);
            emailCreatedAllowedTomorrow.Update(_connection);

            List <Email> emails         = OptionBase.ReadAllowed <Email>(_connection, null);
            Email        emailRetreived = emails.Single();

            AssertEmail(emailCreatedAllowed, emailRetreived);
        }
Example #20
0
        public void ActiveOptionsAdd(OptionBase option, Worker worker)
        {
            if (option == null)
            {
                return;
            }

            if (ActiveOptions.ContainsKey(option.Id))
            {
                return;
            }

            ActiveOption activeOption = new ActiveOption()
            {
                Begin    = DateTime.Now,
                Name     = option.Name,
                TypeName = option.GetType().Name,
                WorkerId = worker._id,
            };

            ActiveOptions.Add(option.Id, activeOption);
        }
Example #21
0
        public void DelayOptionFromFails(OptionBase option)
        {
            DatabaseOptionStatusLine line = _optionStatus.GetDatabaseOptionStatusLineOnOption(option);

            int failsThisHour = 0;

            if (line != null)
            {
                failsThisHour = line.Fail1Hour;
            }

            if (failsThisHour == 0)
            {
                return;
            }

            double minutesExtraDouble = 10.0 * Math.Log(failsThisHour);

            TimeSpan minutesExtra = TimeSpan.FromMinutes(minutesExtraDouble);

            option.DatabaseOption.Schedule.NextAllowedExecution += minutesExtra;
        }
Example #22
0
		public void EndOption(OptionBase currentOption, OptionReport report)
		{
			lock (_statusLock)
			{
				_databaseOptionStatus.ActiveOptionsRemove(currentOption.DatabaseOption);

				if (report != null)
				{
					DatabaseOptionResult.Create(_mongoConnection, report.BeginTime, report.EndTime, report.OptionType.Name, report.Success, report.Memory);

					UpdateEstimatedStatistics(report);

					if (_databaseOptionStatus.optionLastMemory.ContainsKey(report.OptionType.Name))
					{
						_databaseOptionStatus.optionLastMemory[report.OptionType.Name] = report.Memory;
					}
					else
					{
						_databaseOptionStatus.optionLastMemory.Add(report.OptionType.Name, report.Memory);
					}
				}
			}
		}
        internal static (Action <TRunInfo, object> Setter, Type Type) CreateSetter(OptionBase <TRunInfo> option)
        {
            dynamic      opt          = option;
            PropertyInfo propertyInfo = ReflectionHelper <TRunInfo> .GetPropertyInfoFromExpression(opt.Property);

            Type valueType = propertyInfo.PropertyType;

            Action <TRunInfo, object> setter = (runInfo, value) =>
            {
                bool isNullableEnum = Nullable.GetUnderlyingType(valueType)?.IsEnum == true;

                if (isNullableEnum)
                {
                    if (value != null && value.GetType() != Nullable.GetUnderlyingType(valueType))
                    {
                        throw new InvalidOperationException($"'{value}' is not a valid '{valueType}' type.");
                    }
                }
                else
                {
                    if (value.GetType() != valueType)
                    {
                        throw new InvalidOperationException($"'{value}' is not a valid '{valueType}' type.");
                    }
                }

                //if (!(isNullableEnum && value == null) && value.GetType() != valueType)
                //{
                //	throw new InvalidOperationException($"'{value}' is not a valid '{valueType}' type.");
                //}

                propertyInfo.SetValue(runInfo, value);
            };

            return(setter, valueType);
        }
Example #24
0
 public override int CompareTo(OptionBase other)
 {
     if (other is Rock)
     {
         return(-1);
     }
     if (other is Paper)
     {
         return(1);
     }
     if (other is Scissors)
     {
         return(0);
     }
     if (other is Lizard)
     {
         return(1);
     }
     if (other is Spock)
     {
         return(-1);
     }
     throw new InvalidOperationException("Don't cheat...");
 }
Example #25
0
        public List <OptionBase> Find(DatabaseWorker worker)
        {
            List <OptionBase> options = new List <OptionBase>();

            List <DatabaseOptionBase> databaseOptions;

            if (worker == null)
            {
                databaseOptions = _databaseOptionFinder.Find();
            }
            else
            {
                databaseOptions = _databaseOptionFinder.Find(worker);
            }

            List <Type> optionTypes = ReflectionHelper.GetChildTypes(typeof(OptionBase));

            foreach (DatabaseOptionBase databaseOption in databaseOptions)
            {
                string optionName = databaseOption.GetType().Name;

                Type optionType = optionTypes.SingleOrDefault(type => type.Name == optionName);

                if (optionType == null)
                {
                    Log.Write(_connection, $"Unknown option type {optionType}", typeof(OptionFinder), DataLayer.MongoData.Config.LogLevelEnum.OptionError);
                    continue;
                }

                OptionBase option = (OptionBase)Activator.CreateInstance(optionType, _connection, databaseOption);

                options.Add(option);
            }

            return(options);
        }
Example #26
0
        public Dictionary <string, object> GetResponse(DatabaseOptionBase databaseOption)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            OptionBase option = null;

            try
            {
                option = GetOption(databaseOption);

                if (option == null)
                {
                    return(parameters);
                }

                return(option.ExecuteOption());
            }
            catch (Exception exception)
            {
                Log.Write(_mongoConnection, exception.Message, typeof(OptionHandler), exception.StackTrace, Config.LogLevelEnum.OptionError);
            }

            return(parameters);
        }
Example #27
0
 /// <summary>
 ///     create a new option base
 /// </summary>
 /// <param name="name">option name</param>
 /// <param name="parent">parent option</param>
 /// <param name="defaultValue">default value</param>
 protected OptionBase(string name, OptionBase <TOption>?parent, TOption defaultValue) : base(name, parent)
 {
     Parent            = parent;
     value             = defaultValue;
     this.defaultValue = defaultValue;
 }
        public static void AddServicesFromClientLib(this IServiceCollection services, OptionBase opts)
        {
            var connection = new VssConnection(new Uri(opts.OrganizationURL), new VssBasicCredential(string.Empty, opts.PAT));

            services.AddSingleton(connection);
            services.AddSingleton(connection.GetClient <TeamHttpClient>());
            services.AddSingleton(connection.GetClient <WorkItemTrackingHttpClient>());
            services.AddSingleton(connection.GetClient <GitHttpClient>());
        }
Example #29
0
 protected override void AfterParsed(OptionBase opt, Program app)
 {
     base.AfterParsed(opt, app);
     ((PeopleOptionBase)opt).PeopleId = PeopleId;
 }