Ejemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            int page;

            int.TryParse(context.Request.Params["page"], out page);
            if (page == 0)
            {
                page = 1;
            }

            using (var t1 = new TEST1Entities())
            {
                var list = t1.UserInfo.OrderBy(c => c.Id).Pager(page, 10);
                context.Response.Write(JsonAdapter.Serialize(list.ToFlexigridObject(c => c.Id,
                                                                                    x => x.Add(c => c.Id)
                                                                                    .Add(c => c.Email)
                                                                                    .Add(c => c.Name)
                                                                                    .Add(c => c.Age)
                                                                                    .Add(c => 1))
                                                             ));
            }

            context.Response.End();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// userid
        /// </summary>
        public void Add(Note note, IUser user)
        {
            note.LastCommentTime     = note.EditTime = note.AddTime = DateTime.Now;
            note.LastCommentUsername = "";
            using (var db = DbInstance)
            {
                db.Note.Add(note);
                db.SaveChanges();
            }
            switch ((NoteType)note.Type)
            {
            case NoteType.Note:
                EventLog.Add(new EventLog
                {
                    OwnerId      = note.UserId,
                    TemplateName = "AddNote",
                    AddTime      = DateTime.Now,
                    ShowLevel    = 0,
                    Json         = JsonAdapter.Serialize(Dictionary.CreateFromArgs("id", note.Id,
                                                                                   "title", note.Title, "addtime",
                                                                                   note.AddTime, "name", user.Name))
                });
                break;

            case NoteType.GroupPost:
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        public int Login(Account account, Boolean isAutoLogin, Boolean isPasswordMd5, IContext context)
        {
            string userName = account.UserName;
            string password = account.Password;

            if (string.IsNullOrEmpty(userName.Trim()))
            {
                throw new Exception("用户名不能为空");
            }
            password = isPasswordMd5 ? password.Trim().ToMd5() : password.Trim();
            WebIdentity identity = GeneralIdentity(userName, password, context.Site.Score.LogOn);

            if (identity == null)
            {
                return(-1);                  //无账号
            }
            Logout(context);
            DateTime expires    = isAutoLogin ? DateTime.Now.AddMinutes(60) : DateTime.Now.AddYears(1);
            var      authTicket = new FormsAuthenticationTicket(1, identity.Name, DateTime.Now, expires, true,
                                                                JsonAdapter.Serialize(identity));
            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

            var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                Expires = expires
            };

            context.HttpContext.Response.Cookies.Add(authCookie);

            if (!isAutoLogin)
            {
                return(identity.Status);
            }
            return(identity.Status);
        }
Ejemplo n.º 4
0
        public void Send(Message data)
        {
            try
            {
                string jsonData = JsonAdapter <Message> .Serialize(data);

                Action <DeliveryReport <Null, string> > handler = r =>
                                                                  Console.WriteLine(!r.Error.IsError
                ? $"Delivered message to {r.TopicPartitionOffset}"
                : $"Delivery Error: {r.Error.Reason}");

                producer.Produce(topic, new Message <Null, string> {
                    Value = jsonData
                }, handler);


                producer.Flush(TimeSpan.FromSeconds(10));
            }
            catch (ProduceException <Null, string> ex)
            {
                Console.WriteLine(ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 5
0
        public void ToJsonStringTest()
        {
            var a = new Dictionary {
                { "title", "gogo" }
            };

            Assert.AreEqual(JsonAdapter.Serialize(a), "{\"title\":\"gogo\"}");
        }
Ejemplo n.º 6
0
        public void Serialize()
        {
            object       o        = new { Name = "chsword", Sex = true };
            const string expected = "{\"Name\":\"chsword\",\"Sex\":true}";
            var          actual   = JsonAdapter.Serialize(o);

            Assert.AreEqual(expected, actual);
            // Assert.AreEqual(string.Empty, JsonAdapter.Serialize(typeof(EnumExtensionType)));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Agrees the friend request.
        /// </summary>
        /// <param name="operaterId">The operater ID.</param>
        /// <param name="toId">To ID.</param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool Agree(long operaterId, long toId, IUser user)
        {
            var    b    = Agree(operaterId, toId);
            string name = UserInfo.GetUserName(toId);

            EventLog.Add(new EventLog
            {
                OwnerId      = toId,
                ViewerId     = operaterId,
                TemplateName = "MakeFriend",
                AddTime      = DateTime.Now,
                ShowLevel    = 0,
                Json         =
                    JsonAdapter.Serialize(Dictionary.CreateFromArgs("ownername", name, "sendername", user.Name)
                                          )
            }
                         );
            return(b);
        }
Ejemplo n.º 8
0
 public void SaveText(long uid, string text, IContext context)
 {
     using (var db = DbInstance)
     {
         var p = db.Profile.FirstOrDefault(c => c.UserId == uid);
         if (null == p)
         {
             return;
         }
         //              p.show = magicbox;
         db.SaveChanges();
     }
     EventLog.Add(new EventLog
     {
         OwnerId      = context.User.UserId,
         TemplateName = "ProText",
         AddTime      = DateTime.Now,
         ShowLevel    = 0,
         Json         = JsonAdapter.Serialize(Dictionary.CreateFromArgs("name", context.User.Name,
                                                                        "text", text))
     });
 }
Ejemplo n.º 9
0
        public async Task Test_HttpAction_InsertOnStartInsertOnEnd()
        {
            var evs     = new List <AuditEventHttpClient>();
            var actions = new List <HttpAction>();

            Audit.Core.Configuration.Setup()
            .Use(_ => _.OnInsertAndReplace(ev =>
            {
                evs.Add(JsonAdapter.Deserialize <AuditEventHttpClient>(JsonAdapter.Serialize(ev)));
                actions.Add(JsonAdapter.Deserialize <HttpAction>(JsonAdapter.Serialize(ev.GetHttpAction())));
            }))
            .WithCreationPolicy(Core.EventCreationPolicy.InsertOnStartInsertOnEnd);

            var cli = ClientFactory.Create(config);
            var url = "http://google.com/some/path?some=querystring";

            using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, url))
            {
                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "123456");
                requestMessage.Headers.Add("pepe", new[] { "test1", "test2" });
                requestMessage.Content = new StringContent("string content", Encoding.UTF8);
                await cli.SendAsync(requestMessage);
            }

            Assert.AreEqual(2, actions.Count);
            Assert.AreEqual(2, evs.Count);

            Assert.AreEqual("test", evs[0].EventType);
            Assert.AreEqual("POST", actions[0].Method);
            Assert.IsNotNull(actions[0].Request);
            Assert.IsNotNull(actions[0].Request.Content);
            Assert.AreEqual("string content", actions[0].Request.Content.Body.ToString());
            Assert.AreEqual("text/plain; charset=utf-8", actions[0].Request.Content.Headers["Content-Type"]);
            Assert.AreEqual("http", actions[1].Request.Scheme);
            Assert.AreEqual("test1, test2", actions[0].Request.Headers["pepe"]);
            Assert.AreEqual("?some=querystring", actions[0].Request.QueryString);
            Assert.AreEqual("/some/path", actions[0].Request.Path);
            Assert.IsNull(actions[0].Response);
            Assert.AreEqual(url, actions[0].Url);

            Assert.AreEqual("POST", actions[1].Method);
            Assert.IsNotNull(actions[1].Request);
            Assert.IsNotNull(actions[1].Response);
            Assert.AreEqual(url, actions[1].Url);
            Assert.IsTrue(actions[1].Response.Headers.Count > 0);
            Assert.AreEqual(false, actions[1].Response.IsSuccess);
            Assert.AreEqual(404, actions[1].Response.StatusCode);
            Assert.AreEqual("Not Found", actions[1].Response.Reason);
            Assert.AreEqual("NotFound", actions[1].Response.Status);
            Assert.IsTrue(actions[1].Response.Content.Body.ToString().Length > 0);
            Assert.IsTrue(actions[1].Response.Content.Headers.Count > 0);
        }
Ejemplo n.º 10
0
        public static TDest Cast <TDest>(object source)
        {
            string json = JsonAdapter.Serialize(source);

            return(JsonAdapter.Deserialize <TDest>(json));
        }