Exemplo n.º 1
0
        public QClient(string name, int bufferSize = 100 * 1024, string ip = "127.0.0.1", int port = 39654)
        {
            _name = name;

            HeartSpan = 1000 * 1000;

            HeartAsync();

            _batcher = new Batcher <byte[]>(3000, 10); //此参数用于控制产生或消费速读,过大会导致溢出异常

            _batcher.OnBatched += _batcher_OnBatched;

            _qContext = new QContext();

            _qUnpacker = (QUnpacker)_qContext.Unpacker;

            _queueCoder = new QueueCoder();

            ISocketOption socketOption = SocketOptionBuilder.Instance.SetSocket(Sockets.Model.SAEASocketType.Tcp)
                                         .UseIocp(_qContext)
                                         .SetIP(ip)
                                         .SetPort(port)
                                         .SetWriteBufferSize(bufferSize)
                                         .SetReadBufferSize(bufferSize)
                                         .ReusePort(false)
                                         .Build();

            _clientSocket = SocketFactory.CreateClientSocket(socketOption);

            _clientSocket.OnReceive += _clientSocket_OnReceive;

            _clientSocket.OnError += _clientSocket_OnError;

            _clientSocket.OnDisconnected += _clientSocket_OnDisconnected;
        }
Exemplo n.º 2
0
        private bool CheckContextForElement(QContext context)
        {
            bool isRightContext = false;

            if (DateTime.Now.TimeOfDay > context.StartTime.TimeOfDay && DateTime.Now.TimeOfDay < context.EndTime.TimeOfDay)
            {
                isRightContext = true;
            }

            return(isRightContext);
        }
Exemplo n.º 3
0
        public async Task <bool> Run(JobInfo jobInfo, CancellationToken cancelToken)
        {
            var db = new ActivityDB();

            foreach (QStudy study in CurrentUser.Instance.User.ActiveStudiesObjects)
            {
                if (study.Elements != null)
                {
                    foreach (QElement element in study.Elements)
                    {
                        var contextDoc = await CrossCloudFirestore.Current
                                         .Instance
                                         .GetCollection(QContext.CollectionPath)
                                         .GetDocument(element.LinkToContext)
                                         .GetDocumentAsync();

                        QContext context = contextDoc.ToObject <QContext>();

                        if (CheckContextForElement(context) && db.GetElementCountForToday(element.ID) < element.RepeatPerDay)
                        {
                            db.AddActivity(
                                new QActivity
                            {
                                Name        = study.Title,
                                Date        = DateTime.Now,
                                Description = element.Description,
                                ElementId   = element.ID,
                                Status      = "open",
                                Link        = element.LinkToUserElement,
                            });

                            await this.dependency.SendNotification(study.Title, "You're in the right context answer a question. Go ahead 🚀");
                        }
                    }
                }
            }

            return(true); // this is for iOS - try not to lie about this - return true when you actually do receive new data from the remote method
        }