Exemplo n.º 1
0
        /// <summary>
        /// The actual generation work is done here.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="language"></param>
        private void GenerateCollectionClasses(string path, string language)
        {
            string langExt = "";

            try {
                if (File.Exists(path))
                {
                    Log(Level.Info, path);
                    CollectionGenerator.CollectionGenerator generator = null;
                    // load the file
                    switch (language)
                    {
                    case "CSharp":
                        langExt   = ".cs";
                        generator = new CSharpCollectionGenerator();
                        break;

                    case "VB":
                        generator = new VBCollectionGenerator();
                        langExt   = ".vb";
                        break;
                    }
                    StreamReader reader        = new StreamReader(path);
                    string       collectionXML = reader.ReadToEnd();
                    reader.Close();

                    string generatedCode = generator.GenerateCodeFromXml(collectionXML);
                    string outputFile    = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(path) + langExt;
                    // create new .lang file file
                    StreamWriter writer = new StreamWriter(outputFile);

                    writer.Write(generatedCode);
                    writer.Close();
                }
                else
                {
                    throw new FileNotFoundException();
                }
            }
            catch (Exception e) {
                string msg = String.Format("Failed to generate collection classes for file : '{0}'", path);
                throw new BuildException(msg, Location, e);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The actual generation work is done here.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="language"></param>
        private void GenerateCollectionClasses(string path, string language){
            string langExt = "";
            try {
                if (File.Exists(path)) {
                    Log(Level.Info, path);
                    CollectionGenerator.CollectionGenerator generator = null;
                    // load the file
                    switch ( language ) {
                        case "CSharp" :
                            langExt = ".cs";
                            generator = new CSharpCollectionGenerator();
                            break;
                        case "VB" :
                            generator = new VBCollectionGenerator();
                            langExt = ".vb";
                            break;
                    }
                    StreamReader reader = new StreamReader( path );
                    string collectionXML = reader.ReadToEnd();
                    reader.Close();

                    string generatedCode = generator.GenerateCodeFromXml( collectionXML );
                    string outputFile = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension( path ) + langExt;
                    // create new .lang file file 
                    StreamWriter writer = new StreamWriter( outputFile );
                                     
                    writer.Write( generatedCode );                                    
                    writer.Close();
                } else {
                    throw new FileNotFoundException();
                }
            } 
            catch( Exception e ){
                string msg = String.Format("Failed to generate collection classes for file : '{0}'", path);
                throw new BuildException(msg, Location, e);
            }            
        }