Example #1
0
 public virtual void Application_AcquireRequestState()
 {
     // For each request initialize the culture values with the
     // user language as specified by the browser.
     System.String[] lang = new System.String[] { Request.QueryString["lang"], null };
     if (this.Context.Session != null && this.Session["effectiveculture"] != null)
     {
         lang[1] = this.Session["effectiveculture"].ToString();
     }
     System.Globalization.CultureInfo culture = this.ParseCultures(lang, Request.UserLanguages);
     if (culture == null)
     {
         culture = invariant;
     }
     if (culture != null && lang[1] != culture.Name)
     {
         if (!culture.IsNeutralCulture)
         {
             System.Threading.Thread.CurrentThread.CurrentCulture = culture;
         }
         System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
         if (this.Context.Session != null)
         {
             Session["resources"]        = resources.GetResourceSet(culture, true, true);
             Session["effectiveculture"] = getEffectiveCulture(culture);
         }
     }
 }
Example #2
0
        public static bool Exists(string path)
        {
            if (string.IsNullOrEmpty(path) || path.Length <= _resourceFilePrefix.Length)
                return false;
            path = path.Substring(_resourceFilePrefix.Length).ToLower();
            if(_resourcePath==null)
            {
                _resourcePath = new Dictionary<string, string>();
                var culture = System.Threading.Thread.CurrentThread.CurrentCulture;
                var assembly = System.Reflection.Assembly.GetExecutingAssembly();
                var resourceName = assembly.GetName().Name + ".g";
                var resourceManager = new System.Resources.ResourceManager(resourceName, assembly);
                try
                {
                    var resourceSet = resourceManager.GetResourceSet(culture, true, true);
                    foreach (System.Collections.DictionaryEntry resource in resourceSet)
                    {
                        _resourcePath.Add(resource.Key.ToString(), "");
                    }
                }
                finally
                {
                    resourceManager.ReleaseAllResources();
                }
            }

            return _resourcePath.ContainsKey(path);
        }
        public override void OnPageShown()
        {
            if (!EnvUtils.RunningOnWindows())
            {
                return;
            }

            var rm = new System.Resources.ResourceManager("GitUI.Properties.Images", Assembly.GetExecutingAssembly());

            // dummy request; for some strange reason the ResourceSets are not loaded untill after the first object request... bug?
            rm.GetObject("dummy");

            using System.Resources.ResourceSet resourceSet = rm.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
            foreach (DictionaryEntry icon in resourceSet.Cast <DictionaryEntry>().OrderBy(icon => icon.Key))
            {
                if (icon.Value is Bitmap bitmap)
                {
                    EmbeddedIcons.Images.Add(icon.Key.ToString(), bitmap.AdaptLightness());
                }
            }

            resourceSet.Close();
            rm.ReleaseAllResources();

            lvScripts.LargeImageList     =
                lvScripts.SmallImageList = EmbeddedIcons;
            _imagsLoaded = true;

            if (_scripts is object)
            {
                BindScripts(_scripts, null);
            }
        }
Example #4
0
        public static string GetResxValByKey(string key, string lang = "en-US")
        {
            string baseName = string.Empty;

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);

            if (lang.Equals("fr-FR"))
            {
                baseName = "ApniMaa.Globalization.fr-FR";
            }
            if (lang.Equals("en-US"))
            {
                baseName = "ApniMaa.Globalization.en-US";
            }
            if (string.IsNullOrEmpty(baseName))
            {
                return(string.Empty);
            }

            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(baseName, (new GlobalizationCulture()).GetType().Assembly);

            var entry =
                rm.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
                .OfType <DictionaryEntry>()
                .FirstOrDefault(e => e.Key.ToString() == key);

            var value = entry.Value.ToString();

            return(value);
        }
Example #5
0
        /// <summary>
        /// 언어별 리소스 데이터를 반환
        /// </summary>
        /// <param name="ResourceManager">리소스매니저</param>
        /// <returns>Json형의 key & value로 리소스 내용을 반환</returns>
        public static string GetResourceJsonKeyValue(System.Resources.ResourceManager ResourceManager)
        {
            string _retValue = string.Empty;

            int i = 0;

            _retValue = "{";
            CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(GetCurrentCultureName);

            System.Resources.ResourceSet resourceSet = ResourceManager.GetResourceSet(cultureInfo, true, true);
            foreach (System.Collections.DictionaryEntry entry in resourceSet)
            {
                if (i == 0)
                {
                    _retValue += entry.Key.ToString() + ": \"" + entry.Value.ToString() + "\"";
                }
                else
                {
                    _retValue += ", " + entry.Key.ToString() + ": \"" + entry.Value.ToString() + "\"";
                }
                i++;
            }
            _retValue += "};";

            return(_retValue);
        }
        /// <summary>
        /// This method is used for get the label information from resource file according to navigation id.
        /// </summary>
        /// <param name="navigationId"></param>
        /// <returns></returns>
        public List <ResourceKeyValueModel> GetLabelInfoValues(int navigationId)
        {
            try
            {
                List <ResourceKeyValueModel>     arrayList = new List <ResourceKeyValueModel>();
                ResourceKeyValueModel            objResourceKeyValueModel = new ResourceKeyValueModel();
                System.Resources.ResourceManager rm = new System.Resources.ResourceManager("GEE_Web.Resource", this.GetType().Assembly);

                var entry =
                    rm.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
                    .OfType <DictionaryEntry>();


                var abc = entry.Where(a => a.Key.ToString().Contains(navigationId.ToString())).ToList();
                foreach (var item in abc)
                {
                    if (item.Key.ToString().ToLower().Contains("lbl"))
                    {
                        objResourceKeyValueModel.Key   = item.Key.ToString();
                        objResourceKeyValueModel.Value = item.Value.ToString();
                        arrayList.Add(objResourceKeyValueModel);
                    }
                }
                return(arrayList);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        //public static List<T> ConvertDataTable<T>(DataTable dt)
        //{
        //    List<T> data = new List<T>();
        //    foreach (DataRow row in dt.Rows)
        //    {
        //        T item = GetItem<T>(row);
        //        data.Add(item);
        //    }
        //    return data;
        //}
        //public static T GetItem<T>(DataRow dr)
        //{
        //    Type temp = typeof(T);
        //    T obj = Activator.CreateInstance<T>();

        //    foreach (DataColumn column in dr.Table.Columns)
        //    {
        //        foreach (PropertyInfo pro in temp.GetProperties())
        //        {
        //            if (pro.Name.ToLower() == column.ColumnName.ToLower())
        //                pro.SetValue(obj, dr[column.ColumnName], null);
        //            else
        //                continue;
        //        }
        //    }
        //    return obj;
        //}

        /// <summary>
        /// This method is used to get value from rex file based on Key
        /// Added by Jiya
        /// Addded when 09-April-2018
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string  GetKeyValueFromResx(string keys)
        {
            try
            {
                string    keyValue = string.Empty;
                string [] splkeys  = keys.Split(',');
                List <ResourceKeyValueModel>     arrayList = new List <ResourceKeyValueModel>();
                ResourceKeyValueModel            objResourceKeyValueModel = new ResourceKeyValueModel();
                System.Resources.ResourceManager rm = new System.Resources.ResourceManager("GEE_Web.Resource", this.GetType().Assembly);

                var entry =
                    rm.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
                    .OfType <DictionaryEntry>();

                for (int i = 0; i < splkeys.Length; i++)
                {
                    var value = entry.Where(a => a.Key.ToString() == splkeys[i].ToString()).FirstOrDefault();
                    if (value.Value != null)
                    {
                        keyValue += value.Value.ToString() + ",";
                    }
                    else
                    {
                        keyValue += splkeys[i].ToString() + ",";
                    }
                }

                return(keyValue.Remove(keyValue.Length - 1));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #8
0
 public static string GetResource(Type t, string name, string lang)
 {
     if (string.IsNullOrEmpty(name)) return string.Empty;
     System.Resources.ResourceManager rm = new System.Resources.ResourceManager(t);
     System.Resources.ResourceSet rs = rm.GetResourceSet(new System.Globalization.CultureInfo(lang), true, true);
     return rs.GetString(name);
 }
        public override void OnPageShown()
        {
			if (EnvUtils.RunningOnWindows())
			{
				System.Resources.ResourceManager rm =
					new System.Resources.ResourceManager("GitUI.Properties.Resources",
								System.Reflection.Assembly.GetExecutingAssembly());

				// dummy request; for some strange reason the ResourceSets are not loaded untill after the first object request... bug?
				rm.GetObject("dummy");

				System.Resources.ResourceSet resourceSet = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true);

				contextMenuStrip_SplitButton.Items.Clear();

				foreach (System.Collections.DictionaryEntry icon in resourceSet)
				{
					//add entry to toolstrip
					if (icon.Value.GetType() == typeof(Icon))
					{
						//contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)((Icon)icon.Value).ToBitmap(), SplitButtonMenuItem_Click);
					}
					else if (icon.Value.GetType() == typeof(Bitmap))
					{
						contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)icon.Value, SplitButtonMenuItem_Click);
					}
					//var aa = icon.Value.GetType();
				}

				resourceSet.Close();
				rm.ReleaseAllResources();
			}
        }
        public override void OnPageShown()
        {
            if (EnvUtils.RunningOnWindows())
            {
                System.Resources.ResourceManager rm =
                    new System.Resources.ResourceManager("GitUI.Properties.Resources",
                                                         System.Reflection.Assembly.GetExecutingAssembly());

                // dummy request; for some strange reason the ResourceSets are not loaded untill after the first object request... bug?
                rm.GetObject("dummy");

                System.Resources.ResourceSet resourceSet = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true);

                contextMenuStrip_SplitButton.Items.Clear();

                foreach (System.Collections.DictionaryEntry icon in resourceSet)
                {
                    //add entry to toolstrip
                    if (icon.Value.GetType() == typeof(Icon))
                    {
                        //contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)((Icon)icon.Value).ToBitmap(), SplitButtonMenuItem_Click);
                    }
                    else if (icon.Value.GetType() == typeof(Bitmap))
                    {
                        contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)icon.Value, SplitButtonMenuItem_Click);
                    }
                    //var aa = icon.Value.GetType();
                }

                resourceSet.Close();
                rm.ReleaseAllResources();
            }
        }
Example #11
0
        public IEnumerable <System.Globalization.CultureInfo> GetAvailableCultures(Type type)
        {
            List <System.Globalization.CultureInfo> result = new List <System.Globalization.CultureInfo>();
            var rm = new System.Resources.ResourceManager(type);

            System.Globalization.CultureInfo[] cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures);
            foreach (System.Globalization.CultureInfo culture in cultures)
            {
                try
                {
                    if (culture.Equals(System.Globalization.CultureInfo.InvariantCulture))
                    {
                        continue;                                                                    //do not use "==", won't work
                    }
                    var rs = rm.GetResourceSet(culture, true, false);
                    if (rs != null)
                    {
                        result.Add(culture);
                    }
                }
                catch (System.Globalization.CultureNotFoundException)
                {
                    //NOP
                }
                rm.ReleaseAllResources();
            }
            return(result);
        }
Example #12
0
        public static bool Exists(string path)
        {
            if (string.IsNullOrEmpty(path) || path.Length <= _resourceFilePrefix.Length)
            {
                return(false);
            }
            path = path.Substring(_resourceFilePrefix.Length).ToLower();
            if (_resourcePath == null)
            {
                _resourcePath = new Dictionary <string, string>();
                var culture         = System.Threading.Thread.CurrentThread.CurrentCulture;
                var assembly        = System.Reflection.Assembly.GetExecutingAssembly();
                var resourceName    = assembly.GetName().Name + ".g";
                var resourceManager = new System.Resources.ResourceManager(resourceName, assembly);
                try
                {
                    var resourceSet = resourceManager.GetResourceSet(culture, true, true);
                    foreach (System.Collections.DictionaryEntry resource in resourceSet)
                    {
                        _resourcePath.Add(resource.Key.ToString(), "");
                    }
                }
                finally
                {
                    resourceManager.ReleaseAllResources();
                }
            }

            return(_resourcePath.ContainsKey(path));
        }
Example #13
0
        /// <include file='doc\Localizer.uex' path='docs/doc[@for="LocalizationExtenderProvider.LocalizationExtenderProvider"]/*' />
        /// <devdoc>
        /// <para>Initializes a new instance of the <see cref='System.ComponentModel.Design.LocalizationExtenderProvider'/> class using the
        ///    specified service provider and base component.</para>
        /// </devdoc>
        public LocalizationExtenderProvider(ISite serviceProvider, IComponent baseComponent)
        {
            this.serviceProvider = (IServiceProvider)serviceProvider;
            this.baseComponent   = baseComponent;

            if (serviceProvider != null)
            {
                IExtenderProviderService es = (IExtenderProviderService)serviceProvider.GetService(typeof(IExtenderProviderService));
                if (es != null)
                {
                    es.AddExtenderProvider(this);
                }
            }
            language = CultureInfo.InvariantCulture;

            //We need to check to see if our baseComponent has its localizable value persisted into
            //the resource file.  If so, we'll want to "inherit" this value for our baseComponent.
            //This enables us to create Inherited forms and inherit the  localizable props from the base.
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(baseComponent.GetType());
            if (resources != null)
            {
                System.Resources.ResourceSet rSet = resources.GetResourceSet(language, true, false);
                if (rSet != null)
                {
                    object objLocalizable = rSet.GetObject("$this.Localizable");
                    if (objLocalizable is bool)
                    {
                        defaultLocalizable = (bool)objLocalizable;
                        this.localizable   = defaultLocalizable;
                    }
                }
            }
        }
Example #14
0
        public void Copiar(string carpeta, System.Resources.ResourceManager rMgr)
        {
            if (_listaCopiados.Contains(rMgr))
            {
                return;
            }
            else
            {
                _listaCopiados.Add(rMgr);
            }

            List <string> listaReportes = GetListaReportes();

            if (!Directory.Exists(carpeta))
            {
                Directory.CreateDirectory(carpeta);
            }

            System.Resources.ResourceSet r = rMgr.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true);

            foreach (string nombreReporte in listaReportes)
            {
                string archivoReporte = Path.Combine(carpeta, nombreReporte + ".rpt");
                byte[] bytesReporte   = (byte[])r.GetObject(nombreReporte);
                if (bytesReporte != null)
                {
                    if (File.Exists(archivoReporte))
                    {
                        File.Delete(archivoReporte);
                    }
                    File.WriteAllBytes(archivoReporte, bytesReporte);
                }
            }
        }
Example #15
0
        public static MvcHtmlString Localize(this HtmlHelper htmlHelper, string key)
        {
            var rm      = new System.Resources.ResourceManager("FasTnT.Web.Internationalization.Resources", typeof(Resources).Assembly);
            var culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            var entry   = rm.GetResourceSet(culture, true, true).OfType <DictionaryEntry>().FirstOrDefault(e => e.Key.ToString() == key);

            return(MvcHtmlString.Create(entry.Value?.ToString() ?? key));
        }
Example #16
0
 public static string GetResource(Type t, string name, string lang)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(string.Empty);
     }
     System.Resources.ResourceManager rm = new System.Resources.ResourceManager(t);
     System.Resources.ResourceSet     rs = rm.GetResourceSet(new System.Globalization.CultureInfo(lang), true, true);
     return(rs.GetString(name));
 }
Example #17
0
        private static string GetResxNameByValue(string filename, string value, Type type)
        {
            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(filename, type.Assembly);
            var entry = rm.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true)
                        .OfType <DictionaryEntry>()
                        .FirstOrDefault(e => e.Value.ToString() == value);

            var key = entry.Key.ToString();

            return(key);
        }
        private object TranslateBack(string value, System.Resources.ResourceManager resourceManager, CultureInfo culture, Type targetType)
        {
            var resourceSet = resourceManager.GetResourceSet(culture, true, true);

            foreach (DictionaryEntry entry in resourceSet)
            {
                if (entry.Value.ToString() == value)
                {
                    return(Enum.Parse(targetType, entry.Key.ToString()));
                }
            }

            return(value);
        }
Example #19
0
        public string GetResourceNameByValue(string value)
        {
            System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("MISA.ImportDemo.Core.Properties.Resources", this.GetType().Assembly);
            var entry =
                resourceManager.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
                .OfType <DictionaryEntry>()
                .FirstOrDefault(e => e.Value.ToString() == value);

            if (entry.Key == null)
            {
                return(null);
            }
            return(entry.Key.ToString());
        }
Example #20
0
        /// <summary>
        /// Lấy tên Resource theo giá trị (VD lấy ra Enum_Gender_Male theo giá trị là "Nam")
        /// </summary>
        /// <param name="value">Giá trị truyền vào</param>
        /// <param name="enumNameStringContains">Contain của Resource (VD:Enum_Gender)</param>
        /// <returns>Tên đầy đủ của Resource (Enum_Gender_Male)</returns>
        /// CreatedBy: NVMANH (10/06/2020)
        public string GetResourceNameByValue(string value, string enumNameStringContains)
        {
            var enumValueRemoveDiacritic = RemoveDiacritics(value);

            System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("MISA.ImportDemo.Core.Properties.Resources", this.GetType().Assembly);
            var entry =
                resourceManager.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
                .OfType <DictionaryEntry>()
                .FirstOrDefault(e => RemoveDiacritics(e.Value.ToString()) == enumValueRemoveDiacritic && e.Key.ToString().Contains(enumNameStringContains));

            if (entry.Key == null)
            {
                return(null);
            }
            return(entry.Key.ToString());
        }
Example #21
0
 public static void ChangeLocale(this CultureInfo culture)
 {
     if (culture is CultureInfo && resourceCulture != culture)
     {
         resourceSet = resourceMan.GetResourceSet(culture, true, true);
         //Properties.Resources.Culture = culture;
         resourceCulture = culture;
         if (_be_locale_ == null)
         {
             _be_locale_ = new Dictionary <FrameworkElement, bool>();
         }
         else
         {
             _be_locale_.Clear();
         }
     }
 }
Example #22
0
 private string GetImage()
 {
     System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
     System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture;
     string resourceName = asm.GetName().Name + ".g";
     System.Resources.ResourceManager rm = new System.Resources.ResourceManager(resourceName, asm);
     System.Resources.ResourceSet resourceSet = rm.GetResourceSet(culture, true, true);
     List<string> resources = new List<string>();
     foreach (DictionaryEntry resource in resourceSet)
     {
         if(((string)resource.Key).StartsWith("images/splash%20screens/"))
         resources.Add((string)resource.Key);
     }
     rm.ReleaseAllResources();
     Random r = new Random();
     int i = r.Next(0, resources.Count());
     return resources[i];
 }
        public static List <string> GetImageListFromDLL(string assemblyName)
        {
            Assembly asm = Assembly.LoadFrom(assemblyName + (assemblyName.Contains(".dll") ? "" : ".dll"));

            System.Globalization.CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture;
            string resourceName = asm.GetName().Name + ".g";

            System.Resources.ResourceManager rm          = new System.Resources.ResourceManager(resourceName, asm);
            System.Resources.ResourceSet     resourceSet = rm.GetResourceSet(culture, true, true);
            List <string> resources = new List <string>();

            foreach (System.Collections.DictionaryEntry resource in resourceSet)
            {
                resources.Add((string)resource.Key);
            }
            rm.ReleaseAllResources();
            return(resources);
        }
        public static IEnumerable <object> GetResourcePaths(Assembly assembly)
        {
            var culture         = System.Threading.Thread.CurrentThread.CurrentCulture;
            var resourceName    = assembly.GetName().Name + ".g";
            var resourceManager = new System.Resources.ResourceManager(resourceName, assembly);

            try
            {
                var resourceSet = resourceManager.GetResourceSet(culture, true, true);

                foreach (System.Collections.DictionaryEntry resource in resourceSet)
                {
                    yield return(resource.Key);
                }
            }
            finally
            {
                resourceManager.ReleaseAllResources();
            }
        }
Example #25
0
        private string GetResxNameByValue(string value)
        {
            var key = "";

            try
            {
                System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Resources.Einvoice", Assembly.Load("App_GlobalResources"));

                var entry = rm.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
                            .OfType <DictionaryEntry>()
                            .FirstOrDefault(e => e.Key.ToString() == value);

                key = entry.Value.ToString();
            }
            catch
            {
                key = value;
            }
            return(key);
        }
Example #26
0
 public static void LoadDLLResources()
 {
     try
     {
         Assembly myAssembly = Assembly.Load("UniGitResources");
         var      rc         = new System.Resources.ResourceManager("UniGitResources.Properties.Resources", myAssembly);
         foreach (DictionaryEntry e in rc.GetResourceSet(CultureInfo.InvariantCulture, true, true))
         {
             if (e.Value.GetType().Name == "Bitmap")
             {
                 textures.Add((string)e.Key, LoadTextureFromBitmap((string)e.Key, e.Value));
             }
         }
         rc.ReleaseAllResources();
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
Example #27
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("EmployeeManagement.UI.Settings.Localization.Resource", GetType().Assembly);

            var key = resourceManager.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentUICulture, true, true)
                      .OfType <DictionaryEntry>()
                      .FirstOrDefault(x => x.Value.ToString() == (string)value).Key.ToString();

            if (Enum.IsDefined(typeof(Sex), key))
            {
                return((Sex)Enum.Parse(typeof(Sex), key));
            }

            if (Enum.IsDefined(typeof(Profession), key))
            {
                return((Profession)Enum.Parse(typeof(Profession), key));
            }

            throw new NotImplementedException();
        }
Example #28
0
        /// <summary>
        /// Tries to find the dictionary in the Application Resources
        /// </summary>
        /// <param name="name">filename without extension</param>
        /// <returns></returns>
        private static Uri TryGetDictionaryUri(string name)
        {
            Assembly assembly      = Application.ResourceAssembly;
            var      resourcesName = assembly.GetName().Name + ".g";
            var      manager       = new System.Resources.ResourceManager(resourcesName, assembly);
            var      resourceSet   = manager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
            var      allXamlFiles  =
                from entry in resourceSet.OfType <DictionaryEntry>()
                let fileName = (string)entry.Key
                               where fileName.EndsWith(name.ToLower() + ".baml")
                               select fileName.Substring(0, fileName.Length - 5) + ".xaml";

            var f = allXamlFiles.FirstOrDefault();

            if (f != null)
            {
                Uri u = new Uri(f, UriKind.Relative);
                return(u);
            }
            return(null);
        }
Example #29
0
        public string GetConclusion(int row, int col, System.Globalization.CultureInfo culture, bool bStrict)
        {
            System.Resources.ResourceManager rm = GetResourceManager();
            if (null != rm)
            {
                string stringId = GetStringId(row, col);
                string result   = null;

                if (bStrict)
                {
                    System.Resources.ResourceSet rs = rm.GetResourceSet(culture, true, false);
                    if (null != rs)
                    {
                        result = rs.GetString(stringId);
                    }
                    else
                    {
                        _log.Debug($"ResourceSet could not be acquired for culture '{culture}' (strict).");
                    }
                }
                else
                {
                    result = rm.GetString(stringId, culture);
                }

                if ((null == result) || (0 == result.Length))
                {
                    _log.Debug($"No string with id='{stringId}' found for culture '{culture}'. ResourceManager: {rm.BaseName}");
                    return(string.Empty);
                }

                return(result);
            }
            else
            {
                _log.Debug("Resource manager not acquired.");
            }
            return(string.Empty);
        }
Example #30
0
        private void WindowBase_Loaded(object sender, RoutedEventArgs e)
        {
            //System.Windows.Resources.StreamResourceInfo sri = Application.GetResourceStream(new Uri("/Images/bg01.jpg", UriKind.RelativeOrAbsolute));
            //Console.WriteLine(sri.ContentType);

            //System.Windows.Media.Imaging.BitmapImage image = new BitmapImage();
            //image.BeginInit();
            //image.StreamSource = sri.Stream;
            //image.EndInit();
            //Image1.Source = image;

            //System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(this.GetType());
            //string resourceName = assembly.GetName().Name + ".g";
            //System.Resources.ResourceManager rsManager = new System.Resources.ResourceManager(resourceName, assembly);
            //using (System.Resources.ResourceSet set = rsManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true))
            //{
            //    System.IO.UnmanagedMemoryStream umn = (System.IO.UnmanagedMemoryStream)set.GetObject("Images/bg01.jpg", true);
            //    System.Windows.Media.Imaging.BitmapImage image = new BitmapImage();
            //    image.BeginInit();
            //    image.StreamSource = umn;
            //    image.EndInit();
            //    Image1.Source = image;
            //}

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(this.GetType());
            string resourceName = assembly.GetName().Name + ".g";

            System.Resources.ResourceManager rsManager = new System.Resources.ResourceManager(resourceName, assembly);
            using (System.Resources.ResourceSet set = rsManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true))
            {
                foreach (System.Collections.DictionaryEntry res in set)
                {
                    TextBox1.AppendText(res.Key.ToString());
                    TextBox1.AppendText("\t");
                    TextBox1.AppendText(res.Value.GetType().ToString());
                    TextBox1.AppendText("\r");
                }
            }
        }
Example #31
0
        private string GetImage()
        {
            System.Reflection.Assembly       asm     = System.Reflection.Assembly.GetExecutingAssembly();
            System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture;
            string resourceName = asm.GetName().Name + ".g";

            System.Resources.ResourceManager rm          = new System.Resources.ResourceManager(resourceName, asm);
            System.Resources.ResourceSet     resourceSet = rm.GetResourceSet(culture, true, true);
            List <string> resources = new List <string>();

            foreach (DictionaryEntry resource in resourceSet)
            {
                if (((string)resource.Key).StartsWith("images/splash%20screens/"))
                {
                    resources.Add((string)resource.Key);
                }
            }
            rm.ReleaseAllResources();
            Random r = new Random();
            int    i = r.Next(0, resources.Count());

            return(resources[i]);
        }
Example #32
0
        public void TestEnsureStaticImages()
        {
            var manager = new System.Resources.ResourceManager("XenAdmin.Properties.Resources",
                                                               typeof(XenAdmin.Properties.Resources).Assembly);

            var images = manager.GetResourceSet(CultureInfo.CurrentCulture, true, true)
                         .Cast <DictionaryEntry>().Where(e => e.Value is Bitmap).ToList();

            var staticImages = typeof(XenAdmin.Images.StaticImages).GetFields()
                               .Where(f => f.IsStatic && f.FieldType == typeof(Bitmap)).ToList();

            var extraImages = (from DictionaryEntry e in images
                               let key = e.Key as string
                                         where !staticImages.Exists(s => s.Name == key)
                                         select key).ToList();

            var extraStatics = (from FieldInfo s in staticImages
                                where !images.Exists(i => s.Name == (string)i.Key)
                                select s.Name).ToList();

            Assert.True(extraStatics.Count == 0 && extraImages.Count == 0,
                        $"Orphaned static images: {string.Join(", ", extraStatics)}\n" +
                        $"Resources without a static counterpart: {string.Join(", ", extraImages)}");
        }
Example #33
0
        static void Main(string[] args)
        {
            // ReadRessourceFile();
            string filename = @"C:\Program Files\paint.net\resx\PaintDotNet.Strings.3.resx";

            // .NET-Core resources are different ?
            System.Resources.ResourceReader rsxr = new System.Resources.ResourceReader(filename);

            System.Resources.ResourceManager RM = new System.Resources.ResourceManager("basename", System.Reflection.Assembly.GetExecutingAssembly());

            // ResourceNamespace.ResxFileName.ResourceManager.GetString("ResourceKey");

            var rs = RM.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, false, false);

            // rs.GetDefaultReader().
            // http://www.lhotka.net/weblog/NETCoreUsingExistingResxResourceFile.aspx


            foreach (System.Collections.DictionaryEntry d in rsxr)
            {
                if (d.Key != null)
                {
                    System.Console.Write(d.Key.ToString() + ":\t");
                }

                if (d.Value != null)
                {
                    System.Console.Write(d.Value.ToString());
                }

                System.Console.WriteLine();
            }

            System.Console.WriteLine(" --- Press any key to continue --- ");
            System.Console.ReadKey();
        }
Example #34
0
        public List <LanguageContent> GetByMoudelname(IConnectionHandler connectionHandler, string moudelname, string culture)
        {
            var key       = string.Format("{0}{1}", Constants.CultureInfo.CultureKey, moudelname);
            var managerDa = new LanguageContentDA(connectionHandler);
            var list      = managerDa.GetByMoudelname(key, culture);
            var assembly  = Assembly.LoadFrom(Assembly.GetExecutingAssembly()
                                              .EscapedCodeBase.ToLower()
                                              .Replace("common", moudelname.ToLower()));

            if (assembly != null)
            {
                var firstOrDefault =
                    assembly.GetTypes().FirstOrDefault(x => x.FullName.ToLower().Contains("resources." + moudelname.ToLower()));
                if (firstOrDefault != null)
                {
                    var resourceManager = new System.Resources.ResourceManager(firstOrDefault);
                    var cultureInfo     = CultureInfo.CreateSpecificCulture(culture);
                    var set             = resourceManager.GetResourceSet(cultureInfo, true, true);
                    foreach (DictionaryEntry de in set)
                    {
                        var format = string.Format("{0}{1}.{2}", Constants.CultureInfo.CultureKey, moudelname, de.Key);
                        if (list.Any(x => x.Key == format))
                        {
                            continue;
                        }
                        list.Add(new LanguageContent()
                        {
                            Key        = format,
                            Value      = de.Value.ToString(),
                            LanguageId = culture,
                        });
                    }
                }
            }
            return(list);
        }
Example #35
0
 public static DateTime ConvertDate(string xDateString, DateFormat xDateFormat, bool isMutiLang)
 {
     if (string.IsNullOrEmpty(xDateString)) return DateTime.MinValue;
     switch (xDateFormat)
     {
         case DateFormat.ddMMyyyys:
             string[] dateInfo = xDateString.Split('/');
             string dd = string.Empty;
             string MM = string.Empty;
             string yyyy = string.Empty;
             if (dateInfo.Length == 3)
             {
                 dd = dateInfo[0].Trim();
                 if (dd.Length != 2)
                 {
                     if (dd.Length > 2)
                     {
                         dd = dd.Substring(0, 2);
                     }
                     else if (dd.Length == 1 && dd != "0")
                     {
                         dd = "0" + dd;
                     }
                     else
                     {
                         dd = "01";
                     }
                 }
                 else if (dd == "00")
                 {
                     dd = "01";
                 }
                 MM = dateInfo[1].Trim();
                 if (MM.Length != 2)
                 {
                     if (MM.Length > 2)
                     {
                         MM = MM.Substring(0, 2);
                     }
                     else if (MM.Length == 1)
                     {
                         MM = "0" + MM;
                     }
                     else
                     {
                         MM = "01";
                     }
                 }
                 else if (MM == "00")
                 {
                     MM = "01";
                 }
                 yyyy = dateInfo[2].Trim();
                 if (yyyy.Length == 2)
                 {
                     yyyy += "20";
                 }
                 else if (yyyy.Length != 4)
                 {
                     if (yyyy.Length > 4)
                     {
                         yyyy = yyyy.Substring(0, 4);
                     }
                     else
                     {
                         yyyy = DateTime.Now.ToString("yyyy");
                     }
                 }
                 else if (yyyy == "0000")
                 {
                     yyyy = DateTime.Now.ToString("yyyy");
                 }
             }
             else
             {
                 return DateTime.MinValue;
             }
             xDateString = string.Format("{0}/{1}/{2}", dd, MM, yyyy);
             break;
         case DateFormat.ddMMyyyyn:
             break;
         case DateFormat.ddMMyyyysp:
             break;
         case DateFormat.ddMMyyyyd:
             break;
         case DateFormat.ddMMMyyyys:
             break;
         case DateFormat.ddMMMyyyyn:
             break;
         case DateFormat.ddMMMyyyysp:
             break;
         case DateFormat.ddMMMyyyyd:
             break;
         case DateFormat.MMMddyyyyspcm:
             break;
         case DateFormat.ddMMMyyyyspwt:
             break;
         case DateFormat.ddMMMyyyyHHmm:
             break;
         case DateFormat.yyyyMMMdd:
             break;
         case DateFormat.yyyyMMdd:
             break;
         case DateFormat.yyMMddHHmm:
             break;
         case DateFormat.MMMdd:
             break;
         case DateFormat.ddMMMyyyyddd:
             break;
         case DateFormat.ddMMMyyyyml:
             break;
         default:
             break;
     }
     MutiLanguage.Languages lang = MutiLanguage.GetCultureType();
     lang = isMutiLang ? lang : MutiLanguage.Languages.en_us;
     string langstr = isMutiLang ? MutiLanguage.EnumToString(lang) : MutiLanguage.EnumToString(MutiLanguage.Languages.en_us);
     System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Resources.Date));
     System.Resources.ResourceSet rs = rm.GetResourceSet(new System.Globalization.CultureInfo(langstr), true, true);
     return DateTime.ParseExact(xDateString, rs.GetString(xDateFormat.ToString()), System.Globalization.DateTimeFormatInfo.InvariantInfo);
 }
 /// <summary>    
 /// GetResourceDictionary    
 /// </summary>    
 public static ResourceDictionary GetResourceDictionary(string name)
 {
     var resourceName = name;
     if (string.IsNullOrEmpty(resourceName)) { resourceName = "themes/generic.xaml"; }
     ResourceDictionary retVal = null;
     if (_resourceDictionaryCache.TryGetValue(resourceName, out retVal)) { return retVal; }
     System.Reflection.Assembly assembly = typeof(ResourceManager).Assembly;
     string baseName = string.Format("{0}.g", assembly.FullName.Split(new char[] { ',' })[0]);
     string fullName = string.Format("{0}.resources", baseName);
     foreach (string s in assembly.GetManifestResourceNames())
     {
         if (s == fullName)
         {
             System.Resources.ResourceManager manager = new System.Resources.ResourceManager(baseName, assembly);
             System.Resources.ResourceSet set = manager.GetResourceSet(CultureInfo.InvariantCulture, true, true);
             foreach (System.Collections.DictionaryEntry entry in set)
             {
                 Console.WriteLine("{0} {1}", entry.Key, entry.Value);
             }
             using (System.IO.Stream stream = manager.GetStream(resourceName))
             {
                 using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
                 {
                     retVal = System.Windows.Markup.XamlReader.Load(stream) as ResourceDictionary;//reader.ReadToEnd()
                     if (retVal != null)
                     {
                         _resourceDictionaryCache.Add(resourceName, retVal);
                         return retVal;
                     }
                 }
             }
             break;
         }
     }
     return null;
 }
Example #37
0
 /// <summary>
 /// ��ָ����ʽ���ַ���ת��Ϊ����
 /// </summary>
 public static DateTime ConvertDate(string xDateString, string xDateFormat, bool isMutiLang)
 {
     MutiLanguage.Languages lang = MutiLanguage.GetCultureType();
     lang = isMutiLang ? lang : MutiLanguage.Languages.en_us;
     string langstr = isMutiLang ? MutiLanguage.EnumToString(lang) : MutiLanguage.EnumToString(MutiLanguage.Languages.en_us);
     System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Resources.Date));
     System.Resources.ResourceSet rs = rm.GetResourceSet(new System.Globalization.CultureInfo(langstr), true, true);
     string fmt = string.IsNullOrEmpty(rs.GetString(xDateFormat)) ? xDateFormat : rs.GetString(xDateFormat);
     return DateTime.ParseExact(xDateString, fmt, System.Globalization.DateTimeFormatInfo.InvariantInfo);
 }
Example #38
0
        /// <summary>
        /// Writes scripts (including localized script resources) to the specified stream
        /// </summary>
        /// <param name="scriptEntries">list of scripts to write</param>
        /// <param name="outputWriter">writer for output stream</param>
        private static void WriteScripts(List<ScriptEntry> scriptEntries, TextWriter outputWriter)
        {
            foreach (ScriptEntry scriptEntry in scriptEntries)
            {
                if (!scriptEntry.Loaded)
                {
                    if (!IsScriptCombinable(scriptEntry))
                    {
                        throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Combined script request includes uncombinable script \"{0}\".", scriptEntry.Name));
                    }

                    // This script hasn't been loaded by the browser, so add it to the combined script file
                    outputWriter.Write("//START ");
                    outputWriter.WriteLine(scriptEntry.Name);
                    string script = scriptEntry.GetScript();
                    if (WebResourceRegex.IsMatch(script))
                    {
                        // This script uses script substitution which isn't supported yet, so throw an exception since it's too late to fix
                        throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "ToolkitScriptManager does not support <%= WebResource/ScriptResource(...) %> substitution as used by script file \"{0}\".", scriptEntry.Name));
                    }
                    outputWriter.WriteLine(script);

                    // Save current culture and set the specified culture
                    CultureInfo currentUiCulture = Thread.CurrentThread.CurrentUICulture;
                    try
                    {
                        try
                        {
                            Thread.CurrentThread.CurrentUICulture = new CultureInfo(scriptEntry.Culture);
                        }
                        catch (ArgumentException)
                        {
                            // Invalid culture; proceed with default culture (just as for unsupported cultures)
                        }

                        // Write out the associated script resources (if any) in the proper culture
                        Assembly scriptAssembly = scriptEntry.LoadAssembly();
                        foreach (ScriptResourceAttribute scriptResourceAttribute in scriptAssembly.GetCustomAttributes(typeof(ScriptResourceAttribute), false))
                        {
                            if (scriptResourceAttribute.ScriptName == scriptEntry.Name)
                            {
                                // Found a matching script resource; write it out
                                outputWriter.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}={{", scriptResourceAttribute.TypeName));

                                // Get the script resource name (without the trailing ".resources")
                                string scriptResourceName = scriptResourceAttribute.ScriptResourceName;
                                if (scriptResourceName.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))
                                {
                                    scriptResourceName = scriptResourceName.Substring(0, scriptResourceName.Length - 10);
                                }

                                // Load a ResourceManager/ResourceSet and walk through the list to output them all
                                System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager(scriptResourceName, scriptAssembly);
                                using (System.Resources.ResourceSet resourceSet = resourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, true))
                                {
                                    bool first = true;
                                    foreach (System.Collections.DictionaryEntry de in resourceSet)
                                    {
                                        if (!first)
                                        {
                                            // Need a comma between all entries
                                            outputWriter.Write(",");
                                        }
                                        // Output the entry
                                        string name = (string)de.Key;
                                        string value = resourceManager.GetString(name);
                                        outputWriter.Write(string.Format(CultureInfo.InvariantCulture, "\"{0}\":\"{1}\"", QuoteString(name), QuoteString(value)));
                                        first = false;
                                    }
                                }
                                outputWriter.WriteLine("};");
                            }
                        }

                    }
                    finally
                    {
                        // Restore culture
                        Thread.CurrentThread.CurrentUICulture = currentUiCulture;
                    }

                    // Done with this script
                    outputWriter.Write("//END ");
                    outputWriter.WriteLine(scriptEntry.Name);
                }

                // This script is now (or will be soon) loaded by the browser
                scriptEntry.Loaded = true;
            }
        }