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); } }
protected void Application_AuthenticateRequest(object sender, EventArgs e) { HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName]; if (null == authCookie) { return; } FormsAuthenticationTicket authTicket; try { authTicket = FormsAuthentication.Decrypt(authCookie.Value); } catch (Exception) { return; } if (null == authTicket) { return; } var profile = JsonAdapter.Deserialize <WebIdentity>(authTicket.UserData); Context.User = new WebPrincipal { Identity = profile }; }
public ActionResult Demo() { StrObjectDict dict = GetParams(); string temp = dict.GetString("FormStruct"); string FormID = dict.GetString("FormID"); string VersionCode = dict.GetString("VersionCode"); StrObjectDict tes1 = JsonAdapter.FromJsonAsDictionary(temp).toStrObjDict(); string result = temp.ToJson(); //string[] array = temp.Trim().Split(','); //string temp2 = ""; //for (int i = 0; i < array.Length; i++) //{ // array[i] += ","; // temp2 += array[i]; //} //temp2 = temp2.Substring(0, temp2.Length - 1); //IList<string> lis = new List<string>(array); int temps = FormManager.Instance.InsertData(tes1, dict); //return this.MyJson(1, lis); return(this.MyJson(1, tes1)); }
void Start() { awsManager = AWSManager.instance; xmlManager = XMLManager.ins; csvManager = CSVManager.instance; jsonAdapter = JsonAdapter.instance; }
/// <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; } }
public void Test_log4net_InsertOnStartReplaceOnEnd() { Audit.Core.Configuration.Setup() .UseLog4net(_ => _ .LogLevel(LogLevel.Info)); _adapter.Clear(); using (var s = new AuditScopeFactory().Create(new AuditScopeOptions() { CreationPolicy = EventCreationPolicy.InsertOnStartReplaceOnEnd, EventType = "Test_log4net_InsertOnStartReplaceOnEnd" })) { } var events = _adapter.PopAllEvents(); Assert.AreEqual(2, events.Length); Assert.AreEqual("Test_log4net_InsertOnStartReplaceOnEnd", JsonAdapter.Deserialize <AuditEvent>(events[0].MessageObject.ToString()).EventType); Assert.AreEqual("Test_log4net_InsertOnStartReplaceOnEnd", JsonAdapter.Deserialize <AuditEvent>(events[1].MessageObject.ToString()).EventType); var jsonAdapter = new JsonAdapter(); Assert.AreEqual(jsonAdapter.Deserialize <AuditEvent>(events[0].MessageObject.ToString()).CustomFields["EventId"].ToString(), jsonAdapter.Deserialize <AuditEvent>(events[1].MessageObject.ToString()).CustomFields["EventId"].ToString()); }
public void Initialize(Mailbox mailbox_, ProfilePopup popup) { profilePopup = popup; mailbox = mailbox_; DateTime now = DateTime.Now; DateTime send_time = DateTime.ParseExact(mailbox.time, "yyyy-MM-dd HH:mm:ss", null); TimeSpan timeSpan = now - send_time; int day = timeSpan.Days; //지난 날 int hour = timeSpan.Hours; //지난 시간 int day_remain = 13 - day; int hour_remain = 24 - hour; Debug.Log(day + "d" + hour + "h"); dateText.text = day_remain + "d" + hour_remain + "h"; senderText.text = "<color=white>" + mailbox.sender + "</color> 님이" + Environment.NewLine + "하트 1개를 선물했어요"; UserInfo friendInfo = AWSManager.instance.allUserInfo.Find((x) => x.nickname == mailbox.sender); //UserFriend friend = AWSManager.instance.userFriend.Find(x => x.nickname_friend == friendInfo.nickname); senderStyleImage.sprite = Resources.Load <Sprite>("Icon/Skin/" + friendInfo.profile_skin); //friendshipText.text = friend.friendship.ToString(); jsonAdapter = JsonAdapter.instance; }
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); }
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(); }
public Message Handle() { Message message = null; try { consumer.Subscribe("hello-topic"); CancellationTokenSource cts = new CancellationTokenSource(); Console.CancelKeyPress += (_, e) => { e.Cancel = true; cts.Cancel(); }; var cr = consumer.Consume(cts.Token); consumer.Close(); message = JsonAdapter <Message> .Deserialize(cr.Value); } catch (ConsumeException ex) { Console.WriteLine($"Ocorreu um erro: {ex.Error.Reason}"); } return(message); }
public void ToJsonStringTest() { var a = new Dictionary { { "title", "gogo" } }; Assert.AreEqual(JsonAdapter.Serialize(a), "{\"title\":\"gogo\"}"); }
/// <summary> ///Deserialize 的测试 ///</summary> public void DeserializeTestHelper <T>() { var o = string.Empty; var expected = default(T); var actual = JsonAdapter.Deserialize <T>(o); Assert.AreEqual(expected, actual); }
private static void AdapterTest() { String data = string.Empty; IGetDataAdapter getDataAdapter; getDataAdapter = new JsonAdapter(); data = getDataAdapter.GetData(); }
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))); }
T GetRequestParamter <T>() { string json = ""; using (StreamReader sr = new StreamReader(Request.InputStream)) { json = sr.ReadToEnd(); } return(JsonAdapter.Deserialize <T>(json)); }
public void ToJObjectTest() { string str = "{title:'text of title',body:'content',addtime:'2008-08-08 20:00:00'}"; // TODO: 初始化为适当的值 // JObject expected = null; // TODO: 初始化为适当的值 var actual = JsonAdapter.Deserialize <Dictionary <string, string> >(str); Assert.AreEqual(actual["title"], "text of title"); Assert.AreEqual(actual["body"], "content"); Assert.AreEqual(DateTime.Parse(actual["addtime"].ToString()), DateTime.Parse("2008-08-08 20:00")); }
public virtual void Initialize(UserInfo friendinfo, UserFriend friend_, ProfilePopup profilePopup) { friendInfo = friendinfo; friend = friend_; nicknameText.text = friendInfo.nickname; styleText.text = friendInfo.profile_style; profileImage.sprite = Resources.Load <Sprite>("Icon/Skin/" + friendInfo.profile_skin); jsonAdapter = JsonAdapter.instance; popup = profilePopup; }
private void Initialize() { CsvStatsImporter csvStatsImporter = new CsvStatsImporter(); IStatsImporter csvAdapter = new CsvAdapter(csvStatsImporter); JsonStatsImporter jsonStatsImporter = new JsonStatsImporter(); IStatsImporter jsonImporter = new JsonAdapter(jsonStatsImporter); var jsonImportedSettings = jsonImporter.FetchData(); var csvIMportedSettings = csvAdapter.FetchData(); }
public void ChangeXmlToJson() { var computer = new Computer(); global::Adapter.Adapters.Adapter adapter = new global::Adapter.Adapters.Adapter(new XmlAdapter()); Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><Computer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ProjectName>My dream nr 7005</ProjectName><Case>Obudowa Lian Li DK-03X</Case><Motherboard>Asus ROG RAMPAGE VI EXTREME</Motherboard></Computer>", adapter.Request(computer)); JsonAdapter jsonAdapter = new JsonAdapter(); adapter.ChangeRequest(jsonAdapter.CreateJson); Assert.AreEqual("{\"ProjectName\":\"My dream nr 7005\",\"Case\":\"Obudowa Lian Li DK-03X\",\"Motherboard\":\"Asus ROG RAMPAGE VI EXTREME\"}", adapter.Request(computer)); }
public void GetAll_WhenInvoked_ReturnsAllOwnersWithPets() { var adapter = new JsonAdapter(new LoggerFactory(), _mockFileSystem.Object); var petsContext = new PetsContext(); adapter.Fill(null, petsContext); Assert.Equal(6, petsContext.Owners.Count()); Assert.Equal(10, petsContext.Owners.Where(o => o.Pets != null).SelectMany(x => x.Pets).Count()); }
public ActionResult TargetLoad() { var sod = GetParams(); var data = _dal.List <NursingMarkTarget>(sod); var lst = new List <dynamic>(); string strScoreValue, strScoreRemark; foreach (var item in data) { strScoreValue = strScoreRemark = string.Empty; var strJson = "["; if (!string.IsNullOrEmpty(item.ScoreValue)) { var scoreValue = item.ScoreValue.Split(','); var valueRange = item.ValueRange.Split(','); var scoreRemark = string.IsNullOrEmpty(item.ScoreRemark) ? null : item.ScoreRemark.Split(','); for (int i = 0; i < scoreValue.Length; i++) { strJson += "{"; strJson += string.Format("'fz':'{0}','zy':'{1}','sm':'{2}'", scoreValue[i], valueRange[i], scoreRemark == null ? "" : scoreRemark[i]); strJson += "},"; strScoreValue += string.Format("{0}={1},", valueRange[i], scoreValue[i]); strScoreRemark += string.Format("{0}分({1});", scoreValue[i], scoreRemark == null ? "" : scoreRemark[i]); } strScoreValue = strScoreValue.TrimEnd(','); strScoreRemark = strScoreRemark.TrimEnd(';'); strJson = strJson.TrimEnd(','); } strJson += "]"; var obj = new { ID = item.ID, Name = item.Name, MarkTabID = item.MarkTabID, Remark = item.Remark, SerialNumber = item.SerialNumber, IsMultiple = item.IsMultiple, ElementID = item.ElementID, StrScoreValue = strScoreValue, StrScoreRemark = strScoreRemark, score_group = JsonAdapter.FromJsonAsDictionary(strJson) }; lst.Add(obj); } return(this.MyJson(1, lst)); }
void Start() { //PlayerPrefs.SetInt("tutorial",1); //PlayerPrefs.SetInt("tutorial", IslandData.tutorial + 1);//튜토리얼 건너 뛰기 awsManager = AWSManager.instance; xmlManager = XMLManager.ins; jsonAdapter = JsonAdapter.instance; xmlManager.LoadItems();//if xml file not exist create it. jsonAdapter.GetAllUserInfo(WebRequestCallback); jsonAdapter.GetAllEditorMap(WebRequestCallback); }
public string CreateTable(string Json) { try { Table table = JsonAdapter.AdaptTableFromJson(Json); string Sql = TableCollector.CreateTable(table); NpgController.InvokeQueryWithoutAnswer(Sql); return(new JObject().AddStatus("Success").ToString()); } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }
public string DropTable(string Json) { try { string TableName = JsonAdapter.TableNameFromJson(Json); string sql = TableCollector.DropTable(TableName); NpgController.InvokeQueryWithoutAnswer(sql); return(new JObject().AddStatus("Success").ToString()); } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }
private void Awake() { if (instance == null) { Debug.Log("Single instance is null"); instance = this; } else if (instance != this) { Debug.Log("Single instance is not Single.. Destroy gameobject!"); Destroy(gameObject); } DontDestroyOnLoad(gameObject);//Dont destroy this singleton gameobject :( }
//解析token ActionResult AnalysisToken(ApiParamter paramter, out bool isret, out tMembersEntity member) { member = null; isret = true; if (paramter == null) { return(RetToLogin("登录过期,请重新登录")); } if (paramter.token.IsEmpty()) { return(RetToLogin("登录过期,请重新登录")); } paramter.token = DES3Encrypt.Decrypt(paramter.token); paramter.user = JsonAdapter.Deserialize <UserToken>(paramter.token); if (paramter.user == null) { return(RetJsonResult(ApiResponseCodeEnum.Fail, "非法请求")); } if (DateHelper.GetTimeStamp_Seconds() - paramter.user.time > (30 * 60)) { return(RetToLogin("登录过期,请重新登录")); } if (paramter.user.Id <= 0) { return(RetJsonResult(ApiResponseCodeEnum.Fail, "非法请求")); } member = tMembersBLL.Instance.GetModel(paramter.user.Id); if (member == null) { return(RetJsonResult(ApiResponseCodeEnum.Fail, "非法请求")); } if (member.mbState.Value.Equals(YesNoEnum.No.GetHashCode())) { return(RetToLogin("账户被禁用")); } paramter.clientType = ClientHelper.IsPC(Request.UserAgent) ? "PC" : "H5"; isret = false; return(RetJsonResult(ApiResponseCodeEnum.Success)); }
public string Delete(string Json) { try { string TableName = JsonAdapter.TableNameFromJson(Json); List <Packet> packets = PackageAdapter.PacketsFromJson(Json); string Condition = FilterAdapter.GetCondition(TableName, packets.ToArray()); string sql = $"DELETE FROM \"{TableName}\" WHERE {Condition}"; return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql))); } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }
public string Add(string Json) { try { List <Entity> entities = JsonAdapter.AdaptEntityFromJson(Json); foreach (Entity item in entities) { string Sql = RowCollector.Insert(item, NpgController); NpgController.InvokeQuery(Sql); } return(new JObject().AddStatus("Success").ToString()); } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }
public virtual ActionResult History(long versionId) { KeyValuePair <Wiki, WikiVersion> t = Entry.GetFromVersion(versionId); if (t.Key == null || t.Value == null) { return(View("wait", "site")); } Wiki entry = t.Key; WikiVersion version = t.Value; ViewData["version"] = version; ViewData["entry"] = entry; ViewData["ext"] = JsonAdapter.Deserialize <EntryExt>(version.Ext); Title = entry.Url; return(View()); }
public string GetAll(string Json) { try { LimitPacket packet = GetLimit(ref Json); string limit = packet == null ? "" : $" {LimitAdapter.AdaptToSql(packet)}"; string TableName = JsonAdapter.TableNameFromJson(Json); string Sql = $"SELECT * FROM \"{TableName}\"{limit}"; return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(Sql))); } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }