Beispiel #1
0
  }//public static void ResourceAdd()

  ///<summary>ResourceList</summary>
  public static void ResourceList
  (
   ref UtilityResourceArgument  utilityResourceArgument,
   ref string                   exceptionMessage
  )
  {
   
   HttpContext            httpContext            =  HttpContext.Current;
   IDictionaryEnumerator  iDictionaryEnumerator  =  null;
   ResXResourceReader     resXResourceReader     =  null;
   
   try
   {
    foreach( string filenameCurrent in utilityResourceArgument.resourceFilename )
    {
     // Create a ResXResourceReader for the file items.resx.
     resXResourceReader    =  new ResXResourceReader( filenameCurrent );

     // Create an IDictionaryEnumerator to iterate through the resources.
     iDictionaryEnumerator  =  resXResourceReader.GetEnumerator();       

     // Iterate through the resources and display the contents to the console.
     foreach ( DictionaryEntry  dictionaryEntry in resXResourceReader ) 
     {
      System.Console.WriteLine
      (
       dictionaryEntry.Key.ToString() + ":\t" + dictionaryEntry.Value.ToString()
      );
     }//foreach ( DictionaryEntry  dictionaryEntry in iDictionaryEnumerator )

     //Close the reader.
     resXResourceReader.Close();
    }//foreach( string filenameCurrent in utilityResourceArgument.resourceFilename )
   }//try
   catch( Exception exception )
   {
    exceptionMessage = "Exception: " + exception.Message;   	
   }//catch( Expression expression )
   finally
   {
    if ( resXResourceReader != null )
    {
     resXResourceReader.Close();
    }//if ( resXResourceReader != null ) 
   }//finally   	

   if ( exceptionMessage != null )
   {
    if ( httpContext == null )
    {
     System.Console.WriteLine( exceptionMessage );
    }//if ( httpContext == null )
    else
    {
     //httpContext.Response.Write( exceptionMessage );
    }//else 
   }//if ( exceptionMessage != null )

  }//public static void ResourceList()
Beispiel #2
0
  ///<summary>The entry point for the application.</summary>
  ///<param name="argv">A list of command line arguments</param>
  public static void Main
  (
   String[] argv
  )
  {
   Boolean                           booleanParseCommandLineArguments          =  false;
   string                            exceptionMessage                          =  null;     
   UtilityResourceArgument           utilityResourceArgument                   =  null;
   
   utilityResourceArgument                =  new UtilityResourceArgument();
   
   booleanParseCommandLineArguments =  UtilityParseCommandLineArgument.ParseCommandLineArguments
   ( 
    argv, 
    utilityResourceArgument
   );

   if ( booleanParseCommandLineArguments == false )
   {
    // error encountered in arguments. Display usage message
    System.Console.Write
    (
     UtilityParseCommandLineArgument.CommandLineArgumentsUsage( typeof ( UtilityResourceArgument ) )
    );
    return;
   }//if ( booleanParseCommandLineArguments  == false )

   if 
   ( 
    utilityResourceArgument.resourceAdd != null  &&
    !String.IsNullOrEmpty( utilityResourceArgument.resourceAddFilenameTarget )    
   ) 
   {
    ResourceAdd
    (
     ref utilityResourceArgument,
     ref exceptionMessage
    );
   }

   if ( utilityResourceArgument.resourceList )
   {
    ResourceList
    (
     ref utilityResourceArgument,
     ref exceptionMessage
    );
   }//if ( utilityResourceArgument.resourceList )
    
  }//static void Main( String[] argv ) 
Beispiel #3
0
  }//static void Main( String[] argv ) 

  ///<summary>ResourceAdd</summary>
  public static void ResourceAdd
  (
   ref UtilityResourceArgument  utilityResourceArgument,
   ref string                   exceptionMessage
  )
  {
   
   bool                  fileCreate          =  false;

   string[]              resourceAlias       =  null;
   string                resourceName        =  null;
   string                resourceType        =  null;
   string                resourceValue       =  null;
   
   HttpContext           httpContext         =  HttpContext.Current;
   System.Drawing.Image  image               =  null;
   ResXResourceWriter    resXResourceWriter  =  null;
   
   try
   {

    foreach( string resourceAddCurrent in utilityResourceArgument.resourceAdd )
    {
     resourceName   =  null;
     resourceType   =  null;
     resourceValue  =  null;
     
     if ( string.IsNullOrEmpty( resourceAddCurrent ) )
     { 
      continue;
     }//if ( !String.IsNullOrEmpty( resourceAddCurrent ) )

     resourceAlias = resourceAddCurrent.Split( DelimiterCharResourceAdd );

     if ( resourceAlias.Length < ResourceAddIndexRankType )
     {
      throw new Exception("/resourceAdd:name| value [|type]");
     }
     else if ( resourceAlias.Length > ResourceAddIndexRankType )
     {
      resourceType = resourceAlias[ ResourceAddIndexRankType ].Trim().ToUpper();
     }
     else
     {
      resourceType = ResourceTypeString;
     }

     resourceName   =  resourceAlias[ ResourceAddIndexRankName ].Trim();
     resourceValue  =  resourceAlias[ ResourceAddIndexRankValue ].Trim();

     if ( resourceName.Length < 1 )
     {
      throw new Exception("/resourceAdd:name| value [|type]");
     }//if ( resourceName.Length < 1 )
     
     if ( !fileCreate )
     {
      if ( File.Exists( utilityResourceArgument.resourceAddFilenameTarget ) )
      {
       if ( !utilityResourceArgument.resourceOverwrite )
       {
       	throw new Exception("/resourceAdd:name| value [|type] /resourceOverwrite");
       }//if ( !utilityResourceArgument.resourceOverwrite )
       File.Delete( utilityResourceArgument.resourceAddFilenameTarget );
      }//if ( File.Exists( utilityResourceArgument.resourceAddFilenameTarget ) )  
      resXResourceWriter = new ResXResourceWriter
      ( 
       utilityResourceArgument.resourceAddFilenameTarget 
      );
      fileCreate = true;
     }//if ( !fileCreate )

     switch ( resourceType )
     {
      case "":
      case ResourceTypeString:
       resXResourceWriter.AddResource( resourceName, resourceValue ); 
       break;
      case ResourceTypeFile:
       image = System.Drawing.Image.FromFile( resourceValue );
       resXResourceWriter.AddResource( resourceName, image ); 
       break;
     }//switch ( resourceType )

     #if (DEBUG)
      System.Console.WriteLine
      ( 
       "Name: {0} | Value: {1} | Type: {2}",
       resourceName,
       resourceValue,
       resourceType
      );
     #endif

    }//foreach( string resourceAddCurrent in resourceAdd )

    if ( resXResourceWriter != null )
    {
     resXResourceWriter.Generate();
     resXResourceWriter.Close();
    }//if ( resXResourceWriter. != null ) 
        
   }//try
   catch( InvalidOperationException exception )
   {
    exceptionMessage = "InvalidOperationException: " + exception.Message;   	
   }//catch( Expression expression )
   catch( Exception exception )
   {
    exceptionMessage = "Exception: " + exception.Message;   	
   }//catch( Expression expression )
   finally
   {
    if ( resXResourceWriter != null )
    {
     resXResourceWriter.Close();
    }//if ( resXResourceWriter. != null ) 
   }//finally

   if ( exceptionMessage != null )
   {
    if ( httpContext == null )
    {
     System.Console.WriteLine( exceptionMessage );
    }//if ( httpContext == null )
    else
    {
     //httpContext.Response.Write( exceptionMessage );
    }//else 
   }//if ( exceptionMessage != null )

  }//public static void ResourceAdd()