GetCustomAttributes() публичный Метод

Retrieves a collection of custom attributes that are applied to a specified assembly.
public GetCustomAttributes ( ) : object[]
Результат object[]
Пример #1
0
        public static string GetCopyrightString(Assembly assembly, string prefix = "Copyright", bool appendCompanyName = true)
        {
            var str = "";

            var copyrightAttributes = assembly.GetCustomAttributes(typeof (AssemblyCopyrightAttribute), true);
            if (copyrightAttributes.Length > 0)
            {
                var copyrightString = ((AssemblyCopyrightAttribute) copyrightAttributes[0]).Copyright;

                if (!string.IsNullOrEmpty(copyrightString))
                    str = copyrightString;
            }

            if (appendCompanyName)
            {
                string companyString = null;

                var companyAttributes = assembly.GetCustomAttributes(typeof (AssemblyCompanyAttribute), true);
                if (companyAttributes.Length > 0)
                    companyString = ((AssemblyCompanyAttribute) companyAttributes[0]).Company;

                if (!string.IsNullOrEmpty(companyString) && !str.EndsWith(companyString))
                {
                    str += string.Format(" {0}", companyString);
                }
            }

            if (!str.StartsWith(prefix))
                str = str.Insert(0, string.Format("{0} ", prefix));

            return str;
        }
Пример #2
0
        public ModuleInfo(Assembly _asm)
        {
            _name = _asm.GetName().Name;
            _version = DepVersion.VersionParse (_asm.GetName().Version.ToString ());

            ModuleDependencyAttribute _depAttr = ((ModuleDependencyAttribute)(_asm.GetCustomAttributes (typeof (ModuleDependencyAttribute), false)[0]));

            if (_depAttr != null) {
                DepLexer _lexer = new DepLexer (new StringReader (_depAttr.DepString));
                DepParser _parser = new DepParser (_lexer);

                // woot...lets do this!
                _dependencies = new DepNode ();

                _parser.expr (_dependencies);
            } else
                _dependencies = null;

            ModuleRoleAttribute _roleAttr = ((ModuleRoleAttribute)(_asm.GetCustomAttributes (typeof (ModuleRoleAttribute), false)[0]));

            if (_roleAttr != null) {
                _roles = _roleAttr.Roles;
            } else
                throw new ModuleInfoException (string.Format ("The module {0} has no defined roles, and is not a valid NModule module.", _asm.GetName ().Name));

            _owner = _asm;
        }
Пример #3
0
		static string GetAssemblyInfo (Assembly a)
		{
			object[] attrs;
			StringBuilder sb;

			string app_name;
			string evidence_str;
			string version;

			attrs = a.GetCustomAttributes (typeof (AssemblyProductAttribute), false);
			if (attrs != null && attrs.Length > 0)
				app_name = ((AssemblyProductAttribute)attrs[0]).Product;
			else
				app_name = AppDomain.CurrentDomain.FriendlyName;

			sb = new StringBuilder();

			sb.Append ("evidencehere");

			evidence_str = sb.ToString();

			attrs = a.GetCustomAttributes (typeof (AssemblyVersionAttribute), false);
			if (attrs != null && attrs.Length > 0)
				version = ((AssemblyVersionAttribute)attrs[0]).Version;
			else
				version = "1.0.0.0" /* XXX */;


			return Path.Combine (String.Format ("{0}_{1}", app_name, evidence_str), version);
		}
Пример #4
0
 public Plugin(Assembly Assembly)
 {
     Name = Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false).OfType<AssemblyTitleAttribute>().FirstOrDefault().Title;
     Description = Assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false).OfType<AssemblyDescriptionAttribute>().FirstOrDefault().Description;
     try
     {
         Version = Assembly.GetCustomAttributes(typeof(AssemblyVersionAttribute), false).OfType<AssemblyVersionAttribute>().FirstOrDefault().Version;
     }
     catch
     {
         Version = null;
     }
     Type[] tt = Assembly.GetExportedTypes();
     List<Type> fe = new List<Type>();
     List<Type> ce = new List<Type>();
     List<Type> pe = new List<Type>();
     foreach (var t in tt)
     {
         if (!t.IsClass) continue;
         if (t.IsSubclassOf(typeof(EFEPlugin)))
         {
             Initializer = (EFEPlugin)t.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
             continue;
         }
         var v = t.GetInterfaces();
         if (v.Length != 0 && t.GetInterfaces()[0].Name == "FileFormatBase") fe.Add(t);
         else if (v.Length != 0 && t.GetInterfaces()[0].Name == "CompressionFormatBase") ce.Add(t);
         else if (v.Length != 0 && t.GetInterfaces()[0].Name == "ProjectBase") pe.Add(t);
     }
     FileFormatTypes = fe.ToArray();
     CompressionTypes = ce.ToArray();
     ProjectTypes = pe.ToArray();
 }
Пример #5
0
        public AboutBSM(Icon icon, Assembly a)
        {
            InitializeComponent();

            if (icon != null) this.Icon = icon;

            if (a != null) {
                software_title.Text = ((AssemblyTitleAttribute)a.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]).Title;
                version.Text = a.GetName().Version.ToString();
                copyright.Text = ((AssemblyCopyrightAttribute)a.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright;

                Assembly b = Assembly.GetAssembly(this.GetType());
                library_title.Text = ((AssemblyTitleAttribute)b.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]).Title;
                library_version.Text = b.GetName().Version.ToString();
                library_copyright.Text = ((AssemblyCopyrightAttribute)b.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright;

                Assembly dll = Assembly.GetAssembly(typeof(BrawlLib.StringTable));
                brawllib.Text = "Using " +
                    ((AssemblyTitleAttribute)dll.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]).Title + "\r\n" +
                    ((AssemblyCopyrightAttribute)dll.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright;

                textBox1.Text = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n" +
                "\r\n" +
                "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n" +
                "\r\n" +
                "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.";
            }
        }
Пример #6
0
 public AssemblyPropertyHelper(Assembly asm)
 {
     var attributes = asm.GetCustomAttributes(typeof (AssemblyProductAttribute), false);
     if (attributes.Length > 0)
         _product = (AssemblyProductAttribute) attributes[0];
     attributes = asm.GetCustomAttributes(typeof (AssemblyCompanyAttribute), false);
     if (attributes.Length > 0)
         _company = (AssemblyCompanyAttribute) attributes[0];
     attributes = asm.GetCustomAttributes(typeof (AssemblyCopyrightAttribute), false);
     if (attributes.Length > 0)
         _copyright = (AssemblyCopyrightAttribute) attributes[0];
     attributes = asm.GetCustomAttributes(typeof (AssemblyDescriptionAttribute), false);
     if (attributes.Length > 0)
         _description = (AssemblyDescriptionAttribute) attributes[0];
 }
Пример #7
0
 private static IEnumerable<string> GetVersionOptions(Assembly assembly)
 {
     yield return assembly
         .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)
         .OfType<AssemblyInformationalVersionAttribute>()
         .Select(a => a.InformationalVersion).FirstOrDefault();
     yield return assembly
         .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
         .OfType<AssemblyFileVersionAttribute>()
         .Select(a => a.Version).FirstOrDefault();
     yield return assembly
         .GetName()
         .Version
         .ToString();
 }
Пример #8
0
        public static System.Type GetImplemetationType(Assembly assembly, Type interfaceType, Type assemblyAttribute, bool searchFromAllExportedType)
        {
            if (null == assembly)
                return null;

            object[] attributes = assembly.GetCustomAttributes(assemblyAttribute, true);
            if (null != attributes && attributes.Length > 0 && assemblyAttribute.IsAssignableFrom(attributes[0].GetType()))
            {
                PropertyInfo prop = assemblyAttribute.GetProperty("Type");
                Type t = prop.GetValue(attributes[0], null) as Type;
                if (null != t && interfaceType.IsAssignableFrom(t))
                    return t;
            }

            if (!searchFromAllExportedType)
                return null;

            //Couldn't get interfaceType via assemblyAttribute,
            //iterate  through all exported types and checkif there is a
            //interfaceType implementation.
            //
            Type[] types = assembly.GetExportedTypes();
            foreach (var item in types)
            {
                if (!item.IsAbstract && !item.IsInterface && interfaceType.IsAssignableFrom(item))
                    return item;
            }

            return null;
        }
        public static string GetModuleName(Assembly assm)
        {
            foreach (ModuleAttribute attrib in assm.GetCustomAttributes(typeof(ModuleAttribute), false))
                return attrib.Name;

            return null;
        }
Пример #10
0
		/// <summary>
		///   Determines whether this assembly has internals visible to dynamic proxy.
		/// </summary>
		/// <param name = "asm">The assembly to inspect.</param>
		public static bool IsInternalToDynamicProxy(Assembly asm)
		{
			using (var locker = internalsToDynProxyLock.ForReadingUpgradeable())
			{
				if (internalsToDynProxy.ContainsKey(asm))
				{
					return internalsToDynProxy[asm];
				}

				locker.Upgrade();

				if (internalsToDynProxy.ContainsKey(asm))
				{
					return internalsToDynProxy[asm];
				}

				var atts = (InternalsVisibleToAttribute[])
				           asm.GetCustomAttributes(typeof(InternalsVisibleToAttribute), false);

				var found = false;

				foreach (var internals in atts)
				{
					if (internals.AssemblyName.Contains(ModuleScope.DEFAULT_ASSEMBLY_NAME))
					{
						found = true;
						break;
					}
				}

				internalsToDynProxy.Add(asm, found);

				return found;
			}
		}
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AboutViewModel"/> class.
        /// </summary>
        /// <param name="a">
        /// An assembly.
        /// </param>
        public AboutViewModel(Assembly a)
        {
            this.SystemInfoText = "System Info...";
            this.CopyReportText = "Copy report";

            if (a == null)
            {
                throw new InvalidOperationException();
            }

            if (a.Location == null)
            {
                throw new InvalidOperationException();
            }

            this.FileVersionInfo = FileVersionInfo.GetVersionInfo(a.Location);
            this.FileInfo = new FileInfo(this.FileVersionInfo.FileName);

            var va = (AssemblyVersionAttribute[])a.GetCustomAttributes(typeof(AssemblyVersionAttribute), true);
            if (va != null && va.Length > 0)
            {
                this.AssemblyVersion = va[0].Version;
            }

            comments = this.FileVersionInfo.Comments;
        }
Пример #12
0
 /// <summary>
 /// Extracts an assembly description (usually created by Visual Studio?)
 /// </summary>
 /// <returns></returns>
 public static string AssemblyDescription(Assembly ass)
 {
     // Get all Description attributes on this assembly
     object[] attributes = ass.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
     // If there aren't any Description attributes, return an empty string. If there is a Description attribute, return its value.
     return (attributes.Length == 0) ? "" : ((AssemblyDescriptionAttribute)attributes[0]).Description;
 }
Пример #13
0
        private bool IsRelease(Assembly assembly)
        {
            object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), false);

            if (attributes.Length == 0)
            {
                //Console.WriteLine(String.Format("{0} is a RELEASE Build....", assembly.FullName));
                return true;
            }
            foreach (Attribute attr in attributes)
            {
                if (attr is DebuggableAttribute)
                {
                    DebuggableAttribute d = attr as DebuggableAttribute;
                    //Console.WriteLine(String.Format("Run time Optimizer is enabled : {0}", !d.IsJITOptimizerDisabled));
                    //Console.WriteLine(String.Format("Run time Tracking is enabled : {0}", d.IsJITTrackingEnabled));

                    if (d.IsJITOptimizerDisabled == true)
                    {
                        //Console.WriteLine(String.Format("{0} is a DEBUG Build....", assembly.FullName));
                        return false;
                    }
                    else
                    {
                        //Console.WriteLine(String.Format("{0} is a RELEASE Build....", assembly.FullName));
                        return true;
                    }
                }
            }

            return false;
        }
Пример #14
0
 public static string AssemblyCopyright(Assembly ass)
 {
     // Get all Copyright attributes on this assembly
     object[] attributes = ass.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
     // If there aren't any Copyright attributes, return an empty string. If there is a Copyright attribute, return its value.
     return (attributes.Length == 0) ? "" : ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
 }
        PackageManifest extractFromAssemblyAttributes(Assembly assembly)
        {
            var attribs = assembly.GetCustomAttributes(typeof(BottleAttribute), false);
            if (attribs.Any())
            {
                var attrib = attribs.Single().As<BottleAttribute>();
                return new PackageManifest()
                {
                    Name = attrib.Name,
                    Assemblies = attrib.Assemblies,
                    BinPath = attrib.BinPath,
                    ConfigFileSet = new FileSet()
                    {
                        Include = attrib.ConfigFileSet
                    },
                    ContentFileSet = new FileSet()
                    {
                        Include = attrib.ContentFileSet
                    },
                    DataFileSet = new FileSet()
                    {
                        Include = attrib.DataFileSet
                    },
                    Dependencies = attrib.GetDependencies(),
                    ManifestFileName = "assembly attributes",
                    Role = attrib.Role
                };
            }

            return null;
        }
Пример #16
0
		public static void RegisterAssembly (Assembly a) {
			var attributes = a.GetCustomAttributes (typeof (RequiredFrameworkAttribute), false);

			foreach (var attribute in attributes) {
				var requiredFramework = (RequiredFrameworkAttribute)attribute;
				string libPath;
				string libName = requiredFramework.Name;
				
				if (libName.Contains (".dylib")) {
					libPath = ResourcesPath;
				}
				else {
					libPath = FrameworksPath;
					libPath = Path.Combine (libPath, libName);
					libName = libName.Replace (".frameworks", "");
				}
				libPath = Path.Combine (libPath, libName);
				
				if (Dlfcn.dlopen (libPath, 0) == IntPtr.Zero)
					throw new Exception (string.Format ("Unable to load required framework: '{0}'", requiredFramework.Name),
				new Exception (Dlfcn.dlerror()));
			}
			
			if (assemblies == null) {
				assemblies = new List <Assembly> ();
				Class.Register (typeof (NSObject));
			}

			assemblies.Add (a);

			foreach (Type type in a.GetTypes ()) {
				if (type.IsSubclassOf (typeof (NSObject)) && !Attribute.IsDefined (type, typeof (ModelAttribute), false))
					Class.Register (type);
			}
		}
 public static IEnumerable<ProviderAssemblyAttributeBase> Get(Assembly assembly)
 {
     if (assembly.ReflectionOnly)
     {
         foreach (var referencedAssembly in assembly.GetReferencedAssemblies())
         {
             if (AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies().All(a => a.GetName().FullName != referencedAssembly.FullName))
             {
                 try
                 {
                     Assembly.ReflectionOnlyLoad(referencedAssembly.FullName);
                 }
                 catch (FileNotFoundException)
                 {
                     return Enumerable.Empty<ProviderAssemblyAttributeBase>();
                 }
             }
         }
         var hasAttribute = assembly.GetCustomAttributesData().Any(
             cad => typeof (ProviderAssemblyAttributeBase).IsAssignableFrom(cad.Constructor.DeclaringType));
         if (hasAttribute)
         {
             assembly = Assembly.Load(assembly.GetName());
         }
         else
         {
             return Enumerable.Empty<ProviderAssemblyAttributeBase>();
         }
     }
     return assembly.GetCustomAttributes(typeof (ProviderAssemblyAttributeBase), false)
         .Cast<ProviderAssemblyAttributeBase>();
 }
Пример #18
0
        public void EnsureLoaded(Assembly a)
        {
            if (assembliesProcessed.Contains(a.FullName)) return;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            try {
                object[] attrs = a.GetCustomAttributes(typeof(Util.NativeDependenciesAttribute), true);
                if (attrs.Length == 0) return;
                var attr = attrs[0] as Util.NativeDependenciesAttribute;
                string shortName = a.GetName().Name;
                string resourceName = shortName + "." + attr.Value;

                var info = a.GetManifestResourceInfo(resourceName);
                if (info == null) { this.AcceptIssue(new Issues.Issue("Plugin error - failed to find embedded resource " + resourceName, Issues.IssueSeverity.Error)); return; }

                using (Stream s = a.GetManifestResourceStream(resourceName)){
                    var x = new System.Xml.XmlDocument();
                    x.Load(s);

                    var n = new Node(x.DocumentElement, this);
                    EnsureLoaded(n, shortName,sw);
                }

            } finally {
                assembliesProcessed.Add(a.FullName);
            }
        }
        public override bool IsNonApplicationAssembly(Assembly assembly)
        {
            ArgumentUtility.CheckNotNull ("assembly", assembly);

              return assembly.GetCustomAttributes (false).Any (
              attribute => attribute.GetType ().FullName == "Remotion.Reflection.TypeDiscovery.NonApplicationAssemblyAttribute");
        }
		internal AssemblyInformation(Assembly assembly)
		{
			_assembly = assembly;

			this.InformationalVersion = string.Empty;
			this.ProductVersion = string.Empty;
			this.Major = string.Empty;
			this.Minor = string.Empty;
			this.Revision = string.Empty;
			this.Build = string.Empty;
			this.FullName = string.Empty;

			try
			{
				AssemblyInformationalVersionAttribute attribute = (AssemblyInformationalVersionAttribute)_assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();

				if (attribute != null)
				{
					this.InformationalVersion = attribute.InformationalVersion;
				}
			}
			catch { }

			try
			{
				this.ProductVersion = FileVersionInfo.GetVersionInfo(_assembly.Location).ProductVersion;
			}
			catch { }

			try
			{
				this.FullName = _assembly.FullName;
			}
			catch { }

			try
			{
				this.Major = _assembly.GetName().Version.Major.ToString();
			}
			catch { }

			try
			{
				this.Minor = _assembly.GetName().Version.Minor.ToString();
			}
			catch { }

			try
			{
				this.Revision = _assembly.GetName().Version.Revision.ToString();
			}
			catch { }

			try
			{
				this.Build = _assembly.GetName().Version.Build.ToString();
			}
			catch { }
		}
Пример #21
0
		public static SwitchAttribute [] GetAll (Assembly assembly)
		{
			object [] atts = assembly.GetCustomAttributes (typeof (SwitchAttribute), false);
			SwitchAttribute [] ret = new SwitchAttribute [atts.Length];
			for (int i = 0; i < atts.Length; i++)
				ret [i] = (SwitchAttribute) atts [i];
			return ret;
		}
Пример #22
0
		internal static DAssemblyAttribute Reflect(Assembly/*!*/ assembly)
		{
#if !SILVERLIGHT
			Debug.Assert(!assembly.ReflectionOnly);
#endif
			object[] attrs = assembly.GetCustomAttributes(typeof(DAssemblyAttribute), false);
			return (attrs.Length == 1) ? (DAssemblyAttribute)attrs[0] : null;
		}
 private static bool IsAssemblyAptca(Assembly assembly)
 {
     if (aptca == null)
     {
         aptca = typeof(AllowPartiallyTrustedCallersAttribute);
     }
     return (assembly.GetCustomAttributes(aptca, false).Length > 0);
 }
Пример #24
0
 /// <summary>
 /// Get attribute of a given type on an assembly. If multiple attributes
 /// of a type are present, the first one found is returned.
 /// </summary>
 /// <param name="assembly">The assembly to examine</param>
 /// <param name="attrName">The FullName of the attribute type to look for</param>
 /// <param name="inherit">True to include inherited attributes</param>
 /// <returns>The attribute or null</returns>
 public static System.Attribute GetAttribute(Assembly assembly, string attrName, bool inherit)
 {
     object[] attributes = assembly.GetCustomAttributes(inherit);
     foreach (Attribute attribute in attributes)
         if ( IsInstanceOfType(attrName, attribute) )
             return attribute;
     return null;
 }
Пример #25
0
        public static IEnumerable<IPulser> FromAssembly(
            Assembly assembly)
        {

            return assembly.GetCustomAttributes(typeof (SimpleAutoPulserDescriptionAttribute))
                .Cast<SimpleAutoPulserDescriptionAttribute>()
                .Select(x => new SimpleAutoPulser(TimeSpan.FromSeconds(x.IntervalSeconds), x.EventType));
        }
Пример #26
0
        public AboutBox(Assembly assembly, string title)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            MaximizeBox = false;

            // == Load version info. etc. from assembly ==

            // Title
            if (title == null)
            {
                var ata = (AssemblyTitleAttribute[])assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), true);
                if (ata.Length > 0)
                {
                    // Take the first one. Do we ever have more???
                    titleLabel.Text = ata[0].Title;
                    Text = "About " + titleLabel.Text;
                }
            }
            else
            {
                titleLabel.Text = title;
                Text = "About " + titleLabel.Text;
            }

            // Version
            versionLabel.Text = "Version: " + assembly.GetName().Version;

            // Description
            var ada = (AssemblyDescriptionAttribute[])assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), true);
            if (ada.Length > 0)
            {
                // Take the first one. Do we ever have more???
                descLabel.Text = ada[0].Description;
            }

            // Copyright
            var aca = (AssemblyCopyrightAttribute[])assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), true);
            if (aca.Length > 0)
            {
                // Take the first one. Do we ever have more???
                copyrightLabel.Text = aca[0].Copyright;
            }
        }
 /// <summary>
 /// Checks for the DebuggableAttribute on the assembly provided to determine
 /// whether it has been built in Debug mode.
 /// </summary>
 public static bool AssemblyIsDebugBuild(Assembly assembly)
 {
     return assembly
         .GetCustomAttributes(false)
         .OfType<DebuggableAttribute>()
         .Select(attr => attr.IsJITTrackingEnabled)
         .FirstOrDefault();
 }
 public virtual void Hunt(Assembly assembly)
 {
     String pluginName = assembly.GetName().Name;
     foreach (RouteAttribute attr in assembly.GetCustomAttributes<RouteAttribute>())
     {
         pluginAliasDict[attr.Path] = pluginName;
     }
 }
 internal SymbolTable(Assembly root)
 {
     _rootAssembly = root;
     _assemblyNameMapping = new Dictionary<SegmentType, string>();
     _sharedView = root.GetCustomAttributes(typeof(PipelineHints.ShareViews), false).Length > 0;
     _rootName = root.GetName().Name;
     InitAssemblyNames(root);
 }
 public void Load(Assembly assembly)
 {
     object[] typeAttributes = assembly.GetCustomAttributes(typeof(ConfigurationDesignManagerAttribute), true);
     foreach (ConfigurationDesignManagerAttribute typeAttribute in typeAttributes)
     {
         Load(typeAttribute);
     }
 }
Пример #31
0
 private static string GetVersionAndCopyrightInfo()
 {
     System.Reflection.Assembly asm = System.Reflection.Assembly.GetEntryAssembly();
     object[] desc = asm.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), false);
     if (desc.Length == 1)
     {
         object[] copyright = asm.GetCustomAttributes(typeof(System.Reflection.AssemblyCopyrightAttribute), false);
         if (copyright.Length == 1)
         {
             return(string.Format("{0} version {1}{2}{3}{2}http://www.ikvm.net/",
                                  ((System.Reflection.AssemblyTitleAttribute)desc[0]).Title,
                                  asm.GetName().Version,
                                  Environment.NewLine,
                                  ((System.Reflection.AssemblyCopyrightAttribute)copyright[0]).Copyright));
         }
     }
     return("");
 }
Пример #32
0
        public WebAttributes()
        {
            char SEPARATOR = Convert.ToChar(",");

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

            string [] FullName = assembly.FullName.Split(SEPARATOR);

            for (int i = 0; i < FullName.Length; i++)
            {
                if (FullName[i].LastIndexOf("Version=") > 0)
                {
                    int    length    = FullName[i].LastIndexOf("=");
                    string stVersion = FullName[i].Substring(length + 1) + "\r\n";

                    Version version = new Version(stVersion);

                    _MinorVersion = version.Major + "." + version.Minor;
                    _Version      = version.Major + "." + version.Minor + "." + version.Build;
                    _FullVersion  = version.Major + "." + version.Minor + "." + version.Build + "." + version.Revision;
                }
            }

            object[] customAttributes = assembly.GetCustomAttributes(true);

            for (int j = 0; j < customAttributes.Length; j++)
            {
                System.Type Type = customAttributes[j].GetType();

                if (Type.Name == "AssemblyTitleAttribute")
                {
                    _Title = ((AssemblyTitleAttribute)customAttributes[j]).Title;
                }

                if (Type.Name == "AssemblyCopyrightAttribute")
                {
                    _Copyright = ((AssemblyCopyrightAttribute)customAttributes[j]).Copyright;
                }

                if (Type.Name == "AssemblyProductAttribute")
                {
                    _Product = ((AssemblyProductAttribute)customAttributes[j]).Product;
                }
                if (Type.Name == "AssemblyCompanyAttribute")
                {
                    _Company = ((AssemblyCompanyAttribute)customAttributes[j]).Company;
                }
                if (Type.Name == "AssemblyDescriptionAttribute")
                {
                    _Description = ((AssemblyDescriptionAttribute)customAttributes[j]).Description;
                }
                if (Type.Name == "AssemblyTrademarkAttribute")
                {
                    _Trademark = ((AssemblyTrademarkAttribute)customAttributes[j]).Trademark;
                }
            }    //END For loop
        }        // END WebAttributes class constructor;
Пример #33
0
        static VerInfo()
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            Name    = assembly.GetName().Name;
            Version = assembly.GetName().Version;

            object[] devph = assembly.GetCustomAttributes(typeof(DevelopPhaseAttribute), false);
            if (devph.Length > 0)
            {
                DevPhase = (devph[0] as DevelopPhaseAttribute).Phase;
            }

            object[] config = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyConfigurationAttribute), false);
            if (config.Length > 0)
            {
                Config = (config[0] as System.Reflection.AssemblyConfigurationAttribute).Configuration;
            }
        }
 private string FormatApplicationName(System.Reflection.Assembly asm)
 {
     object[] customAttributes = asm.GetCustomAttributes(typeof(ApplicationNameAttribute), true);
     if (customAttributes.Length > 0)
     {
         return(((ApplicationNameAttribute)customAttributes[0]).Value);
     }
     return(asm.GetName().Name);
 }
Пример #35
0
 static string GetAssemblyProduct()
 {
     System.Reflection.Assembly currentAssem = typeof(Program).Assembly;
     object[] attribs = currentAssem.GetCustomAttributes(typeof(AssemblyProductAttribute), true);
     if (attribs.Length > 0)
     {
         return(((AssemblyProductAttribute)attribs[0]).Product);
     }
     return(null);
 }
Пример #36
0
 public static string AssemblyGuidCurrent()
 {
     System.Reflection.Assembly assembly   = System.Reflection.Assembly.GetExecutingAssembly();
     System.Object[]            attributes = assembly.GetCustomAttributes(typeof(GuidAttribute), false);
     if (attributes.Any())
     {
         return(((GuidAttribute)attributes.First()).Value);
     }
     return("");
 }
Пример #37
0
        public static string GetAppGuid()
        {
            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            Type type = typeof(System.Runtime.InteropServices.GuidAttribute);

            foreach (GuidAttribute guid in asm.GetCustomAttributes(type, false))
            {
                return(guid.Value);
            }
            return(string.Empty);
        }
Пример #38
0
 public string AssemblyGuidString(System.Reflection.Assembly assembly)
 {
     object[] objects = assembly.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
     if (objects.Length > 0)
     {
         return(((System.Runtime.InteropServices.GuidAttribute)objects[0]).Value);
     }
     else
     {
         return(String.Empty);
     }
 }
Пример #39
0
        /// <summary>
        /// Gets a formatted, printable string that includes the assembly name, copyright, and build time.
        /// </summary>
        /// <typeparam name="T">A type that is in the assemblyyou want to get the information from.</typeparam>
        /// <returns>A string in the format: AssemblyName x.x.x.x\nCopyright Information\nBuilt on: M/D/Y H:M:S</returns>
        public static string GetBuildAndCopyrightString <T>()
        {
            SRAssembly assembly      = CallingAssembly;
            string     name          = GetAssemblyName <T>();
            string     version       = assembly.GetName().Version.ToString();
            var        configAttrib  = assembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), true)[0] as AssemblyConfigurationAttribute;
            string     configuration = configAttrib.Configuration;

            if (string.IsNullOrWhiteSpace(configuration) == false)
            {
                version = $"{version} {configuration}";
            }

            string   copyright       = (assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), true)[0] as AssemblyCopyrightAttribute).Copyright;
            DateTime linkerTimestamp = assembly.RetrieveLinkerTimestamp();
            string   buildTime       = linkerTimestamp.ToShortDateString() + " " + linkerTimestamp.ToShortTimeString();

            string buildString = $"{name} {version}{Environment.NewLine}{copyright}{Environment.NewLine}Built on: {buildTime}";

            return(buildString);
        }
Пример #40
0
 public static string GetTitle()
 {
     System.Reflection.Assembly thisAssembly = Assembly.GetEntryAssembly();
     object[] attributes = thisAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
     if (attributes.Length == 1)
     {
         return(((AssemblyTitleAttribute)attributes[0]).Title);
     }
     else
     {
         throw new ApplicationException("Found more than one Assembly Title attribute. Unable to choose service name.");
     }
 }
Пример #41
0
        /// <summary>
        /// Gets the assembly attribute.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static T GetAssemblyAttribute <T>(this System.Reflection.Assembly assembly) where T : Attribute
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            object[] attributes = assembly.GetCustomAttributes(typeof(T), false);

            return((attributes == null || attributes.Length == 0)
                ? null
                : attributes.OfType <T>().SingleOrDefault());
        }
Пример #42
0
 public static string GetCopyright()
 {
     System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
     object[] obj = asm.GetCustomAttributes(false);
     foreach (object o in obj)
     {
         if (o.GetType() == typeof(System.Reflection.AssemblyCopyrightAttribute))
         {
             return(((System.Reflection.AssemblyCopyrightAttribute)o).Copyright);
         }
     }
     return(string.Empty);
 }
Пример #43
0
        /// <summary>
        /// Enumerates files in current directory and finds tests.
        /// </summary>
        /// <returns>List of tests loaded.</returns>
        public List <TestInfo> LoadTests()
        {
            // initialize lists
            _testInfos     = new List <TestInfo>();
            _onvifProfiles = new List <IProfileDefinition>();

            Dictionary <Type, Type> controls = new Dictionary <Type, Type>();

            string location = Assembly.GetExecutingAssembly().Location;
            string path     = Path.GetDirectoryName(location);

            // enumerate files
            foreach (string file in Directory.GetFiles(path, "*.dll"))
            {
                try
                {
                    System.Reflection.Assembly assembly = Assembly.LoadFile(file);

                    // check if this is a test assembly
                    if (assembly.GetCustomAttributes(
                            typeof(TestAssemblyAttribute),
                            false).Length > 0)
                    {
                        // Test assembly

                        // enumerate types
                        foreach (Type t in assembly.GetTypes())
                        {
                            // Load tests, if this is a test class
                            object[] attrs = t.GetCustomAttributes(typeof(TestClassAttribute), true);
                            if (attrs.Length > 0)
                            {
                                LoadTests(t);
                            }

                            // Load profiles, if this is sa profile
                            attrs = t.GetCustomAttributes(typeof(ProfileDefinitionAttribute), true);
                            if (attrs.Length > 0)
                            {
                                LoadProfile(t);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                }
            }

            return(_testInfos);
        }
Пример #44
0
        static private bool isAssemblyDebugBuild()
        {
            System.Reflection.Assembly assemb = System.Reflection.Assembly.GetExecutingAssembly();

            foreach (object att in assemb.GetCustomAttributes(false))
            {
                if (att.GetType() == System.Type.GetType("System.Diagnostics.DebuggableAttribute"))
                {
                    return(((System.Diagnostics.DebuggableAttribute)att).IsJITTrackingEnabled);
                }
            }

            return(false);
        }
Пример #45
0
        /// <summary>
        /// Create a new instance of an assembly version object from an existing assembly.
        /// </summary>
        /// <param name="assembly">An assembly to create a assembly version instance for.</param>
        public AssemblyInformation(System.Reflection.Assembly assembly) : base(assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _name = assembly.GetName().Name;

            _path = assembly.Location.Substring(0, assembly.Location.LastIndexOf(@"\"));

            // declare variable for attribute querying
            object[] attrs = null;

            // get the title information
            attrs = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            if (attrs.Length > 0)
            {
                AssemblyTitleAttribute ata = attrs[0] as AssemblyTitleAttribute;
                _title = ata.Title;
            }
            // get the description information
            attrs = assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
            if (attrs.Length > 0)
            {
                AssemblyDescriptionAttribute ada = attrs[0] as AssemblyDescriptionAttribute;
                _description = ada.Description;
            }
            // get the company information
            attrs = assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
            if (attrs.Length > 0)
            {
                AssemblyCompanyAttribute aca = attrs[0] as AssemblyCompanyAttribute;
                _company = aca.Company;
            }
            // get the product information
            attrs = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
            if (attrs.Length > 0)
            {
                AssemblyProductAttribute apa = attrs[0] as AssemblyProductAttribute;
                _product = apa.Product;
            }
            // get the copyright information
            attrs = assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
            if (attrs.Length > 0)
            {
                AssemblyCopyrightAttribute acpa = attrs[0] as AssemblyCopyrightAttribute;
                _copyright = acpa.Copyright;
            }
            // get the trademark information
            attrs = assembly.GetCustomAttributes(typeof(AssemblyTrademarkAttribute), false);
            if (attrs.Length > 0)
            {
                AssemblyTrademarkAttribute atma = attrs[0] as AssemblyTrademarkAttribute;
                _trademark = atma.Trademark;
            }
        }
Пример #46
0
        private void InitOneAssembly(string extensionPath)
        {
            System.Reflection.Assembly assExtention = System.Reflection.Assembly.LoadFrom(extensionPath);
            string menuTitle = "Menu";

            if (assExtention != null)
            {
                object[] customAttributes = assExtention.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if ((customAttributes != null) && (customAttributes.Length > 0))
                {
                    menuTitle = ((AssemblyTitleAttribute)customAttributes[0]).Title;
                }
                else
                {
                    menuTitle = assExtention.GetName().Name;
                }
            }

            MenuItem mi = new MenuItem();

            mi.Header = menuTitle;
            mCoder.Items.Add(mi);

            Type[]             types  = assExtention.GetTypes();
            IEnumerable <Type> atypes = types.OrderBy(s => s.Name);

            foreach (Type type in atypes)
            {
                if (type.IsSubclassOf(typeof(ZippyCoder.AbstractCoder)))
                {
                    MenuItem miCoder = new MenuItem();
                    object[] ziAttrs = type.GetCustomAttributes(typeof(ZippyCoder.PluginIndicatorAttribute), false);
                    if ((ziAttrs != null) && (ziAttrs.Length > 0))
                    {
                        miCoder.Header = ((ZippyCoder.PluginIndicatorAttribute)ziAttrs[0]).Title;
                    }
                    else
                    {
                        miCoder.Header = type.Name;
                    }
                    miCoder.Tag    = type;
                    miCoder.Click += new RoutedEventHandler(miCoder_Click);
                    mi.Items.Add(miCoder);
                }
            }
        }
        void initialize(System.Reflection.Assembly assembly)
        {
            string groupName = null;

            object[] attrobjs = assembly.GetCustomAttributes(typeof(LocalizationAttribute), true /* inherit */);
            if (attrobjs != null && attrobjs.Length > 0 && attrobjs[0] != null) // focus on only the first.
            {
                LocalizationAttribute locAttr = (LocalizationAttribute)attrobjs[0];
                groupName = locAttr.locGroupName;
                if (groupName == null)
                {
                    groupName = assembly.GetName().Name;
                }
            }
            LocalizationGroupStack.Push(groupName);
            m_Pushed       = true;
            m_LocGroupName = groupName;
        }
Пример #48
0
        /// <summary>
        /// Returns true if the given assembly was built with a debuggable attribute, or if JITTracking is enabled.
        /// </summary>
        /// <param name="assembly">The assembly to inspect</param>
        /// <returns>true, if debug</returns>
        public static bool IsDebug(this SRAssembly assembly)
        {
            if (assembly is null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), true);
            if (attributes == null || attributes.Length == 0)
            {
                return(true);
            }

            var d = (DebuggableAttribute)attributes[0];

            if (d.IsJITTrackingEnabled)
            {
                return(true);
            }

            return(false);
        }
Пример #49
0
        /// <summary>
        /// Returns true if the given assembly was built withou anyt debuggable attribute.
        /// </summary>
        /// <param name="assembly">The assembly to inspect</param>
        /// <returns>true, if release</returns>
        public static bool IsRelease(this SRAssembly assembly)
        {
            if (assembly is null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), true);
            if (attributes == null || attributes.Length == 0)
            {
                return(true);
            }

            var d = (DebuggableAttribute)attributes[0];

            if ((d.DebuggingFlags & DebuggableAttribute.DebuggingModes.Default) == DebuggableAttribute.DebuggingModes.None)
            {
                return(true);
            }

            return(false);
        }
Пример #50
0
        /// <summary>
        /// 输出程序集信息.
        /// </summary>
        /// <param name="twer">文本输出者.</param>
        /// <param name="assembly">程序集.</param>
        public static void OutputAssembly(System.IO.TextWriter twer, System.Reflection.Assembly assembly)
        {
            if (null == twer)
            {
                return;
            }
            if (null == assembly)
            {
                return;
            }
            AssemblyName name = assembly.GetName();

            twer.WriteLine(string.Format("[{0}]", name.Name));
            twer.WriteLine(string.Format("FullName={0}", assembly.FullName));
            twer.WriteLine(string.Format("ImageRuntimeVersion={0}", assembly.ImageRuntimeVersion));
            twer.WriteLine(string.Format("Location={0}", assembly.Location));
            //twer.WriteLine(string.Format("CodeBase={0}", name.CodeBase));
            twer.WriteLine(string.Format("ProcessorArchitecture={0}", name.ProcessorArchitecture));
            object[] attributes = assembly.GetCustomAttributes(false);
            foreach (object o in attributes)
            {
                if (null == o)
                {
                    continue;
                }
                //Type otype = o.GetType();
                //string tname = otype.Name;
                //if (string.IsNullOrEmpty(tname)) continue;
                //if (tname.IndexOf("version", StringComparison.OrdinalIgnoreCase) >= 0) {
                //    twer.WriteLine(string.Format("  {0}", o));
                //}
                object ovalue = GetAttributeValue(o);
                if (null != ovalue)
                {
                    twer.WriteLine(string.Format("  {0}\t// {1}", o, ovalue));
                }
            }
            twer.WriteLine();
        }
Пример #51
0
        //--
        //-- returns string name / string value pair of all attribs
        //-- for specified assembly
        //--
        //-- note that Assembly* values are pulled from AssemblyInfo file in project folder
        //--
        //-- Product         = AssemblyProduct string
        //-- Copyright       = AssemblyCopyright string
        //-- Company         = AssemblyCompany string
        //-- Description     = AssemblyDescription string
        //-- Title           = AssemblyTitle string
        //--
        private static NameValueCollection GetAssemblyAttribs()
        {
            object[]            objAttributes          = null;
            object              objAttribute           = null;
            string              strAttribName          = null;
            string              strAttribValue         = null;
            NameValueCollection objNameValueCollection = new NameValueCollection();

            System.Reflection.Assembly objAssembly = GetEntryAssembly();

            objAttributes = objAssembly.GetCustomAttributes(false);
            foreach (object objAttribute_loopVariable in objAttributes)
            {
                objAttribute   = objAttribute_loopVariable;
                strAttribName  = objAttribute.GetType().ToString();
                strAttribValue = "";
                switch (strAttribName)
                {
                case "System.Reflection.AssemblyTrademarkAttribute":
                    strAttribName  = "Trademark";
                    strAttribValue = ((AssemblyTrademarkAttribute)objAttribute).Trademark.ToString();
                    break;

                case "System.Reflection.AssemblyProductAttribute":
                    strAttribName  = "Product";
                    strAttribValue = ((AssemblyProductAttribute)objAttribute).Product.ToString();
                    break;

                case "System.Reflection.AssemblyCopyrightAttribute":
                    strAttribName  = "Copyright";
                    strAttribValue = ((AssemblyCopyrightAttribute)objAttribute).Copyright.ToString();
                    break;

                case "System.Reflection.AssemblyCompanyAttribute":
                    strAttribName  = "Company";
                    strAttribValue = ((AssemblyCompanyAttribute)objAttribute).Company.ToString();
                    break;

                case "System.Reflection.AssemblyTitleAttribute":
                    strAttribName  = "Title";
                    strAttribValue = ((AssemblyTitleAttribute)objAttribute).Title.ToString();
                    break;

                case "System.Reflection.AssemblyDescriptionAttribute":
                    strAttribName  = "Description";
                    strAttribValue = ((AssemblyDescriptionAttribute)objAttribute).Description.ToString();
                    break;

                default:
                    break;
                    //Console.WriteLine(strAttribName)
                }
                if (!string.IsNullOrEmpty(strAttribValue))
                {
                    if (string.IsNullOrEmpty(objNameValueCollection[strAttribName]))
                    {
                        objNameValueCollection.Add(strAttribName, strAttribValue);
                    }
                }
            }

            //-- add some extra values that are not in the AssemblyInfo, but nice to have
            var _with1 = objNameValueCollection;

            _with1.Add("CodeBase", objAssembly.CodeBase.Replace("file:///", ""));
            _with1.Add("BuildDate", AssemblyBuildDate(objAssembly).ToString());
            _with1.Add("Version", objAssembly.GetName().Version.ToString());
            _with1.Add("FullName", objAssembly.FullName);

            //-- we must have certain assembly keys to proceed.
            if (objNameValueCollection["Product"] == null)
            {
                throw new MissingFieldException("The AssemblyInfo file for the assembly " + objAssembly.GetName().Name + " must have the <Assembly:AssemblyProduct()> key populated.");
            }
            if (objNameValueCollection["Company"] == null)
            {
                throw new MissingFieldException("The AssemblyInfo file for the assembly " + objAssembly.GetName().Name + " must have the <Assembly: AssemblyCompany()>  key populated.");
            }

            return(objNameValueCollection);
        }
Пример #52
0
        /// <summary>
        /// Enumerates files in current directory and finds tests.
        /// </summary>
        /// <returns>List of tests loaded.</returns>
        public List <TestInfo> LoadTests()
        {
            _testInfos     = new List <TestInfo>();
            _onvifProfiles = new List <IProfileDefinition>();

            _controls      = new Dictionary <Guid, SettingsTabPage>();
            _settingsTypes = new List <Type>();

            Dictionary <Type, Type> controls = new Dictionary <Type, Type>();


            string location = Assembly.GetExecutingAssembly().Location;
            string path     = Path.GetDirectoryName(location);

            foreach (string file in Directory.GetFiles(path, "*.dll"))
            {
                try
                {
                    System.Reflection.Assembly assembly = Assembly.LoadFile(file);
                    if (assembly.GetCustomAttributes(
                            typeof(TestAssemblyAttribute),
                            false).Length > 0)
                    {
                        // Test assembly

                        foreach (Type t in assembly.GetTypes())
                        {
                            object[] attrs = t.GetCustomAttributes(typeof(TestClassAttribute), true);
                            if (attrs.Length > 0)
                            {
                                LoadTests(t);
                            }

                            attrs = t.GetCustomAttributes(typeof(ProfileDefinitionAttribute), true);
                            if (attrs.Length > 0)
                            {
                                LoadProfile(t);
                            }

                            attrs = t.GetCustomAttributes(typeof(SettingsControlAttribute), true);
                            if (attrs.Length > 0)
                            {
                                SettingsControlAttribute attr = (SettingsControlAttribute)attrs[0];
                                if (!controls.ContainsKey(attr.ParametersType))
                                {
                                    controls.Add(attr.ParametersType, t);
                                }
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                }
            }


            foreach (Type type in _settingsTypes)
            {
                Type ctrlType = controls[type];

                object          ctrl = Activator.CreateInstance(ctrlType);
                SettingsTabPage ctl  = (SettingsTabPage)ctrl;
                ctl.Dock = DockStyle.Fill;

                _controls.Add(type.GUID, (SettingsTabPage)ctrl);
            }

            if (SettingPagesLoaded != null)
            {
                SettingPagesLoaded(_controls.Values.ToList());
            }

            View.DisplayTests(_testInfos);

            View.DisplayProfiles(_onvifProfiles.OrderBy(P => P.Name));

            if (TestsLoaded != null)
            {
                TestsLoaded(_testInfos);
            }
            return(_testInfos);
        }
Пример #53
0
        /// <summary>
        /// Enumerates files in current directory and finds tests.
        /// </summary>
        /// <returns>List of tests loaded.</returns>
        public List <TestInfo> LoadTests()
        {
            // initialize lists
            _testInfos     = new List <TestInfo>();
            _onvifProfiles = new List <IProfileDefinition>();
            _controls      = new Dictionary <Guid, SettingsTabPage>();
            _settingsTypes = new List <Type>();

            Dictionary <Type, Type> controls = new Dictionary <Type, Type>();

            string location = Assembly.GetExecutingAssembly().Location;
            string path     = Path.GetDirectoryName(location);

            // enumerate files
            foreach (string file in Directory.GetFiles(path, "*.dll"))
            {
                try
                {
                    System.Reflection.Assembly assembly = Assembly.LoadFile(file);

                    // check if this is a test assembly
                    if (assembly.GetCustomAttributes(
                            typeof(TestAssemblyAttribute),
                            false).Length > 0)
                    {
                        // Test assembly

                        // enumerate types
                        foreach (Type t in assembly.GetTypes())
                        {
                            // Load tests, if this is a test class
                            object[] attrs = t.GetCustomAttributes(typeof(TestClassAttribute), true);
                            if (attrs.Length > 0)
                            {
                                LoadTests(t);
                            }

                            // Load profiles, if this is sa profile
                            attrs = t.GetCustomAttributes(typeof(ProfileDefinitionAttribute), true);
                            if (attrs.Length > 0)
                            {
                                LoadProfile(t);
                            }

                            // Load settings controls, if this is a settings control
                            attrs = t.GetCustomAttributes(typeof(SettingsControlAttribute), true);
                            if (attrs.Length > 0)
                            {
                                SettingsControlAttribute attr = (SettingsControlAttribute)attrs[0];
                                // use only one control for each type.
                                if (!controls.ContainsKey(attr.ParametersType))
                                {
                                    controls.Add(attr.ParametersType, t);
                                }
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                }
            }

            // create only necessary settings controls
            foreach (Type type in _settingsTypes)
            {
                Type ctrlType = controls[type];

                object          ctrl = Activator.CreateInstance(ctrlType);
                SettingsTabPage ctl  = (SettingsTabPage)ctrl;
                ctl.Dock = DockStyle.Fill;

                _controls.Add(type.GUID, (SettingsTabPage)ctrl);
            }

            // notify that settings control are loaded
            if (SettingPagesLoaded != null)
            {
                SettingPagesLoaded(_controls.Values.ToList());
            }

            // Display tests
            if (View.TestTreeView != null)
            {
                View.TestTreeView.DisplayTests(_testInfos);
            }
            // Display profiles
            if (View.ProfilesView != null)
            {
                View.ProfilesView.DisplayProfiles(_onvifProfiles.OrderBy(P => P.GetProfileName()));
            }

            return(_testInfos);
        }
Пример #54
0
        //--
        //-- returns string name / string value pair of all attribs
        //-- for specified assembly
        //--
        //-- note that Assembly* values are pulled from AssemblyInfo file in project folder
        //--
        //-- Product         = AssemblyProduct string
        //-- Copyright       = AssemblyCopyright string
        //-- Company         = AssemblyCompany string
        //-- Description     = AssemblyDescription string
        //-- Title           = AssemblyTitle string
        //--
        private static NameValueCollection GetAssemblyAttribs()
        {
            object[] objAttributes  = null;
            object   objAttribute   = null;
            string   strAttribName  = null;
            string   strAttribValue = null;

            System.Collections.Specialized.NameValueCollection objNameValueCollection = new System.Collections.Specialized.NameValueCollection();
            System.Reflection.Assembly objAssembly = GetEntryAssembly();

            objAttributes = objAssembly.GetCustomAttributes(false);
            foreach (object objAttribute_loopVariable in objAttributes)
            {
                objAttribute   = objAttribute_loopVariable;
                strAttribName  = objAttribute.GetType().ToString();
                strAttribValue = "";
                switch (strAttribName)
                {
                case "System.Reflection.AssemblyInformationalVersionAttribute":
                    strAttribName  = "InformationalVersion";
                    strAttribValue = ((AssemblyInformationalVersionAttribute)objAttribute).InformationalVersion.ToString();
                    break;

                case "System.Reflection.AssemblyTrademarkAttribute":
                    strAttribName  = "Trademark";
                    strAttribValue = ((AssemblyTrademarkAttribute)objAttribute).Trademark.ToString();
                    break;

                case "System.Reflection.AssemblyProductAttribute":
                    strAttribName  = "Product";
                    strAttribValue = ((AssemblyProductAttribute)objAttribute).Product.ToString();
                    break;

                case "System.Reflection.AssemblyCopyrightAttribute":
                    strAttribName  = "Copyright";
                    strAttribValue = ((AssemblyCopyrightAttribute)objAttribute).Copyright.ToString();
                    break;

                case "System.Reflection.AssemblyCompanyAttribute":
                    strAttribName  = "Company";
                    strAttribValue = ((AssemblyCompanyAttribute)objAttribute).Company.ToString();
                    break;

                case "System.Reflection.AssemblyTitleAttribute":
                    strAttribName  = "Title";
                    strAttribValue = ((AssemblyTitleAttribute)objAttribute).Title.ToString();
                    break;

                case "System.Reflection.AssemblyDescriptionAttribute":
                    strAttribName  = "Description";
                    strAttribValue = ((AssemblyDescriptionAttribute)objAttribute).Description.ToString();
                    break;

                default:
                    break;
                }
                if (!string.IsNullOrEmpty(strAttribValue))
                {
                    if (string.IsNullOrEmpty(objNameValueCollection[strAttribName]))
                    {
                        objNameValueCollection.Add(strAttribName, strAttribValue);
                    }
                }
            }

            //-- add some extra values that are not in the AssemblyInfo, but nice to have
            objNameValueCollection.Add("CodeBase", objAssembly.CodeBase.Replace("file:///", ""));
            objNameValueCollection.Add("BuildDate", AssemblyBuildDate(objAssembly).ToString());
            objNameValueCollection.Add("Version", objAssembly.GetName().Version.ToString());
            objNameValueCollection.Add("FullName", objAssembly.FullName);

            //-- we must have certain assembly keys to proceed.
            if (objNameValueCollection["Product"] == null)
            {
                objNameValueCollection["Product"] = "";
            }
            if (objNameValueCollection["Company"] == null)
            {
                objNameValueCollection["Company"] = "";
            }

            return(objNameValueCollection);
        }
Пример #55
0
        /// <summary>
        /// Enumerates files in current directory and finds tests.
        /// </summary>
        /// <returns>List of tests loaded.</returns>
        public List <TestInfo> LoadTests()
        {
            _testInfos = new List <TestInfo>();

            string location = Assembly.GetExecutingAssembly().Location;
            string path     = Path.GetDirectoryName(location);

            foreach (string file in Directory.GetFiles(path, "*.dll"))
            {
                try
                {
                    System.Reflection.Assembly assembly = Assembly.LoadFile(file);
                    if (assembly.GetCustomAttributes(
                            typeof(TestAssemblyAttribute),
                            false).Length > 0)
                    {
                        // Test assembly

                        foreach (Type t in assembly.GetTypes())
                        {
                            object[] attrs = t.GetCustomAttributes(typeof(TestClassAttribute), true);
                            if (attrs.Length > 0)
                            {
                                if (t.IsSubclassOf(typeof(Tests.Common.TestBase.BaseTest)))
                                {
                                    foreach (MethodInfo mi in t.GetMethods())
                                    {
                                        object[] testAttributes = mi.GetCustomAttributes(typeof(TestAttribute), true);

                                        if (testAttributes.Length > 0)
                                        {
                                            TestAttribute attribute = (TestAttribute)testAttributes[0];

                                            TestInfo existing =
                                                _testInfos.Where(ti => ti.Order == attribute.Order).FirstOrDefault();

                                            if (existing != null)
                                            {
                                                System.Diagnostics.Debug.WriteLine(string.Format("One more test with order {0} found {1}", attribute.Order, attribute.Name));

                                                if (existing.Version > attribute.Version)
                                                {
                                                    System.Diagnostics.Debug.WriteLine("Leave test already loaded");
                                                    continue;
                                                }
                                                else
                                                {
                                                    System.Diagnostics.Debug.WriteLine("Reload newer test");
                                                    _testInfos.Remove(existing);
                                                }
                                            }

                                            TestInfo testInfo = new TestInfo();
                                            testInfo.Method           = mi;
                                            testInfo.Name             = attribute.Name;
                                            testInfo.Group            = attribute.Path;
                                            testInfo.Order            = attribute.Order;
                                            testInfo.Version          = attribute.Version;
                                            testInfo.Interactive      = attribute.Interactive;
                                            testInfo.RequirementLevel = attribute.RequirementLevel;
                                            testInfo.RequiredFeatures.AddRange(attribute.RequiredFeatures);
                                            testInfo.Services.AddRange(attribute.Services);

                                            _testInfos.Add(testInfo);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                }
            }

            View.DisplayTests(_testInfos);

            if (TestsLoaded != null)
            {
                TestsLoaded(_testInfos);
            }
            return(_testInfos);
        }
Пример #56
0
 /// <summary>
 /// Returns an Assembly attribute.
 /// </summary>
 public static T GetAssemblyAttribute <T>(this System.Reflection.Assembly assembly) where T : Attribute
 {
     return(assembly.GetCustomAttributes(typeof(T), false).Cast <T>().FirstOrDefault());
 }
Пример #57
0
        /// <summary>
        /// Returns the Copyright value from the Assembly.
        /// </summary>
        public static string GetCopyright(this System.Reflection.Assembly assembly)
        {
            var attributes = assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);

            return(attributes.Length == 0 ? "" : ((AssemblyCopyrightAttribute)attributes[0]).Copyright);
        }
Пример #58
0
        internal static AssemblyInfoModel GetAssemblyInfo()
        {
            string description          = "";
            string version              = "";
            string company              = "";
            string copyright            = "";
            string title                = "";
            string product              = "";
            string informationalVersion = "";

            System.Reflection.Assembly entryAssembly = Assembly.GetEntryAssembly();

            object[] attributes = entryAssembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
            if (attributes.Length != 0)
            {
                description = ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }

            attributes = entryAssembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
            if (attributes.Length != 0)
            {
                company = ((AssemblyCompanyAttribute)attributes[0]).Company;
            }

            attributes = entryAssembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
            if (attributes.Length != 0)
            {
                copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }

            attributes = entryAssembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
            if (attributes.Length != 0)
            {
                product = ((AssemblyProductAttribute)attributes[0]).Product;
            }

            title      = System.IO.Path.GetFileNameWithoutExtension(entryAssembly.CodeBase);
            attributes = entryAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            if (attributes.Length != 0)
            {
                if (((AssemblyTitleAttribute)attributes[0]).Title != "")
                {
                    title = ((AssemblyTitleAttribute)attributes[0]).Title;
                }
            }

            version = entryAssembly.GetName().Version.ToString().Replace(".0", "");

            attributes = entryAssembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
            if (attributes.Length != 0)
            {
                informationalVersion = ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
            }

            AssemblyInfoModel properties = new AssemblyInfoModel(description
                                                                 , version
                                                                 , company
                                                                 , copyright
                                                                 , title
                                                                 , product
                                                                 , informationalVersion);

            return(properties);
        }
Пример #59
0
        private VerticalProductName prodName = VerticalProductName.None;         //ACAD ???

        #region IWizard Members
        /// <summary>
        /// Runs custom wizard logic at the beginning of a template wizard run. Set the replace parameters
        /// based on the user input.
        /// </summary>
        /// <param name="automationObject">The automation object being used by the template wizard.</param>
        /// <param name="replacementsDictionary">The list of standard parameters to be replaced.</param>
        /// <param name="runKind">A WizardRunKind indicating the type of wizard run.</param>
        /// <param name="customParams">The custom parameters with which to perform parameter replacement in the project.</param>
        void IWizard.RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();             // GetEntryAssembly()
            AddInCompany = ((AssemblyCompanyAttribute)Attribute.GetCustomAttribute(ass, typeof(AssemblyCompanyAttribute), false)).Company;
            AssemblyTitleAttribute titleAttr = ass.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), false)[0] as AssemblyTitleAttribute;

            AddInProductName = titleAttr.Title;
            AddInVersion     = ass.GetName().Version.ToString();

            //- Display the wizard UI to gather user input.
            //- If the user cancels the UI, return to the new project dialog.
            ObjectARXLocatorForm optForm = new ObjectARXLocatorForm();

            if (optForm.ShowDialog() != DialogResult.OK)
            {
                throw new WizardBackoutException();
            }

            this.sdkpath  = optForm.sdkpath.Text;
            this.acadpath = optForm.acadpath.Text;

            this.prodName = optForm.CurrentVerticalProductName;

            #region Get AutoCAD References UI check status
            //AutoCAD
            this.acdbmgd     = optForm.acdbmgd.Checked;
            this.acmgd       = optForm.acmgd.Checked;
            this.accoremgd   = optForm.accoremgd.Checked;
            this.adwindows   = optForm.adwindows.Checked;
            this.acwindows   = optForm.acwindows.Checked;
            this.actcmgd     = optForm.actcmgd.Checked;
            this.acdx        = optForm.acdx.Checked;
            this.interop0    = optForm.interop0.Checked;
            this.interop1    = optForm.interop1.Checked;
            this.acdbmgdbrep = optForm.acdbmgdbrep.Checked;
            this.accui       = optForm.accui.Checked;
            #endregion
            #region Get Map 3D References UI check status
            //Map 3D
            if (prodName == VerticalProductName.Map3D)
            {
                this.fdopath = this.acadpath + "\\bin\\fdo";
                //map 3d
                this.mapPlatform         = optForm.mapPlatform.Checked;
                this.mapPlatformCore     = optForm.mapPlatformCore.Checked;
                this.osgeoMgFoundation   = optForm.OsgeoMgFoundation.Checked;
                this.osgeoMgGeom         = optForm.OsgeoMgGeom.Checked;
                this.osgeoMgPlatformBase = optForm.OsgeoMgPlatformBase.Checked;
                this.osgeoFdoCommon      = optForm.OsgeoFdoCommon.Checked;
                this.osgeoFdoGeom        = optForm.OsgeoFdoGeom.Checked;
                this.osgeoFdo            = optForm.OsgeoFdo.Checked;
                this.acMPloygonMgd       = optForm.AcMPloygonMgd.Checked;
                this.mgdMapApi           = optForm.MgdMapApi.Checked;
            }
            #endregion
            #region Get Civil 3D References UI check status
            //Civil 3D
            if (prodName == VerticalProductName.Civil3D)
            {
                this.fdopath = this.acadpath + "\\bin\\fdo";
                //map3d
                this.mapPlatform         = optForm.mapPlatform.Checked;
                this.mapPlatformCore     = optForm.mapPlatformCore.Checked;
                this.osgeoMgFoundation   = optForm.OsgeoMgFoundation.Checked;
                this.osgeoMgGeom         = optForm.OsgeoMgGeom.Checked;
                this.osgeoMgPlatformBase = optForm.OsgeoMgPlatformBase.Checked;
                this.osgeoFdoCommon      = optForm.OsgeoFdoCommon.Checked;
                this.osgeoFdoGeom        = optForm.OsgeoFdoGeom.Checked;
                this.osgeoFdo            = optForm.OsgeoFdo.Checked;
                this.acMPloygonMgd       = optForm.AcMPloygonMgd.Checked;
                this.mgdMapApi           = optForm.MgdMapApi.Checked;
                //civil 3d
                this.aecBaseMgd     = optForm.aecBaseMgd.Checked;
                this.aeccDbMgd      = optForm.aeccDbMgd.Checked;
                this.comAeccLand    = optForm.aeccLand.Checked;
                this.comAeccPipe    = optForm.aeccPipe.Checked;
                this.comAeccSurvey  = optForm.aeccSurvey.Checked;
                this.comAeccRoadway = optForm.aeccRoadway.Checked;
                this.civilComCommon = comAeccLand || comAeccPipe ||
                                      comAeccSurvey || comAeccRoadway;
            }
            #endregion
            #region Get ACA References UI check status
            //ACA
            if (prodName == VerticalProductName.ACA)
            {
                this.aecArchMgd        = optForm.acaAecArchMgd.Checked;
                this.aecArchDACHMgd    = optForm.acaArchDACHMgd.Checked;
                this.aecBaseMgd        = optForm.acaAecBaseMgd.Checked;
                this.aecBaseUtilsMgd   = optForm.acaAecBaseUtilsMgd.Checked;
                this.aecProjectBaseMgd = optForm.acaAecProjectBaseMgd.Checked;
                this.aecPropDataMgd    = optForm.acaAecPropDataMgd.Checked;
                this.aecRcpMgd         = optForm.acaAecRcpMgd.Checked;
                this.aecStructureMgd   = optForm.acaAecStructureMgd.Checked;
                this.aecUIBaseMgd      = optForm.acaAecUIBaseMgd.Checked;
                this.aecUtilityMgd     = optForm.acaAecUtilityMgd.Checked;
            }
            #endregion
            #region Get AME References UI check status
            //AME
            if (prodName == VerticalProductName.AME)
            {
                this.aecArchMgd        = optForm.ameAecArchMgd.Checked;
                this.aecArchDACHMgd    = optForm.ameAecArchDACHMgd.Checked;
                this.aecBaseMgd        = optForm.ameAecBaseMgd.Checked;
                this.aecBaseUtilsMgd   = optForm.ameAecBaseUtilsMgd.Checked;
                this.aecProjectBaseMgd = optForm.ameAecProjectBaseMgd.Checked;
                this.aecPropDataMgd    = optForm.ameAecPropDataMgd.Checked;
                this.aecRcpMgd         = optForm.ameAecRcpMgd.Checked;
                this.aecStructureMgd   = optForm.ameAecStructureMgd.Checked;
                this.aecUIBaseMgd      = optForm.ameAecUIBaseMgd.Checked;
                this.aecUtilityMgd     = optForm.ameAecUtilityMgd.Checked;

                this.aecbBldSrvMgd       = optForm.ameAecbBldSrvMgd.Checked;
                this.aecbElecBaseMgd     = optForm.ameAecbElecBaseMgd.Checked;
                this.aecbHvacBaseMgd     = optForm.ameAecbHvacBaseMgd.Checked;
                this.aecbPlumbingBaseMgd = optForm.ameAecbPlumbingBaseMgd.Checked;
                this.aecbPipeBaseMgd     = optForm.ameAecbPipeBaseMgd.Checked;
                this.aecbPartBaseMgd     = optForm.ameAecbPartBaseMgd.Checked;
            }
            #endregion

            //- This approach works for both Express Editions and full VS
            this.AddReferencesOnExpress(replacementsDictionary);

            // Replace parameters can be added dynamically in IWizard.RunStarted,
            // as demonstrated in the code below.
            //replacementsDictionary.Add("$AboutBoxCodeProjectItem$", "");

            // CustomParameters in .vstemplate file contains default replace parameters.
            // If the user chooses not to use them, reset these replace parameters to
            // empty string so that they don't appear in the generated code.
            //replacementsDictionary["$EditMenuItemsCreation$"] = "";
        }
Пример #60
0
 public string ProgramCopyrightNotice()
 {
     System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
     System.Reflection.AssemblyCopyrightAttribute copyrightAttr = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyCopyrightAttribute), false)[0] as System.Reflection.AssemblyCopyrightAttribute;
     return(copyrightAttr?.Copyright);
 }