Ejemplo n.º 1
0
        public LoggedException(string message, ExType level, Exception ex) : base(message, ex)
        {
            _log = new AppLogger();
            _ex  = ex;
            switch (level)
            {
            case ExType.Error:
                _log.LogError("MESSAGE: " + ex.Message + "\n *-*-*-*-*- \nSTACK TRACE: " + ex.StackTrace);
                break;

            case ExType.Fatal:
                _log.LogFatal("MESSAGE: " + ex.Message + "\n *-*-*-*-*- \nSTACK TRACE: " + ex.StackTrace);
                break;
            }
        }
Ejemplo n.º 2
0
 private static Type AsTExType(ExType ext)
 {
     if (ext == ExType.V2)
     {
         return(typeof(TExV2));
     }
     if (ext == ExType.V3)
     {
         return(typeof(TExV3));
     }
     if (ext == ExType.RV2)
     {
         return(typeof(TExRV2));
     }
     return(typeof(TEx <float>));
 }
Ejemplo n.º 3
0
 private static Type AsType(ExType ext)
 {
     if (ext == ExType.V2)
     {
         return(typeof(Vector2));
     }
     if (ext == ExType.V3)
     {
         return(typeof(Vector3));
     }
     if (ext == ExType.RV2)
     {
         return(typeof(V2RV2));
     }
     return(typeof(float));
 }
Ejemplo n.º 4
0
 private static Type AsWeakTExType(ExType ext)
 {
     if (ext == ExType.V2)
     {
         return(typeof(TEx <Vector2>));
     }
     if (ext == ExType.V3)
     {
         return(typeof(TEx <Vector3>));
     }
     if (ext == ExType.RV2)
     {
         return(typeof(TEx <V2RV2>));
     }
     return(typeof(TEx <float>));
 }
Ejemplo n.º 5
0
        public AppException(string message, string level, Exception ex) : base(message, ex)
        {
            _ex = ex;
            ExType type = (ExType)Enum.Parse(typeof(ExType), level);

            switch (type)
            {
            case ExType.Error:
                Logger.LogError("MESSAGE: " + ex.Message + "\n *-*-*-*-*- \nSTACK TRACE: " + ex.StackTrace);
                break;

            case ExType.Fatal:
                Logger.LogFatal("MESSAGE: " + ex.Message + "\n *-*-*-*-*- \nSTACK TRACE: " + ex.StackTrace);
                break;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Databases the execute.
        /// </summary>
        /// <typeparam name="T"> parameter type</typeparam>
        /// <param name="executeAction">The execute action.</param>
        /// <param name="type">The type.</param>
        /// <param name="async">if set to <c>true</c> [asynchronous].</param>
        /// <returns>Returns the entity</returns>
        protected T DbExecute <T>(Func <instahangoutsEntities, T> executeAction, ExType type = ExType.Get, bool async = false) where T : class
        {
            var result = executeAction(this.dbContext);

            if (type == ExType.Set)
            {
                if (async)
                {
                    this.dbContext.SaveChangesAsync();
                }
                else
                {
                    this.dbContext.SaveChanges();
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        //计算将要下单的价格
        public static decimal GetPrice(ExType type, string marketid, int count = 20)//20
        {
            var     depth      = exchange.GetOrderBook(marketid, count);
            var     bids       = depth.Bids.OrderByDescending(a => a.Value.Price);
            var     asks       = depth.Asks.OrderBy(a => a.Value.Price);
            decimal amountBids = 0;
            decimal amountAsks = 0;

            //计算买价,获取累计深度达到预设的价格
            if (type == ExType.Buy)
            {
                for (var i = 0; i < deep; i++)
                {
                    amountBids += bids.ElementAt(i).Value.Amount;
                    //floatamountbuy就是预设的累计买单深度
                    if (amountBids > floatamountbuy)
                    {
                        //稍微加0.01,使得订单排在前面
                        return(bids.ElementAt(i).Value.Price + 1.10m * floatPrice);
                    }
                }
            }
            //同理计算卖价
            if (type == ExType.Sell)
            {
                for (var j = 0; j < deep; j++)
                {
                    amountAsks += asks.ElementAt(j).Value.Amount;
                    if (amountAsks > floatamountsell)
                    {
                        return(asks.ElementAt(j).Value.Price - floatPrice);
                    }
                }
            }
            //遍历了全部深度仍未满足需求,就返回一个价格,以免出现bug
            return(asks.ElementAt(0).Value.Price);
        }
Ejemplo n.º 8
0
 public static FiringCtx.DataType AsFCtxType(this ExType t) => t switch
 {
Ejemplo n.º 9
0
 /// <summary>
 ///  Constructeur recevant le numéro d'erreur à déclancher
 ///  et une éventuelle exception remontée (pour relancer une exception sql non traitée,...).
 /// </summary>
 /// <param name="exType"></param>
 /// <param name="e"></param>
 public CstmEx(ExType exType, Exception e = null)
 {
     _exType = exType;
     _e      = e;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Instancie une exception Custom.
 /// (Remplace "throw New".
 /// </summary>
 /// <param name="exType"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public static CstmEx ThrowCstmEx(ExType exType, Exception e = null)
 {
     throw new CstmEx(exType, e);
 }
Ejemplo n.º 11
0
        private void OnConnectionBroken(Exception e, ExType exType)
        {
            switch (exType)
            {
            case ExType.Socket:
            case ExType.Connection:
                if (_forcedDisconnect)
                {
                    if (_logger.IsErrorLogsEnabled)
                    {
                        _logger.NCacheLog.Error("Connection.ReceivedThread",
                                                "Connection with server lost gracefully");
                    }
                }
                else if (_logger.IsErrorLogsEnabled)
                {
                    _logger.NCacheLog.Error("Connection.ReceivedThread",
                                            "An established connection with the server " + _serverAddress + " is lost. Error:" +
                                            e.ToString());
                }

                if (!_forcedDisconnect)
                {
                    _connectionStatusLatch.SetStatusBit(ConnectionStatus.Disconnected, ConnectionStatus.Connected);
                }
                _primaryReceiveThread = null;
                _serverLost(_serverAddress, _forcedDisconnect);
                break;

            case ExType.Interrupt:
            case ExType.Abort:
                if (AppDomain.CurrentDomain.IsFinalizingForUnload())
                {
                    return;
                }
                if (_forcedDisconnect)
                {
                    if (_logger.IsErrorLogsEnabled)
                    {
                        _logger.NCacheLog.Error("Connection.ReceivedThread",
                                                "Connection with server lost gracefully");
                        _logger.NCacheLog.Flush();
                    }
                }

                if (!_forcedDisconnect)
                {
                    _connectionStatusLatch.SetStatusBit(ConnectionStatus.Disconnected, ConnectionStatus.Connected);
                }
                _serverLost(_serverAddress, _forcedDisconnect);
                break;

            case ExType.General:
                if (_logger.IsErrorLogsEnabled)
                {
                    _logger.NCacheLog.Error("Connection.ReceivedThread", e.ToString());
                    _logger.NCacheLog.Flush();
                }

                if (!_forcedDisconnect)
                {
                    _connectionStatusLatch.SetStatusBit(ConnectionStatus.Disconnected, ConnectionStatus.Connected);
                }
                _serverLost(_serverAddress, _forcedDisconnect);
                break;
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Add Pre-Defined Experiment Type
 /// </summary>
 /// <param name="type"></param>
 public void AddExType(ExType type)
 {
     AddExType(type.ToString(), (int)type);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Init with custom experiment design parameters
        /// </summary>
        /// <param name="extype"></param>
        /// <param name="expara"></param>
        /// <param name="cond"></param>
        /// <param name="block"></param>
        /// <param name="trial"></param>
        /// <param name="stimuli"></param>
        /// <param name="brestT"></param>
        /// <param name="trestT"></param>
        /// <param name="srestT"></param>
        /// <param name="preT"></param>
        /// <param name="durT"></param>
        /// <param name="posT"></param>
        /// <param name="bgcolor"></param>
        /// <param name="length"></param>
        public SLExperiment(ExType[] extype, ExPara[] expara, SLInterpolation[] cond, int block, int trial, int[] stimuli, float brestT, float trestT, float srestT, float preT, float durT, float posT, Color bgcolor, int length)
        {
            Extype = new List<KeyValuePair<string, int>>();
            Cond = new List<SLKeyValuePair<string, int, SLInterpolation>>();

            Exdesign = new ExDesign(extype, expara, cond, block, trial, stimuli, brestT, trestT, srestT, preT, durT, posT, bgcolor);
            Flow = new FlowControl();
            PPort = new ParallelPort();
            Rand = new SLRandom(length);
        }
Ejemplo n.º 14
0
        public ActionResult Experiment()
        {
            List <ExType> exTypes = new List <ExType>();

            List <Human> listHumanExp   = new List <Human>();
            List <Human> addedHumansExp = new List <Human>();
            bool         whereExp       = false;

            if (Session["whereExp"] != null)
            {
                whereExp = ((bool)(Session["whereExp"]));
            }
            if (whereExp == true)
            {
                listHumanExp   = new List <Human>(((List <Human>)(Session["listHumanExp"])));
                addedHumansExp = new List <Human>(((List <Human>)(Session["addedHumansExp"])));
                exTypes        = new List <ExType>(((List <ExType>)(Session["ExTypes"])));
                fleet          = ((List <SpaceShip>)(Session["fleet"]));
                whereExp       = ((bool)(Session["whereExp"]));
            }
            if (whereExp == false)
            {
                addedHumansExp.Clear();
                fleet.Clear();
                listHumanExp.Clear();
                exTypes.Clear();
                //Session["whereExp"] = false;
                //Session["fleet"] = new List<SpaceShip>();
                //Session["listHumanExp"] = new List<Human>();
                //Session["addedHumansExp"] = new List<Human>();
                //Session["exTypes"] = new List<ExType>();

                whereExp = false;
                var connString = @"workstation id=FunnyV11.mssql.somee.com;packet size=4096;user id=Aldun_SQLLogin_1;pwd=6yy6wjrql5;data source=FunnyV11.mssql.somee.com;persist security info=False;initial catalog=FunnyV11 ";
                using (var conn = new SqlConnection(connString))
                {
                    conn.Open();
                    using (var cmd = new SqlCommand("SELECT * FROM Humen", conn))
                        using (var reader = cmd.ExecuteReader())
                            while (reader.Read())
                            {
                                Human human = new Human();
                                human.Id         = (int)reader[0];
                                human.Email      = reader[1].ToString();
                                human.Password   = reader[2].ToString();
                                human.FirstName  = reader[3].ToString();
                                human.SecondName = reader[4].ToString();
                                human.RoleId     = 2;
                                human.Age        = (int)reader[5];
                                reader.IsDBNull(reader.GetOrdinal("SpaceShipId"));
                                int?p = reader.IsDBNull(reader.GetOrdinal("SpaceShipId")) ? -1 : (int?)reader[7];
                                if (p != -1)
                                {
                                    human.SpaceShipId = p;
                                }
                                listHumanExp.Add(human);
                            }
                    if (exTypes.Count == 0)
                    {
                        using (var cmd = new SqlCommand("SELECT * FROM ExTypes", conn))
                            using (var reader = cmd.ExecuteReader())
                                while (reader.Read())
                                {
                                    ExType ext = new ExType();
                                    ext.Type        = reader[0].ToString();
                                    ext.Description = reader[1].ToString();
                                    exTypes.Add(ext);
                                }
                    }
                    if (fleet.Count == 0)
                    {
                        using (var cmd = new SqlCommand("SELECT * FROM SpaceShips", conn))
                            using (var reader = cmd.ExecuteReader())
                                while (reader.Read())
                                {
                                    SpaceShip spaceship = new SpaceShip();
                                    spaceship.Id           = (int)reader[0];
                                    spaceship.Name         = reader[1].ToString();
                                    spaceship.ShipId       = (int)reader[2];
                                    spaceship.ShipTypeType = reader[3].ToString();
                                    fleet.Add(spaceship);
                                }
                    }
                    conn.Close();
                }
            }
            ViewBag.fleet             = fleet;// Session["fleet"];
            ViewBag.where             = whereExp;
            ViewBag.listHuman         = listHumanExp;
            Session["addedHumansExp"] = new List <Human>(addedHumansExp);
            Session["listHumanExp"]   = new List <Human>(listHumanExp);
            Session["fleet"]          = fleet;
            Session["whereExp"]       = whereExp;
            Session["exTypes"]        = new List <ExType>(exTypes);
            ViewBag.exTypes           = exTypes;
            ViewBag.addedHumans       = addedHumansExp;
            return(View(listHumanExp));
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Add Pre-Defined Experiment Type
 /// </summary>
 /// <param name="type"></param>
 public void AddExType(ExType type)
 {
     AddExType(type.ToString(), (int)type);
 }