protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            stoppingToken.ThrowIfCancellationRequested();

            var consumer = new AsyncEventingBasicConsumer(_channel);

            consumer.Received += async(ch, ea) =>
            {
                var content  = Encoding.UTF8.GetString(ea.Body.ToArray());
                var activity = JsonConvert.DeserializeObject <Activity>(content);

                using (var scope = _serviceScopeFactory.CreateScope())
                {
                    var _unitOfWork = scope.ServiceProvider.GetRequiredService <IUnitOfWork>();
                    _unitOfWork.ActivityRepository.Insert(activity);
                    _unitOfWork.Save();

                    var patient = _unitOfWork.PatientRepository.GetByID(activity.PatientId);

                    ActivityMessage message = new ActivityMessage {
                        PatientName = patient.Name, CaregiverId = patient.CaregiverId
                    };

                    await CheckRulesAsync(activity, message);
                }

                _channel.BasicAck(ea.DeliveryTag, false);
            };

            _channel.BasicConsume("Activities", false, consumer);
            await Task.CompletedTask;
        }
Beispiel #2
0
        public IActionResult AssignMessage(int msgid, string st, AssignActivityMessageDto model)
        {
            var actMsg = new ActivityMessage();

            actMsg.Activity.Id       = model.ActivityId;
            actMsg.Message.Id        = msgid;
            actMsg.SendingTime.Id    = "after";
            actMsg.CreatedBy.Id      = partnerManager.GetCurrentUserId(this.HttpContext);
            actMsg.CreatedBy.Account = partnerManager.GetCurrentUserAccount(this.HttpContext);
            actMsg.MessageOrder      = -1;
            var result   = new ActivityMessageRepo(db, partnerManager).Create(actMsg);
            var activity = new ActivityRepo(db, partnerManager).GetActivity(model.ActivityId);

            model.Activity = activity;
            var sendingTime = new CommonCodeRepo(db).GetCodesByType("ActivityMessage.SendingTime");

            model.SendingTime = sendingTime;
            var messages = new MessageTemplateRepo(db, partnerManager).GetAll(activity.Id);
            var listOfSelectedMessage = new List <SelectedMessages>();

            if (messages != null)
            {
                foreach (var item in messages)
                {
                    listOfSelectedMessage.Add(new SelectedMessages
                    {
                        Message     = item,
                        SendingTime = sendingTime
                    });;
                }
            }
            model.Messages         = listOfSelectedMessage;
            model.ActivityMessages = new ActivityMessageRepo(db, partnerManager).GetList(activity.Id, -1);
            return(View(model));
        }
Beispiel #3
0
        public async Task SendActivityLog(string message)
        {
            Context.Items.TryGetValue("Group", out var groupItem);
            string groupName = (string)groupItem;

            Context.Items.TryGetValue("Name", out var nameItem);
            string name            = (string)nameItem;
            var    gameSession     = ActiveGameSessions.FirstOrDefault(x => x.GroupName == groupName);
            var    player          = gameSession.Players.FirstOrDefault(p => p.Name == name);
            var    activityMessage = new ActivityMessage
            {
                Color   = player.Color,
                Message = $"{name}: {message}"
            };

            if (gameSession.ActivityLogs.Count != 0)
            {
                if (gameSession.ActivityLogs[gameSession.ActivityLogs.Count - 1] == activityMessage)
                {
                    return;
                }
            }
            gameSession.ActivityLogs.Add(activityMessage);
            await Clients.Client(gameSession.GameMaster.ConnectionId).SendAsync("receiveActivityLog", activityMessage);
        }
        /// <summary>
        /// Change Activity informations.
        /// </summary>
        /// <param name="request">activity request.</param>
        /// <returns>Activity message.</returns>
        public ActivityMessage UpdateActivity(ActivityRequest request)
        {
            ActivityMessage message = new ActivityMessage();

            try
            {
                request.FindActivityDto = FindActivityDto.ActivityId;
                ActivityResponsePivot response = _serviceActivity.FindActivities(request.ToPivot());
                if (response?.ActivityPivot != null)
                {
                    _serviceActivity.UpdateActivity(request.ToPivot());
                    message.OperationSuccess = true;
                }
                else
                {
                    message.ErrorMessage     = ActivityMessageResource.NotFoundActivity;
                    message.ErrorType        = ErrorType.FunctionalError;
                    message.OperationSuccess = false;
                }
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }
Beispiel #5
0
        public void AddActivity(long creator, ActivityMessage message, long subdomainid)
        {
            // if so check if it allows multiples don't need to check
            if (!message.AllowMultiple())
            {
                // check if db already contains entry
                var count = db.activities.Count(x => x.type == message.GetMessageType() &&
                                                x.appid == message.appid);

                if (count != 0)
                {
                    return;
                }
            }

            var activity = new activity
            {
                appid        = message.appid,
                owner        = creator,
                title        = message.Format(),
                type         = message.GetMessageType(),
                created      = DateTime.UtcNow,
                targetUserid = message.targetUserid
            };

            db.activities.InsertOnSubmit(activity);

            CacheHelper.Instance.invalidate_dependency(DependencyType.activities, subdomainid.ToString());
        }
Beispiel #6
0
        public List <ActivityMessage> GetList(string activityId, int messageId)
        {
            string whereClause = string.Empty;

            #region Parameters
            var parameters = new List <OracleParameter>();
            if (!string.IsNullOrEmpty(activityId))
            {
                var activityIdParamenter = new OracleParameter {
                    ParameterName = "activityId", OracleDbType = OracleDbType.Varchar2, Value = activityId
                };
                whereClause = " WHERE act_id=:activityId ";
                parameters.Add(activityIdParamenter);
            }
            if (messageId > 0)
            {
                var messageIdParamenter = new OracleParameter {
                    ParameterName = "messageId", OracleDbType = OracleDbType.Varchar2, Value = messageId
                };
                whereClause += string.IsNullOrEmpty(whereClause) ? " WHERE msg_id=:messageId " : " AND msg_id=:messageId ";
                parameters.Add(messageIdParamenter);
            }

            #endregion
            var masterDataTable = db.GetData("Select * from activity_message t  " + whereClause + "order by msg_order" +
                                             "", parameters);

            if (masterDataTable == null)
            {
                return(null);
            }
            if (masterDataTable.Rows.Count == 0)
            {
                return(null);
            }

            var list = new List <ActivityMessage>();
            foreach (DataRow row in masterDataTable.Rows)
            {
                var obj   = new ActivityMessage();
                var actId = row["act_id"] == DBNull.Value ? string.Empty : row["act_id"].ToString();
                obj.Activity = new ActivityRepo(db, partnerManager).GetActivity(actId);
                var msgId = row["msg_id"] == DBNull.Value ? 0 : int.Parse(row["msg_id"].ToString());
                obj.MessageOrder = row["msg_order"] == DBNull.Value ? 0 : int.Parse(row["msg_order"].ToString());
                obj.Message      = new MessageTemplateRepo(db, partnerManager).GetSingle(msgId);
                var sendingTime = row["sending_time"] == DBNull.Value ? string.Empty : row["sending_time"].ToString();
                obj.SendingTime = new CommonCodeRepo(db).GetCodesById(sendingTime, "ActivityMessage.SendingTime");
                obj.CreatedOn   = row["createdon"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["createdon"].ToString());
                var createdAccount = row["createdbyacc"] == DBNull.Value ? -1 : int.Parse(row["createdbyacc"].ToString());
                var partner        = partnerManager.GetPartnerByAccount(createdAccount);
                obj.CreatedBy.Id      = row["createdby"] == DBNull.Value ? string.Empty : row["createdby"].ToString();
                obj.CreatedBy.Name    = partner.Name;
                obj.CreatedBy.Account = partner.Account;
                list.Add(obj);
            }
            return(list);
        }
Beispiel #7
0
        public void CanMapActiveMessageToDtoObject()
        {
            //Arange
            var activityMessage = new ActivityMessage();
            //Act
            var dtoObject = messageMapper.Map(activityMessage);

            //Assert
            Assert.That(dtoObject, Is.Not.Null);
        }
        public void Receive(ActivityMessage message)
        {
            bool notifyUI = false;

            if (message.MessageType == "Task")
            {
                var  messageTask = AT_BC.Data.Helpers.DataContractSerializeHelper.DeSerialize <CO_IA.Data.Task>(message.Content);
                bool bExist      = false;
                foreach (var task in this.taskList)
                {
                    if (messageTask.Key == task.Key)
                    {
                        task.FormState   = messageTask.FormState;
                        task.Description = messageTask.Description;
                        task.Creator     = messageTask.Creator;
                        task.CreateTime  = messageTask.CreateTime;
                        task.DisturbInfo = messageTask.DisturbInfo;
                        task.Executors   = messageTask.Executors;
                        task.Submitter   = messageTask.Submitter;
                        task.SubmitTime  = messageTask.SubmitTime;
                        task.TaskPlaceID = messageTask.TaskPlaceID;
                        task.TaskType    = messageTask.TaskType;
                        task.Urgency     = messageTask.Urgency;
                        bExist           = true;
                        break;
                    }
                }
                if (!bExist)
                {
                    this.taskList.Add(messageTask);
                    notifyUI = true;
                }
            }
            else if (message.MessageType == "TaskExecuteConclusion")
            {
                var conclusion = AT_BC.Data.Helpers.DataContractSerializeHelper.DeSerialize <CO_IA.Data.TaskExecuteConclusion>(message.Content);
                foreach (var task in this.taskList)
                {
                    if (conclusion.TaskGuid == task.Key)
                    {
                        if (task.Executors[0].Executor == conclusion.Executor)
                        {
                            task.Executors[0].Executed = conclusion.Executed;
                            notifyUI = true;
                        }
                    }
                }
            }
            if (notifyUI)
            {
                this.executedTasks.View.Refresh();
                this.executableTasks.View.Refresh();
            }
        }
Beispiel #9
0
        public OpertionResult Create(ActivityMessage msg)
        {
            try
            {
                #region Parameters
                var parameters = new List <OracleParameter> {
                    new OracleParameter {
                        ParameterName = "retVal", OracleDbType = OracleDbType.Int32, Direction = ParameterDirection.ReturnValue
                    },
                    new OracleParameter {
                        ParameterName = "v_act_id", OracleDbType = OracleDbType.Varchar2, Value = msg.Activity.Id
                    },
                    new OracleParameter {
                        ParameterName = "v_msg_id", OracleDbType = OracleDbType.Int32, Value = msg.Message.Id
                    },
                    new OracleParameter {
                        ParameterName = "v_sending_time", OracleDbType = OracleDbType.Varchar2, Value = msg.SendingTime.Id
                    },
                    new OracleParameter {
                        ParameterName = "v_createdby", OracleDbType = OracleDbType.Varchar2, Value = msg.CreatedBy.Id
                    },
                    new OracleParameter {
                        ParameterName = "v_createdbyacc", OracleDbType = OracleDbType.Int32, Value = msg.CreatedBy.Account
                    },
                    new OracleParameter {
                        ParameterName = "v_msg_order", OracleDbType = OracleDbType.Int32, Value = msg.MessageOrder
                    }
                };
                #endregion
                db.ExecuteStoredProc("pk_settings.fn_create_activity_message", parameters);
                var result = int.Parse(parameters.Find(x => x.ParameterName == "retVal").Value.ToString());

                if (result > 0)
                {
                    return(new OpertionResult {
                        AffectedCount = result, Success = true, Error = string.Empty
                    });
                }
                else
                {
                    return(new OpertionResult {
                        AffectedCount = result, Success = false, Error = string.Empty
                    });
                }
            }
            catch (Exception ex)
            {
                return(new OpertionResult {
                    AffectedCount = -1, Success = false, Error = ex.Message
                });
            }
        }
Beispiel #10
0
 public MessageDto Map(ActivityMessage activityMessage)
 {
     if (activityMessage == null)
     {
         throw new ArgumentNullException("activityMessage", "Object to map was null");
     }
     return(new MessageDto
     {
         PrId = encryptor.Encode(activityMessage.ProjectId.ToString()),
         AcId = encryptor.Encode(activityMessage.ActivityId.ToString()),
         Start = TimeStampConverter.ConvertToUnixTimestamp(activityMessage.StartTime),
         End = TimeStampConverter.ConvertToUnixTimestamp(activityMessage.StopTime),
     });
 }
        public async Task CheckRulesAsync(Activity activity, ActivityMessage message)
        {
            var duration = (activity.EndDate - activity.StartDate);

            switch (activity.ActivityName)
            {
            case "Sleeping":
                if (duration.TotalHours > 7)
                {
                    message.Message = "has slept for more than 7 hours.";
                    await _messageHub.Clients.All.SendMessage(message);
                }
                break;

            case "Leaving":
                if (duration.TotalHours > 5)
                {
                    message.Message = "has been outside for more than 5 hours.";
                    await _messageHub.Clients.All.SendMessage(message);
                }
                break;

            case "Toileting":
                if (duration.TotalMinutes > 30)
                {
                    message.Message = "has been inside the bathroom for more than 30 minutes.";
                    await _messageHub.Clients.All.SendMessage(message);
                }
                break;

            case "Showering":
                if (duration.TotalMinutes > 30)
                {
                    message.Message = "has been inside the bathroom for more than 30 minutes.";
                    await _messageHub.Clients.All.SendMessage(message);
                }
                break;

            case "Grooming":
                if (duration.TotalMinutes > 30)
                {
                    message.Message = "has been inside the bathroom for more than 30 minutes.";
                    await _messageHub.Clients.All.SendMessage(message);
                }
                break;

            default: break;
            }
        }
        /// <summary>
        /// Create new Activity
        /// </summary>
        /// <param name="request">activity request.</param>
        /// <returns>Activity message.</returns>
        public ActivityMessage CreateActivity(ActivityRequest request)
        {
            ActivityMessage message = new ActivityMessage();

            try
            {
                message = _serviceActivity.CreateActivity(request.ToPivot()).ToMessage();
                message.OperationSuccess = true;
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }
        /// <summary>
        /// Get list of Activity
        /// </summary>
        /// <returns>Activity message.</returns>
        public ActivityMessage GetAllActivities()
        {
            ActivityMessage message = new ActivityMessage();

            try
            {
                message = _serviceActivity.GetAllActivities().ToMessage();
                message.OperationSuccess = true;
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }
Beispiel #14
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (Messages.Count == _settings.MaxActivity)
            {
                _dispatcher.InvokeAsync(() => Messages.RemoveAt(0));
            }

            var message = new ActivityMessage
            {
                Time      = DateTime.Now,
                LogLevel  = logLevel,
                Exception = exception,
                ThreadId  = Thread.CurrentThread.ManagedThreadId,
                Message   = formatter(state, exception)
            };

            _dispatcher.InvokeAsync(() => Messages.Add(message));
        }
Beispiel #15
0
        public App()
        {
            //InitializeComponent();

            UriChanger   = new PicUriChanger();
            SettingTheme = new Theme();
            DataCatcherE = new DataCatcher();

            //LoginPerson = new PersonMessage(-1);
            //TempClear();
            CCat = new PersonMessage(-1);
            //PP = new PersonMessage(-2);
            DisplayPerson = CCat;   //temp, Change After taking Log in
            //DemoActivity = new ActivityMessage("", "", "", "", 10, BlackCat.App.CCat, -1);
            //Demo2 = new ActivityMessage("", "", "", "", 4, BlackCat.App.CCat, -2);


            DisplayActivity = new ActivityMessage();
            MainP           = new MainPage();
            PageInfo        = new NavigationPage(new LoginPage("", ""));


            MainPage = PageInfo;
        }