Exemple #1
0
        /// <summary>
        /// Convert DataSource from old DataSourceDefinition to new DataSourceDefinition. It create temporaryDataSource definition and perform all operations
        /// on temporary DataSourcedefinition and return it.
        /// </summary>
        /// <param name="fromDataSourceDefinition"></param>
        /// <param name="toDataSourceDefinition"></param>
        /// <returns>Temporary DataSourceDefinition</returns>
        private DataSourceDefinition ConvertDataSource(DataSourceDefinition fromDataSourceDefinition, DataSourceDefinition toDataSourceDefinition)
        {
            Logger.Instance.WriteSupportToLog("convertDataSource():>>>> ", true);
            Logger.Instance.WriteSupportToLog(String.Format("convertDataSource(): converting table {0}", fromDataSourceDefinition.Name), true);

            GatewayResult result = null;

            string temporaryTableName = GetTemporaryTableName(fromDataSourceDefinition.Id);

            DataSourceDefinition temporaryDataSourceDefinition = (DataSourceDefinition)toDataSourceDefinition.Clone();

            temporaryDataSourceDefinition.Name = temporaryTableName;

            // In order to genearte temporary key name for the temporary dbh set magic key mask on the keys.
            for (int keyIndex = 0; keyIndex < temporaryDataSourceDefinition.Keys.Count; keyIndex++)
            {
                DBKey key = temporaryDataSourceDefinition.Keys[keyIndex];
                key.SetMask(KeyMasks.MagicKeyMask);
            }

            // Delete temporary table, if exists
            result = GatewayCommandsFactory.CreateFileDeleteCommand(temporaryTableName, temporaryDataSourceDefinition, ClientManager.Instance.LocalManager).Execute();
            if (!result.Success && result.ErrorCode != GatewayErrorCode.FileNotExist)
            {
                throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription);
            }

            // Open source and temporary table
            temporaryDataSourceDefinition.SetMask(DbhMask.CheckExistMask);
            result = GatewayCommandsFactory.CreateFileOpenCommand(temporaryTableName, temporaryDataSourceDefinition, Access.Write, ClientManager.Instance.LocalManager).Execute();
            if (result.Success)
            {
                result = GatewayCommandsFactory.CreateFileOpenCommand(fromDataSourceDefinition.Name, fromDataSourceDefinition, Access.Read, ClientManager.Instance.LocalManager).Execute();
            }

            if (!result.Success)
            {
                throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription);
            }

            //Convert values of source table and insert it into temporary table
            ConvertAndInsertValues(fromDataSourceDefinition, temporaryDataSourceDefinition);

            //Close source and temporary table
            result = GatewayCommandsFactory.CreateFileCloseCommand(temporaryDataSourceDefinition, ClientManager.Instance.LocalManager).Execute();
            if (result.Success)
            {
                GatewayCommandsFactory.CreateFileCloseCommand(fromDataSourceDefinition, ClientManager.Instance.LocalManager).Execute();
            }

            if (!result.Success)
            {
                throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription);
            }

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

            return(temporaryDataSourceDefinition);
        }
Exemple #2
0
        /// <summary>
        /// Execute File delete gateway command.
        /// </summary>
        /// <returns></returns>
        internal override ReturnResultBase Execute()
        {
            ReturnResultBase result = new ReturnResult();
            bool             exist  = false;
            int    dataSourceNumber = clientDbDelCommand.DataSourceNumber;
            string dataSourceName   = clientDbDelCommand.DataSourceName;

            DataSourceDefinition dataSourceDefintion = ClientManager.Instance.LocalManager.ApplicationDefinitions.DataSourceDefinitionManager.GetDataSourceDefinition(Task.getCtlIdx(), dataSourceNumber);

            //If Wrong Data Source Number is Given
            if (dataSourceDefintion == null)
            {
                Logger.Instance.WriteExceptionToLog("ClientDbDel - Invalid Data Source Number");
                result = new ReturnResult(MsgInterface.STR_CLIENT_DB_DEL_OPERATION_FAILED);
            }
            else
            {
                if (string.IsNullOrEmpty(dataSourceName))
                {
                    dataSourceName = dataSourceDefintion.Name;
                }
                //Check for Table exist or not.
                if (dataSourceDefintion.CheckExist == 'N')
                {
                    exist = true;
                }
                else
                {
                    GatewayCommandFileExist dbFileExistCommand = GatewayCommandsFactory.CreateFileExistCommand(dataSourceName, dataSourceDefintion, LocalDataviewManager.LocalManager);
                    result = dbFileExistCommand.Execute();
                    exist  = result.Success;
                }

                //If Table exists then go for file delete operation.
                if (exist)
                {
                    GatewayCommandFileDelete dbDeleteCommand = GatewayCommandsFactory.CreateFileDeleteCommand(dataSourceName, dataSourceDefintion, LocalDataviewManager.LocalManager);

                    if (!dbDeleteCommand.Execute().Success)
                    {
                        Logger.Instance.WriteExceptionToLog("ClientDbDel - Cannot delete Table");
                        result = new ReturnResult(MsgInterface.STR_CLIENT_DB_DEL_OPERATION_FAILED);
                    }
                }
                else
                {
                    Logger.Instance.WriteExceptionToLog(string.Format("ClientDbDel - {0}", result.ErrorDescription));
                    result = new ReturnResult(MsgInterface.STR_CLIENT_DB_DEL_OPERATION_FAILED);
                }
            }

            return(result);
        }
Exemple #3
0
        public void Execute()
        {
            Logger.Instance.WriteSupportToLog("DeleteCommand.Execute():>>>>> ", true);
            Logger.Instance.WriteSupportToLog(string.Format("DeleteCommand.Execute(): deleting table {0}", dataSourceDefinition.Name), true);

            GatewayCommandFileDelete fileDeleteCommand = GatewayCommandsFactory.CreateFileDeleteCommand(dataSourceDefinition.Name, dataSourceDefinition, ClientManager.Instance.LocalManager);
            GatewayResult            result            = fileDeleteCommand.Execute();

            if (!result.Success && result.ErrorCode != GatewayErrorCode.FileNotExist)
            {
                throw new DataSourceConversionFailedException(dataSourceDefinition.Name, result.ErrorDescription);
            }

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