Ejemplo n.º 1
0
        public bool UpdateResourceString(string Value, string ResourceId, string ResourceSet, string LocaleId)
        {
            if (string.IsNullOrEmpty(Value))
            {
                return(Manager.DeleteResource(ResourceId, LocaleId, ResourceSet));
            }

            if (Manager.UpdateOrAdd(ResourceId, Value, LocaleId, ResourceSet, null) == -1)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
 public JsonResult SaveResource(string path, string key, string culture, string data)
 {
     try {
         var c = String.IsNullOrEmpty(culture) ? CultureInfo.InvariantCulture : CultureInfo.GetCultureInfo(culture);
         culture = c.TwoLetterISOLanguageName;
         c       = new CultureInfo(culture);
         // remove unwanted para elements
         if (data.StartsWith("<p>") && data.EndsWith("</p>"))
         {
             data = data.Substring(3, data.Length - 7);
         }
         DbResourceDataManager.UpdateOrAdd(key, data, c, path);
         // UNDO
         Stack q;
         if (Session[String.Format("Undo_{0}_{1}_{2}", path, key, culture)] == null)
         {
             q = new Stack();
             q.Push(data);
         }
         else
         {
             q = (Stack)Session[String.Format("Undo_{0}_{1}_{2}", path, key, culture)];
             q.Push(data);
         }
         Session[String.Format("Undo_{0}_{1}_{2}", path, key, culture)] = q;
         return(Json(new {
             msg = "OK (" + culture + ")", data
         })); // 0 (added) or 1 (updated)
     } catch (Exception ex) {
         return(Json(new {
             msg = ex.Message, data
         })); // 0 (added) or 1 (updated)
     }
 }
Ejemplo n.º 3
0
            private static void AddResourceToStore(string key, object value, string resourceSet, IServiceProvider serviceProvider)
            {
                // Use custom data manager to write the values into the database
                DbResourceDataManager Manager = new DbResourceDataManager();

                if (Manager.UpdateOrAdd(key, value, "", resourceSet, null) == -1)
                {
                    throw new InvalidOperationException("Resource update error: " + Manager.ErrorMessage);
                }
            }
Ejemplo n.º 4
0
        protected void btnFileUpload_Click(object sender, EventArgs e)
        {
#if OnlineDemo
            this.ErrorDisplay.ShowError(WebUtils.LRes("FeatureDisabled"));
            return;
#endif


            if (!FileUpload.HasFile)
            {
                return;
            }

            //FileInfo fi = new FileInfo(this.FileUpload.FileName);
            string Extension = Path.GetExtension(FileUpload.FileName).TrimStart('.');  // fi.Extension.TrimStart('.');

            string Filter = ",bmp,ico,gif,jpg,png,css,js,txt,wav,mp3,";
            if (Filter.IndexOf("," + Extension + ",") == -1)
            {
                ErrorDisplay.ShowError(WebUtils.LRes("InvalidFileUploaded"));
                return;
            }

            string FilePath = Server.MapPath(FileUpload.FileName);

            File.WriteAllBytes(FilePath, FileUpload.FileBytes);

            string ResourceId = txtNewResourceId.Text;

            // *** Try to add the file
            DbResourceDataManager Data = new DbResourceDataManager();
            if (Data.UpdateOrAdd(ResourceId, FilePath, txtNewLanguage.Text, ResourceSet, null, true) == -1)
            {
                ErrorDisplay.ShowError(WebUtils.LRes("ResourceUpdateFailed") + "<br/>" + Data.ErrorMessage);
            }
            else
            {
                ErrorDisplay.ShowMessage(WebUtils.LRes("ResourceUpdated"));
            }

            File.Delete(FilePath);

            lstResourceIds.Items.Add(ResourceId);
            lstResourceIds.SelectedValue = ResourceId;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes a resource either creating or updating an existing resource
        /// </summary>
        /// <param name="resourceId">Resource Id to write. Resource Ids can be any string up to 1024 bytes in length</param>
        /// <param name="value">Value to set the resource to</param>
        /// <param name="lang">Language as ieetf code: en-US, de-DE etc.
        /// Value can be left blank for Invariant/Default culture to set.
        /// </param>
        /// <param name="resourceSet">The resourceSet to store the resource on.
        /// If no resource set name is provided a default empty resource set is used.</param>
        /// <returns>true or false</returns>
        public static bool WriteResource(string resourceId, string value = null, string lang = null, string resourceSet = null)
        {
            if (lang == null)
            {
                lang = string.Empty;
            }
            if (resourceSet == null)
            {
                resourceSet = string.Empty;
            }
            if (value == null)
            {
                value = resourceId;
            }

            var db = new DbResourceDataManager();

            return(db.UpdateOrAdd(resourceId, value, lang, resourceSet, null) > -1);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Imports an individual ResX Resource file into the database
        /// </summary>
        /// <param name="FileName">Full path to the the ResX file</param>
        /// <param name="ResourceSetName">Name of the file or for local resources the app relative path plus filename (admin/default.aspx or default.aspx)</param>
        /// <param name="LocaleId">Locale Id of the file to import. Use "" for Invariant</param>
        /// <returns></returns>
        public bool ImportResourceFile(string FileName, string ResourceSetName, string LocaleId)
        {
            string FilePath = Path.GetDirectoryName(FileName) + "\\";

            DbResourceDataManager Data = new DbResourceDataManager();

            XmlDocument Dom = new XmlDocument();

            try
            {
                Dom.Load(FileName);
            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.Message;
                return(false);
            }

            XmlNodeList nodes = Dom.DocumentElement.SelectNodes("data");

            foreach (XmlNode Node in nodes)
            {
                string Value; // = Node.ChildNodes[0].InnerText;

                XmlNodeList valueNodes = Node.SelectNodes("value");
                if (valueNodes.Count == 1)
                {
                    Value = valueNodes[0].InnerText;
                }
                else
                {
                    Value = Node.InnerText;
                }

                string Name = Node.Attributes["name"].Value;
                string Type = null;
                if (Node.Attributes["type"] != null)
                {
                    Type = Node.Attributes["type"].Value;
                }

                string  Comment     = null;
                XmlNode commentNode = Node.SelectSingleNode("comment");
                if (commentNode != null)
                {
                    Comment = commentNode.InnerText;
                }


                if (string.IsNullOrEmpty(Type))
                {
                    Data.UpdateOrAdd(Name, Value, LocaleId, ResourceSetName, Comment);
                }
                else
                {
                    // File based resources are formatted: filename;full type name
                    string[] tokens = Value.Split(';');
                    if (tokens.Length > 0)
                    {
                        string ResFileName = FilePath + tokens[0];
                        if (File.Exists(ResFileName))
                        {
                            // DataManager knows about file resources and can figure type info
                            Data.UpdateOrAdd(Name, ResFileName, LocaleId, ResourceSetName, Comment, true);
                        }
                    }
                }
            }

            return(true);
        }