Example #1
0
        /// <summary>
        /// Assembly has been registered (every assembly has to be registered exactly one if loaded).
        /// </summary>
        /// <param name="assembly">Registered assembly.</param>
        private void _onAssemblyRegistered(AssemblyProvider assembly)
        {
            //attach after action to outer scope of assembly
            after_reloadAssembly(assembly);
            startTransaction("Registering assembly: " + assembly.Name);

            //hook component handlers
            assembly.ComponentAdded   += (compInfo) => _onComponentAdded(assembly, compInfo);
            assembly.ComponentRemoved += (compInfo) => _onComponentRemoved(assembly, compInfo);

            var services = new TypeServices(assembly, this);

            //this assign causes assembly initialization (loading references)
            assembly.TypeServices = services;

            try
            {
                if (AssemblyAdded != null)
                {
                    AssemblyAdded(assembly);
                }
            }
            finally
            {
                commitTransaction();
            }

            //assembly has to be be initialized only if it is a Root assembly or Root's assembly reference by caller
        }
Example #2
0
        /// <summary>
        /// Parses typeof representation.
        /// </summary>
        /// <param name="valueRepresentation">The value representation.</param>
        /// <param name="contextType">Type of the context.</param>
        /// <param name="contextElement">The context element.</param>
        /// <returns>Descriptor of type if available, <c>null</c> otherwise.</returns>
        private TypeDescriptor parseType(ref string valueRepresentation, TypeDescriptor contextType, CodeElement contextElement)
        {
            var typePrefix = "typeof(";

            if (valueRepresentation.StartsWith(typePrefix))
            {
                valueRepresentation = valueRepresentation.Substring(typePrefix.Length).Replace(")", "");
                valueRepresentation = TranslatePath(valueRepresentation);

                //find  type
                var implicitNamespaces = GetImplicitNamespaces(contextType);

                var namespaces = implicitNamespaces.Concat(GetNamespaces(contextElement));
                foreach (var ns in namespaces)
                {
                    var prefix = ns == "" ? "" : ns + ".";

                    var descriptor = TypeDescriptor.Create(prefix + valueRepresentation);
                    if (TypeServices.GetChain(descriptor) != null)
                    {
                        return(descriptor);
                    }
                }

                return(TypeDescriptor.Create(valueRepresentation));
            }

            return(null);
        }
Example #3
0
        public List <TypeServices> ListarTypeServices()
        {
            List <TypeServices> _Lista_TypeServices = new List <TypeServices>();
            TypeServices        services            = null;

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["Connect_database"].ToString()))
            {
                try
                {
                    cn.Open();
                    SqlCommand command = new SqlCommand("uspListTypeServices", cn);
                    command.CommandType = CommandType.StoredProcedure;
                    SqlDataReader sqlData = command.ExecuteReader();

                    if (sqlData.HasRows)
                    {
                        while (sqlData.Read())
                        {
                            services = new TypeServices();
                            services.TypeServicesId    = int.Parse(sqlData["TypeServicesId"].ToString());
                            services.Name_TypeServices = sqlData["Name_TypeServices"].ToString();
                            _Lista_TypeServices.Add(services);
                        }
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    cn.Close();
                }
            }
            return(_Lista_TypeServices);
        }
Example #4
0
        /// <summary>
        /// Handler called for every invalidated name.
        /// </summary>
        /// <param name="name">Invalidated name.</param>
        private void onNameInvalidation(string name)
        {
            if (name == null)
            {
                return;
            }

            //get components defined in current assembly
            var components = TypeServices.GetComponents(this).ToArray();

            //check for components that may be invalidated.
            foreach (var component in components)
            {
                foreach (var componentName in component.DependencyNames)
                {
                    if (componentName.StartsWith(name) || name.EndsWith(componentName))
                    {
                        //component is invalidated
                        var componentClass = GetTypeNode(component.ComponentType.TypeName) as CodeClass;
                        if (componentClass != null)
                        {
                            _toDiscover.Add(componentClass);
                            ComponentRemoveDiscovered(component.ComponentType.TypeName);
                        }

                        break;
                    }
                }
            }

            if (_toDiscover.Count > 0)
            {
                requireComponentDiscovering();
            }
        }
Example #5
0
        public ParsedGenerator(TypeMethodInfo info, string sourceCode, IEnumerable <string> genericParameters, TypeServices services)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (sourceCode == null)
            {
                throw new ArgumentNullException("sourceCode");
            }

            if (genericParameters == null)
            {
                throw new ArgumentNullException("genericParameters");
            }

            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            SourceCode         = sourceCode;
            Method             = info;
            _services          = services;
            _genericParameters = genericParameters;
        }
        /// <summary>
        /// Resolves the full path.
        /// </summary>
        /// <param name="relativePath">The relative path.</param>
        /// <param name="services">The services.</param>
        /// <returns>System.String.</returns>
        public static string ResolveFullPath(string relativePath, TypeServices services)
        {
            var codeBase = services.CodeBaseFullPath;

            var combined = Path.Combine(codeBase, relativePath);
            var fullPath = Path.GetFullPath(combined);

            return(fullPath);
        }
Example #7
0
        public double GetTypeMultiplicator(@Type type)
        {
            int eff = TypeServices.GetTypeEfficience(this.Type1, type);

            if (Type2.HasValue)
            {
                eff = eff * TypeServices.GetTypeEfficience(this.Type2.Value, type);
            }
            return(eff / 10000);
        }
        public ActionResult Create(TypeServicesViewModel model, string redirectUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            TypeServices type = model.Map <TypeServices>();

            Types.Create(type);

            return(RedirectToLocal(redirectUrl));
        }
Example #9
0
        /// <summary>
        /// Create <see cref="InheritanceChain" /> enumeration from given typeNodes.
        /// </summary>
        /// <param name="typeNodes">The type nodes.</param>
        /// <returns>IEnumerable&lt;InheritanceChain&gt;.</returns>
        private IEnumerable <InheritanceChain> createInheritanceChains(CodeElements typeNodes)
        {
            var chains = new List <InheritanceChain>();

            foreach (CodeElement typeNode in typeNodes)
            {
                var descriptor = InfoBuilder.CreateDescriptor(typeNode);
                var chain      = TypeServices.GetChain(descriptor);
                chains.Add(chain);
            }

            return(chains);
        }
        public static T ToObject <T>(TableRow tableRow)
        {
            PropertyInfo[] propertyInfos = typeof(T).GetProperties();
            T target = Activator.CreateInstance <T>();

            foreach (PropertyInfo pi in propertyInfos)
            {
                var    piType = pi.PropertyType;
                var    piName = pi.Name;
                object value  = TypeServices.ChangeType(tableRow[piName], piType);
                pi.SetValue(target, value);
            }
            return(target);
        }
        public override InheritanceChain GetInheritanceChain(PathInfo typePath)
        {
            //informace o dědičnosti poskytujeme pouze
            //pro náš definovaný typ
            if (typePath.Signature == _declaringType.TypeName)
            {
                //definovaný typ je potomkem typu object
                InheritanceChain baseType = TypeServices.GetChain(TypeDescriptor.ObjectInfo);
                return(TypeServices.CreateChain(_declaringType, new[] { baseType }));
            }

            //dotaz se týkal typu, který nedefinujeme
            return(null);
        }
Example #12
0
        /// <summary>
        /// Initialize instance of <see cref="ComponentSearcher"/>
        /// </summary>
        /// <param name="services"><see cref="TypeServices"/> used for resolving types' inheritance</param>
        /// <param name="assembly">Assembly using current searcher</param>
        internal ComponentSearcher(VsProjectAssembly assembly, TypeServices services)
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _services = services;
            _assembly = assembly;
        }
Example #13
0
        /// <summary>
        /// Gets inheritance chain for type described by given path.
        /// </summary>
        /// <param name="typePath">The type path.</param>
        /// <returns>InheritanceChain.</returns>
        public override InheritanceChain GetInheritanceChain(PathInfo typePath)
        {
            requireBuilded();

            var descriptor = TypeDescriptor.Create(typePath.Name);

            if (!_knownInheritance.ContainsKey(descriptor))
            {
                //we handle only contained types
                return(null);
            }

            //inheritance according to known definitions
            return(TypeServices.CreateChain(descriptor, new[] { TypeServices.GetChain(_knownInheritance[descriptor]) }));
        }
Example #14
0
        /// <summary>
        /// Initializes the specified containing assembly.
        /// </summary>
        /// <param name="containingAssembly">The containing assembly.</param>
        /// <param name="typeServices">The type services.</param>
        /// <exception cref="System.ArgumentNullException">
        /// runtimeAssembly
        /// or
        /// typeServices
        /// </exception>
        internal void Initialize(RuntimeAssembly containingAssembly, TypeServices typeServices)
        {
            if (containingAssembly == null)
            {
                throw new ArgumentNullException("runtimeAssembly");
            }

            if (typeServices == null)
            {
                throw new ArgumentNullException("typeServices");
            }

            Services           = typeServices;
            ContainingAssembly = containingAssembly;
        }
Example #15
0
        public CILGenerator(TypeMethodInfo info, CILMethod source, TypeServices services)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            Source    = source;
            Info      = info;
            _services = services;
        }
Example #16
0
        internal CILGenerator(MethodDefinition method, TypeMethodInfo methodInfo, TypeServices services)
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            //method can be null - is used for default implementations

            /*if(method==null)
             *  throw new ArgumentNullException("method");*/

            _method   = method;
            _info     = methodInfo;
            _services = services;
        }
Example #17
0
        /// <summary>
        /// Hook handler that will recieve change events in project.
        /// </summary>
        private void hookChangesHandler()
        {
            try
            {
                VS.RegisterElementAdd(_assemblyProject, onAdd);
                VS.RegisterElementRemove(_assemblyProject, onRemove);
                VS.RegisterElementChange(_assemblyProject, onChange);
                _referenceEvents.ReferenceAdded   += (r) => addReference(r as Reference3);
                _referenceEvents.ReferenceRemoved += (r) => removeReference(r as Reference3);

                TypeServices.RegisterInvalidationHandler(onNameInvalidation);
            }
            catch (Exception ex)
            {
                VS.LogException(ex, "Hooking changes handlers in assembly {0} failed", Name);
            }
        }
Example #18
0
        /// <summary>
        /// Create <see cref="InheritanceChain" /> from given typeNode.
        /// </summary>
        /// <param name="typeNode">Type node which inheritance chain will be created.</param>
        /// <returns>Created <see cref="InheritanceChain" />.</returns>
        private InheritanceChain createInheritanceChain(CodeType typeNode)
        {
            var subChains = new List <InheritanceChain>();

            var baseChains = createInheritanceChains(typeNode.Bases);

            subChains.AddRange(baseChains);

            var classNode = typeNode as CodeClass;

            if (classNode != null)
            {
                var interfaceChains = createInheritanceChains(classNode.ImplementedInterfaces);
                subChains.AddRange(interfaceChains);
            }

            var typeDescriptor = InfoBuilder.CreateDescriptor(typeNode);

            return(TypeServices.CreateChain(typeDescriptor, subChains));
        }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompilationContext"/> class.
        /// </summary>
        /// <param name="emitter">The emitter.</param>
        /// <param name="source">The source.</param>
        /// <param name="services">The services.</param>
        /// <exception cref="System.ArgumentNullException">
        /// emitter
        /// or
        /// source
        /// or
        /// services
        /// </exception>
        internal CompilationContext(EmitterBase emitter, Source source, TypeServices services)
        {
            if (emitter == null)
            {
                throw new ArgumentNullException("emitter");
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            Emitter  = emitter;
            Source   = source;
            Services = services;
        }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompositionContext" /> class.
 /// </summary>
 /// <param name="services">The services from <see cref="MEFEditor.TypeSystem"/>.</param>
 /// <param name="context">The context of analysis.</param>
 internal CompositionContext(TypeServices services, AnalyzingContext context)
 {
     _services = services;
     _context  = context;
 }
 public void SetService(TypeServices types)
 {
     this.Service = types.GetHashCode();
 }
Example #22
0
        /// <summary>
        /// Generates the instructions of given method.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="info">The method information.</param>
        /// <param name="emitter">The emitter where instructions will be generated.</param>
        /// <param name="services">The services from <see cref="MEFEditor.TypeSystem"/>.</param>
        public static void GenerateInstructions(CILMethod method, TypeMethodInfo info, EmitterBase emitter, TypeServices services)
        {
            Console.WriteLine(method.ToString());

            var compiler = new Compiler(method, info, emitter, services);

            compiler.generateInstructions();

            //Console.WriteLine(emitter.GetEmittedInstructions().Code);
        }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Compiler"/> class.
 /// </summary>
 /// <param name="method">The method.</param>
 /// <param name="methodInfo">The method information.</param>
 /// <param name="emitter">The emitter.</param>
 /// <param name="services">The services.</param>
 private Compiler(CILMethod method, TypeMethodInfo methodInfo, EmitterBase emitter, TypeServices services)
 {
     _method     = method;
     _methodInfo = methodInfo;
     E           = emitter;
 }
        private static T Instance <T>(TableRow row, MappingBehaviour mappingBehaviour) where T : class, new()
        {
            Type type = typeof(T);

            if (!TypeMapping.ContainsType(type))
            {
                TypeMapping.RegisterType <T>();
            }

            var container = TypeMapping.GetTypeInfosContainer(type);

            switch (mappingBehaviour)
            {
            case MappingBehaviour.Loose:
                break;

            case MappingBehaviour.Strict:
                StringBuilder sb = new StringBuilder();
                var           headersExceptPropertyNames = row.Keys.Except(container.PropertyNames).ToArray();
                if (headersExceptPropertyNames.Any())
                {
                    sb.AppendLine();
                    sb.AppendFormat(
                        "** The following column(s) are present in the table row but not the target type '{0}': {1}",
                        type.Name, headersExceptPropertyNames.JoinStrings());
                }
                var propertyNamesExceptHeaders = container.PropertyNames.Except(row.Keys).ToArray();
                if (propertyNamesExceptHeaders.Any())
                {
                    sb.AppendLine();
                    sb.AppendFormat(
                        "** The following column(s) are present in the target type '{0}' but not in the table row: {1}",
                        type.Name, propertyNamesExceptHeaders.JoinStrings());
                }
                string message = sb.ToString();
                if (!string.IsNullOrWhiteSpace(message))
                {
                    throw new MappingException(message);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(string.Format("Mapping behaviour '{0}' not managed", mappingBehaviour));
            }
            var instance = Activator.CreateInstance <T>();

            foreach (PropertyInfo propertyInfo in container.PropertyInfos)
            {
                object value = TypeServices.ChangeType(row[propertyInfo.Name], propertyInfo.PropertyType);
                propertyInfo.SetValue(instance, value);
            }

            //var instance = TypeServices.Resolve<T>();
            //foreach (PropertyInfo propertyInfo in container.AllPropertyInfos)
            //{
            //    object value = TypeServices.ChangeType(row[propertyInfo.Name], propertyInfo.PropertyType);
            //    propertyInfo.SetValue(instance, value);
            //}

            return(instance);
        }