Ejemplo n.º 1
0
        public Dictionary <string, object>[] UnsafeSqlQuery(DbTransaction transaction, string sql, TDbParameter[] parameters = null)
        {
            var ret = new List <Dictionary <string, object> >();

            using var command = new TDbCommand
                  {
                      Transaction = transaction,
                      CommandText = sql,
                      Connection  = Connection,
                  };
            if (parameters != null)
            {
                command.Parameters.AddRange(parameters);
            }

            using var reader = command.ExecuteReader();
            while (reader.Read())
            {
                var dict = new Dictionary <string, object>();
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    var fieldName = reader.GetName(i);
                    dict[fieldName] = reader.GetValue(i);
                }
                ret.Add(dict);
            }
            reader.Close();
            OnExecuted?.Invoke(command);

            return(ret.ToArray());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Execute the given <code>qasmExe.code</code> launching <code>qasmExe.shots</code> executions.
 /// When the result is ready, the <code>onExecuted</code> callback will be called.
 /// The <see cref="OnExecuted"/> will recieve <see cref="QASMExecutionResult"/>
 /// with the accumulated result.
 /// </summary>
 /// <param name="qasmExe">Executable configuration</param>
 /// <param name="onExecuted">The callback called when execution ends</param>
 public void ExecuteCode(QASMExecutable qasmExe, OnExecuted onExecuted)
 {
     // Request is not needed yet, see "ExecuteCodeRawResult" implementation in case of future changes
     GenericExecution(qasmExe, useMemory: false, (jsonResult) => {
         onExecuted(ReadCountJSON(jsonResult));
     });
 }
Ejemplo n.º 3
0
        public CommandData Execute(string[] tokens, IOutput output)
        {
            if (!ParameterValues.Parse(Parameters, tokens, out ParameterValues values))
            {
                return(null);
            }

            CommandData data = new CommandData(values, output);

            OnExecuted?.Invoke(data);

            return(data.DisplayHelp ? null : data);
        }
Ejemplo n.º 4
0
        private T ExecuteWarp <T>(Func <IDbCommand, T> excute, IDbConnectionSession dbSession, RequestContext context)
        {
            var dbCommand = _preparedCommand.Prepare(dbSession, context);

            dbSession.OpenConnection();
            T result = excute(dbCommand);

            OnExecuted?.Invoke(this, new OnExecutedEventArgs
            {
                DbSession      = dbSession,
                RequestContext = context
            });
            return(result);
        }
Ejemplo n.º 5
0
        private async Task <T> ExecuteWarpAsync <T>(Func <DbCommand, Task <T> > excute, IDbConnectionSession dbSession, RequestContext context)
        {
            var dbCommand = _preparedCommand.Prepare(dbSession, context);
            await dbSession.OpenConnectionAsync();

            var dbCommandAsync = dbCommand as DbCommand;
            T   result         = await excute(dbCommandAsync);

            OnExecuted?.Invoke(this, new OnExecutedEventArgs
            {
                DbSession      = dbSession,
                RequestContext = context
            });
            return(result);
        }
Ejemplo n.º 6
0
        public TEntity[] UnsafeSqlQuery <TEntity>(DbTransaction transaction, string sql, TDbParameter[] parameters = null)
            where TEntity : class, new()
        {
            var ret = new List <TEntity>();

            using var command = new TDbCommand
                  {
                      Transaction = transaction,
                      CommandText = sql,
                      Connection  = Connection,
                  };
            if (parameters != null)
            {
                command.Parameters.AddRange(parameters);
            }

            var columns = Common.EntityPropertiesCache[typeof(TEntity)].Value;

            using var reader = command.ExecuteReader();
            while (reader.Read())
            {
                var entity = new TEntity();
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    var fieldName = reader.GetName(i);
                    var column    = columns.FirstOrDefault(x => string.Equals(x.ColumnName, fieldName, StringComparison.InvariantCultureIgnoreCase));

                    if (column != null)
                    {
                        var ovalue = reader.GetValue(i);
                        var value  = ovalue is DBNull ? null : ConvertEx.ChangeType(ovalue, column.Property.PropertyType);
                        try
                        {
                            column.Property.SetValue(entity, value);
                        }
                        catch (Exception ex)
                        {
                            throw new ArgumentException($"Can not set value for field({fieldName}).", ex);
                        }
                    }
                }
                ret.Add(entity);
            }
            reader.Close();
            OnExecuted?.Invoke(command);

            return(ret.ToArray());
        }
Ejemplo n.º 7
0
        internal override Ret InsertGet <DT, Ret>(DT data, string tableName, params string[] excludeColNames)
        {
            DbConnection conn = null;
            DbCommand    cmd  = null;

            try
            {
                var kv = InsertScript(data, tableName, excludeColNames);

                conn = CreateConn();
                cmd  = BuildCommandByParam(conn, kv.Key, kv.Value, 30);

                var result1 = cmd.ExecuteNonQuery();

                if (OnExecuted != null)
                {
                    OnExecuted.Invoke(cmd, result1);
                }

                OracleDBInfo OraInfo = Info as OracleDBInfo;

                string identitySql = Script.IdentitySql(DBType, tableName, OraInfo.IdentitySeqName(tableName));

                cmd.CommandText = identitySql;
                cmd.Parameters.Clear();

                var result2 = cmd.ExecuteScalar().ChangeType <Ret>();

                if (OnExecuted != null)
                {
                    OnExecuted.Invoke(cmd, result2);
                }

                return(result2);
            }
            catch (Exception ex)
            {
                if (this.OnError != null)
                {
                    this.OnError.Invoke(cmd, ex);
                }
                throw ex;
            }
            finally
            {
                conn?.Close();
            }
        }
 protected void ExecuteCore()
 {
     OnExecuting?.Invoke();
     try
     {
         HandleExecuteCore();
     }
     catch (Exception ex)
     {
         OnExecutionError?.Invoke(ex);
         throw;
     }
     finally
     {
         OnExecuted?.Invoke();
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Execute the given <code>qasmExe.code</code> launching <code>qasmExe.shots</code> executions.
 /// When the result is ready, the <code>onExecuted</code> callback will be called.
 /// The <see cref="OnExecuted"/> will recieve <see cref="QASMExecutionResult"/>
 /// with the per shot results as rawResult.
 /// If the backends does not supports memory feature, the raw result will be simulated with
 /// accumulated results.
 /// </summary>
 /// <param name="qasmExe">Executable configuration</param>
 /// <param name="onExecuted">The callback called when execution ends</param>
 public void ExecuteCodeRawResult(QASMExecutable qasmExe, OnExecuted onExecuted)
 {
     RequestBackendConfig((_) => {
         GenericExecution(qasmExe, useMemory: _backendConfig.supportsMemory, (jsonResult) => {
             if (_backendConfig.supportsMemory)
             {
                 onExecuted(ReadRawDataJSON(jsonResult));
             }
             else
             {
                 QASMExecutionResult result = ReadCountJSON(jsonResult);
                 result.SimulateRawResult();
                 onExecuted(result);
             }
         });
     });
 }
Ejemplo n.º 10
0
        public int UnsafeSql(DbTransaction transaction, string sql, TDbParameter[] parameters = null)
        {
            using var command = new TDbCommand
                  {
                      Transaction = transaction,
                      CommandText = sql,
                      Connection  = Connection,
                  };
            if (parameters != null)
            {
                command.Parameters.AddRange(parameters);
            }

            var ret = command.ExecuteNonQuery();

            OnExecuted?.Invoke(command);
            return(ret);
        }
Ejemplo n.º 11
0
        protected override void OnExecute(string Entity)
        {
            var Code = false;

            var OldSizeText = ConfigHelper.GetValue($"{Entity}_Size");

            if (string.IsNullOrWhiteSpace(OldSizeText))
            {
                Code = true;
            }

            if (!long.TryParse(OldSizeText, out long OldSize))
            {
                Code = true;
            }

            var NewSize = PathHelper.GetFileSize(Entity);

            if (OldSize != NewSize)
            {
                ConfigHelper.SetValue($"{Entity}_Size", NewSize.ToString());
                Code = true;
            }

            var OldMd5 = ConfigHelper.GetValue($"{Entity}_MD5");

            if (string.IsNullOrWhiteSpace(OldMd5))
            {
                Code = true;
            }

            var NewMd5 = PathHelper.FileMD5(Entity);

            if (OldMd5 != NewMd5)
            {
                ConfigHelper.SetValue($"{Entity}_MD5", NewMd5);
                Code = true;
            }

            OnExecuted?.Invoke(Entity, Code);
        }
Ejemplo n.º 12
0
        internal override Ret InsertGet <DT, Ret>(DT data, string tableName, params string[] excludeColNames)
        {
            DbConnection conn = null;
            DbCommand    cmd  = null;

            try
            {
                var kv = InsertScript(data, tableName, excludeColNames);

                conn = CreateConn();
                cmd  = BuildCommandByParam(conn, kv.Key, kv.Value, 30);

                PostgreSqlDBInfo postgreInfo = Info as PostgreSqlDBInfo;

                cmd.CommandText = kv.Key + ";" + Script.IdentitySql(DBType, tableName, null, postgreInfo.IdentityColumnName(tableName));

                var result2 = cmd.ExecuteScalar().ChangeType <Ret>();

                if (OnExecuted != null)
                {
                    OnExecuted.Invoke(cmd, result2);
                }

                return(result2);
            }
            catch (Exception ex)
            {
                if (this.OnError != null)
                {
                    this.OnError.Invoke(cmd, ex);
                }
                throw ex;
            }
            finally
            {
                conn?.Close();
            }
        }
Ejemplo n.º 13
0
 public void Rollback()
 {
     OnPreviewExecuted?.Invoke();
     Setter.Invoke(PrevProperty);
     OnExecuted?.Invoke();
 }
Ejemplo n.º 14
0
 public void RollForward()
 {
     OnPreviewExecuted?.Invoke();
     Setter.Invoke(Property);
     OnExecuted?.Invoke();
 }
Ejemplo n.º 15
0
 public void Finished()
 {
     OnExecuted?.Invoke(currentObjectBeingMoved.gameObject);
 }
Ejemplo n.º 16
0
        public override KeyValuePair <DataTable, long> GetDataTableByPager(int currentPage, int pageSize, string selColumns, string joinTableName, string whereStr, string orderbyStr)
        {
            if (string.IsNullOrEmpty(selColumns))
            {
                selColumns = "*";
            }

            if (currentPage <= 0)
            {
                currentPage = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 50;
            }

            string    cntSQL = string.Empty, strPageSQL = string.Empty;
            DataTable data       = new DataTable();
            long      totalCount = 0;

            if (!string.IsNullOrWhiteSpace(whereStr))
            {
                whereStr = Regex.Replace(whereStr, @"(\s)*(where)?(\s)*(.+)", "where 1=1 and $3$4", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            }

            if (!string.IsNullOrWhiteSpace(orderbyStr))
            {
                orderbyStr = Regex.Replace(orderbyStr, @"(\s)*(order)(\s)+(by)(.+)", "$5", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            }
            else
            {
                throw new ArgumentNullException("orderbyStr");
            }

            cntSQL = "select count(1) from {0}  {1}";
            cntSQL = string.Format(cntSQL, joinTableName, whereStr);

            string strSQL = "select {0},ROW_NUMBER() OVER ( ORDER BY {3} ) RN from {1}  {2} ";

            strSQL = string.Format(strSQL, selColumns, joinTableName, whereStr, orderbyStr);

            strPageSQL = string.Format(@"SELECT * FROM ({0}) A WHERE   RN BETWEEN {1} AND {2}",
                                       strSQL, (currentPage - 1) * pageSize + 1, (currentPage) * pageSize);


            DataSet      ds   = new DataSet("ds");
            DbConnection conn = null;
            DbCommand    cmd  = null;

            try
            {
                conn = CreateConn();
                cmd  = BuildCommand(conn, strPageSQL, 300);
                DataAdapter adapter = CreateAdapter(cmd);
                adapter.Fill(ds);

                if (ds.Tables.Count > 0)
                {
                    data = ds.Tables[0];
                }

                cmd.CommandText = cntSQL;
                cmd.Parameters.Clear();

                totalCount = cmd.ExecuteScalar().ChangeType <long>();

                KeyValuePair <DataTable, long> res = new KeyValuePair <DataTable, long>(data, totalCount);
                if (OnExecuted != null)
                {
                    OnExecuted.Invoke(cmd, res);
                }
                return(res);
            }
            catch (Exception ex)
            {
                if (this.OnError != null)
                {
                    this.OnError.Invoke(cmd, ex);
                }
                throw ex;
            }
            finally
            {
                conn?.Close();
            }
        }
Ejemplo n.º 17
0
 protected void Execute(object args) => OnExecuted?.Invoke(args);
Ejemplo n.º 18
0
 public async void Execute(object parameter)
 {
     _transitLink(new HttpRequestMessage(HttpMethod.Get, new Uri(_url)));
     OnExecuted.Invoke();
 }
Ejemplo n.º 19
0
 public void RollForward()
 {
     OnPreviewExecuted?.Invoke();
     _rollForward.Invoke();
     OnExecuted?.Invoke();
 }
Ejemplo n.º 20
0
 public static void ExecuteRawResult(string qasmCode, OnExecuted onExecuted) => instance?.ExecuteCodeRawResult(qasmCode, onExecuted);
Ejemplo n.º 21
0
 public static void Execute(string qasmCode, OnExecuted onExecuted) => instance?.ExecuteCode(qasmCode, onExecuted);
 /// <summary>
 /// Executes the event
 /// </summary>
 /// <param name="context">The object that the menu was opened on</param>
 public override void Execute(object context)
 {
     OnExecuted.SafeInvoke(this, new GUIMenuItemEventArgs(this, context));
 }
Ejemplo n.º 23
0
        protected override void OnExecute(CopyFileItemEntity Entity)
        {
            var Code = PathHelper.CopyFile(Entity.InputFilePath, Entity.OutputFilePath);

            OnExecuted?.Invoke(Entity, Code);
        }
Ejemplo n.º 24
0
 public void Rollback()
 {
     OnPreviewExecuted?.Invoke();
     _rollBack.Invoke();
     OnExecuted?.Invoke();
 }
Ejemplo n.º 25
0
        protected override void OnExecute(CompressItemEntity Entity)
        {
            var Code = PngQuant.Compress(Entity.InputFilePath, Entity.OutputFilePath);

            OnExecuted?.Invoke(Entity, Code);
        }