public void EndGetCustomerServiceData(System.IAsyncResult result) { GetCustomerServiceResult callResult = new GetCustomerServiceResult(); try { HttpWebRequest request = (HttpWebRequest)result.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); // Crear la instancia del deserializador. DataContractSerializer serializer = new DataContractSerializer(typeof(CustomerServiceDataEntity)); // Deserializar el modelo de datos. CustomerServiceDataEntity deserializedCustomerService = (CustomerServiceDataEntity)serializer.ReadObject(response.GetResponseStream()); callResult.CustomerService = deserializedCustomerService; } catch (SerializationException serializationError) { Debug.WriteLine(serializationError.Message); } catch (WebException webError) { Debug.WriteLine(webError.Message); } // Si hay callback, invocarlo. if (getCustomerServiceCallback != null) { getCustomerServiceCallback(callResult); getCustomerServiceCallback = null; } }
/// <summary> /// Function to save a CustomerServiceDataEntity to the database. /// </summary> /// <param name="customerServiceDataEntity">CustomerServiceDataEntity to save</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the CustomerServiceDataEntity was saved successfully, the same CustomerServiceDataEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="customerServiceDataEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public CustomerServiceDataEntity Save(CustomerServiceDataEntity customerServiceDataEntity, string session) { bool permited = ValidationService.Instance.ValidatePermission(session, "save", "CustomerServiceData"); 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(customerServiceDataEntity)) { return(customerServiceDataEntity); } try { // Save customerServiceDataEntity using data access object customerservicedataDataAccess.Save(customerServiceDataEntity); return(null); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmall.Server.BusinessLogic.UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }
/// <summary> /// Actualiza los archivos de ensamblado en la entidad de servicio. /// </summary> /// <param name="serviceModel">El modelo de servicio desde el cuál se actualizan los datos.</param> /// <param name="fileName">El nombre de archivo.</param> /// <param name="clientVersionFileName">El nombre del archivo del cliente</param> /// <param name="sessionIdentifier">Sesión de usuario</param> /// <returns>True si se guardó con éxito.</returns> static private bool SaveCustomServiceModel(CustomerServiceDataEntity serviceModel, string fileName, string clientVersionFileName, string sessionIdentifier) { try { ServiceDataAccess serviceDataAccess = new ServiceDataAccess(); ServiceEntity serviceEntity = serviceModel.Service; if (serviceEntity == null) { Service serviceLogic = new Service(); serviceEntity = serviceLogic.GetService(serviceModel.IdService, false, sessionIdentifier); } serviceEntity.Deployed = true; serviceEntity.PathAssemblyServer = Path.GetFileNameWithoutExtension(fileName) + ".dll"; serviceEntity.RelativePathAssembly = Path.GetFileNameWithoutExtension(clientVersionFileName) + ".dll"; serviceDataAccess.Save(serviceEntity); return(true); } catch (UtnEmallDataAccessException error) { Debug.WriteLine("FAILURE : While updating custom service entity. ERROR : " + error.Message); return(false); } catch (UtnEmallBusinessLogicException error) { Debug.WriteLine("FAILURE : While updating custom service entity. ERROR : " + error.Message); return(false); } }
/// <summary> /// Construir programa Meta D++ /// </summary> /// <param name="serviceModel">El modelo de servicio</param> /// <param name="buildMobil">True para construir la versión móvil</param> /// <returns>El nombre del programa</returns> private string BuildMetaDppProgramForCustomerService(CustomerServiceDataEntity serviceModel, bool buildMobil) { string filename = null; string fileContent = null; if (buildMobil) { filename = "CustomService" + serviceModel.Id + "_Mobile.dpp"; fileContent = DppExporter.Service(serviceModel, true); } else { filename = "CustomService" + serviceModel.Id + ".dpp"; fileContent = DppExporter.Service(serviceModel, false); } filename = Path.GetDirectoryName(serverPath) + Path.DirectorySeparatorChar + AssembliesFolder + Path.DirectorySeparatorChar + filename; try { CheckAssembliesFolder(); StreamWriter file = new StreamWriter(filename); file.Write(fileContent); file.Close(); } catch (SecurityException secuirtyError) { Debug.WriteLine("ERROR : security error while saving meta dpp program for custom service. ORIGINAL ERROR : " + secuirtyError.Message); } catch (IOException ioError) { Debug.WriteLine("ERROR : io error while saving meta dpp program for custom service. ORIGINAL ERROR : " + ioError.Message); } return(filename); }
public void BeginSaveCustomerServiceData(CustomerServiceDataEntity customServiceDataEntity, SaveCustomerServiceCallback callback) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( new Uri(serverBaseUri, relativeSaveCustomerServiceDataURI)); request.Method = "POST"; saveCustomerServiceCallback = 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(CustomerServiceDataEntity)); serializer.WriteObject(streamWriter.BaseStream, customServiceDataEntity); streamWriter.Close(); // Realizar una llamada asíncrona. Se invocará un Callback sobre un hilo ejecutándose en segundo plano. request.BeginGetResponse(new AsyncCallback(EndSaveCustomerServiceData), request); } , request); }
/// <summary> /// Function to delete a CustomerServiceDataEntity from database. /// </summary> /// <param name="customerServiceDataEntity">CustomerServiceDataEntity to delete</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the CustomerServiceDataEntity was deleted successfully, the same CustomerServiceDataEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="customerServiceDataEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public CustomerServiceDataEntity Delete(CustomerServiceDataEntity customerServiceDataEntity, string session) { bool permited = ValidationService.Instance.ValidatePermission(session, "delete", "CustomerServiceData"); 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 (customerServiceDataEntity == null) { throw new ArgumentException("The argument can not be null or be empty"); } try { // Delete customerServiceDataEntity using data access object customerservicedataDataAccess.Delete(customerServiceDataEntity); return(null); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmall.Server.BusinessLogic.UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }
private static void IndexItems(CustomerServiceDataEntity customerServiceDataEntity, Dictionary <int, ConnectionWidgetEntity> connectionWidgetDictionary, Dictionary <int, ComponentEntity> componentDictionary, Dictionary <int, ConnectionPointEntity> connectionPointDictionary, Dictionary <int, TableEntity> tableDictionary, Dictionary <int, FieldEntity> fieldDictionary) { if (customerServiceDataEntity.DataModel != null) { foreach (TableEntity table in customerServiceDataEntity.DataModel.Tables) { AddDictionary(tableDictionary, table.Id, table); foreach (FieldEntity field in table.Fields) { AddDictionary(fieldDictionary, field.Id, field); } } } foreach (ConnectionWidgetEntity connectionWidgetEntity in customerServiceDataEntity.Connections) { AddDictionary(connectionWidgetDictionary, connectionWidgetEntity.Id, connectionWidgetEntity); AddDictionary(connectionPointDictionary, connectionWidgetEntity.Source.Id, connectionWidgetEntity.Source); AddDictionary(connectionPointDictionary, connectionWidgetEntity.Target.Id, connectionWidgetEntity.Target); } foreach (ComponentEntity componentEntity in customerServiceDataEntity.Components) { IndexComponentEntity(componentEntity, connectionWidgetDictionary, componentDictionary, connectionPointDictionary, tableDictionary, fieldDictionary); } }
public bool SaveCustomerServiceData(CustomerServiceDataEntity customerServiceDataEntity) { ServiceEntity currentService = null; // Carga el servicio. currentService = ServicesClients.Service.GetService((int)Session[SessionConstants.IdCurrentService], true, this.UserSession); if (currentService != null) { // Corrige referencias circulares. customerServiceDataEntity.DataModel = this.InternalLoadDataModel(); CircularReferencesManager.FixCustomerServiceDataCircularReferences(customerServiceDataEntity); // Asigna los datos del servicio personalizado al servicio. currentService.CustomerServiceData = customerServiceDataEntity; customerServiceDataEntity.Service = currentService; // Guarda el servicio. ServiceEntity result = ServicesClients.Service.Save(currentService, this.UserSession); if (result == null) { return(true); } } // ...sino retorna falso. return(false); }
public CustomerServiceDataEntity GetCustomerServiceData(int customerServiceId) { CustomerServiceDataEntity customerService = ServicesClients.CustomerServiceData.GetCustomerServiceData( customerServiceId, true, this.UserSession); if (customerService != null) { CircularReferencesManager.BrokeCustomerServiceDataCircularReference(customerService); return(customerService); } return(null); }
public static void BrokeCustomerServiceDataCircularReference(CustomerServiceDataEntity customerServiceDataEntity) { int id; // Rompe la referencia con el servicio. id = customerServiceDataEntity.IdService; customerServiceDataEntity.Service = null; customerServiceDataEntity.IdService = id; // Itera las conexiones. foreach (ConnectionWidgetEntity connectionWidgetEntity in customerServiceDataEntity.Connections) { connectionWidgetEntity.CustomerServiceData = null; AssingTempId(connectionWidgetEntity); AssingTempId(connectionWidgetEntity.Source); AssingTempId(connectionWidgetEntity.Target); id = connectionWidgetEntity.Source.IdConnectionWidget; connectionWidgetEntity.Source.ConnectionWidget = null; connectionWidgetEntity.Source.IdConnectionWidget = id; id = connectionWidgetEntity.Target.IdConnectionWidget; connectionWidgetEntity.Target.ConnectionWidget = null; connectionWidgetEntity.Target.IdConnectionWidget = id; id = connectionWidgetEntity.Source.IdComponent; connectionWidgetEntity.Source.Component = null; connectionWidgetEntity.Source.IdComponent = id; id = connectionWidgetEntity.Target.IdComponent; connectionWidgetEntity.Target.Component = null; connectionWidgetEntity.Target.IdComponent = id; } // Itera los componentes. foreach (ComponentEntity componentEntity in customerServiceDataEntity.Components) { BrokeComponentEntityCircularReference(componentEntity); } id = customerServiceDataEntity.IdDataModel; customerServiceDataEntity.DataModel = null; customerServiceDataEntity.IdDataModel = id; id = customerServiceDataEntity.IdInitComponent; customerServiceDataEntity.InitComponent = null; customerServiceDataEntity.IdInitComponent = id; id = customerServiceDataEntity.IdService; customerServiceDataEntity.Service = null; customerServiceDataEntity.IdService = id; }
/// <summary> /// Función que convierte un ServiceDocument en un CustomerServiceDataEntity para poder guardarlo. /// </summary> /// <returns></returns> public CustomerServiceDataEntity Save() { CustomerServiceDataEntity customerServiceDataEntity = null; try { customerServiceDataEntity = LogicalLibrary.Utilities.ConvertServiceModelToEntity(this, this.DataModelEntity); return(customerServiceDataEntity); } catch (InvalidCastException) { return(null); } }
public void BeginSaveCustomerService(ServiceDocument serviceDocument, SaveCustomerServiceCallback callback) { try { CustomerServiceDataEntity customerServiceData = Utilities.ConvertServiceModelToEntity(serviceDocument, this.dataModelEntity); CircularReferencesManager.BrokeCustomerServiceDataCircularReference(customerServiceData); SilverlightServicesClient client = Utils.SilverlightServicesClient; client.BeginSaveCustomerServiceData(customerServiceData, callback); } catch (Exception) { throw; } }
private void buttonSave_Click(object sender, RoutedEventArgs e) { CustomerServiceDataEntity customerServiceDataEntity = document.Save(); if (customerServiceDataEntity == null) { Util.ShowErrorMessage("No se pudo guardar el servicio"); return; } document.ServiceEntity.CustomerServiceData = customerServiceDataEntity; Util.ShowOKMessage("Servicio guardado exitosamente", "Éxito"); this.result = true; this.Close(); }
private void buttonSave_Click(object sender, RoutedEventArgs e) { CustomerServiceDataEntity customerServiceDataEntity = document.Save(); if (customerServiceDataEntity == null) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.ImpossibleSaveService); return; } document.ServiceEntity.CustomerServiceData = customerServiceDataEntity; Util.ShowInformationDialog(UtnEmall.ServerManager.Properties.Resources.ServiceSavedSuccessfully, UtnEmall.ServerManager.Properties.Resources.SaveSuccessfully); this.Result = true; this.Close(); }
/// <summary> /// Function to validate a CustomerServiceDataEntity before it's saved. /// </summary> /// <param name="customerServiceDataEntity">CustomerServiceDataEntity to validate</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the CustomerServiceDataEntity was deleted successfully, the same CustomerServiceDataEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="customerServiceDataEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public bool Validate(CustomerServiceDataEntity customerServiceData) { bool result = true; if (customerServiceData == null) { throw new ArgumentException("The argument can not be null or be empty"); } // Check entity data if (customerServiceData.CustomerServiceDataType < 0) { customerServiceData.Errors.Add(new Error("CustomerServiceDataType", "CustomerServiceDataType", "El tipo de dato del servicio no puede ser negativo")); result = false; } return(result); }
private void InitCustomServices() { try { // Cargar los modelos de datos y verificar los ensamblados ServiceDataAccess serviceDataAccess = new ServiceDataAccess(); Collection <ServiceEntity> services = serviceDataAccess.LoadAll(true); foreach (ServiceEntity service in services) { string assemblyFileName = service.PathAssemblyServer; if (assemblyFileName != null) { if (File.Exists(Path.Combine(ServiceBuilder.AssembliesFolder, assemblyFileName))) { Type[] servicesTypes = ServiceBuilder.GetCustomServiceTypes(assemblyFileName); Binding serviceBinding = new BasicHttpBinding(); if (PublishCustomService(servicesTypes[0], servicesTypes[1], serviceBinding)) { Debug.WriteLine("SUCCESS : custom service published."); } else { Debug.WriteLine("FAILURE : trying to publish custom service."); } } else { CustomerServiceDataDataAccess customerServiceData = new CustomerServiceDataDataAccess(); CustomerServiceDataEntity customerService = customerServiceData.Load(service.IdCustomerServiceData, true); ServiceBuilder builder = new ServiceBuilder(); service.Deployed = false; customerService.Service = service; builder.BuildAndImplementCustomService(customerService, 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 static void FixCustomerServiceDataCircularReferences(CustomerServiceDataEntity customerServiceDataEntity) { var connectionWidgetDictionary = new Dictionary <int, ConnectionWidgetEntity>(); var componentDictionary = new Dictionary <int, ComponentEntity>(); var connectionPointDictionary = new Dictionary <int, ConnectionPointEntity>(); var tableDictionary = new Dictionary <int, TableEntity>(); var fieldDictionary = new Dictionary <int, FieldEntity>(); AddDictionary(connectionWidgetDictionary, 0, null); AddDictionary(componentDictionary, 0, null); AddDictionary(connectionPointDictionary, 0, null); AddDictionary(tableDictionary, 0, null); AddDictionary(fieldDictionary, 0, null); IndexItems(customerServiceDataEntity, connectionWidgetDictionary, componentDictionary, connectionPointDictionary, tableDictionary, fieldDictionary); FixCustomerServiceDataCircularReferences(customerServiceDataEntity, connectionWidgetDictionary, componentDictionary, connectionPointDictionary, tableDictionary, fieldDictionary); }
private static string Forms(Collection <ComponentEntity> components, CustomerServiceDataEntity serviceModel) { string forms = ""; // Reemplaza elementos de plantilla foreach (ComponentEntity component in components) { ComponentType type = (ComponentType)component.ComponentType; switch (type) { case ComponentType.ListForm: case ComponentType.MenuForm: case ComponentType.ShowDataForm: case ComponentType.EnterSingleDataFrom: forms += Form(component, serviceModel); break; } } return(FormsTemplate.Replace("%FORMS%", forms)); }
private void ButtonSave_Click(object sender, RoutedEventArgs e) { try { document.StartWidget = comboBoxForms.SelectedItem as Widget; if (document.StartWidget == null) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.NoStartForm, ""); return; } Collection <Error> listOfDesignerError = document.CheckDesignerLogic(); if (listOfDesignerError.Count > 0) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.ServiceDesignLogicIncorrect, listOfDesignerError); return; } if (!document.CheckValidPathForms()) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.InvalidServicePath); return; } CustomerServiceDataEntity customerServiceDataEntity = document.Save(); if (customerServiceDataEntity == null) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.SaveServiceError); return; } document.ServiceEntity.CustomerServiceData = customerServiceDataEntity; this.result = true; this.Close(); } catch (Exception error) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.UnhandledError + ": " + error.Message); } }
/// <summary> /// Cargar la entidad del servicio /// </summary> /// <param name="serviceModel">El servicio de cliente a partir del cual cargar la entidad.</param> /// <param name="sessionIdentifier">Identificador de sesión.</param> private static void LoadService(CustomerServiceDataEntity serviceModel, string sessionIdentifier) { if (serviceModel == null) { throw new ArgumentException("The argument serviceModel can not be null.", "serviceModel"); } // Si el servicio ya está desplegado, retornar. if (serviceModel.Service != null) { return; } // en caso contrario, cargarlo desde la base de datos try { Service serviceLogic = new Service(); serviceModel.Service = serviceLogic.GetService(serviceModel.IdService, false, sessionIdentifier); } catch (Exception) { throw new FaultException("Error loading service data."); } }
private static void FixCustomerServiceDataCircularReferences(CustomerServiceDataEntity customerServiceDataEntity, Dictionary <int, ConnectionWidgetEntity> connectionWidgetDictionary, Dictionary <int, ComponentEntity> componentDictionary, Dictionary <int, ConnectionPointEntity> connectionPointDictionary, Dictionary <int, TableEntity> tableDictionary, Dictionary <int, FieldEntity> fieldDictionary) { // Iterar conexiones. foreach (ConnectionWidgetEntity connectionWidgetEntity in customerServiceDataEntity.Connections) { // Relación 1 connectionWidgetEntity.CustomerServiceData = customerServiceDataEntity; // Relación 2 connectionWidgetEntity.Source = connectionPointDictionary[connectionWidgetEntity.IdSource]; connectionWidgetEntity.Source.ConnectionWidget = connectionWidgetDictionary[connectionWidgetEntity.Source.IdConnectionWidget]; connectionWidgetEntity.Target = connectionPointDictionary[connectionWidgetEntity.IdTarget]; connectionWidgetEntity.Target.ConnectionWidget = connectionWidgetDictionary[connectionWidgetEntity.Target.IdConnectionWidget]; // Relación 3 connectionWidgetEntity.Source.Component = componentDictionary[connectionWidgetEntity.Source.IdComponent]; // Relación 3 connectionWidgetEntity.Target.Component = componentDictionary[connectionWidgetEntity.Target.IdComponent]; } // Iterar Componente foreach (ComponentEntity componentEntity in customerServiceDataEntity.Components) { FixComponentEntityCircularReference(componentEntity, customerServiceDataEntity, connectionWidgetDictionary, componentDictionary, connectionPointDictionary, tableDictionary, fieldDictionary); } customerServiceDataEntity.InitComponent = componentDictionary[customerServiceDataEntity.IdInitComponent]; }
/// <summary> /// Construye un programa Meta D++ para un servicio de cliente. /// Genera un programa servidor y un programa cliente. /// El argumento clientVersion es usado para seleccionar la versión del programa a generar. /// </summary> /// <param name="serviceModel">El servicio del cliente a partir del cual se generará el programa Meta D++.</param> /// <param name="clientVersion">Determina las versiones de cliente o servidor.</param> /// <returns>El texto de un programa Meta D++.</returns> public static string Service(CustomerServiceDataEntity serviceModel, bool clientVersion) { string tpl; string storeId = serviceModel.Service.IdStore.ToString(NumberFormatInfo.InvariantInfo); string programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Replace("\\", "\\\\"); string compactFrameworkPath = ServiceBuilder.CompactFrameworkPartialPath.Replace("\\", "\\\\"); string netFramework3PartialPath = ServiceBuilder.NetFramework3PartialPath.Replace("\\", "\\\\"); // Reemplaza los elementos de plantillas if (clientVersion) { tpl = GlobalTemplateClient; tpl = tpl.Replace("%INFRASTRUCTURE_DLL%", "Store" + storeId + "Infrastructure_Mobile.dll"); tpl = tpl.Replace("%SERVICE_CLASS_NAME%", "ModelMobile"); } else { tpl = GlobalTemplateServer; tpl = tpl.Replace("%INFRASTRUCTURE_DLL%", "Store" + storeId + "Infrastructure.dll"); tpl = tpl.Replace("%SERVICE_CLASS_NAME%", "CustomServiceServer"); } tpl = tpl.Replace("%NAMESPACE%", "UtnEmall::Store" + storeId + "::Services"); tpl = tpl.Replace("%SERVICE_NAME%", "CustomService" + serviceModel.Id.ToString(NumberFormatInfo.InvariantInfo)); tpl = tpl.Replace("%SERVICE_ID%", serviceModel.IdService.ToString(NumberFormatInfo.InvariantInfo)); tpl = tpl.Replace("%STORE_ID%", storeId); tpl = tpl.Replace("%SERVICE_DESCRIPTION%", Utilities.GetValidStringValue(serviceModel.Service != null ? serviceModel.Service.Description : "")); tpl = tpl.Replace("%RELATIONS%", Relations(serviceModel.Connections)); tpl = tpl.Replace("%FORMS%", Forms(serviceModel.Components, serviceModel)); tpl = tpl.Replace("%DATA_SOURCES%", DataSources(serviceModel.Components)); // Reemplaza carpetas de systema tpl = tpl.Replace("%PROGRAMFILES_FOLDER%", programFilesPath); tpl = tpl.Replace("%COMPACT_FRAMEWORK_FOLDER%", compactFrameworkPath); tpl = tpl.Replace("%NET_FRAMEWORK3_FOLDER%", netFramework3PartialPath); return(tpl); }
public bool BuildAndImplementCustomService(CustomerServiceDataEntity customerService, string sessionIdentifier) { // Verificar argumentos if (customerService == null) { throw new ArgumentException("Invalid null argument. Must provide an instance of DataModelEntity.", "customerService"); } if (sessionIdentifier == null) { throw new ArgumentException("Invalid null argument.", "sessionIdentifier"); } // Verificar si el servicio es válido CustomerServiceData customerServiceLogic = new CustomerServiceData(); if (!customerServiceLogic.Validate(customerService)) { throw new ArgumentException("Provided customer service is not valid.", "customerService"); } // Si el servicio ya está desplegado, lanzar un error if (customerService.Service == null) { // Si el servicio no fue cargado, cargarlo Service serviceLogic = new Service(); customerService.Service = serviceLogic.GetService(customerService.IdService, false, sessionIdentifier); } if (customerService.Service.Deployed) { throw new FaultException(Resources.CustomerServiceAlreadyDeployed); } // El modelo de datos asociado debe ser desplegado if (!customerService.DataModel.Deployed) { throw new FaultException(Resources.DataModelMustBeDeployed); } ConsoleWriter.SetText("Building custom service."); // Carga el contenedor del servicio LoadService(customerService, sessionIdentifier); // Construir el programa Meta D++ string fileName = BuildMetaDppProgramForCustomerService(customerService, false); string clientVersionFileName = BuildMetaDppProgramForCustomerService(customerService, true); // Intentar transferir el servicio si está activo if (ServerHost.Instance.StopCustomService(Path.GetFileNameWithoutExtension(fileName))) { try { File.Delete(Path.ChangeExtension(fileName, ".dll")); File.Delete(Path.ChangeExtension(clientVersionFileName, ".dll")); } catch { Debug.WriteLine("Old services files couldn´t be deleted."); } // Compilar el programa Meta D++ if (CompileMetaDppProgram(new Uri(fileName), false)) { // Construir la versión móvil del servicio de infraestructura if (CompileMetaDppProgram(new Uri(clientVersionFileName), true)) { ConsoleWriter.SetText("Building custom service successful."); Debug.WriteLine("Custom Service Dll for Mobile succeful builded."); fileName = Path.ChangeExtension(fileName, ".dll"); clientVersionFileName = Path.ChangeExtension(clientVersionFileName, ".dll"); SaveCustomServiceModel(customerService, fileName, clientVersionFileName, sessionIdentifier); // Inciar el servicio web return(PublishCustomService(fileName)); } else { Debug.WriteLine("Error building Custom Service Dll for Mobile."); } } } return(false); }
private static string Form(ComponentEntity component, CustomerServiceDataEntity serviceModel) { string tpl = FormTemplate; // Reemplaza elementos de plantillas tpl = tpl.Replace("%TYPE%", ComponentTypeToString(component.ComponentType)); tpl = tpl.Replace("%NAME%", GetNameForComponent(component, false)); tpl = tpl.Replace("%FORMTITLE%", Utilities.GetValidStringValue(component.Title)); tpl = tpl.Replace("%COMPONENT_ID%", component.Id.ToString(NumberFormatInfo.InvariantInfo)); if (component.Id == serviceModel.IdInitComponent) { tpl = tpl.Replace("%STARTFORM%", "true"); } else { tpl = tpl.Replace("%STARTFORM%", "false"); } tpl = tpl.Replace("%FINALFORM%", (component.FinalizeService) ? "true" : "false"); ComponentType type = (ComponentType)component.ComponentType; if (component.ComponentType != (int)ComponentType.FormMenuItem) { string tplExtra = FormExtraTemplate; string tplExtraEnter = FormExtraEnterTemplate; string fields = ""; if (component.InputDataContext == null) { tplExtra = tplExtra.Replace("%INPUT%", "null"); tplExtra = tplExtra.Replace("%INPUT_TABLE_ID%", "null"); } else { tplExtra = tplExtra.Replace("%INPUT%", Utilities.GetValidIdentifier(component.InputDataContext.Name, false) + "Entity"); tplExtra = tplExtra.Replace("%INPUT_TABLE_ID%", component.InputDataContext.Id.ToString(NumberFormatInfo.InvariantInfo)); } if (component.OutputDataContext == null) { tplExtra = tplExtra.Replace("%OUTPUT%", "null"); } else { tplExtra = tplExtra.Replace("%OUTPUT%", Utilities.GetValidIdentifier(component.OutputDataContext.Name, false) + "Entity"); } switch (type) { case ComponentType.EnterSingleDataFrom: tplExtra = tplExtra.Replace("%ISINPUTAREGISTER%", "true"); tplExtra = tplExtra.Replace("%ISOUTPUTAREGISTER%", "true"); tplExtraEnter = tplExtraEnter.Replace("%ENTERDATAVALUETYPE%", component.DataTypes.ToString(CultureInfo.CurrentCulture.NumberFormat)); tplExtraEnter = tplExtraEnter.Replace("%ENTERDATAFIELDNAME%", Utilities.GetValidIdentifier(component.Title, true, false)); tplExtraEnter = tplExtraEnter.Replace("%ENTERDATADESCRIPTION%", Utilities.GetValidStringValue(component.DescriptiveText)); break; case ComponentType.MenuForm: tplExtra = tplExtra.Replace("%ISINPUTAREGISTER%", "false"); tplExtra = tplExtra.Replace("%ISOUTPUTAREGISTER%", "true"); tplExtraEnter = ""; break; case ComponentType.ListForm: tplExtra = tplExtra.Replace("%ISINPUTAREGISTER%", "false"); tplExtra = tplExtra.Replace("%ISOUTPUTAREGISTER%", "true"); tplExtraEnter = ""; break; case ComponentType.ShowDataForm: tplExtra = tplExtra.Replace("%ISINPUTAREGISTER%", "true"); tplExtra = tplExtra.Replace("%ISOUTPUTAREGISTER%", "true"); tplExtraEnter = ""; break; default: throw new ArgumentException("Componen must be a Form"); } tpl = tpl.Replace("%EXTRAFIELDS%", tplExtra); tpl = tpl.Replace("%EXTRAFIELDSENTER%", tplExtraEnter); if (component.ComponentType == (int)ComponentType.ListForm || component.ComponentType == (int)ComponentType.ShowDataForm) { foreach (ComponentEntity field in component.TemplateListFormDocument.Components) { fields += Field(field); } } if (component.ComponentType == (int)ComponentType.MenuForm) { foreach (ComponentEntity field in component.MenuItems) { fields += FieldMenuItem(field); } } tpl = tpl.Replace("%FIELDS%", fields); } else { tpl = tpl.Replace("%EXTRAFIELDS%", ""); } return(tpl); }
/// <summary> /// Convierte un CustomerServiceDataEntity almacenado en la base de datos en un ServiceDocumentWpf para ser usado en un proyecto wpf /// </summary> /// <param name="documentEntity"></param> /// <param name="serviceDocumentWpf"></param> public static void ConvertEntityToServiceModel(CustomerServiceDataEntity documentEntity, ServiceDocumentWpf serviceDocumentWpf) { Dictionary <Component, ComponentEntity> connectableComponents = new Dictionary <Component, ComponentEntity>(); foreach (ComponentEntity componentEntity in documentEntity.Components) { switch (componentEntity.ComponentType) { // Convierte un DataSourceEntity en un DataSourceWpf case (int)ComponentType.DataSource: DataSourceWpf dataSource = Utilities.ConvertEntityToDataSource(componentEntity, serviceDocumentWpf.DataModel); dataSource.MakeCanvas(); serviceDocumentWpf.Components.Add(dataSource); connectableComponents.Add(dataSource, componentEntity); break; // Convierte un EnterSingleDataFormEntity en un EnterSingleDataFormWpf case (int)ComponentType.EnterSingleDataFrom: EnterSingleDataFormWpf enterSingleData = Utilities.ConvertEntityToEnterSingleData(componentEntity); enterSingleData.MakeCanvas(); serviceDocumentWpf.Components.Add(enterSingleData); connectableComponents.Add(enterSingleData, componentEntity); break; // Convierte un ListFormEntity en un ListFormWpf case (int)ComponentType.ListForm: ListFormWpf listFormWpf = Utilities.ConvertEntityToListForm(componentEntity); listFormWpf.MakeCanvas(); serviceDocumentWpf.Components.Add(listFormWpf); connectableComponents.Add(listFormWpf, componentEntity); if (documentEntity.InitComponent != null && documentEntity.InitComponent.Id == componentEntity.Id) { serviceDocumentWpf.StartWidget = listFormWpf; } break; // Convierte un MenuFormEntity en un MenuFormWpf case (int)ComponentType.MenuForm: MenuFormWpf menuForm = Utilities.ConvertEntityToMenuForm(componentEntity); menuForm.MakeCanvas(); serviceDocumentWpf.Components.Add(menuForm); connectableComponents.Add(menuForm, componentEntity); for (int i = 0; i < menuForm.MenuItems.Count; i++) { connectableComponents.Add(menuForm.MenuItems[i], componentEntity.MenuItems[i]); } if (documentEntity.InitComponent != null && documentEntity.InitComponent.Id == componentEntity.Id) { serviceDocumentWpf.StartWidget = menuForm; } break; // Convierte un ShowDataFormEntity en un ShowDataFormWpf case (int)ComponentType.ShowDataForm: ShowDataFormWpf showDataFormWpf = Utilities.ConvertEntityToShowDataForm(componentEntity); showDataFormWpf.MakeCanvas(); serviceDocumentWpf.Components.Add(showDataFormWpf); connectableComponents.Add(showDataFormWpf, componentEntity); break; default: break; } } // Convierte cada una de las conexiones foreach (ConnectionWidgetEntity connectionWidgetEntity in documentEntity.Connections) { ConnectionWpf connectionWpf = ConvertEntityToConnection(connectableComponents, connectionWidgetEntity, serviceDocumentWpf); serviceDocumentWpf.AddConnection(connectionWpf); } }
private static void FixComponentEntityCircularReference(ComponentEntity componentEntity, CustomerServiceDataEntity customerServiceDataEntity, Dictionary <int, ConnectionWidgetEntity> connectionWidgetDictionary, Dictionary <int, ComponentEntity> componentDictionary, Dictionary <int, ConnectionPointEntity> connectionPointDictionary, Dictionary <int, TableEntity> tableDictionary, Dictionary <int, FieldEntity> fieldDictionary) { componentEntity.CustomerServiceData = customerServiceDataEntity; // Rompo ref 4 componentEntity.InputConnectionPoint = connectionPointDictionary[componentEntity.IdInputConnectionPoint]; // componentEntity.IdInputConnectionPoint = id; componentEntity.OutputConnectionPoint = connectionPointDictionary[componentEntity.IdOutputConnectionPoint]; //Rompo ref 3 if (componentEntity.InputConnectionPoint != null) { componentEntity.InputConnectionPoint.ParentComponent = componentDictionary[componentEntity.InputConnectionPoint.IdParentComponent]; if (componentEntity.InputConnectionPoint != null) { componentEntity.InputConnectionPoint.ConnectionWidget = connectionWidgetDictionary[componentEntity.InputConnectionPoint.IdConnectionWidget]; } } if (componentEntity.OutputConnectionPoint != null) { componentEntity.OutputConnectionPoint.ParentComponent = componentDictionary[componentEntity.OutputConnectionPoint.IdParentComponent]; if (componentEntity.OutputConnectionPoint != null) { componentEntity.OutputConnectionPoint.ConnectionWidget = connectionWidgetDictionary[componentEntity.OutputConnectionPoint.IdConnectionWidget]; } } // Rompo Ref 5 componentEntity.ParentComponent = componentDictionary[componentEntity.IdParentComponent]; // componentEntity.IdParentComponent = id; //Parte de Fields y Tables componentEntity.FieldAssociated = fieldDictionary[componentEntity.IdFieldAssociated]; // componentEntity.IdFieldAssociated = id; componentEntity.FieldToOrder = fieldDictionary[componentEntity.IdFieldToOrder]; // componentEntity.IdFieldToOrder = id; componentEntity.OutputDataContext = tableDictionary[componentEntity.IdOutputDataContext]; // componentEntity.IdOutputDataContext = id; componentEntity.InputDataContext = tableDictionary[componentEntity.IdInputDataContext]; // componentEntity.IdInputDataContext = id; componentEntity.RelatedTable = tableDictionary[componentEntity.IdRelatedTable]; // Menuitems if (componentEntity.MenuItems != null) { foreach (ComponentEntity menuItem in componentEntity.MenuItems) { FixComponentEntityCircularReference(menuItem, customerServiceDataEntity, connectionWidgetDictionary, componentDictionary, connectionPointDictionary, tableDictionary, fieldDictionary); } } // Template if (componentEntity.TemplateListFormDocument != null) { FixCustomerServiceDataCircularReferences( componentEntity.TemplateListFormDocument, connectionWidgetDictionary, componentDictionary, connectionPointDictionary, tableDictionary, fieldDictionary); } }
/// <summary> ///Funcion que convierte un CustomerServiceDataEntity en un TemplateListFormDocumentWpf para ser usado en un proyecto wpf /// </summary> /// <param name="customerServiceDataEntity"></param> /// <returns></returns> public static TemplateListFormDocumentWpf ConvertEntityToTemplateListDocument(CustomerServiceDataEntity customerServiceDataEntity) { TemplateListFormDocumentWpf templateListFormDocument = new TemplateListFormDocumentWpf(); foreach (ComponentEntity templateListItemEntity in customerServiceDataEntity.Components) { TemplateListItemWpf templateListItemWpf = ConvertEntityToTemplateListItemWpf(templateListItemEntity); templateListFormDocument.Components.Add(templateListItemWpf); } return(templateListFormDocument); }
/// <summary> /// Constructor de clase. /// </summary> /// <param name="control">El componente que será usado para invocar el evento en el hilo de la interfaz.</param> /// <param name="customerServiceData">Los datos del servicio del cliente a construir.</param> public CustomServiceBuilder(UserControl1 control, CustomerServiceDataEntity customerServiceData) { Control = control; this.customerServiceData = customerServiceData; }
/// <summary> /// Convierte un CustomerServiceDataEntity guardado en la base de datos en un ServiceDocumentWpf para ser usado en un proyecto wpf. /// </summary> /// <param name="documentEntity"></param> /// <param name="serviceDocumentWpf"></param> /// <param name="session"></param> public static void ConvertEntityToServiceModelWithStatistics(CustomerServiceDataEntity documentEntity, ServiceDocumentWpf serviceDocumentWpf, string session) { Dictionary <Component, ComponentEntity> connectableComponents = new Dictionary <Component, ComponentEntity>(); foreach (ComponentEntity componentEntity in documentEntity.Components) { StatisticsWpf statisticsCanvas; switch (componentEntity.ComponentType) { case (int)ComponentType.DataSource: // Genera e inserta un componente de origen de dato en un documento de servicio. DataSourceWpf dataSource = Utilities.ConvertEntityToDataSource(componentEntity, serviceDocumentWpf.DataModel); dataSource.MakeCanvas(); serviceDocumentWpf.Components.Add(dataSource); connectableComponents.Add(dataSource, componentEntity); break; case (int)ComponentType.EnterSingleDataFrom: // Genera e inserta el componente de entrada de datos en el documento del servicio. EnterSingleDataFormWpf enterSingleData = Utilities.ConvertEntityToEnterSingleData(componentEntity); enterSingleData.MakeCanvas(); serviceDocumentWpf.Components.Add(enterSingleData); connectableComponents.Add(enterSingleData, componentEntity); // Genera el componente de estadistica para el formulario y lo agrega statisticsCanvas = new StatisticsWpf(enterSingleData, serviceDocumentWpf.DrawArea, StatisticsWpf.GenerateStatisticSummary(componentEntity, session)); serviceDocumentWpf.Components.Add(statisticsCanvas); break; case (int)ComponentType.ListForm: // Genera e inserta el componente de origen de datos en el documento del servicio ListFormWpf listFormWpf = Utilities.ConvertEntityToListForm(componentEntity); listFormWpf.MakeCanvas(); serviceDocumentWpf.Components.Add(listFormWpf); connectableComponents.Add(listFormWpf, componentEntity); // Asigna el formulario de listas como el componente de inicio si lo es. if (documentEntity.InitComponent != null && documentEntity.InitComponent.Id == componentEntity.Id) { serviceDocumentWpf.StartWidget = listFormWpf; } // Genera el componente de estadistica y lo agrega statisticsCanvas = new StatisticsWpf(listFormWpf, serviceDocumentWpf.DrawArea, StatisticsWpf.GenerateStatisticSummary(componentEntity, session)); serviceDocumentWpf.Components.Add(statisticsCanvas); break; case (int)ComponentType.MenuForm: // Genera e inserta el componetne de origen de datos en el documento del servicio MenuFormWpf menuForm = Utilities.ConvertEntityToMenuForm(componentEntity); menuForm.MakeCanvas(); serviceDocumentWpf.Components.Add(menuForm); // Agrega el formulario de menu y todos los items del menu connectableComponents.Add(menuForm, componentEntity); for (int i = 0; i < menuForm.MenuItems.Count; i++) { connectableComponents.Add(menuForm.MenuItems[i], componentEntity.MenuItems[i]); } // Asigna el formulario de menu como componente de inicio if (documentEntity.InitComponent != null && documentEntity.InitComponent.Id == componentEntity.Id) { serviceDocumentWpf.StartWidget = menuForm; } // Genera el componente de estadistica y lo agrega statisticsCanvas = new StatisticsWpf(menuForm, serviceDocumentWpf.DrawArea, StatisticsWpf.GenerateStatisticSummary(componentEntity, session)); serviceDocumentWpf.Components.Add(statisticsCanvas); break; case (int)ComponentType.ShowDataForm: // Genera e inserta el componente de origen de datos en el documento de servicio. ShowDataFormWpf showDataFormWpf = Utilities.ConvertEntityToShowDataForm(componentEntity); showDataFormWpf.MakeCanvas(); serviceDocumentWpf.Components.Add(showDataFormWpf); connectableComponents.Add(showDataFormWpf, componentEntity); // Genera el componente de estadistica y lo agrega statisticsCanvas = new StatisticsWpf(showDataFormWpf, serviceDocumentWpf.DrawArea, StatisticsWpf.GenerateStatisticSummary(componentEntity, session)); serviceDocumentWpf.Components.Add(statisticsCanvas); break; } } // Convierte cada una de las conexiones foreach (ConnectionWidgetEntity connectionWidgetEntity in documentEntity.Connections) { try { ConnectionWpf connectionWpf = ConvertEntityToConnection(connectableComponents, connectionWidgetEntity, serviceDocumentWpf); serviceDocumentWpf.AddConnection(connectionWpf); } catch (ArgumentNullException) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.NonFatalErrorLoadingConnection); } } }