public static void BrokeDataModelCircularReferences(DataModelEntity dataModelEntity) { // Rompe la referencia con la tienda. int id = dataModelEntity.IdStore; dataModelEntity.Store = null; dataModelEntity.IdStore = id; if (dataModelEntity != null) { foreach (TableEntity table in dataModelEntity.Tables) { // Asigna un id temporal para permitir corregir las referencias. if (table.Id == 0) { table.Id = table.GetHashCode(); } foreach (FieldEntity field in table.Fields) { // Rompe las referencias con el campo. field.Table = null; } } } }
private void InitInfrastructureServices() { try { // Cargar todos los modelos de datos y verificar ensamblados DataModelDataAccess dataModelDataAccess = new DataModelDataAccess(); Collection <DataModelEntity> result = dataModelDataAccess.LoadWhere(DataModelEntity.DBIdStore, "0", false, OperatorType.Equal); dataModelDataAccess = new DataModelDataAccess(); Collection <DataModelEntity> dataModels = dataModelDataAccess.LoadAll(true); if (result.Count == 0) { ConsoleWriter.SetText("Creating mall data model"); DataModelEntity dataModel = new DataModelEntity(); MallEntity mall = new MallEntity(); mall.MallName = "Mall"; (new MallDataAccess()).Save(mall); dataModel.Mall = mall; dataModelDataAccess.Save(dataModel); } foreach (DataModelEntity dataModel in dataModels) { string assemblyFileName = dataModel.ServiceAssemblyFileName; if (assemblyFileName != null) { if (File.Exists(Path.Combine(ServiceBuilder.AssembliesFolder, assemblyFileName))) { Type[] servicesTypes = ServiceBuilder.GetInfrastructureServiceTypes(assemblyFileName); Binding serviceBinding = new BasicHttpBinding(); if (PublishInfrastructureService(servicesTypes[0], servicesTypes[1], serviceBinding)) { Debug.WriteLine("SUCCESS : infrastructure service published."); } else { Debug.WriteLine("FAILURE : trying to publish infrastructure service."); } } else { ServiceBuilder builder = new ServiceBuilder(); dataModel.Deployed = false; builder.BuildAndImplementInfrastructureService(dataModel, false, serverSession); } } } } catch (DataException dataError) { Debug.WriteLine("ERROR : Data exception running infrastructure services. MESSAGE : " + dataError.Message); } catch (IOException ioError) { Debug.WriteLine("ERROR : IO error running infrastructure services. MESSAGE : " + ioError.Message); } }
public void EndGetDataModel(System.IAsyncResult result) { GetDataModelResult callResult = new GetDataModelResult(); try { HttpWebRequest request = (HttpWebRequest)result.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); // Crear la instancia del deserializador. DataContractSerializer serializer = new DataContractSerializer(typeof(DataModelEntity)); // Deserializar el modelo de datos. DataModelEntity deserializedDataModel = (DataModelEntity)serializer.ReadObject(response.GetResponseStream()); callResult.DataModel = deserializedDataModel; } catch (SerializationException serializationError) { Debug.WriteLine(serializationError.Message); } catch (WebException webError) { Debug.WriteLine(webError.Message); } // Si existe un callback, invocarlo. if (getDataModelCallback != null) { getDataModelCallback(callResult); getDataModelCallback = null; } }
public static void FixDataModelCircularReferences(DataModelEntity dataModelEntity) { Dictionary <int, TableEntity> tables = new Dictionary <int, TableEntity>(); if (dataModelEntity != null) { foreach (TableEntity tableEntity in dataModelEntity.Tables) { tables.Add(tableEntity.Id, tableEntity); } foreach (TableEntity tableEntity in dataModelEntity.Tables) { foreach (FieldEntity fieldEntity in tableEntity.Fields) { fieldEntity.Table = tableEntity; } } foreach (RelationEntity relationEntity in dataModelEntity.Relations) { relationEntity.Source = tables[relationEntity.IdSource]; relationEntity.Target = tables[relationEntity.IdTarget]; } } }
public void BeginSaveDataModel(DataModelEntity dataModelEntity, SaveDataModelCallback callback) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( new Uri(serverBaseUri, relativeSaveDataModelURI)); request.Method = "POST"; saveDataModelCallback = callback; request.BeginGetRequestStream(delegate(IAsyncResult result) { HttpWebRequest webRequest = result.AsyncState as HttpWebRequest; webRequest.ContentType = "text/xml"; Stream requestStream = webRequest.EndGetRequestStream(result); StreamWriter streamWriter = new StreamWriter(requestStream); // Serializar los datos a enviar. DataContractSerializer serializer = new DataContractSerializer(typeof(DataModelEntity)); serializer.WriteObject(streamWriter.BaseStream, dataModelEntity); streamWriter.Close(); // Invocar una llamada asíncrona. Un Callback será invocado en un hilo ejecutándose en segundo plano. request.BeginGetResponse(new AsyncCallback(EndSaveDataModel), request); } , request); }
/// <summary> /// Function to delete a DataModelEntity from database. /// </summary> /// <param name="dataModelEntity">DataModelEntity to delete</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the DataModelEntity was deleted successfully, the same DataModelEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="dataModelEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public DataModelEntity Delete(DataModelEntity dataModelEntity, string session) { bool permited = ValidationService.Instance.ValidatePermission(session, "delete", "DataModel"); if (!permited) { ExceptionDetail detail = new ExceptionDetail(new UtnEmall.Server.BusinessLogic.UtnEmallPermissionException("The user hasn't permissions to delete an entity")); throw new FaultException <ExceptionDetail>(detail); } if (dataModelEntity == null) { throw new ArgumentException("The argument can not be null or be empty"); } try { // Check that the service is not deployed if (dataModelEntity.Deployed) { dataModelEntity.Errors.Add(new Error("DataModel Deployed", "", "The data model is already deployed. Can not be deleted.")); return(dataModelEntity); } // Delete dataModelEntity using data access object datamodelDataAccess.Delete(dataModelEntity); return(null); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmall.Server.BusinessLogic.UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }
/// <summary> /// Function to validate a DataModelEntity before it's saved. /// </summary> /// <param name="dataModelEntity">DataModelEntity to validate</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the DataModelEntity was deleted successfully, the same DataModelEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="dataModelEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public bool Validate(DataModelEntity dataModel) { bool result = true; if (dataModel == null) { throw new ArgumentException("The argument can not be null or be empty"); } // Check entity data if (dataModel.Tables == null) { dataModel.Errors.Add(new Error("Tables", "Tables", "El nombre de la tabla no puede estar vacío")); result = false; } if (!ValidateTables(dataModel.Tables)) { result = false; } if (dataModel.Relations == null) { dataModel.Errors.Add(new Error("Relations", "Relations", "Las relaciones no pueden estar vacías")); result = false; } if (!ValidateRelations(dataModel.Relations)) { result = false; } return(result); }
public bool SaveDataModel(DataModelEntity dataModelEntity) { try { CircularReferencesManager.FixDataModelCircularReferences(dataModelEntity); DataModelEntity lastDataModel = InternalLoadDataModel(); if (lastDataModel == null) { lastDataModel = dataModelEntity; lastDataModel.IdStore = this.User.IdStore; } else { lastDataModel.Tables = dataModelEntity.Tables; lastDataModel.Relations = dataModelEntity.Relations; } DataModelEntity result = ServicesClients.DataModel.Save(lastDataModel, this.UserSession); return(result == null); } catch (UtnEmallPermissionException permissionException) { throw new FaultException(permissionException.Message); } catch (UtnEmallBusinessLogicException businessLogicException) { throw new FaultException(businessLogicException.Message); } }
/// <summary> /// Esta función crea un nuevo modelo de dato wpf que representa un modelo de datos(data model) dentro del proyecto WPF. /// </summary> /// <param name="dataModelEntity">El modelo de datos</param> public void CreateDataModelDocument(DataModelEntity dataModelEntity) { if (dataModelEntity == null) { throw new ArgumentNullException("dataModelEntity", "dataModelEntity can not be null"); } dataModelDocumentWpf = new DataModelDocumentWpf(this, dataModelEntity); }
/// <summary> ///constructor /// </summary> /// <param name="dataModelEntity">El modelo de datos a editar</param> public WindowDataModelDesigner(DataModelEntity dataModelEntity) { if (dataModelEntity == null) { throw new ArgumentNullException("dataModelEntity", "dataModelEntity can not be null"); } InitializeComponent(); CreateDataModelDocument(dataModelEntity); this.Loaded += new RoutedEventHandler(WindowDataModelDesignerLoaded); }
public DataModelEntity GetDataModel() { DataModelEntity dataModel = InternalLoadDataModel(); if (dataModel != null) { CircularReferencesManager.BrokeDataModelCircularReferences(dataModel); return(dataModel); } return(null); }
private void GetDataModelCompleted(GetDataModelResult result) { dataModelEntity = result.DataModel; if (dataModelEntity != null) { CircularReferencesManager.FixDataModelCircularReferences(dataModelEntity); DataModel dataModel = Utilities.ConvertEntityToDataModel(dataModelEntity); if (dataModelLoadedCallback != null) { dataModelLoadedCallback(dataModel); dataModelLoadedCallback = null; } } }
/// <summary> /// Function to save a DataModelEntity to the database. /// </summary> /// <param name="dataModelEntity">DataModelEntity to save</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the DataModelEntity was saved successfully, the same DataModelEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="dataModelEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public DataModelEntity Save(DataModelEntity dataModelEntity, string session) { bool permited = ValidationService.Instance.ValidatePermission(session, "save", "DataModel"); if (!permited) { ExceptionDetail detail = new ExceptionDetail(new UtnEmall.Server.BusinessLogic.UtnEmallPermissionException("The user hasn't permissions to save an entity")); throw new FaultException <ExceptionDetail>(detail); } if (!Validate(dataModelEntity)) { return(dataModelEntity); } try { // Check that the service is not deployed if (dataModelEntity.Deployed) { dataModelEntity.Errors.Add(new Error("DataModel Deployed", "", "The data model is already deployed. Can not be saved.")); return(dataModelEntity); } // Check that there isn't related custom services if (dataModelEntity.Id > 0) { CustomerServiceDataDataAccess customerServiceData = new CustomerServiceDataDataAccess(); // Get all customer services where IdDataModel is the same as us int referencedServices = customerServiceData.LoadWhere(CustomerServiceDataEntity.DBIdDataModel, dataModelEntity.Id, false, OperatorType.Equal).Count; // If there are customer services it is an error if (referencedServices > 0) { dataModelEntity.Errors.Add(new Error("DataModel Deployed", "", "The data model has related customer services. Can not be updated.")); return(dataModelEntity); } } // Save dataModelEntity using data access object datamodelDataAccess.Save(dataModelEntity); return(null); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmall.Server.BusinessLogic.UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }
public void BeginSaveDataModel(DataModel dataModel, SaveDataModelCallback callback) { try { DataModelEntity dataModelEntity = Utilities.ConvertDataModelToEntity(dataModel); dataModelEntity.IdStore = customServiceId; CircularReferencesManager.BrokeDataModelCircularReferences(dataModelEntity); SilverlightServicesClient client = Utils.SilverlightServicesClient; client.BeginSaveDataModel(dataModelEntity, callback); } catch (Exception) { throw; } }
public async Task <ActionResult> GetInput(DataModelEntity dataModelEntity) { if (ModelState.IsValid) { var caller = new ApiCaller(); var cos = await caller.CallToApi(dataModelEntity.InputString); dataModelEntity.TranslatedString = cos.ToString(); db.dataModelEntities.Add(dataModelEntity); db.SaveChanges(); return(View("TranslatedString", dataModelEntity)); } return(Content("Please, enter the text!")); }
/// <summary> /// Ejecuta el filtro en obj para saber si debe filtrarse. /// </summary> /// <param name="obj"> /// El objeto sobre el cual se aplicará el filtro. /// </param> /// <param name="filterText"> /// El texto que filtra la lista. /// </param> /// <returns> /// Verdadero si obj pasa el filtro, de otro modo, falso. /// </returns> private bool DoFilter(Object obj, string filterText) { if (string.IsNullOrEmpty(filterText)) { return(true); } DataModelEntity model = (DataModelEntity)obj; if (model.Store.Name.Contains(filterText)) { return(true); } return(false); }
/// <summary> /// Actualiza la entidad DataModelEntity en la base de datos /// </summary> /// <param name="serviceDataModel">Modelo de datos a guardar.</param> /// <param name="sessionIdentifier">Identificador de sesión.</param> /// <returns>true si tiene éxito.</returns> static private bool SaveDataModel(DataModelEntity serviceDataModel, string sessionIdentifier) { DataModelDataAccess dataModelLogic = new DataModelDataAccess(); serviceDataModel.ServiceAssemblyFileName = Path.GetFileName(serviceDataModel.ServiceAssemblyFileName); serviceDataModel.Deployed = true; try { dataModelLogic.Save(serviceDataModel); return(true); } catch (UtnEmallDataAccessException error) { Debug.WriteLine("FAILURE : While updating data model entity. ERROR : " + error.Message); return(false); } }
// CONVIERTE ENTIDADES A OBJETOS DE WPF O SILVERLIGHT //<summary> // Convierte un DataModelEntity guardado en una base de datos a un objeto DataModel que se usa en proyectos wpf. // </summary> // <param name="dataModelEntity">objeto a nivel de capas inferiores</param> // <returns></returns> public static DataModel ConvertEntityToDataModel(DataModelEntity dataModelEntity) { DataModel dataModel = new DataModel(); foreach (TableEntity tableEntity in dataModelEntity.Tables) { TableWpf table = ConvertEntityToTable(tableEntity); dataModel.AddTable(table); } foreach (RelationEntity relationEntity in dataModelEntity.Relations) { RelationWpf relation = GetRelationFromDataModelEntity(dataModel, relationEntity); dataModel.AddRelation(relation); } return(dataModel); }
/// <summary> /// Agrega un modelo de datos a la lista. /// </summary> /// <param name="dataModel">El modelo de datos a agregar.</param> public void Add(DataModelEntity dataModel) { if (dataModel.Store != null) { list.Add(dataModel); usedStores.Add(dataModel.Store.Name); } // Si la tienda es null, es el modelo de datos del shopping. else { StoreEntity store = new StoreEntity(); store.Name = UtnEmall.ServerManager.Properties.Resources.Mall; dataModel.Store = store; list.Add(dataModel); usedStores.Add(dataModel.Store.Name); } }
/// <summary> /// Función que prepara el DataModelEntity que va a ser almacenado. /// </summary> public Collection <Error> SaveDataModel() { Collection <Error> errors = new Collection <Error>(); myDataModel.Validate(errors); if (errors.Count == 0) { // Reemplaza el modelo de dato viejo con el actual // Generará nuevos registros para tablas y columnas DataModelEntity dataModelEntity = LogicalLibrary.Utilities.ConvertDataModelToEntity(this.myDataModel); dataModelEntity.Id = oldDataModelEntity.Id; dataModelEntity.IdStore = oldDataModelEntity.IdStore; dataModelEntity.IsNew = false; this.oldDataModelEntity = dataModelEntity; } return(errors); }
/// <summary> /// Constructor /// </summary> /// <param name="window">Windows Container para el DataModelDocument</param> /// <param name="dataModelEntity">DataModelEntity a dibujar</param> /// <param name="session">Identificador de sesión</param> public DataModelDocumentWpf(WindowDataModelDesigner window, DataModelEntity dataModelEntity) { if (window == null) { throw new ArgumentNullException("window", "window can not be null"); } if (dataModelEntity == null) { throw new ArgumentNullException("dataModelEntity", "dataModelEntity can not be null"); } // this.session = session; this.oldDataModelEntity = dataModelEntity; windowsDataModelDesigner = window; this.canvasDraw = windowsDataModelDesigner.canvasDraw; this.canvasDrawPrincipal = windowsDataModelDesigner.canvasDrawPrincipal; this.canvasDrawPrincipal.MouseMove += new System.Windows.Input.MouseEventHandler(canvasDraw_MouseMove); LoadDataModel(dataModelEntity); }
/// <summary> /// Función que carga un DataModelEntity al DataModelDocumentWpf /// </summary> /// <param name="dataModelEntity"></param> private void LoadDataModel(DataModelEntity dataModelEntity) { if (dataModelEntity == null) { throw new ArgumentNullException("dataModelEntity", "dataModelEntity can not be null"); } DataModel dataModelLoaded = Utilities.ConvertEntityToDataModel(dataModelEntity); if (dataModelLoaded != null) { myDataModel = dataModelLoaded; ReDrawDataModel(); return; } this.MyDataModel = new DataModel(); }
/// <summary> /// Método invocado cuando se hace click en el botón Editar. /// </summary> /// <param name="sender"> /// El objeto que genera el evento. /// </param> /// <param name="e"> /// Un objeto que contiene información acerca del evento. /// </param> protected override void OnEditSelected(object sender, EventArgs e) { DataModelEntity dataModel = (DataModelEntity)Selected; if (dataModel == null) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.NoDataModelSelected); return; } if (designer != null && designer.IsVisible) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.DesignerOpened); return; } designer = new WindowDataModelDesigner(dataModel); designer.Closed += new EventHandler(OnDesignerClosed); designer.ShowDialog(); }
public bool BuildAndImplementInfrastructureService(DataModelEntity serviceDataModel, bool insertTestData, string sessionIdentifier) { // Verificar argumentos if (serviceDataModel == null) { throw new ArgumentException("Invalid null argument. Must provide an instance of DataModelEntity.", "serviceDataModel"); } if (sessionIdentifier == null) { throw new ArgumentException("Invalid null argument.", "sessionIdentifier"); } // Verificar el identificado de sesión con el administrador de sesión // Verifica si un servicio es válido BusinessLogic.DataModel dataModel = new BusinessLogic.DataModel(); if (!dataModel.Validate(serviceDataModel)) { throw new ArgumentException("Provided data model is not valid.", "serviceDataModel"); } // Si el servicio se desplegó lanzar un error if (serviceDataModel.Deployed) { throw new FaultException(Resources.DataModelAlreadyDeployed); } // Debe contener almenos una tabla if (serviceDataModel.Tables.Count == 0) { throw new FaultException(Resources.DataModelMustHaveOneTable); } Console.WriteLine("Building infrastructure service."); // Construir el programa Meta D++ string fileName = BuildMetaDppProgramForInfrastructureService(serviceDataModel, false); // Intentar bajar el servicio si está activo if (ServerHost.Instance.StopInfrastructureService(Path.GetFileNameWithoutExtension(fileName) + "Service")) { // Compilar el programa Meta D++ en una librería if (CompileMetaDppProgram(new Uri(fileName), false)) { // Construir la versión móvil del servicio de infraestructura string clientVersionFileName = BuildMetaDppProgramForInfrastructureService(serviceDataModel, true); if (CompileMetaDppProgram(new Uri(clientVersionFileName), true)) { Debug.WriteLine("Infrastructure Service Dll for Mobile succeful builded."); fileName = Path.ChangeExtension(fileName, ".dll"); // Iniciar el servicio web if (PublishInfrastructureService(fileName, insertTestData)) { // Actualizar la información del modelo de datos serviceDataModel.ServiceAssemblyFileName = fileName; serviceDataModel.Deployed = true; if (SaveDataModel(serviceDataModel, sessionIdentifier)) { Debug.WriteLine("SUCCESS : saving data model."); Debug.WriteLine("Building infrastructure service successful."); return(true); } else { Debug.WriteLine("FAILURE : error trying to save data model."); return(false); } } } else { Debug.WriteLine("Error building Infrastructure Service Dll for Mobile."); } } } return(false); }
/// <summary> /// Construir el programa Meta D++ /// </summary> /// <param name="serviceDataModel">Datos de servicio de infraestructura.</param> /// <returns>El nombre del archivo, null si falló.</returns> private string BuildMetaDppProgramForInfrastructureService(DataModelEntity serviceDataModel, bool buildClient) { // Verifica argumento if (serviceDataModel == null) { throw new ArgumentException("Must provide not null argument.", "serviceDataModel"); } string programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Replace("\\", "\\\\"); string compactFrameworkPath = CompactFrameworkPartialPath.Replace("\\", "\\\\"); string netFramework3PartialPath = NetFramework3PartialPath.Replace("\\", "\\\\"); // Construye programa Meta D++ string fileStr = null; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assembly=mscorlib\";\n"; if (!buildClient) { fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assembly=System\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assembly=System.Drawing\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assembly=System.Data\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assembly=System.Web.Services\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=" + programFilesPath + netFramework3PartialPath + "\\\\System.ServiceModel.dll\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=" + programFilesPath + netFramework3PartialPath + "\\\\System.Runtime.Serialization.dll\";\n"; fileStr += "import \"UtnEmall\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=..\\\\BaseDesktop.dll\";\n"; } else { fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=" + programFilesPath + compactFrameworkPath + "\\\\System.Drawing.dll\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=" + programFilesPath + compactFrameworkPath + "\\\\System.dll\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=" + programFilesPath + compactFrameworkPath + "\\\\System.Data.dll\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=" + programFilesPath + compactFrameworkPath + "\\\\System.Xml.dll\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=" + programFilesPath + compactFrameworkPath + "\\\\System.ServiceModel.dll\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=" + programFilesPath + compactFrameworkPath + "\\\\System.Runtime.Serialization.dll\";\n"; fileStr += "import \"System\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=.\\\\libsclient\\\\System.Data.SqlServerCe.dll\";\n"; fileStr += "import \"UtnEmall\", \"platform=DotNET\", \"ns=DotNET\", \"assemblyfilename=.\\\\libsclient\\\\BaseMobile.dll\";\n"; } fileStr += "\n"; fileStr += "using Zoe;\n"; fileStr += "using zoe::lang;\n"; fileStr += "using DotNET::System;\n"; fileStr += "using DotNET::System::Collections;\n"; fileStr += "using DotNET::System::Data;\n"; fileStr += "using DotNET::System::Data::Common;\n"; fileStr += "using DotNET::System::Data::SqlClient;\n"; fileStr += "using UtnEmall::Store" + serviceDataModel.IdStore + ";\n"; fileStr += "using UtnEmall::Store" + serviceDataModel.IdStore + "::EntityModel;\n"; fileStr += "using UtnEmall::Store" + serviceDataModel.IdStore + "::BusinessLogic;\n"; if (!buildClient) { fileStr += "using DotNET::UtnEmall::Server::EntityModel;\n"; fileStr += "using DotNET::UtnEmall::Server::DataModel;\n"; fileStr += "using DotNET::UtnEmall::Server::BusinessLogic;\n"; fileStr += "using DotNET::UtnEmall::Server::Base;\n"; fileStr += "using DotNET::System::ServiceModel;\n"; fileStr += "using DotNET::System::Runtime::Serialization;\n"; fileStr += "using UtnEmall::Server::EntityModel;\n"; } else { fileStr += "using DotNET::System::Xml;\n"; fileStr += "using DotNET::System::ServiceModel;\n"; fileStr += "using DotNET::System::ServiceModel::Channels;\n"; fileStr += "using DotNET::System::Data::SqlServerCe;\n"; fileStr += "using DotNET::UtnEmall::Client::EntityModel;\n"; fileStr += "using DotNET::UtnEmall::Client::DataModel;\n"; fileStr += "using DotNET::UtnEmall::Client::BusinessLogic;\n"; fileStr += "using DotNET::UtnEmall::Client::PresentationLayer;\n"; fileStr += "using UtnEmall::Client::PresentationLayer;\n"; fileStr += "using UtnEmall::Client::EntityModel;\n"; } fileStr += "using UtnEmall::Utils;\n"; fileStr += "using DotNET::System::Collections::Generic;\n"; fileStr += "using DotNET::System::Collections::ObjectModel;\n"; fileStr += "using System::Collections::Generic;\n"; fileStr += "\n"; fileStr += "Model::DefineNamespace(UtnEmall::Store" + serviceDataModel.IdStore + "::EntityModel);\n"; fileStr += "Model::DefineBusinessNamespace(UtnEmall::Store" + serviceDataModel.IdStore + "::BusinessLogic);\n"; fileStr += "Model::DefineIdentity(false);\n"; if (buildClient) { fileStr += "Model::DefineMobil(true);\n"; fileStr += "ModelBusiness::IsWindowsMobile(true, false);\n"; fileStr += "InfService::IsMobil(true);\n"; } fileStr += "\n"; fileStr += "namespace UtnEmall{\n"; fileStr += "\n"; if (!buildClient) { fileStr += "Model::DefineMobil(false);\n"; } else { fileStr += "Model::DefineMobil(true);\n"; } string[] relationTypes = new string[] { "OneToOne", "OneToMany", "ManyToMany" }; string[] fieldTypes = new string[] { "String", "Integer", "DateTime", "Boolean", "UtnEmall::Utils::Image" }; // El servicio fileStr += "InfService::New(InfrastructureService" + serviceDataModel.Id.ToString(System.Globalization.CultureInfo.CurrentCulture.NumberFormat) + ", " + serviceDataModel.IdStore + ", \"Service description\"){\n"; { // Las tablas foreach (TableEntity table in serviceDataModel.Tables) { if (table.IsStorage) { fileStr += "InfService::Table(" + UtnEmall.Server.Base.Utilities.GetValidIdentifier(table.Name, false) + ", true){ };\n"; } else { fileStr += "InfService::Table(" + UtnEmall.Server.Base.Utilities.GetValidIdentifier(table.Name, false) + "){\n"; // Los campos foreach (FieldEntity field in table.Fields) { fileStr += "InfService::Field(" + UtnEmall.Server.Base.Utilities.GetValidIdentifier(field.Name, false, false) + ", " + fieldTypes[field.DataType - 1] + ", \"\" );\n"; } fileStr += "};\n"; } } // Las relaciones foreach (RelationEntity relation in serviceDataModel.Relations) { fileStr += "InfService::Relation(" + UtnEmall.Server.Base.Utilities.GetValidIdentifier(relation.Source.Name, false) + ", " + UtnEmall.Server.Base.Utilities.GetValidIdentifier(relation.Target.Name, false) + ", " + relationTypes[relation.RelationType - 1] + ");\n"; } } fileStr += "};\n"; fileStr += "\n"; fileStr += "}\n"; // Guardar el programa Meta D++ en el disco string outputFileName; StreamWriter file = null; if (!buildClient) { outputFileName = Path.GetDirectoryName(serverPath) + Path.DirectorySeparatorChar + AssembliesFolder + Path.DirectorySeparatorChar + "Store" + serviceDataModel.IdStore.ToString(CultureInfo.InvariantCulture) + "Infrastructure.dpp"; } else { // Si el ensamblado del dispositivo móvil existe, crear uno diferente outputFileName = Path.GetDirectoryName(serverPath) + Path.DirectorySeparatorChar + AssembliesFolder + Path.DirectorySeparatorChar + "Store" + serviceDataModel.IdStore.ToString(CultureInfo.InvariantCulture) + "Infrastructure_Mobile.dpp"; } try { CheckAssembliesFolder(); file = new StreamWriter(outputFileName); file.Write(fileStr); } catch (IOException ioError) { Debug.WriteLine("FAILURE : While saving Meta D++ program to disk. ERROR : " + ioError.Message); return(null); } finally { if (file != null) { file.Close(); } } // En caso de éxito, retornar el nombre del programa return(outputFileName); }
/// <summary> /// Constructor de clase. /// </summary> public DataModelEditor() { this.InitializeComponent(); dataModel = new DataModelEntity(); storeDict = new Dictionary <string, StoreEntity>(); }
/// <summary> /// Carga el contenido del formulario en el objeto de entidad. /// </summary> private void Load() { dataModel = new DataModelEntity(); dataModel.Store = storeDict[(string)stores.SelectedItem]; }
/// <summary> /// Constructor de clase /// </summary> /// <param name="control">El componente que invoca al evento</param> /// <param name="dataModel">El modelo de datos del servicio</param> public ServiceBuilder(UserControl1 control, DataModelEntity dataModel) { Control = control; this.dataModel = dataModel; }