public ResXViewForm(string fileName)
        {
            const int BASEWIDTH = 1000;
            const int BASEHEIGHT = 250;
            ClientSize = new Size((BASEWIDTH + 20), BASEHEIGHT + 100);

            resxFile = new FileInfo(fileName);

            using (var resxSet = new ResXResourceSet(resxFile.FullName))
            {
                Text = resxSet.GetString("FormTitle");
                Icon = (Icon)resxSet.GetObject("ShieldIcon");
            }

            const int margin = 10;
            var resList = new ListView
            {
                Bounds = new Rectangle(new Point(margin, margin), new Size(BASEWIDTH, BASEHEIGHT)),
                View = View.Details,
                GridLines = true,
            };

            var columnWidth = (resList.ClientSize.Width / 3);
            resList.Columns.Add("Resource Name", columnWidth);
            resList.Columns.Add("Type", columnWidth);
            resList.Columns.Add("Value", columnWidth);

            using (var resxReader = new ResXResourceReader(resxFile.FullName))
            {
                foreach (DictionaryEntry entry in resxReader)
                {
                    var resItem = new ListViewItem((string)entry.Key);
                    resItem.SubItems.Add(entry.Value.GetType().FullName);
                    resItem.SubItems.Add(entry.Value.ToString());
                    resList.Items.Add(resItem);
                }
            }

            var resxButton = new Button
            {
                Text = "Show ResX",
                Location = new Point(resList.Bounds.Left, resList.Bounds.Bottom + margin)
            };
            resxButton.Click += (sender, args) => Process.Start("Notepad.exe", resxFile.FullName);

            var exitButton = new Button { Text = "Exit" };
            exitButton.Location = new Point(resList.Bounds.Right - exitButton.Width, resList.Bounds.Bottom + margin);
            exitButton.Click += (sender, args) => Application.Exit();

            FormBorderStyle = FormBorderStyle.Sizable;
            MaximizeBox = true;
            MinimizeBox = false;
            StartPosition = FormStartPosition.CenterScreen;

            Controls.Add(resList);
            Controls.Add(resxButton);
            Controls.Add(exitButton);

            InitializeComponent();
        }
 /// <summary>
 /// function to get the value from the resource for a key in Views
 /// </summary>
 /// <param name="currentContext"></param>
 /// <param name="resourceFileName"></param>
 /// <param name="keyName"></param>
 /// <returns></returns>
 public static string GetKeyValue(HttpContext currentContext, string resourceFileName, string keyName)
 {
     string keyValue = "";
     string sResxPath = GetResourceFilePath(resourceFileName, CultureInfo.CurrentCulture.Name);
     if (!File.Exists(sResxPath))
     {
         sResxPath = sResxPath.Replace(CultureInfo.CurrentCulture.Name, "en-IN");
     }
     using (ResXResourceSet resxSet = new ResXResourceSet(sResxPath))
     {
         keyValue = resxSet.GetString(keyName);
     }
     return keyValue;
 }
		protected override ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) {
			
			ResourceSet rs = (ResourceSet) base.ResourceSets[culture];
			
			if (rs == null) {

                string fileName = GetFileName(culture);

                if (fileName == null) {
					return base.InternalGetResourceSet(culture, createIfNotExists, tryParents);
				}

                rs = new ResXResourceSet(fileName);

				if (rs != null) {
					base.ResourceSets.Add(culture, rs);
				}
			}
			return rs;
		}
        public string getObjectSearchPath(string objectPath)
        {
            string objectID = "";
            string pageName = getResourceFileName(objectPath);

            if (pageName != null)
            {
                string objectName = getPageObjectName(objectPath);
                try
                {
                    ResXResourceSet resxSet = new ResXResourceSet(pageName);
                    objectID = resxSet.GetString(objectName);
                }
                catch (Exception e)
                {
                    //Reporter.Log(ReportLevel.Warn, "Object not found in the given file location : " + pageName + ". <br/> Actual Error : " + e.Message);
                }
            }
            return objectID;
        }
Exemple #5
0
        public ResourceSet LoadResource(string site, CultureInfo culture)
        {
            string key = MakeKey(site, culture);
            ResourceSet resource = m_Cache.Get(key) as ResourceSet;
            if (resource != null)
            {
                return resource;
            }

            string resourceFile = GetResourceFileName(site, culture);
            try
            {
                if (File.Exists(resourceFile))
                {
                    resource = new ResXResourceSet(resourceFile);
                }
            }
            catch (Exception ex)
            {
                throw new ResourceLoadingException(string.Format("load resource file {0} failed", resourceFile), ex);
            }
            if (resource == null)
            {
                resource = new EmptyResourceSet();
            }

            CacheItemPolicy policy = new CacheItemPolicy();
            policy.ChangeMonitors.Add(new PathsChangeMonitor(new List<string> { resourceFile }));
            m_Cache.Add(key, resource, policy);
            return resource;
        }
Exemple #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Ent.Ident = (int)(Session["prestador"]);

            if (!IsPostBack)                                        //   es la primera vez que cargo la pagina
            // agrego esto porque sino en cada seleccion del combo se recarga la pagina
            // y vuelve a selected value = 0
            {
                centro.DataSource = ObtenerCentro();
                centro.DataValueField = "IdentCentro";
                centro.DataTextField = "Nombrecentro";
                centro.DataBind();
                centro.Items.Insert(0, new ListItem("seleccione el Centro", ""));
                centro.SelectedIndex = 0;
            }

            // recupero el nombre de session prestador
            Label1.Text = Convert.ToString(Session["nombreprestador"]);

            using (ResXResourceSet resx = new ResXResourceSet("C:\\punto.net\\logeo\\logeo\\App_GlobalResources\\Resources ar-ES.resx"))
            {

                this.Label2.Text = resx.GetString("InicioLabel");

            }
            // obtener parametro 21
            SqlConnection dbconn21 = ConexionBd_Operaciones.ObtenerConexion();

            SqlCommand msc21 = new SqlCommand("dbo.ObtenerParametro", dbconn21);
            //parametros de entrada
            msc21.Parameters.AddWithValue("@parametro", 21);
            //parametros de salida
            msc21.Parameters.Add("@valor", SqlDbType.VarChar, 120);
            msc21.Parameters["@valor"].Direction = ParameterDirection.Output;
            try
            {
                if (dbconn21.State == ConnectionState.Closed)
                    dbconn21.Open();
                msc21.CommandType = CommandType.StoredProcedure;
                msc21.ExecuteNonQuery();
                string valorfila21 = msc21.Parameters["@valor"].Value.ToString();
                if (valorfila21 == "SI")
                {
                    si.Visible = true;
                    no.Visible = true;

                }

            }
            catch (Exception exp)
            {
                throw (exp);
            }
            finally
            {
                if (dbconn21.State == ConnectionState.Open)
                    dbconn21.Close();
            }
        }
Exemple #7
0
		private void buttonResXRead_Click(object sender, EventArgs e)
		{
		#if !ECMA_COMPAT && CONFIG_SERIALIZATION
			ResXResourceSet rs = new ResXResourceSet("test.resx");
			textBoxResXData.AppendText("my string:" + rs.GetObject("my string") + "\r\n");
			textBoxResXData.AppendText("my color:" + rs.GetObject("my color") + "\r\n");
			byte[] b = (byte[])rs.GetObject("my byte array") ;
			textBoxResXData.AppendText("my byte array:" + b.ToString()+ "\r\n");
			textBoxResXData.AppendText("{" + b[0] +"," + b[1]+"," + b[2]+"}");
		#endif
		}
Exemple #8
0
 private void OpenFile(string fileName)
 {
     if (!Path.GetExtension(fileName).Contains("resx"))
     {
         this.isDocumentOpen = false;
         this.ReportError("File must be a RESX file");
         return;
     }
     try
     {
         this.xmlDocument = new XmlDataDocument();
         this.xmlDocument.DataSet.ReadXmlSchema(fileName);
         stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
         this.xmlDocument.Load(stream);
         stream.Close();
         this.xmlGridView.DataSource = this.xmlDocument.DataSet;
         this.xmlGridView.DataMember = "data";
         stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
         this.resourceSet = new ResXResourceSet(stream);
     }
     catch (SecurityException exx)
     {
         Msbox.ShowMessage(this, "Cannot open file name " + fileName + "because\n" + exx.Message, "Error", Msbox.MsBoxIcon.Error, Msbox.MsBoxButtons.Close);
     }
     catch (FileNotFoundException)
     {
         Msbox.ShowMessage(this, "Cannot find file name " + fileName, "Error", Msbox.MsBoxIcon.Error, Msbox.MsBoxButtons.Close);
     }
     catch (UnauthorizedAccessException)
     {
         Msbox.ShowMessage(this, "Cannot access file name " + fileName + " because you are unauthorized to access the file", "Error", Msbox.MsBoxIcon.Error, Msbox.MsBoxButtons.Close);
     }
     catch (Exception exception)
     {
         this.isDocumentOpen = false;
         this.ReportError(exception.Message);
         return;
     }
     this.xmlFileName = fileName;
     this.InitGrid();
     foreach (DictionaryEntry entry in this.resourceSet)
     {
         if (entry.Value.GetType() != new string('a', 1).GetType())
         {
             foreach (DataGridViewRow row in (IEnumerable)this.xmlGridView.Rows)
             {
                 if (row.Cells["name"].Value.ToString() == entry.Key.ToString())
                 {
                     row.Visible = false;
                 }
             }
         }
     }
     int x = 1;
     foreach (DataGridViewRow row in (IEnumerable)this.xmlGridView.Rows)
     {
         row.Cells["id"].Value = x;
         x++;
     }
     this.resourceSet.Close();
     stream.Close();
     this.isDataModified = false;
     this.isDocumentOpen = true;
     this.init();
 }
Exemple #9
0
 static IEnumerable<Tuple<string, string>> GetValues(string resxFilePath)
 {
     var values = new List<Tuple<string, string>>();
     using (var resx = new ResXResourceSet(resxFilePath))
     {
         var en = resx.GetEnumerator();
         while (en.MoveNext())
         {
             var name = (string) en.Key;
             var value = resx
                 .GetString(name)
                 .Replace(Environment.NewLine, " ")
                 .Replace("&", "-");
             values.Add(new Tuple<string, string>(name, value));
         }
     }
     return values.OrderBy(x => x.Item1).ToList();
 }
Exemple #10
0
 private string GetResourceString(string key)
 {
     try
     {
         using (var resxSet = new ResXResourceSet(@"SpecificResources\SpecificResource.resx"))
         {
             return resxSet.GetString(key);
         }
     }
     catch
     {
         return null;
     }
 }
        private void LoadCurrentLanguage()
        {
            bool isEnglish = false;
            ResourceSet resourceSet = null;

            // Hmm, I must be blind, I can't find the way to access metadata strings though the ResourceSet,
            // so for now I'll load the XML document. :(
            XmlDocument resourceSetXml = new XmlDocument();

            for (CultureInfo culture = currentLanguage; !isEnglish && !string.IsNullOrEmpty(culture.Name); culture = culture.Parent)
            {
                if (culture.Name == "en") isEnglish = true;
            }

            if (File.Exists(TargetResXFileName))
            {
                resourceSet = new ResXResourceSet(TargetResXFileName);
                resourceSetXml.Load(TargetResXFileName);
            }

            var inheritedResources = InheritedResourceSets;
            foreach (var str in TranslatableStrings)
            {
                string inheritedTarget = null;
                foreach (var inheritedResourceSet in inheritedResources)
                {
                    inheritedTarget = inheritedResourceSet.GetString(str.Key);
                    if (!string.IsNullOrEmpty(inheritedTarget)) break;
                }

                // Special rule - as the program default resources are en English, always use them as the ultimate
                // fallback for any English language culture
                if (isEnglish && string.IsNullOrEmpty(inheritedTarget)) inheritedTarget = str.Source;

                string newTarget = "";
                string newTranslatedSource = "";
                if (resourceSet != null)
                {
                    newTarget = resourceSet.GetString(str.Key);
                    string xpathParm = EscapeXPathParameter(OrgSourceMetadataKeyPrefix + str.Key);

                    XmlNode metaDataValueNode = resourceSetXml.SelectSingleNode(string.Format("/root/metadata[@name={0}]/value", xpathParm));
                    if (metaDataValueNode != null) newTranslatedSource = metaDataValueNode.InnerText;
                }

                str.InheritedTarget = inheritedTarget;
                str.Target = newTarget;
                str.TranslatedSource = newTranslatedSource;
                str.ClearDirty();
            }
        }