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"));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
    //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);
    }
Exemplo n.º 6
0
        /// <summary>
        /// Cache Country Percentages
        /// </summary>
        public void CacheCountryPercentages()
        {
            var data = new StatsCountryPercentages().CallObjects <CountryPercentage>();
            var blob = new JsonContainer();

            blob.Save("globalheatmap", data);
        }
Exemplo n.º 7
0
        private async Task EbayScrape(string term)
        {
            var         ebaysearchurl = EbayBaseUrl + term;
            EbayScraper ebayScraper   = new EbayScraper();

            _jsonContainer = await ebayScraper.BeginScrapeAsync(ebaysearchurl);
        }
Exemplo n.º 8
0
        private async Task AmazonScrape(string term)
        {
            var           amazonnsearchurl = AmazonBaseUrl + term;
            AmazonScraper amazonScraper    = new AmazonScraper();

            _jsonContainer = await amazonScraper.BeginScrapeAsync(amazonnsearchurl);
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        /// <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));
            }
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
 public HltReader(string filename)
 {
     using (var r = new StreamReader(filename))
     {
         var serializer = new DataContractJsonSerializer(typeof(JsonContainer));
         this.hlt = serializer.ReadObject(r.BaseStream) as JsonContainer;
     }
 }
Exemplo n.º 14
0
 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);
     }
 }
Exemplo n.º 15
0
    protected override void Awake()
    {
        base.Awake();
//#if UNITY_ANDROID
        Application.targetFrameRate = 60;
//#endif

        JsonContainer.JsonLoad(out StageData);
    }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        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()]));
        }
Exemplo n.º 19
0
        /// <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);
        }
Exemplo n.º 20
0
        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 ();
        }
Exemplo n.º 21
0
 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));
     }
 }
Exemplo n.º 22
0
        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));
        }
Exemplo n.º 23
0
        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));
        }
Exemplo n.º 24
0
        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));
        }
Exemplo n.º 25
0
        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));
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 28
0
        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);
            }
        }
Exemplo n.º 29
0
        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]);
            }
        }
Exemplo n.º 30
0
        /// <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);
            }
        }
Exemplo n.º 31
0
    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);
    }
Exemplo n.º 32
0
        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;
            }
        }
Exemplo n.º 33
0
        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);
            }
        }
Exemplo n.º 34
0
        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;
        }
Exemplo n.º 35
0
        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;
        }
Exemplo n.º 36
0
 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 );
         }
     }
 }
Exemplo n.º 37
0
        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 ();
        }
Exemplo n.º 38
0
        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 ();
        }
Exemplo n.º 39
0
        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;
        }