示例#1
0
        protected Task <ErrorStatusPb> Handle(PacketPb.Types.ActionType action, IList <TCloudItemDiff> data)
        {
            var           readOnlyData = new ReadOnlyCollection <TCloudItemDiff>(data);
            ErrorStatusPb errorStatus  = new ErrorStatusPb()
            {
                ErrType = ErrorStatusPb.Types.ErrorStatusEnum.Succeeded
            };

            try
            {
                lock (Container)
                {
                    switch (action)
                    {
                    case PacketPb.Types.ActionType.Add:
                        Container.AddRange(readOnlyData);
                        break;

                    case PacketPb.Types.ActionType.Update:
                        Container.Update(readOnlyData);
                        break;

                    case PacketPb.Types.ActionType.Remove:
                        Container.Remove(readOnlyData);
                        break;

                    case PacketPb.Types.ActionType.Clear:
                        Container.Clear();
                        break;
                    }
                }
            }
            catch (Exception err)
            {
                errorStatus.ErrType = ErrorStatusPb.Types.ErrorStatusEnum.Failed;
                errorStatus.Message = err.Message;
            }

            Timer.Stop();
            Logger.Info($"[{GetType().Name}.Handle] {DateTime.Now} " +
                        $"Elapsed time: {Timer.ElapsedMilliseconds} ms. " +
                        $"Error status: {errorStatus}");

            return(Task.FromResult(errorStatus));
        }
        protected virtual ICommand GetCommand(IList <SlamTrackedObjectDiff> objs, PacketPb.Types.ActionType action)
        {
            if (objs is null || objs.Count == 0)
            {
                return(null);
            }
            switch (action)
            {
            case PacketPb.Types.ActionType.Add:
                return(new AddCommand <SlamTrackedObject, SlamTrackedObjectDiff>(_container, objs));

            case PacketPb.Types.ActionType.Update:
                return(new UpdateCommand <SlamTrackedObject, SlamTrackedObjectDiff>(_container, objs));

            case PacketPb.Types.ActionType.Remove:
                return(new RemoveTrackedObjDiffCommands(_container, objs));

            case PacketPb.Types.ActionType.Clear:
                return(new ClearTrackedObjsCommand(_container));

            default: return(null);
            }
        }