예제 #1
0
        public void ActivityDelete()
        {
            var activityNew = new UpdateActivity <TE>();
            var invokerNew  = new WorkflowInvoker(activityNew);
            var te          = new TE();

            te.AsDynamic().TECODE          = "TestNameDel";
            te.AsDynamic().TETYPECODE_R    = "EURO";
            te.AsDynamic().TECURRENTPLACE  = "TestName";
            te.AsDynamic().TECREATIONPLACE = "TestName";
            te.AsDynamic().TESTATUS        = 123;
            te.AsDynamic().TEMAXWEIGHT     = 123;
            var parameters = new Dictionary <string, object> {
                { "Key", te }
            };

            invokerNew.Invoke(parameters, DefaultTimeOut);

            var activity = new DeleteActivity <TE>();
            var invoker  = new WorkflowInvoker(activity);

            invoker.Invoke(parameters, DefaultTimeOut);

            var activityCheck   = new GetByKeyActivity <TE>();
            var invokerCheck    = new WorkflowInvoker(activityCheck);
            var parametersCheck = new Dictionary <string, object> {
                { "Key", "TestNameDel" }
            };
            var results = invokerCheck.Invoke(parametersCheck, DefaultTimeOut);

            Assert.True(results.Count != 0);
        }
예제 #2
0
        /**
         * Team Sevice 訊息處理
         */
        public void TeamServiceMsgProcess(string msg)
        {
            if (msg != string.Empty)
            {
                try
                {
                    JObject jsMain = JObject.Parse(msg);

                    if (jsMain.ContainsKey("CmdID"))
                    {
                        int cmdID = (int)jsMain["CmdID"];

                        if (jsMain.ContainsKey("Data"))
                        {
                            string packetData = jsMain["Data"].ToString();

                            switch (cmdID)
                            {
                            case (int)TeamPacket.ClientToServer.C2S_CmdID.emUpdateBulletin:

                                UpdateBulletin bulletinMsg = JsonConvert.DeserializeObject <UpdateBulletin>(packetData);

                                OnTeamBulletin(bulletinMsg);

                                break;

                            case (int)TeamPacket.ClientToServer.C2S_CmdID.emUpdateActivity:

                                UpdateActivity actMsg = JsonConvert.DeserializeObject <UpdateActivity>(packetData);

                                OnTeamActivity(actMsg);

                                break;

                            default:
                                SaveLog($"[Warning] Controller::TeamServiceMsgProcess, Can't Find CmdID {cmdID}");

                                break;
                            }
                        }
                        else
                        {
                            SaveLog("[Warning] Controller::TeamServiceMsgProcess, Can't Find Member \"Data\" ");
                        }
                    }
                    else
                    {
                        SaveLog("[Warning] Controller::TeamServiceMsgProcess, Can't Find Member \"CmdID\" ");
                    }
                }
                catch (Exception ex)
                {
                    SaveLog("[Error] Controller::TeamServiceMsgProcess, Process Error Msg:" + ex.Message);
                }
            }
            else
            {
                SaveLog("[Warning] Controller::TeamServiceMsgProcess, Msg Is Empty");
            }
        }
예제 #3
0
        public Activity Handle(UpdateActivity request)
        {
            var activity = _activityDataStorage.Find(request.Key);

            activity.Name = request.Name;

            return(_activityDataStorage.Update(activity));
        }
예제 #4
0
        public Activity UpdateActivity(int key, [FromBody] UpdateActivity request)
        {
            if (key != request.Key)
            {
                throw new ArgumentException("request.Key is invalid and doesn't match to key");
            }

            return(_dispatcher.Process(request));
        }
예제 #5
0
        public object Put(UpdateActivity request)
        {
            var entity = request.ConvertTo <Activity>();

            return(InTransaction(db =>
            {
                Logic.Update(entity);
                return new CommonResponse(Logic.GetById(entity.Id));
            }));
        }
예제 #6
0
        public async Task UpdateActivityHandlerInvokesUpdateActivityWithCorrectActivity()
        {
            var message = new UpdateActivity {
                Activity = new Activity()
            };
            var dataAccess = new Mock <IAllReadyDataAccess>();
            var sut        = new UpdateActivityHandler(dataAccess.Object);
            await sut.Handle(message);

            dataAccess.Verify(x => x.UpdateActivity(message.Activity), Times.Once);
        }
예제 #7
0
        /**
         * 車隊活動
         */
        private void OnTeamActivity(UpdateActivity packet)
        {
            NotifyTeamActivity rData = new NotifyTeamActivity()
            {
                TeamID        = packet.TeamID,
                MemberID      = packet.MemberID,
                MemberList    = packet.MemberList,
                ActDate       = packet.ActDate,
                Title         = packet.Title,
                MeetTime      = packet.MeetTime,
                TotalDistance = packet.TotalDistance,
                MaxAltitude   = packet.MaxAltitude,
                Route         = packet.Route,
                Description   = packet.Description,
            };

            JObject jsMain = new JObject();

            jsMain.Add("CmdID", (int)ClientPacket.ServerToClient.S2C_CmdID.emNotifyTeamActivity);
            jsMain.Add("Data", JsonConvert.DeserializeObject <JObject>(JsonConvert.SerializeObject(rData)));

            BrocastMsg(packet.TeamID, jsMain.ToString());
        }
예제 #8
0
        public UpdateResult UpdateOne <T>(Expression <Func <T, bool> > filter, UpdateDefinition <T> updateDef, UpdateOptions options = null) where T : IMongoEntity
        {
            T    oldValue = default(T);
            bool writeLog = ShouldWriteLog <T>();

            if (writeLog)
            {
                oldValue = Find(filter).FirstOrDefault();
            }
            var res = GetCollection <T>().UpdateOne(filter, updateDef, options);

            if (oldValue != null)
            {
                UpdateActivity updateActivity = new UpdateActivity(GetUserNameFunc())
                {
                    CollectionName = GetCollectionName(typeof(T)), ObjId = oldValue.Id
                };
                T newValue = FindById <T>(oldValue.Id);
                updateActivity.SetDiff(oldValue, newValue);
                Save((UserActivity)updateActivity);
            }
            return(res);
        }
예제 #9
0
        public void ActivityGetByFilter()
        {
            var activityNew = new UpdateActivity <TE>();
            var invokerNew  = new WorkflowInvoker(activityNew);
            var te          = new TE();

            te.AsDynamic().TECODE          = "TestNameGetF";
            te.AsDynamic().TETYPECODE_R    = "EURO";
            te.AsDynamic().TECURRENTPLACE  = "TestName";
            te.AsDynamic().TECREATIONPLACE = "TestName";
            te.AsDynamic().TESTATUS        = 123;
            te.AsDynamic().TEMAXWEIGHT     = 123;
            var parametersNew = new Dictionary <string, object> {
                { "Key", te }
            };

            invokerNew.Invoke(parametersNew, DefaultTimeOut);

            var          activity   = new GetByFilterActivity <TE>();
            var          invoker    = new WorkflowInvoker(activity);
            var          parameters = new Dictionary <string, object>();
            const string filter     = "((TECODE = 'TestNameGetF'))";

            parameters.Add("Filter", filter);
            var results = invoker.Invoke(parameters, DefaultTimeOut);

            Assert.True(results.Count > 0);

            var activityDel   = new DeleteActivity <TE>();
            var invokerDel    = new WorkflowInvoker(activityDel);
            var parametersDel = new Dictionary <string, object> {
                { "Key", te }
            };

            invokerDel.Invoke(parametersDel, new TimeSpan(0, 0, 0, 30));
        }
예제 #10
0
        public HttpResponseMessage PutEdit(int activityId, [FromBody] string mode)
        {
            try
            {
                var editActivity = _queryProcessor.Execute(new ActivityById(activityId));
                if (editActivity == null)
                {
                    var message = string.Format("Activity Id {0} not found.", activityId);
                    throw new Exception(message);
                }

                if (!editActivity.EditSourceId.HasValue)
                {
                    var message = string.Format("Activity Id {0} is not being edited.", activityId);
                    throw new Exception(message);
                }

                var updateActivityCommand = new UpdateActivity(User, editActivity.EditSourceId.Value, DateTime.Now, mode)
                {
                    Values = editActivity.Values.SingleOrDefault(x => x.ModeText == editActivity.ModeText)
                };
                _updateActivity.Handle(updateActivityCommand);

                var deleteActivityCommand = new DeleteActivity(User, editActivity.RevisionId);
                _deleteActivity.Handle(deleteActivityCommand);
            }
            catch (Exception ex)
            {
                var responseMessage = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.NotModified,
                    Content = new StringContent(ex.Message),
                    ReasonPhrase = "Activity update error"
                };
                throw new HttpResponseException(responseMessage);    
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
예제 #11
0
        public HttpResponseMessage Put(int activityId, ActivityApiModel model)
        {
            if ((activityId == 0) || (model == null))
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError);
            }

            var activity = Mapper.Map<Activity>(model);

            try
            {
                var updateActivityCommand = new UpdateActivity(User,
                                                               activity.RevisionId,
                                                               DateTime.Now,
                                                               activity.ModeText)
                {
                    Values = activity.Values.SingleOrDefault(x => x.ModeText == activity.ModeText)
                };
                _updateActivity.Handle(updateActivityCommand);
            }
            catch (Exception ex)
            {
                var responseMessage = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.NotModified,
                    Content = new StringContent(ex.Message),
                    ReasonPhrase = "Activity update error"
                };
                throw new HttpResponseException(responseMessage);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
예제 #12
0
        public void Save <T>(T item) where T : IMongoEntity
        {
            bool writeLog   = DefaultWriteLog;
            bool preprocess = DefaultPreprocess;
            Type type       = typeof(T);
            CollectionSaveAttribute attr = GetSaveAttribute(type);

            if (attr != null)
            {
                writeLog   = attr.WriteLog;
                preprocess = attr.Preprocess;
            }

            if (preprocess && objectPreprocessor != null)
            {
                objectPreprocessor.Preprocess(item);
            }

            ActivityType activityType;
            T            oldValue = default(T);

            if (item.Id == null)
            {
                GetCollection <T>().InsertOne(item);
                activityType = ActivityType.Insert;
            }
            else
            {
                if (writeLog)
                {
                    oldValue = FindById <T>(item.Id);
                }
                GetCollection <T>().ReplaceOne(t => t.Id == item.Id, item, new ReplaceOptions {
                    IsUpsert = true
                });
                activityType = ActivityType.Update;
            }
            if (writeLog)
            {
                string username = GetUserNameFunc();
                if (activityType == ActivityType.Insert)
                {
                    var insertActivity = new InsertActivity(username)
                    {
                        CollectionName = GetCollectionName(type), ObjId = item.Id
                    };
                    Save((UserActivity)insertActivity);
                }
                else
                {
                    UpdateActivity update = new UpdateActivity(username)
                    {
                        CollectionName = GetCollectionName(type), ObjId = oldValue.Id
                    };
                    update.SetDiff(oldValue, item);
                    if (update.Diff.Count > 0)
                    {
                        Save((UserActivity)update);
                    }
                }
            }
        }
예제 #13
0
        public HttpResponseMessage Put(int activityId, ActivityApiPutModel model)
        {
            // autosave invokes this method for everything except documents
            if (activityId == 0 || model == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            // invoke update command using the model's id and mode
            var command = new UpdateActivity(User, activityId)
            {
                Impersonator = Request.GetHttpContext().Session.UserImpersonating(),
            };
            Mapper.Map(model, command);
            _updateActivity.Handle(command);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
예제 #14
0
        public async Task <IActionResult> Put([FromBody] UpdateActivity command)
        {
            await DispatchAsync(command);

            return(NoContent());
        }