Exemple #1
0
        public static Dto.NewsStory MapXmlDataToDto(this NewsStoryXml newsStoryXml)
        {
            Dto.NewsStory newsStory;

            // check if we actually have some valid data to work with
            if (newsStoryXml == null || string.IsNullOrEmpty(newsStoryXml.Id))
            {
                return(newsStory = new Dto.NewsStory());
            }

            // try mapping the data to the new dto object
            try
            {
                newsStory = new Dto.NewsStory()
                {
                    Id       = newsStoryXml.Id,
                    TopTitle = newsStoryXml.TopTitle,
                    Body     = newsStoryXml.Body,
                    Imageloc = newsStoryXml.Imageloc
                };
            }
            catch (Exception /*ex*/)
            {
                // log this
                newsStory = new Dto.NewsStory();
            }

            return(newsStory);
        }
Exemple #2
0
        public void Given_Valid_Xml_Test_File_Inflate_NewsStory_Entity()
        {
            _newsStory = _xmlFtpDataHandler.GetNewsStory(xmlTestFile);

            _newsStory.Should().NotBeNull().And.BeOfType <NewsStoryXml>();
            _newsStory.Id.Should().NotBeNull().And.Match(TESTID);
        }
Exemple #3
0
        private void ProcessFile(string fileName)
        {
            var fileExtension  = Path.GetExtension(fileName);
            var imageDirectory = ConfigurationManager.AppSettings.Get(IMAGEPATHKEY);

            if (fileExtension.ToLower() == XMLEXTENSION)
            {
                try
                {
                    // its an XML file so get contents and inflate the entity
                    var xmlSerializer = new XmlSerializer(typeof(NewsStoryXml));
                    using (var fs = new FileStream(fileName, FileMode.Open))
                    {
                        newsStory = (NewsStoryXml)xmlSerializer.Deserialize(fs);
                    }

                    //File.Delete(fileName);

                    return;
                }
                catch (XmlException /*xex*/)
                {
                    // log this
                }
            }

            if (fileName.IsRecognisedImageFile())
            {
                // copy the file to the server image path
                if (!Directory.Exists(imageDirectory))
                {
                    Directory.CreateDirectory(imageDirectory);
                }

                var imagePath = $"{imageDirectory}\\{fileName}";

                File.Copy(fileName, imagePath);

                newsStory.Imageloc = imagePath;

                // delete the existing file
                File.Delete(fileName);

                return;
            }
        }