/// <summary>
        /// The main method to retrieve a specific resource key. The provider
        /// internally handles resource fallback based on the ResourceSet implementation.
        /// </summary>
        /// <param name="ResourceKey"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        object IResourceProvider.GetObject(string ResourceKey, CultureInfo culture)
        {
            
            object value = this.ResourceManager.GetObject(ResourceKey, culture);

            // If the value is still null and we're at the invariant culture
            // let's add a marker that the value is missing
            // this also allows the pre-compiler to work and never return null
            if (value == null && (culture == null || culture == CultureInfo.InvariantCulture) )
            {
                // No entry there
                value =  "";

                if (DbResourceConfiguration.Current.AddMissingResources)
                {
                    // Add invariant resource
                    DbResourceDataManager Data = new DbResourceDataManager();
                    if (!Data.ResourceExists(ResourceKey,"",this._className))
                        Data.UpdateOrAdd(ResourceKey,"*** Missing","",this._className,null);
                }                
            }

            return value;
        }
    /// <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;
    }
        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;
        }
Esempio n. 4
0
    /// <summary>
    /// Writes a resource either creating or updating an existing resource 
    /// </summary>
    /// <param name="resourceId"></param>
    /// <param name="value"></param>
    /// <param name="lang"></param>
    /// <param name="resourceSet"></param>
    /// <returns></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;
    }
 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);
 }