Пример #1
0
        /// <summary>
        /// Prepare and Open runtime cursor
        /// </summary>
        /// <param name="runtimeCursor"></param>
        private void PrepareAndOpenCursor(RuntimeCursor runtimeCursor, bool openTransaction)
        {
            GatewayResult result = null;

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

            result = GatewayCommandsFactory.CreateCursorPrepareCommand(runtimeCursor, ClientManager.Instance.LocalManager).Execute();
            if (result.Success)
            {
                if (openTransaction)
                {
                    result = GatewayCommandsFactory.CreateGatewayCommandOpenTransaction(ClientManager.Instance.LocalManager).Execute();
                }
                if (result.Success)
                {
                    result = GatewayCommandsFactory.CreateCursorOpenCommand(runtimeCursor, ClientManager.Instance.LocalManager).Execute();
                }
            }

            if (!result.Success)
            {
                throw new DataSourceConversionFailedException(runtimeCursor.CursorDefinition.DataSourceDefinition.Name, result.ErrorDescription);
            }
        }
Пример #2
0
        /// <summary>
        /// open transaction
        /// if there is no transaction opened already then
        ///     open and save it info on ClientManager.Instance.CurrentLocalTransactionOpened
        /// else
        ///     if (transaction that was opend is in my parent task)
        ///         OK
        ///     else
        ///         failed !!!
        ///
        /// </summary>
        internal override ReturnResultBase Execute()
        {
            ReturnResultBase returnResultBase = new GatewayResult();

            Transaction transaction = DataviewManager.Transaction.OwnerTask.DataviewManager.LocalDataviewManager.Transaction;

            if (!transaction.isOpened())
            {
                // need to open in the gateway only if no opend before
                if (TaskTransactionManager.LocalOpenedTransactionsCount == 0)
                {
                    returnResultBase = GatewayCommandsFactory.CreateGatewayCommandOpenTransaction(LocalManager).Execute();
                }
                if (returnResultBase.Success)
                {
                    transaction.Opened = true;
                    TaskTransactionManager.LocalOpenedTransactionsCount++;

                    //transaction.OwnerTask.TaskTransactionManager.SetCurrentOpenTransactionAsLocalTransaction();
                    //Debug.WriteLine("Open Transaction on task--> " + LocalDataviewManager.CurrentOpenTransaction.OwnerTask);
                }

                //else
                //{
                //   // check if the open transaction is in the parent task
                //   if (!transaction.OwnerTask.isDescendentOf(LocalDataviewManager.CurrentOpenTransaction.OwnerTask))
                //      returnResultBase = new ReturnResult(MsgInterface.FMERROR_STR_TRANS_OPEN_FAILED);
                //}
            }
            return(returnResultBase);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal override ReturnResultBase Execute()
        {
            GatewayResult gatewayResult = new GatewayResult();

            Transaction transaction = DataviewManager.Transaction.OwnerTask.DataviewManager.LocalDataviewManager.Transaction;

            // closeclose the transaction only if there is transaction that open
            if (TaskTransactionManager.LocalOpenedTransactionsCount > 0)
            {
                gatewayResult = CloseTransactionInGateway();
                if (gatewayResult.Success)
                {
                    //Debug.WriteLine("Commit Transaction on task--> " + LocalDataviewManager.CurrentOpenTransaction.OwnerTask);
                    transaction.Opened = false;
                    TaskTransactionManager.LocalOpenedTransactionsCount--;

                    // there is tasks that in local transaction, we must open the transaction again
                    if (TaskTransactionManager.LocalOpenedTransactionsCount > 0)
                    {
                        gatewayResult = GatewayCommandsFactory.CreateGatewayCommandOpenTransaction(LocalManager).Execute();
                    }
                }
                else
                {
                    gatewayResult.ErrorCode = GatewayErrorCode.TransactionCommit;
                }
            }
            return(gatewayResult);
        }
Пример #4
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);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal override ReturnResultBase Execute()
        {
            GatewayResult gatewayResult = new GatewayResult();

            Transaction ownerTransaction = null;

            if (TaskTransactionManager.LocalOpenedTransactionsCount > 0)
            {
                gatewayResult = RollbaclTransactionInGateway();
                if (gatewayResult.Success)
                {
                    if (DataviewManager.Transaction != null)
                    {
                        ownerTransactionTask = DataviewManager.Transaction.OwnerTask;
                        ownerTransaction     = ownerTransactionTask.DataviewManager.LocalDataviewManager.Transaction;

                        //1.  calculate the current task , the task that was execute the rollback transaction (Command.taskgTag)
                        //Debug.WriteLine("Commit Transaction on task--> " + LocalDataviewManager.CurrentOpenTransaction.OwnerTask);
                        ownerTransactionTask.CancelAndRefreshCurrentRecordAfterRollback();
                    }


                    GatewayCommandBase transactionCommand = GatewayCommandsFactory.CreateGatewayCommandOpenTransaction(LocalManager);
                    gatewayResult = transactionCommand.Execute();

                    //2.	Close\refresh all tasks that are under the current transaction
                    switch (Command.Rollback)
                    {
                    case RollbackEventCommand.RollbackType.CANCEL:
                        MGDataCollection.Instance.ForEachTask(new TaskDelegate(CancelAndRefreshCurrentRecordAfterRollback), ownerTransactionTask);
                        MGDataCollection.Instance.ForEachTask(new TaskDelegate(ViewRefreshAfterRollback), ownerTransactionTask);
                        break;

                    case RollbackEventCommand.RollbackType.ROLLBACK:
                    {
                        // fixed bug#294247 rollback the value in StopExecution
                        bool saveStopExec = ClientManager.Instance.EventsManager.GetStopExecutionFlag();
                        StopExecWasUpdated = false;
                        MGDataCollection.Instance.ForEachTask(new TaskDelegate(CancelAndRefreshCurrentRecordAfterRollback), null);
                        MGDataCollection.Instance.ForEachTask(new TaskDelegate(ViewRefreshAfterRollback), null);

                        if (ownerTransactionTask != null)
                        {
                            ownerTransactionTask.AbortDirectTasks();
                        }

                        if (StopExecWasUpdated)
                        {
                            ClientManager.Instance.EventsManager.setStopExecution(saveStopExec);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
                else
                {
                    gatewayResult.ErrorCode = GatewayErrorCode.TransactionAbort;
                }
            }
            return(gatewayResult);
        }