예제 #1
0
        public virtual bool TryGetResponse(out string response)
        {
            var resp = response = null;

            ResponseTask = Task.Factory.StartNew(() =>
            {
                resp = GetResponse(IdleTimeout + ServerTimeout * 3);
            });

            try
            {
                if (ResponseTask.Wait(IdleTimeout))
                {
                    response = resp;
                    ResponseTask.Dispose();
                    ResponseTask = null;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (AggregateException)
            {
                throw;
            }
        }
예제 #2
0
        void WatchIdleQueue()
        {
            try
            {
                string last = null, resp;

                while (true)
                {
                    if (!TryGetResponse(out resp))
                    {
                        // Child task should still running on ReadByte here.
                        // Need to send some data to get it to exit.

                        SendCommand("DONE"); //_ResponseTask should pick up response and exit
                        if (!ResponseTask.Wait(ServerTimeout))
                        {
                            // Not responding
                            Disconnect();
                            throw new ImapClientException("Lost communication to IMAP server, connection closed.");
                        }

                        ResponseTask.Dispose();
                        ResponseTask = null;

                        IdleResumeCommand();

                        continue;
                    }

                    if (resp.Contains("OK IDLE"))//Server response after DONE
                    {
                        return;
                    }

                    var data = resp.Split(' ');
                    if (data[0] == "*" && data.Length >= 3)
                    {
                        var args = new MessageEventArgs {
                            Client = this, MessageCount = int.Parse(data[1])
                        };
                        if (data[2].Is("EXISTS") && !last.Is("EXPUNGE") && args.MessageCount > 0)
                        {
                            Task.Factory.StartNew(() => newMessage.Fire(this, args)); //Fire the event in a task
                        }
                        else if (data[2].Is("EXPUNGE"))
                        {
                            Task.Factory.StartNew(() => messageDeleted.Fire(this, args));
                        }

                        last = data[2];
                    }
                }
            }
            catch (Exception e)
            {
                var args = new ImapClientExceptionEventArgs(e);
                Task.Factory.StartNew(() => ImapException.Fire(this, args));
            }
        }
예제 #3
0
        public static async Task <bool> UpdateTasksAsync(ResponseTask responseTask)
        {
            Uri baseUri = new Uri(BaseAddress);
            HttpResponseMessage response = await _client.PostAsJsonAsync(new Uri(baseUri, "api/tasks/update"), responseTask);

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }
            return(false);
        }
예제 #4
0
        public void RequestTaskReward(MsgPack msgPack)
        {
            RequestTask data   = msgPack.Msg.RequestTask;
            NetMsg      netMsg = new NetMsg
            {
                cmd = (int)Command.ResponseTask
            };
            PlayerData playerData = _cacheSvc.GetPlayerDataBySession(msgPack.Session);

            TaskRewardCfg  taskCfg  = _resCfgSvc.GetTaskData(data.TaskId);
            TaskRewardData taskData = CalcTaskRewardData(playerData, data.TaskId);

            if (taskData.Prangs == taskCfg.Count && !taskData.Tasked)
            {
                playerData.Coin += taskCfg.Coin;
                PeRoot.CalcExp(playerData, taskCfg.Exp);
                playerData.Diamond += taskCfg.Diamond;
                taskData.Tasked     = true;
                CalcTaskArray(playerData, taskData);

                if (!_cacheSvc.UpdatePlayerData(playerData.Id, playerData))
                {
                    netMsg.err = (int)ErrorCode.UpdateDbError;
                }
                else
                {
                    ResponseTask responseTask = new ResponseTask
                    {
                        Coin      = playerData.Coin,
                        Level     = playerData.Level,
                        Diamond   = playerData.Diamond,
                        Exp       = playerData.Exp,
                        TaskArray = playerData.TaskArray,
                    };
                    netMsg.ResponseTask = responseTask;
                }
            }
            else
            {
                netMsg.err = (int)ErrorCode.ClientDataError;
            }

            msgPack.Session.SendMsg(netMsg);
        }
예제 #5
0
        public ResponseTask CountResponseTask(string userName, int type, string dbName)
        {
            string       connectionString = cons.GetConn(dbName);
            ResponseTask userTask         = new ResponseTask();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                using (SqlCommand cmd = new SqlCommand("spCountUserTask", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@cUserName", userName);
                    cmd.Parameters.AddWithValue("@iUserType", type);

                    SqlDataReader reader;
                    reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        userTask.TotalResponseTasks             = reader["TotalTasks"].ToString();
                        userTask.DeadlineResponseTasks          = reader["DeadlineTasks"].ToString();
                        userTask.OverDeadlineResponseTasks      = reader["OverDeadlineTasks"].ToString();
                        userTask.AppointmentResponseTasks       = reader["AppointmentTasks"].ToString();
                        userTask.OverAppointmentResponseTasks   = reader["OverAppointmentTasks"].ToString();
                        userTask.NoDeadlineDatesResponseTask    = reader["NoDeadlineDates"].ToString();
                        userTask.NoAppointmentDatesResponseTask = reader["NoAppointmentDates"].ToString();
                    }
                    reader.Close();
                }
                con.Close();
            }

            return(userTask);
        }
예제 #6
0
        private Task RunWork(Viber client, Config config, CancellationToken token)
        {
            API.BaseAddress = config.ApiUrl;
            client.Run();

            var t = new Task(async() =>
            {
                try
                {
                    var count = 0;
                    while (true)
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        var tasks        = await API.GetTasksAsync(config.MaxCountMessage);
                        var responseTask = new ResponseTask
                        {
                            Tasks = new List <Result>()
                        };

                        foreach (var domain in tasks.Domains)
                        {
                            try
                            {
                                foreach (var task in domain.Tasks)
                                {
                                    if (CountViberProfile() > 1 && count >= config.AccountChangeAfter)
                                    {
                                        client.Close();
                                        await SelectNextViberProfileAsync();
                                        client.Run();
                                        count = 1;
                                    }

                                    Guid statusId;
                                    if (client.Send(task.Phone, domain.Message))
                                    {
                                        count++;
                                    }

                                    switch (client.State)
                                    {
                                    case ViberState.ClickMessageMenu:
                                        statusId = NotRegisteredId;
                                        break;

                                    case ViberState.SendMessage:
                                        statusId = Sended;
                                        break;

                                    case ViberState.Run:
                                        return;

                                    default:
                                        statusId = Failure;
                                        break;
                                    }

                                    responseTask.Tasks.Add(new Result
                                    {
                                        Id       = task.Id,
                                        StatusId = statusId
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex);
                            }
                            finally
                            {
                                if (responseTask.Tasks.Any())
                                {
                                    await API.UpdateTasksAsync(responseTask);
                                }
                            }
                        }

                        Thread.Sleep(config.PauseBetweenTasks);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
                finally
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(
                        (Action)(() =>
                    {
                        SetDisabled(Stop);
                        SetEnabled(Start);
                    }
                                 ));
                }
            });

            t.Start();

            return(t);
        }