public ConventionBasedCodingStyle()
        {
            types = new List <IType>();

            MaxFetchDepth = new SingleConfiguration <ConventionBasedCodingStyle, int>(this, nameof(MaxFetchDepth), true);

            Type            = new ConventionBasedConfiguration <ConventionBasedCodingStyle, object, IType>(this, nameof(Type));
            TypeIsValue     = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IType, bool>(this, nameof(TypeIsValue));
            TypeIsView      = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IType, bool>(this, nameof(TypeIsView));
            IdExtractor     = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IType, IIdExtractor>(this, nameof(IdExtractor));
            ValueExtractor  = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IType, IValueExtractor>(this, nameof(ValueExtractor));
            Locator         = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IType, ILocator>(this, nameof(Locator));
            Converters      = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IType, IConverter>(this, nameof(Converters));
            StaticInstances = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IType, object>(this, nameof(StaticInstances));
            Initializers    = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IType, IConstructor>(this, nameof(Initializers));
            Datas           = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IType, IProperty>(this, nameof(Datas));
            Operations      = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IType, IMethod>(this, nameof(Operations));

            DataFetchedEagerly = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IProperty, bool>(this, nameof(DataFetchedEagerly));

            ParameterIsOptional   = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IParameter, bool>(this, nameof(ParameterIsOptional));
            ParameterDefaultValue = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IParameter, object>(this, nameof(ParameterDefaultValue));

            Module        = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IType, string>(this, nameof(Module), true);
            TypeName      = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IType, string>(this, nameof(TypeName), true);
            DataName      = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IProperty, string>(this, nameof(DataName), true);
            OperationName = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IMethod, string>(this, nameof(OperationName), true);
            ParameterName = new ConventionBasedConfiguration <ConventionBasedCodingStyle, IParameter, string>(this, nameof(ParameterName), true);

            TypeMarks        = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IType, string>(this, nameof(TypeMarks));
            InitializerMarks = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IConstructor, string>(this, nameof(InitializerMarks));
            DataMarks        = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IProperty, string>(this, nameof(DataMarks));
            OperationMarks   = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IMethod, string>(this, nameof(OperationMarks));
            ParameterMarks   = new ConventionBasedListConfiguration <ConventionBasedCodingStyle, IParameter, string>(this, nameof(ParameterMarks));
        }
        public VirtualParameter(IParametric owner)
        {
            this.owner = owner;

            Name          = new SingleConfiguration <VirtualParameter, string>(this, nameof(Name), true);
            ParameterType = new SingleConfiguration <VirtualParameter, IType>(this, nameof(ParameterType), true);
            Index         = new SingleConfiguration <VirtualParameter, int>(this, nameof(Index));
        }
        public void Returns_configured_value()
        {
            var testing = new SingleConfiguration <string, string>("dummy", "test");

            testing.Set("expected");

            Assert.AreEqual("expected", testing.Get());
        }
        public void When_setting_value__parent_configuration_can_be_used()
        {
            var testing = new SingleConfiguration <string, string>("dummy", "test");

            testing.Set(s => s.Replace("d", "s").Replace("m", "n"));

            Assert.AreEqual("sunny", testing.Get());
        }
示例#5
0
 public VirtualType()
 {
     Name              = new SingleConfiguration <VirtualType, string>(this, nameof(Name), true);
     Namespace         = new SingleConfiguration <VirtualType, string>(this, nameof(Namespace), true);
     IsInterface       = new SingleConfiguration <VirtualType, bool>(this, nameof(IsInterface));
     DefaultInstanceId = new SingleConfiguration <VirtualType, string>(this, nameof(DefaultInstanceId), true);
     ToStringMethod    = new SingleConfiguration <VirtualType, Func <VirtualObject, string> >(this, nameof(ToStringMethod));
     AssignableTypes   = new ListConfiguration <VirtualType, VirtualType>(this, nameof(AssignableTypes));
     Methods           = new ListConfiguration <VirtualType, IMethod>(this, nameof(Methods));
 }
        public void When_not_set_and_not_required_returns_default_value()
        {
            var testing = new SingleConfiguration <string, string>("dummy", "test");

            Assert.IsNull(testing.Get());

            var testingInt = new SingleConfiguration <string, int>("dummy", "test");

            Assert.AreEqual(0, testingInt.Get());
        }
        public void When_set_more_than_once__returns_last_configured_value()
        {
            var testing = new SingleConfiguration <string, string>("dummy", "test");

            testing.Set("expected");
            testing.Set("expected2");
            testing.Set("expected3");

            Assert.AreEqual("expected3", testing.Get());
        }
        public ConventionBasedServiceClientConfiguration()
        {
            ServiceUrlBase = new SingleConfiguration <ConventionBasedServiceClientConfiguration, string>(this, nameof(ServiceUrlBase), true);

            RequestHeaders = new ListConfiguration <ConventionBasedServiceClientConfiguration, string>(this, nameof(RequestHeaders));

            Exception                = new ConventionBasedConfiguration <ConventionBasedServiceClientConfiguration, ExceptionResult, Exception>(this, nameof(Exception));
            RequestHeaderValue       = new ConventionBasedConfiguration <ConventionBasedServiceClientConfiguration, string, string>(this, nameof(RequestHeaderValue));
            ResponseHeaderProcessors = new ListConfiguration <ConventionBasedServiceClientConfiguration, IHeaderProcessor>(this, nameof(ResponseHeaderProcessors));
        }
示例#9
0
        public VirtualMethod(IType parentType)
        {
            this.parentType = parentType;

            Name                 = new SingleConfiguration <VirtualMethod, string>(this, nameof(Name), true);
            ReturnType           = new SingleConfiguration <VirtualMethod, IType>(this, nameof(ReturnType), true);
            Body                 = new SingleConfiguration <VirtualMethod, Func <object, object[], object> >(this, nameof(Body), true);
            TypeRetrieveStrategy = new SingleConfiguration <VirtualMethod, Func <object, IType> >(this, nameof(TypeRetrieveStrategy), true);
            Parameters           = new ListConfiguration <VirtualMethod, IParameter>(this, nameof(Parameters));

            TypeRetrieveStrategy.Set(o => o is VirtualObject vo ? vo.Type : o.GetTypeInfo());
        }
        public ConventionBasedServiceConfiguration()
        {
            RootPath = new SingleConfiguration <ConventionBasedServiceConfiguration, string>(this, nameof(RootPath), true);

            EnableTestApp = new SingleConfiguration <ConventionBasedServiceConfiguration, bool>(this, nameof(EnableTestApp), true);
            TestAppPath   = new SingleConfiguration <ConventionBasedServiceConfiguration, string>(this, nameof(TestAppPath), true);

            AllowGet = new ConventionBasedConfiguration <ConventionBasedServiceConfiguration, OperationWithObjectModel, bool>(this, nameof(AllowGet), true);

            RequestHeaders          = new ListConfiguration <ConventionBasedServiceConfiguration, string>(this, nameof(RequestHeaders));
            RequestHeaderProcessors = new ListConfiguration <ConventionBasedServiceConfiguration, IHeaderProcessor>(this, nameof(RequestHeaderProcessors));

            ResponseHeaders     = new ListConfiguration <ConventionBasedServiceConfiguration, string>(this, nameof(ResponseHeaders));
            ResponseHeaderValue = new ConventionBasedConfiguration <ConventionBasedServiceConfiguration, string, string>(this, nameof(ResponseHeaderValue));

            ExceptionResult = new ConventionBasedConfiguration <ConventionBasedServiceConfiguration, Exception, ExceptionResult>(this, nameof(ExceptionResult));
        }
示例#11
0
        public ProxyMethod(IType parentType, IMethod real, Func <object, object[], object> targetDelegate, IEnumerable <IParameter> parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            Name = new SingleConfiguration <ProxyMethod, string>(this, nameof(Name), true);

            this.real           = real ?? throw new ArgumentNullException(nameof(real));
            this.parentType     = parentType ?? throw new ArgumentNullException(nameof(parentType));
            this.targetDelegate = targetDelegate ?? throw new ArgumentNullException(nameof(targetDelegate));

            this.parameters = parameters.Select((p, i) => new ProxyParameter(p, this, i) as IParameter).ToList();

            parameterOffset = this.parameters.Count;

            this.parameters.AddRange(real.Parameters.Select((p, i) => new ProxyParameter(p, this, parameterOffset + i) as IParameter));

            Name.Set(real.Name);
        }
示例#12
0
        /// <summary>
        /// 开始工作。
        /// </summary>
        /// <param name="configuration">工作相关配置</param>
        public void StartWork(SingleConfiguration configuration)
        {
            if (_jobNames.Contains(configuration.name))
            {
                string newName = configuration.name + Guid.NewGuid().ToString("N");
                Log.Warn(string.Format("已存在名为\"{0}\"的任务,当前任务将改名为\"{1}\"。", configuration.name, newName));
                configuration.name = newName;
            }

            _jobNames.Add(configuration.name);
            if (configuration.crontab == null || configuration.crontab.Count == 0)
            {
                throw new ArgumentException(string.Format("任务\"{0}\"的crontab字段为空。", configuration.name));
            }

            JobDataMap map = new JobDataMap
            {
                [ConfKey] = configuration
            };
            IJobDetail job = JobBuilder.Create <BackupWorker>()
                             .WithIdentity("job_" + configuration.name, _groupName)
                             .UsingJobData(map)
                             .Build();

            TriggerBuilder triggerBuilder = TriggerBuilder.Create()
                                            .WithIdentity("trigger_" + configuration.name, _groupName)
                                            .StartNow();

            foreach (var i in configuration.crontab)
            {
                triggerBuilder.WithCronSchedule(i);
            }

            ITrigger trigger = triggerBuilder.Build();

            _scheduler.ScheduleJob(job, trigger);
        }
        public void When_not_set_and_required_throws_ConfigurationException()
        {
            var testing = new SingleConfiguration <string, string>("dummy", "test", true);

            Assert.Throws <ConfigurationException>(() => testing.Get());
        }