Ejemplo n.º 1
0
        /// <summary>
        /// Checks if correspondng table of data source is exist at backend
        /// </summary>
        /// <param name="dataSourceDefinition"></param>
        /// <returns>returns true if table exists</returns>
        private bool IsTableExist(DataSourceDefinition dataSourceDefinition)
        {
            GatewayCommandFileExist fileExistCommand = GatewayCommandsFactory.CreateFileExistCommand(dataSourceDefinition.Name, dataSourceDefinition,
                                                                                                     ClientManager.Instance.LocalManager);
            GatewayResult result = fileExistCommand.Execute();

            return(result.Success);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update dataview to DataSource.
        /// </summary>
        private ReturnResultBase UpdateDataViewToDataSource()
        {
            bool   transactionOpened = false;
            string error             = string.Empty;

            string dataSourceName = ClientManager.Instance.getEnvParamsTable().translate(updateDataViewToDataSourceCommand.DestDataSourceName);

            if (string.IsNullOrEmpty(dataSourceName))
            {
                dataSourceName = destinationDataSourceDefinition.Name;
            }

            GatewayResult result = GatewayCommandsFactory.CreateFileExistCommand(dataSourceName, destinationDataSourceDefinition, ClientManager.Instance.LocalManager).Execute();

            bool insertMode = !result.Success;

            if (!insertMode)
            {
                uniqueKey = GetUniqueKey();

                if (uniqueKey == null)
                {
                    error = "DataViewToDataSource - When using the DataViewtoDataSource function, a unique index must be defined in the destination data source .";
                    Logger.Instance.WriteExceptionToLog(error);
                    ClientManager.Instance.ErrorToBeWrittenInServerLog = error;
                    return(new ReturnResult(MsgInterface.STR_DATAVIEW_TO_DATASOURCE_OPERATION_FAILED));
                }
                else if (!CheckDestinationColumnListContainUniqueKeyColumns())
                {
                    error = "DataViewToDataSource - When using the DataViewtoDataSource function, all the segments of the unique index must be selected.";
                    Logger.Instance.WriteExceptionToLog(error);
                    ClientManager.Instance.ErrorToBeWrittenInServerLog = error;
                    return(new ReturnResult(MsgInterface.STR_DATAVIEW_TO_DATASOURCE_OPERATION_FAILED));
                }
            }

            result = GatewayCommandsFactory.CreateFileOpenCommand(dataSourceName, destinationDataSourceDefinition, Access.Write, ClientManager.Instance.LocalManager).Execute();
            if (result.Success)
            {
                //Build the runtime cursor.
                MainCursorBuilder cursorBuilder            = new MainCursorBuilder(null);
                RuntimeCursor     destinationRuntimeCursor = cursorBuilder.Build(destinationDataSourceDefinition, Access.Write);

                destinationRuntimeCursor.CursorDefinition.StartPosition   = new DbPos(true);
                destinationRuntimeCursor.CursorDefinition.CurrentPosition = new DbPos(true);

                // Prepare the cursor.
                result = GatewayCommandsFactory.CreateCursorPrepareCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager).Execute();

                if (result.Success)
                {
                    //If tansaction is not open then open the transaction.
                    if (TaskTransactionManager.LocalOpenedTransactionsCount == 0)
                    {
                        result            = GatewayCommandsFactory.CreateGatewayCommandOpenTransaction(ClientManager.Instance.LocalManager).Execute();
                        transactionOpened = true;
                    }

                    if (result.Success)
                    {
                        SetDataToRuntimeParser();
                        RecordForDataViewToDataSource record = GetRecord();

                        while (record != null)
                        {
                            BuildCurrentValues(destinationRuntimeCursor, record);
                            result = GatewayCommandsFactory.CreateCursorInsertCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager, true).Execute();

                            if (!result.Success)
                            {
                                if (result.ErrorCode == GatewayErrorCode.DuplicateKey)
                                {
                                    if (!insertMode)
                                    {
                                        //Build the ranges using unique key segments value.
                                        BuildRanges(record, destinationRuntimeCursor);

                                        //Open the cursor and apply the ranges.
                                        result = GatewayCommandsFactory.CreateCursorOpenCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager, true).Execute();
                                        if (result.Success)
                                        {
                                            //Fetch the record
                                            result = GatewayCommandsFactory.CreateCursorFetchCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager).Execute();

                                            BuildCurrentValues(destinationRuntimeCursor, record);

                                            //If record found, that means record with same key value exists, so update the current record with destination record.
                                            if (result.Success)
                                            {
                                                result = GatewayCommandsFactory.CreateGatewayCommandCursorUpdateRecord(destinationRuntimeCursor, ClientManager.Instance.LocalManager, true).Execute();
                                            }
                                            else
                                            {
                                                if (!string.IsNullOrEmpty(ClientManager.Instance.ErrorToBeWrittenInServerLog))
                                                {
                                                    ClientManager.Instance.ErrorToBeWrittenInServerLog += "\r\n";
                                                }

                                                ClientManager.Instance.ErrorToBeWrittenInServerLog += result.ErrorDescription;
                                            }

                                            //Close the cursor.
                                            GatewayCommandsFactory.CreateCursorCloseCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager).Execute();
                                        }
                                        else
                                        {
                                            if (!string.IsNullOrEmpty(ClientManager.Instance.ErrorToBeWrittenInServerLog))
                                            {
                                                ClientManager.Instance.ErrorToBeWrittenInServerLog += "\r\n";
                                            }

                                            ClientManager.Instance.ErrorToBeWrittenInServerLog += result.ErrorDescription;
                                        }
                                    }
                                    else
                                    {
                                        if (!string.IsNullOrEmpty(ClientManager.Instance.ErrorToBeWrittenInServerLog))
                                        {
                                            ClientManager.Instance.ErrorToBeWrittenInServerLog += "\r\n";
                                        }

                                        ClientManager.Instance.ErrorToBeWrittenInServerLog += result.ErrorDescription;

                                        record = GetRecord();

                                        continue;
                                    }
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(ClientManager.Instance.ErrorToBeWrittenInServerLog))
                                    {
                                        ClientManager.Instance.ErrorToBeWrittenInServerLog += "\r\n";
                                    }

                                    ClientManager.Instance.ErrorToBeWrittenInServerLog += result.ErrorDescription;

                                    break;
                                }
                            }

                            record = GetRecord();
                        }

                        //If transaction is opened , then close the transaction. If any error occurs then abort the transation else do commit.
                        if (transactionOpened)
                        {
                            GatewayCommandCloseTransaction closeTransactionCommand = GatewayCommandsFactory.CreateGatewayCommandCloseTransaction(ClientManager.Instance.LocalManager);
                            if (result.Success)
                            {
                                closeTransactionCommand.TransactionModes = TransactionModes.Commit;
                            }
                            else
                            {
                                closeTransactionCommand.TransactionModes = TransactionModes.Abort;
                            }

                            closeTransactionCommand.Execute();
                        }

                        //Release the cursor and close the file.
                        GatewayCommandsFactory.CreateCursorReleaseCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager).Execute();

                        GatewayCommandsFactory.CreateFileCloseCommand(destinationDataSourceDefinition, ClientManager.Instance.LocalManager).Execute();
                    }
                    else
                    {
                        ClientManager.Instance.ErrorToBeWrittenInServerLog = result.ErrorDescription;
                    }
                }
                else
                {
                    ClientManager.Instance.ErrorToBeWrittenInServerLog = result.ErrorDescription;
                }
            }
            else
            {
                ClientManager.Instance.ErrorToBeWrittenInServerLog = result.ErrorDescription;
            }

            return(result);
        }