コード例 #1
0
        public override Task <UpdateAdvResponse> UpdateAdv(UpdateAdvRequest request, ServerCallContext context)
        {
            UpdateAdvResponse response = new UpdateAdvResponse {
                UpdateSucc = true
            };
            AdvDao dao = new AdvDao();

            switch (request.Type)
            {
            case UpdateAdvRequest.Types.UpdateType.Create:
                Console.WriteLine("a new create comme...");
                request.Adv.AdvId = AdvIdGenerator.GetAdvId().Result;
                AdvManager.Save(request.Adv);
                dao.Add(AdvUtil.CreateAdv(request.Adv));
                break;

            case UpdateAdvRequest.Types.UpdateType.Update:
                AdvManager.Set(request.Adv);
                dao.Update(AdvUtil.CreateAdv(request.Adv));
                break;

            case UpdateAdvRequest.Types.UpdateType.Delete:
                AdvManager.Drop(request.Adv.AdvId);
                dao.Delete(request.Adv.AdvId);
                break;

            default:
                Console.WriteLine("Unknown update type");
                response.UpdateSucc = false;
                break;
            }
            return(Task.FromResult(response));
        }
コード例 #2
0
        List <QueryAdvResponse> QueryComplexAdv(QueryAdvRequest request)
        {
            AdvDao     dao       = new AdvDao();
            uint       timestamp = request.CreationTime != 0 ? request.CreationTime : Util.ToTimestamp(DateTime.Now);
            List <Adv> list      = dao.GetByCtime(timestamp);
            List <QueryAdvResponse> responses = new List <QueryAdvResponse>();

            foreach (var adv in list)
            {
                OrcaAdv          orca_adv = AdvManager.Get(adv.AdvId);
                QueryAdvResponse response = new QueryAdvResponse
                {
                    Adv = new OrcaAdv
                    {
                        AdvId    = adv.AdvId,
                        DivPaper = orca_adv.DivPaper
                    }
                };
                if (request.Resolution == QueryAdvRequest.Types.Resolution.Res4To3)
                {
                    response.Adv.WallPaper4To3 = orca_adv.WallPaper4To3;
                }
                if (request.Resolution == QueryAdvRequest.Types.Resolution.Res16To9)
                {
                    response.Adv.WallPaper16To9 = orca_adv.WallPaper16To9;
                }
                responses.Add(response);
            }
            return(responses);
        }
コード例 #3
0
        List <QueryAdvResponse> QuerySimpleAdv(QueryAdvRequest request)
        {
            AdvDao     dao  = new AdvDao();
            List <Adv> list = request.CreationTime != 0 ? dao.GetByCtime(request.CreationTime) : dao.GetAll();
            List <QueryAdvResponse> responses = new List <QueryAdvResponse>();

            foreach (var adv in list)
            {
                QueryAdvResponse response = new QueryAdvResponse
                {
                    Adv = AdvManager.Get(adv.AdvId)
                };
                responses.Add(response);
            }
            return(responses);
        }