Exemplo n.º 1
0
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     var frame = ActiveFrame;
     if (frame == null)
         return false;
     var ct = frame.Pane as ICommandTarget;
     if (ct == null)
         return false;
     return ct.QueryStatus(cmdId, status, text);
 }
Exemplo n.º 2
0
 public override bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (cmdId.Guid == CmdSets.GuidReko)
     {
         switch (cmdId.ID)
         {
         case CmdIds.ActionNextPhase:
         case CmdIds.ActionFinishDecompilation:
             status.Status = MenuStatus.Visible;
             return true;
         }
     }
     return base.QueryStatus(cmdId, status, text);
 }
Exemplo n.º 3
0
 public override bool QueryStatus(CommandID cmdID, CommandStatus status, CommandText txt)
 {
     if (cmdID.Guid == CmdSets.GuidDecompiler)
     {
         switch (cmdID.ID)
         {
         case CmdIds.ActionMarkProcedure:
         case CmdIds.ActionScanHeuristically:
             status.Status = MenuStatus.Enabled|MenuStatus.Visible;
             return true;
         }
     }
     return base.QueryStatus(cmdID, status, txt);
 }
Exemplo n.º 4
0
        public override bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
        {
            if (cmdId.Guid == CmdSets.GuidReko)
            {
                switch (cmdId.ID)
                {
                case CmdIds.ActionRestartDecompilation:
                    status.Status = MenuStatus.Visible | MenuStatus.Enabled;
                    return(true);

                case CmdIds.ActionNextPhase:
                case CmdIds.ActionFinishDecompilation:
                    status.Status = MenuStatus.Visible;
                    return(true);
                }
            }
            return(base.QueryStatus(cmdId, status, text));
        }
Exemplo n.º 5
0
        public MySqlDataReader Query()
        {
            if (_dbConnector != null || Reader != null)
            {
                throw new AegisException(AegisResult.DataReaderNotClosed, "There is already an open DataReader associated with this Connection which must be closed first.");
            }


            _dbConnector         = _pool.GetDBC();
            _command.Connection  = _dbConnector.Connection;
            _command.CommandText = CommandText.ToString();

            Prepare();
            Reader = _command.ExecuteReader();
            _dbConnector.QPS.Add(1);

            return(Reader);
        }
Exemplo n.º 6
0
        public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
        {
            if (mruFirst <= cmdId.ID && cmdId.ID < mruMax)
            {
                status.Status = MenuStatus.Visible | MenuStatus.Enabled;
                text.Text     = string.Format("MRU {0}", cmdId.ID - mruFirst);
                return(true);
            }

            if (mpCmdIdToStatus.Contains(cmdId.ID))
            {
                status.Status = (MenuStatus)mpCmdIdToStatus[cmdId.ID];
                Console.WriteLine("Testring cmd {0}: status {1}", cmdId.ID, status.Status);

                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
        public void UpdateToolbarState()
        {
            var status = new CommandStatus();
            var text   = new CommandText();

            foreach (ToolStripItem item in ToolBar.Items)
            {
                if (item.Tag is MenuCommand cmd)
                {
                    text.Text = null;
                    var st = interactor.QueryStatus(cmd.CommandID, status, text);
                    item.Enabled = st && (status.Status & MenuStatus.Enabled) != 0;
                    if (!string.IsNullOrEmpty(text.Text))
                    {
                        item.Text = text.Text;
                    }
                }
            }
        }
Exemplo n.º 8
0
        public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
        {
            if (cmdId.Guid == CmdSets.GuidReko)
            {
                switch (cmdId.ID)
                {
                case CmdIds.EditCopy:
                    status.Status = listView.SelectedIndices.Count > 0
                        ? MenuStatus.Visible | MenuStatus.Enabled
                        : MenuStatus.Visible;
                    return(true);

                case CmdIds.EditSelectAll:
                    status.Status = MenuStatus.Visible | MenuStatus.Enabled;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 9
0
        // requires: this must be a StoreProcedure command
        // effects: determines the EntityContainer function import referenced by this.CommandText
        private EdmFunction DetermineFunctionImport()
        {
            Debug.Assert(CommandType.StoredProcedure == CommandType);

            if (string.IsNullOrEmpty(CommandText) ||
                string.IsNullOrEmpty(CommandText.Trim()))
            {
                throw new InvalidOperationException(Strings.EntityClient_FunctionImportEmptyCommandText);
            }

            // parse the command text
            string containerName;
            string functionImportName;
            string defaultContainerName = null; // no default container in EntityCommand

            CommandHelper.ParseFunctionImportCommandText(CommandText, defaultContainerName, out containerName, out functionImportName);

            return(CommandHelper.FindFunctionImport(_connection.GetMetadataWorkspace(), containerName, functionImportName));
        }
Exemplo n.º 10
0
        public override object ExecuteScalar()
        {
            if (ScalarMethodCache.TryGetValue(CommandText, out var cached) == false)
            {
                var lastDotIndex = CommandText.LastIndexOf('.');

                var typeString = CommandText.Substring(0, lastDotIndex);
                var type       = Assembly.GetExecutingAssembly().GetType(typeString);

                var methodString = CommandText.Substring(lastDotIndex + 1);
                cached = type.GetMethod(methodString);

                ScalarMethodCache.Add(CommandText, cached);
            }

            var value = cached.Invoke(null, null);

            return(value ?? DBNull.Value);
        }
Exemplo n.º 11
0
        protected override void ParseQuery()
        {
            // find index of open bracket in create query, where are descriptions of columns
            var openBacket = CommandText.IndexOf('(');
            // find index of close bracket in create query, where are descriptions of columns
            var closeBacket = CommandText.LastIndexOf(')');

            if (openBacket == -1 || closeBacket == -1 || openBacket == closeBacket)
            {
                throw new CreateTableParse($"Command has incorrect signature. Check brackets.");
            }
            // get command words, words befor descriptions of columns
            var commandWords = CommandText?
                               .Substring(0, openBacket)
                               .Trim()
                               .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (commandWords.Length != 3)
            {
                throw new CreateTableParse($"Command has incorrect signature. Check table name.");
            }
            // set table name and database name if format [dbname].[tableName]
            var tableAndDatabaseNames = commandWords[2].Split('.');

            if (tableAndDatabaseNames.Length == 2)
            {
                DatabaseName = tableAndDatabaseNames[0];
                TableName    = tableAndDatabaseNames[1];
            }
            else
            {
                TableName = tableAndDatabaseNames[0];
            }
            //
            Columns = CommandText?
                      .Substring(openBacket + 1, closeBacket - openBacket - 1)
                      .Trim()
                      .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (Columns.Length == 0)
            {
                throw new CreateTableParse($"Command does not have new columns description.");
            }
        }
Exemplo n.º 12
0
        public void EndQuery()
        {
            CommandText.Clear();
            _prepareBindings.Clear();
            _command.Parameters.Clear();
            _command.Connection = null;

            if (Reader != null)
            {
                Reader.Dispose();
                Reader = null;
            }

            if (_dbConnector != null)
            {
                _pool.ReturnDBC(_dbConnector);
                _dbConnector = null;
            }
        }
Exemplo n.º 13
0
        public virtual ICoreParseResult Slice(int numberOfLeadingSectionsToRemove)
        {
            if (numberOfLeadingSectionsToRemove == 0)
            {
                return(this);
            }

            if (numberOfLeadingSectionsToRemove >= Sections.Count)
            {
                return(new CoreParseResult(0, 0, string.Empty, new[] { string.Empty }, 0, new Dictionary <int, int> {
                    { 0, 0 }
                }, new HashSet <int>()));
            }

            string commandText = CommandText.Substring(SectionStartLookup[numberOfLeadingSectionsToRemove]);
            int    caretPositionWithinCommandText = CaretPositionWithinCommandText - SectionStartLookup[numberOfLeadingSectionsToRemove];

            if (caretPositionWithinCommandText < 0)
            {
                caretPositionWithinCommandText = 0;
            }

            Dictionary <int, int> sectionStartLookup = new Dictionary <int, int>();
            List <string>         sections           = new List <string>();

            for (int i = 0; i < Sections.Count - numberOfLeadingSectionsToRemove; ++i)
            {
                sectionStartLookup[i] = SectionStartLookup[numberOfLeadingSectionsToRemove + i] - SectionStartLookup[numberOfLeadingSectionsToRemove];
                sections.Add(Sections[numberOfLeadingSectionsToRemove + i]);
            }

            int selectedSection = SelectedSection - numberOfLeadingSectionsToRemove;

            if (selectedSection < 0)
            {
                selectedSection = 0;
            }

            HashSet <int> quotedSections = new HashSet <int>(_quotedSections.Where(x => x > 0).Select(x => x - 1));

            return(new CoreParseResult(caretPositionWithinCommandText, CaretPositionWithinSelectedSection, commandText, sections, selectedSection, sectionStartLookup, quotedSections));
        }
Exemplo n.º 14
0
        public override bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
        {
            if (cmdId.Guid == CmdSets.GuidReko)
            {
                switch (cmdId.ID)
                {
                case CmdIds.ViewGoToAddress:
                case CmdIds.ViewFindWhatPointsHere:
                case CmdIds.ActionEditSignature:
                case CmdIds.EditRename:
                    status.Status = MenuStatus.Visible | MenuStatus.Enabled;
                    return(true);

                case CmdIds.ActionAssumeRegisterValues:
                    status.Status = MenuStatus.Visible | MenuStatus.Enabled;
                    return(true);
                }
            }
            return(false);
        }
        private void HandleTempTable()
        {
            if (!CommandText.Contains(SingleRowTempTableRequiredToken))
            {
                return;
            }

            var commandText = CommandText;
            var tempFile    = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(Connection.DataSource)), SingleRowTempTableName + ".dbf");

            if (!File.Exists(tempFile))
            {
                CommandText = "CREATE TABLE '" + tempFile + "' FREE (PK i)";
                ExecuteNonQuery();
                CommandText = "INSERT INTO '" + tempFile + "' VALUE(1)";
                ExecuteNonQuery();
            }

            CommandText = commandText.Replace(SingleRowTempTableRequiredToken, "'" + tempFile + "'");
        }
Exemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void InternalExecute()
        {
            var command      = GetSqlCommand();
            var commandTexts = CommandText.Split(Separator, StringSplitOptions.RemoveEmptyEntries);

            foreach (var commandText in commandTexts)
            {
                if (string.IsNullOrEmpty(commandText))
                {
                    continue;
                }

                command.CommandText = commandText;
                command.ExecuteNonQuery();
            }

            Transaction.Commit();
            command.Connection?.Close();
            command.Dispose();
        }
Exemplo n.º 17
0
        /// <summary>
        ///  将表达式转换为数据库的 in/not in 数组操作
        /// </summary>
        /// <param name="exp"></param>
        /// <param name="method"></param>
        protected void In_Not_Parameter(Expression exp, string method)
        {
            var           f      = Expression.Lambda(exp).Compile();
            ICollection   _value = (ICollection)f.DynamicInvoke();
            List <string> keys   = new List <string>();
            IEnumerator   rator  = _value.GetEnumerator();

            while (rator.MoveNext())
            {
                string          p_key     = Guid.NewGuid().ToString("N");
                NpgsqlParameter parameter = new NpgsqlParameter(p_key, rator.Current);
                Parameters.Add(parameter);
                keys.Add("@" + p_key);
            }
            if (keys.Count == 0)
            {
                throw new ArgumentNullException($"{method} 查询必须提供参数,{exp}");
            }
            CommandText.Append($" {method} ({string.Join(",", keys)})");
        }
Exemplo n.º 18
0
        public bool EndOfWhere(string replaceWith)
        {
            bool   flag  = false;
            string input = CommandText.ToString();
            Match  match = TrailingWhereAndOrRegex.Match(input);

            if (match.Success)
            {
                CommandText.Clear();
                CommandText.Append(input.Remove(input.Length - match.Groups["FullOperator"].Length, match.Groups["FullOperator"].Length));
                if (match.Groups["Operator"].Value.Equals("where", StringComparison.InvariantCultureIgnoreCase))
                {
                    CommandText.Append(match.Groups["LinePrefix"].Value);
                }
                CommandText.Append(replaceWith);
                CommandText.Append(match.Groups["LineSuffix"].Value);
                flag = true;
            }
            return(flag);
        }
Exemplo n.º 19
0
        private void UpdateToolbarState()
        {
            var status = new CommandStatus();
            var text   = new CommandText();

            foreach (ToolStripItem item in form.ToolBar.Items)
            {
                var cmd = item.Tag as MenuCommand;
                if (cmd != null)
                {
                    text.Text = null;
                    var st = QueryStatus(cmd.CommandID, status, text);
                    item.Enabled = st && (status.Status & MenuStatus.Enabled) != 0;
                    if (!string.IsNullOrEmpty(text.Text))
                    {
                        item.Text = text.Text;
                    }
                }
            }
        }
Exemplo n.º 20
0
 private void PlayPauseCommandAction()
 {
     if (CommandText.Equals(PLAY_COMMAND))
     {
         if (_stopped)
         {
             _stopped = false;
             _audioPlayerService.PlayFromFile("Galway.mp3");
         }
         else
         {
             _audioPlayerService.Play();
         }
         CommandText = PAUSE_COMMAND;
     }
     else
     {
         _audioPlayerService.Pause();
         CommandText = PLAY_COMMAND;
     }
 }
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            /*
             * SchemaManager (and why here) explained:
             *
             * From what I can tell, the EF designer is only able to get schema information from querying data using the connection.  This seemed to be
             * a problem because I couldn't figure a way to get all the required information from a DBC... plus, I really didn't want to require a DBC to use this
             * EF Provider.  What I figured I could do instead was hook into the query process and use a combination of techniques to get the schema information
             * and write it to a temp table.  Then rewrite the command text to include the temp table.
             *
             * The part of the query that needs to be rewritten comes from the DefiningQuery in StoreSchemaDefinition.ssdl.  The DefiningQuery will have a token
             * that identifies the requested schema information.
             *
             * This was the only place that I found where I had an instance of the connection and the command...
             *
             */
            if (SchemaManager.IsSchemaQuery(this.CommandText))
            {
                DataTable dataTable = null;

                SchemaManager.Using(Connection.ConnectionString, (schemaManager) => dataTable = schemaManager.CreateDataTable(CommandText, Parameters));

                return(dataTable.CreateDataReader());
            }

            var hasExecuteScalar = CommandText.Contains(ExecuteScalarBeginDelimiter);

            HandleTempTable();
            SplitMultipleCommands();
            HandleExecuteScalar();

            var reader = (VfpClient.VfpDataReader)base.ExecuteDbDataReader(behavior);

            if (hasExecuteScalar)
            {
                return(new VfpAutoIncDataReader(reader, CommandText));
            }

            return(reader);
        }
Exemplo n.º 22
0
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            IDataReader reader;

            if (CommandText.StartsWith("insert", true, CultureInfo.InvariantCulture))
            {
                return(null);
            }

            if (DbTransaction == null)
            {
                reader = this.dataAction.ExecuteDataReaderParametrized(
                    CommandText, CommandType, this.parameters, behavior);
            }
            else
            {
                reader = this.dataAction.ExecuteDataReaderParametrized(
                    CommandText, CommandType, this.parameters, behavior, this.transaction.TransactionName);
            }

            return(new AptifyDataReader(reader));
        }
Exemplo n.º 23
0
        public void CreateFile(string path, string name)
        {
            path = "D:\\Users\\Sven\\Desktop\\";
            name = "install.bat";

            string filepath = path + name;

            if (!File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            // Create a file to write to.
            using (StreamWriter sw = File.CreateText(filepath))
            {
                CommandText title = new CommandText("sdfajlk");
                title.Text = "Hello";

                sw.WriteLine("@echo off");
                sw.WriteLine(title.Titel());
                sw.WriteLine("pause");
            }
        }
Exemplo n.º 24
0
        private DbCommand GetDbCommand(DbUtility actualData)
        {
            DbCommand cmd = actualData.CreateDbCommand();

            if (cmd != null)
            {
                cmd.CommandText    = CommandText.Trim();
                cmd.CommandTimeout = TimeOut;
                cmd.CommandType    = (CommandType)Enum.Parse(typeof(CommandType), CommandType.ToString());

                if (Parameters != null && Parameters.Param != null && Parameters.Param.Length > 0)
                {
                    foreach (DataOperationsDataCommandParametersParam param in Parameters.Param)
                    {
                        cmd.Parameters.Add(param.GetDbParameter(cmd));
                    }
                }

                return(cmd);
            }
            return(null);
        }
Exemplo n.º 25
0
        private int ExecuteNonQuery(bool freeHandle)
        {
            int records = 0;

            if (Connection == null)
            {
                throw new InvalidOperationException("No open connection");
            }
            if (Connection.State == ConnectionState.Closed)
            {
                throw new InvalidOperationException("Connection state is closed");
            }
            // FIXME: a third check is mentioned in .NET docs

            ExecSQL(CommandText);

            // .NET documentation says that except for INSERT, UPDATE and
            // DELETE  where the return value is the number of rows affected
            // for the rest of the commands the return value is -1.
            if ((CommandText.ToUpper().IndexOf("UPDATE") != -1) ||
                (CommandText.ToUpper().IndexOf("INSERT") != -1) ||
                (CommandText.ToUpper().IndexOf("DELETE") != -1))
            {
                int        numrows = 0;
                OdbcReturn ret     = libodbc.SQLRowCount(hstmt, ref numrows);
                records = numrows;
            }
            else
            {
                records = -1;
            }

            if (freeHandle && !prepared)
            {
                FreeStatement();
            }

            return(records);
        }
Exemplo n.º 26
0
        public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
        {
            if (Control.MemoryView.Focused)
            {
                if (cmdId.Guid == CmdSets.GuidReko)
                {
                    switch (cmdId.ID)
                    {
                    case CmdIds.ViewGoToAddress:
                    case CmdIds.ActionMarkType:
                    case CmdIds.ViewFindWhatPointsHere:
                    case CmdIds.ActionMarkProcedure:
                        status.Status = MenuStatus.Visible | MenuStatus.Enabled; return(true);

                    case CmdIds.EditCopy:
                    case CmdIds.ViewFindPattern:
                        status.Status = ValidSelection()
                            ? MenuStatus.Visible | MenuStatus.Enabled
                            : MenuStatus.Visible;
                        return(true);
                    }
                }
            }
            else if (Control.DisassemblyView.Focused)
            {
                var selAddress = Control.DisassemblyView.SelectedObject as Address;
                if (cmdId.Guid == CmdSets.GuidReko)
                {
                    switch (cmdId.ID)
                    {
                    case CmdIds.OpenLink:
                    case CmdIds.OpenLinkInNewWindow:
                        status.Status = selAddress != null ? MenuStatus.Visible | MenuStatus.Enabled : 0;
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 27
0
        void ValidateParameters(IEnumerable <DbParameter> parameters)
        {
            const string errmsg = "Issue found with parameter `{0}` on object `{1}`:{2}{2}{3}";

            foreach (var p in parameters)
            {
                var n = p.ParameterName;

                Debug.Assert(n.Length >= 2,
                             string.Format(errmsg, p, this, Environment.NewLine,
                                           "Parameters should always be 2 or more characters (one for the prefix, one or more for the name)."));

                Debug.Assert(n[0] == ParameterPrefixChar,
                             string.Format(errmsg, p, this, Environment.NewLine, "Parameters should begin with the ParameterPrefix."));

                Debug.Assert(n[1] != ParameterPrefixChar,
                             string.Format(errmsg, p, this, Environment.NewLine, "The second character should not be the ParameterPrefix."));

                Debug.Assert(CommandText.Contains(p.ParameterName),
                             string.Format(errmsg, p, this, Environment.NewLine, "The parameter could not be found in the CommandText..."));
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// 根据传入的值,创建一个 NpgsqlParameter 对象,并装入属性 Parameters 中
 /// </summary>
 /// <param name="val">参数的值</param>
 /// <param name="type">运算符类型</param>
 /// <param name="specificType">数据库指定列的类型</param>
 protected void SetValue(object val, ExpressionType type)
 {
     if (val == null)
     {
         CommandText.Remove(CommandText.Length - 3, 3);
         if (type == ExpressionType.Equal)
         {
             CommandText.Append(" IS NULL");
         }
         else if (type == ExpressionType.NotEqual)
         {
             CommandText.Append(" IS NOT NULL");
         }
     }
     else
     {
         string          p_key     = Guid.NewGuid().ToString("N");
         NpgsqlParameter parameter = new NpgsqlParameter(p_key, val);
         Parameters.Add(parameter);
         CommandText.Append($"@{p_key}");
     }
 }
Exemplo n.º 29
0
 private void CommandText_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == 13)
     {
         if (CommandText.Text.IndexOf("tail") > -1)
         {
             this.Text = IP.Text + " - LogAnalysis - [" + CommandText.Text + "]";
         }
         else
         {
             //this.Text = IP.Text + " - LogAnalysis ";
         }
         byte[] sb = System.Text.Encoding.Default.GetBytes(CommandText.Text + " \n");
         reader._pf.Transmit(sb);
         addComboBoxList((ComboBox)sender, CommandText.Text);
         CommandText.SelectAll();
     }
     if (e.KeyChar.Equals(Convert.ToChar(Keys.Cancel)))
     {
         this.Text = IP.Text + " - LogAnalysis ";
         reader._pf.Transmit(new byte[] { Convert.ToByte(Keys.Cancel) });
     }
 }
Exemplo n.º 30
0
        private int ExecuteScalarOrNonQuery()
        {
            using var unmanagedString = CommandText.ToUnmanagedString();

            var result = PlatformIndependentBindings.NativeMethods.DuckDBQuery(connection.NativeConnection, unmanagedString, out var queryResult);

            if (!string.IsNullOrEmpty(queryResult.ErrorMessage))
            {
                throw new DuckDBException(queryResult.ErrorMessage, result);
            }

            if (!result.IsSuccess())
            {
                throw new DuckDBException("DuckDBQuery failed", result);
            }

            if (queryResult.ColumnCount > 0 && queryResult.RowCount > 0)
            {
                return(PlatformIndependentBindings.NativeMethods.DuckDBValueInt32(queryResult, 0, 0));
            }

            return(0);
        }
Exemplo n.º 31
0
        public override bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
        {
            if (cmdId.Guid == CmdSets.GuidReko)
            {
                switch (cmdId.ID)
                {
                case CmdIds.ViewGoToAddress:
                case CmdIds.ViewShowAllFragments:
                case CmdIds.ViewShowUnscanned:
                case CmdIds.ActionMarkProcedure:
                case CmdIds.ActionRestartDecompilation:
                    status.Status = 0;
                    return(true);

                case CmdIds.ActionNextPhase:
                    status.Status = CanAdvance
                        ? MenuStatus.Visible | MenuStatus.Enabled
                        : MenuStatus.Visible;
                    text.Text = Resources.ScanBinaries;
                    return(true);
                }
            }
            return(base.QueryStatus(cmdId, status, text));
        }
Exemplo n.º 32
0
        internal async Task <DbDataReader> ExecuteReaderAsync(CommandBehavior behavior, IOBehavior ioBehavior,
                                                              CancellationToken cancellationToken)
        {
            // MyCAT: Split statements
            var statements = CommandText.Split(';');

            if (statements.Count() <= 1)
            {
                return(await m_commandExecutor.ExecuteReaderAsync(CommandText, m_parameterCollection, behavior, ioBehavior, cancellationToken).ConfigureAwait(false));
            }
            else
            {
                for (var i = 0; i < statements.Count(); i++)
                {
                    var reader = await m_commandExecutor.ExecuteReaderAsync(statements[i], m_parameterCollection, behavior, ioBehavior, cancellationToken).ConfigureAwait(false);

                    if (i == statements.Count() - 1)
                    {
                        return(reader);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 33
0
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     return false;
 }
Exemplo n.º 34
0
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (Control.MemoryView.Focused)
     {
         if (cmdId.Guid == CmdSets.GuidReko)
         {
             switch (cmdId.ID)
             {
             case CmdIds.ViewGoToAddress:
             case CmdIds.ActionMarkType:
             case CmdIds.ViewFindWhatPointsHere:
             case CmdIds.ActionMarkProcedure:
             case CmdIds.TextEncodingChoose:
                 status.Status = MenuStatus.Visible | MenuStatus.Enabled; return true;
             case CmdIds.EditCopy:
             case CmdIds.ViewFindPattern:
                 status.Status = ValidSelection()
                     ? MenuStatus.Visible | MenuStatus.Enabled
                     : MenuStatus.Visible;
                 return true;
             }
         }
     }
     else if (Control.DisassemblyView.Focused)
     {
         var selAddress = Control.DisassemblyView.SelectedObject as Address;
         var instr = Control.DisassemblyView.SelectedObject as MachineInstruction;
         if (cmdId.Guid == CmdSets.GuidReko)
         {
             switch (cmdId.ID)
             {
             case CmdIds.EditCopy:
                 status.Status = ValidDisassemblerSelection()
                     ? MenuStatus.Visible | MenuStatus.Enabled
                     : MenuStatus.Visible;
                 return true;
             case CmdIds.OpenLink:
             case CmdIds.OpenLinkInNewWindow:
                 status.Status = selAddress != null ? MenuStatus.Visible | MenuStatus.Enabled : 0;
                 return true;
             case CmdIds.EditAnnotation:
                 status.Status = instr != null ? MenuStatus.Visible | MenuStatus.Enabled : 0;
                 return true;
             case CmdIds.ActionCallTerminates:
                 if (instr != null)
                 {
                     if ((instr.InstructionClass &  InstructionClass.Call) != 0)
                     {
                         status.Status = MenuStatus.Visible | MenuStatus.Enabled;
                     }
                     else
                     {
                         status.Status = MenuStatus.Visible;
                     }
                 }
                 else
                 {
                     status.Status = 0;
                 }
                 return true;
             case CmdIds.TextEncodingChoose:
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 35
0
        internal string GetCommandTextForBatching()
        {
            if (BatchableCommandText == null)
            {
                // if the command starts with insert and is "simple" enough, then
                // we can use the multi-value form of insert
                if (String.Compare(CommandText.Substring(0, 6), "INSERT", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    MySqlCommand   cmd       = new MySqlCommand("SELECT @@sql_mode", Connection);
                    string         sql_mode  = StringUtility.ToUpperInvariant(cmd.ExecuteScalar().ToString());
                    MySqlTokenizer tokenizer = new MySqlTokenizer(CommandText);
                    tokenizer.AnsiQuotes       = sql_mode.IndexOf("ANSI_QUOTES") != -1;
                    tokenizer.BackslashEscapes = sql_mode.IndexOf("NO_BACKSLASH_ESCAPES") == -1;
                    string token = StringUtility.ToLowerInvariant(tokenizer.NextToken());
                    while (token != null)
                    {
                        if (StringUtility.ToUpperInvariant(token) == "VALUES" &&
                            !tokenizer.Quoted)
                        {
                            token = tokenizer.NextToken();
                            Debug.Assert(token == "(");

                            // find matching right paren, and ensure that parens
                            // are balanced.
                            int openParenCount = 1;
                            while (token != null)
                            {
                                BatchableCommandText += token;
                                token = tokenizer.NextToken();

                                if (token == "(")
                                {
                                    openParenCount++;
                                }
                                else if (token == ")")
                                {
                                    openParenCount--;
                                }

                                if (openParenCount == 0)
                                {
                                    break;
                                }
                            }

                            if (token != null)
                            {
                                BatchableCommandText += token;
                            }
                            token = tokenizer.NextToken();
                            if (token != null && (token == "," ||
                                                  StringUtility.ToUpperInvariant(token) == "ON"))
                            {
                                BatchableCommandText = null;
                                break;
                            }
                        }
                        token = tokenizer.NextToken();
                    }
                }
                // Otherwise use the command verbatim
                else
                {
                    BatchableCommandText = CommandText;
                }
            }

            return(BatchableCommandText);
        }
Exemplo n.º 36
0
        public bool QueryStatus(CommandID cmdId, CommandStatus cmdStatus, CommandText cmdText)
        {
            var ct = GetSubCommandTarget();

            if (ct != null && ct.QueryStatus(cmdId, cmdStatus, cmdText))
            {
                return(true);
            }

            if (currentPhase != null && currentPhase.QueryStatus(cmdId, cmdStatus, cmdText))
            {
                return(true);
            }
            if (cmdId.Guid == CmdSets.GuidReko)
            {
                if (QueryMruItem(cmdId.ID, cmdStatus, cmdText))
                {
                    return(true);
                }

                switch (cmdId.ID)
                {
                case CmdIds.FileOpen:
                case CmdIds.FileExit:
                case CmdIds.FileOpenAs:
                case CmdIds.FileAssemble:
                case CmdIds.ViewProjectBrowser:
                case CmdIds.ViewProcedureList:
                case CmdIds.ToolsOptions:
                case CmdIds.WindowsCascade:
                case CmdIds.WindowsTileVertical:
                case CmdIds.WindowsTileHorizontal:
                case CmdIds.WindowsCloseAll:
                case CmdIds.HelpAbout:
                    cmdStatus.Status = MenuStatus.Enabled | MenuStatus.Visible;
                    return(true);

                //$TODO: finish implementing this :)
                case CmdIds.ToolsKeyBindings:
                    cmdStatus.Status = MenuStatus.Visible;
                    return(true);

                case CmdIds.FileMru:
                    cmdStatus.Status = MenuStatus.Visible;
                    return(true);

                case CmdIds.ActionRestartDecompilation:
                    cmdStatus.Status = MenuStatus.Enabled | MenuStatus.Visible;
                    break;

                case CmdIds.ActionNextPhase:
                    cmdStatus.Status = currentPhase.CanAdvance
                        ? MenuStatus.Enabled | MenuStatus.Visible
                        : MenuStatus.Visible;
                    return(true);

                case CmdIds.FileAddBinary:
                case CmdIds.FileAddMetadata:
                case CmdIds.FileSave:
                case CmdIds.FileCloseProject:
                case CmdIds.EditFind:
                case CmdIds.ViewCallGraph:
                case CmdIds.ViewFindAllProcedures:
                case CmdIds.ViewFindStrings:
                    cmdStatus.Status = IsDecompilerLoaded
                        ? MenuStatus.Enabled | MenuStatus.Visible
                        : MenuStatus.Visible;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 37
0
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (cmdId.Guid == CmdSets.GuidReko)
     {
         if (!ShowAllItems())
         {
             switch (cmdId.ID)
             {
             case CmdIds.EditDeclaration:
             case CmdIds.ViewCfgGraph:
                 status.Status = MenuStatus.Visible;
                 return true;
             }
         }
         switch (cmdId.ID)
         {
         case CmdIds.TextEncodingChoose:
             status.Status = MenuStatus.Enabled | MenuStatus.Visible;
             return true;
         case CmdIds.EditCopy:
             status.Status = FocusedTextView == null || FocusedTextView.Selection.IsEmpty
                 ? MenuStatus.Visible
                 : MenuStatus.Visible | MenuStatus.Enabled;
             return true;
         case CmdIds.ViewCfgGraph:
             status.Status = gViewer.Visible
                 ? MenuStatus.Visible | MenuStatus.Enabled | MenuStatus.Checked
                 : MenuStatus.Visible | MenuStatus.Enabled;
             return true;
         case CmdIds.ViewCfgCode:
             status.Status = gViewer.Visible
                 ? MenuStatus.Visible | MenuStatus.Enabled
                 : MenuStatus.Visible | MenuStatus.Enabled | MenuStatus.Checked;
             return true;
         case CmdIds.EditDeclaration:
             status.Status = GetAnchorAddress() == null 
                 ? MenuStatus.Visible
                 : MenuStatus.Enabled | MenuStatus.Visible;
             return true;
         }
     }
     return false;
 }
Exemplo n.º 38
0
 private void UpdateToolbarState()
 {
     var status = new CommandStatus();
     var text = new CommandText();
     foreach (ToolStripItem item in form.ToolBar.Items)
     {
         var cmd = item.Tag as MenuCommand;
         if (cmd != null)
         {
             text.Text = null;
             var st = QueryStatus(cmd.CommandID, status, text);
             item.Enabled = (status.Status & MenuStatus.Enabled) != 0;
             if (!string.IsNullOrEmpty(text.Text))
                 item.Text = text.Text;
         }
     }
 }
Exemplo n.º 39
0
 public override bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (cmdId.Guid == CmdSets.GuidReko)
     {
         MenuCommand cmd;
         if (!mpCmdidToCommand.TryGetValue(cmdId.ID, out cmd))
             return false;
         status.Status = (MenuStatus) cmd.OleStatus;
         return true;
     }
     return false;
 }
Exemplo n.º 40
0
 /// <summary>
 /// Forward the query to the active IWindowPane -- if it in turn supports ICommandTarget.
 /// </summary>
 /// <param name="cmdSet"></param>
 /// <param name="cmdId"></param>
 /// <param name="status"></param>
 /// <param name="text"></param>
 /// <returns></returns>
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     ICommandTarget ct = ActiveCommandTarget();
     if (ct == null)
         return false;
     return ct.QueryStatus(cmdId, status, text);
 }
Exemplo n.º 41
0
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (cmdId.Guid == CmdSets.GuidReko)
     {
         switch (cmdId.ID)
         {
         case CmdIds.EditCopy:   //$TODO: once the TextViewer supports selections, these two
             status.Status = codeView.TextView.Selection.IsEmpty
                 ? MenuStatus.Visible
                 : MenuStatus.Visible | MenuStatus.Enabled;
             return true;
         }
     }
     return false;
 }
Exemplo n.º 42
0
        public bool QueryStatus(CommandID cmdId, CommandStatus cmdStatus, CommandText cmdText)
        {
            var ct = GetSubCommandTarget();
            if (ct != null && ct.QueryStatus(cmdId, cmdStatus, cmdText))
                return true;

            if (currentPhase != null && currentPhase.QueryStatus(cmdId, cmdStatus, cmdText))
                return true;
            if (cmdId.Guid == CmdSets.GuidReko)
            {
                if (QueryMruItem(cmdId.ID, cmdStatus, cmdText))
                    return true;

                switch (cmdId.ID)
                {
                case CmdIds.FileOpen:
                case CmdIds.FileExit:
                case CmdIds.FileOpenAs:
                case CmdIds.FileAssemble:
                case CmdIds.ToolsOptions:
                case CmdIds.WindowsCascade:
                case CmdIds.WindowsTileVertical:
                case CmdIds.WindowsTileHorizontal:
                case CmdIds.WindowsCloseAll:
                case CmdIds.HelpAbout:
                    cmdStatus.Status = MenuStatus.Enabled | MenuStatus.Visible;
                    return true;
                case CmdIds.FileMru:
                    cmdStatus.Status = MenuStatus.Visible;
                    return true;
                case CmdIds.ActionRestartDecompilation:
                    cmdStatus.Status = MenuStatus.Enabled | MenuStatus.Visible;
                    break;
                case CmdIds.ActionNextPhase:
                    cmdStatus.Status = currentPhase.CanAdvance
                        ? MenuStatus.Enabled | MenuStatus.Visible
                        : MenuStatus.Visible;
                    return true;
                case CmdIds.FileAddBinary:
                case CmdIds.FileAddMetadata:
                case CmdIds.FileSave:
                case CmdIds.FileCloseProject:
                case CmdIds.EditFind:
                case CmdIds.ViewFindAllProcedures:
                case CmdIds.ViewFindStrings:
                    cmdStatus.Status = IsDecompilerLoaded
                        ? MenuStatus.Enabled | MenuStatus.Visible
                        : MenuStatus.Visible;
                    return true;
                }
            }
            return false;
        }
Exemplo n.º 43
0
 private bool QueryMruItem(int cmdId, CommandStatus cmdStatus, CommandText cmdText)
 {
     int iMru = cmdId - CmdIds.FileMru;
     if (0 <= iMru && iMru < mru.Items.Count)
     {
         cmdStatus.Status = MenuStatus.Visible | MenuStatus.Enabled;
         cmdText.Text = string.Format("&{0} {1}", iMru+1, mru.Items[iMru]);
         return true;
     }
     return false;
 }
Exemplo n.º 44
0
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (result == null)
         return false;
     return result.QueryStatus(cmdId, status, text);
 }
Exemplo n.º 45
0
 public override bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (cmdId.Guid == CmdSets.GuidReko)
     {
         switch (cmdId.ID)
         {
         case CmdIds.ActionFinishDecompilation:
         case CmdIds.ActionRestartDecompilation:
             status.Status = MenuStatus.Visible | MenuStatus.Enabled;
             return true;
         case CmdIds.ActionNextPhase:
             status.Status = MenuStatus.Visible | MenuStatus.Enabled;
             text.Text = Resources.AnalyzeDataflow;
             return true;
         default:
             MenuCommand cmd;
             if (!mpCmdidToCommand.TryGetValue(cmdId.ID, out cmd))
                 return false;
             status.Status = (MenuStatus)cmd.OleStatus;
             return true;
         }
     }
     return false;
 }
Exemplo n.º 46
0
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (cmdId.Guid == CmdSets.GuidDecompiler)
     {
         switch (cmdId.ID)
         {
         case CmdIds.EditCopy:   //$TODO: once the TextViewer supports selections, these two 
                                 // verbs will need to differ.
         case CmdIds.EditCopyAll:
             status.Status = MenuStatus.Enabled | MenuStatus.Visible;
             return true;
         }
     }
     return false;
 }
Exemplo n.º 47
0
 public bool QueryStatus(CommandID cmdId, CommandStatus status, CommandText text)
 {
     if (Control.MemoryView.Focused)
     {
         if (cmdId.Guid == CmdSets.GuidReko)
         {
             switch (cmdId.ID)
             {
             case CmdIds.ViewGoToAddress:
             case CmdIds.ActionMarkType:
             case CmdIds.ViewFindWhatPointsHere:
             case CmdIds.ActionMarkProcedure:
                 status.Status = MenuStatus.Visible | MenuStatus.Enabled; return true;
             case CmdIds.EditCopy:
             case CmdIds.ViewFindPattern:
                 status.Status = ValidSelection()
                     ? MenuStatus.Visible | MenuStatus.Enabled
                     : MenuStatus.Visible;
                 return true;
             }
         }
     }
     else if (Control.DisassemblyView.Focused)
     {
         var selAddress = Control.DisassemblyView.SelectedObject as Address;
         if (cmdId.Guid == CmdSets.GuidReko)
         {
             switch (cmdId.ID)
             {
             case CmdIds.OpenLink:
             case CmdIds.OpenLinkInNewWindow:
                 status.Status = selAddress != null ? MenuStatus.Visible | MenuStatus.Enabled : 0;
                 return true;
             }
         }
     }
     return false;
 }