Arnoldus The Multi Language Site in C#

Multi Language Site: DataBase Structures (Part 2.3)



This is the continuation of Part 2.2 (Multi Language Site: DataBase Structures: Media Classes)


Media Classes (Continued...)

As explained before, the classes define an album or a multi-media object as an object that references a single record for the language dependent fields: i.e. the “AlbumTitles” and “MediaText“ tables. It is also true that a multi-media object must belong to an album, therefore, a complete multi-media object contains also data from the albums tables. Thus a media object references four tables. Consider the following code, that retrieves the multi-media objects contained in an album:


/*** Object: StoredProcedure [dbo].[GetGalleryMedia]    Script Date: 07/18/2008 10:57:48 ***/

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
 
 
ALTER PROCEDURE [dbo].[GetGalleryMedia]
      @AlbumID int,
      @Application nvarchar(50),
      @IsPublic bit,
      @Lang char(2)
AS
      SELECT Media.*, MediaText.Caption, MediaText.Keywords, AlbumTitles.Title
      FROM    Albums INNER JOIN
              AlbumTitles ON Albums.AlbumID = AlbumTitles.AlbumID
              INNER JOIN Media ON Albums.AlbumID = Media.AlbumID
              INNER JOIN MediaText ON Media.MediaID = MediaText.MediaID
      WHERE
            [Media].[AlbumID] = @AlbumID
            AND ([Albums].[IsPublic] = @IsPublic
            OR [Albums].[IsPublic] = 1)
            AND [Albums].[Application] = @Application
            AND (AlbumTitles.Lang = @Lang)
            AND (MediaText.Lang = @Lang)
      RETURN


As you can see, the “MediaText.Caption” (media title), “MediaText.Keywords” (media keywords) and “AlbumTitles.Title“ (album title) are retrieved in the user language, as in the following code snippet that calls the stored procedure referenced before:


    static public List<Media> GetGalleryMedia (int AlbumID)
    {
        string strLanguage = ThisSession.Language;
        string strApplication = System.Convert.ToString (ConfigurationManager.AppSettings
               ["Application"]);
        using (SqlConnection connection = new SqlConnection
              (ConfigurationManager.ConnectionStrings["Personal"].ConnectionString))
        {
            using (SqlCommand command = new SqlCommand ("GetGalleryMedia", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add (new SqlParameter ("@AlbumID", AlbumID));
                command.Parameters.Add (new SqlParameter ("@IsPublic", Filter));
                command.Parameters.Add (new SqlParameter ("@Application", strApplication));
                command.Parameters.Add (new SqlParameter ("@Lang", strLanguage));
                connection.Open ();
                SqlDataReader reader = command.ExecuteReader ();
                List<Media> list = new List<Media> ();
                while (reader.Read ())
                {
                    Media media = MediaFromReader (reader);
                    list.Add (media);
                }
                reader.Close ();
                return list;
            }
        }
    }


Given that the multi-media files are stored in the file system of the server, it makes sense that the album name makes part of the tree name (such as (in C#): "~/Images/" + strAlbumName + "/Original Media/" + strFileName; or "~/Images/" + strAlbumName + "/ThumbNail Media/" + strFileName;). Which, for retrieval purposes, then is translated in the server's tree name using the “HttpContext.Current.Server.MapPath” function. However, as the album name now is different in each language, this does not work anymore. Therefore, to keep things easy, the albums table now contains the field “Directory”, which for compatibility reasons on creation is set to the English title. (see the previous page: stored procedure: “[dbo].[AddAlbum]”.) Since the treename is only required for file stream operations, those use a helper routine: “static string GetAlbumDirectory(int AlbumID)”.

Continue to: Multi Language Site: DataBase Structures (Part 2.4): Email Texts.