Exemplo n.º 1
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call CultureName when NeutralResourcesLanguageAttribute created with string.Empty reference");

        try
        {
            NeutralResourcesLanguageAttribute attr = new NeutralResourcesLanguageAttribute(string.Empty);

            if (attr == null)
            {
                TestLibrary.TestFramework.LogError("001.1", "Calling CultureName when NeutralResourcesLanguageAttribute created with string.Empty returns null reference");
                retVal = false;
            }

            string actual = attr.CultureName;
            if (actual != string.Empty)
            {
                TestLibrary.TestFramework.LogError("001.2", "Calling CultureName when NeutralResourcesLanguageAttribute created with string.Empty does not returns null CultureName");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call ctor with string.Empty reference");

        try
        {
            NeutralResourcesLanguageAttribute attr = new NeutralResourcesLanguageAttribute(string.Empty);

            if (attr == null)
            {
                TestLibrary.TestFramework.LogError("001.1", "Calling ctor with string.Empty returns null reference");
                retVal = false;
            }

            string actual = attr.CultureName;
            if (actual != string.Empty)
            {
                TestLibrary.TestFramework.LogError("001.2", "Calling ctor with string.Empty does not returns null CultureName");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Call ctor with rand string");

        try
        {
            string expected = TestLibrary.Generator.GetString(-55, false, 1, 10);
            NeutralResourcesLanguageAttribute attr = new NeutralResourcesLanguageAttribute(expected);

            if (attr == null)
            {
                TestLibrary.TestFramework.LogError("002.1", "Calling ctor with rand string returns null reference");
                retVal = false;
            }

            string actual = attr.CultureName;
            if (actual != expected)
            {
                TestLibrary.TestFramework.LogError("002.2", "Calling ctor with rand string does not returns expected CultureName");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actual = " + actual + ", expected = " + expected);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
Exemplo n.º 4
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Call CultureName when NeutralResourcesLanguageAttribute created with rand string");

        try
        {
            string expected = TestLibrary.Generator.GetString(-55, false, 1, 10);
            NeutralResourcesLanguageAttribute attr = new NeutralResourcesLanguageAttribute(expected);

            if (attr == null)
            {
                TestLibrary.TestFramework.LogError("002.1", "Calling ctor with rand string returns null reference");
                retVal = false;
            }

            string actual = attr.CultureName;
            if (actual != expected)
            {
                TestLibrary.TestFramework.LogError("002.2", "Calling ctor with rand string does not returns expected CultureName");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actual = " + actual + ", expected = " + expected);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Exemplo n.º 5
0
        private EmbeddedResourceManager()
            : base("AxCrypt.Content.Properties.Resources", typeof(global::AxCrypt.Content.Properties.Resources).GetTypeInfo().Assembly)
        {
            Dictionary <string, string> dictionary = CultureDictionary(String.Empty);

            NeutralResourcesLanguageAttribute neutral = _resourcesAssembly.GetCustomAttribute <NeutralResourcesLanguageAttribute>();

            _cultureResourceDictionary.Add(neutral.CultureName, dictionary);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 어셈블리의 주 어셈블리에 대한 기본 culture의 이름을 구합니다.
        /// </summary>
        /// <param name="assembly">구하려는 어셈블리</param>
        /// <returns>어셈블리의 주 어셈블리에 대한 기본 culture의 이름을 반환합니다.</returns>
        public static string GetAssemblyCultureName(this Assembly assembly)
        {
            NeutralResourcesLanguageAttribute assemblyGetCustomAttributes = assembly.GetCustomAttributes <NeutralResourcesLanguageAttribute>().FirstOrDefault();

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

            return(string.Empty);
        }
Exemplo n.º 7
0
 public void Load()
 {
     __IsLoaded = false;
     try
     {
         __Assembly = Assembly.LoadFrom(__FileName);
         __NeutralResourceAttribute = Attribute.GetCustomAttribute(__Assembly, typeof(System.Resources.NeutralResourcesLanguageAttribute))
                                      as System.Resources.NeutralResourcesLanguageAttribute;
     }
     catch (Exception e)
     {
         __WasExceptionOnLoad = true;
         __ExceptionOnLoad    = e;
     }
 }
Exemplo n.º 8
0
        private static ReadOnlyCollection <CultureInfo> GetAvailableCultures()
        {
            List <CultureInfo> list = new List <CultureInfo>();

            string   startupDir = Application.StartupPath;
            Assembly asm        = Assembly.GetEntryAssembly();

            CultureInfo neutralCulture = CultureInfo.InvariantCulture;

            if (asm != null)
            {
                NeutralResourcesLanguageAttribute attr = Attribute.GetCustomAttribute(asm, typeof(NeutralResourcesLanguageAttribute)) as NeutralResourcesLanguageAttribute;
                if (attr != null)
                {
                    neutralCulture = CultureInfo.GetCultureInfo(attr.CultureName);
                }
            }
            // -- rather than neutral culture choose en-us
            neutralCulture = CultureInfo.GetCultureInfo("en-US");
            list.Add(neutralCulture);

            if (asm != null)
            {
                string baseName = asm.GetName().Name;
                foreach (string dir in Directory.GetDirectories(startupDir))
                {
                    // Check that the directory name is a valid culture
                    DirectoryInfo dirinfo  = new DirectoryInfo(dir);
                    CultureInfo   tCulture = null;
                    try
                    {
                        tCulture = CultureInfo.GetCultureInfo(dirinfo.Name);
                    }
                    // Not a valid culture : skip that directory
                    catch (ArgumentException)
                    {
                        continue;
                    }

                    // Check that the directory contains satellite assemblies
                    if (dirinfo.GetFiles(baseName + ".resources.dll").Length > 0)
                    {
                        list.Add(tCulture);
                    }
                }
            }
            return(list.AsReadOnly());
        }
Exemplo n.º 9
0
        private static IEnumerable <string> CopyResourceAssemblies(Assembly cachedAssembly, string originalAssemblyDirectory)
        {
            string str = null;

            try
            {
                object[] customAttributes = cachedAssembly.GetCustomAttributes(false);
                int      num = 0;
                while (num < (int)customAttributes.Length)
                {
                    NeutralResourcesLanguageAttribute neutralResourcesLanguageAttribute = (Attribute)customAttributes[num] as NeutralResourcesLanguageAttribute;
                    if (neutralResourcesLanguageAttribute == null)
                    {
                        num++;
                    }
                    else
                    {
                        str = neutralResourcesLanguageAttribute.CultureName;
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
            }
            for (CultureInfo i = CultureInfo.CurrentUICulture; !i.Equals(CultureInfo.InvariantCulture); i = i.Parent)
            {
                string str1 = i.ToString();
                if (str != null && string.Equals(str1, str, StringComparison.OrdinalIgnoreCase))
                {
                    str = null;
                }
                string str2 = ProjectAssemblyHelper.TryCopyResourceAssembly(cachedAssembly, originalAssemblyDirectory, str1);
                if (str2 != null)
                {
                    yield return(str2);
                }
            }
            if (str != null)
            {
                string str3 = ProjectAssemblyHelper.TryCopyResourceAssembly(cachedAssembly, originalAssemblyDirectory, str);
                if (str3 != null)
                {
                    yield return(str3);
                }
            }
        }
Exemplo n.º 10
0
        //
        // Get Neutral Resource language for the assembly of this ResourceManagerWrapper
        //
        private CultureInfo GetNeutralResourcesLanguage( )
        {
            //
            // If NeutralResourceLanguageAttribute is not set, the resource must be
            // in Main assembly, return CultureInfor.InvariantCulture.
            //
            CultureInfo ciNeutral = CultureInfo.InvariantCulture;

            NeutralResourcesLanguageAttribute neutralLangAttr = Attribute.GetCustomAttribute(_assembly, typeof(NeutralResourcesLanguageAttribute)) as NeutralResourcesLanguageAttribute;

            if (neutralLangAttr != null)
            {
                ciNeutral = new CultureInfo(neutralLangAttr.CultureName);
            }

            return ciNeutral;
        }
Exemplo n.º 11
0
        protected override ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
        {
            // CultureInfo.InvariantCulture.Name is empty
            if (culture.Name.IsEmpty() && MainAssembly.TryGetCustomAttribute(out NeutralResourcesLanguageAttribute attribute))
            {
                culture = new CultureInfo(attribute.CultureName);
            }
            else
            {
                attribute = new NeutralResourcesLanguageAttribute(string.Empty);
            }

            var resourceSetKey = $"{nameof(BaseName)}={BaseName},{nameof(CultureInfo)}={culture.Name}";

            if (!_resourceSets.TryGetValue(resourceSetKey, out ResourceSet resourceSet))
            {
                try
                {
                    // 提供对内置资源的支持
                    if (IsInternalResourceBaseName() && culture.Name.Equals(attribute.CultureName, StringComparison.OrdinalIgnoreCase))
                    {
                        resourceSet = GetAssemblyResourceSet(MainAssembly);
                    }
                    else
                    {
                        resourceSet = GetAssemblyResourceSet(MainAssembly.GetSatelliteAssembly(culture));
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex.AsInnerMessage());
                }

                if (resourceSet.IsNotNull())
                {
                    _resourceSets.GetOrAdd(resourceSetKey, resourceSet);
                }
            }

            return(resourceSet);
        }
    public bool NegTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest1: Call ctor with null reference");

        try
        {
            NeutralResourcesLanguageAttribute attr = new NeutralResourcesLanguageAttribute(null);
            TestLibrary.TestFramework.LogError("101.1", "ArgumentNullException exception does not thrown when calling ctor with null reference");
            retVal = false;
        }
        catch (ArgumentNullException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("101.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
        public static void ConstructorBasic(string cultureName)
        {
            NeutralResourcesLanguageAttribute nrla = new NeutralResourcesLanguageAttribute(cultureName);

            Assert.Equal(cultureName, nrla.CultureName);
        }
 public static void ConstructorBasic(string cultureName)
 {
     NeutralResourcesLanguageAttribute nrla = new NeutralResourcesLanguageAttribute(cultureName);
     Assert.Equal(cultureName, nrla.CultureName);
 }
Exemplo n.º 15
0
        public AssemblyInfo(Assembly assembly)
        {
            Add(InfoItem.fullpath, Path.GetDirectoryName(assembly.Location));
            Add(InfoItem.filename, Path.GetFileName(assembly.Location));
            // Get values from the assembly.
            AssemblyTitleAttribute titleAttr =
                GetAssemblyAttribute <AssemblyTitleAttribute>(assembly);

            if (titleAttr != null)
            {
                Add(InfoItem.title, titleAttr.Title);
            }
            else
            {
                Add(InfoItem.title, string.Empty);
            }

            AssemblyDescriptionAttribute assemblyAttr =
                GetAssemblyAttribute <AssemblyDescriptionAttribute>(assembly);

            if (assemblyAttr != null)
            {
                Add(InfoItem.description, assemblyAttr.Description);
            }
            else
            {
                Add(InfoItem.description, string.Empty);
            }

            AssemblyCompanyAttribute companyAttr =
                GetAssemblyAttribute <AssemblyCompanyAttribute>(assembly);

            if (companyAttr != null)
            {
                Add(InfoItem.company, companyAttr.Company);
            }
            else
            {
                Add(InfoItem.company, string.Empty);
            }


            AssemblyProductAttribute productAttr =
                GetAssemblyAttribute <AssemblyProductAttribute>(assembly);

            if (productAttr != null)
            {
                Add(InfoItem.product, productAttr.Product);
            }
            else
            {
                Add(InfoItem.product, string.Empty);
            }

            AssemblyCopyrightAttribute copyrightAttr =
                GetAssemblyAttribute <AssemblyCopyrightAttribute>(assembly);

            if (copyrightAttr != null)
            {
                Add(InfoItem.copyright, copyrightAttr.Copyright);
            }
            else
            {
                Add(InfoItem.copyright, string.Empty);
            }

            AssemblyTrademarkAttribute trademarkAttr =
                GetAssemblyAttribute <AssemblyTrademarkAttribute>(assembly);

            if (trademarkAttr != null)
            {
                Add(InfoItem.trademark, trademarkAttr.Trademark);
            }
            else
            {
                Add(InfoItem.trademark, string.Empty);
            }

            Add(InfoItem.assemblyVersion, assembly.GetName().Version.ToString());

            AssemblyFileVersionAttribute fileVersionAttr =
                GetAssemblyAttribute <AssemblyFileVersionAttribute>(assembly);

            if (fileVersionAttr != null)
            {
                Add(InfoItem.fileVersion, fileVersionAttr.Version);
            }
            else
            {
                Add(InfoItem.fileVersion, string.Empty);
            }

            GuidAttribute guidAttr = GetAssemblyAttribute <GuidAttribute>(assembly);

            if (guidAttr != null)
            {
                Add(InfoItem.guid, guidAttr.Value);
            }
            else
            {
                Add(InfoItem.guid, string.Empty);
            }

            NeutralResourcesLanguageAttribute languageAttr =
                GetAssemblyAttribute <NeutralResourcesLanguageAttribute>(assembly);

            if (languageAttr != null)
            {
                Add(InfoItem.language, languageAttr.CultureName);
            }
            else
            {
                Add(InfoItem.language, string.Empty);
            }
        }
Exemplo n.º 16
0
        public static void Main(string[] args)
        {
            bool mutexReserved;

            using (Mutex appMutex = new Mutex(true, "SpeditGlobalMutex", out mutexReserved))
            {
                if (mutexReserved)
                {
                    bool ProgramIsNew = false;
#if !DEBUG
                    try
                    {
#endif
                    Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
#if !DEBUG
                    ProfileOptimization.SetProfileRoot(Environment.CurrentDirectory);
                    ProfileOptimization.StartProfile("Startup.Profile");
#endif
                    //todo implement own updater
                    Options = OptionsControl.Load(out ProgramIsNew);

                    Assembly assembly = Assembly.GetExecutingAssembly();
                    NeutralResourcesLanguageAttribute a = (NeutralResourcesLanguageAttribute)assembly.GetCustomAttribute(typeof(NeutralResourcesLanguageAttribute));
                    Culture.cultures = Culture.GetAvailableCultures();
                    CultureInfo defCultureInfo = new CultureInfo(string.IsNullOrEmpty(Options.Language) ? a.CultureName : Options.Language);
                    CultureInfo.DefaultThreadCurrentUICulture = defCultureInfo;
                    CultureInfo.DefaultThreadCurrentCulture   = defCultureInfo;

                    ConfigList = ConfigLoader.Load();
                    foreach (Config config in ConfigList.Configs.Where(config => config.Name == Options.SelectedConfig))
                    {
                        ConfigList.CurrentConfig = ConfigList.Configs.IndexOf(config);
                        break;
                    }
                    if (!Options.UseHardwareAcceleration)
                    {
                        RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
                    }
#if !DEBUG
                    if (ProgramIsNew)
                    {
                        if (Translations.AvailableLanguageIDs.Length > 0)
                        {
                            splashScreen.Close(new TimeSpan(0, 0, 1));
                            var languageWindow = new UI.Interop.LanguageChooserWindow(Translations.AvailableLanguageIDs, Translations.AvailableLanguages);
                            languageWindow.ShowDialog();
                            string potentialSelectedLanguageID = languageWindow.SelectedID;
                            if (!string.IsNullOrWhiteSpace(potentialSelectedLanguageID))
                            {
                                OptionsObject.Language = potentialSelectedLanguageID;
                                Translations.LoadLanguage(potentialSelectedLanguageID);
                            }
                            splashScreen.Show(false, true);
                        }
                    }
#endif
                    MainWindow = new MainWindow();
                    new PipeInteropServer(MainWindow).Start();
#if !DEBUG
                }
                catch (Exception e)
                {
                    File.WriteAllText("CRASH_" + Environment.TickCount.ToString() + ".txt", BuildExceptionString(e, "SPEDIT LOADING"));
                    MessageBox.Show("An error occured while loading." + Environment.NewLine + "A crash report was written in the editor-directory.",
                                    "Error while Loading",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    Environment.Exit(Environment.ExitCode);
                }
#endif
                    Application app = new Application();
#if !DEBUG
                    try
                    {
                        if (OptionsObject.Program_CheckForUpdates)
                        {
                            UpdateCheck.Check(true);
                        }
#endif
                    app.Run(MainWindow);
                    OptionsControl.Save();
#if !DEBUG
                }
                catch (Exception e)
                {
                    File.WriteAllText("CRASH_" + Environment.TickCount.ToString() + ".txt", BuildExceptionString(e, "SPEDIT MAIN"));
                    MessageBox.Show("An error occured." + Environment.NewLine + "A crash report was written in the editor-directory.",
                                    "Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    Environment.Exit(Environment.ExitCode);
                }
#endif
                }
                else
                {
                    try
                    {
                        StringBuilder sBuilder   = new StringBuilder();
                        bool          addedFiles = false;
                        for (int i = 0; i < args.Length; ++i)
                        {
                            if (!string.IsNullOrWhiteSpace(args[i]))
                            {
                                FileInfo fInfo = new FileInfo(args[i]);
                                if (fInfo.Exists)
                                {
                                    string ext = fInfo.Extension.ToLowerInvariant().Trim('.', ' ');
                                    //todo fix this?
                                    if (ext == "sp" || ext == "inc" || ext == "txt" || ext == "smx")
                                    {
                                        addedFiles = true;
                                        sBuilder.Append(fInfo.FullName);
                                        if ((i + 1) != args.Length)
                                        {
                                            sBuilder.Append("|");
                                        }
                                    }
                                }
                            }
                        }
                        if (addedFiles)
                        {
                            PipeInteropClient.ConnectToMasterPipeAndSendData(sBuilder.ToString());
                        }
                    }
                    catch (Exception) { } //dont f**k the user up with irrelevant data
                }
            }
        }
Exemplo n.º 17
0
        public AssemblyInformation(Assembly assembly)
        {
            // Get values from the assembly.
            AssemblyTitleAttribute titleAttr =
                GetAssemblyAttribute <AssemblyTitleAttribute>(assembly);

            if (titleAttr != null)
            {
                Title = titleAttr.Title;
            }

            AssemblyDescriptionAttribute assemblyAttr =
                GetAssemblyAttribute <AssemblyDescriptionAttribute>(assembly);

            if (assemblyAttr != null)
            {
                Description =
                    assemblyAttr.Description;
            }

            AssemblyCompanyAttribute companyAttr =
                GetAssemblyAttribute <AssemblyCompanyAttribute>(assembly);

            if (companyAttr != null)
            {
                Company = companyAttr.Company;
            }

            AssemblyProductAttribute productAttr =
                GetAssemblyAttribute <AssemblyProductAttribute>(assembly);

            if (productAttr != null)
            {
                Product = productAttr.Product;
            }

            AssemblyCopyrightAttribute copyrightAttr =
                GetAssemblyAttribute <AssemblyCopyrightAttribute>(assembly);

            if (copyrightAttr != null)
            {
                Copyright = copyrightAttr.Copyright;
            }

            AssemblyTrademarkAttribute trademarkAttr =
                GetAssemblyAttribute <AssemblyTrademarkAttribute>(assembly);

            if (trademarkAttr != null)
            {
                Trademark = trademarkAttr.Trademark;
            }

            AssemblyVersion = assembly.GetName().Version.ToString();

            AssemblyFileVersionAttribute fileVersionAttr =
                GetAssemblyAttribute <AssemblyFileVersionAttribute>(assembly);

            if (fileVersionAttr != null)
            {
                FileVersion =
                    fileVersionAttr.Version;
            }

            GuidAttribute guidAttr = GetAssemblyAttribute <GuidAttribute>(assembly);

            if (guidAttr != null)
            {
                Guid = guidAttr.Value;
            }

            NeutralResourcesLanguageAttribute languageAttr =
                GetAssemblyAttribute <NeutralResourcesLanguageAttribute>(assembly);

            if (languageAttr != null)
            {
                NeutralLanguage =
                    languageAttr.CultureName;
            }

            ComVisibleAttribute comAttr =
                GetAssemblyAttribute <ComVisibleAttribute>(assembly);

            if (comAttr != null)
            {
                IsComVisible = comAttr.Value;
            }
        }
    public bool NegTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest1: Call ctor with null reference");

        try
        {
            NeutralResourcesLanguageAttribute attr = new NeutralResourcesLanguageAttribute(null);
            TestLibrary.TestFramework.LogError("101.1", "ArgumentNullException exception does not thrown when calling ctor with null reference");
            retVal = false;
        }
        catch ( ArgumentNullException )
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("101.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }