コード例 #1
0
        public void CreateShipWrong2()
        {
            MethodFactory factory = EarthFactory.Instance;
            var           ship    = factory.BuildCapitalShip("asdadwdq");

            Assert.IsNull(ship);
        }
コード例 #2
0
        public void CreateShipEmpty()
        {
            MethodFactory factory = EarthFactory.Instance;
            var           ship    = factory.BuildFrigate(null);

            Assert.IsNull(ship);
        }
コード例 #3
0
        public void CreateShipWrong()
        {
            MethodFactory factory = EarthFactory.Instance;
            var           ship    = factory.BuildFrigate("aeria");

            Assert.IsNull(ship);
        }
コード例 #4
0
        public void CreateShipWrong1()
        {
            MethodFactory factory = EarthFactory.Instance;
            var           ship    = factory.BuildCruiser("dwqdqwd");

            Assert.IsNull(ship);
        }
コード例 #5
0
        public void CreateShip2()
        {
            MethodFactory factory = EarthFactory.Instance;
            var           ship    = factory.BuildCapitalShip("vulkoras");

            Assert.IsNotNull(ship);
        }
コード例 #6
0
        public void CreateShip1()
        {
            MethodFactory factory = EarthFactory.Instance;
            var           ship    = factory.BuildCruiser("destra");

            Assert.IsNotNull(ship);
        }
コード例 #7
0
        public void CreateShip()
        {
            MethodFactory factory = EarthFactory.Instance;
            var           ship    = factory.BuildFrigate("disciple");

            Assert.IsNotNull(ship);
        }
コード例 #8
0
        public void CreateShipEmpty2()
        {
            MethodFactory factory = EarthFactory.Instance;
            var           ship    = factory.BuildCapitalShip(null);

            Assert.IsNull(ship);
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationItemFactory"/> class.
        /// </summary>
        /// <param name="assemblies">The assemblies to scan for named items.</param>
        public ConfigurationItemFactory(params Assembly[] assemblies)
        {
            this.CreateInstance = FactoryHelper.CreateInstance;
            this.targets = new Factory<Target, TargetAttribute>(this);
            this.filters = new Factory<Filter, FilterAttribute>(this);
            this.layoutRenderers = new Factory<LayoutRenderer, LayoutRendererAttribute>(this);
            this.layouts = new Factory<Layout, LayoutAttribute>(this);
            this.conditionMethods = new MethodFactory<ConditionMethodsAttribute, ConditionMethodAttribute>();
            this.ambientProperties = new Factory<LayoutRenderer, AmbientPropertyAttribute>(this);
            this.timeSources = new Factory<TimeSource, TimeSourceAttribute>(this);
            this.allFactories = new List<object>
            {
                this.targets,
                this.filters,
                this.layoutRenderers,
                this.layouts,
                this.conditionMethods,
                this.ambientProperties,
                this.timeSources,
            };

            foreach (var asm in assemblies)
            {
                this.RegisterItemsFromAssembly(asm);
            }
        }
コード例 #10
0
    /// <summary>
    /// 初始化
    /// </summary>
    static Copier()
    {
        MethodFactory <Func <TValue, TValue> > method = MethodFactory.Create <Func <TValue, TValue> >();
        Type type = typeof(TValue);

        if (type == typeof(object))
        {
            method.LoadArg(0).Return();
            return;
        }
        switch (Type.GetTypeCode(type))
        {
        case TypeCode.Object:
            if (type.IsClass)
            {
                method.LoadArg(0).Call(Reflector.GetMethod(typeof(object), "MemberwiseClone")).Cast(typeof(object), typeof(TValue)).Return();
            }
            else
            {
                method.LoadArg(0).Return();
            }
            break;

        default:
            method.LoadArg(0).Return();
            break;
        }
        Clone = method.Delegation;
    }
コード例 #11
0
        public void MethodFactoryShouldReturnCorrectMethodInstance(string flowType, Type methodType)
        {
            var factory = new MethodFactory(_loggerMock);
            IDischargeCalculator method = factory.SelectCalculator(flowType, _settingsMock);

            Assert.AreEqual(methodType, method.GetType());
        }
コード例 #12
0
        public async Task <TResponse> Handle(
            TRequest request,
            CancellationToken cancellationToken,
            RequestHandlerDelegate <TResponse> next)
        {
            foreach (var property in request.Command.GetType().GetProperties())
            {
                if (!TryGetRequestValue(property, request.Command, out var keyPair))
                {
                    continue;
                }

                if (!property.TryGetAttribute <IdCollectionAttribute>(out var attribute))
                {
                    request.RequestPropertyValues.Add(keyPair.Key, keyPair.Value);
                    continue;
                }

                var entities = await MethodFactory.GetManyAsync(attribute.EntityType)
                               .InvokeAsync(
                    _repository,
                    new object[] { keyPair.Value, cancellationToken });

                request.RequestPropertyValues.Add(keyPair.Key, entities);
                request.RequestForeignEntities.Add(keyPair.Key, attribute.EntityType);
                request.IncludeNavigation = string.Join(".", keyPair.Key);
            }

            return(await next());
        }
コード例 #13
0
        private static string CalcOneMethod(SemiSpaceParameters parameters)
        {
            var bound12 = new Parallelepiped(-1, 1, -1, 1, FunctionsForSemiSpace.H, 1, 4, 4, 4)
            {
                Name = BoundNumber.Bound12
            };
            var bound2 = new Parallelepiped(-1, 1, -1, 1, FunctionsForSemiSpace.H, 1, 4, 4, 4)
            {
                Name = BoundNumber.Bound2
            };
            var bound13 = new Parallelepiped(-1, 1, 0, 1, -1, FunctionsForSemiSpace.H, 4, 4, 4)
            {
                Name = BoundNumber.Bound13
            };
            var bound3 = new Parallelepiped(-1, 1, 0, 1, -1, FunctionsForSemiSpace.H, 4, 4, 4)
            {
                Name = BoundNumber.Bound3
            };
            //   var bound12 = new Sphere(new Point3D(5, 0, FunctionsForSemiSpace.H)) { Name = BoundNumber.Bound12 };
            //var bound2 = new Sphere(new Point3D(5, 0, FunctionsForSemiSpace.H)) { Name = BoundNumber.Bound2 };
            //  var bound13 = new Sphere(new Point3D(5, 0, FunctionsForSemiSpace.H)) { Name = BoundNumber.Bound13 };
            //  var bound3 = new Sphere(new Point3D(5, 0, FunctionsForSemiSpace.H)) { Name = BoundNumber.Bound3 };
            var boundWithCondition = ConditionSetter.SetBoundSphere(bound12, bound2, bound13, bound3).ToList();
            //   var boundWithCondition = ConditionSetter.SetBoundSphere(bound12, bound2).ToList();
            var method = MethodFactory.GetSphereMethod(boundWithCondition, null, parameters);

            method.Solve();
            var plotter = PlotterFactory.GetPlotter(method.U, parameters);

            plotter.Plot();
            return(plotter.FormatedFileName);
        }
コード例 #14
0
        // registry this type with the registry
        public void RegisterType(Type type)
        {
            var info = type.GetTypeInfo();

            if (info.IsEnum || constructors.ContainsKey(type))
            {
                return;
            }

            var constructor = type.GetConstructors().FirstOrDefault(x => x.GetParameters().Length == 0);

            if (constructor == null)
            {
                throw new ArgumentException($"{type.FullName} does not have any accessible parameterless constructors.", nameof(type));
            }

            var attribute     = info.GetCustomAttribute <RtmpSharpAttribute>(false) ?? RtmpSharpAttribute.Empty;
            var canonicalName = attribute.CanonicalName ?? type.FullName;
            var names         = attribute.Names ?? EmptyCollection <string> .Array;

            foreach (var name in names)
            {
                localTypeLookup[name] = type;
            }

            constructors[type] = MethodFactory.CompileConstructor(constructor);
            remoteNameLookup[type.FullName] = canonicalName;

            if (canonicalName != "")
            {
                localTypeLookup[canonicalName] = type;
            }
        }
コード例 #15
0
        public static IMethodInfo GetMethod(this InvokeExpression invokeExpr, SemanticContext context)
        {
            var parts = invokeExpr.MethodName.Parts.ToInvertedStack();

            TypeDefinition type;

            if (!context.TypeRegistry.TrySearch(parts, out type))
            {
                throw new SemanticException("Can't find method by identifier: {0}", invokeExpr.MethodName);
            }

            // todo: implement member chaining

            var methodName = parts.Pop();
            var types      = invokeExpr.Arguments
                             .Select(x => TypeInference.InferType(x.Value, context))
                             .ToArray(invokeExpr.Arguments.Count);

            var method = type.GetMethod(methodName, types);

            if (method == null)
            {
                throw new SemanticException("Can't find method by identifier: {0}", invokeExpr.MethodName);
            }

            if (method.DeclaringType.Assembly.Equals(context.TypeDefinition.Assembly))
            {
                return(method);
            }

            return(MethodFactory.GetMethodReference(method));
        }
コード例 #16
0
        public void SetUp()
        {
            _relatedMethodFinderMock = MockRepository.GenerateStrictMock <IRelatedMethodFinder>();

            _factory = new MethodFactory(_relatedMethodFinderMock);

            _mutableType = MutableTypeObjectMother.Create(baseType: typeof(DomainType));
        }
コード例 #17
0
        public void SetUp()
        {
            _relatedMethodFinderMock = new Mock <IRelatedMethodFinder> (MockBehavior.Strict);

            _factory = new MethodFactory(_relatedMethodFinderMock.Object);

            _mutableType = MutableTypeObjectMother.Create(baseType: typeof(DomainType));
        }
コード例 #18
0
        public void CreateWehicleChecEmptyName()
        {
            MethodFactory factory1 = MarsFactory.Instance;
            MethodFactory factory2 = MarsFactory.Instance;
            var           ship1    = factory1.BuildCruiser("skarovas");
            var           ship2    = factory2.BuildCruiser("skarovas");

            Assert.AreEqual(ship1.Name, ship2.Name);
        }
コード例 #19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (UDIRSHelper.PersonDetails != null)
         {
             MethodFactory.BindStatusSearch(ref ddlStatus);
             BindGridview(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, UDIRSHelper.PersonDetails.Id);
         }
     }
 }
コード例 #20
0
ファイル: FunctionEmitter.cs プロジェクト: Sable/McCli
        public static FunctionMethod Emit(IR.Function function, MethodFactory methodFactory, FunctionLookup functionLookup)
        {
            Contract.Requires(function != null);
            Contract.Requires(methodFactory != null);
            Contract.Requires(functionLookup != null);

            var emitter = new FunctionEmitter(function, methodFactory, functionLookup);

            emitter.EmitBody();
            return(emitter.Method);
        }
コード例 #21
0
        public PaperKirghoff1UmovaProgram(Bound <Point3D> bound, List <InnerSourceWithFunction <Point3D> > source)
        {
            var boundWithCondition = ConditionSetter.SetDirichletConditionSphere(bound);

            method = MethodFactory.GetCollocationKirghoffMethod(
                boundWithCondition,
                source,
                KirghoffTransformation.Pow,
                KirghoffTransformation.ConversePow);
            method.Solve();
        }
コード例 #22
0
        public void MethodFactoryShouldThrowExceptionIfUnsupportedFlowType(string flowType)
        {
            var factory = new MethodFactory(_loggerMock);

            Assert.Throws <Exception>(() =>
            {
                factory.SelectCalculator(flowType, _settingsMock);
            });

            Mock.Get(_loggerMock).Verify(x => x.Error(It.IsAny <string>()), Times.Once);
            Mock.Get(_loggerMock).Invocations.Clear();
        }
コード例 #23
0
        static void Main(string[] args)
        {
            var Configuration = ReadFromAppSettings();

            var methodInvoker = new MethodFactory(new MethodFactoryConfiguration()
            {
                AssemblyPrefix = new List <string>()
                {
                    "CustomMethod"
                },
                AssemblySuffix = new List <string>()
                {
                    "MethodLib"
                },
                AssemblyRelatedPath = Configuration["AssemblyRelatedPath"] ?? string.Empty
            });

            var regex = new Regex(@"(?<first>[0-9 ]+)(?<expression>\+|\-|\*|\/)(?<second>[0-9 ]+)", RegexOptions.Compiled);

            while (true)
            {
                Console.WriteLine($"Key in any arithmetic like '123 + 321' or 'Exit' to leave.");

                var input = Console.ReadLine();

                if (input.Equals("Exit", StringComparison.InvariantCultureIgnoreCase))
                {
                    break;
                }

                var match = regex.Match(input);

                if (!match.Success)
                {
                    Console.WriteLine($"Format error!");
                    continue;
                }

                var firstNumber  = Convert.ToInt32(match.Groups["first"].Value);
                var secondNumber = Convert.ToInt32(match.Groups["second"].Value);
                var expression   = match.Groups["expression"].Value.ToString();

                // Get Method
                var method = methodInvoker.GetInvokeMethod(GetMethodName(expression), null);

                // Call function
                var returnResult = (int)method.DynamicInvoke(new object[] { firstNumber, secondNumber });

                Console.WriteLine($"The answer is : {returnResult}");
            }
        }
コード例 #24
0
        private object InvokeEntityMethod(string methodName)
        {
            MethodInfo methodInfo = MethodFactory.GetMethodInfo(this.Page.GetType(), methodName);

            if (methodInfo != null && this.IsAjaxMethod(methodInfo))
            {
                ParameterInfo[] pareameterInfos    = ParameterFactory.GetParameterInfos(methodInfo);
                object[]        parameterValueList = this.GetEntityParameterValueList(pareameterInfos);
                return(methodInfo.Invoke(this.Page, parameterValueList));
            }
            else
            {
                throw new Exception("没有找到指定调用方法");
            }
        }
コード例 #25
0
        public void DoWork()
        {
            var sw = new Stopwatch();

            sw.Start();
            //  var bound = new ParallelepipedNearBound();
            var bound = new Parallelepiped();
            var boundWithCondition = ConditionSetter.SetKirghoffCondition(bound);
            var source             = new InnerSourcePlate();
            //  var innerSource = new List<InnerSourceWithFunction<Point3D>>(); //no innersors CollocationKirghoffMethod
            var innerSource = InnerSourceFactory.GetSourcesParalelepiped(source);

            var eps = 1;

            var    paperKirghoff = new PaperKirghoff1UmovaProgram(bound, innerSource);
            var    dPrevious     = paperKirghoff.GetSolutionVector();
            Vector dCurrent;

            while (true)
            {
                var method1 = MethodFactory.GetJakobiMethod(boundWithCondition, innerSource, dPrevious);
                method1.Solve();
                dCurrent  = dPrevious + method1.Solution;
                dPrevious = dCurrent;
                Console.WriteLine("d: " + method1.Solution.Norma());
                if (method1.Solution.Norma() < eps)
                {
                    break;
                }
            }
            var method = MethodFactory.GetCollocationKirghoffMethod(
                boundWithCondition,
                innerSource,
                KirghoffTransformation.Pow,
                KirghoffTransformation.ConversePow);

            method.Solution = dCurrent;

            var plotter = PlotterFactory.GetPlotter(bound, method.U);

            plotter.Plot();
            // Console.WriteLine("Total time: " + sw.ElapsedMilliseconds);

            /*f-1*f(d0)=x
             * d1=d0-x,
             * f-1*f(d1)=x
             * d2=d1-x*/
        }
コード例 #26
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (UDIRSHelper.PersonDetails != null)
         {
             MethodFactory.BindStatusSearch(ref ddlStatus);
             BindGridview(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 0);
             PopulateLocation();
         }
     }
     else
     {
         //lblMsg.Text = "No Incident Report.";
     }
 }
コード例 #27
0
        public void AddtionProcessTest()
        {
            var methodInvoker = new MethodFactory();

            var firstNumber      = 20;
            var secondNumber     = 30;
            var expressionMethod = "AddtionProcess";

            // Get Method
            var method = methodInvoker.GetInvokeMethod(expressionMethod, null);

            // Call function
            var returnResult = (int)method.DynamicInvoke(new object[] { firstNumber, secondNumber });

            Assert.AreEqual(firstNumber + secondNumber, returnResult);
        }
コード例 #28
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            object                       instance         = MethodFactory.CreateInstance(destinationType);
            ClassDescription             classDescription = this._serializationContext.GetClassDescription(destinationType, instance);
            IDictionary <string, object> dictionary       = value as IDictionary <string, object>;

            if (dictionary == null)
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            foreach (KeyValuePair <string, object> keyValuePair in (IEnumerable <KeyValuePair <string, object> >)dictionary)
            {
                IMemberWrapper memberWrapper;
                if (classDescription.TryGetMember(keyValuePair.Key, out memberWrapper))
                {
                    memberWrapper.SetValue(instance, keyValuePair.Value);
                }
            }
            return(instance);
        }
コード例 #29
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            var instance         = MethodFactory.CreateInstance(destinationType);
            var classDescription = serializationContext.GetClassDescription(destinationType, instance);
            var source           = value as IDictionary <string, object>;

            if (source != null)
            {
                foreach (var kv in source)
                {
                    IMemberWrapper wrapper;
                    if (classDescription.TryGetMember(kv.Key, out wrapper))
                    {
                        wrapper.SetValue(instance, kv.Value);
                    }
                }
                return(instance);
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
コード例 #30
0
 public static object InvokeMethod(this object entity, string methodName, object[] parameters)
 {
     try
     {
         MethodInfo methodInfo = MethodFactory.GetMethodInfo(entity.GetType(), methodName);
         if (methodInfo != null)
         {
             ParameterInfo[] pareameterInfos = ParameterFactory.GetParameterInfos(methodInfo);
             return(methodInfo.Invoke(entity, parameters));
         }
         else
         {
             throw new Exception("没有找到指定调用方法");
         }
     }
     catch (Exception e)
     {
         throw new Exception(string.Format("调用指定调用方法时出错,{0}", e.Message));
     }
 }
コード例 #31
0
        public void DoWork()
        {
            var bound = new Circle(800, 2)
            {
                IsOuter = true
            };

            ////var bound = new Rectangle(new Point2D(-1, -1), new Point2D(1, 1), 160) { IsOuter = true };
            var segment1 = new Segment(new Point2D(-1.1, -1.1), new Point2D(1.1, 1.1), 160);
            ////var segment1 = new Segment(new Point2D(-0.75, 0.1), new Point2D(0, 0.9), 80);
            ////var segment2 = new Segment(new Point2D(-0.75, -0.1), new Point2D(0, -0.9), 80);
            ////var segment3 = new Segment(new Point2D(0.75, 0.1), new Point2D(0, 0.9), 80);
            ////var segment4 = new Segment(new Point2D(0.75, -0.1), new Point2D(0, -0.9), 80);
            var boundWithCondition = ConditionSetter.SetDirichletCondition(segment1, bound);
            var method             = MethodFactory.GetCollocationPaper6Method(boundWithCondition, 1);

            method.Solve();
            var plotter = PlotterFactory.GetPlotter(bound, method.U, 40);

            plotter.Plot();
        }
コード例 #32
0
ファイル: ConfigurationItemFactory.cs プロジェクト: ExM/NLog
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationItemFactory"/> class.
        /// </summary>
        /// <param name="assemblies">The assemblies to scan for named items.</param>
        public ConfigurationItemFactory(params Assembly[] assemblies)
        {
            CreateInstance = FactoryHelper.CreateInstance;
            _targets = new Factory<Target, TargetAttribute>(this);
            _filters = new Factory<Filter, FilterAttribute>(this);
            _layoutRenderers = new Factory<LayoutRenderer, LayoutRendererAttribute>(this);
            _layouts = new Factory<Layout, LayoutAttribute>(this);
            _conditionMethods = new MethodFactory<ConditionMethodsAttribute, ConditionMethodAttribute>();
            _ambientProperties = new Factory<LayoutRenderer, AmbientPropertyAttribute>(this);
            _allFactories = new List<object>
            {
                _targets,
                _filters,
                _layoutRenderers,
                _layouts,
                _conditionMethods,
                _ambientProperties,
            };

            foreach (var asm in assemblies)
                RegisterItemsFromAssembly(asm);
        }