Esempio n. 1
0
        public void lataaFillarit()
        {
            if (new FileInfo(fillaritTiedosto).Length == 0)
            {
                return;
            }

            KnownTypesBinder loKnownTypesBinder = new KnownTypesBinder()
            {
                KnownTypes = new List <Type> {
                    typeof(Polkupyora)
                }
            };

            JsonSerializerSettings loJsonSerializerSettings = new JsonSerializerSettings()
            {
                TypeNameHandling    = TypeNameHandling.Objects,
                SerializationBinder = loKnownTypesBinder,
                Formatting          = Formatting.Indented
            };

            polkupyorat = JsonConvert.DeserializeObject <List <Polkupyora> >(File.ReadAllText(fillaritTiedosto), loJsonSerializerSettings);

            if (polkupyorat.Count > maxLkm)
            {
                polkupyorat.RemoveRange(maxLkm, polkupyorat.Count - maxLkm);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Tallentaa telineessä olevat polkupyörät JSON muodossa tiedostoon
        /// </summary>
        public void tallennaFillarit()
        {
            KnownTypesBinder loKnownTypesBinder = new KnownTypesBinder()
            {
                KnownTypes = new List <Type> {
                    typeof(Polkupyora)
                }
            };

            IEnumerable <Polkupyora> Data = polkupyorat.AsEnumerable();

            JsonSerializerSettings loJsonSerializerSettings = new JsonSerializerSettings()
            {
                TypeNameHandling    = TypeNameHandling.Objects,
                SerializationBinder = loKnownTypesBinder,
                Formatting          = Formatting.Indented
            };

            String json = JsonConvert.SerializeObject(Data, loJsonSerializerSettings);

            File.WriteAllText(fillaritTiedosto, json);
        }
Esempio n. 3
0
        // Tallentaa ruudut tiedostoon
        public void tallennaParkkipaikat()
        {
            KnownTypesBinder loKnownTypesBinder = new KnownTypesBinder()
            {
                KnownTypes = new List <Type> {
                    typeof(Auto), typeof(Moottoripyora)
                }
            };

            IEnumerable <Parkkipaikka> Data = parkkipaikat.AsEnumerable();

            JsonSerializerSettings loJsonSerializerSettings = new JsonSerializerSettings()
            {
                TypeNameHandling    = TypeNameHandling.Objects,
                SerializationBinder = loKnownTypesBinder,
                Formatting          = Formatting.Indented
            };

            String json = JsonConvert.SerializeObject(Data, loJsonSerializerSettings);

            File.WriteAllText(autotTiedosto, json);
        }
Esempio n. 4
0
        // Lataa ruudut tiedostosta
        public void lataaParkkipaikat()
        {
            if (new FileInfo(autotTiedosto).Length == 0)
            {
                return;
            }

            KnownTypesBinder loKnownTypesBinder = new KnownTypesBinder()
            {
                KnownTypes = new List <Type> {
                    typeof(Auto), typeof(Moottoripyora), typeof(Parkkipaikka)
                }
            };


            JsonSerializerSettings loJsonSerializerSettings = new JsonSerializerSettings()
            {
                TypeNameHandling    = TypeNameHandling.Objects,
                SerializationBinder = loKnownTypesBinder,
                Formatting          = Formatting.Indented
            };

            this.parkkipaikat = JsonConvert.DeserializeObject <List <Parkkipaikka> >(File.ReadAllText(autotTiedosto), loJsonSerializerSettings);
        }