public static bool AddNewLog(LogModel log)
        {
            string dateStr = Convert.ToDateTime(log.Date).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);

            String query = "INSERT IGNORE INTO " + TblLogs;
            query += " (`UserID`, `Date`, `MsgType`, `Symbol`, `Group`, `Status`,`Timeframe`,`Application`) VALUES";
            query += "(";
            query += log.UserId + ",";
            query += "'" + dateStr + "',";
            query += "'" + log.MsgType + "',";
            query += "'" + log.Symbol + "',";
            query += "'" + log.Group + "',";
            query += "'" + log.Status + "',";
            query += "'" + log.Timeframe + "',";
            query += "'" + log.Application + "'" + ");COMMIT;";

            return DoSql(query);
        }
Beispiel #2
0
        private void DataNetCollectingSymbolStarted(DataAdminMessageFactory.LogMessage msg)
        {
            lock (_thisLock)
            {
                IEnumerable<string> symbolList = null;

                if (msg.LogType == DataAdminMessageFactory.LogMessage.Log.CollectGroup)
                {
                    var idGr = AdminDatabaseManager.GetGroups().Find(a => a.GroupName == msg.Group).GroupId;

                    symbolList = from symbols in AdminDatabaseManager.GetSymbolsInGroup(idGr) select symbols.SymbolName;
                    lock (_thisLock)
                    {
                        var logmodel = new LogModel
                        {
                            Date = msg.Time,
                            Group = msg.Group,
                            UserId = msg.UserID,
                            MsgType = Convert.ToInt32(msg.LogType),
                            Status = Convert.ToInt32(msg.OperationStatus),
                            Symbol = "",//todo empty msg.Symbol,
                            Timeframe = msg.TimeFrame,
                            Application = ApplicationType.DataNet.ToString()
                        };

                        AdminDatabaseManager.AddNewLog(logmodel);
                    }
                }
                else
                    if (msg.LogType == DataAdminMessageFactory.LogMessage.Log.CollectSymbol)
                    {
                        symbolList = msg.Symbol.Split(',').ToList().AsEnumerable();
                    }

                if (symbolList != null)
                    foreach (var smbcollect in symbolList)
                    {

                        var smb = _symbols.Find(a => a.SymbolName == smbcollect);
                        var bsmb = new DataAdminService.BusySymbol
                        {
                            ID = smb.SymbolId,
                            IsDataNet = msg.IsByDataNetBusy,
                            UserName =
                                (from items in _users where items.Id == msg.UserID select items.Name).
                                First(),
                            TimeFrames = new List<DataAdminService.TimeFrameModel>
                                                            {
                                                                new DataAdminService.TimeFrameModel
                                                                    {TimeFrame =  msg.TimeFrame,
                                                                UserId =  msg.UserID}
                                                            }

                        };

                        if (!_adminService.BusySymbols.Exists(a => a.ID == bsmb.ID))
                            _adminService.BusySymbols.Add(bsmb);
                        else
                        {
                            bsmb.IsTickNet = _adminService.BusySymbols.Find(a => a.ID == bsmb.ID).IsTickNet;
                            _adminService.BusySymbols.Find(a => a.ID == bsmb.ID).IsDataNet = true;
                            if (!_adminService.BusySymbols.Find(a => a.ID == bsmb.ID).TimeFrames.Exists(oo => oo.TimeFrame == msg.TimeFrame))
                                _adminService.BusySymbols.Find(a => a.ID == bsmb.ID).TimeFrames.Add(
                                    new DataAdminService.TimeFrameModel { TimeFrame = msg.TimeFrame, UserId = msg.UserID });

                        }

                        var tickNetStatus = bsmb.IsTickNet ? "Busy" : "Enabled";
                        var dataNetStatus = bsmb.IsDataNet ? "Busy" : "Enabled";
                        foreach (DataGridViewRow row in ui_symbols_dGrid_Symbols.Rows)
                        {
                            var name = row.Cells[0].Value.ToString();
                            if (name != smb.SymbolName) continue;
                            row.Cells[1].Value = dataNetStatus;
                            row.Cells[2].Value = tickNetStatus;
                        }

                        var logmodellow = new LogModel
                        {
                            Date = msg.Time,
                            Group = "",
                            UserId = msg.UserID,
                            MsgType = Convert.ToInt32(DataAdminMessageFactory.LogMessage.Log.CollectSymbol),
                            Status = Convert.ToInt32(msg.OperationStatus),
                            Symbol = smbcollect,
                            Timeframe = msg.TimeFrame,
                            Application = ApplicationType.DataNet.ToString()
                        };

                        lock (_thisLock)
                        {
                            AdminDatabaseManager.AddNewLog(logmodellow);
                        }

                    }

                _adminService.SendBusySymbolList(msg.UserID);

                UpdateLogsTable();
            }
        }
        public static List<LogModel> GetLogBetweenDates(DateTime startDate, DateTime endDate, bool desc = true)
        {
            string dateStart = Convert.ToDateTime(startDate).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
            string dateEnd = Convert.ToDateTime(endDate).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);

            var resultList = new List<LogModel>();

            string sql = "SELECT * FROM " + TblLogs + " WHERE Date BETWEEN '" + dateStart + "' AND '" + dateEnd + "' ORDER BY `Date` " + (desc ? "DESC" : " ") + " , `ID` ASC;";
            lock (LockReader)
            {
                var reader = GetReader(sql);
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        var log = new LogModel
                        {
                            LogId = reader.GetInt32(0),
                            UserId = reader.GetInt32(1),
                            Date = reader.GetDateTime(2),
                            MsgType = reader.GetInt32(3),
                            Symbol = reader.GetString(4),
                            Group = reader.GetString(5),
                            Status = reader.GetInt32(6),
                            Timeframe = reader.GetString(7),
                            Application = reader.GetString(8),
                        };

                        resultList.Add(log);
                    }

                    reader.Close();
                }
            }
            return resultList;
        }
Beispiel #4
0
        private void DataNetCollectingGroupStarted(DataAdminMessageFactory.LogMessage msg)
        {
            lock (_thisLock)
            {
                var logmodel = new LogModel
                {
                    Date = msg.Time,
                    Group = msg.Group,
                    UserId = msg.UserID,
                    MsgType = Convert.ToInt32(msg.LogType),
                    Status = Convert.ToInt32(msg.OperationStatus),
                    Symbol = "",//todo empty msg.Symbol,
                    Timeframe = msg.TimeFrame,
                    Application = ApplicationType.DataNet.ToString()
                };

                AdminDatabaseManager.AddNewLog(logmodel);

                UpdateLogsTable();
            }
        }
Beispiel #5
0
        private void DataNetCollectingSymbolFinished(DataAdminMessageFactory.LogMessage msg)
        {
            lock (_thisLock)
            {
                IEnumerable<SymbolModel> symbolList = null;

                var smList = msg.Symbol.Split(',').ToList();
                symbolList = from items in _symbols
                                where smList.Exists(o => o == items.SymbolName)
                                select items;

                if (symbolList != null)
                    foreach (var smb in symbolList)
                    {
                        var bsmb = new DataAdminService.BusySymbol
                        {
                            ID = smb.SymbolId
                        };

                        if (_adminService.BusySymbols.Exists(a => a.ID == bsmb.ID))
                        {
                            var tempbsm = _adminService.BusySymbols.Find(a => a.ID == bsmb.ID);
                            if (!tempbsm.IsTickNet && tempbsm.TimeFrames.Count == 1)
                            {
                                _adminService.BusySymbols.Remove(tempbsm);
                                bsmb.IsDataNet = false;

                            }
                            else

                                if (tempbsm.IsTickNet && tempbsm.TimeFrames.Count == 1)
                                {
                                    bsmb.IsTickNet = tempbsm.IsTickNet;
                                    bsmb.IsDataNet = false;
                                    tempbsm.IsDataNet = false;
                                    var tf = tempbsm.TimeFrames.Find(oo => oo.TimeFrame == msg.TimeFrame);
                                    tempbsm.TimeFrames.Remove(tf);
                                }
                                else
                                    if (tempbsm.TimeFrames.Count > 1)
                                    {
                                        bsmb.IsTickNet = tempbsm.IsTickNet;
                                        bsmb.IsDataNet = true;
                                        var tf = tempbsm.TimeFrames.Find(oo => oo.TimeFrame == msg.TimeFrame);
                                        tempbsm.TimeFrames.Remove(tf);
                                    }
                        }

                        var tickNetStatus = bsmb.IsTickNet ? "Busy" : "Enabled";
                        var dataNetStatus = bsmb.IsDataNet ? "Busy" : "Enabled";
                        foreach (DataGridViewRow row in ui_symbols_dGrid_Symbols.Rows)
                        {
                            if (row.Cells[0].Value.ToString() != smb.SymbolName) continue;
                            row.Cells[1].Value = dataNetStatus;
                            row.Cells[2].Value = tickNetStatus;
                        }

                        lock (_lockFinishedCollect)
                        {
                            var logmodelLow = new LogModel
                            {
                                Date = msg.Time,
                                Group = msg.Group,
                                UserId = msg.UserID,
                                MsgType = Convert.ToInt32(msg.LogType),
                                Status = Convert.ToInt32(msg.OperationStatus),
                                Symbol = msg.Symbol,
                                Timeframe = msg.TimeFrame,
                                Application = ApplicationType.DataNet.ToString(),
                                Comments = msg.Comments
                            };
                            AdminDatabaseManager.AddNewLog(logmodelLow);
                        }
                    }

                _adminService.SendBusySymbolList(msg.UserID);

                UpdateLogsTable();
            }
        }
Beispiel #6
0
        private void ClientLoggedOutLog(DataAdminMessageFactory.LogMessage msg, string msgMain, string userName)
        {
            _onlineUsers = _adminService.OnlineClients.GetAllItems();
            foreach (DataGridViewRow row in ui_users_dgridX_users.Rows)
            {
                if (_onlineUsers.Exists(a => a.UserName == userName))
                {
                    var tickNet = _onlineUsers.Find(a => a.UserName == userName).IsTickNetConnected;
                    var dNet = _onlineUsers.Find(a => a.UserName == userName).IsDatanetConnected;

                    if (row.Cells[0].Value.ToString() == userName && dNet)
                    {
                        row.Cells[2].Value = "online";
                    }
                    else
                    {
                        row.Cells[2].Value = "offline";
                    }

                    if (row.Cells[0].Value.ToString() == userName && tickNet)
                    {
                        row.Cells[3].Value = "online";
                    }
                    else
                    {
                        row.Cells[3].Value = "offline";
                    }
                }
                else
                {
                    if (row.Cells[0].Value.ToString() == userName)
                    {
                        row.Cells[2].Value = "offline";
                        row.Cells[3].Value = "offline";
                    }
                }
            }
            var logmodel = new LogModel
            {
                Date = msg.Time,
                Group = msg.Group,
                UserId = msg.UserID,
                MsgType = Convert.ToInt32(msg.LogType),
                Status = Convert.ToInt32(msg.OperationStatus),
                Symbol = msg.Symbol,
                Timeframe = msg.TimeFrame,
                Application = (msg.IsDataNetClient ? "DataNet" : msg.IsTickNetClient ? "TickNet" : "DataExport")
            };
            AdminDatabaseManager.AddNewLog(logmodel);
            UpdateLogsTable();
        }
Beispiel #7
0
        private void AbortedOperationLog(object sender, DataAdminMessageFactory.LogMessage msg)
        {
            if (msg.IsDataNetClient&& msg.LogType == DataAdminMessageFactory.LogMessage.Log.CollectSymbol)
            {
                Task.Factory.StartNew(() => DataNetCollectingSymbolFinished(msg));
                return;
            }

            var logmodel = new LogModel
            {
                Date = msg.Time,
                Group = msg.Group,
                UserId = msg.UserID,
                MsgType = Convert.ToInt32(msg.LogType),
                Status = Convert.ToInt32(msg.OperationStatus),
                Symbol = msg.Symbol,
                Timeframe = msg.TimeFrame,
                Comments = msg.Comments
            };

            AdminDatabaseManager.AddNewLog(logmodel);
            UpdateLogsTable();
        }
Beispiel #8
0
        private void TickNetCollectStarted(DataAdminMessageFactory.LogMessage msg)
        {
            lock (_thisNLock)
            {

                try
                {
                    var logmodel = new LogModel
                    {
                        Date = msg.Time,
                        Group = msg.Group,
                        UserId = msg.UserID,
                        MsgType = Convert.ToInt32(msg.LogType),
                        Status = Convert.ToInt32(msg.OperationStatus),
                        Symbol = msg.Symbol,
                        Timeframe = msg.TimeFrame
                    };

                    #region group collecting

                    if (msg.LogType == DataAdminMessageFactory.LogMessage.Log.CollectGroup)
                    {
                        var idGr = _groups.Find(a => a.GroupName == msg.Group).GroupId;

                        var listSmb = AdminDatabaseManager.GetSymbolsInGroup(idGr);

                        foreach (var symbolModel in listSmb)
                        {
                            var rankList = _adminService.TickNetSymbolAccesRank[symbolModel.SymbolName];
                            //the list which consist the user list
                            if (!rankList.Exists(a => a.DBId == msg.UserID))
                            {
                                var user = _adminService.OnlineClients.GetAllItems().Find(o => o.DBId == msg.UserID);
                                user.DepthValue = msg.DepthValue;
                                _adminService.TickNetSymbolAccesRank[symbolModel.SymbolName].Add(user);
                            }
                        }
                        foreach (var smb in listSmb)
                        {
                            var busySmb = new DataAdminService.BusySymbol
                            {
                                ID = smb.SymbolId,
                                //IsDataNet = msg.IsByDataNetBusy,
                                IsTickNet = msg.IsByTickNetBusy
                            };

                            var tickNetStatus = busySmb.IsTickNet ? "Busy" : "Enabled";
                            var dataNetStatus = busySmb.IsDataNet ? "Busy" : "Enabled";
                            foreach (DataGridViewRow row in ui_symbols_dGrid_Symbols.Rows)
                            {
                                if (row.Cells[0].Value.ToString() != smb.SymbolName) continue;
                                row.Cells[1].Value = dataNetStatus;
                                row.Cells[2].Value = tickNetStatus;
                            }
                        }

                    }
                    #endregion

                    else if (msg.LogType == DataAdminMessageFactory.LogMessage.Log.CollectSymbol)
                    {

                        var smb = _symbols.Find(a => a.SymbolName == msg.Symbol);
                        if (_adminService.TickNetSymbolAccesRank.All(o => o.Key != smb.SymbolName))
                        {
                            _adminService.TickNetSymbolAccesRank.Add(smb.SymbolName, new List<DataClient>());
                            var user = _adminService.OnlineClients.GetAllItems().Find(o => o.DBId == msg.UserID);
                            user.DepthValue = msg.DepthValue;
                            _adminService.TickNetSymbolAccesRank[smb.SymbolName].Add(user);
                            try
                            {
                                user.TClientProxy.SendActivateMsgToClient(smb.SymbolName);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                                ErrorReport(new ErrorInfo
                                {
                                    AdditionalInformation = "",
                                    InvokeTime = DateTime.Now,
                                    MethodName = "TicknetCollectStarted-SendActivateMsgToClient",
                                    ErrorText = ex.Message
                                });
                            }
                            //add symbol to busy symbol list

                            var bsm = new DataAdminService.BusySymbol
                            {
                                ID = smb.SymbolId,
                                IsDataNet = msg.IsByDataNetBusy,
                                IsTickNet = msg.IsByTickNetBusy
                            };
                            if (!_busySymbols.Exists(a => a.ID == bsm.ID)) _busySymbols.Add(bsm);
                            else
                            {
                                var fsmb = _busySymbols.Find(o => o.ID == bsm.ID);
                                fsmb.IsTickNet = true;
                            }

                        }
                        else if (_adminService.TickNetSymbolAccesRank[smb.SymbolName].Count == 0)
                        {
                            var user = _adminService.OnlineClients.GetAllItems().Find(o => o.DBId == msg.UserID);
                            user.DepthValue = msg.DepthValue;
                            _adminService.TickNetSymbolAccesRank[smb.SymbolName].Add(user);
                            try
                            {
                                user.TClientProxy.SendActivateMsgToClient(smb.SymbolName);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                                ErrorReport(new ErrorInfo
                                {
                                    AdditionalInformation = "",
                                    InvokeTime = DateTime.Now,
                                    MethodName = "TicknetCollectStarted-SendActivateMsgToClient",
                                    ErrorText = ex.Message
                                });
                            }
                            var bsm = new DataAdminService.BusySymbol
                            {
                                ID = smb.SymbolId,
                                IsDataNet = msg.IsByDataNetBusy,
                                IsTickNet = msg.IsByTickNetBusy
                            };
                            if (!_busySymbols.Exists(a => a.ID == bsm.ID)) _busySymbols.Add(bsm);
                            else
                            {
                                var fsmb = _busySymbols.Find(o => o.ID == bsm.ID);
                                fsmb.IsTickNet = true;
                            }
                        }
                        else
                        {
                            var rankList =
                                _adminService.TickNetSymbolAccesRank[smb.SymbolName].OrderByDescending(o => o.DepthValue)
                                    .
                                    ToList(); //the list which consist the user list
                            if (!rankList.Exists(a => a.DBId == msg.UserID))
                            {
                                var user = _adminService.OnlineClients.GetAllItems().Find(o => o.DBId == msg.UserID);
                                user.DepthValue = msg.DepthValue;
                                string tempuser = rankList[0].UserName;
                                int depthValue = rankList[0].DepthValue;
                                if (depthValue < user.DepthValue)
                                {
                                    _adminService.TickNetSymbolAccesRank[smb.SymbolName].Add(user);
                                    try
                                    {
                                        _adminService.Clients.GetAllItems().Find(oo => oo.UserName == tempuser).TClientProxy.SendWaitToClients(smb.SymbolName);
                                        nextTNClient = user.UserName;
                                        nextTNSymbol = smb.SymbolName;

                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex);
                                        ErrorReport(new ErrorInfo
                                        {
                                            AdditionalInformation = "",
                                            InvokeTime = DateTime.Now,
                                            MethodName = "TicknetCollectStarted-SendActivateMsgToClient",
                                            ErrorText = ex.Message
                                        });
                                    }

                                }

                                else
                                    _adminService.TickNetSymbolAccesRank[smb.SymbolName].Add(user);
                            }
                        }
                        var tickNetStatus = msg.IsByTickNetBusy ? "Busy" : "Enabled";
                        var ids = _symbols.Find(o => o.SymbolName == msg.Symbol).SymbolId;
                        var dataNetStatus = _busySymbols.Find(o => o.ID == ids).IsDataNet ? "Busy" : "Enabled";

                        var absm = new DataAdminService.BusySymbol { ID = ids, IsDataNet = msg.IsByDataNetBusy };
                        if (!_busySymbols.Exists(a => a.ID == absm.ID)) _busySymbols.Add(absm);
                        else
                        {
                            var fsmb = _busySymbols.Find(o => o.ID == absm.ID);
                            fsmb.IsTickNet = true;
                        }

                        foreach (DataGridViewRow row in ui_symbols_dGrid_Symbols.Rows)
                        {
                            var name = row.Cells[0].Value.ToString();
                            if (name != smb.SymbolName) continue;
                            row.Cells[1].Value = dataNetStatus;
                            row.Cells[2].Value = tickNetStatus;
                        }
                    }
                    //         _adminService.SendBusySymbolList();
                    Task.Factory.StartNew(() => AdminDatabaseManager.AddNewLog(logmodel)).ContinueWith(delegate
                    {
                        UpdateLogsTable();
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    ErrorReport(new ErrorInfo
                    {
                        AdditionalInformation = "",
                        ErrorText = ex.Message

                    });
                }
            }
        }
Beispiel #9
0
        private void TicknetCollectFinished(DataAdminMessageFactory.LogMessage msg)
        {
            var logmodel = new LogModel
            {
                Date = msg.Time,
                Group = msg.Group,
                UserId = msg.UserID,
                MsgType = Convert.ToInt32(msg.LogType),
                Status = Convert.ToInt32(msg.OperationStatus),
                Symbol = msg.Symbol,
                Timeframe = msg.TimeFrame
            };

            var smb = _symbols.Find(a => a.SymbolName == msg.Symbol);
            if (_adminService.TickNetSymbolAccesRank.Any(o => o.Key == smb.SymbolName))
            {
                if (_adminService.TickNetSymbolAccesRank[smb.SymbolName].Count == 0) return;

                var usr = _adminService.TickNetSymbolAccesRank[smb.SymbolName].OrderByDescending(o => o.DepthValue).ToList()[0];

                if (usr.DBId != msg.UserID)
                {
                    var delusr =
                        _adminService.TickNetSymbolAccesRank[smb.SymbolName].Find(
                            o => o.DBId == msg.UserID);
                    _adminService.TickNetSymbolAccesRank[smb.SymbolName].Remove(delusr);
                    AdminDatabaseManager.AddNewLog(logmodel);

                    return;
                }
            }

            Task.Factory.StartNew(() => ActivateNextClient(msg.Symbol)).Wait();

            AdminDatabaseManager.AddNewLog(logmodel);
            UpdateLogsTable();
        }
Beispiel #10
0
        private void SimpleMessageLog(object sender, DataAdminMessageFactory.LogMessage msg)
        {
            var logmodel = new LogModel
            {
                Date = msg.Time,
                Group = "",

                UserId = msg.UserID,
                MsgType = Convert.ToInt32(msg.LogType),
                Status = Convert.ToInt32(msg.OperationStatus),
                Symbol = msg.Symbol,
                Timeframe = msg.TimeFrame
            };

            AdminDatabaseManager.AddNewLog(logmodel);
        }