Пример #1
0
 public void AliasType(string alias, string typeName)
 {
     _log.Try(() =>
     {
         var type = new TypePath(typeName).FindType();
         _aliases.Add(alias, type);
     }).AndReportErrorAs(165, typeName, alias);
 }
Пример #2
0
 public void OverrideProfile(TypePath typePath, string instanceKey)
 {
     _pluginGraph.Log.WithType(typePath, "while trying to add an override for a Profile", pluginType =>
     {
         var instance = new ReferencedInstance(instanceKey);
         _pluginGraph.SetDefault(_lastProfile, pluginType, instance);
     });
 }
Пример #3
0
        public void can_parse_assembly_qualified_generics()
        {
            Type sampleGenericType = typeof (IConcept<AWidget>);
            string genericAssemblyQualifiedName = sampleGenericType.AssemblyQualifiedName;

            var path = new TypePath(genericAssemblyQualifiedName);
            path.FindType().ShouldEqual(sampleGenericType);
        }
Пример #4
0
 public void AddRegistry(string registryTypeName)
 {
     _pluginGraph.Log.Try(() =>
     {
         Type type = new TypePath(registryTypeName).FindType();
         var registry = (Registry) Activator.CreateInstance(type);
         _discoveredConfigurations.Add(registry);
     }).AndReportErrorAs(290, registryTypeName);
 }
Пример #5
0
        public void ParseAlias(XmlElement element)
        {
            var attribute = element.GetAttribute("Key");
            var typeName  = element.GetAttribute("Type");

            if (String.IsNullOrEmpty(attribute) || String.IsNullOrEmpty(typeName))
            {
                throw new MalformedAliasException(element.OuterXml);
            }

            _aliases[attribute] = new TypePath(typeName).FindType();
        }
Пример #6
0
        public void ParseInstanceElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));

            _builder.ConfigureFamily(pluginTypePath, family =>
            {
                InstanceMemento memento =
                    new XmlInstance(element);
                //family.AddInstance(memento);
                throw new NotImplementedException();
            });
        }
Пример #7
0
 public void ConfigureFamily(TypePath pluginTypePath, Action <PluginFamily> action)
 {
     try
     {
         Type         pluginType = pluginTypePath.FindType();
         PluginFamily family     = _pluginGraph.FindFamily(pluginType);
         action(family);
     }
     catch (Exception ex)
     {
         _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.AssemblyQualifiedName);
     }
 }
Пример #8
0
        private Plugin getPluginByType(PluginFamily family)
        {
            string pluggedTypeName = getPluggedType();

            if (string.IsNullOrEmpty(pluggedTypeName))
            {
                return(null);
            }

            Type pluggedType = new TypePath(pluggedTypeName).FindType();

            return(PluginCache.GetPlugin(pluggedType));
        }
Пример #9
0
        public void ParseDefaultElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));

            _builder.ConfigureFamily(pluginTypePath, family =>
            {
                InstanceScope scope = findScope(element);
                family.Lifecycle = Lifecycles.GetLifecycle(scope);
                throw new NotImplementedException();
                InstanceMemento memento = new XmlInstance(element);
                //family.AddDefaultMemento(memento);
            });
        }
Пример #10
0
        public void ParseDefaultElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));


            _builder.ConfigureFamily(pluginTypePath, family =>
            {
                InstanceScope scope = findScope(element);
                family.SetScopeTo(scope);

                InstanceMemento memento = _mementoCreator.CreateMemento(element);
                family.AddDefaultMemento(memento);
            });
        }
Пример #11
0
        public override AnnotationVisitor VisitLocalVariableAnnotation(int typeRef, TypePath
                                                                       typePath, Label[] start, Label[] end, int[] index, string descriptor, bool visible
                                                                       )
        {
            var type          = Type.GetType(descriptor);
            var remappedIndex = new int[index.Length];

            for (var i = 0; i < remappedIndex.Length; ++i)
            {
                remappedIndex[i] = Remap(index[i], type);
            }
            return(base.VisitLocalVariableAnnotation(typeRef, typePath, start, end, remappedIndex
                                                     , descriptor, visible));
        }
Пример #12
0
        public void ParseDefaultElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));


            _builder.ConfigureFamily(pluginTypePath, family => {
                var scope = findScope(element);
                family.SetScopeTo(scope);

                var memento  = ConfigurationParser.CreateMemento(element);
                var instance = memento.ToInstance(this, family.PluginType);
                family.SetDefault(instance);
            });
        }
Пример #13
0
        public Plugin PluginFor(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (name.Contains(","))
            {
                var pluggedType = new TypePath(name).FindType();
                return(new Plugin(pluggedType));
            }

            return(_aliases.Has(name) ?  new Plugin(_aliases[name]) : null);
        }
Пример #14
0
        public override AnnotationVisitor VisitTypeAnnotation(int typeRef, TypePath typePath
                                                              , string descriptor, bool visible)
        {
            CheckVisitEndNotCalled();
            var sort = new TypeReference(typeRef).GetSort();

            if (sort != TypeReference.Field)
            {
                throw new ArgumentException("Invalid type reference sort 0x" + sort.ToString("x8"));
            }
            CheckClassAdapter.CheckTypeRef(typeRef);
            CheckMethodAdapter.CheckDescriptor(OpcodesConstants.V1_5, descriptor, false);
            return(new CheckAnnotationAdapter(base.VisitTypeAnnotation(typeRef, typePath, descriptor
                                                                       , visible)));
        }
Пример #15
0
        public void Call_the_action_on_configure_family_if_the_pluginType_is_found()
        {
            var typePath = new TypePath(typeof(IGateway));

            var iWasCalled = false;
            var builder    = new GraphBuilder(new PluginGraph());

            builder.ConfigureFamily(typePath, f => {
                Assert.AreEqual(typeof(IGateway), f.PluginType);
                iWasCalled = true;
            });


            Assert.IsTrue(iWasCalled);
        }
Пример #16
0
        public override AnnotationVisitor VisitTypeAnnotation(int typeRef, TypePath typePath
                                                              , string descriptor, bool visible)
        {
            var typeAnnotation = new TypeAnnotationNode(typeRef, typePath, descriptor
                                                        );

            if (visible)
            {
                visibleTypeAnnotations = Util.Add(visibleTypeAnnotations, typeAnnotation);
            }
            else
            {
                invisibleTypeAnnotations = Util.Add(invisibleTypeAnnotations, typeAnnotation);
            }
            return(typeAnnotation);
        }
Пример #17
0
        private void createOverrideInstance(string fullName, XmlElement instanceElement, WriteOverride function,
                                            string profileName)
        {
            string          key     = Profile.InstanceKeyForProfile(profileName);
            InstanceMemento memento = _creator.CreateMemento(instanceElement);

            memento.InstanceKey = key;

            var familyPath = new TypePath(fullName);

            _graphBuilder.ConfigureFamily(familyPath, family =>
            {
                family.AddInstance(memento);
                function(fullName, key);
            });
        }
        private void createOverrideInstance(string fullName, XmlElement instanceElement, WriteOverride function,
            string profileName)
        {
            string key = Profile.InstanceKeyForProfile(profileName);
            InstanceMemento memento = new XmlInstance(instanceElement);
            memento.InstanceKey = key;

            var familyPath = new TypePath(fullName);

            _graphBuilder.ConfigureFamily(familyPath, family =>
            {
                throw new NotImplementedException();
                //family.AddInstance(memento);
                function(fullName, key);
            });
        }
Пример #19
0
 public void WithType(TypePath path, string context, Action <Type> action)
 {
     try
     {
         Type type = path.FindType();
         action(type);
     }
     catch (StructureMapException ex)
     {
         RegisterError(ex);
     }
     catch (Exception ex)
     {
         RegisterError(131, ex, path.AssemblyQualifiedName, context);
     }
 }
Пример #20
0
        public static bool GetSelectBy_sis_caminho(SYS_Sistema entity, TypePath type)
        {
            SYS_SistemaDAO dao = new SYS_SistemaDAO();

            if (type == TypePath.login)
            {
                return(dao.SelectBy_sis_caminho(entity));
            }
            else if (type == TypePath.logout)
            {
                return(dao.SelectBy_sis_caminhoLogout(entity));
            }
            else
            {
                return(false);
            }
        }
Пример #21
0
        public void ParseFamily(XmlElement familyElement)
        {
            TypePath typePath = TypePath.CreateFromXmlNode(familyElement);

            _builder.ConfigureFamily(typePath, family =>
            {
                family.DefaultInstanceKey =
                    familyElement.GetAttribute(DEFAULT_KEY_ATTRIBUTE);

                InstanceScope scope = findScope(familyElement);
                family.SetScopeTo(scope);

                attachMementoSource(family, familyElement);
                attachPlugins(family, familyElement);
                attachInterceptors(family, familyElement);
                attachInstances(family, familyElement, _builder);
            });
        }
Пример #22
0
        public override AnnotationVisitor VisitTryCatchAnnotation(int typeRef, TypePath typePath
                                                                  , string descriptor, bool visible)
        {
            var tryCatchBlock  = tryCatchBlocks[(typeRef & 0x00FFFF00) >> 8];
            var typeAnnotation = new TypeAnnotationNode(typeRef, typePath, descriptor
                                                        );

            if (visible)
            {
                tryCatchBlock.visibleTypeAnnotations = Util.Add(tryCatchBlock.visibleTypeAnnotations
                                                                , typeAnnotation);
            }
            else
            {
                tryCatchBlock.invisibleTypeAnnotations = Util.Add(tryCatchBlock.invisibleTypeAnnotations
                                                                  , typeAnnotation);
            }
            return(typeAnnotation);
        }
Пример #23
0
        public override AnnotationVisitor VisitLocalVariableAnnotation(int typeRef, TypePath
                                                                       typePath, Label[] start, Label[] end, int[] index, string descriptor, bool visible
                                                                       )
        {
            var localVariableAnnotation = new LocalVariableAnnotationNode
                                              (typeRef, typePath, GetLabelNodes(start), GetLabelNodes(end), index, descriptor);

            if (visible)
            {
                visibleLocalVariableAnnotations = Util.Add(visibleLocalVariableAnnotations, localVariableAnnotation
                                                           );
            }
            else
            {
                invisibleLocalVariableAnnotations = Util.Add(invisibleLocalVariableAnnotations, localVariableAnnotation
                                                             );
            }
            return(localVariableAnnotation);
        }
Пример #24
0
        protected override Expression VisitMemberAccess(MemberExpression memberExp)
        {
            var type = (memberExp.Member as PropertyInfo).PropertyType;

            if (!type.IsGenericType)
            {
                TypePath.Add(memberExp.Member.Name);
                TypePath.Add(type.Name);
            }
            else
            {
                TypePath.Add(memberExp.Member.Name);
                TypePath.Add(type.GetGenericArguments().First().Name);
            }

            Visit(memberExp.Expression);

            return(memberExp);
        }
Пример #25
0
        private void attachPlugin(XmlElement pluginElement, PluginFamily family)
        {
            TypePath pluginPath  = TypePath.CreateFromXmlNode(pluginElement);
            string   concreteKey = pluginElement.GetAttribute(CONCRETE_KEY_ATTRIBUTE);

            string context = "creating a Plugin for " + family.PluginType.AssemblyQualifiedName;

            _builder.WithType(pluginPath, context, pluggedType =>
            {
                if (concreteKey == string.Empty)
                {
                    throw new StructureMapException(112, pluggedType.FullName);
                }

                Plugin plugin = family.AddPlugin(pluggedType, concreteKey);

                pluginElement.ForTextInChild("Setter/@Name").Do(prop => plugin.Setters.MarkSetterAsMandatory(prop));
            });
        }
        public void SetUp()
        {
            var builder = new GraphBuilder(new Registry[0]);

            _graph = builder.PluginGraph;

            _parser =
                new FamilyParser(builder,
                                 new XmlMementoCreator(XmlMementoStyle.NodeNormalized, XmlConstants.TYPE_ATTRIBUTE,
                                                       XmlConstants.ATTRIBUTE_STYLE));

            _document = new XmlDocument();
            _document.LoadXml("<PluginFamily />");
            _familyElement = _document.DocumentElement;

            thePluginType = typeof(IGateway);

            TypePath.WriteTypePathToXmlElement(thePluginType, _familyElement);
        }
Пример #27
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="path">Путь</param>
 /// <param name="typePath">Тип</param>
 /// <param name="status">Статус</param>
 public UploadFile(string path, TypePath typePath, string status)
 {
     this.Path     = path;
     this.TypePath = typePath;
     this.Status   = status;
 }
Пример #28
0
 public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
 {
     try
     {
         Type pluginType = pluginTypePath.FindType();
         PluginFamily family = _pluginGraph.FindFamily(pluginType);
         action(family);
     }
     catch (Exception ex)
     {
         _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.AssemblyQualifiedName);
     }
 }
Пример #29
0
        public override AnnotationVisitor VisitTypeAnnotationExperimental(int typeRef, TypePath
                                                                          typePath, string descriptor, bool visible)
        {
            var annotationVisitor = base.VisitTypeAnnotationExperimental(typeRef
                                                                         , typePath, remapper.MapDesc(descriptor), visible);

            return(annotationVisitor == null
                ? null
                : CreateAnnotationRemapper(annotationVisitor
                                           ));
        }
Пример #30
0
 private string BuildEntityTypePath()
 {
     return(string.Join("-", TypePath.Select(name => name).ToArray()));
 }
Пример #31
0
 public void CanBuildTypeCreatedFromType()
 {
     var path = new TypePath(GetType());
     path.FindType();
 }
Пример #32
0
        /// <summary>
        /// UploadAndResizeImage
        /// </summary>
        /// <param name="fileContent"></param>
        /// <param name="filename"></param>
        /// <param name="width"></param>
        /// <param name="typePath"></param>
        /// <returns></returns>
        public static bool UploadAndResizeImage(string fileContent, string filename, int width, TypePath typePath)
        {

            //Convert string to byte[]
            var imageBytes = Convert.FromBase64String(fileContent);

            //Convert and resize image
            var imageNewBytes = ResizeImage(new MemoryStream(imageBytes), width);

            // instance a memory stream and pass the byte array to its constructor
            var memoryStream = new MemoryStream(imageNewBytes);

            // initialize ftp 
            var ftp = new Ftp(FtpHost, FtpUserName, FtpPassword);

            var dir = "";

            switch (typePath)
            {
                case TypePath.Avatar:
                    dir = DirectoryPathAvatar;
                    break;
                case TypePath.Post:
                    dir = DirectoryPathPost;
                    break;
                case TypePath.Cover:
                    dir = DirectoryPathCoverImage;
                    break;
                default:
                    dir = DirectoryPathPost;
                    break;

            }

            var fileDir = dir + "/" + filename;

            var upload = ftp.Upload(fileDir, memoryStream);

            // clean up
            memoryStream.Close();

            // return true if we made it this far
            return upload;

        }
Пример #33
0
        public override AnnotationVisitor VisitTypeAnnotationExperimental(int typeRef, TypePath
                                                                          typePath, string descriptor, bool visible)
        {
            var annotationPrinter = printerExperimental.VisitRecordComponentTypeAnnotationExperimental
                                        (typeRef, typePath, descriptor, visible);

            return(new TraceAnnotationVisitor(base.VisitTypeAnnotationExperimental(typeRef, typePath
                                                                                   , descriptor, visible), annotationPrinter));
        }
Пример #34
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="path">Путь</param>
 /// <param name="typePath">Тип</param>
 public UploadFile(string path, TypePath typePath) : this(path, typePath, "Ожидает")
 {
 }
Пример #35
0
 public void WithType(TypePath path, string context, Action <Type> action)
 {
     _pluginGraph.Log.WithType(path, context, action);
 }
Пример #36
0
 public static void WithType(this GraphLog log, TypePath path, string context, Action<Type> action)
 {
     try
     {
         Type type = path.FindType();
         action(type);
     }
     catch (StructureMapException ex)
     {
         log.RegisterError(ex);
     }
     catch (Exception ex)
     {
         log.RegisterError(131, ex, path.AssemblyQualifiedName, context);
     }
 }
Пример #37
0
        public void CanBuildTypeCreatedFromType()
        {
            var path = new TypePath(GetType());

            path.FindType();
        }
Пример #38
0
 /// <summary>
 ///     Constructs a new
 ///     <see cref="LocalVariableAnnotationNode" />
 ///     .
 ///     <i>
 ///         Subclasses must not use this
 ///         constructor
 ///     </i>
 ///     . Instead, they must use the
 ///     <see
 ///         cref="LocalVariableAnnotationNode(int, Org.Objectweb.Asm.TypePath, LabelNode[], LabelNode[], int[], string)
 ///     " />
 ///     version.
 /// </summary>
 /// <param name="typeRef">
 ///     a reference to the annotated type. See
 ///     <see cref="Org.Objectweb.Asm.TypeReference" />
 ///     .
 /// </param>
 /// <param name="typePath">
 ///     the path to the annotated type argument, wildcard bound, array element type, or
 ///     static inner type within 'typeRef'. May be
 ///     <literal>null</literal>
 ///     if the annotation targets
 ///     'typeRef' as a whole.
 /// </param>
 /// <param name="start">
 ///     the fist instructions corresponding to the continuous ranges that make the scope
 ///     of this local variable (inclusive).
 /// </param>
 /// <param name="end">
 ///     the last instructions corresponding to the continuous ranges that make the scope of
 ///     this local variable (exclusive). This array must have the same size as the 'start' array.
 /// </param>
 /// <param name="index">
 ///     the local variable's index in each range. This array must have the same size as
 ///     the 'start' array.
 /// </param>
 /// <param name="descriptor">the class descriptor of the annotation class.</param>
 public LocalVariableAnnotationNode(int typeRef, TypePath typePath, LabelNode[] start
                                    , LabelNode[] end, int[] index, string descriptor)
     : this(VisitorAsmApiVersion.Asm7, typeRef, typePath, start, end, index, descriptor)
 {
 }
Пример #39
0
        /// <summary>
        /// Upload file
        /// </summary>
        /// <param name="fileContent"></param>
        /// <param name="filename"></param>
        /// <param name="extentionFile"></param>
        /// <param name="typePath"></param>
        /// <returns></returns>
        public static bool UploadFile(string fileContent, string filename, TypePath typePath)
        {
            //Convert string to byte[]
            var imageBytes = Convert.FromBase64String(fileContent);

            // instance a memory stream and pass the byte array to its constructor
            var memoryStream = new MemoryStream(imageBytes);

            var dir = "";

            switch (typePath)
            {
                case TypePath.Avatar:
                    dir = Config.DirectoryPathAvatar;
                    break;
                case TypePath.Product:
                    dir = Config.DirectoryPathProductImage;
                    break;
                case TypePath.Banner:
                    dir = Config.DirectoryPathBannerImage;
                    break;
                default:
                    dir = Config.DirectoryPathProductImage;
                    break;

            }

            var fileDir = dir + "/" + filename;

            using (var fileStream = new FileStream(HttpContext.Current.Server.MapPath("~/") + fileDir, FileMode.CreateNew, FileAccess.ReadWrite))
            {
                var buffer = new byte[2048];

                var byteSave = memoryStream.Read(buffer, 0, 2048);

                while (byteSave != 0)
                {
                    fileStream.Write(buffer, 0, byteSave);
                    byteSave = memoryStream.Read(buffer, 0, 2048);
                }
                //fileStream.Write(memoryStream.ToArray(), 0, 1024);
            }

            // clean up
            memoryStream.Close();

            // return true if we made it this far
            return true;
        }