Пример #1
0
 public AboutViewModel()
 {
     // Get the application information.
     var app = Assembly.GetExecutingAssembly();
     _copyright = (AssemblyCopyrightAttribute)Attribute.GetCustomAttribute(app, typeof(AssemblyCopyrightAttribute));
     _version = (AssemblyFileVersionAttribute)Attribute.GetCustomAttribute(app, typeof(AssemblyFileVersionAttribute));
 }
        public void Handler_ShouldReturnAssemblyInfo_IfAssemblyInformationThere()
        {
            // Arrange
            var productName = _fixture.Create<string>();
            var productAttribute = new AssemblyProductAttribute(productName);
            _sut.Stub(x => x.GetAssemblyAttribute<AssemblyProductAttribute>(_currentAssembly)).Return(productAttribute);

            var fileVersion = _fixture.Create<string>();
            var fileVersionAttribute = new AssemblyFileVersionAttribute(fileVersion);
            _sut.Stub(x => x.GetAssemblyAttribute<AssemblyFileVersionAttribute>(_currentAssembly))
                .Return(fileVersionAttribute);

            var buildId = _fixture.Create<string>();
            var asmInfoAttribute = new AssemblyInformationalVersionAttribute(buildId);
            _sut.Stub(x => x.GetAssemblyAttribute<AssemblyInformationalVersionAttribute>(_currentAssembly))
                .Return(asmInfoAttribute);

            // Act
            dynamic answer = _sut.Handler(_question);

            // Assert
            Assert.IsNotInstanceOfType(answer, typeof (string));

            Assert.AreEqual(productName, answer.Product);
            Assert.AreEqual(fileVersion, answer.ProductVersion);
            Assert.AreEqual(buildId, answer.BuildId);
        }
Пример #3
0
        /// <summary>
        /// 어셈블리 파일 버전에 대해 특정 버전 번호를 구합니다.
        /// </summary>
        /// <param name="assembly">구하려는 어셈블리</param>
        /// <returns>어셈블리 파일 버전에 대해 특정 버전 번호를 반환합니다.</returns>
        public static string GetAssemblyFileVersion(this Assembly assembly)
        {
            AssemblyFileVersionAttribute assemblyGetCustomAttributes = assembly.GetCustomAttributes <AssemblyFileVersionAttribute>().FirstOrDefault();

            if (assemblyGetCustomAttributes != null)
            {
                return(assemblyGetCustomAttributes.Version);
            }

            return(string.Empty);
        }
Пример #4
0
        public static String AssemblyFileVersionInfo(this System.Reflection.Assembly assembly)
        {
            String InfoStr;

#if UseWindowsDesktop
            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
            String          AsemVersion     = fileVersionInfo.FileVersion;

            if (fileVersionInfo.FileBuildPart != 0)
            {
                String buildNoString = DateTimeBuildNo.ToBuildDateString(fileVersionInfo.FileBuildPart, fileVersionInfo.FilePrivatePart);
                InfoStr = String.Format("{0} {1}", AsemVersion, buildNoString);
            }
            else
            {
                InfoStr = AsemVersion;
            }
#else
            // AssemblyVersionAttribute ava =  assembly.GetCustomAttribute<AssemblyVersionAttribute>();
            AssemblyFileVersionAttribute afva = assembly.GetCustomAttribute <AssemblyFileVersionAttribute>();

            if (afva != null)
            {
                String   AsemVersion = afva.Version;
                String[] parts       = AsemVersion.Split('.');
                if (parts.Length >= 2)
                {
                    Int32 FileBuildPart   = 0;
                    Int32 FilePrivatePart = 0;

                    Int32.TryParse(parts[2], out FileBuildPart);
                    if (parts.Length >= 3)
                    {
                        Int32.TryParse(parts[3], out FilePrivatePart);
                    }
                    String buildNoString = DateTimeBuildNo.ToBuildDateString(FileBuildPart, FilePrivatePart);
                    InfoStr = String.Format("{0} {1}", AsemVersion, buildNoString);
                }
                else
                {
                    InfoStr = afva.Version;
                }
            }
            else
            {
                InfoStr = "null";
            }
#endif // UseWindowsDesktop
            return(InfoStr);
        }
		public AssemblyFileVersionAttributeTest ()
		{
			//create a dynamic assembly with the required attribute
			//and check for the validity

			dynAsmName.Name = "TestAssembly";

			dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
				dynAsmName,AssemblyBuilderAccess.Run
				);

			// Set the required Attribute of the assembly.
			Type attribute = typeof (AssemblyFileVersionAttribute);
			ConstructorInfo ctrInfo = attribute.GetConstructor (
				new Type [] { typeof(string) }
				);
			CustomAttributeBuilder attrBuilder =
				new CustomAttributeBuilder(ctrInfo, new object [1] { "1.0.0.0" });
			dynAssembly.SetCustomAttribute (attrBuilder);
			object [] attributes = dynAssembly.GetCustomAttributes (true);
			attr = attributes [0] as AssemblyFileVersionAttribute;
		}
 public AssemblyUtilsTests()
 {
     this.fileAttr = new AssemblyFileVersionAttribute(FileVersion);
     this.asmMock = new Mock<AssemblyMock>();
     this.asm = this.asmMock.Object;
 }
Пример #7
0
 private string GetAssembly(Type type)
 {
     if (type.ToString() == "System.Reflection.AssemblyVersionAttribute")
     {//程序集版本号,要用这个方法获取,无法用下边的方法获取,原因不知
         return(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
     }
     object[] attributes = System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(type, false);
     if (attributes.Length > 0)
     {
         if (type.ToString() == "System.Reflection.AssemblyCompanyAttribute")
         {
             #region//公司
             System.Reflection.AssemblyCompanyAttribute company = (System.Reflection.AssemblyCompanyAttribute)attributes[0];
             if (company.Company != "")
             {
                 return(company.Company);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyCopyrightAttribute")
         {
             #region//版权
             System.Reflection.AssemblyCopyrightAttribute company = (System.Reflection.AssemblyCopyrightAttribute)attributes[0];
             if (company.Copyright != "")
             {
                 return(company.Copyright);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyTitleAttribute")
         {
             #region//标题
             System.Reflection.AssemblyTitleAttribute company = (System.Reflection.AssemblyTitleAttribute)attributes[0];
             if (company.Title != "")
             {
                 return(company.Title);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyDescriptionAttribute")
         {
             #region//备注
             System.Reflection.AssemblyDescriptionAttribute company = (System.Reflection.AssemblyDescriptionAttribute)attributes[0];
             if (company.Description != "")
             {
                 return(company.Description);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyProductAttribute")
         {
             #region//产品名称
             System.Reflection.AssemblyProductAttribute company = (System.Reflection.AssemblyProductAttribute)attributes[0];
             if (company.Product != "")
             {
                 return(company.Product);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyTrademarkAttribute")
         {
             #region//商标
             System.Reflection.AssemblyTrademarkAttribute company = (System.Reflection.AssemblyTrademarkAttribute)attributes[0];
             if (company.Trademark != "")
             {
                 return(company.Trademark);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyConfigurationAttribute")
         {
             #region//获取程序集配置信息,具体什么内容,不清楚
             System.Reflection.AssemblyConfigurationAttribute company = (System.Reflection.AssemblyConfigurationAttribute)attributes[0];
             if (company.Configuration != "")
             {
                 return(company.Configuration);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyCultureAttribute")
         {
             #region//获取属性化程序集支持的区域性,具体什么内容,不清楚
             System.Reflection.AssemblyCultureAttribute company = (System.Reflection.AssemblyCultureAttribute)attributes[0];
             if (company.Culture != "")
             {
                 return(company.Culture);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyVersionAttribute")
         {
             #region//程序集版本号
             System.Reflection.AssemblyVersionAttribute company = (System.Reflection.AssemblyVersionAttribute)attributes[0];
             if (company.Version != "")
             {
                 return(company.Version);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyFileVersionAttribute")
         {
             #region//文件版本号
             System.Reflection.AssemblyFileVersionAttribute company = (System.Reflection.AssemblyFileVersionAttribute)attributes[0];
             if (company.Version != "")
             {
                 return(company.Version);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyInformationalVersionAttribute")
         {
             #region//产品版本号
             System.Reflection.AssemblyInformationalVersionAttribute company = (System.Reflection.AssemblyInformationalVersionAttribute)attributes[0];
             if (company.InformationalVersion != "")
             {
                 return(company.InformationalVersion);
             }
             #endregion
         }
     }
     //如果没有  属性,或者  属性为一个空字符串,则返回 .exe 的名称
     return(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().CodeBase));
 }
        internal static IEnumerable<KeyValuePair<string, object>> EnumerateMetadata(Assembly assembly)
        {
            ComponentName cname = ComponentName.FromAssemblyName(assembly.GetName());

            var data = assembly.GetCustomAttributesData();
            TargetFrameworkAttribute targetAttr = null;
            AssemblyConfigurationAttribute configAttr = null;
            AssemblyFileVersionAttribute fileAttr = null;

            foreach (var m in data) {
                var decl = m.Constructor.DeclaringType;
                if (decl == typeof(TargetFrameworkAttribute))
                    targetAttr = new TargetFrameworkAttribute((string) m.ConstructorArguments[0].Value);

                else if (decl == typeof(AssemblyConfigurationAttribute))
                    configAttr = new AssemblyConfigurationAttribute((string) m.ConstructorArguments[0].Value);

                else if (decl == typeof(AssemblyFileVersionAttribute))
                    fileAttr = new AssemblyFileVersionAttribute((string) m.ConstructorArguments[0].Value);
            }

            FrameworkName target = GetFrameworkName(assembly, targetAttr);
            string config = GetConfiguration(configAttr);
            string platform = GetPlatform(assembly);
            Version version = assembly.GetName().Version;

            ICustomAttributeProvider attributes;

            if (assembly.ReflectionOnly)
                attributes = new ReflectOnlyAssemblyAttributeProvider(assembly);
            else
                attributes = assembly;

            Uri myBase = null;
            Uri url = null;
            Uri license = null;

            var baseAttribute = CustomAttributeProvider.GetCustomAttribute<BaseAttribute>(attributes, false);
            if (baseAttribute != null) {
                myBase = baseAttribute.Source;
            }

            var licenseAttribute = CustomAttributeProvider.GetCustomAttribute<LicenseAttribute>(attributes, false);
            if (licenseAttribute != null) {
                license = licenseAttribute.Uri;
            }

            var ua = CustomAttributeProvider.GetCustomAttribute<UrlAttribute>(attributes, false);
            if (ua != null) {
                url = ua.Url;
            }

            return Properties.FromValue(new {
                                            name = cname.Name,
                                            configuration = config,
                                            assemblyName = cname,
                                            platform = platform,
                                            targetFramework = target,
                                            @base = myBase,
                                            license = license,
                                            url = url,
                                            version = version, });
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        query.Model.Texts.ReloadNativeResources();
        Korzh.EasyQuery.WebControls.TextResources.ReloadNativeResources();

        query.Model.Texts.LoadFromFileForCulture(System.IO.Path.Combine(baseDataPath, "EQCoreMessages"));
        query.Model.RefreshResources();
        Korzh.EasyQuery.WebControls.TextResources.LoadFromFileForCulture(System.IO.Path.Combine(baseDataPath, "EQWebMessages"));

        if (!Page.IsPostBack)
        {
            string queryName = Page.Request.QueryString.Get("query");
            if (queryName != null)
            {
                query.LoadFromFile(baseDataPath + "\\" + queryName + ".xml");
            }
        }

        QueryPanel1.Query = query;

        QueryColumnsPanel1.Query = QueryPanel1.Query;
        EntitiesPanel1.Query     = QueryPanel1.Query;

        SortColumnsPanel1.Query = QueryPanel1.Query;

        query.ColumnsChanged    += new Korzh.EasyQuery.ColumnsChangedEventHandler(query_ColumnsChanged);
        query.ConditionsChanged += new Korzh.EasyQuery.ConditionsChangedEventHandler(query_ConditionsChanged);
        query.SortOrderChanged  += new Korzh.EasyQuery.SortOrderChangedEventHandler(query_SortOrderChanged);

        System.Reflection.AssemblyFileVersionAttribute versionAttr =
            (System.Reflection.AssemblyFileVersionAttribute)System.Attribute.GetCustomAttribute(QueryPanel1.GetType().Assembly, typeof(System.Reflection.AssemblyFileVersionAttribute));

        LabelVersion.Text = "Version: " + versionAttr.Version;

        EnableLinkButton(lnkBtnEng);
        EnableLinkButton(lnkBtnRu);
        EnableLinkButton(lnkBtnEsp);


        qpAddRow                = new LabelListXElement();
        qpAddRow.ID             = "QPAddRowLink";
        qpAddRow.EmptyValueText = GetLocalResourceObject("txtQPAddRow").ToString();
        QueryPanel1.FillElementByEntityTree(qpAddRow);
        qpAddRow.ContentChanged += new ContentChangedEventHandler(QPAddRowContentChanged);
        qpAddRow.TextAdjusting  += new TextAdjustingEventHandler(QPAddRowTextAdjusting);
        QPAddRowPanel.Controls.Add(qpAddRow);

        qcAddRow                = new LabelListXElement();
        qcAddRow.ID             = "QCAddRowLink";
        qcAddRow.EmptyValueText = GetLocalResourceObject("txtQCAddRow").ToString();
        QueryColumnsPanel1.FillEntityElement(qcAddRow);
        qcAddRow.ContentChanged += new ContentChangedEventHandler(QCAddRowContentChanged);
        qcAddRow.TextAdjusting  += new TextAdjustingEventHandler(QCAddRowTextAdjusting);
        QCAddRowPanel.Controls.Add(qcAddRow);

        qsAddRow                = new LabelListXElement();
        qsAddRow.ID             = "QSAddRowLink";
        qsAddRow.EmptyValueText = GetLocalResourceObject("txtQSAddRow").ToString();
        SortColumnsPanel1.FillEntityElement(qsAddRow);
        qsAddRow.ContentChanged += new ContentChangedEventHandler(QSAddRowContentChanged);
        qsAddRow.TextAdjusting  += new TextAdjustingEventHandler(QSAddRowTextAdjusting);
        QSAddRowPanel.Controls.Add(qsAddRow);


        QueryPanel1.ToolTip        = GetLocalResourceObject("txtQPTooltip").ToString();
        QueryColumnsPanel1.ToolTip = GetLocalResourceObject("txtQCTooltip").ToString();
        SortColumnsPanel1.ToolTip  = GetLocalResourceObject("txtQSTooltip").ToString();

        UpdateSql();
    }