Ejemplo n.º 1
0
        private void AliasPublisher(List <string> aSourcePublisher, string aTargetPublisher)
        {
            ApplicationsDAO        lApplicationsDAO        = new ApplicationsDAO();
            ApplicationInstanceDAO lApplicationInstanceDAO = new ApplicationInstanceDAO();

            // insert a record into the PUBLISHER_ALIAS table
            foreach (string lSourcePublisher in aSourcePublisher)
            {
                int lPublisherAliasID = new PublisherAliasDAO().Insert(lSourcePublisher, aTargetPublisher);

                // confirm record entered ok?
                if (lPublisherAliasID != -1)
                {
                    DataTable sourcePublisherApplicationsDataTable = lApplicationsDAO.SelectApplicationByPublisherName(lSourcePublisher);

                    foreach (DataRow applicationRow in sourcePublisherApplicationsDataTable.Rows)
                    {
                        // check if the proposed new application already exists
                        // it is possible (but unlikely) that an application name and version combo already exist
                        int    lSourceApplicationId = (int)applicationRow.ItemArray[0];
                        string lApplicationName     = applicationRow.ItemArray[2].ToString();
                        string lApplicationVersion  = applicationRow.ItemArray[3].ToString();

                        int lExisitingApplicationId = lApplicationsDAO.SelectIdByPublisherNameVersion(aTargetPublisher, lApplicationName, lApplicationVersion);

                        if (lExisitingApplicationId > 0)
                        {
                            // found a match
                            // need to get the original applicationid and update all of the application_instances for this application

                            // one final issue is whether the application is aliased
                            // if it is, we need to update the application_instances so that the base applicationid is the original app id
                            // and the _applicationid is the aliased_toid
                            int lBaseApplicationId = 0;
                            int lAliasedToId       = lApplicationsDAO.SelectAliasedToIdByApplicationId(lExisitingApplicationId);

                            if (lAliasedToId != 0)
                            {
                                lBaseApplicationId      = lExisitingApplicationId;
                                lExisitingApplicationId = lAliasedToId;
                            }

                            lApplicationInstanceDAO.UpdateApplicationInstanceByApplicationId(lExisitingApplicationId, lBaseApplicationId, lSourceApplicationId);

                            // final step will be to delete the application we are aliasing. This will mean that if the user tries to revert
                            // this alias they won't be able to do so
                            lApplicationsDAO.DeleteByApplicationId(lSourceApplicationId);
                        }
                        else
                        {
                            // publiser, name, version combo doesn;t already exist so we can just update the publisher name
                            // enter a record into the PUBLISHER_ALIAS_APP table, this will allow us to revert the alias later if needed
                            new PublisherAliasAppDAO().Insert(lSourceApplicationId, lPublisherAliasID);

                            // finally updated the application to reflect the new publisher
                            lApplicationsDAO.UpdateAliasedPublishers(aTargetPublisher, lSourceApplicationId);
                        }
                    }
                }
            }
        }