public void GenerateComponent(ComponentDTO componentDTO)
        {
            Hashtable templateTable = GetTemplates ();
            Hashtable componentTable = InitComponentTable (componentDTO, templateTable);
            componentTable = FillTable (componentDTO, componentTable);
            //Haremos una segunda pasada para construir los métodos.
            componentTable = FillMethods (componentDTO, componentTable, templateTable);
            //Tercera pasada para conseguir las respuestas.
            componentTable = FillResponses (componentDTO, componentTable, templateTable);

            //Ahora solo resta guardarlo en archivos.  Con la ruta por
            //defecto que se haya configurado.
            DirectoryInfo componentDirectory = CreateSkeleton (componentDTO);
            WriteFiles (componentTable, componentDirectory, componentDTO);

            /**
            IDictionaryEnumerator enumerator = componentTable.GetEnumerator ();
            while (enumerator.MoveNext ()) {
                Console.WriteLine (enumerator.Key + "\n" + enumerator.Value);
            }
            */
        }
 public IDataTransferObject GetDataForm()
 {
     if (ValidateForm ()) {
         switch (ActionState) {
             case ActionState.Create:
                 ComponentDTO componentDTO = new ComponentDTO ();
                 componentDTO.ComponentName = componentNameEntry.Text;
                 componentDTO.ClassExceptionManager = exceptionManagerEntry.Text;
                 componentDTO.ViewCollection = viewTableModel.ListModel;
                 componentDTO.MethodCollection = methodTableModel.ListModel;
                 ActionState = ActionState.None;
                 return componentDTO;
             case ActionState.Edit:
                 this.componentDTO.ComponentName = componentNameEntry.Text;
                 this.componentDTO.ClassExceptionManager = exceptionManagerEntry.Text;
                 this.componentDTO.ViewCollection = viewTableModel.ListModel;
                 this.componentDTO.MethodCollection = methodTableModel.ListModel;
                 ActionState = ActionState.None;
                 return this.componentDTO;
             case ActionState.None:
                 break;
             default:
                 ActionState = ActionState.None;
                 break;
         }
     }
     return null;
 }
 private void OnTestClicked(object sender, EventArgs args)
 {
     ActionState = ActionState.Edit;
     componentDTO = (ComponentDTO) GetDataForm ();
 }
 /* Interface Implementation */
 public void LoadDataForm(IDataTransferObject dto)
 {
     if (dto is ComponentDTO) {
         ComponentDTO componentDTO = (ComponentDTO) dto;
         this.componentDTO = componentDTO;
         componentNameEntry.Text = componentDTO.ComponentName;
         exceptionManagerEntry.Text = componentDTO.ClassExceptionManager;
         viewTableModel = new ViewTableModel (componentDTO.ViewCollection);
         viewsTreeView.Model = viewTableModel.ListStore;
         methodTableModel = new MethodTableModel (componentDTO.MethodCollection);
         methodsTreeView.Model = methodTableModel.ListStore;
     }
 }
 private Hashtable InitComponentTable(ComponentDTO componentDTO, Hashtable templateTable)
 {
     Hashtable componentTable = new Hashtable ();
     //Key fileName without path, string value.
     componentTable.Add (componentDTO.ComponentName+"ComponentModel.cs", templateTable[TemplateNamesDTO.BusinessObject]);
     //Añadimos el gestor de exceptions
     componentTable.Add (componentDTO.ClassExceptionManager+".cs", templateTable[TemplateNamesDTO.ExceptionManager]);
     //Añadimos el manifiesto.
     /**
     StringBuilder manifestBuilder = new StringBuilder (TemplateNamesDTO.AssemblyInfo);
     manifestBuilder = manifestBuilder.Replace ("template", "cs");
     componentTable.Add (manifestBuilder.ToString (), templateTable[TemplateNamesDTO.AssemblyInfo]);
     */
     //Añaidmos las vistas
     IEnumerator enumerator = componentDTO.ViewCollection.GetEnumerator ();
     while (enumerator.MoveNext ()) {
         ViewDTO currentView = (ViewDTO) enumerator.Current;
         componentTable.Add (currentView.ViewName + ".cs", templateTable[TemplateNamesDTO.ViewHandler]);
     }
     //Añadimos el file nant.
     if (preferencesDTO.GenerateBuildfile) {
         componentTable.Add (componentDTO.ComponentName+".build", templateTable[TemplateNamesDTO.NAntBuildfile]);
     }
     return componentTable;
 }
        private void WriteFiles(Hashtable componentTable, DirectoryInfo componentDirectory, ComponentDTO componentDTO)
        {
            StringCollection stringCollection = new StringCollection ();
            IEnumerator enumerator = componentTable.Keys.GetEnumerator ();
            while (enumerator.MoveNext ()) {
                stringCollection.Add ((string) enumerator.Current);
            }

            enumerator = (stringCollection as IEnumerable).GetEnumerator ();
            while (enumerator.MoveNext ()) {
                string fileName = (string) enumerator.Current;
                string content = (string) componentTable[fileName];
                if (fileName.EndsWith ("ComponentModel.cs")) {
                    WriteFileAt (fileName, componentDirectory.GetDirectories ("Bo")[0], content);
                }
                if (fileName.StartsWith (componentDTO.ClassExceptionManager)) {
                    WriteFileAt (fileName, componentDirectory.GetDirectories ("Exceptions")[0], content);
                }
                if (fileName.StartsWith ("AssemblyInfo")) {
                    WriteFileAt (fileName, componentDirectory, content);
                }
                IEnumerator auxEnumerator = (componentDTO.ViewCollection as IEnumerable).GetEnumerator ();
                while (auxEnumerator.MoveNext ()) {
                    if (fileName.StartsWith ((string)auxEnumerator.Current)) {
                        WriteFileAt (fileName, componentDirectory.GetDirectories ("Forms")[0], content);
                    }
                }
            }

            if (preferencesDTO.GenerateBuildfile) {
                enumerator.Reset ();
                while (enumerator.MoveNext ()) {
                    string fileName = (string) enumerator.Current;
                    if (fileName.StartsWith (componentDTO.ComponentName) && fileName.EndsWith (".build")) {
                        string content = (string) componentTable [fileName];
                        WriteFileAt (fileName, componentDirectory, content);
                    }
                }
            }
        }
        private Hashtable FillTable(ComponentDTO componentDTO, Hashtable componentTable)
        {
            StringCollection stringCollection = new StringCollection ();
            IEnumerator enumerator = componentTable.Keys.GetEnumerator ();
            while (enumerator.MoveNext ()) {
                stringCollection.Add ((string) enumerator.Current);
            }

            enumerator = (stringCollection as IEnumerable).GetEnumerator ();
            while (enumerator.MoveNext ()) {
                string currentKey = (string)enumerator.Current;
                StringBuilder stringBuilder = new StringBuilder ((string)componentTable[currentKey]);
                if (currentKey.EndsWith (".build"))
                    stringBuilder = stringBuilder.Replace (TagValuesDTO.NAntComponentName, componentDTO.ComponentName);
                else
                    stringBuilder = stringBuilder.Replace (TagValuesDTO.ComponentName, componentDTO.ComponentName);
                stringBuilder = stringBuilder.Replace (TagValuesDTO.ExceptionManager, componentDTO.ClassExceptionManager);
                if (preferencesDTO.PrefixNamespace.Length != 0) {
                    //Lo seteará y añadirá un punto.
                    StringBuilder prefixBuilder = new StringBuilder (preferencesDTO.PrefixNamespace);
                    prefixBuilder = prefixBuilder.Append (".");
                    stringBuilder = stringBuilder.Replace (TagValuesDTO.Prefix, prefixBuilder.ToString ());
                }
                else {
                    //No lo seteara el prefix namespace
                    stringBuilder = stringBuilder.Replace (TagValuesDTO.Prefix, preferencesDTO.PrefixNamespace);
                }
                //Ahora para las vistas se discernira para cada una.
                foreach (ViewDTO viewDTO in componentDTO.ViewCollection) {
                    string view = viewDTO.ViewName;
                    if (currentKey.StartsWith (view)) {
                        stringBuilder = stringBuilder.Replace (TagValuesDTO.ViewName, view);
                    }
                }
                componentTable[currentKey] = stringBuilder.ToString ();
            }
            return componentTable;
        }
 private Hashtable FillResponses(ComponentDTO componentDTO, Hashtable componentTable, Hashtable templateTable)
 {
     foreach (ViewDTO viewDTO in componentDTO.ViewCollection) {
         string viewName = viewDTO.ViewName;
         StringBuilder responseBuilder = new StringBuilder ();
         foreach (MethodDTO methodDTO in componentDTO.MethodCollection) {
             if (methodDTO.ViewToResponse.Equals (viewName)) {
                 responseBuilder = responseBuilder.Append (templateTable[TemplateNamesDTO.ResponseMethod]);
                 responseBuilder = responseBuilder.Replace (TagValuesDTO.ResponseName, methodDTO.ResponseMethod);
             }
         }
         StringBuilder viewBuilder = new StringBuilder ((string)componentTable [viewName + ".cs"]);
         viewBuilder = viewBuilder.Replace (TagValuesDTO.Body, responseBuilder.ToString ());
         componentTable [viewName + ".cs"] = viewBuilder.ToString ();
     }
     return componentTable;
 }
        private Hashtable FillMethods(ComponentDTO componentDTO, Hashtable componentTable, Hashtable templateTable)
        {
            StringBuilder stringBuilder = new StringBuilder ();
            foreach (MethodDTO methodDTO in componentDTO.MethodCollection) {
                stringBuilder = stringBuilder.Append (templateTable[TemplateNamesDTO.MethodBody]);
                stringBuilder = stringBuilder.Replace (TagValuesDTO.ReturnType, methodDTO.ReturnType);
                stringBuilder = stringBuilder.Replace (TagValuesDTO.MethodName, methodDTO.MethodName);
                //TODO:Build parameters
                StringBuilder methodStringBuilder = new StringBuilder ();
                foreach (ParameterDTO parameterDTO in methodDTO.ParametersCollection) {
                    methodStringBuilder.Append (parameterDTO.TypeName);
                    methodStringBuilder.Append (" ");
                    methodStringBuilder.Append (parameterDTO.VarName);
                    methodStringBuilder.Append (", ");
                }
                //Eliminamos la coma y el ultimo espacio.
                if (methodStringBuilder.Length != 0)
                    methodStringBuilder.Remove (methodStringBuilder.Length -2, 2);
                stringBuilder = stringBuilder.Replace (TagValuesDTO.Parameters, methodStringBuilder.ToString ());
                //Attributes.
                //Set up prefix

                if (preferencesDTO.PrefixNamespace.Length != 0) {
                    //Lo seteará y añadirá un punto.
                    StringBuilder prefixBuilder = new StringBuilder (preferencesDTO.PrefixNamespace);
                    prefixBuilder = prefixBuilder.Append (".");
                    stringBuilder = stringBuilder.Replace (TagValuesDTO.Prefix, prefixBuilder.ToString ());
                }
                else {
                    //No lo seteara el prefix namespace
                    stringBuilder = stringBuilder.Replace (TagValuesDTO.Prefix, preferencesDTO.PrefixNamespace);
                }
                stringBuilder = stringBuilder.Replace (TagValuesDTO.ComponentName, componentDTO.ComponentName);

                stringBuilder = stringBuilder.Replace (TagValuesDTO.ViewName, methodDTO.ViewToResponse);
                stringBuilder = stringBuilder.Replace (TagValuesDTO.ResponseName, methodDTO.ResponseMethod);
            }
            //Obtenemos el BO del componente y seteamos el valor, reemplazando.
            //
            StringCollection stringCollection = new StringCollection ();
            IEnumerator enumerator = componentTable.Keys.GetEnumerator ();
            while (enumerator.MoveNext ()) {
                stringCollection.Add ((string) enumerator.Current);
            }
            enumerator = (stringCollection as IEnumerable).GetEnumerator ();
            string currentValue = String.Empty;
            while (enumerator.MoveNext ()) {
                currentValue = (string) enumerator.Current;
                if (currentValue.EndsWith ("ComponentModel.cs")) {
                    break;
                }
            }
            if (!currentValue.Equals (String.Empty)) {
                //Esta comprobación igual sobra.
                StringBuilder componentTemplateBuilder = new StringBuilder ((string)componentTable[currentValue]);
                componentTemplateBuilder = componentTemplateBuilder.Replace (TagValuesDTO.Body, stringBuilder.ToString ());
                componentTable[currentValue] = componentTemplateBuilder.ToString ();
            }

            return componentTable;
        }
        private DirectoryInfo CreateSkeleton(ComponentDTO componentDTO)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo (preferencesDTO.OutputPath);
            DirectoryInfo componentDirectoryInfo = directoryInfo.CreateSubdirectory (componentDTO.ComponentName);
            //Ahora crearemos uno para cada cosa, Bo, Forms, Dto, Exceptions ...
            componentDirectoryInfo.CreateSubdirectory ("Bo");
            componentDirectoryInfo.CreateSubdirectory ("Forms");
            componentDirectoryInfo.CreateSubdirectory ("Dto");
            componentDirectoryInfo.CreateSubdirectory ("Exceptions");
            componentDirectoryInfo.CreateSubdirectory ("Resources");

            return componentDirectoryInfo;
        }
Esempio n. 11
0
 public ComponentNode(ComponentDTO componentDTO)
     : base((IDataTransferObject) componentDTO)
 {
 }