public void ToArrayTest_JsonContains() { var o = new Dictionary <string, object>(); o.Add("child1", "a"); o.Add("child2", "b"); var o2 = new Dictionary <string, object>(); o2.Add("child1", "a"); o2.Add("child2", "b"); var s = new[] { o, o2 }; var content = new Dictionary <string, object>(); content.Add("key", s); var jsonContainer = new JsonContainer(content); JsonContainer[] target = jsonContainer.ToArray <JsonContainer>("key"); Assert.AreEqual("a", target[0].ToString("child1")); Assert.AreEqual("b", target[0].ToString("child2")); Assert.AreEqual("a", target[1].ToString("child1")); Assert.AreEqual("b", target[1].ToString("child2")); }
public ActionResult Search(SearchViewModel model, int?page) { List <SearchResult> tempList = new List <SearchResult>(); if (ModelState.IsValid) { MainResult = _deepServce.LoadFullJson(); tempList = MainResult.people.Where(item => item.name.Contains(model.Name)) .Select(item => new SearchResult { BirthPlace = getPlaceName(Convert.ToInt32(item.place_id)), Gender = string.IsNullOrEmpty(item.gender) ? "" : (item.gender == "M" ? "Male" : "Female"), Id = item.id, Name = item.name }).ToList(); if (!string.IsNullOrEmpty(model.Gender)) { tempList = tempList.Where(item => item.Gender.ToLower() == (model.Gender.ToLower() == "m" ? "male" : "female")).ToList(); } model.PageNumber = page ?? 1; model.PageCount = tempList.Count; model.Results = tempList.ToPagedList(page ?? 1, 10); } return(View(model)); }
public void AnaylzTheKeyTest_PathError() { var content = new Dictionary <string, object> { { "l1", new Dictionary <string, object> { { "l1-1", new Dictionary <string, object> { { "value", Int32.MaxValue } } } } } }; var current = new JsonContainer(content); string keyPath = "l1.l2.value"; string lastKey; string lastKeyExpect = "value"; JsonContainer actual = JsonContainer_Accessor.AnaylzTheKey(keyPath, out lastKey, current); Assert.AreEqual(lastKeyExpect, lastKey); Assert.AreEqual(Int32.MaxValue, actual.ToInt32(lastKey)); }
public JsonResult GetSubNode(JsonContainer jsonData) { var model = Session[Definitions.SMART_CONFIG_SESSION_KEY] as SmartConfigDataModel; if (!string.IsNullOrEmpty(jsonData.JsonString) && null != model) { if (jsonData.JsonString.StartsWith("N/A")) { return(Json(new JsonContainer { JsonString = "<div/>" })); } var node = model.GetConfigNodeByJPath(jsonData.JsonString); if (null != node) { var subNodeHtml = _RenderToHtmlString(PartialView("_ConfigTreeNode", node)); var idx = jsonData.JsonString.LastIndexOf('.'); if (-1 != idx) { var parentNode = model.GetConfigNodeByJPath(jsonData.JsonString.Substring(0, idx)); if (null != parentNode) { node.CurrentSelectedSubPath = jsonData.JsonString; } } var subNodeInfo = new SubnodeInfo(); subNodeInfo.SubnodeHtml = subNodeHtml; subNodeInfo.SelectedNextSubNodePath = node.CurrentSelectedSubPath; this._UpdateSessionModel(model); return(Json(subNodeInfo)); } } return(null); }
//main method public static Environment Initialize(string path, byte[] data = null) { templateParts = new List <GameObject>(); ruleLookup = new Dictionary <string, int>(); if (path != null) { jsonCont = LoadFromWasp(path); } else { jsonCont = LoadFromWaspFile(data); } GlobalReferences.RuleMatrix = BuildRuleMatrix(); GlobalReferences.Rules = LoadRules(); GlobalReferences.RuleGroups = LoadRuleGrammar(); GlobalReferences.AdditionalGeometry = BuildAdditional(); GlobalReferences.BlueprintGeometry = BuildBlueprint(); return(jsonCont.environment); }
/// <summary> /// Cache Country Percentages /// </summary> public void CacheCountryPercentages() { var data = new StatsCountryPercentages().CallObjects <CountryPercentage>(); var blob = new JsonContainer(); blob.Save("globalheatmap", data); }
private async Task EbayScrape(string term) { var ebaysearchurl = EbayBaseUrl + term; EbayScraper ebayScraper = new EbayScraper(); _jsonContainer = await ebayScraper.BeginScrapeAsync(ebaysearchurl); }
private async Task AmazonScrape(string term) { var amazonnsearchurl = AmazonBaseUrl + term; AmazonScraper amazonScraper = new AmazonScraper(); _jsonContainer = await amazonScraper.BeginScrapeAsync(amazonnsearchurl); }
public ActionResult loadCourseTimings(string courseName) { var Jcon = new JsonContainer(); var objCourseHelper = new CourseHelper(); var courseDetails = new Course { userId = 0, courseName = string.Empty, startTime = string.Empty, endTime = string.Empty }; var dtCourse = objCourseHelper.SearchCourse(courseDetails); List <Course> courseList = new List <Course>(); foreach (DataRow dr in dtCourse.Rows) { var course = new Course { startTime = dr["startTime"].ToString(), endTime = dr["startTime"].ToString() + " - " + dr["endTime"].ToString() }; courseList.Add(course); } Jcon.Result = courseList.Distinct().OrderBy(x => x.startTime).ToList(); return(Json(Jcon)); }
byte[] SerializeObject(object o) { using (var ms = new MemoryStream()) { if (m_UseJson) { // see: https://stackoverflow.com/questions/25741895/error-serialising-simple-string-to-bson-using-newtonsoft-json-net //var containerArray = Array.CreateInstance(o.GetType(), 1); //containerArray.SetValue(o, 0); var containerObj = new JsonContainer() { PayLoad = o }; using (var w = new BsonWriter(ms)) { jsonFormatter.Serialize(w, containerObj); } } else { m_Formatter.Serialize(ms, o); } byte[] ret = ms.GetBuffer(); //if (ret.Length > ms.Position) { // Array.Resize(ref ret, (int)ms.Position); //} return(ret); } }
/// <summary> /// Home Page /// </summary> /// <returns>Action Result</returns> public ActionResult Index(string ReturnUrl = null) { if (base.User.Identity.IsAuthenticated) { var cookie = Request.Cookies[returnCookieName]; if (null == cookie || string.IsNullOrWhiteSpace(cookie.Value)) { return(this.RedirectToAction("Index", "Dashboard")); } else { cookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Set(cookie); return(Redirect(cookie.Value)); } } else { if (!string.IsNullOrWhiteSpace(ReturnUrl)) { var cookie = new HttpCookie(returnCookieName, ReturnUrl) { Expires = DateTime.Now.AddHours(1), }; Response.Cookies.Add(cookie); } var theme = Request.QueryString["theme"]; if (!string.IsNullOrWhiteSpace(theme)) { var cookie = new HttpCookie(ThemeCookieName, theme) { Expires = DateTime.Now.AddDays(31), }; Response.Cookies.Add(cookie); } var emptyHomePage = new HomePage() { Share = new ItemShare(), }; try { if (null == homePage) { var blob = new JsonContainer(); homePage = blob.Get <HomePage>("landingpage"); } } catch { } return(View(homePage ?? emptyHomePage)); } }
public ActionResult UpdateSelectedViewType(JsonContainer jsonData) { var model = Session[Definitions.BKC_IMAGE_PARSER_KEY] as BkcImageParserModel; model.SelectedParserViewType = jsonData.JsonString; Session[Definitions.BKC_IMAGE_PARSER_KEY] = model; return(Json(model)); }
public HltReader(string filename) { using (var r = new StreamReader(filename)) { var serializer = new DataContractJsonSerializer(typeof(JsonContainer)); this.hlt = serializer.ReadObject(r.BaseStream) as JsonContainer; } }
public JsonContainer LoadFullJson() { using (StreamReader r = new StreamReader(HostingEnvironment.ApplicationPhysicalPath + @"\JsonFiles" + @"\data_large.json")) { string json = r.ReadToEnd(); JsonContainer items = JsonConvert.DeserializeObject <JsonContainer>(json); return(items); } }
protected override void Awake() { base.Awake(); //#if UNITY_ANDROID Application.targetFrameRate = 60; //#endif JsonContainer.JsonLoad(out StageData); }
public ActionResult searchResults(string courseName, string courseTiming) { string startTime = string.Empty, endTime = string.Empty; courseName = string.IsNullOrEmpty(courseName) ? "-SELECT-" : courseName; courseTiming = string.IsNullOrEmpty(courseTiming) ? "-SELECT-" : courseTiming; if (courseName.ToUpper() == "-SELECT-") { courseName = string.Empty; } if (courseTiming.ToUpper() == "-SELECT-") { courseTiming = string.Empty; } else { var substrings = courseTiming.Split('-'); startTime = substrings[0].Trim(' '); endTime = substrings[1].Trim(' '); } var Jcon = new JsonContainer(); var objCourseHelper = new CourseHelper(); var courseDetails = new Course { userId = 0, courseName = courseName, startTime = startTime, endTime = endTime }; var dtCourse = objCourseHelper.SearchCourse(courseDetails); List <Course> courseList = new List <Course>(); foreach (DataRow dr in dtCourse.Rows) { var course = new Course { courseName = dr["courseName"].ToString(), courseDescription = dr["courseDescription"].ToString(), courseCategory = dr["courseCategory"].ToString(), startTime = dr["startTime"].ToString(), endTime = dr["endTime"].ToString(), numberOfStudent = long.Parse(dr["numberOfStudent"].ToString()), instructorName = dr["instructorName"].ToString() }; courseList.Add(course); } Jcon.Result = courseList.Distinct().OrderBy(x => x.courseName).ToList(); return(Json(Jcon)); }
public JsonResult UpdateRawDataContents(JsonContainer jsonData) { var model = Session[Definitions.SMART_CONFIG_SESSION_KEY] as SmartConfigDataModel; ConfigTreeNode node = null; var jsonContainer = new JsonContainer(); if (null != model) { var serializer = new JsonSerializer(); var reader = new JsonTextReader(new StringReader(jsonData.JsonString)); var updateInfo = serializer.Deserialize <RawDataMapInfo>(reader); node = model.GetConfigNodeByGuid(updateInfo.Id); if (null != node) { if (!string.IsNullOrEmpty(updateInfo.RawDataMap.Offset)) { node.RawDataMap.Offset = updateInfo.RawDataMap.Offset; node.NodeEditStatus = ConfigNodeStatus.Modified.ToString(); } if (!string.IsNullOrEmpty(updateInfo.RawDataMap.Size)) { node.RawDataMap.Size = updateInfo.RawDataMap.Size; node.NodeEditStatus = ConfigNodeStatus.Modified.ToString(); } if (!string.IsNullOrEmpty(updateInfo.RawDataMap.Value)) { var val = updateInfo.RawDataMap.Value; if (val == EditDataType.DataSizeEdit.ToString() || val == EditDataType.RawDataEdit.ToString()) { node.RawDataMap.EditType = val; } else { node.RawDataMap.Value = val; var buffer = val.Replace(" ", string.Empty).HexStringToByteArray(); if (null != buffer) { var offset = node.RawDataMap.Offset.HexToLong(); if (node.RawDataMap.TargetBinaryStream.CanSeek) { node.RawDataMap.TargetBinaryStream.Seek(offset.Value, SeekOrigin.Begin); node.RawDataMap.TargetBinaryStream.Write(buffer, 0, buffer.Length); } } } node.NodeEditStatus = ConfigNodeStatus.Modified.ToString(); } jsonContainer.JsonString = _RenderToHtmlString(PartialView("_ConfigTreeNodeContents", node)); } this._UpdateSessionModel(model); } return(Json(jsonContainer)); }
public ActionResult UpdateSelectedPlatform(JsonContainer jsonData) { var model = Session[Definitions.RELEASE_ORCHSTRATION_KEY] as ReleaseOrchstrationModel; if (null != jsonData) { model.SelectedPlatform = jsonData.JsonString; _UpdateSessionModel(model); } return(Json(model[model.SelectedPlatform.ToString()])); }
/// <summary> /// Cache Home Page Data /// </summary> public void CacheHomePageData() { var data = new HomePageData() { Share = new GoodsRecentItemShare().CallObject <HomePageShare>(), }; var blob = new JsonContainer(); blob.Save("landingpage", data); }
public LsfFont( Stream stream ) { fileSystem = new ZipFileSystem ( stream ); Stream file = fileSystem.OpenFile ( "info.json" ); JsonContainer entry = new JsonContainer ( file ); FontFamily = entry [ "fontfamily" ] as string; FontSize = ( int ) entry [ "fontsize" ]; Texture2DContentLoader.AddDefaultDecoders (); imageContentLoader = new Texture2DContentLoader (); }
public void ExportStrings(string filename) { using (var writer = new StreamWriter(filename)) { var obj = new JsonContainer() { filetype = "strings", data = strings }; writer.Write(JsonConvert.SerializeObject(obj, Formatting.Indented)); } }
public ActionResult UpdateSelectedConfigJson(JsonContainer jsonData) { var model = Session[Definitions.BKC_IMAGE_PARSER_KEY] as BkcImageParserModel; if (null != jsonData && jsonData.JsonString != "N/A") { model.SelectedEmbeddedJson = jsonData.JsonString; _UpdateSessionModel(model); } return(Json(model)); }
public ActionResult SecurityGroups() { List <Dictionary <string, string> > lstgroups = _repository.GetSecurityGroups(); JsonContainer <List <Dictionary <string, string> > > container = new JsonContainer <List <Dictionary <string, string> > >(); container.items = lstgroups; container.success = true; container.total = lstgroups.Count; return(Json(container, JsonRequestBehavior.AllowGet)); }
public static long Get(Currency currency, JsonContainer collection) { object value; collection.TryGetValue(currency.ShortName, out value); if (value == null) { return(0); } return(Convert.ToInt64(value)); }
public ActionResult DataLayers() { DataLayers dataLayers = _repository.GetDataLayers(); JsonContainer <DataLayers> container = new JsonContainer <DataLayers>(); container.items = dataLayers; container.success = true; container.total = dataLayers.Count; return(Json(container, JsonRequestBehavior.AllowGet)); }
public ActionResult InitializeUISettings() { NameValueList nvlSettings = _repository.GetGlobalVariables(); JsonContainer <NameValueList> container = new JsonContainer <NameValueList>(); container.items = nvlSettings; container.success = true; container.total = nvlSettings.Count; return(Json(container, JsonRequestBehavior.AllowGet)); }
public void AnaylzTheKeyTest_FirstKeyError() { var content = new Dictionary <string, object> { { "l1", 1 } }; var current = new JsonContainer(content); string keyPath = "notExist"; string lastKey; JsonContainer actual = JsonContainer_Accessor.AnaylzTheKey(keyPath, out lastKey, current); }
public ArcadeContainer() { Users = new JsonContainer <ArcadeUser>(@"..\data\users\"); Guilds = new JsonContainer <BaseGuild>(@"..\data\guilds\"); Data = JsonHandler.Load <ArcadeData>(@"..\data\global.json") ?? new ArcadeData(); // This is used to rename and replace all old vars that were stored foreach (ArcadeUser user in Users.Values.Values) { Stats.RenameIds(user); } }
public override void Load(ContentManager Content) { base.Load(Content); JsonContainer MetaJson = Content.Load <JsonContainer>(Filename + ".meta"); Meta = JsonConvert.DeserializeObject <AsepriteData>(MetaJson.Data); for (int i = 0; i < Meta.meta.frameTags.Length; i++) { Animations.Add(Meta.meta.frameTags[i].name, Meta.meta.frameTags[i]); } }
/// <summary> /// "Minifies" a container of money, making it so that it takes up the smallest amount of coinage. /// </summary> /// <param name="container"></param> public static void Minify(JsonContainer container) { var value = Convert.ToDecimal(GetValue(container)); Clear(container); foreach (var currency in Game.Data.AllCurrencies) { var coins = Math.Floor(value / Convert.ToDecimal(currency.Value)); Set(currency, container, Convert.ToInt64(coins)); value -= (coins * currency.Value); } }
private static JsonContainer LoadFromWasp(string path) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(JsonContainer)); JsonContainer partsAndRules = null; using (FileStream stream = new FileStream(path, FileMode.Open)) { partsAndRules = serializer.ReadObject(stream) as JsonContainer; } return(partsAndRules); }
public object Read( Stream stream, ResourceTable resourceTable, params object [] args ) { try { return new Sprite ( textureContentLoader.Read ( stream, resourceTable, args ) as ITexture2D ); } catch { JsonContainer data = new JsonContainer ( stream ); Sprite sprite = new Sprite ( null ); if ( data.Contains ( "colorkey" ) ) { JsonContainer colorKey = data [ "colorkey" ] as JsonContainer; sprite.Texture = textureContentLoader.Read ( new MemoryStream ( Convert.FromBase64String ( data [ "image" ] as string ) ), resourceTable, new Color ( ( byte ) colorKey [ 0 ], ( byte ) colorKey [ 1 ], ( byte ) colorKey [ 2 ], ( byte ) colorKey [ 3 ] ) ) as ITexture2D; } else sprite.Texture = textureContentLoader.Read ( new MemoryStream ( Convert.FromBase64String ( data [ "image" ] as string ) ), resourceTable ) as ITexture2D; if ( data.Contains ( "cliparea" ) ) { JsonContainer clipArea = data [ "clipArea" ] as JsonContainer; if ( clipArea.ContainerType == ContainType.Object ) { sprite.ClippingArea = new Rectangle ( ( int ) clipArea [ "left" ], ( int ) clipArea [ "top" ], ( int ) clipArea [ "right" ] - ( int ) clipArea [ "left" ], ( int ) clipArea [ "bottom" ] - ( int ) clipArea [ "top" ] ); } else { sprite.ClippingArea = new Rectangle ( ( int ) clipArea [ 0 ], ( int ) clipArea [ 1 ], ( int ) clipArea [ 2 ] - ( int ) clipArea [ 0 ], ( int ) clipArea [ 3 ] - ( int ) clipArea [ 1 ] ); } } if ( data.Contains ( "overlay" ) ) { JsonContainer overlay = data [ "overlay" ] as JsonContainer; sprite.OverlayColor = new Color ( ( byte ) overlay [ 0 ], ( byte ) overlay [ 1 ], ( byte ) overlay [ 2 ], ( byte ) overlay [ 3 ] ); } return sprite; } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpRequestBase request = filterContext.RequestContext.HttpContext.Request; ParameterDescriptor[] parameterNames = filterContext.ActionDescriptor.GetParameters(); if (!_submitDirectJquery) { NameValueCollection requestKeySet = request.HttpMethod.ToLower() == "post" ? request.Form : request.QueryString; if (requestKeySet.Keys[0] != null) { foreach (ParameterDescriptor parameterName in parameterNames) { if (parameterName.ParameterType == typeof (JsonContainer)) { filterContext.ActionParameters[parameterName.ParameterName] = JsonContainer.Create(requestKeySet[parameterName.ParameterName]); } } } else { filterContext.ActionParameters[parameterNames[0].ParameterName] = JsonContainer.Create(requestKeySet[0]); } } else { var jquerySet = new Dictionary<string, JsonContainer>(); foreach (ParameterDescriptor parameterName in parameterNames) { if (parameterName.ParameterType == typeof (JsonContainer)) { var json = new JsonContainer(); jquerySet.Add(parameterName.ParameterName, json); filterContext.ActionParameters[parameterName.ParameterName] = json; } } MakeJsonContainer(request, jquerySet); } }
void AddContainer(JsonContainer container) { if (stack.Count != 0) { var parentContainer = stack.Peek(); parentContainer.AddChild(container.JsonValue); } stack.Push(container); if (stack.Count == 1) root = stack.Peek().JsonValue; }
public static PackageInfo LoadFromFileSystem( IFileSystem fileSystem ) { if ( !fileSystem.IsFileExist ( "packageInfo.json" ) ) throw new ArgumentException (); PackageInfo packageInfo = new PackageInfo (); JsonContainer entry = new JsonContainer ( fileSystem.OpenFile ( "packageInfo.json" ) ); packageInfo.PackageName = entry [ "title" ] as string; packageInfo.Author = entry [ "author" ] as string; packageInfo.Copyright = entry [ "copyright" ] as string; packageInfo.Description = entry [ "description" ] as string; packageInfo.PackageID = new Guid ( entry [ "packId" ] as string ); packageInfo.Version = new Version ( entry [ "version" ] as string ); packageInfo.ReleaseDate = DateTime.Parse ( entry [ "release_date" ] as string ); if ( packageInfo.IsSubPackage = ( bool ) entry [ "issubpack" ] ) { List<Guid> mainGuid = new List<Guid> (); JsonContainer mainPackIds = entry [ "mainpacks" ] as JsonContainer; foreach ( object item in mainPackIds.GetListEnumerable () ) mainGuid.Add ( new Guid ( item as string ) ); if ( !mainGuid.Contains ( Core.MainPackage.PackageID ) ) { bool isContains = false; foreach ( PackageInfo subpack in Core.SubPackages ) if ( mainGuid.Contains ( subpack.PackageID ) ) isContains = true; if ( !isContains ) throw new ArgumentException ( "This package is not allowed to this package." ); } packageInfo.MainPackageIDs = mainGuid.ToArray (); } if ( fileSystem.IsFileExist ( "packageCover.png" ) ) { ImageInfo imageInfo; new PngDecoder ().Decode ( fileSystem.OpenFile ( "packageCover.png" ), out imageInfo ); packageInfo.PackageCover = imageInfo; } if ( fileSystem.IsFileExist ( "stringTable.stt" ) ) packageInfo.StringTable = new StringTable ( fileSystem.OpenFile ( "stringTable.stt" ) ); if ( fileSystem.IsFileExist ( "resourceTable.rst" ) ) packageInfo.ResourceTable = new ResourceTable ( new ZipFileSystem ( fileSystem.OpenFile ( "resourceTable.rst" ) ) ); return packageInfo; }
private void listViewLanguages_DoubleClick( object sender, EventArgs e ) { if ( listViewLanguages.SelectedItems.Count > 0 ) { listViewEditor.Items.Clear (); string key = listViewLanguages.SelectedItems [ 0 ].Text; opened = data [ key ] as JsonContainer; listViewEditor.Enabled = true; foreach ( KeyValuePair<object, object> s in opened.GetDictionaryEnumerable () ) { listViewEditor.Items.Add ( s.Key as string ).SubItems.Add ( s.Value as string ); } } }
private void NewFile() { if ( !CheckSave () ) return; saved = true; savePath = null; data = new JsonContainer ( ContainType.Object ); data.Add ( "1.0", "tableversion" ); data.Add ( "Misty String Table Editor", "generator" ); data.Add ( new JsonContainer ( ContainType.Object ), "unknown" ); listViewLanguages.Items.Add ( "unknown" ); SetTitle (); }
private void OpenFile() { if ( !CheckSave () ) return; if ( openFileDialog1.ShowDialog () == DialogResult.Cancel ) return; using ( Stream stream = new FileStream ( openFileDialog1.FileName, FileMode.Open, FileAccess.Read ) ) { data = new JsonContainer ( stream ); listViewLanguages.Items.Clear (); listViewEditor.Items.Clear (); listViewEditor.Enabled = false; opened = null; foreach ( KeyValuePair<object, object> i in data.GetDictionaryEnumerable () ) if ( !( i.Key as string == "tableversion" || i.Key as string == "generator" ) ) listViewLanguages.Items.Add ( i.Key as string ); } saved = true; savePath = openFileDialog1.FileName; SetTitle (); }
private bool SaveFile() { if ( savePath == null ) return SaveAsFile (); using ( Stream stream = new FileStream ( savePath, FileMode.Create, FileAccess.Write ) ) { byte [] data; if ( Path.GetExtension ( saveFileDialog1.FileName ) == "bson" ) data = this.data.ToBinary (); else data = Encoding.UTF8.GetBytes ( this.data.ToString () ); stream.Write ( data, 0, data.Length ); } saved = true; return true; }