예제 #1
0
        public void XmlSer_testDeserialize_ReturnsCorrectProperties()
        {
            //arrange
            const string guid       = "eb31d4ff-be0b-4366-9838-994ed803dd69";
            const string title      = "TestBezeichnung";
            DateTime     valutaDate = new DateTime(2010, 09, 10);
            const string type       = "Quittungen";
            const string notes      = "TestStichwort";
            DateTime     entryDate  = new DateTime(2020, 09, 10);
            const string username   = "******";
            MetadataItem testItem   = new MetadataItem(guid, title, valutaDate, type, notes, entryDate, username);
            XmlSer       des        = new XmlSer();

            des.SerializeFile(testItem, "Testordner\\Deserialisierung.xml");

            //act
            MetadataItem result = des.DeserializeFile <MetadataItem>("Testordner\\Deserialisierung.xml");

            //assert
            Assert.That(result, Is.TypeOf <MetadataItem>());
            Assert.That(result.Guid, Is.EqualTo("eb31d4ff-be0b-4366-9838-994ed803dd69"));
            Assert.That(result.Title, Is.EqualTo("TestBezeichnung"));
            Assert.That(result.ValutaDate, Is.EqualTo(new DateTime(2010, 09, 10)));
            Assert.That(result.Type, Is.EqualTo("Quittungen"));
            Assert.That(result.Notes, Is.EqualTo("TestStichwort"));
            Assert.That(result.EntryDate, Is.EqualTo(new DateTime(2020, 09, 10)));
            Assert.That(result.Username, Is.EqualTo("TestBenutzer"));
        }
예제 #2
0
        private static void WriteLogF(object o)
        {
            if (!Active)
            {
                return;
            }

            lock (O)
            {
                try
                {
                    var t = o as LogObject;

                    if (t != null)
                    {
                        string s = t.Moment.ToString(DateMask) + " " + t.Group + " : " + t.Message + Environment.NewLine;
                        string x = XmlSer <LogObject> .ToXmlString(t) + Environment.NewLine;

                        File.AppendAllText(LogFile, s);
                        File.AppendAllText(LogFullFile, x);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
        }
예제 #3
0
        public void XmlSer_testDeserializeWithoutFile_ReturnsNull()
        {
            //arrange
            XmlSer des = new XmlSer();

            //act
            MetadataItem result = des.DeserializeFile <MetadataItem>("Testordner");

            //assert
            Assert.That(result, Is.Null);
        }
예제 #4
0
        public void XmlSer_testSerialize_Returnfalse()
        {
            //arrange
            const string guid       = "eb31d4ff-be0b-4366-9838-994ed803dd69";
            const string title      = "TestBezeichnung";
            DateTime     valutaDate = new DateTime(2010, 09, 10);
            const string type       = "Quittungen";
            const string notes      = "TestStichwort";
            DateTime     entryDate  = new DateTime(2020, 09, 10);
            const string username   = "******";
            MetadataItem testItem   = new MetadataItem(guid, title, valutaDate, type, notes, entryDate, username);
            XmlSer       ser        = new XmlSer();

            //act
            bool result = ser.SerializeFile(testItem, "Testordner");

            //assert
            Assert.That(result, Is.False);
        }
예제 #5
0
        static void Main(string[] args)
        {
            Directory.CreateDirectory(c.AppFolder);

            if (File.Exists(Path.Combine(c.AppFolder, fn2)))
            {
                ppl = XmlSer <PackageInfoList> .FromString(File.ReadAllText(Path.Combine(c.AppFolder, fn2)));
            }
            else
            {
                ppl = new PackageInfoList();
            }

            if (args.Length == 0)
            {
                return;
            }
            if (!methods.ContainsKey(args[0]))
            {
                Console.WriteLine("Не известная команда !");
                return;
            }
            methods[args[0]].Invoke(null, args[1..]);
예제 #6
0
        //private static void ClearCache()
        //{
        //    DataCache.RemoveCache(RedirectConfigCacheKey);
        //    DataCache.RemoveCache(RedirectMappingsDictionaryCacheKey(true));
        //    DataCache.RemoveCache(RedirectMappingsDictionaryCacheKey(false));
        //}

        //public static bool Exists()
        //{
        //    return File.Exists(Common.RedirectConfigFile());
        //}
        private static RedirectConfig FromFile(string filename)
        {
            // create the file if it doesn't exsist
            //if (!File.Exists(filename))
            //    CreateFile(filename);

            RedirectConfig retval = null;
            FileStream     fs     = null;

            try
            {
                // if it exists we can just open it
                // otherwise return new configuration
                if (File.Exists(filename))
                {
                    fs     = new FileStream(filename, FileMode.Open);
                    retval = (RedirectConfig)XmlSer.Deserialize(fs);
                }
                else
                {
                    retval = new RedirectConfig();
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                    fs.Dispose();
                }
            }
            return(retval);
        }