Exemple #1
0
 internal void Init()
 {
     TaskDefinitionIdsManager    = new TaskDefinitionIdsManager();
     OfflineSnippetsManager      = new OfflineSnippetsManager();
     DataSourceDefinitionManager = new DataSourceDefinitionManager();
     DatabaseDefinitionsManager  = new DatabaseDefinitionsManager();
 }
Exemple #2
0
        /// <summary>
        /// Checks if table can be deleted, by checking its references in all data sources in repository
        /// </summary>
        /// <param name="dbName">table name</param>
        /// <param name="dataSourceRepository">repository</param>
        /// <returns></returns>
        private bool CanDeleteTable(String dbName, DataSourceDefinitionManager dataSourceRepository)
        {
            foreach (KeyValuePair <DataSourceId, DataSourceDefinition> definitionEntry in dataSourceRepository.DataSourceDefinitions)
            {
                DataSourceDefinition dataSourceDefinition = (DataSourceDefinition)definitionEntry.Value;
                if (dataSourceDefinition.Name.Equals(dbName))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Read old data source repository
        /// </summary>
        /// <param name="dataDefinitionIdsUrl"> repository url to read old repository </param>
        /// <returns>returns old data source repository only if it is modified</returns>
        private DataSourceDefinitionManager GetOldDataSourceDefinitions(String dataDefinitionIdsUrl)
        {
            DataSourceDefinitionManager oldDataSourceDefinitionManager = null;

            try
            {
                // Get old data source repository url from last offline response
                String oldDataDefinitionIdsUrl = GetLastDataSourcesIdUrl();

                // Last offline response can not be available if startup program is modified or in case of executing non-offline program.
                // In this case , read the repository file available in cache without remote time constraint
                if (oldDataDefinitionIdsUrl == null)
                {
                    // split the url --> url and remote time
                    string[] urlAndRemoteTimePair = HttpUtility.UrlDecode(dataDefinitionIdsUrl, Encoding.UTF8).Split('|');
                    oldDataDefinitionIdsUrl = urlAndRemoteTimePair[0];
                }

                // read content form data source repository
                byte[] oldRepositoryContents = null;
                // the old (i.e. without the '_tmp' suffix) DbhDataIds may not be found in case this is the first access to the application.
                if (PersistentOnlyCacheManager.GetInstance().IsCompleteCacheRequestURLExistsLocally(oldDataDefinitionIdsUrl))
                {
                    oldRepositoryContents = LocalCommandsProcessor.GetInstance().GetContent(oldDataDefinitionIdsUrl, true);
                }

                // if contents are modified then return old data source repository
                if (oldRepositoryContents != null && (oldRepositoryContents.Length != NewDataSourceRepositoryContents.Length ||
                                                      !Misc.CompareByteArray(oldRepositoryContents, NewDataSourceRepositoryContents, NewDataSourceRepositoryContents.Length)))
                {
                    // parse repository content and read data sources and build the data source definition collection
                    oldDataSourceDefinitionManager = new DataSourceDefinitionManager();
                    oldDataSourceDefinitionManager.DataSourceBuilder.DataSourceReader = GetOldDataSourceBuffer;
                    new DataSourceDefinitionManagerSaxHandler(oldRepositoryContents, oldDataSourceDefinitionManager);
                }

                // new repository contents are not needed more for datasource converter
                NewDataSourceRepositoryContents = null;
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteExceptionToLog(ex);
            }

            CommandsProcessorManager.SessionStatus = CommandsProcessorManager.SessionStatusEnum.Remote;

            return(oldDataSourceDefinitionManager);
        }
Exemple #4
0
        /// <summary>
        /// Compares the old and new repository and handles conversion of data sources
        /// </summary>
        /// <param name="newRepository"></param>
        /// <param name="dataDefinitionIdsUrl">repository url to read old repository</param>
        public void HandleRepositoryChanges(DataSourceDefinitionManager newRepository, String dataDefinitionIdsUrl)
        {
            Logger.Instance.WriteSupportToLog("HandleRepositoryChanges():>>>> ", true);

            DataSourceDefinitionManager oldRepository = GetOldDataSourceDefinitions(dataDefinitionIdsUrl);

            // Skip conversion if old repository is not exist or it is not old.
            if (oldRepository == null)
            {
                return;
            }

            // change mouse cursor to busy as converion may take time in case tables with larger data
            Commands.setCursor(MgCursors.WAITCURSOR);

            foreach (KeyValuePair <DataSourceId, DataSourceDefinition> definitionEntry in oldRepository.DataSourceDefinitions)
            {
                DataSourceDefinition oldDefinition = (DataSourceDefinition)definitionEntry.Value;
                DataSourceDefinition newDefinition = newRepository.GetDataSourceDefinition(oldDefinition.Id);

                // Check for deletion
                if (newDefinition == null)
                {
                    // Chech if any other data sources in new repository refers to same table
                    if (CanDeleteTable(oldDefinition.Name, newRepository))
                    {
                        // Mark old table for delete
                        _convertCommandList.Add(new DeleteCommand(oldDefinition));
                    }
                }
                else
                {
                    // check if corresponding table is exist
                    if (!IsTableExist(oldDefinition))
                    {
                        continue;
                    }

                    // Check for conversion
                    ConversionReason reason = NeedsConversion(oldDefinition, newDefinition);

                    // todo: use startegy pattern instead of switch case of conversion reason and handling the corresponding operation
                    switch (reason)
                    {
                    case ConversionReason.DefinitionModified:
                    {
                        // Convert the old table to a temporary table using new definition
                        DataSourceDefinition convertedDefinition = ConvertDataSource(oldDefinition, newDefinition);

                        // Mark old table for delete
                        _convertCommandList.Add(new DeleteCommand(oldDefinition));

                        // Mark converted table to be renamed to original name
                        _convertCommandList.Add(new RenameCommand(convertedDefinition, newDefinition));
                    }
                    break;

                    case ConversionReason.KeyDBNameModified:
                    case ConversionReason.TableDBNameModified:
                        // Mark old table to be renamed
                        _convertCommandList.Add(new RenameCommand(oldDefinition, newDefinition));
                        break;

                    case ConversionReason.NotNeeded:
                        break; // Do nothing
                    }
                }
            }

            Commands.setCursor(MgCursors.ARROW);

            Logger.Instance.WriteSupportToLog("HandleRepositoryChanges():<<<< ", true);
        }