Ejemplo n.º 1
0
 public Service(IUnitOfWork work)
 {
     this.work  = work;
     Account    = new AccountService(work);
     Tournament = new TournamentService(work);
     Type       = new TypeService(work);
 }
Ejemplo n.º 2
0
        public void AddMatchingInterfaces()
        {
            foreach (var interfaceMatch in Config.InterfaceMatches)
            {
                var matchConfigExists = !string.IsNullOrEmpty(interfaceMatch.Match);
                var matchRegEx        = matchConfigExists ? new Regex(interfaceMatch.Match) : null;

                var excludeMatchConfigExists = !string.IsNullOrEmpty(interfaceMatch.ExcludeMatch);
                var excludeMatchRegEx        = excludeMatchConfigExists ? new Regex(interfaceMatch.ExcludeMatch) : null;

                var baseTypeNameConfigExists = !string.IsNullOrEmpty(interfaceMatch.BaseTypeName);
                if (baseTypeNameConfigExists)
                {
                    var baseType = TypeService.GetTypeDefinition(interfaceMatch.BaseTypeName);
                    AddInterfaceNode(baseType);
                }

                foreach (var type in TypeService.Types)
                {
                    var isMatch = matchRegEx != null && matchRegEx.IsMatch(type.FullName) &&
                                  (!excludeMatchConfigExists || !excludeMatchRegEx.IsMatch(type.FullName));

                    var doesBaseTypeMatch = !baseTypeNameConfigExists ||
                                            TypeService.GetBaseTypes(type).Any(t => t.FullName.EndsWith(interfaceMatch.BaseTypeName));

                    if (isMatch && doesBaseTypeMatch)
                    {
                        AddInterfaceNode(type);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private Grid GetGridForInput(SnippetInput input)
        {
            var newInputGrid = new Grid();

            newInputGrid.Visibility = Visibility.Visible;
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.RowDefinitions.Add(new RowDefinition());

            var variableName = new TextBox();

            variableName.Text = input.VariableName;
            newInputGrid.Children.Add(variableName);
            Grid.SetColumn(variableName, 0);

            var friendlyName = new TextBox();

            friendlyName.Text = input.FriendlyName;
            newInputGrid.Children.Add(friendlyName);
            Grid.SetColumn(friendlyName, 1);

            var description = new TextBox();

            description.Text = input.Description;
            newInputGrid.Children.Add(description);
            Grid.SetColumn(description, 2);

            var type = new ComboBox();

            type.DisplayMemberPath = "Value";
            type.SelectedValuePath = "Key";
            var availableTypes = TypeService.GetAvailableTypes().ToDictionary(x => x.ID, x => x.Name);

            type.ItemsSource   = availableTypes;
            type.SelectedValue = input.TypeID;
            newInputGrid.Children.Add(type);
            Grid.SetColumn(type, 3);

            var optional = new CheckBox();

            optional.IsChecked = input.IsOptional;
            newInputGrid.Children.Add(optional);
            Grid.SetColumn(optional, 4);

            var remove = new Button();

            remove.Content = "Remove";
            remove.Click  += (sender, args) =>
            {
                InputStack.Children.Remove(newInputGrid);
            };
            newInputGrid.Children.Add(remove);
            Grid.SetColumn(remove, 5);

            return(newInputGrid);
        }
        internal override void ProcessOperand(TypeService service, MethodDef method, IList <Instruction> body, ref int index, MethodSpec operand)
        {
            Debug.Assert(service != null, $"{nameof(service)} != null");
            Debug.Assert(method != null, $"{nameof(method)} != null");
            Debug.Assert(body != null, $"{nameof(body)} != null");
            Debug.Assert(operand != null, $"{nameof(operand)} != null");
            Debug.Assert(index >= 0, $"{nameof(index)} >= 0");
            Debug.Assert(index < body.Count, $"{nameof(index)} < {nameof(body)}.Count");

            var current = service.GetItem(method);

            if (operand.Method is MethodDef operandDef)
            {
                var operandScanned = service.GetItem(operandDef);
                if (operandScanned?.IsScambled == true)
                {
                    operand.GenericInstMethodSig = operandScanned.CreateGenericMethodSig(current, service, operand.GenericInstMethodSig);
                }
            }
            else if (current?.IsScambled == true)
            {
                var generics = operand.GenericInstMethodSig.GenericArguments.Select(x => current.ConvertToGenericIfAvalible(x));
                operand.GenericInstMethodSig = new GenericInstMethodSig(generics.ToArray());
            }
        }
Ejemplo n.º 5
0
            /// <exception cref="IOException"> 发生 I/O 错误。</exception>
            /// <exception cref="ObjectDisposedException"> <see cref="T:System.IO.TextWriter" /> 是关闭的。</exception>
            public void Write(object obj, JsonWriterArgs args)
            {
                if (obj == null)
                {
                    args.WriterContainer.GetNullWriter().Write(null, args);
                    return;
                }
                var writer = TypeService.IsImmutable <TValue>() ? args.WriterContainer.GetWriter <TValue>() : null;

                args.BeginObject();
                var comma = new CommaHelper(args.Writer);

                foreach (var item in (IDictionary <TKey, TValue>)obj)
                {
                    var value = item.Value;
                    if (args.IgnoreNullMember)
                    {
                        if (value == null || value is DBNull)
                        {
                            continue;
                        }
                    }
                    comma.AppendCommaIgnoreFirst();

                    args.WriterContainer.GetWriter <string>().Write(item.Key as string ?? item.Key.To <string>(), args);
                    args.Colon();
                    args.WriteCheckLoop(value, writer);
                }

                args.EndObject();
            }
Ejemplo n.º 6
0
        internal GenericInstMethodSig CreateGenericMethodSig(ScannedMethod from, TypeService srv, GenericInstMethodSig original = null)
        {
            var types = new List <TypeSig>(TrueTypes.Count);

            foreach (var trueType in TrueTypes)
            {
                if (trueType.IsGenericMethodParameter)
                {
                    Debug.Assert(original != null, $"{nameof(original)} != null");

                    var number = ((GenericSig)trueType).Number;
                    Debug.Assert(number < original.GenericArguments.Count,
                                 $"{nameof(number)} < {nameof(original)}.GenericArguments.Count");
                    var originalArgument = original.GenericArguments[(int)number];
                    types.Add(originalArgument);
                }
                else if (from?.IsScambled == true)
                {
                    types.Add(from.ConvertToGenericIfAvalible(trueType));
                }
                else if (trueType.ToTypeDefOrRef() is TypeDef def)
                {
                    // I am sure there are cleaner and better ways to do this.
                    var item = srv.GetItem(def);
                    types.Add(item?.IsScambled == true ? item.CreateGenericTypeSig(null) : trueType);
                }
                else
                {
                    types.Add(trueType);
                }
            }
            return(new GenericInstMethodSig(types));
        }
Ejemplo n.º 7
0
        private bool AreRunInputsValid()
        {
            var availableTypes = TypeService.GetAvailableTypes();

            foreach (var child in RunInputs.Children)
            {
                var grid = child as Grid;
                if (grid != null)
                {
                    var typeID   = ((Label)grid.Children[2]).Content.ToString();
                    var thisType = availableTypes.First(x => x.ID == Guid.Parse(typeID));

                    if (!thisType.HasMultipleValues)
                    {
                        var value = ((TextBox)grid.Children[1]).Text;

                        if (!String.IsNullOrEmpty(thisType.Regex))
                        {
                            var regex = new Regex(thisType.Regex);
                            if (!regex.IsMatch(value))
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 8
0
        internal void Process(TypeService service, MethodDef method, IList <Instruction> instructions, ref int index)
        {
            Debug.Assert(service != null, $"{nameof(service)} != null");
            Debug.Assert(method != null, $"{nameof(method)} != null");
            Debug.Assert(instructions != null, $"{nameof(instructions)} != null");
            Debug.Assert(index >= 0, $"{nameof(index)} >= 0");
            Debug.Assert(index < instructions.Count, $"{nameof(index)} < {nameof(instructions)}.Count");

            Instruction current = instructions[index];

            if (current.Operand == null)
            {
                return;
            }

            var currentRefType = current.Operand.GetType();

            while (currentRefType != typeof(object))
            {
                if (RewriterDefinitions.TryGetValue(currentRefType, out var rw))
                {
                    rw.ProcessInstruction(service, method, instructions, ref index, current);
                    break;
                }
                currentRefType = currentRefType.BaseType;
            }
        }
Ejemplo n.º 9
0
            public void Write(object obj, JsonWriterArgs args)
            {
                if (obj == null)
                {
                    args.WriterContainer.GetNullWriter().Write(null, args);
                    return;
                }
                var writer = TypeService.IsImmutable <T>() ? args.WriterContainer.GetWriter <T>() : null;
                var list   = (IList <T>)obj;

                if (list.Count == 0)
                {
                    args.BeginArray();
                    args.EndArray();
                    return;
                }
                args.BeginArray();
                args.WriteCheckLoop(list[0], writer);

                for (int i = 1, length = list.Count; i < length; i++)
                {
                    args.Common();
                    args.WriteCheckLoop(list[i], writer);
                }

                args.EndArray();
            }
        public static PropertyDescriptorCollection GetPropertiesOf(Type type)
        {
            Type itemType = TypeService.GetItemType(collectionType: type);

            if (itemType != null)
            {
                type = itemType;
            }

            IVMDescriptor childDescriptor = ClassDescriptorAttribute
                                            .GetClassDescriptorOf(type);

            if (childDescriptor != null)
            {
                var browsableDescriptors = childDescriptor
                                           .GetPropertyDescriptors()
                                           .OfType <ViewModelPropertyDescriptor>()
                                           .Select(actual => new BrowsablePropertyDescriptor(actual))
                                           .ToArray();

                return(new PropertyDescriptorCollection(browsableDescriptors));
            }

            return(TypeDescriptor.GetProperties(type));
        }
Ejemplo n.º 11
0
        private Grid GetRunInputGridForInput(SnippetInput input)
        {
            var newInputGrid = new Grid();

            newInputGrid.Visibility = Visibility.Visible;
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newInputGrid.RowDefinitions.Add(new RowDefinition());

            var friendlyName = new Label();

            friendlyName.Content = input.FriendlyName;
            newInputGrid.Children.Add(friendlyName);
            Grid.SetColumn(friendlyName, 0);

            var type = TypeService.GetAvailableTypes().First(x => x.ID == input.TypeID);

            if (!type.HasMultipleValues)
            {
                var friendlyNameInput = new TextBox();
                newInputGrid.Children.Add(friendlyNameInput);
                Grid.SetColumn(friendlyNameInput, 1);
            }
            else
            {
                var listDropDown = new ComboBox();
                if (type.ListValues.Count == 1)
                {
                    listDropDown.ItemsSource = type.ListValues.First().Value;
                }
                else
                {
                    var items = new List <Item>();
                    foreach (var listSection in type.ListValues)
                    {
                        foreach (var element in listSection.Value)
                        {
                            items.Add(new Item(element, listSection.Key));
                        }
                    }

                    var listCollection = new ListCollectionView(items);
                    listCollection.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
                    listDropDown.ItemsSource = listCollection;
                }
                newInputGrid.Children.Add(listDropDown);
                Grid.SetColumn(listDropDown, 1);
            }

            var id = new Label();

            id.Content    = input.TypeID;
            id.Visibility = Visibility.Collapsed;
            newInputGrid.Children.Add(id);
            Grid.SetColumn(id, 2);

            return(newInputGrid);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericMessage"/> class with the given invoke method request values.
 /// </summary>
 /// <param name="requestId">The request id.</param>
 /// <param name="method">The method.</param>
 /// <param name="parameters">The parameters.</param>
 /// <param name="responseExptected">if set to <c>true</c> [response exptected].</param>
 public GenericMessage(long requestId, MethodInfo method, object[] parameters, bool responseExptected)
 {
     this.Type      = responseExptected ? MessageType.MethodInvokeRequest : MessageType.AsyncMethodInvokeRequest;
     this.RequestId = requestId;
     this.Target    = TypeService.GetSourceCodeTypeName(method.DeclaringType);
     this.Name      = method.Name;
     this.Payload   = parameters;
 }
Ejemplo n.º 13
0
        public void TestCreateProxyImplementationAsyncAwaitMethods()
        {
            Type result = TypeService.BuildProxyImplementation(typeof(IMyRemoteAsyncAwaitTestService));

            IMyRemoteAsyncAwaitTestService instance = (IMyRemoteAsyncAwaitTestService)Activator.CreateInstance(result, new object[2]);

            Assert.NotNull(instance);
        }
Ejemplo n.º 14
0
 public IndexModel(SourceService sourceService, AdvancedCardSearchService advancedCardSearchService,
                   SetService setService, TypeService typeService)
 {
     _sourceService             = sourceService;
     _advancedCardSearchService = advancedCardSearchService;
     _setService  = setService;
     _typeService = typeService;
 }
Ejemplo n.º 15
0
        public ActionResult AddResult()
        {
            var aniType = new TypeService();
            var type    = aniType.GetAll();

            ViewBag.GType = new SelectList(type, "Tid", "TName");
            return(View());
        }
        // GET: Type
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new TypeService(userId);
            var model   = service.GetAllTypes();

            return(View(model));
        }
Ejemplo n.º 17
0
        public void CanAssignNull_ReferenceType()
        {
            Assert.IsTrue(TypeService.CanAssignNull(typeof(object)));
            Assert.IsTrue(TypeService.CanAssignNull(typeof(Nullable <int>)));

            Assert.IsFalse(TypeService.CanAssignNull(typeof(int)));
            Assert.IsFalse(TypeService.CanAssignNull(typeof(TestStruct)));
        }
Ejemplo n.º 18
0
        public void TestCreateProxyImplementationGuidMethods()
        {
            Type result = TypeService.BuildProxyImplementation(typeof(IAutoImplementTestInterface));

            IAutoImplementTestInterface instance = (IAutoImplementTestInterface)Activator.CreateInstance(result, new object[2]);

            Assert.NotNull(instance);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Call the service and get data back
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private object CallService(RequestData data)
        {
            var type     = TypeService.GetServiceType(data.ServiceName);
            var method   = type.GetMethod(data.MethodName);
            var instance = Activator.CreateInstance(type);

            return(method.Invoke(instance, GetParameters(method, data.Parameters)));
        }
Ejemplo n.º 20
0
        internal override void ProcessOperand(TypeService service, MethodDef method, IList <Instruction> body, ref int index, MemberRef operand)
        {
            Debug.Assert(service != null, $"{nameof(service)} != null");
            Debug.Assert(method != null, $"{nameof(method)} != null");
            Debug.Assert(body != null, $"{nameof(body)} != null");
            Debug.Assert(operand != null, $"{nameof(operand)} != null");
            Debug.Assert(index >= 0, $"{nameof(index)} >= 0");
            Debug.Assert(index < body.Count, $"{nameof(index)} < {nameof(body)}.Count");

            var current = service.GetItem(method);

            if (operand.MethodSig == null)
            {
                return;
            }

            if (operand.MethodSig.Params.Count > 0 || body[index].OpCode != OpCodes.Newobj)
            {
                return;
            }

            ModuleDef mod = method.Module;

            var gettype        = typeof(Type).GetMethod("GetTypeFromHandle");
            var createInstance = typeof(Activator).GetMethod("CreateInstance", new Type[] { typeof(Type) });

            TypeSig sig = null;

            if (operand.Class is TypeRef typeRef)
            {
                sig = typeRef.ToTypeSig();
            }

            if (operand.Class is TypeSpec typeSpec)
            {
                sig = typeSpec.ToTypeSig();
            }

            if (sig != null)
            {
                body[index].OpCode = OpCodes.Ldtoken;

                var          gen         = current?.GetGeneric(sig);
                TypeSpecUser newTypeSpec = null;
                if (gen != null)
                {
                    newTypeSpec = new TypeSpecUser(new GenericMVar(gen.Number));
                }
                else
                {
                    newTypeSpec = new TypeSpecUser(sig);
                }
                body[index].Operand = newTypeSpec;

                body.Insert(++index, Instruction.Create(OpCodes.Call, mod.Import(gettype)));
                body.Insert(++index, Instruction.Create(OpCodes.Call, mod.Import(createInstance)));
            }
        }
Ejemplo n.º 21
0
        private static IValueItem AutoCreateMissingDeserializeType(uint expectedTypeId, string orgAssemblyName, string typeFullName, IStreamReader reader, ISerializeContext ctx)
        {
            //todo: restrict property count and global auto create types
            short propertyCount = reader.ReadInt16();

            string typeName = typeFullName.Split('.').Last();

            string assemblyName = $"IOCTalk.AutoGenerated.{orgAssemblyName}";

            StringBuilder code = new StringBuilder();

            code.AppendLine("using System;");
            code.AppendLine();
            code.Append("namespace ");
            code.Append(assemblyName);
            code.AppendLine();
            code.AppendLine("{");
            code.Append($"   public class {typeName}AutoGenerated");

            code.AppendLine();
            code.AppendLine("   {");
            code.AppendLine();

            for (int i = 0; i < propertyCount; i++)
            {
                ItemType itemType       = (ItemType)reader.ReadInt16(); // ItemType Enum
                uint     propertyTypeId = reader.ReadUInt32();          // TypeId (Type Hash)
                string   propertyName   = reader.ReadString();          // Property Name
                bool     isNullable     = reader.ReadBool();            // Nullable Flag

                // add property code
                Type propType = ValueItem.GetRuntimeType(itemType);

                if (propType == null)
                {
                    propType = typeof(object);
                }

                code.AppendLine($"      public {TypeService.GetSourceCodeTypeName(propType)} {propertyName} {{get; set;}}");
                code.AppendLine();
            }

            code.AppendLine();
            code.AppendLine("   }");
            code.AppendLine("}");

            var type = TypeService.ImplementDynamicType(code.ToString(), assemblyName);

            ComplexStructure autoCreateStructure = new ComplexStructure(type, null, null, null, ctx);

            autoCreateStructure.TypeId = expectedTypeId;    // reset type id because of object only properties

            // Register auto created type
            BinarySerializer.RegisterTolerantTypeMapping(autoCreateStructure);

            return(autoCreateStructure);
        }
Ejemplo n.º 22
0
 public Printer(IPetService petService, ICustomerService customerService, ITypeService typeService)
 {
     _petService = (PetService)petService;
     _petService.InitDatabaseData();
     _customerService = (CustomerService)customerService;
     _customerService.InitDatabaseDataCustomer();
     _typeService = (TypeService)typeService;
     _typeService.InitDatabaseDataType();
 }
Ejemplo n.º 23
0
 public ProjectsController()
 {
     if (Projects == null) { Projects = new ProjectService(); }
     if (Tasks == null) { Tasks = new MilestoneService(); }
     if (Timeframes == null) { Timeframes = new TimeframesService(); }
     if (Divisions == null) { Divisions = new DivisionService(); }
     if (Tyypes == null) { Tyypes = new TypeService(); }
     base.Initialize(new System.Web.Routing.RequestContext());
 }
Ejemplo n.º 24
0
 public IndexModel(SingleCardService singleCardService, SourceService sourceService, CardRulingService cardRulingService,
                   LessonService lessonService, TypeService typeService)
 {
     _singleCardService = singleCardService;
     _sourceService     = sourceService;
     _cardRulingService = cardRulingService;
     _lessonService     = lessonService;
     _cardTypeService   = typeService;
 }
Ejemplo n.º 25
0
        public void AjoutNotificationService(TypeService type, Message m)
        {
            Service service = bdd.Services.FirstOrDefault(s => s.Type == type);

            foreach (Collaborateur c in service.Collaborateurs)
            {
                AjoutNotif(c.Id, m);
            }
        }
Ejemplo n.º 26
0
        public void TestGetMethods()
        {
            var typeService = new TypeService();
            var methods     = typeService.GetMethod("BookService");

            Assert.AreEqual(methods.Count, 2);
            Assert.AreEqual("AddBook", methods[0]);
            Assert.AreEqual("SaveBatch", methods[1]);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Constructeur d'une donnée produit prenant en paramètre un produit
 /// </summary>
 /// <param name="produit">Produit dont on veut stocker les données au moment T</param>
 public DonneeProduit(Produit produit) : this()
 {
     Nom         = produit.Libelle;
     Commentaire = produit.Détails;
     PrixHT      = produit.PrixHT;
     Reduction   = produit.Reduction;
     TVA         = produit.TVA;
     Type        = produit.Type;
 }
Ejemplo n.º 28
0
        public async Task SetViewBag()
        {
            ShopService shopService = new ShopService();
            TypeService typeService = new TypeService();

            ViewBag.Shops = await shopService.GetShopsAsync();

            ViewBag.Types = await typeService.GetTypesAsync();
        }
Ejemplo n.º 29
0
        public override void ProcessOperand(TypeService service, MethodDef method, IList <Instruction> body, ref int index, TypeDef operand)
        {
            ScannedItem t = service.GetItem(operand.MDToken);

            if (t == null)
            {
                return;
            }
            body[index].Operand = new TypeSpecUser(t.CreateGenericTypeSig(service.GetItem(method.DeclaringType.MDToken)));
        }
Ejemplo n.º 30
0
        private static void TestCollectionInstanceCreation(Type interfaceType)
        {
            object createdType = TypeService.BuildInterfaceImplementationType(interfaceType.FullName);

            Assert.True(createdType != null && createdType is Type);

            Type type = (Type)createdType;

            Assert.True(interfaceType.IsAssignableFrom(type));
        }
Ejemplo n.º 31
0
        public void TestMethodCreateInheritInterfaceImplementation()
        {
            object createdType = TypeService.BuildInterfaceImplementationType(typeof(ITestInterfaceExtended).FullName);

            Assert.True(createdType != null && createdType is Type);

            Type type = (Type)createdType;

            Assert.True(type.GetInterface(typeof(ITestInterfaceExtended).FullName) != null);
        }
Ejemplo n.º 32
0
 public CarViewPage()
 {
     DataContext = new Context();
     Users = new UserService(DataContext);
     Cars = new CarService(DataContext);
     ImageCars = new ImageCarService(DataContext);
     Models = new ModelService(DataContext);
     Brands = new BrandService(DataContext);
     Types = new TypeService(DataContext);
     Security = new SecurityService(Users);
     CurrentUser = Security.GetCurrentUser();
 }
Ejemplo n.º 33
0
 public TasksController()
 {
     if (Events == null) { Events = new GlobalEventService(); }
     if (Types == null) { Types = new TypeService(); }
     base.Initialize(new System.Web.Routing.RequestContext());
 }