protected void Page_Load(object sender, EventArgs e) { byte[] requestBodyBytes; using (StreamReader reader = new StreamReader(Request.InputStream)) { string body = reader.ReadToEnd(); requestBodyBytes = Encoding.UTF8.GetBytes(body); } dynamic requestBody = DynamicJson.Parse(Encoding.UTF8.GetString(requestBodyBytes)); if (requestBody != null) { StampUrl = requestBody.url; SendTo = requestBody.to; //スタンプ送信のリクエストボディ dynamic pushBody = new DynamicJson(); pushBody.to = SendTo; pushBody.messages = new[] { new { type = "image", originalContentUrl = StampUrl, previewImageUrl = StampUrl } }; SendPush(Encoding.UTF8.GetBytes(pushBody.ToString())); System.Diagnostics.Trace.WriteLine("stamper: to:" + SendTo + " image:" + StampUrl); } Response.AppendHeader("Access-Control-Allow-Origin", "*"); return; }
public static void Operate() { var json = DynamicJsonConvert.Parse(@"{""foo"":""json"", ""bar"":100, ""nest"":{ ""foobar"":true } }"); // Check Defined Peroperty // .name() is shortcut of IsDefined("name") var b1_1 = json.IsDefined("foo"); // true var b2_1 = json.IsDefined("foooo"); // false var b1_2 = json.foo(); // true var b2_2 = json.foooo(); // false; // Add json.Arr = new string[] { "NOR", "XOR" }; // Add Array json.Obj1 = new { }; // Add Object json.Obj2 = new { foo = "abc", bar = 100 }; // Add and Init // Delete // ("name") is shortcut of Delete("name") json.Delete("foo"); json.Arr.Delete(0); json("bar"); json.Arr(1); // Replace json.Obj1 = 5000; // Create New JsonObject dynamic newjson = new DynamicJson(); newjson.str = "aaa"; newjson.obj = new { foo = "bar" }; // Serialize(to JSON String) var jsonstring = newjson.ToString(); // {"str":"aaa","obj":{"foo":"bar"}} }
private string PrepareSortieData() { dynamic json = new DynamicJson(); var escapedPos = new List <int>(); var posOffset = 0; foreach (var fleetData in KCDatabase.Instance.Fleet.Fleets.Values.Where(fleet => fleet.IsInSortie)) { for (var i = 0; i < fleetData.Members.Count; i++) { if (fleetData.EscapedShipList.Contains(fleetData.Members[i])) { escapedPos.Add(i + posOffset); } } posOffset += 6; } json.escapedPos = escapedPos; // TODO: Unverified! // Our lifecycle seems to be the same with Poi's ;) json.currentNode = KCDatabase.Instance.Battle?.Compass?.Destination; string serialized = json.ToString(); return(serialized); }
static void Main(string[] args) { dynamic json = null; if (File.Exists(PROP_NAME)) { Console.WriteLine("read from " + PROP_NAME); using (FileStream fs = new FileStream(PROP_NAME, FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { json = DynamicJson.Parse(sr.ReadToEnd()); } } } else { Console.WriteLine("write to " + PROP_NAME); json = new DynamicJson(); json.name = "basyura"; // 厳密には別ファイルを作成した後で mv するべきだよなぁ using (FileStream fs = new FileStream(PROP_NAME, FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine(json.ToString()); } } } Console.WriteLine(json.name); json.name = "hoge"; Console.WriteLine(json.name); Console.WriteLine(json.ToString()); }
// ************************************************************ public bool SaveFile(string p) { bool ret = false; dynamic obj = new DynamicJson(); double[] sz = new double[2]; sz[0] = (double)m_ButtonSize.Width; sz[1] = (double)m_ButtonSize.Height; obj["ButtonSize"] = sz; var dat = new object[m_List.Count]; if (m_List.Count > 0) { for (int i = 0; i < m_List.Count; i++) { dat[i] = m_List[i].ToJson(); } obj["kk"] = m_List[0].ToJson(); } obj["List"] = dat; try { string js = obj.ToString(); File.WriteAllText(p, js, Encoding.GetEncoding("utf-8")); ret = true; } catch { ret = false; } return(ret); }
static void Main(string[] args) { //①読み込むJSONデータ var jsonString = @"{""Address"":""Tokyo"",""Age"":32,""Name"":""Doi""}"; //②DynamicJsonクラスのParseメソッドでJSONデータを解析してdynamic型として返す var obj = DynamicJson.Parse(jsonString); //③変換したクラスのプロパティ内容を確認 Console.WriteLine("Name:{0}, Address:{1}, Age:{2}", obj.Name, obj.Address, obj.Age); var friend = new FriendInfo() { Name = "Doi", Address = "Tokyo", Age = 32 }; //DynamicJsonクラスのSerializeメソッドで.NETオブジェクトをJSONデータに変換 Console.Write(DynamicJson.Serialize(friend)); //DynamicJsonクラスをインスタンス化 dynamic obj2 = new DynamicJson(); //任意のプロパティを設定可能 obj2.Name = "Doi"; obj2.TelNo = "03-xxxx-xxxx"; obj2.MobileTelNo = "090-xxxx-xxxx"; //DynamicJsonオブジェクトのToStringメソッドでJSONデータを出力 Console.WriteLine(obj2.ToString()); PostalCodeSample(); }
private string PrepareMiscData() { dynamic json = new DynamicJson(); json.combinedFleet = KCDatabase.Instance.Fleet.CombinedFlag > 0; return(json.ToString()); }
public void WhenCollectedNoGlobalDataThenGlobalDataIsEmpty() { var first = new Configurator(_libraryFolder.Path, NavigationIsolator.GetOrCreateTheOneNavigationIsolator()); dynamic j = new DynamicJson(); j.one = 1; first.CollectJsonData(j.ToString()); Assert.AreEqual(j, DynamicJson.Parse(first.LocalData)); }
public void GetLibraryData_NoGlobalData_Empty() { var first = new Configurator(_libraryFolder.Path, NavigationIsolator.GetOrCreateTheOneNavigationIsolator()); dynamic j = new DynamicJson(); j.one = 1; first.CollectJsonData(j.ToString()); Assert.AreEqual("{}", first.GetLibraryData()); }
public void GetAllData_LocalOnly_ReturnLocal() { var c = new Configurator(_libraryFolder.Path, NavigationIsolator.GetOrCreateTheOneNavigationIsolator()); dynamic j = new DynamicJson(); j.one = 1; c.CollectJsonData(j.ToString()); Assert.AreEqual(j, DynamicJson.Parse(c.GetAllData())); }
public void WhenCollectedNoLocalDataThenLocalDataIsEmpty() { var first = new Configurator(_libraryFolder.Path); dynamic j = new DynamicJson(); j.library = new DynamicJson(); j.library.librarystuff = "foo"; first.CollectJsonData(j.ToString()); AssertEmpty(first.LocalData); }
protected static string MakeDeleteFileContent(string _description, string filename) { dynamic _result = new DynamicJson(); dynamic _file = new DynamicJson(); _result.description = _description; _result.files = new { }; _result.files[filename] = "null"; return(_result.ToString()); }
protected static string MakeEditContent(string _description, string _oldFileName, string _newFileName, string _content) { dynamic _result = new DynamicJson(); dynamic _file = new DynamicJson(); _result.description = _description; _result.files = new { }; _result.files[_oldFileName] = new { filename = _newFileName, content = _content }; return(_result.ToString()); }
private async void InitializeComment() { Owner.Comment.IsCommentLoading = true; var list = await Owner.CommentInstance.GetCommentAsync(); if (list != null) { foreach (var entry in list) { VideoData.CommentData.Add(new CommentEntryViewModel(entry, Owner)); } dynamic json = new DynamicJson(); json.array = list; InjectComment(json.ToString()); Owner.Comment.CanComment = true; Owner.Comment.IsCommentLoading = false; //投稿者コメントがあったら取得する if (VideoData.ApiData.HasOwnerThread) { var ulist = await Owner.CommentInstance.GetUploaderCommentAsync(); dynamic ujson = new DynamicJson(); json.array = ulist; InjectUploaderComment(json.ToString()); } } if (!Settings.Instance.CommentVisibility) { InvokeScript("AsToggleComment"); } else { Owner.CommentVisibility = true; } }
public string ToJson() { dynamic root = new DynamicJson(); root.Hide3DSComment = App.ViewModelRoot.Config.NGComment.Hide3DSComment; root.HideWiiUComment = App.ViewModelRoot.Config.NGComment.HideWiiUComment; root.NGSharedLevel = App.ViewModelRoot.Config.NGComment.NGSharedLevel; root.CommentAlpha = CommentAlpha / 100; //%から小数点に root.DefaultCommentSize = DefaultCommentSize; return(root.ToString()); }
public override byte[] CreateReplyBodyBytes(RequestInfoFromLine info) { dynamic replyBody = new DynamicJson(); if (info.Message.Contains("グループID")) { replyBody.replyToken = info.ReplyToken; if (info.FromId != null) { replyBody.messages = new[] { new { type = "text", text = "このグループのURLは以下ですよ" }, new { type = "text", text = "https://script.google.com/macros/s/AKfycbz8izLdmSMTJZUGR6ZkY5UMdwAbYIXGx5THlukI61wZMQbUFN8/exec?gid=" + info.FromId// +"&version=2" } }; } } else if (info.Message.Contains("スタンプBotいらないよ")) { replyBody.replyToken = info.ReplyToken; replyBody.messages = new[] { new { type = "template", altText = "除外機能が使えないようです。管理画面URL下部のtwitterより連絡お願い致します。", template = new { type = "confirm", text = "MOB@MP M@STERをトークルームから除外しますか?", actions = new[] { new { type = "postback", label = "はい", data = "ok" }, new { type = "postback", label = "いいえ", data = "no" } } } } }; } return(Encoding.UTF8.GetBytes(replyBody.ToString())); }
protected static string MakeCreateContent(string _description, bool _isPublic, IEnumerable <Tuple <string, string> > fileContentCollection) { dynamic _result = new DynamicJson(); dynamic _file = new DynamicJson(); _result.description = _description; _result.@public = _isPublic.ToString().ToLower(); _result.files = new { }; foreach (var fileContent in fileContentCollection) { _result.files[fileContent.Item1] = new { filename = fileContent.Item1, content = fileContent.Item2 }; } return(_result.ToString()); }
public void Save() { //ロード中に呼び出されたら困る if (Loading) { return; } //このクラスのタイプを取得 var type = GetType(); //%APPDATA%/SRNicoNico/user.settingsに保存する var properties = type.GetProperties(); dynamic json = new DynamicJson(); var list = new List <object>(); foreach (var property in properties) { //ジェネリクスはちょっとややこしい //型名に<Generic>を追加する if (property.PropertyType.GenericTypeArguments.Length != 0) { string generic = "<"; foreach (var types in property.PropertyType.GenericTypeArguments) { generic += types.Name + ", "; } generic = generic.Substring(0, generic.Length - 2) + ">"; string st = property.PropertyType.Name; st = st.Split('`')[0] + generic; list.Add(new { Name = property.Name, Type = st, Value = GetNeedValue(st, property) }); } else { list.Add(new { Name = property.Name, Type = property.PropertyType.Name, Value = GetNeedValue(property.PropertyType.Name, property) }); } } json.settings = list; var s = Format(json.ToString()); var fi = new StreamWriter(Dir + "user.settings"); fi.AutoFlush = true; fi.Write(s); fi.Close(); }
public Tweet() { try { FileStream Stream = File.OpenRead("token"); var json = DynamicJson.Parse(Stream); var token = json.consumerKey; var secret = json.consumerSecret; var access = json.accessToken; var accessSecret = json.accessTokenSecret; //全て揃っていたら if(token != "?" && secret != "?" && access != "?" && accessSecret != "?") { Tokens = CoreTweet.Tokens.Create(token, secret, access, accessSecret); IsTweetButtonEnable = true; return; } //コンシューマーキーのみだったら if(token != "" && secret != "" && access == "?") { Service = OAuth.Authorize(token, secret); return; } Stream.Close(); IsTweetButtonEnable = true; } catch(FileNotFoundException) { IsTweetButtonEnable = false; StreamWriter writer = File.CreateText("token"); writer.AutoFlush = true; dynamic json = new DynamicJson(); json.consumerKey = ""; json.consumerSecret = ""; json.accessToken = ""; json.accessTokenSecret = ""; writer.WriteLine(json.ToString()); writer.Close(); } }
public override byte[] CreateReplyBodyBytes(RequestInfoFromLine info) { //友だち追加の場合、以下の固定メッセージを返す。 dynamic replyBody = new DynamicJson(); replyBody.replyToken = info.ReplyToken; replyBody.messages = new[] { new { type = "text", text = "友だち追加ありがとうございます!\r\n このBotをグループに追加する事で、\r\n モバマスのスタンプを送る事が出来ますよ!" } }; return(Encoding.UTF8.GetBytes(replyBody.ToString())); }
private void Button_Click(object sender, RoutedEventArgs e) { if (textBox_ID.Text != "" && textBox_Password.Password != "") { dynamic json = new DynamicJson(); json.id = textBox_ID.Text; json.password = textBox_Password.Password; json.proxy = textBox_Proxy.Text; File.WriteAllText("data.json", json.ToString(), new UTF8Encoding()); Window_Initialized(null, null); } else { MessageBox.Show("ID or Password is invalid.", "error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (textBox_ID.Text != "" && textBox_Password.Password != "") { dynamic json = new DynamicJson(); json.id = textBox_ID.Text; json.password = textBox_Password.Password; json.proxy = textBox_Proxy.Text; File.WriteAllText("data.json", json.ToString(), new UTF8Encoding()); Window_Initialized(null, null); } else { MessageBox.Show("IDまたはPasswordを正確に入力してください。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Since this is typically not a real "server", its ipaddress could be assigned dynamically, /// and could change each time someone wakes it up. /// </summary> private void UpdateAdvertisementBasedOnCurrentIpAddress() { if (_currentIpAddress != GetLocalIpAddress()) { _currentIpAddress = GetLocalIpAddress(); dynamic advertisement = new DynamicJson(); advertisement.title = BookTitle; advertisement.version = BookVersion; advertisement.language = TitleLanguage; advertisement.protocolVersion = WiFiPublisher.ProtocolVersion; advertisement.sender = System.Environment.MachineName; _sendBytes = Encoding.UTF8.GetBytes(advertisement.ToString()); //EventLog.WriteEntry("Application", "Serving at http://" + _currentIpAddress + ":" + ChorusHubOptions.MercurialPort, EventLogEntryType.Information); } }
public string ToJson() { dynamic data = new DynamicJson(); int LC = 0; int FC = 0; if (m_SoundData.Length >= 0) { LC = m_SoundData.Length; FC = m_SoundData[0].Length; } data["LevelCount"] = LC; data["FrameCount"] = FC; data["data"] = m_SoundData; return(data.ToString()); }
//------------------------------------------------------------------------ public void PrefSave() { dynamic root = new DynamicJson(); // ルートのコンテナ root.AerenderPath = amr.AerenderPath; root.JobCount = amr.JobCount; root.LX = this.Location.X; root.LY = this.Location.Y; root.SW = this.Size.Width; root.SH = this.Size.Height; string str = root.ToString(); string p = Path.Combine(Application.UserAppDataPath, Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".pref"); File.WriteAllText(p, str, Encoding.GetEncoding("utf-8")); }
public override byte[] CreateReplyBodyBytes(RequestInfoFromLine info) { //グループ追加の場合、以下の固定メッセージを返す。 dynamic replyBody = new DynamicJson(); replyBody.replyToken = info.ReplyToken; replyBody.messages = new[] { new { type = "text", text = "グループ追加ありがとうございます!!\r\n このグループのURLは以下です。" }, new { type = "text", text = "https://script.google.com/macros/s/AKfycbz8izLdmSMTJZUGR6ZkY5UMdwAbYIXGx5THlukI61wZMQbUFN8/exec?gid=" + info.FromId// +"&version=2" } }; return(Encoding.UTF8.GetBytes(replyBody.ToString())); }
public void Save(string cookieName, string cookieValue, Dictionary<string, string> parameters) { var collection = HttpContext.Current.Response.Headers; if (collection.AllKeys.Contains(MobileCookie.COOKIE_NAME)) { string json = collection[MobileCookie.COOKIE_NAME]; dynamic x1 = DynamicJson.Parse(json); x1[cookieName] = cookieValue; string v = x1.ToString(); collection[MobileCookie.COOKIE_NAME] = v; } else { dynamic x1 = new DynamicJson(); x1[cookieName] = cookieValue; string v = x1.ToString(); HttpContext.Current.Response.AddHeader(MobileCookie.COOKIE_NAME, v); } }
public void Save(string cookieName, string cookieValue, Dictionary <string, string> parameters) { var collection = HttpContext.Current.Response.Headers; if (collection.AllKeys.Contains(MobileCookie.COOKIE_NAME)) { string json = collection[MobileCookie.COOKIE_NAME]; dynamic x1 = DynamicJson.Parse(json); x1[cookieName] = cookieValue; string v = x1.ToString(); collection[MobileCookie.COOKIE_NAME] = v; } else { dynamic x1 = new DynamicJson(); x1[cookieName] = cookieValue; string v = x1.ToString(); HttpContext.Current.Response.AddHeader(MobileCookie.COOKIE_NAME, v); } }
public static void Gun_IN_post(int team_id, int gun_with_user_id, int location) { dynamic newjson = new DynamicJson(); newjson.team_id /*这是节点*/ = team_id; /* 这是值*/ newjson.gun_with_user_id /*这是节点*/ = gun_with_user_id; /* 这是值*/ newjson.location /*这是节点*/ = location; /* 这是值*/ int count = 0; while (true) { string result = POST.GUN_OUTandIN_Team(newjson.ToString()); switch (ResultPro.Result_Pro(ref result, "GUN_OUTandIN_Team_PRO", false)) { case 1: { return; } case 0: { continue; } case -1: { count++; if (count == 2) { return; } break; } default: break; } } }
// public string ToJson() { dynamic ardj = new DynamicJson(); ardj.header = D_Header; ardj.cellCount = data.CellCount; ardj.frameCount = data.FrameCount; ardj.pageSec = (int)data.PageSec; ardj.frameRate = (int)data.FrameRate; ardj.sheetName = data.SheetName; ardj.CREATE_USER = data.CREATE_USER; ardj.UPDATE_USER = data.UPDATE_USER; ardj.CREATE_TIME = data.CREATE_TIME; ardj.UPDATE_TIME = data.UPDATE_TIME; ardj.TITLE = data.TITLE; ardj.SUB_TITLE = data.SUB_TITLE; ardj.OPUS = data.OPUS; ardj.SCECNE = data.SCECNE; ardj.CUT = data.CUT; ardj.CAMPANY_NAME = data.CAMPANY_NAME; ardj.caption = data.GetCellCaption(); int[][][] cc = new int[data.CellCount][][]; for (int i = 0; i < data.CellCount; i++) { List <List <int> > a = data.CellLayerT(i); cc[i] = new int[a.Count][]; for (int j = 0; j < a.Count; j++) { cc[i][j] = new int[2]; cc[i][j][0] = a[j][0]; cc[i][j][1] = a[j][1]; } } ardj.cell = cc; //return DynamicJson.Serialize(ardj); return(ardj.ToString()); }
private string PrepareBattleData() { dynamic json = new DynamicJson(); json.result = new { }; var battleManager = KCDatabase.Instance.Battle; var battle = battleManager.SecondBattle ?? battleManager.FirstBattle; if (battle != null) { // TODO: Verify if this works for combined fleet. var friendCount = battle.Initial.FriendFleet.Members.Count + (battle.IsFriendCombined ? battle.Initial.FriendFleetEscort.Members.Count : 0); json.result.deckHp = battle.ResultHPs.Take(friendCount).Select(i => i < 0 ? 0 : i).ToArray(); // Enemy fleet var enemyShips = battle.Initial.EnemyMembers.Where(i => i > 0).ToList(); var enemyHp = battle.ResultHPs.Skip(12).Take(enemyShips.Count).ToList(); // Enemy escort fleet var enemyEscortShips = battle.IsEnemyCombined ? battle.Initial.EnemyMembersEscort.Where(i => i > 0).ToList() : new List <int>(); var enemyEscortHp = battle.ResultHPs.Skip(18).Take(enemyEscortShips.Count).ToList(); json.result.enemyShipId = enemyShips.Concat(enemyEscortShips).ToArray(); json.result.enemyHp = enemyHp.Concat(enemyEscortHp).ToArray(); } // TODO: our lifecycle is different than Poi! This is updated in api_req_map/start and api_req_map/next. json.result.mapCell = battleManager.Compass?.Destination; string serialized = json.ToString(); // Some issue in dynamic dispatch forced us to do this :( return(serialized); }
public bool SaveToFileJ(string path) { bool ret = false; dynamic dat = new DynamicJson(); dat["Header"] = Header; var dat2 = new object[funcTable.Length]; for (int i = 0; i < funcTable.Length; i++) { dynamic dat3 = new DynamicJson(); dat3["funcName"] = funcName[i, 0]; dat3["key"] = (double)funcTable[i].key; dat3["keysub"] = (double)funcTable[i].keySub; dat2[i] = dat3; } string js = dat.ToString(); File.WriteAllText(path, js, Encoding.GetEncoding("utf-8")); ret = File.Exists(path); return(ret); }
// *********************************************************************** public bool Export(string p) { bool ret = false; dynamic obj = new DynamicJson(); obj["out_flags"] = m_out_flags.ToObj; obj["out_flags2"] = m_out_flags2.ToObj; var json = obj.ToString(); try { File.WriteAllText(p, json, Encoding.GetEncoding("utf-8")); ret = true; } catch { ret = false; } return(ret); }
public void TestCURD() { // 将Json字符串解析成DynamicJson对象 var json = DynamicJson.Parse(@"{""foo"":""json"", ""bar"":100, ""nest"":{ ""foobar"":true } }"); // 判断json字符串中是否包含指定键 var b1_1 = json.IsDefined("foo"); // true var b2_1 = json.IsDefined("foooo"); // false // 上面的判断还可以更简单,直接通过json.键()就可以判断 var b1_2 = json.foo(); // true var b2_2 = json.foooo(); // false; // 新增操作 json.Arr = new string[] { "NOR", "XOR" }; // 新增一个js数组 json.Obj1 = new { }; // 新增一个js对象 json.Obj2 = new { foo = "abc", bar = 100 }; // 初始化一个匿名对象并添加到json字符串中 // 删除操作 json.Delete("foo"); json.Arr.Delete(0); // 还可以更简单去删除,直接通过json(键); 即可删除。 json("bar"); json.Arr(1); // 替换操作 json.Obj1 = 5000; // 创建一个新的JsonObject dynamic newjson = new DynamicJson(); newjson.str = "aaa"; newjson.obj = new { foo = "bar" }; // 直接序列化输出json字符串 var jsonstring = newjson.ToString(); // {"str":"aaa","obj":{"foo":"bar"}} }
public string ToJson() { HistryPush(); dynamic obj = new DynamicJson(); obj["Title"] = m_Combs[0].Text; obj["TitleHis"] = CombToArray(m_Combs[0]); obj["Momo1"] = m_Combs[1].Text; obj["Momo1His"] = CombToArray(m_Combs[1]); obj["Momo2"] = m_Combs[2].Text; obj["Momo2His"] = CombToArray(m_Combs[2]); obj["Date"] = m_Combs[3].Text; obj["DateHis"] = CombToArray(m_Combs[3]); obj["Campany"] = m_Combs[4].Text; obj["CampanyHis"] = CombToArray(m_Combs[4]); string ret = obj.ToString(); return(ret); }
private async void InitializeComment() { Owner.Comment.IsCommentLoading = true; var list = await Owner.CommentInstance.GetCommentAsync(); VideoData.CommentData.Clear(); if(list != null) { foreach(var entry in list) { VideoData.CommentData.Add(new CommentEntryViewModel(entry, Owner)); } dynamic json = new DynamicJson(); json.array = list; InvokeScript("CommentViewModel$initialize"); InjectComment(json.ToString()); Owner.Comment.CanComment = true; Owner.Comment.IsCommentLoading = false; //投稿者コメントがあったら取得する if(VideoData.ApiData.HasOwnerThread) { var ulist = await Owner.CommentInstance.GetUploaderCommentAsync(); dynamic ujson = new DynamicJson(); ujson.array = ulist; if(ulist != null) { foreach(var entry in ulist) { VideoData.CommentData.Add(new CommentEntryViewModel(entry, Owner)); } InjectUploaderComment(ujson.ToString()); } } } if(!Settings.Instance.CommentVisibility) { //InvokeScript("AsToggleComment"); } else { Owner.CommentVisibility = true; } }
public async void ReloadCommentAsync() { Owner.CommentStatus = "リロード中"; var list = await Owner.CommentInstance.ReloadCommentAsync(); if(list != null) { foreach(var entry in list) { int i = 0; foreach(var comment in VideoData.CommentData) { //リロードしたコメントをどこに挿入するか if(int.Parse(comment.Entry.Vpos) > int.Parse(entry.Vpos)) { VideoData.CommentData.Insert(i, new CommentEntryViewModel(entry, Owner)); break; } i++; } } dynamic json = new DynamicJson(); json.array = list; InjectComment(json.ToString()); Owner.Comment.CanComment = true; Owner.Comment.IsCommentLoading = false; } //成功しようが失敗しようが完了なのさ Owner.CommentStatus = "リロード完了"; }
public String toJsonString() { try { // just in case :) I don't trust dyamic variables, especially in c# dynamic d = new DynamicJson (); if (seed != null) { d.secret = seed.ToString (); RippleAddress r = seed.getPublicRippleAddress (); if (r != null) { d.Account = r.ToString (); } else { // todo debug } } if (encrypted_wallet != null) { d.encrypted = encrypted_wallet; if (encryption_type!=null) { d.encryption_type = encryption_type; } } else { if (seed!=null && seed.ToString()!=null) { d.secret = seed.ToString(); } } if (walletname!=null) { d.name = walletname; } object ao = new object { }; return d.ToString(); } catch (Exception e) { return null; } }
public void Open(string liveid) { using (var takeComment = new WebClient() { Encoding = Encoding.UTF8 }) { Observable.FromEventPattern<DownloadStringCompletedEventHandler, DownloadStringCompletedEventArgs> (a => takeComment.DownloadStringCompleted += a, a => takeComment.DownloadStringCompleted -= a) .ObserveOnDispatcher() .Subscribe(ret => { if (ret.EventArgs.Error != null) { this.Close(); } dynamic ijson = DynamicJson.Parse(ret.EventArgs.Result); int ccount = ijson.IsDefined("comment_num") ? (int)ijson.comment_num : 0; Enumerable.Range(1, ccount) .Where(a => ijson.IsDefined("num_" + a)) .Select(c => { dynamic comment = ijson["num_" + c]; var time = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) .AddMilliseconds(comment.time) .AddTicks(TimeZoneInfo.Local.BaseUtcOffset.Ticks); string name = ""; if (comment.auth) { name = comment.name; } return new CavetubeComment() { Name = name, PostDate = time, Number = c, Text = comment.message }; }).OrderBy(a => a.Number, (a, b) => a - b) .ForEach(a => this.RaiseOnMessage(new CavetubeClientOnMessageEventArgs(a))); this.Comments = new List<CavetubeComment>(); this.Connector.OnOpen += e => { dynamic json = new DynamicJson(); json.mode = "join"; json.room = liveid; this.Send(json.ToString()); }; this.Connector.Open(new Uri("http://ws.cavelis.net:3000/")); }); takeComment.DownloadStringAsync(new Uri("http://gae.cavelis.net/viewedit/getcomment?stream_name=" + liveid + "&comment_num=1")); } }
public string ToJson() { dynamic root = new DynamicJson(); root.Hide3DSComment = App.ViewModelRoot.Config.NGComment.Hide3DSComment; root.HideWiiUComment = App.ViewModelRoot.Config.NGComment.HideWiiUComment; root.NGSharedLevel = App.ViewModelRoot.Config.NGComment.NGSharedLevel; root.CommentAlpha = CommentAlpha / 100; //%から小数点に root.DefaultCommentSize = DefaultCommentSize; return root.ToString(); }
void JoinWebSocketHandler(object sender, WebSocketEventArgs args) { WebSocketInfo wi = args.Info; JoinInfo info = (JoinInfo)wi.State; var msg = DynamicJson.Parse(JSONEncoding.GetString(args.Payload, 0, (int)args.PayloadSize)); if (info.State == JoinState.Initialized) { Console.WriteLine("[JoinHandler] Initialized"); ALMInfo group = null; lock (groups_) { if (!groups_.TryGetValue(msg.g, out group)) group = null; } if (group == null) { dynamic retMsg = new DynamicJson(); retMsg.r = "not found"; Console.WriteLine("[JoinHandler] NotFound group"); wi.Send (retMsg.ToString(), JSONEncoding); } else { info.RequestedPeer = wi; dynamic newMemberMsg = new DynamicJson(); long ekey = Interlocked.Increment (ref ephemeral_); newMemberMsg.m = "new"; newMemberMsg.e = ekey.ToString(); newMemberMsg.s = msg.s; lock (waitings_) { waitings_.Add (ekey, info); } info.State = JoinState.IceProcess; Console.WriteLine("[JoinHandler] Relay Offer SDP"); group.Info.Send (newMemberMsg.ToString(), JSONEncoding); } return; } if (info.State == JoinState.IceProcess) { if (info.CandidatePeer == null) { lock (info.IceQueue) { info.IceQueue.Add(msg.ice); } Console.WriteLine("[JoinHandler] Ice Candidates added to queue"); } else { dynamic msg2 = new DynamicJson(); msg2.ice = msg.ice; Console.WriteLine("[JoinHandler] Relay Ice Candidates"); string json = msg2.ToString(); info.CandidatePeer.Send(json, JSONEncoding); } return; } }
protected static string MakeCreateContent(string _description, bool _isPublic, IEnumerable<Tuple<string, string>> fileContentCollection) { dynamic _result = new DynamicJson(); dynamic _file = new DynamicJson(); _result.description = _description; _result.@public = _isPublic.ToString().ToLower(); _result.files = new { }; foreach (var fileContent in fileContentCollection) { _result.files[fileContent.Item1] = new { filename = fileContent.Item1, content = fileContent.Item2 }; } return _result.ToString(); }
private void Initialize(string videoUrl) { IsActive = true; Task.Run(() => { Mylist = new VideoMylistViewModel(this); VideoData = new VideoData(); Status = "動画情報取得中"; //動画情報取得 VideoData.ApiData = NicoNicoWatchApi.GetWatchApiData(videoUrl); //ロードに失敗したら if(VideoData.ApiData == null) { LoadFailed = true; IsActive = false; Status = "動画の読み込みに失敗しました。"; return; } //有料動画なら if(VideoData.ApiData.IsPaidVideo) { App.ViewModelRoot.Messenger.Raise(new TransitionMessage(typeof(PaidVideoDialog), this, TransitionMode.Modal)); return; } DispatcherHelper.UIDispatcher.BeginInvoke(new Action(() => { while(VideoFlash == null) { Thread.Sleep(1); } if(VideoData.ApiData.Cmsid.Contains("nm")) { VideoData.VideoType = NicoNicoVideoType.SWF; WebBrowser.Source = new Uri(GetNMPlayerPath()); } else if(VideoData.ApiData.GetFlv.VideoUrl.StartsWith("rtmp")) { VideoData.VideoType = NicoNicoVideoType.RTMP; WebBrowser.Source = new Uri(GetRTMPPlayerPath()); } else { if(VideoData.ApiData.MovieType == "flv") { VideoData.VideoType = NicoNicoVideoType.FLV; } else { VideoData.VideoType = NicoNicoVideoType.MP4; } WebBrowser.Source = new Uri(GetPlayerPath()); } })); IsActive = false; Time = new VideoTime(); //動画時間 Time.VideoTimeString = NicoNicoUtil.ConvertTime(VideoData.ApiData.Length); if(VideoData.ApiData.GetFlv.IsPremium && !VideoData.ApiData.GetFlv.VideoUrl.StartsWith("rtmp")) { Task.Run(() => { Status = "ストーリーボード取得中"; NicoNicoStoryBoard sb = new NicoNicoStoryBoard(VideoData.ApiData.GetFlv.VideoUrl); VideoData.StoryBoardData = sb.GetStoryBoardData(); Status = "ストーリーボード取得完了"; }); } NicoNicoComment comment = new NicoNicoComment(VideoData.ApiData.GetFlv, this); List<NicoNicoCommentEntry> list = comment.GetComment(); if(list != null) { foreach(NicoNicoCommentEntry entry in list) { VideoData.CommentData.Add(new CommentEntryViewModel(entry)); } dynamic json = new DynamicJson(); json.array = list; DispatcherHelper.UIDispatcher.BeginInvoke(new Action(() => InjectComment(json.ToString()))); } if(!Properties.Settings.Default.CommentVisibility) { DispatcherHelper.UIDispatcher.BeginInvoke(new Action(() => InvokeScript("JsToggleComment"))); } else { CommentVisibility = true; } //App.ViewModelRoot.StatusBar.Status = "動画取得完了"; }); }
protected static string MakeEditContent(string _description, string _oldFileName, string _newFileName, string _content) { dynamic _result = new DynamicJson(); dynamic _file = new DynamicJson(); _result.description = _description; _result.files = new { }; _result.files[_oldFileName] = new { filename = _newFileName, content = _content }; return _result.ToString(); }
public void Send(string eventId, string eventData) { dynamic e = new DynamicJson(); e.id = eventId; e.payload = eventData; //note, if there is no open socket, this isn't going to do anything, and //that's (currently) fine. lock(this) { foreach (var socket in _allSockets) { socket.Send(e.ToString()); } } }
protected static string MakeDeleteFileContent(string _description, string filename) { dynamic _result = new DynamicJson(); dynamic _file = new DynamicJson(); _result.description = _description; _result.files = new { }; _result.files[filename] = "null"; return _result.ToString(); }
public void Save() { //ロード中に呼び出されたら困る if(Loading) { return; } //このクラスのタイプを取得 var type = GetType(); //%APPDATA%/SRNicoNico/user.settingsに保存する var properties = type.GetProperties(); dynamic json = new DynamicJson(); var list = new List<object>(); foreach(var property in properties) { //ジェネリクスはちょっとややこしい //型名に<Generic>を追加する if(property.PropertyType.GenericTypeArguments.Length != 0) { string generic = "<"; foreach(var types in property.PropertyType.GenericTypeArguments) { generic += types.Name + ", "; } generic = generic.Substring(0, generic.Length - 2) + ">"; string st = property.PropertyType.Name; st = st.Split('`')[0] + generic; list.Add(new { Name = property.Name, Type = st, Value = GetNeedValue(st, property) }); } else { list.Add(new { Name = property.Name, Type = property.PropertyType.Name, Value = GetNeedValue(property.PropertyType.Name, property) }); } } json.settings = list; var s = Format(json.ToString()); var fi = new StreamWriter(Dir + "user.settings"); fi.AutoFlush = true; fi.Write(s); fi.Close(); }
void CandidateWebSocketHandler(object sender, WebSocketEventArgs args) { WebSocketInfo wi = args.Info; CandidateInfo info = (CandidateInfo)wi.State; var msg = DynamicJson.Parse (JSONEncoding.GetString (args.Payload, 0, (int)args.PayloadSize)); string errMsg = string.Empty; if (info.State == CandidateState.Initialized) { Console.WriteLine ("[CandidateHandler] Initialized"); long key; if (!msg.IsDefined ("e") || !msg.IsDefined ("s") || !long.TryParse (msg.e, out key)) { errMsg = "msg format error"; goto OnError; } JoinInfo join_info = null; lock (waitings_) { if (!waitings_.TryGetValue (key, out join_info)) { errMsg = "ignore"; goto OnError; } waitings_.Remove (key); } join_info.CandidatePeer = wi; info.Info = join_info; info.State = CandidateState.IceProcess; dynamic msg2 = new DynamicJson (); msg2.r = "ok"; msg2.s = msg.s; join_info.RequestedPeer.Send (msg2.ToString (), JSONEncoding); Console.WriteLine ("[CandidateHandler] Relay SDP to join requested peer"); lock(join_info.IceQueue) { foreach(string ice_cand in join_info.IceQueue) { msg2 = new DynamicJson(); msg2.ice = ice_cand; Console.WriteLine("[CandidateHandler] Relay Queued Ice Candidates"); info.Info.RequestedPeer.Send(msg2.ToString(), JSONEncoding); } } return; } if (info.State == CandidateState.IceProcess) { dynamic msg2 = new DynamicJson(); msg2.ice = msg.ice; Console.WriteLine("[CandidateHandler] Relay Ice Candidates"); info.Info.RequestedPeer.Send(msg2.ToString(), JSONEncoding); return; } OnError: Console.WriteLine("[CandidateHandler] ERROR: {0}", errMsg); dynamic retMsg = new DynamicJson (); retMsg.r = errMsg; wi.Send (retMsg.ToString (), JSONEncoding); wi.Close (); }
/// <summary> /// Get JSON string of stroke object /// </summary> /// <returns>JSON strings representing stroke object</returns> public String GetJsonString() { String ret = null; List<object> pointArr = new List<object>(); for (int i = 0, ilen = this.Points.Count; i < ilen; i++) { var elem = new { time = this.Points[i].Time, x = this.Points[i].X, y = this.Points[i].Y, }; pointArr.Add(elem); } dynamic json = new DynamicJson(); json.stroke = pointArr; ret = json.ToString(); return ret; }
public void GetAllData_LocalOnly_ReturnLocal() { var c = new Configurator(_libraryFolder.Path); dynamic j = new DynamicJson(); j.one = 1; c.CollectJsonData(j.ToString()); Assert.AreEqual(j, DynamicJson.Parse(c.GetAllData())); }
public void GetLibraryData_NoGlobalData_Empty() { var first = new Configurator(_libraryFolder.Path); dynamic j = new DynamicJson(); j.one = 1; first.CollectJsonData(j.ToString()); Assert.AreEqual("{}", first.GetLibraryData()); }
void GroupOwnerWebSocketHandler(object sender, WebSocketEventArgs args) { WebSocketInfo wi = args.Info; ALMInfo info = (ALMInfo)wi.State; var msg = DynamicJson.Parse(JSONEncoding.GetString(args.Payload, 0, (int)args.PayloadSize)); if (info.State == ALMGroupState.Initialized) { info.GroupID = msg.g; info.GroupName = msg.IsDefined("n") ? msg.n : info.GroupID; info.GroupDescription = msg.IsDefined("d") ? msg.d : string.Empty; dynamic retMsg = new DynamicJson(); lock (groups_) { if (groups_.ContainsKey(info.GroupID)) { info.State = ALMGroupState.Error; retMsg.r = "group_id already exists"; } else { groups_.Add (info.GroupID, info); info.State = ALMGroupState.Created; retMsg.r = "ok"; info.Info = wi; } } wi.Send (retMsg.ToString(), JSONEncoding); return; } if (info.State == ALMGroupState.Created) { } }
public void WhenCollectedNoGlobalDataThenGlobalDataIsEmpty() { var first = new Configurator(_libraryFolder.Path); dynamic j = new DynamicJson(); j.one = 1; first.CollectJsonData(j.ToString()); Assert.AreEqual(j, DynamicJson.Parse(first.LocalData)); }
/// <summary> /// SetJson /// </summary> /// <returns>json</returns> private string SetJson() { dynamic json = new DynamicJson(); json["Name"] = this.Name; json["Sid"] = this.Sid; json["LoginTime"] = this.LoginTime; return json.ToString(); }