예제 #1
0
        /// <summary>
        /// Obtiene una entidad de tabla, dependiendo del nombre y la tienda.
        /// </summary>
        private static TableEntity ObtainTableEntity(string tableName, StoreEntity store, string sessionId)
        {
            Table businessTableClient       = new Table();
            Collection <TableEntity> tables = businessTableClient.GetTableWhereEqual(TableEntity.DBName, tableName, sessionId);
            TableEntity result = null;

            switch (tables.Count)
            {
            // Lanzar una excepción en el caso de que no exista la tabla.
            case 0:
                throw new UtnEmallBusinessLogicException("The table doesn't exists");

            case 1:
                // La tabla debe tener un nombre
                if (tables[0].Name == tableName)
                {
                    result = tables[0];
                }
                else
                {
                    // Si el nombre de la tabla es diferente, lanzar una excepción
                    throw new UtnEmallBusinessLogicException("The table doesn't exists");
                }
                break;

            // Obtener la tienda propietaria de la tabla
            default:
                BusinessLogic.DataModel      businessDataModelClient = new BusinessLogic.DataModel();
                DataModelEntity              dataModelEntity;
                Collection <DataModelEntity> dataModels = businessDataModelClient.GetDataModelWhereEqual(DataModelEntity.DBIdStore, store.Id.ToString(System.Globalization.NumberFormatInfo.InvariantInfo), true, sessionId);

                // Recorrer el modelo de datos, hasta encontrar la tabla.
                for (int i = 0; i < dataModels.Count && result == null; i++)
                {
                    dataModelEntity = dataModels[i];

                    for (int j = 0; j < dataModelEntity.Tables.Count && result == null; j++)
                    {
                        TableEntity table = dataModelEntity.Tables[j];

                        if (tableName == table.Name)
                        {
                            result = table;
                        }
                    }
                }
                break;
            }

            // Lanzar una excepción si no se pudo encontrar la tabla
            if (result != null)
            {
                return(result);
            }
            else
            {
                throw new UtnEmallBusinessLogicException("The table doesn't exists");
            }
        }
        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);
        }