public static OperationResult Insert(DataFieldCollection pValues, ConnectionInfo pInfo)
        {
            Transaction lTransaction;

             lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

             bool lLocalTransaction = (lTransaction != null);

             InsertCommand lInsert;

             OperationResult lReturn = new OperationResult(PORT_BANNERQD.TableName, PORT_BANNERQD.TableName);

             if (!lReturn.HasError){
             try{
             if (lLocalTransaction){
                 lReturn.Trace("Transação local, instanciando banco...");
             }

             lInsert = new InsertCommand(PORT_BANNERQD.TableName);

             lReturn.Trace("Adicionando campos ao objeto de insert");

             foreach (DataField lField in pValues.Keys){
                 lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
             }
             decimal lSequence;
             lSequence = DataBaseSequenceControl.GetNext(pInfo, "BAN_ID");
             lInsert.Fields.Add(PORT_BANNERQD._BAN_ID.Name, lSequence, (ItemType)PORT_BANNERQD._BAN_ID.DBType);

             lReturn.Trace("Executando o Insert");

             lInsert.Execute(lTransaction, false);

             if (!lReturn.HasError){
                 if (lLocalTransaction){
                     if (!lReturn.HasError){
                         lReturn.Trace("Insert finalizado, executando commit");

                         lTransaction.Commit();
                     }
                     else{
                         lTransaction.Rollback();
                     }
                 }
             }
             else{
                 if (lLocalTransaction)
                     lTransaction.Rollback();
             }
             }
             catch (Exception ex){
            lReturn.OperationException = new SerializableException(ex);

             if (lLocalTransaction)
                 lTransaction.Rollback();
             }
             }

             return lReturn;
        }
Example #2
0
        /// <summary>
        /// Try and custom process the given InsertCommand when it's appropriate to override
        /// with Visual Studio specific behavior
        /// </summary>
        public bool TryCustomProcess(InsertCommand command)
        {
            var oleCommandData = OleCommandData.Empty;
            try
            {
                if (_vim.InBulkOperation && !command.IsInsertNewLine)
                {
                    // If we are in the middle of a bulk operation we don't want to forward any
                    // input to IOleCommandTarget because it will trigger actions like displaying
                    // Intellisense.  Definitely don't want intellisense popping up during say a 
                    // repeat of a 'cw' operation or macro.
                    //
                    // The one exception to this rule though is the Enter key.  Every single language
                    // formats Enter in a special way that we absolutely want to preserve in a change
                    // or macro operation.  Go ahead and let it go through here and we'll dismiss 
                    // any intellisense which pops up as a result
                    return false;
                }

                if (!_vimApplicationSettings.UseEditorTabAndBackspace && (command.IsBack || command.IsInsertTab))
                {
                    // When the user has opted into 'softtabstop' then Vim has a better understanding of
                    // <BS> than Visual Studio.  Allow that processing to win
                    return false;
                }

                if (!TryGetOleCommandData(command, out oleCommandData))
                {
                    // Not a command that we custom process
                    return false;
                }

                var versionNumber = _textBuffer.CurrentSnapshot.Version.VersionNumber;
                int hr = _nextCommandTarget.Exec(oleCommandData);

                // Whether or not an Exec succeeded is a bit of a heuristic.  IOleCommandTarget implementations like
                // C++ will return E_ABORT if Intellisense failed but the character was actually inserted into 
                // the ITextBuffer.  VsVim really only cares about the character insert.  However we must also
                // consider cases where the character successfully resulted in no action as a success
                return ErrorHandler.Succeeded(hr) || versionNumber < _textBuffer.CurrentSnapshot.Version.VersionNumber;
            }
            finally
            {
                if (oleCommandData != null)
                {
                    oleCommandData.Dispose();
                }

                if (_vim.InBulkOperation && _broker.IsCompletionActive)
                {
                    _broker.DismissDisplayWindows();
                }
            }
        }
Example #3
0
 protected virtual Expression VisitInsert(InsertCommand insert)
 {
     var table = (TableExpression)this.Visit(insert.Table);
     var assignments = this.VisitColumnAssignments(insert.Assignments);
     return this.UpdateInsert(insert, table, assignments);
 }
Example #4
0
        public static OperationResult Insert(
           List<DataFieldCollection> pListValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(TrmxIrmQD.TableName, TrmxIrmQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {

                    foreach (DataFieldCollection pValues in pListValues)
                    {
                        lInsert = new InsertCommand(TrmxIrmQD.TableName);

                        foreach (DataField lField in pValues.Keys)
                        {
                            lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                        }
                        decimal lSequence;
                        lSequence = DataBaseSequenceControl.GetNext(pInfo, "TRMIRM_ID");
                        lInsert.Fields.Add(TrmxIrmQD._TRMIRM_ID.Name, lSequence, (ItemType)TrmxIrmQD._TRMIRM_ID.DBType);

                        lInsert.Execute(lTransaction);

                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                        }
                    }

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
        public static OperationResult Insert(
    DataFieldCollection pValues,
    List<DataFieldCollection> pListInterrupcao,
    ConnectionInfo pInfo                                                                       
 )
        {
            Transaction lTransaction;

             lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

             bool lLocalTransaction = (lTransaction != null);

             InsertCommand lInsert;

             OperationResult lReturn = new OperationResult(DCALC_CONDENACAOQD.TableName, DCALC_CONDENACAOQD.TableName);

             if (!lReturn.HasError)
             {
             try
             {
             if (lLocalTransaction)
             {
                 lReturn.Trace("Transação local, instanciando banco...");
             }

             lInsert = new InsertCommand(DCALC_CONDENACAOQD.TableName);

             lReturn.Trace("Adicionando campos ao objeto de insert");

             foreach (DataField lField in pValues.Keys)
             {
                 lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
             }
             decimal lSequence;
             lSequence = DataBaseSequenceControl.GetNext(pInfo, "COND_ID");
             lInsert.Fields.Add(DCALC_CONDENACAOQD._COND_ID.Name, lSequence, (ItemType)DCALC_CONDENACAOQD._COND_ID.DBType);

             decimal lCOND_ID = 0;
             lCOND_ID = lReturn.SequenceControl;

             lReturn.Trace("Executando o Insert");

             lInsert.Execute(lTransaction);

             if (!lReturn.HasError)
             {
                 if (pListInterrupcao.Count > 0)
                 {
                     foreach (DataFieldCollection lFields in pListInterrupcao)
                     {
                         lFields.Add(DCALC_INTERRUPCAOQD._COD_CONDENACAO, lSequence);

                         lReturn = DCALC_INTERRUPCAODo.Insert(lFields, lTransaction, pInfo);
                         if (lReturn.HasError)
                         {
                             lTransaction.Rollback();
                             return lReturn;
                         }
                     }
                 }

                 if (!lReturn.HasError)
                 {
                     lReturn.SequenceControl = lSequence;
                     lReturn.Trace("Insert finalizado, executando commit");
                     lTransaction.Commit();
                 }
                 else
                 {
                     lTransaction.Rollback();
                 }
             }
             else
             {
                 if (lLocalTransaction)
                     lTransaction.Rollback();
             }
             }
             catch (Exception ex)
             {
             lReturn.OperationException = new SerializableException(ex);

             if (lLocalTransaction)
                 lTransaction.Rollback();
             }
             }

             return lReturn;
        }
Example #6
0
        bool IVimHost.TryCustomProcess(ITextView textView, InsertCommand command)
        {
            if (TryCustomProcessFunc != null)
            {
                return TryCustomProcessFunc(textView, command);
            }

            return false;
        }
Example #7
0
        /// <summary>
        /// Try and custom process the given InsertCommand when it's appropriate to override
        /// with Visual Studio specific behavior
        /// </summary>
        public bool TryCustomProcess(InsertCommand command)
        {
            var oleCommandData = OleCommandData.Empty;
            try
            {
                if (!TryGetOleCommandData(command, out oleCommandData))
                {
                    // Not a command that we custom process
                    return false;
                }
                var versionNumber = _textBuffer.CurrentSnapshot.Version.VersionNumber;
                int hr = _nextTarget.Exec(oleCommandData);

                // Whether or not an Exec succeeded is a bit of a heuristic.  IOleCommandTarget implementations like
                // C++ will return E_ABORT if Intellisense failed but the character was actually inserted into
                // the ITextBuffer.  VsVim really only cares about the character insert.  However we must also
                // consider cases where the character successfully resulted in no action as a success
                return ErrorHandler.Succeeded(hr) || versionNumber < _textBuffer.CurrentSnapshot.Version.VersionNumber;
            }
            finally
            {
                if (oleCommandData != null)
                {
                    oleCommandData.Dispose();
                }
            }
        }
Example #8
0
 protected override Expression VisitInsert(InsertCommand insert)
 {
     this.Append("INSERT INTO ");
     //if (Dialect.SupportSchema && !string.IsNullOrEmpty(insert.Table.Mapping.Schema))
     //{
     //    sb.Append(Dialect.Quote(insert.Table.Mapping.Schema));
     //    sb.Append(".");
     //}
     //this.AppendTableName(insert.Table.Name);
     WriteTableName(insert.Table.Mapping);
     this.Append("(");
     for (int i = 0, n = insert.Assignments.Count; i < n; i++)
     {
         ColumnAssignment ca = insert.Assignments[i];
         if (i > 0) this.Append(", ");
         this.AppendColumnName(ca.Column.Name);
     }
     this.Append(")");
     this.AppendLine(Indentation.Same);
     this.Append("VALUES (");
     for (int i = 0, n = insert.Assignments.Count; i < n; i++)
     {
         ColumnAssignment ca = insert.Assignments[i];
         if (i > 0) this.Append(", ");
         this.Visit(ca.Expression);
     }
     this.Append(")");
     return insert;
 }
        public static OperationResult Insert(
           DataFieldCollection pValues,
           Transaction pTransaction,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            bool lLocalTransaction = (pTransaction == null);

            if (lLocalTransaction)
                lTransaction = new Transaction(Instance.CreateDatabase(pInfo));
            else
                lTransaction = pTransaction;

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaDocumentoQD.TableName, PessoaDocumentoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaDocumentoQD.TableName);

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "PDOC_ID");
                    lInsert.Fields.Add(PessoaDocumentoQD._PDOC_ID.Name, lSequence, (ItemType)PessoaDocumentoQD._PDOC_ID.DBType);
                    lReturn.SequenceControl = lSequence;

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Example #10
0
 public bool TryCustomProcess(ITextView textView, InsertCommand command)
 {
     //throw new NotImplementedException();
     return(false);
 }
Example #11
0
 public static InsertCommand.Insert AsInsert(this InsertCommand command)
 {
     return((InsertCommand.Insert)command);
 }
Example #12
0
        public void Insert(int index, T item)
        {
            InsertCommand command = new InsertCommand(theList, index, item);

            undoManager.Execute(command);
        }
Example #13
0
        public void Add(T item)
        {
            InsertCommand command = new InsertCommand(theList, Count, item);

            undoManager.Execute(command);
        }
        public void Insert <T>(T entity) where T : DatabaseEntity, new()
        {
            var insertCommand = new InsertCommand <T>(TableName, entity);

            ProcessNonQueryCommand(insertCommand);
        }
Example #15
0
 public async Task <QueryTicketModel> HandleAsync(InsertCommand <CommandTicketModel> insertCommand)
 {
     return(await _unitOfWork.TicketRepository.InsertTicketAsync(insertCommand.Data));
 }
Example #16
0
        public virtual void ProcessCommand(ClientManager clientManager, object cmd, long acknowledgementId, UsageStats stats)
        {
            Alachisoft.NCache.Common.Protobuf.Command command = cmd as Alachisoft.NCache.Common.Protobuf.Command;
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "enter");
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "" + command);
            }
            if (SocketServer.Logger.IsDetailedLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " COMMAND to be executed : " + command.type.ToString() + " RequestId :" + command.requestID);
            }

            HPTimeStats milliSecWatch = new HPTimeStats();

            milliSecWatch.BeginSample();
            bool      clientDisposed   = false;
            bool      isAsync          = false;
            string    _methodName      = command.type.ToString();;
            Stopwatch commandExecution = new Stopwatch();

            commandExecution.Start();

            CommandBase incommingCmd = null;
            bool        isUnsafeCommand = false, doThrottleCommand = true;

            switch (command.type)
            {
            case Alachisoft.NCache.Common.Protobuf.Command.Type.INIT:
                Alachisoft.NCache.Common.Protobuf.InitCommand initCommand = command.initCommand;
                initCommand.requestId = command.requestID;
                if (SocketServer.Logger.IsDetailedLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " RequestId :" + command.requestID);
                }
                incommingCmd      = new InitializeCommand(bookie.RequestLoggingEnabled);
                doThrottleCommand = false;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.EXECUTE_READER:
                Alachisoft.NCache.Common.Protobuf.ExecuteReaderCommand executeReaderCommand = command.executeReaderCommand;
                executeReaderCommand.requestId = command.requestID;
                incommingCmd = new ExecuteReaderCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.EXECUTE_READER_CQ:
                Alachisoft.NCache.Common.Protobuf.ExecuteReaderCQCommand executeReaderCQCommand = command.executeReaderCQCommand;
                executeReaderCQCommand.requestId = command.requestID;
                incommingCmd = new ExecuteReaderCQCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_READER_CHUNK:
                Alachisoft.NCache.Common.Protobuf.GetReaderNextChunkCommand getReaderChunkCommand = command.getReaderNextChunkCommand;
                getReaderChunkCommand.requestId = command.requestID;
                incommingCmd = new GetReaderChunkCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.DISPOSE_READER:
                Alachisoft.NCache.Common.Protobuf.DisposeReaderCommand disposeReaderCommand = command.disposeReaderCommand;
                disposeReaderCommand.requestId = command.requestID;
                incommingCmd = new DisposeReaderCommand();
                break;

            // Added in server to cater getProductVersion request from client
            case Common.Protobuf.Command.Type.GET_PRODUCT_VERSION:
                command.getProductVersionCommand.requestId = command.requestID;
                incommingCmd = new GetProductVersionCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD:
                command.addCommand.requestId = command.requestID;
                isAsync         = command.addCommand.isAsync;
                incommingCmd    = new AddCommand();
                isUnsafeCommand = true;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_BULK:
                command.bulkAddCommand.requestId = command.requestID;
                incommingCmd    = new BulkAddCommand();
                isUnsafeCommand = true;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_DEPENDENCY:
                command.addDependencyCommand.requestId = command.requestID;
                incommingCmd = new AddDependencyCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_SYNC_DEPENDENCY:
                command.addSyncDependencyCommand.requestId = command.requestID;
                incommingCmd = new AddSyncDependencyCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.CLEAR:
                command.clearCommand.requestId = command.requestID;
                incommingCmd = new ClearCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.CLOSE_STREAM:
                command.closeStreamCommand.requestId = command.requestID;
                incommingCmd = new CloseStreamCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.CONTAINS:
                command.containsCommand.requestId = command.requestID;
                incommingCmd = new ContainsCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.COUNT:
                command.countCommand.requestId = command.requestID;
                incommingCmd = new CountCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.DISPOSE:
                command.disposeCommand.requestId = command.requestID;
                incommingCmd   = new DisposeCommand();
                clientDisposed = true;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET:
                command.getCommand.requestId = command.requestID;
                incommingCmd = new GetCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_BULK:
                command.bulkGetCommand.requestId = command.requestID;
                incommingCmd = new BulkGetCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_CACHE_ITEM:
                command.getCacheItemCommand.requestId = command.requestID;
                incommingCmd = new GetCacheItemCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_CACHE_BINDING:
                command.getCacheBindingCommand.requestId = command.requestID;
                incommingCmd = new GetCacheBindingCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_ENUMERATOR:
                command.getEnumeratorCommand.requestId = command.requestID;
                incommingCmd = new GetEnumeratorCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_NEXT_CHUNK:
                command.getNextChunkCommand.requestId = command.requestID;
                incommingCmd = new GetNextChunkCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_GROUP_NEXT_CHUNK:
                command.getGroupNextChunkCommand.requestId = command.requestID;
                incommingCmd = new GetGroupNextChunkCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_GROUP:
                Alachisoft.NCache.Common.Protobuf.GetGroupCommand getGroupCommand = command.getGroupCommand;
                getGroupCommand.requestId = command.requestID;
                if (getGroupCommand.getGroupKeys)
                {
                    incommingCmd = new GetGroupKeys();
                    _methodName  = MethodsName.GetGroupKeys;
                }
                else
                {
                    incommingCmd = new GetGroupData();
                    _methodName  = MethodsName.GetGroupData;
                }
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_HASHMAP:
                command.getHashmapCommand.requestId = command.requestID;
                incommingCmd      = new GetHashmapCommand();
                doThrottleCommand = false;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_LOGGING_INFO:
                command.getLoggingInfoCommand.requestId = command.requestID;
                incommingCmd = new GetLogginInfoCommand();
                break;

#if !(DEVELOPMENT)
            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_OPTIMAL_SERVER:
                command.getOptimalServerCommand.requestId = command.requestID;
                incommingCmd      = new GetOptimalServerCommand();
                doThrottleCommand = false;
                break;
#endif
            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_STREAM_LENGTH:
                command.getStreamLengthCommand.requestId = command.requestID;
                incommingCmd = new GetStreamLengthCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_TAG:
                command.getTagCommand.requestId = command.requestID;
                incommingCmd = new GetTagCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REMOVE_BY_TAG:
                command.removeByTagCommand.requestId = command.requestID;
                incommingCmd = new RemoveByTagCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_KEYS_TAG:
                command.getKeysByTagCommand.requestId = command.requestID;
                incommingCmd = new GetKeysByTagCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_TYPEINFO_MAP:
                command.getTypeInfoMapCommand.requestId = command.requestID;
                incommingCmd      = new GetTypeInfoMap();
                doThrottleCommand = false;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT:
                command.insertCommand.requestId = command.requestID;
                incommingCmd    = new InsertCommand();
                isAsync         = command.insertCommand.isAsync;
                isUnsafeCommand = true;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT_BULK:
                command.bulkInsertCommand.requestId = command.requestID;
                incommingCmd    = new BulkInsertCommand();
                isUnsafeCommand = true;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.ISLOCKED:
                command.isLockedCommand.requestId = command.requestID;
                incommingCmd = new IsLockedCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.LOCK:
                command.lockCommand.requestId = command.requestID;
                incommingCmd = new LockCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.LOCK_VERIFY:
                command.lockVerifyCommand.requestId = command.requestID;
                incommingCmd = new VerifyLockCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.OPEN_STREAM:
                command.openStreamCommand.requestId = command.requestID;
                incommingCmd = new OpenStreamCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.RAISE_CUSTOM_EVENT:
                command.raiseCustomEventCommand.requestId = command.requestID;
                incommingCmd = new RaiseCustomNotifCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.READ_FROM_STREAM:
                command.readFromStreamCommand.requestId = command.requestID;
                incommingCmd = new ReadFromStreamCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REGISTER_BULK_KEY_NOTIF:
                command.registerBulkKeyNotifCommand.requestId = command.requestID;
                incommingCmd = new RegisterBulkKeyNotifcationCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REGISTER_KEY_NOTIF:
                command.registerKeyNotifCommand.requestId = command.requestID;
                incommingCmd = new RegisterKeyNotifcationCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REGISTER_NOTIF:
                command.registerNotifCommand.requestId = command.requestID;
                incommingCmd      = new NotificationRegistered();
                doThrottleCommand = false;
                break;

            case Common.Protobuf.Command.Type.REGISTER_POLLING_NOTIFICATION:
                command.registerPollNotifCommand.requestId = command.requestID;
                incommingCmd = new RegisterPollingNotificationCommand();
                break;

            case Common.Protobuf.Command.Type.POLL:
                command.pollCommand.requestId = command.requestID;
                incommingCmd = new PollCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REMOVE:
                command.removeCommand.requestId = command.requestID;
                incommingCmd    = new RemoveCommand();
                isUnsafeCommand = true;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.DELETE:
                command.deleteCommand.requestId = command.requestID;
                incommingCmd = new DeleteCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REMOVE_BULK:
                command.bulkRemoveCommand.requestId = command.requestID;
                incommingCmd    = new BulkRemoveCommand();
                isUnsafeCommand = true;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.DELETE_BULK:
                command.bulkDeleteCommand.requestId = command.requestID;
                incommingCmd = new BulkDeleteCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REMOVE_GROUP:
                command.removeGroupCommand.requestId = command.requestID;
                incommingCmd = new RemoveGroupCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.SEARCH:
                Alachisoft.NCache.Common.Protobuf.SearchCommand searchCommand = command.searchCommand;
                searchCommand.requestId = command.requestID;

                if (searchCommand.searchEntries)
                {
                    incommingCmd = new SearchEnteriesCommand();
                    _methodName  = "SearchEnteries";
                }
                else
                {
                    incommingCmd = new SearchCommand();
                    _methodName  = "Search";
                }
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.SEARCH_CQ:
                Alachisoft.NCache.Common.Protobuf.SearchCQCommand searchCQCommand = command.searchCQCommand;
                searchCQCommand.requestId = command.requestID;

                if (searchCQCommand.searchEntries)
                {
                    _methodName  = "SearchCQEnteries";
                    incommingCmd = new SearchEnteriesCQCommand();
                }
                else
                {
                    _methodName  = "SearchCQ";
                    incommingCmd = new SearchCQCommand();
                }
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.UNREGISTER_CQ:
                command.unRegisterCQCommand.requestId = command.requestID;
                incommingCmd = new UnRegisterCQCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REGISTER_CQ:
                command.registerCQCommand.requestId = command.requestID;
                incommingCmd = new RegisterCQCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.DELETEQUERY:
                Alachisoft.NCache.Common.Protobuf.DeleteQueryCommand deleteQueryCommand = command.deleteQueryCommand;
                deleteQueryCommand.requestId = command.requestID;

                if (deleteQueryCommand.isRemove)
                {
                    incommingCmd = new RemoveQueryCommand();
                    _methodName  = "RemoveQuery";
                }
                else
                {
                    incommingCmd = new DeleteQueryCommand();
                    _methodName  = "DeleteQuery";
                }
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.UNLOCK:
                command.unlockCommand.requestId = command.requestID;
                incommingCmd = new UnlockCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.UNREGISTER_BULK_KEY_NOTIF:
                command.unRegisterBulkKeyNotifCommand.requestId = command.requestID;
                incommingCmd = new UnRegsisterBulkKeyNotification();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.UNREGISTER_KEY_NOTIF:
                command.unRegisterKeyNotifCommand.requestId = command.requestID;
                incommingCmd = new UnRegisterKeyNoticationCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.WRITE_TO_STREAM:
                command.writeToStreamCommand.requestId = command.requestID;
                incommingCmd = new WriteToStreamCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_ATTRIBUTE:
                command.addAttributeCommand.requestId = command.requestID;
                incommingCmd = new AddAttributeCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.SYNC_EVENTS:
                command.syncEventsCommand.requestId = command.requestID;
                incommingCmd = new SyncEventCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.INQUIRY_REQUEST:
                incommingCmd = new InquiryRequestCommand(bookie);
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.MAP_REDUCE_TASK:
                command.mapReduceTaskCommand.requestId = command.requestID;
                incommingCmd = new MapReduceTaskCommand();
                break;

            case Common.Protobuf.Command.Type.TASK_CALLBACK:
                command.TaskCallbackCommand.requestId = command.requestID;
                incommingCmd = new TaskCallbackCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.CANCEL_TASK:
                incommingCmd = new TaskCancelCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.RUNNING_TASKS:
                command.RunningTasksCommand.requestId = command.requestID;
                incommingCmd = new GetRunningTasksCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.TASK_PROGRESS:
                command.TaskProgressCommand.requestId = command.requestID;
                incommingCmd = new TaskProgressCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.TASK_ENUMERATOR:
                incommingCmd = new TaskEnumeratorCommand();
                break;

            case Common.Protobuf.Command.Type.TASK_NEXT_RECORD:
                command.NextRecordCommand.RequestId = command.requestID;
                incommingCmd = new TaskNextRecordCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.INVOKE_ENTRY_PROCESSOR:
                incommingCmd = new InvokeEntryProcessorCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_RUNNING_SERVERS:
                command.getRunningServersCommand.requestId = command.requestID;
                incommingCmd      = new GetRunningServersCommand();
                doThrottleCommand = false;
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_EXPIRATION:
                command.getExpirationCommand.requestId = command.requestID;
                incommingCmd      = new GetExpirationCommand();
                doThrottleCommand = false;
                break;

            case Common.Protobuf.Command.Type.GET_CONNECTED_CLIENTS:
                command.getConnectedClientsCommand.requestId = command.requestID;
                incommingCmd = new GetConnectedClientsCommand();
                break;

            case Common.Protobuf.Command.Type.TOUCH:
                command.touchCommand.requestId = command.requestID;
                incommingCmd = new TouchCommand();
                break;



                #region PUB_SUB
            case Common.Protobuf.Command.Type.GET_TOPIC:
                command.getTopicCommand.requestId = command.requestID;
                incommingCmd = new GetTopicCommand();
                break;

            case Common.Protobuf.Command.Type.SUBSCRIBE_TOPIC:
                command.subscribeTopicCommand.requestId = command.requestID;
                incommingCmd = new SubscribeTopicCommand();
                break;

            case Common.Protobuf.Command.Type.UNSUBSCRIBE_TOPIC:
                command.unSubscribeTopicCommand.requestId = command.requestID;
                incommingCmd = new UnSubscribeTopicCommand();
                break;

            case Common.Protobuf.Command.Type.REMOVE_TOPIC:
                command.removeTopicCommand.requestId = command.requestID;
                incommingCmd = new RemoveTopicCommand();
                break;

            case Common.Protobuf.Command.Type.MESSAGE_PUBLISH:
                command.messagePublishCommand.requestId = command.requestID;
                incommingCmd = new MessagePublishCommand();
                break;

            case Common.Protobuf.Command.Type.GET_MESSAGE:
                command.getMessageCommand.requestId = command.requestID;
                incommingCmd = new GetMessageCommand();
                break;

            case Common.Protobuf.Command.Type.MESSAGE_ACKNOWLEDGMENT:
                command.mesasgeAcknowledgmentCommand.requestId = command.requestID;
                incommingCmd = new MessageAcknowledgementCommand();
                break;
                #endregion
            }


            if (SocketServer.IsServerCounterEnabled)
            {
                _perfStatsCollector.MsecPerCacheOperationBeginSample();
            }

            try
            {
                if (incommingCmd != null)
                {
                    incommingCmd.RequestTimeout = clientManager.RequestTimeout;

                    if (IsMonitoringCommand(command) && ServiceConfiguration.EnableRequestCancellation)
                    {
                        RequestMonitor.Instance.RegisterClientrequestsInLedger(clientManager.ClientID, ((NCache)clientManager.CmdExecuter).Cache.NCacheLog, command.requestID, incommingCmd);
                    }
                }
                if (isUnsafeCommand && clientManager.SupportAcknowledgement)
                {
                    if (clientDisposed)
                    {
                        bookie.RemoveClientAccount(clientManager.ClientID);
                    }
                    else
                    {
                        bookie.RegisterRequest(clientManager.ClientID, command.requestID, command.commandID,
                                               acknowledgementId);
                    }
                }
                incommingCmd.ExecuteCommand(clientManager, command);
                if (command.type == Alachisoft.NCache.Common.Protobuf.Command.Type.INIT && ServiceConfiguration.EnableRequestCancellation)
                {
                    RequestMonitor.Instance.RegisterClientLedger(clientManager.ClientID, ((NCache)clientManager.CmdExecuter).Cache.NCacheLog);
                }
            }
            catch (Exception ex)
            {
                if (isUnsafeCommand && clientManager.SupportAcknowledgement)
                {
                    bookie.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID,
                                         Alachisoft.NCache.Common.Enum.RequestStatus.RECEIVED_WITH_ERROR, null);
                }
                throw;
            }

            finally
            {
                if (IsMonitoringCommand(command) && ServiceConfiguration.EnableRequestCancellation)
                {
                    incommingCmd.Dispose();
                    RequestMonitor.Instance.UnRegisterClientRequests(clientManager.ClientID, command.requestID);
                }
            }
            if (SocketServer.Logger.IsDetailedLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " after executing COMMAND : " + command.type.ToString() + " RequestId :" + command.requestID);
            }

            if (SocketServer.IsServerCounterEnabled)
            {
                _perfStatsCollector.MsecPerCacheOperationEndSample();
            }

#if COMMUNITY
            if (clientManager != null && clientManager.CmdExecuter != null && incommingCmd.OperationResult == OperationResult.Success)
            {
                clientManager.CmdExecuter.UpdateSocketServerStats(new SocketServerStats(clientManager.ClientsRequests, clientManager.ClientsBytesSent, clientManager.ClientsBytesRecieved));
            }
#endif
            if (isUnsafeCommand && clientManager.SupportAcknowledgement)
            {
                if (clientManager != null && clientManager.IsDisposed && incommingCmd.OperationResult == OperationResult.Failure)
                {
                    bookie.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID, Common.Enum.RequestStatus.RECEIVED_WITH_ERROR, null);
                }
                else
                {
                    bookie.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID, Common.Enum.RequestStatus.RECEIVED_AND_EXECUTED, incommingCmd.SerializedResponsePackets);
                }
            }
            if (clientManager != null && !clientManager.IsCacheStopped)
            {
                if (incommingCmd.SerializedResponsePackets != null)
                {
                    if (SocketServer.IsServerCounterEnabled)
                    {
                        _perfStatsCollector.IncrementResponsesPerSecStats(1);
                    }

                    foreach (IList reponse in incommingCmd.SerializedResponsePackets)
                    {
                        ConnectionManager.AssureSend(clientManager, reponse, Alachisoft.NCache.Common.Enum.Priority.Normal);
                    }
                }
                commandExecution.Stop();
                if (!isAsync && command.type != Common.Protobuf.Command.Type.PING && (incommingCmd.SerializedResponsePackets == null || incommingCmd.SerializedResponsePackets.Count <= 0))
                {
                    try
                    {
                        if (Management.APILogging.APILogManager.APILogManger != null && Management.APILogging.APILogManager.EnableLogging)
                        {
                            APILogItemBuilder log = new APILogItemBuilder();
                            log.GenerateCommandManagerLog(_methodName, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), commandExecution.Elapsed, "Serialized Response Packets for " + _methodName + " command is null or empty.");
                        }
                    }
                    catch
                    {
                    }
                }
            }
            double commandElapsedSeconds = commandExecution.Elapsed.TotalSeconds;

            if (ServiceConfiguration.EnableCommandThresholdLogging && commandElapsedSeconds > ServiceConfiguration.CommandExecutionThreshold)
            {
                try
                {
                    string   commandName;
                    string   details       = incommingCmd.GetCommandParameters(out commandName);
                    string[] clientIdParts = clientManager.ClientID.Split(':');
                    string   clientipid    = "CLIENT";
                    try
                    {
                        clientipid = clientIdParts[clientIdParts.Length - 2] + ":" + clientIdParts[clientIdParts.Length - 1];
                    }
                    catch { }

                    CommandLogManager.LogInfo(clientipid, commandElapsedSeconds.ToString(), commandName, details);
                }
                catch (Exception ex)
                {
                }
            }

            if (stats != null)
            {
                stats.EndSample();
                if (incommingCmd != null)
                {
                    // Increment Counter
                    incommingCmd.IncrementCounter(_perfStatsCollector, stats.Current);
                }
            }

            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "exit");
            }
        }
Example #17
0
        public static OperationResult Insert(
             DataFieldCollection pValuesPessoa,
             DataFieldCollection pValuesPai,
             DataFieldCollection pValuesMae,
             DataFieldCollection pValuesRequerente,
             DataFieldCollection pValuesPFamilia,
             DataFieldCollection pValuesSituacaoEscolar,
             DataFieldCollection pValuesEnderecoPai,
             DataFieldCollection pValuesPessoaEnderecoPai,
             DataFieldCollection pValuesEnderecoMae,
             DataFieldCollection pValuesPessoaEnderecoMae,
             DataFieldCollection pValuesEnderecoRequerente,
             DataFieldCollection pValuesPessoaEnderecoRequerente,
             DataFieldCollection pValuesRG,
             DataFieldCollection pValuesCPF,
             DataFieldCollection pValuesRGPai,
             DataFieldCollection pValuesCPFPai,
             DataFieldCollection pValuesRGMae,
             DataFieldCollection pValuesCPFMae,
             DataFieldCollection pValuesRGRequerente,
             DataFieldCollection pValuesCPFRequerente,
             ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaQD.TableName, PessoaQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaQD.TableName);

                    foreach (DataField lField in pValuesPessoa.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesPessoa[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequencePessoa;
                    decimal lSequencePai = 0;
                    decimal lSequenceMae = 0;
                    decimal lSequenceRequerente = 0;
                    lSequencePessoa = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                    lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequencePessoa, (ItemType)PessoaQD._PES_ID.DBType);

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (pValuesRG.Count > 0)
                        {
                            pValuesRG.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesRG, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesCPF.Count > 0)
                        {
                            pValuesCPF.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesCPF, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesSituacaoEscolar.Count > 0)
                        {
                            pValuesSituacaoEscolar.Add(SituacaoEscolarQD._PES_ID, lSequencePessoa);
                            lReturn = SituacaoEscolarDo.Insert(pValuesSituacaoEscolar, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        #region Pai
                        if (pValuesPai.Count > 0)
                        {
                            lInsert = new InsertCommand(PessoaQD.TableName);

                            foreach (DataField lField in pValuesPai.Keys)
                            {
                                lInsert.Fields.Add(lField.Name, pValuesPai[lField], (ItemType)lField.DBType);
                            }

                            lSequencePai = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                            lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequencePai, (ItemType)PessoaQD._PES_ID.DBType);

                            lInsert.Execute(lTransaction);

                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            if (pValuesEnderecoPai.Count > 0)
                            {
                                lReturn = EnderecoDo.Insert(pValuesEnderecoPai, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }

                                decimal lSequenceEndereco = lReturn.SequenceControl;

                                DataFieldCollection lFieldsPE = new DataFieldCollection();
                                pValuesPessoaEnderecoPai.Add(PessoaEnderecoQD._ENDE_ID, lSequenceEndereco);
                                pValuesPessoaEnderecoPai.Add(PessoaEnderecoQD._PES_ID, lSequencePai);

                                lReturn = PessoaEnderecoDo.Insert(pValuesPessoaEnderecoPai, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesRGPai.Count > 0)
                            {
                                pValuesRGPai.Add(PessoaDocumentoQD._PES_ID, lSequencePai);
                                lReturn = PessoaDocumentoDo.Insert(pValuesRGPai, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesCPFPai.Count > 0)
                            {
                                pValuesCPFPai.Add(PessoaDocumentoQD._PES_ID, lSequencePai);
                                lReturn = PessoaDocumentoDo.Insert(pValuesCPFPai, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }
                        #endregion

                        #region Mae
                        if (pValuesMae.Count > 0)
                        {
                            lInsert = new InsertCommand(PessoaQD.TableName);

                            foreach (DataField lField in pValuesMae.Keys)
                            {
                                lInsert.Fields.Add(lField.Name, pValuesMae[lField], (ItemType)lField.DBType);
                            }

                            lSequenceMae = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                            lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequenceMae, (ItemType)PessoaQD._PES_ID.DBType);

                            lInsert.Execute(lTransaction);

                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            if (pValuesEnderecoMae.Count > 0)
                            {
                                lReturn = EnderecoDo.Insert(pValuesEnderecoMae, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }

                                decimal lSequenceEndereco = lReturn.SequenceControl;

                                DataFieldCollection lFieldsPE = new DataFieldCollection();
                                pValuesPessoaEnderecoMae.Add(PessoaEnderecoQD._ENDE_ID, lSequenceEndereco);
                                pValuesPessoaEnderecoMae.Add(PessoaEnderecoQD._PES_ID, lSequenceMae);

                                lReturn = PessoaEnderecoDo.Insert(pValuesPessoaEnderecoMae, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesRGMae.Count > 0)
                            {
                                pValuesRGMae.Add(PessoaDocumentoQD._PES_ID, lSequenceMae);
                                lReturn = PessoaDocumentoDo.Insert(pValuesRGMae, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesCPFMae.Count > 0)
                            {
                                pValuesCPFMae.Add(PessoaDocumentoQD._PES_ID, lSequenceMae);
                                lReturn = PessoaDocumentoDo.Insert(pValuesCPFMae, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }
                        #endregion

                        #region Requerente
                        if (pValuesRequerente.Count > 0)
                        {
                            lInsert = new InsertCommand(PessoaQD.TableName);

                            foreach (DataField lField in pValuesRequerente.Keys)
                            {
                                lInsert.Fields.Add(lField.Name, pValuesRequerente[lField], (ItemType)lField.DBType);
                            }

                            lSequenceRequerente = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                            lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequenceRequerente, (ItemType)PessoaQD._PES_ID.DBType);

                            lInsert.Execute(lTransaction);

                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            if (pValuesEnderecoRequerente.Count > 0)
                            {
                                lReturn = EnderecoDo.Insert(pValuesEnderecoRequerente, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }

                                decimal lSequenceEndereco = lReturn.SequenceControl;

                                DataFieldCollection lFieldsPE = new DataFieldCollection();
                                pValuesPessoaEnderecoRequerente.Add(PessoaEnderecoQD._ENDE_ID, lSequenceEndereco);
                                pValuesPessoaEnderecoRequerente.Add(PessoaEnderecoQD._PES_ID, lSequenceRequerente);

                                lReturn = PessoaEnderecoDo.Insert(pValuesPessoaEnderecoRequerente, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesRGRequerente.Count > 0)
                            {
                                pValuesRGRequerente.Add(PessoaDocumentoQD._PES_ID, lSequenceRequerente);
                                lReturn = PessoaDocumentoDo.Insert(pValuesRGRequerente, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesCPFRequerente.Count > 0)
                            {
                                pValuesCPFRequerente.Add(PessoaDocumentoQD._PES_ID, lSequenceRequerente);
                                lReturn = PessoaDocumentoDo.Insert(pValuesCPFRequerente, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        #endregion

                        #region PessoaFamilia
                        if (pValuesPFamilia.Count > 0)
                        {
                            pValuesPFamilia.Add(PessoaFamiliaQD._PES_ID, lSequencePessoa);

                            if(lSequencePai != 0)
                                pValuesPFamilia.Add(PessoaFamiliaQD._PFAM_PAI, lSequencePai);
                            if (lSequenceMae != 0)
                                pValuesPFamilia.Add(PessoaFamiliaQD._PFAM_MAE, lSequenceMae);
                            if (lSequenceRequerente != 0)
                                pValuesPFamilia.Add(PessoaFamiliaQD._PFAM_REQUERENTE, lSequenceRequerente);

                            lReturn = PessoaFamiliaDo.Insert(pValuesPFamilia, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                        }
                        #endregion
                        if (!lReturn.HasError)
                        {
                            lReturn.SequenceControl = lSequencePessoa;
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Example #18
0
 public static bool IsInsert(this InsertCommand command, char c)
 {
     return(IsInsert(command, c.ToString()));
 }
        public static OperationResult Insert(
           DataFieldCollection pValues,
           List<DataFieldCollection> pListValuesSFR,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(SituacaoFamiliarQD.TableName, SituacaoFamiliarQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {

                    lInsert = new InsertCommand(SituacaoFamiliarQD.TableName);

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "STFAM_ID");
                    lInsert.Fields.Add(SituacaoFamiliarQD._STFAM_ID.Name, lSequence, (ItemType)SituacaoFamiliarQD._STFAM_ID.DBType);

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (pListValuesSFR.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListValuesSFR)
                            {
                                lFields.Add(SituacaoFamiliarResideQD._STFAM_ID, lSequence);

                                lReturn = SituacaoFamiliarResideDo.Insert(lFields, lTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.SequenceControl = lSequence;
                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Example #20
0
 public static bool IsInsert(this InsertCommand command, string text)
 {
     return(command.IsInsert && command.AsInsert().Item == text);
 }
Example #21
0
 /// <summary>
 /// Custom processing of an insert command is a host specific operation.  By default
 /// no custom processing is done
 /// </summary>
 public virtual bool TryCustomProcess(ITextView textView, InsertCommand command)
 {
     return false;
 }
Example #22
0
        // TODO handle the defaultGraph case
        internal static INode ToSpinRdf(this SparqlUpdateCommand query, IGraph g)
        {
            INode             root     = g.CreateBlankNode();
            SpinVariableTable varTable = new SpinVariableTable(g);

            switch (query.CommandType)
            {
            case SparqlUpdateCommandType.Add:
                g.Assert(root, RDF.PropertyType, SP.ClassAdd);
                AddCommand add = (AddCommand)query;
                if (add.SourceUri == null)
                {
                    g.Assert(root, SP.PropertyGraphIRI, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyGraphIRI, RDFUtil.CreateUriNode(add.SourceUri));
                }
                if (add.DestinationUri == null)
                {
                    g.Assert(root, SP.PropertyInto, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyInto, RDFUtil.CreateUriNode(add.DestinationUri));
                }
                break;

            case SparqlUpdateCommandType.Clear:
                g.Assert(root, RDF.PropertyType, SP.ClassClear);
                if (((ClearCommand)query).TargetUri == null)
                {
                    g.Assert(root, SP.PropertyGraphIRI, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyGraphIRI, RDFUtil.CreateUriNode(((ClearCommand)query).TargetUri));
                }
                break;

            case SparqlUpdateCommandType.Copy:
                g.Assert(root, RDF.PropertyType, SP.ClassCopy);
                CopyCommand copy = (CopyCommand)query;
                if (copy.SourceUri == null)
                {
                    g.Assert(root, SP.PropertyGraphIRI, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyGraphIRI, RDFUtil.CreateUriNode(copy.SourceUri));
                }
                if (copy.DestinationUri == null)
                {
                    g.Assert(root, SP.PropertyInto, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyInto, RDFUtil.CreateUriNode(copy.DestinationUri));
                }
                break;

            case SparqlUpdateCommandType.Create:
                g.Assert(root, RDF.PropertyType, SP.ClassCreate);
                CreateCommand create = (CreateCommand)query;
                if (create.TargetUri == null)
                {
                    g.Assert(root, SP.PropertyGraphIRI, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyGraphIRI, RDFUtil.CreateUriNode(create.TargetUri));
                }
                break;

            case SparqlUpdateCommandType.Delete:
                g.Assert(root, RDF.PropertyType, SP.ClassModify);
                DeleteCommand delete = (DeleteCommand)query;
                if (delete.GraphUri != null)
                {
                    g.Assert(root, SP.PropertyWith, RDFUtil.CreateUriNode(delete.GraphUri));
                }
                // TODO handle the usings
                g.Assert(root, SP.PropertyDeletePattern, delete.DeletePattern.ToSpinRdf(g, varTable));
                g.Assert(root, SP.PropertyWhere, delete.WherePattern.ToSpinRdf(g, varTable));
                break;

            case SparqlUpdateCommandType.DeleteData:
                g.Assert(root, RDF.PropertyType, SP.ClassDeleteData);
                g.Assert(root, SP.PropertyData, ((DeleteDataCommand)query).DataPattern.ToSpinRdf(g, varTable));
                break;

            case SparqlUpdateCommandType.Drop:
                g.Assert(root, RDF.PropertyType, SP.ClassDrop);
                DropCommand drop = (DropCommand)query;
                if (drop.TargetUri == null)
                {
                    g.Assert(root, SP.PropertyGraphIRI, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyGraphIRI, RDFUtil.CreateUriNode(drop.TargetUri));
                }
                g.Assert(root, SP.PropertyGraphIRI, RDFUtil.CreateUriNode(((DropCommand)query).TargetUri));
                break;

            case SparqlUpdateCommandType.Insert:
                g.Assert(root, RDF.PropertyType, SP.ClassModify);
                InsertCommand insert = (InsertCommand)query;
                if (insert.GraphUri != null)
                {
                    g.Assert(root, SP.PropertyWith, RDFUtil.CreateUriNode(insert.GraphUri));
                }
                g.Assert(root, SP.PropertyInsertPattern, insert.InsertPattern.ToSpinRdf(g, varTable));
                g.Assert(root, SP.PropertyWhere, insert.WherePattern.ToSpinRdf(g, varTable));
                break;

            case SparqlUpdateCommandType.InsertData:
                g.Assert(root, RDF.PropertyType, SP.ClassInsertData);
                g.Assert(root, SP.PropertyData, ((InsertDataCommand)query).DataPattern.ToSpinRdf(g, varTable));
                break;

            case SparqlUpdateCommandType.Load:
                g.Assert(root, RDF.PropertyType, SP.ClassLoad);
                LoadCommand load = (LoadCommand)query;
                if (load.SourceUri == null)
                {
                    g.Assert(root, SP.PropertyGraphIRI, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyGraphIRI, RDFUtil.CreateUriNode(load.SourceUri));
                }
                if (load.TargetUri == null)
                {
                    g.Assert(root, SP.PropertyInto, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyInto, RDFUtil.CreateUriNode(load.TargetUri));
                }
                break;

            case SparqlUpdateCommandType.Modify:
                g.Assert(root, RDF.PropertyType, SP.ClassModify);
                ModifyCommand modify = (ModifyCommand)query;
                if (modify.GraphUri != null)
                {
                    g.Assert(root, SP.PropertyWith, RDFUtil.CreateUriNode(modify.GraphUri));
                }
                if (modify.DeletePattern != null)
                {
                    g.Assert(root, SP.PropertyDeletePattern, modify.DeletePattern.ToSpinRdf(g, varTable));
                }
                if (modify.InsertPattern != null)
                {
                    g.Assert(root, SP.PropertyInsertPattern, modify.InsertPattern.ToSpinRdf(g, varTable));
                }
                g.Assert(root, SP.PropertyWhere, modify.WherePattern.ToSpinRdf(g, varTable));
                break;

            case SparqlUpdateCommandType.Move:
                g.Assert(root, RDF.PropertyType, SP.ClassMove);
                MoveCommand move = (MoveCommand)query;
                if (move.SourceUri == null)
                {
                    g.Assert(root, SP.PropertyGraphIRI, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyGraphIRI, RDFUtil.CreateUriNode(move.SourceUri));
                }
                if (move.DestinationUri == null)
                {
                    g.Assert(root, SP.PropertyInto, SP.PropertyDefault);
                }
                else
                {
                    g.Assert(root, SP.PropertyInto, RDFUtil.CreateUriNode(move.DestinationUri));
                }
                break;

            case SparqlUpdateCommandType.Unknown:
                throw new NotSupportedException("Unkown SPARQL update query encountered " + query.ToString());
            }
            return(root);
        }
Example #23
0
        /// <summary>
        /// Get the command from command string by checking the starting letters of string
        /// and initializes a command of that type
        /// </summary>
        /// <param name="command">command string</param>
        /// <returns>command base</returns>
        public CommandBase GetCommandObject(string command)
        {
            CommandBase incommingCmd = null;

            if (command.StartsWith("INIT ") || command.StartsWith("INIT_NEW "))
            {
                incommingCmd = new InitializeCommand(bookie.RequestLoggingEnabled);
            }

            if (command.StartsWith("INITSECONDARY "))
            {
                incommingCmd = new InitSecondarySocketCommand();
            }

#if !(DEVELOPMENT)
            else if (command.StartsWith("GETOPTIMALSERVER"))
            {
                incommingCmd = new GetOptimalServerCommand();
            }
#endif
            else if (command.StartsWith("GETCACHEBINDING"))
            {
                incommingCmd = new GetCacheBindingCommand();
            }

            else if (command.StartsWith("ADD "))
            {
                incommingCmd = new AddCommand();
            }

            else if (command.StartsWith("INSERT "))
            {
                incommingCmd = new InsertCommand();
            }

            else if (command.StartsWith("GET "))
            {
                incommingCmd = new GetCommand();
            }

            else if (command.StartsWith("GETTAG "))
            {
                incommingCmd = new GetTagCommand();
            }

            else if (command.StartsWith("REMOVE "))
            {
                incommingCmd = new RemoveCommand();
            }

            else if (command.StartsWith("REMOVEGROUP "))
            {
                incommingCmd = new RemoveGroupCommand();
            }

            else if (command.StartsWith("CONTAINS "))
            {
                incommingCmd = new ContainsCommand();
            }

            else if (command.StartsWith("COUNT "))
            {
                incommingCmd = new CountCommand();
            }

            else if (command.StartsWith("CLEAR "))
            {
                incommingCmd = new ClearCommand();
            }

            else if (command.StartsWith("NOTIF "))
            {
                incommingCmd = new NotificationRegistered();
            }

            else if (command.StartsWith("RAISECUSTOMNOTIF "))
            {
                incommingCmd = new RaiseCustomNotifCommand();
            }

            else if (command.StartsWith("ADDBULK "))
            {
                incommingCmd = new BulkAddCommand();
            }

            else if (command.StartsWith("INSERTBULK "))
            {
                incommingCmd = new BulkInsertCommand();
            }

            else if (command.StartsWith("GETBULK "))
            {
                incommingCmd = new BulkGetCommand();
            }

            else if (command.StartsWith("REMOVEBULK "))
            {
                incommingCmd = new BulkRemoveCommand();
            }

            else if (command.StartsWith("UNLOCK "))
            {
                incommingCmd = new UnlockCommand();
            }

            else if (command.StartsWith("LOCK "))
            {
                incommingCmd = new LockCommand();
            }

            else if (command.StartsWith("ISLOCKED "))
            {
                incommingCmd = new IsLockedCommand();
            }

            else if (command.StartsWith("GETCACHEITEM "))
            {
                incommingCmd = new GetCacheItemCommand();
            }

            else if (command.StartsWith("GETGROUPKEYS "))
            {
                incommingCmd = new GetGroupKeys();
            }

            else if (command.StartsWith("GETGROUPDATA "))
            {
                incommingCmd = new GetGroupData();
            }

            else if (command.StartsWith("ADDDEPENDENCY "))
            {
                incommingCmd = new AddDependencyCommand();
            }

            else if (command.StartsWith("ADDSYNCDEPENDENCY "))
            {
                incommingCmd = new AddSyncDependencyCommand();
            }

            else if (command.StartsWith("GETENUM "))
            {
                incommingCmd = new GetEnumeratorCommand();
            }

            else if (command.StartsWith("REGKEYNOTIF "))
            {
                incommingCmd = new RegisterKeyNotifcationCommand();
            }

            else if (command.StartsWith("UNREGKEYNOTIF "))
            {
                incommingCmd = new UnRegisterKeyNoticationCommand();
            }

            else if (command.StartsWith("GETTYPEINFOMAP "))
            {
                incommingCmd = new GetTypeInfoMap();
            }

            else if (command.StartsWith("GETHASHMAP "))
            {
                incommingCmd = new GetHashmapCommand();
            }

            else if (command.StartsWith("SEARCH "))
            {
                incommingCmd = new SearchCommand();
            }

            else if (command.StartsWith("SEARCHENTERIES "))
            {
                incommingCmd = new SearchEnteriesCommand();
            }

            else if (command.StartsWith("BULKREGKEYNOTIF "))
            {
                incommingCmd = new RegisterBulkKeyNotifcationCommand();
            }

            else if (command.StartsWith("BULKUNREGKEYNOTIF "))
            {
                incommingCmd = new UnRegsisterBulkKeyNotification();
            }

            else if (command.StartsWith("DISPOSE "))
            {
                incommingCmd = new DisposeCommand();
            }
#if COMMUNITY
            else if (command.StartsWith("OPENSTREAM "))
            {
                incommingCmd = new OpenStreamCommand();
            }

            else if (command.StartsWith("CLOSESTREAM "))
            {
                incommingCmd = new CloseStreamCommand();
            }

            else if (command.StartsWith("READFROMSTREAM "))
            {
                incommingCmd = new ReadFromStreamCommand();
            }

            else if (command.StartsWith("WRITETOSTREAM "))
            {
                incommingCmd = new WriteToStreamCommand();
            }

            else if (command.StartsWith("GETSTREAMLENGTH "))
            {
                incommingCmd = new GetStreamLengthCommand();
            }
#endif
            else if (command.StartsWith("GETLOGGINGINFO "))
            {
                incommingCmd = new GetLogginInfoCommand();
            }

            return(incommingCmd);
        }
Example #24
0
        private SparqlUpdateCommand TryParseInsertCommand(SparqlUpdateParserContext context, bool allowData)
        {
            List <Uri> usings     = new List <Uri>();
            List <Uri> usingNamed = new List <Uri>();
            IToken     next       = context.Tokens.Dequeue();

            if (allowData)
            {
                //We are allowed to have an INSERT DATA command here so check for it
                if (next.TokenType == Token.DATA)
                {
                    return(this.TryParseInsertDataCommand(context));
                }
            }
            else
            {
                if (next.TokenType == Token.DATA)
                {
                    throw ParserHelper.Error("The DATA keyword is not permitted here as this INSERT command forms part of a modification command", next);
                }
            }

            //Get the Modification Template
            GraphPattern insertions = this.TryParseModifyTemplate(context);

            //Then we expect a WHERE keyword
            next = context.Tokens.Dequeue();
            if (next.TokenType == Token.USING)
            {
                foreach (KeyValuePair <Uri, bool> kvp in this.TryParseUsingStatements(context))
                {
                    if (kvp.Value)
                    {
                        usingNamed.Add(kvp.Key);
                    }
                    else
                    {
                        usings.Add(kvp.Key);
                    }
                }
                next = context.Tokens.Dequeue();
            }
            if (next.TokenType != Token.WHERE)
            {
                throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a WHERE keyword as part of a INSERT command", next);
            }

            //Now parse the WHERE pattern
            SparqlQueryParserContext subContext = new SparqlQueryParserContext(context.Tokens);

            subContext.Query.BaseUri                        = context.BaseUri;
            subContext.Query.NamespaceMap                   = context.NamespaceMap;
            subContext.ExpressionParser.NamespaceMap        = context.NamespaceMap;
            subContext.ExpressionParser.ExpressionFactories = context.ExpressionFactories;
            subContext.ExpressionFactories                  = context.ExpressionFactories;
            subContext.ExpressionParser.QueryParser         = context.QueryParser;
            GraphPattern where = context.QueryParser.TryParseGraphPattern(subContext, context.Tokens.LastTokenType != Token.LEFTCURLYBRACKET);

            //And finally return the command
            InsertCommand cmd = new InsertCommand(insertions, where);

            usings.ForEach(u => cmd.AddUsingUri(u));
            usingNamed.ForEach(u => cmd.AddUsingNamedUri(u));
            return(cmd);
        }
Example #25
0
        public void LinkedWithNextChange_Simple()
        {
            Create("hello");
            var runData1 = VimUtil.CreateCommandRunData(flags: CommandFlags.LinkedWithNextCommand | CommandFlags.Repeatable);
            var runData2 = VimUtil.CreateCommandRunData(flags: CommandFlags.Repeatable, command: Command.NewInsertCommand(InsertCommand.NewInsertText("foo")));

            _runner.Raise(x => x.CommandRan += null, (object)null, new CommandRunDataEventArgs(runData1));
            _runner.Raise(x => x.CommandRan += null, (object)null, new CommandRunDataEventArgs(runData2));
            var lastCommnad = _vimData.LastCommand;

            Assert.True(lastCommnad.IsSome(x => x.IsLinkedCommand));
        }
Example #26
0
        /// <summary>
        /// Returns items for given character.
        /// </summary>
        /// <param name="characterId"></param>
        /// <returns></returns>
        public void SaveCharacterItems(Character character)
        {
            using (var conn = this.GetConnection())
                using (var trans = conn.BeginTransaction())
                {
                    using (var mc = new MySqlCommand("DELETE FROM `inventory` WHERE `characterId` = @characterId", conn, trans))
                    {
                        mc.Parameters.AddWithValue("@characterId", character.Id);
                        mc.ExecuteNonQuery();
                    }

                    var i = 0;
                    foreach (var item in character.Inventory.GetItems().OrderBy(a => a.Key))
                    {
                        var newId = 0L;

                        // Save the actual items into the items table and the
                        // inventory-exclusive values into the inventory table,
                        // while linking to the items.
                        // TODO: Add generic item load and save methods, for
                        //   other item collections to use, such as warehouse.

                        using (var cmd = new InsertCommand("INSERT INTO `items` {0}", conn))
                        {
                            cmd.Set("itemId", item.Value.Id);
                            cmd.Set("amount", item.Value.Amount);

                            cmd.Execute();

                            newId = cmd.LastId;
                        }

                        using (var cmd = new InsertCommand("INSERT INTO `inventory` {0}", conn))
                        {
                            cmd.Set("characterId", character.Id);
                            cmd.Set("itemId", newId);
                            cmd.Set("sort", i++);
                            cmd.Set("equipSlot", 0x7F);

                            cmd.Execute();
                        }
                    }

                    // Save only non-dummy equip to the database, and make sure
                    // that dummy equip that was loaded into the character as a
                    // normal item wrongfully isn't saved again.
                    foreach (var item in character.Inventory.GetEquip().Where(a => !(a.Value is DummyEquipItem) && !Items.DefaultItems.Contains(a.Value.Id)))
                    {
                        var newId = 0L;

                        using (var cmd = new InsertCommand("INSERT INTO `items` {0}", conn))
                        {
                            cmd.Set("itemId", item.Value.Id);
                            cmd.Set("amount", item.Value.Amount);

                            cmd.Execute();

                            newId = cmd.LastId;
                        }

                        using (var cmd = new InsertCommand("INSERT INTO `inventory` {0}", conn))
                        {
                            cmd.Set("characterId", character.Id);
                            cmd.Set("itemId", newId);
                            cmd.Set("sort", 0);
                            cmd.Set("equipSlot", (byte)item.Key);

                            cmd.Execute();
                        }
                    }

                    trans.Commit();
                }
        }
Example #27
0
		public abstract void Visit(InsertCommand insertCommand);
Example #28
0
        /// <summary>
        /// Saves owner's variables in database.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="vars"></param>
        public void SaveVariables(string owner, VariableManager vars)
        {
            using (var conn = this.GetConnection())
                using (var trans = conn.BeginTransaction())
                {
                    using (var mc = new MySqlCommand("DELETE FROM `vars` WHERE `owner` = @owner", conn, trans))
                    {
                        mc.Parameters.AddWithValue("@owner", owner);
                        mc.ExecuteNonQuery();
                    }

                    foreach (var var in vars.GetList())
                    {
                        if (var.Value == null)
                        {
                            continue;
                        }

                        // Get type
                        string type;
                        if (var.Value is byte)
                        {
                            type = "1u";
                        }
                        else if (var.Value is ushort)
                        {
                            type = "2u";
                        }
                        else if (var.Value is uint)
                        {
                            type = "4u";
                        }
                        else if (var.Value is ulong)
                        {
                            type = "8u";
                        }
                        else if (var.Value is sbyte)
                        {
                            type = "1";
                        }
                        else if (var.Value is short)
                        {
                            type = "2";
                        }
                        else if (var.Value is int)
                        {
                            type = "4";
                        }
                        else if (var.Value is long)
                        {
                            type = "8";
                        }
                        else if (var.Value is float)
                        {
                            type = "f";
                        }
                        else if (var.Value is double)
                        {
                            type = "d";
                        }
                        else if (var.Value is bool)
                        {
                            type = "b";
                        }
                        else if (var.Value is string)
                        {
                            type = "s";
                        }
                        else
                        {
                            Log.Warning("SaveVars: Skipping variable '{0}', unsupported type '{1}'.", var.Key, var.Value.GetType().Name);
                            continue;
                        }

                        // Get value
                        var val = "";
                        switch (type)
                        {
                        case "f": val = ((float)var.Value).ToString(CultureInfo.InvariantCulture); break;

                        case "d": val = ((double)var.Value).ToString(CultureInfo.InvariantCulture); break;

                        default: val = var.Value.ToString(); break;
                        }

                        // Make sure value isn't too big for the mediumtext field
                        // (unlikely as it may be). Size: 16,777,215
                        if (val.Length > (1 << 24) - 1)
                        {
                            Log.Warning("SaveVars: Skipping variable '{0}', it's too big.", var.Key);
                            continue;
                        }

                        // Save
                        using (var cmd = new InsertCommand("INSERT INTO `vars` {0}", conn, trans))
                        {
                            cmd.Set("owner", owner);
                            cmd.Set("name", var.Key);
                            cmd.Set("type", type);
                            cmd.Set("value", val);

                            cmd.Execute();
                        }
                    }

                    trans.Commit();
                }
        }
Example #29
0
        public static OperationResult Insert(
           DataFieldCollection pValues,
           Transaction pTransaction,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            bool lLocalTransaction = (pTransaction == null);

            if (lLocalTransaction)
                lTransaction = new Transaction(Instance.CreateDatabase(pInfo));
            else
                lTransaction = pTransaction;

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(OficioQD.TableName, OficioQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(OficioQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "OFC_ID");
                    lInsert.Fields.Add(OficioQD._OFC_ID.Name, lSequence, (ItemType)OficioQD._OFC_ID.DBType);
                    lReturn.SequenceControl = lSequence;

                    string lNumeroOficio = "OFC" + lSequence.ToString().PadLeft(7, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    lInsert.Fields.Add(OficioQD._OFC_NUMERO.Name, lNumeroOficio, (ItemType)OficioQD._OFC_NUMERO.DBType);

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction, false);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Example #30
0
        private static void Generate(DAType dt)
        {
            if (OptionValue("pressKey") != null)
            {
                Console.Read();
            }

            string assembliesDir = OptionValue("dll");
            if (!Directory.Exists(assembliesDir))
            {
                Console.WriteLine("Source directory does not exist. Current dir used.");
            }
            else
            {
                AssemblyTypesCollection.DefaultAssemblyScanStrategy =
                    new AppDomainBaseDirectoryStrategy(assembliesDir);
            }

            string targetDir;
            if (OptionValue("t") != null)
            {
                targetDir = OptionValue("t");
            }
            else
                targetDir = AppDomain.CurrentDomain.BaseDirectory;
            targetDir = Path.Combine(targetDir, dt.ToString());
            if (!string.IsNullOrEmpty(targetDir) && !Directory.Exists(targetDir))
                Directory.CreateDirectory(targetDir);

            var targetFileName = Path.Combine(targetDir,
                                              ((OptionValue("noTables") == null) ? "CreateDBScript.sql" : "DefaultInserts.sql"));

            Console.WriteLine("The result will be at {0}.", targetFileName);

            if (File.Exists(targetFileName))
            {
                Console.WriteLine("Target file name will be overwritten");
            }

            CultureInfo cUI = Thread.CurrentThread.CurrentUICulture;
            CultureInfo myCIclone = (CultureInfo)cUI.Clone();
            myCIclone.NumberFormat.NumberGroupSeparator = "";
            myCIclone.NumberFormat.NumberDecimalSeparator = ".";
            myCIclone.NumberFormat.CurrencyDecimalSeparator = ".";
            Thread.CurrentThread.CurrentUICulture = myCIclone;
            Thread.CurrentThread.CurrentCulture = myCIclone;

            using (StreamWriter Target = File.CreateText(targetFileName))
            {
                IList scripted = new ArrayList();
                IList notScripted = new ArrayList();
                IList scriptedTables = new ArrayList();
                DescriptorCache.Instance = null;
                foreach (TypeDescriptor td in DescriptorCache.Instance)
                {
                    if (CanBeScripted(td.RealType, dt))
                    {
                        notScripted.Add(td);
                    }
                }

                int i = 0;
                while (notScripted.Count > 0)
                {
                    //if (i >= notScripted.Count)
                    //	i = notScripted.Count-1;
                    TypeDescriptor td = (TypeDescriptor)notScripted[i];
                    bool notScriptedReference = false;
                    foreach (ReferenceFieldDescriptor rfd in td.ReferenceFields)
                    {
                        if (!rfd.NoForeignKey)
                        {
                            TypeDescriptor refTd = DescriptorCache.Instance[rfd.ReferencedType];
                            if (refTd != td // дозволяється посилатися на самого себе
                                && (CanBeScripted(refTd.RealType, dt))
                                && !scripted.Contains(refTd))
                            {
                                notScriptedReference = true;
                                i++;
                                if (i >= notScripted.Count)
                                {
                                    Console.WriteLine("Circular references in foreign keys found in {0}", td.RealType.FullName);
                                    Console.WriteLine(" to {0}", refTd.RealType.FullName);
                                }
                                break;
                            }
                        }
                    }
                    if (!notScriptedReference)
                    {
                        i = 0;
                        notScripted.Remove(td);
                        scripted.Add(td);
                    }
                }

                if (OptionValue("noTables") == null)
                {
                    for (int j = scripted.Count - 1; j >= 0; j--)
                    {
                        TypeDescriptor td;
                        IList tables2Delete = new ArrayList();
                        for (int ii = j - 1; ii >= 0; ii--)
                        {
                            td = (TypeDescriptor)scripted[ii];
                            foreach (string tableName in td.TableNames.Keys)
                            {
                                if (!tables2Delete.Contains(tableName))
                                    tables2Delete.Add(tableName);
                            }
                        }

                        td = (TypeDescriptor)scripted[j];
                        var tables = new List<string>();
                        foreach (string tableName in td.TableNames.Keys)
                        {
                            if (!tables2Delete.Contains(tableName))
                            {
                                tables.Add(tableName);
                            }
                        }

                        Target.WriteLine(new DeleteEntityCommand(dt).BuildSql(td, tables)[0]);
                    }

                    foreach (TypeDescriptor td in scripted)
                    {
                        var tables = new List<string>();
                        foreach (string tableName in td.TableNames.Keys)
                        {
                            if (!scriptedTables.Contains(tableName))
                            {
                                tables.Add(tableName);
                                scriptedTables.Add(tableName);
                            }
                        }

                        Console.WriteLine("Parsing class {0}...", td.RealType.FullName);
                        Target.WriteLine(new CreateEntityCommand(dt).BuildSql(td, tables)[0]);
                    }
                }

                if (OptionValue("sp") != null)
                {
                    Console.WriteLine("Generation standard stored procedures...");
                    foreach (TypeDescriptor td in scripted)
                    {
                        Target.WriteLine(new CreateStandardProceduresCommand(dt).BuildSql(td)[0]);
                    }
                }

                if (OptionValue("r") != null)
                {
                    Console.WriteLine("Generation reference data...");
                    foreach (TypeDescriptor td in scripted)
                    {
                        try
                        {
                            Target.WriteLine();
                            Target.WriteLine("-- Table " + td.Name);
                            IPersistent obj = (IPersistent)Activator.CreateInstance(td.RealType);
                            foreach (IPersistent o in obj.DefaultValues())
                            {
                                var command = new InsertCommand(dt);
                                string sql = command.BuildSql(td, SqlGenerator.GetObjectParameters(o), false)[0];
                                if (dt == DAType.Oracle)
                                    sql += "\r\n;\r\n";
                                Target.WriteLine(sql);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(string.Format("Error for class {0}: {1}", td.Name, ex.Message));
                        }
                    }
                }
                Target.Flush();
                Console.WriteLine("Creation scripts successfully created.");
            }
        }
Example #31
0
 protected InsertCommand UpdateInsert(InsertCommand insert, TableExpression table, IEnumerable<ColumnAssignment> assignments)
 {
     if (table != insert.Table || assignments != insert.Assignments)
     {
         return new InsertCommand(table, assignments);
     }
     return insert;
 }
Example #32
0
        /// <summary>
        /// Try and custom process the given InsertCommand when it's appropriate to override
        /// with Visual Studio specific behavior
        /// </summary>
        public bool TryCustomProcess(InsertCommand command)
        {
            // Don't want to let VS process insert commands during clean macro recording.  Doing so
            // will pop up UI, auto complete braces, etc ...  which interfere with recording.
            if (_vim.MacroRecorder.IsRecording && _vimApplicationSettings.CleanMacros)
            {
                return(false);
            }

            VimTrace.TraceInfo($"TryCustomProcess {command} and completion {_broker.IsCompletionActive}");

            var oleCommandData = OleCommandData.Empty;

            try
            {
                if (_vim.InBulkOperation && !command.IsInsertNewLine)
                {
                    // If we are in the middle of a bulk operation we don't want to forward any
                    // input to IOleCommandTarget because it will trigger actions like displaying
                    // Intellisense.  Definitely don't want intellisense popping up during say a
                    // repeat of a 'cw' operation or macro.
                    //
                    // The one exception to this rule though is the Enter key.  Every single language
                    // formats Enter in a special way that we absolutely want to preserve in a change
                    // or macro operation.  Go ahead and let it go through here and we'll dismiss
                    // any intellisense which pops up as a result
                    return(false);
                }

                if (!_vimApplicationSettings.UseEditorTabAndBackspace && (command.IsBack || command.IsInsertTab))
                {
                    // When the user has opted into 'softtabstop' then Vim has a better understanding of
                    // <BS> than Visual Studio.  Allow that processing to win
                    return(false);
                }

                if (!TryGetOleCommandData(command, out oleCommandData))
                {
                    // Not a command that we custom process
                    return(false);
                }

                var versionNumber = _textBuffer.CurrentSnapshot.Version.VersionNumber;
                var hr            = _nextCommandTarget.Exec(oleCommandData);

                // Whether or not an Exec succeeded is a bit of a heuristic.  IOleCommandTarget implementations like
                // C++ will return E_ABORT if Intellisense failed but the character was actually inserted into
                // the ITextBuffer.  VsVim really only cares about the character insert.  However we must also
                // consider cases where the character successfully resulted in no action as a success
                return(ErrorHandler.Succeeded(hr) || versionNumber < _textBuffer.CurrentSnapshot.Version.VersionNumber);
            }
            finally
            {
                if (oleCommandData != null)
                {
                    oleCommandData.Dispose();
                }

                if (_vim.InBulkOperation && _broker.IsCompletionActive)
                {
                    _broker.DismissDisplayWindows();
                }
            }
        }
Example #33
0
        public static OperationResult Insert(
           DataFieldCollection pValuesPessoa,
           DataFieldCollection pValuesEndereco,
           DataFieldCollection pValuesPessoaEndereco,
           DataFieldCollection pValuesRG,
           DataFieldCollection pValuesCPF,
           DataFieldCollection pValuesCNPJ,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaQD.TableName, PessoaQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaQD.TableName);

                    foreach (DataField lField in pValuesPessoa.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesPessoa[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequencePessoa;
                    lSequencePessoa = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                    lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequencePessoa, (ItemType)PessoaQD._PES_ID.DBType);

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (pValuesEndereco.Count > 0)
                        {
                            lReturn = EnderecoDo.Insert(pValuesEndereco, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            decimal lSequenceEndereco = lReturn.SequenceControl;

                            DataFieldCollection lFieldsPE = new DataFieldCollection();
                            pValuesPessoaEndereco.Add(PessoaEnderecoQD._ENDE_ID, lSequenceEndereco);
                            pValuesPessoaEndereco.Add(PessoaEnderecoQD._PES_ID, lSequencePessoa);

                            lReturn = PessoaEnderecoDo.Insert(pValuesPessoaEndereco, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesRG.Count > 0)
                        {
                            pValuesRG.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesRG, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesCPF.Count > 0)
                        {
                            pValuesCPF.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesCPF, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesCNPJ.Count > 0)
                        {
                            pValuesCNPJ.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesCNPJ, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (!lReturn.HasError)
                        {
                            lReturn.SequenceControl = lSequencePessoa;
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Example #34
0
        /// <summary>
        /// Returns a user for the given values, either from the db,
        /// or by creating a new one.
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="characterEntityId"></param>
        /// <param name="characterName"></param>
        /// <param name="server"></param>
        /// <param name="channelName"></param>
        /// <returns></returns>
        public User GetOrCreateContact(string accountId, long characterEntityId, string characterName, string server, string channelName)
        {
            using (var conn = this.Connection)
            {
                var user = new User();
                user.AccountId   = accountId;
                user.CharacterId = characterEntityId;
                user.Name        = characterName;
                user.Server      = server;
                user.ChannelName = channelName;
                user.Status      = ContactStatus.Online;
                user.ChatOptions = ChatOptions.NotifyOnFriendLogIn;
                user.LastLogin   = DateTime.Now;

                // Try to get contact from db
                using (var mc = new MySqlCommand("SELECT * FROM `contacts` WHERE `characterEntityId` = @characterEntityId", conn))
                {
                    mc.Parameters.AddWithValue("@characterEntityId", characterEntityId);

                    using (var reader = mc.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            user.Id          = reader.GetInt32("contactId");
                            user.Status      = (ContactStatus)reader.GetByte("status");
                            user.ChatOptions = (ChatOptions)reader.GetUInt32("chatOptions");
                            user.Nickname    = reader.GetStringSafe("nickname") ?? "";
                            user.LastLogin   = reader.GetDateTimeSafe("lastLogin");

                            if (!Enum.IsDefined(typeof(ContactStatus), user.Status) || user.Status == ContactStatus.None)
                            {
                                user.Status = ContactStatus.Online;
                            }

                            this.UpdateLastLogin(user);

                            return(user);
                        }
                    }
                }

                // Create new contact
                using (var cmd = new InsertCommand("INSERT INTO `contacts` {0}", conn))
                {
                    cmd.Set("accountId", accountId);
                    cmd.Set("characterEntityId", characterEntityId);
                    cmd.Set("characterName", characterName);
                    cmd.Set("server", server);
                    cmd.Set("status", (byte)user.Status);
                    cmd.Set("chatOptions", (uint)user.ChatOptions);
                    cmd.Set("nickname", "");
                    cmd.Set("lastLogin", user.LastLogin);

                    cmd.Execute();

                    user.Id = (int)cmd.LastId;

                    return(user);
                }
            }
        }
        public static OperationResult Insert(
           DataFieldCollection pValues,
           Transaction pTransaction,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            bool lLocalTransaction = (pTransaction == null);

            if (lLocalTransaction)
                lTransaction = new Transaction(Instance.CreateDatabase(pInfo));
            else
                lTransaction = pTransaction;

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(AtuacaoQD.TableName, AtuacaoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    //lReturn.Trace("Excluído Atuações...");
                    //lReturn = UpdateInativo(pValues[AtuacaoQD._PESF_ID].DBToDecimal(), pValues[AtuacaoQD._ATUA_STATUS].ToString(), pInfo);

                    //if (lReturn.HasError)
                    //{
                    //    return lReturn;
                    //}

                    lInsert = new InsertCommand(AtuacaoQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "ATUA_ID");
                    lInsert.Fields.Add(AtuacaoQD._ATUA_ID.Name, lSequence, (ItemType)AtuacaoQD._ATUA_ID.DBType);
                    lReturn.SequenceControl = lSequence;

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Example #36
0
        public static InsertCommand <TEntity> Add <TEntity>(this IGraphClient client, TEntity entity)
        {
            var command = new InsertCommand <TEntity>(client, entity);

            return(command);
        }
Example #37
0
        /// <summary>
        /// Try and convert the given insert command to an OleCommand.  This should only be done
        /// for InsertCommand values which we want to custom process
        /// </summary>
        private bool TryGetOleCommandData(InsertCommand command, out OleCommandData commandData)
        {
            if (command.IsBack)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.BACKSPACE);
                return true;
            }

            if (command.IsDelete)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.DELETE);
                return true;
            }

            if (command.IsDirectInsert)
            {
                var directInsert = (InsertCommand.DirectInsert)command;
                commandData = OleCommandData.CreateTypeChar(directInsert.Item);
                return true;
            }

            if (command.IsInsertTab)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.TAB);
                return true;
            }

            if (command.IsInsertNewLine)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.RETURN);
                return true;
            }

            commandData = OleCommandData.Empty;
            return false;
        }
		private bool CompareInsert(InsertCommand x, InsertCommand y)
		{
			return this.Compare(x.Table, y.Table) && this.CompareColumnAssignments(x.Assignments, y.Assignments);
		}
Example #39
0
 bool IVimHost.TryCustomProcess(ITextView textView, InsertCommand command)
 {
     return TryCustomProcess(textView, command);
 }
Example #40
0
        /// <summary>
        /// Try and convert the given insert command to an OleCommand.  This should only be done
        /// for InsertCommand values which we want to custom process
        /// </summary>
        private bool TryGetOleCommandData(InsertCommand command, out OleCommandData commandData)
        {
            if (command.IsBack)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.BACKSPACE);
                return true;
            }

            if (command.IsDelete)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.DELETE);
                return true;
            }

            if (command.IsInsert)
            {
                var insert = (InsertCommand.Insert)command;
                if (insert.Item != null && insert.Item.Length == 1)
                {
                    commandData = OleCommandData.CreateTypeChar(insert.Item[0]);
                    return true;
                }
            }

            if (command.IsInsertTab)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.TAB);
                return true;
            }

            if (command.IsInsertNewLine)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.RETURN);
                return true;
            }

            commandData = OleCommandData.Empty;
            return false;
        }
 protected virtual bool CompareInsert(InsertCommand x, InsertCommand y)
 {
     return this.Compare(x.Table, y.Table)
         && this.CompareColumnAssignments(x.Assignments, y.Assignments);
 }
Example #42
0
 protected override Expression VisitInsert(InsertCommand insert)
 {
     this.Write("INSERT INTO ");
     this.WriteTableName(insert.Table.Name);
     this.Write("(");
     for (int i = 0, n = insert.Assignments.Count; i < n; i++)
     {
         ColumnAssignment ca = insert.Assignments[i];
         if (i > 0) this.Write(", ");
         this.WriteColumnName(ca.Column.Name);
     }
     this.Write(")");
     this.WriteLine(Indentation.Same);
     this.Write("VALUES (");
     for (int i = 0, n = insert.Assignments.Count; i < n; i++)
     {
         ColumnAssignment ca = insert.Assignments[i];
         if (i > 0) this.Write(", ");
         this.Visit(ca.Expression);
     }
     this.Write(")");
     return insert;
 }
Example #43
0
        public static OperationResult Insert(
           DataFieldCollection pValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(TriagemQD.TableName, TriagemQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(TriagemQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "TRG_ID");
                    lInsert.Fields.Add(TriagemQD._TRG_ID.Name, lSequence, (ItemType)TriagemQD._TRG_ID.DBType);
                    lReturn.SequenceControl = lSequence;
                    decimal lSequenceSenha;

                    if (pValues[TriagemQD._ASTTRG_ID].ToString() == "1")
                    {
                        lSequenceSenha = DataBaseSequenceControl.GetNext(lTransaction, TriagemQD.TableName, "TRG_SENHA", " NUC_ID = " + pValues[TriagemQD._NUC_ID] + " AND TO_CHAR(TRG_REGDATE,'dd/MM/yyyy') = TO_CHAR(SYSDATE,'dd/MM/yyyy') AND ASTTRG_ID = 1 AND TRG_PRIORIDADE = " + pValues[TriagemQD._TRG_PRIORIDADE]);
                        lInsert.Fields.Add(TriagemQD._TRG_SENHA.Name, lSequenceSenha, (ItemType)TriagemQD._TRG_SENHA.DBType);
                    }
                    else if (pValues[TriagemQD._ASTTRG_ID].ToString() == "4")
                    {
                        lSequenceSenha = DataBaseSequenceControl.GetNext(lTransaction, TriagemQD.TableName, "TRG_SENHA", " NUC_ID = " + pValues[TriagemQD._NUC_ID] + " AND TO_CHAR(TRG_REGDATE,'dd/MM/yyyy') = TO_CHAR(SYSDATE,'dd/MM/yyyy') AND ASTTRG_ID = 4 AND TRG_PRIORIDADE = " + pValues[TriagemQD._TRG_PRIORIDADE]);
                        lInsert.Fields.Add(TriagemQD._TRG_SENHA.Name, lSequenceSenha, (ItemType)TriagemQD._TRG_SENHA.DBType);
                    }
                    else if (pValues[TriagemQD._ASTTRG_ID].ToString() == "7")
                    {
                        lSequenceSenha = DataBaseSequenceControl.GetNext(lTransaction, TriagemQD.TableName, "TRG_SENHA", " NUC_ID = " + pValues[TriagemQD._NUC_ID] + " AND TO_CHAR(TRG_REGDATE,'dd/MM/yyyy') = TO_CHAR(SYSDATE,'dd/MM/yyyy') AND ASTTRG_ID = 7 AND TRG_PRIORIDADE = " + pValues[TriagemQD._TRG_PRIORIDADE]);
                        lInsert.Fields.Add(TriagemQD._TRG_SENHA.Name, lSequenceSenha, (ItemType)TriagemQD._TRG_SENHA.DBType);
                    }

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Example #44
0
 protected override Expression VisitInsert(InsertCommand insert)
 {
     return(this.BuildExecuteCommand(insert));
 }
Example #45
0
 protected void SetupInsertCommand(InsertCommand command)
 {
     _insertUtil
         .Setup(x => x.RunInsertCommand(command))
         .Returns(CommandResult.NewCompleted(ModeSwitch.NoSwitch))
         .Verifiable();
 }
        public static OperationResult InsertProcesso(
                DataFieldCollection pValuesAgendamentoDefensor,
                DataFieldCollection pValuesAtendimento,
                List<DataFieldCollection> pListDocumentoMovimentoAtendimento,
                DataFieldCollection pValuesProcesso,
                List<DataFieldCollection> pListAssuntoProcessual,
                List<DataFieldCollection> pListInteressado,
                DataFieldCollection pValuesDocMovTramitacao,
                List<DataFieldCollection> pListDocumentoMovimentoProcesso,
                DataFieldCollection pValuesTramitacao,
                DataFieldCollection pValuesDocMovAnexo,
                DataFieldCollection pValuesAnexoExterno,
                DataFieldCollection pValuesDocMovApf,
                DataFieldCollection pValuesAnexoApf,
                DataFieldCollection pValuesDocMovSiscop,
                DataFieldCollection pValuesAnexoSiscop,
                DataFieldCollection pValuesCriminalDatas,
             ConnectionInfo pInfo
         )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(DocumentoQD.TableName, DocumentoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(DocumentoQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValuesProcesso.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesProcesso[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "DOC_ID");
                    lInsert.Fields.Add(DocumentoQD._DOC_ID.Name, lSequence, (ItemType)DocumentoQD._DOC_ID.DBType);

                    lReturn.SequenceControl = lSequence;

                    decimal lDocNumero = 0;
                    string lNumeroDocumento = "";

                    if (pValuesProcesso[DocumentoQD._TDOC_ID].DBToDecimal() == 1)
                    {
                        lDocNumero = DataBaseSequenceControl.GetNext(pInfo, "DOC_ATENDIMENTO");

                        if (System.Configuration.ConfigurationManager.AppSettings["ApplicationMode"].ToString() == "OnLine")
                            lNumeroDocumento = "A" + pValuesProcesso[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                        else
                            lNumeroDocumento = "T" + pValuesProcesso[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    }
                    else if (pValuesProcesso[DocumentoQD._TDOC_ID].DBToDecimal() == 2)
                    {
                        lDocNumero = DataBaseSequenceControl.GetNext(pInfo, "DOC_NUMERO");

                        if (System.Configuration.ConfigurationManager.AppSettings["ApplicationMode"].ToString() == "OnLine")
                            lNumeroDocumento = "P" + pValuesProcesso[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                        else
                            lNumeroDocumento = "R" + pValuesProcesso[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    }

                    lInsert.Fields.Add(DocumentoQD._DOC_NUMERO.Name, lNumeroDocumento, (ItemType)DocumentoQD._DOC_NUMERO.DBType);

                    lReturn.Trace("Executando o Insert Documento");

                    lInsert.Execute(lTransaction, false);

                    if (!lReturn.HasError)
                    {

                        lReturn = AgendamentoDefensorDo.Update(pValuesAgendamentoDefensor, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        lReturn = DocumentoDo.Update(pValuesAtendimento, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        if (pListDocumentoMovimentoAtendimento.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListDocumentoMovimentoAtendimento)
                            {
                                lReturn = DocumentoMovimentoDo.Insert(lFields, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (pListAssuntoProcessual.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListAssuntoProcessual)
                            {
                                lFields.Add(AssuntoProcessualQD._DOC_ID, lSequence);

                                lReturn = AssuntoProcessualDo.Insert(lFields, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (pListInteressado.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListInteressado)
                            {
                                lFields.Add(InteressadoQD._DOC_ID, lSequence);

                                lReturn = InteressadoDo.Insert(lFields, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (pListDocumentoMovimentoProcesso.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListDocumentoMovimentoProcesso)
                            {
                                lFields.Add(DocumentoMovimentoQD._DOC_ID, lSequence);

                                lReturn = DocumentoMovimentoDo.Insert(lFields, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        pValuesDocMovTramitacao.Add(DocumentoMovimentoQD._DOC_ID, lSequence);
                        lReturn = DocumentoMovimentoDo.Insert(pValuesDocMovTramitacao, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        decimal lDocMov = 0;
                        lDocMov = lReturn.SequenceControl;

                        pValuesTramitacao.Add(DocumentoTramitacaoQD._DOCMOV_ID, lDocMov);
                        lReturn = DocumentoTramitacaoDo.Insert(pValuesTramitacao, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        if (pValuesAnexoExterno.Count > 0)
                        {
                            pValuesDocMovAnexo.Add(DocumentoMovimentoQD._DOC_ID, lSequence);
                            lReturn = DocumentoMovimentoDo.Insert(pValuesDocMovAnexo, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            lDocMov = lReturn.SequenceControl;
                            pValuesAnexoExterno.Add(DocumentoAnexoQD._DOCMOV_ID, lDocMov);
                            lReturn = DocumentoAnexoDo.Insert(pValuesAnexoExterno, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesAnexoApf.Count > 0)
                        {
                            pValuesDocMovApf.Add(DocumentoMovimentoQD._DOC_ID, lSequence);
                            lReturn = DocumentoMovimentoDo.Insert(pValuesDocMovApf, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            lDocMov = lReturn.SequenceControl;
                            pValuesAnexoApf.Add(DocumentoAnexoQD._DOCMOV_ID, lDocMov);
                            lReturn = DocumentoAnexoDo.Insert(pValuesAnexoApf, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesAnexoSiscop.Count > 0)
                        {
                            pValuesDocMovSiscop.Add(DocumentoMovimentoQD._DOC_ID, lSequence);
                            lReturn = DocumentoMovimentoDo.Insert(pValuesDocMovSiscop, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            lDocMov = lReturn.SequenceControl;
                            pValuesAnexoSiscop.Add(DocumentoAnexoQD._DOCMOV_ID, lDocMov);
                            lReturn = DocumentoAnexoDo.Insert(pValuesAnexoSiscop, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesCriminalDatas.Count > 0)
                        {
                            pValuesCriminalDatas.Add(CriminalDatasQD._DOC_ID, lSequence);
                            lReturn = CriminalDatasDo.Insert(pValuesCriminalDatas, lTransaction, pInfo);

                        }

                        if (!lReturn.HasError)
                        {
                            lReturn.SequenceControl = lSequence;
                            lReturn.Trace("Insert finalizado, executando commit");
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
        public static OperationResult Insert(
           DataFieldCollection pValuesPESF,
           List<DataFieldCollection> pListValuesATUA,
           DataFieldCollection pValuesSUSR,
           List<DataFieldCollection> pListValuesPERMISSAO,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaFuncaoQD.TableName, PessoaFuncaoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaFuncaoQD.TableName);

                    foreach (DataField lField in pValuesPESF.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesPESF[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequencePESF_ID;
                    lSequencePESF_ID = DataBaseSequenceControl.GetNext(pInfo, "PESF_ID");
                    lInsert.Fields.Add(PessoaFuncaoQD._PESF_ID.Name, lSequencePESF_ID, (ItemType)PessoaFuncaoQD._PESF_ID.DBType);

                    lReturn.SequenceControl = lSequencePESF_ID;

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {

                        if (pListValuesATUA.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListValuesATUA)
                            {
                                lFields.Add(AtuacaoQD._PESF_ID, lSequencePESF_ID);

                                lReturn = AtuacaoDo.Insert(lFields, lTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        lReturn = SystemUserDo.Insert(pValuesSUSR, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        if (pListValuesPERMISSAO.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListValuesPERMISSAO)
                            {
                                lFields.Add(SecurityUsersDtQD._SU_ID, lSequencePESF_ID);

                                lReturn = SecurityUsersDtDo.Insert(lFields, lTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (!lReturn.HasError)
                        {
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
        public static OperationResult Insert(
           DataFieldCollection pValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(DocumentoQD.TableName, DocumentoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(DocumentoQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "DOC_ID");
                    lInsert.Fields.Add(DocumentoQD._DOC_ID.Name, lSequence, (ItemType)DocumentoQD._DOC_ID.DBType);

                    lReturn.SequenceControl = lSequence;

                    decimal lDocNumero = 0;
                    string lNumeroDocumento = "";

                    if (pValues[DocumentoQD._TDOC_ID].DBToDecimal() == 1)
                    {
                        lDocNumero = DataBaseSequenceControl.GetNext(pInfo, "DOC_ATENDIMENTO");

                        if (System.Configuration.ConfigurationManager.AppSettings["ApplicationMode"].ToString() == "OnLine")
                            lNumeroDocumento = "A" + pValues[DocumentoQD._NUC_ID].ToString().PadLeft(2,'0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                        else
                            lNumeroDocumento = "T" + pValues[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    }
                    else if (pValues[DocumentoQD._TDOC_ID].DBToDecimal() == 2)
                    {
                        lDocNumero = DataBaseSequenceControl.GetNext(pInfo, "DOC_NUMERO");

                        if (System.Configuration.ConfigurationManager.AppSettings["ApplicationMode"].ToString() == "OnLine")
                            lNumeroDocumento = "P" + pValues[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                        else
                            lNumeroDocumento = "R" + pValues[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    }

                    lInsert.Fields.Add(DocumentoQD._DOC_NUMERO.Name, lNumeroDocumento, (ItemType)DocumentoQD._DOC_NUMERO.DBType);

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction, false);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Example #49
0
        /// <summary>
        /// Custom process the insert command if possible.  This is handled by VsCommandTarget
        /// </summary>
        public override bool TryCustomProcess(ITextView textView, InsertCommand command)
        {
            VsCommandTarget vsCommandTarget;
            if (VsCommandTarget.TryGet(textView, out vsCommandTarget))
            {
                return vsCommandTarget.TryCustomProcess(command);
            }

            return false;
        }
Example #50
0
 /// <summary>
 /// Processes an INSERT command
 /// </summary>
 /// <param name="cmd">Insert Command</param>
 public void ProcessInsertCommand(InsertCommand cmd)
 {
     this.ProcessCommand(cmd);
 }