Esempio n. 1
0
        public static void Begin()
        {
            List <Application>       applications       = ApplicationDAO.Get();
            List <Communication>     communications     = CommunicationDAO.Get();
            List <CommunicationType> communicationTypes = CommunicationTypeDAO.Get();
            List <DirectionType>     directionTypes     = DirectionTypeDAO.Get();

            foreach (Application app in applications)
            {
                // for each application, initalize inbound interface connections
            }
        }
Esempio n. 2
0
        //appel de la couche DAL ppur créer une nouvelle agence de Communication
        public int CreerCommunication(string sonNom, string saRue, string sonTelephone, string sonMail, string sonSite, int saVille, out string erreur)
        {
            erreur = "";
            Communication laComm;
            Ville         laVille;
            int           ajoutComm = 0;
            Regex         regex     = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,5})+)$");

            if (sonNom == "")
            {
                erreur += "\nVeuillez saisir le nom du l'agence";
            }
            if (saRue == "")
            {
                erreur += "\nVeuillez saisir la rue de l'agence";
            }
            if (sonTelephone == "")
            {
                erreur += "\nVeuillez saisir le numéro de téléphone de l'agence";
            }
            if (sonMail == "")
            {
                erreur += "\nVeuillez saisir l'adresse mail de l'agence";
            }
            if (regex.IsMatch(sonMail) == false)
            {
                erreur += "\nVeuillez saisir une adresse email correcte ( exemple: [email protected])";
            }
            if (sonSite == "")
            {
                erreur += "\nVeuillez saisir le nom du site web de l'agence";
            }
            if (saVille == 0)
            {
                erreur += "\nVeuillez sélectionner la ville de l'agence";
            }
            if (erreur == "")
            {
                laVille = new Ville(saVille);
                laComm  = new Communication(sonNom, saRue, sonTelephone, sonMail, sonSite, laVille);

                try
                {
                    ajoutComm = CommunicationDAO.GetInstance().AjoutComm(laComm);
                }
                catch (Exception err)
                {
                    erreur = "Erreur lors de la création de l'agence de communication" + err.Message;
                }
            }
            return(ajoutComm);
        }
        public static void Begin(Communication communication)
        {
            int beforeCount = 0;
            int afterCount  = 0;

            // Communication API
            List <Communication> communications;

            // Get exsisting
            beforeCount = CommunicationDAO.Get().Count;

            // Insert and Updating: if ID is included, it will update
            communication = CommunicationDAO.PostUpdate(communication);

            // Reading: Use GetCommunications() to retrieve a list of communicationlications
            communications = CommunicationDAO.Get();

            // get master item count
            afterCount = communications.Count;

            // write
            CommunicationTest.Write(communications, "INSERT", beforeCount, afterCount, true);
            Console.Read();

            // make a soft update to some property
            communication.applicationId = 1;

            // re-assign the before count
            beforeCount = afterCount;

            // Insert and Updating: if ID is included, it will update
            communication = CommunicationDAO.PostUpdate(communication);

            // Reading: Use GetCommunications() to retrieve a list of communicationlications
            communications = CommunicationDAO.Get();

            // Get exsisting
            afterCount = CommunicationDAO.Get().Count;

            // write
            CommunicationTest.Write(communications, "UPDATE", beforeCount, afterCount);
            Console.Read();

            // get a single communicationlication (returns a list)
            communications = CommunicationDAO.Get(communication);

            // get count
            afterCount = communications.Count;

            // reassign count
            beforeCount = afterCount;

            // write
            CommunicationTest.Write(communications, "Single", afterCount, 1);
            Console.Read();

            // Deleting - Send in the communicationlication w/ at minimal the ID populated
            CommunicationDAO.Delete(communication);

            // Reading: Use GetCommunications() to retreieve a list of communicationlications
            communications = CommunicationDAO.Get();

            // get count
            afterCount = communications.Count;

            // write
            CommunicationTest.Write(communications, "Removed", beforeCount, afterCount, true);
            Console.Read();
        }
Esempio n. 4
0
 //appel de la couche DAL pour récupérer une collection de communications
 public List <Communication> GetCommunications()
 {
     //ici on peut appliquer des règles métier
     return(CommunicationDAO.GetInstance().GetCommunications());
 }
        private static bool copyOutgoingDatabase(Application inFromApplication,
                                                 Application inToApplication,
                                                 string directionType,
                                                 string communicationType)
        {
            try
            {
                int toApplicationIdentity   = inFromApplication.id;
                int fromApplicationIdentity = inToApplication.id;
                // get all applications
                List <Configuration> applicationList = ConfigurationDAO.GetApplications(new Application()
                {
                    id = fromApplicationIdentity
                });

                // get all communuication and direction Types
                Configuration masterConfigration = ConfigurationDAO.GetAllConfigurations();

                // get the specific application direction and comm you want
                Configuration fromApplication = applicationList.Find(a => a.communicationType.name == communicationType &&
                                                                     a.directionType.name == directionType);


                // communication translation identities
                int toDirectionTypeId =
                    masterConfigration.directionTypes.Find(d => d.name == fromApplication.directionType.name).id;
                int toCommunicationTypeId =
                    masterConfigration.communicationTypes.Find(c => c.name == fromApplication.communicationType.name).id;

                // create a new application object with your current application identity
                Application toApplication = new Application()
                {
                    id = toApplicationIdentity
                };

                // insert a new communication with your exsisting application
                Communication toCommunication =
                    CommunicationDAO.PostUpdate(new Communication()
                {
                    applicationId       = toApplication.id,
                    communicationTypeId = toCommunicationTypeId,
                    directionTypeId     = toDirectionTypeId
                });


                // get the database_instance information (credential id, name, server, ip) of the communication identity.
                DatabaseInstance fromDatabaseInstance =
                    masterConfigration.databaseInstances.Find(i => i.communicationId == fromApplication.communication.id);

                // get database_instance id of the copy from insert into new database_instance with info prior step
                DatabaseInstance toDatabaseInstance = new DatabaseInstance();

                // copy individual values as not top copy the reference (we need it later)
                toDatabaseInstance = fromDatabaseInstance.ShallowCopy();

                // override the communication id w/ the "to" communication id
                toDatabaseInstance.id = 0;
                toDatabaseInstance.communicationId = toCommunication.id;
                // insert new database instance - get the id from this request
                toDatabaseInstance = DatabaseInstanceDAO.PostUpdate(toDatabaseInstance);

                // get all database tables from the fromDatabaseInstance
                List <Configuration> fromDatabaseTables = ConfigurationDAO.GetDatabaseTables(fromDatabaseInstance);

                // get the database table relations
                List <DatabaseTableRelation> databaseTableRelations = masterConfigration.databaseTableRelations;

                // create a new database relation object
                DatabaseTableRelation databaseTableRelation = new DatabaseTableRelation()
                {
                    id = 0,
                    requiresIdentity      = true,
                    sourceDatabaseTableId = -1,
                    targetDatabaseTableId = -1
                };

                // foreach table that belongs to the from database_instance, get the from database_table information
                fromDatabaseTables.ForEach(delegate(Configuration configurationTable)
                {
                    // extract the database table from the configuration
                    DatabaseTable fromDatabaseTable = new DatabaseTable()
                    {
                        id = configurationTable.databaseTable.id,
                        databaseInstanceId = fromDatabaseInstance.id,
                        name = configurationTable.databaseTable.name
                    };

                    // create new database table
                    DatabaseTable toDatabaseTable = new DatabaseTable()
                    {
                        databaseInstanceId = toDatabaseInstance.id,
                        name = fromDatabaseTable.name
                    };

                    // insert new table into database_table with fromDatabaseTable information but use toDatabaseInstanceId
                    toDatabaseTable = DatabaseTableDAO.PostUpdate(toDatabaseTable);

                    // check for prior source relation
                    if (ConfigurationUtility.IsDatabaseTableRelation(configurationTable.databaseTable, databaseTableRelations))
                    {
                        databaseTableRelation.sourceDatabaseTableId = toDatabaseTable.id;
                    }

                    // check for prior target relation
                    if (ConfigurationUtility.IsDatabaseTableRelation(configurationTable.databaseTable, databaseTableRelations, true))
                    {
                        databaseTableRelation.targetDatabaseTableId = toDatabaseTable.id;
                    }

                    // based on the fromDatabaseTable get all column sets
                    List <Configuration> fromColumnSets = ConfigurationDAO.GetDatabaseColumns(fromDatabaseTable);

                    // foreach columnset that belongs to fromDatabaseColumn copy all information (except for the fromDatabaseTableId)
                    fromColumnSets.ForEach(delegate(Configuration configurationColumnSet)
                    {
                        // define the column set
                        ColumnSet fromColumnSet = new ColumnSet();
                        ColumnSet toColumnSet   = new ColumnSet();

                        // get the column set from the configuration list
                        fromColumnSet = configurationColumnSet.columnSet;
                        fromColumnSet.databaseTableId = configurationColumnSet.databaseTable.id;

                        // do a shallow copy of its properties and override the ones you need
                        toColumnSet    = fromColumnSet.ShallowCopy();
                        toColumnSet.id = 0;
                        toColumnSet.databaseTableId = toDatabaseTable.id;

                        // insert new toColumnSet using new toDAtabaseTable.id
                        toColumnSet = ColumnSetDAO.PostUpdate(toColumnSet);
                    });
                });

                // if relation source or target is not negative one - insert new relation
                if (databaseTableRelation.sourceDatabaseTableId != -1 &&
                    databaseTableRelation.targetDatabaseTableId != -1)
                {
                    databaseTableRelation = DatabaseTableRelationDAO.PostUpdate(databaseTableRelation);
                }
            }
            catch (Exception ex)
            {
                string fromApplicationId = inFromApplication.id.ToString();
                string toApplicationId   = inToApplication.id.ToString();
                ErrorLogger.LogError(ex,
                                     "CopyConfigurationUtility.CopyOutgoingDatabase(fromApplication, toApplication, directionType,communicationType)",
                                     fromApplicationId + "|" +
                                     toApplicationId + "|" +
                                     directionType + "|" +
                                     communicationType);

                return(false);
            }

            return(true);
        }