Exemplo n.º 1
0
        public static void ExtractLoadChapterPublications()
        {
            // Read file
            var engine = new FileHelperEngine<MavroRecord>();
            var results = engine.ReadFile(@"C:\temp\beholderArchiveUrl.csv").Where(r => r.RecordType == "CHAPTER");

            var records = results as IList<MavroRecord> ?? results.ToList().Take(10);
            using (var db = new AppContext())
            {
                foreach (var record in records)
                {
                    var chapter = db.Chapters.Find(Convert.ToInt32(record.Id));
                    Console.WriteLine("Creating publication for chapter: {0}: Id: {1}", chapter.ChapterName, chapter.Id);
                    using (var client = new WebClient())
                    {
                        byte[] buffer = client.DownloadData(record.Url);

                        const int userId = 1;

                        var rel = new ChapterMediaPublishedRel()
                        {
                            ChapterId = chapter.Id,
                            RelationshipTypeId = 99,
                            MediaPublished = new MediaPublished()
                            {
                                MediaTypeId = 4,
                                ConfidentialityTypeId = 4,
                                DateCreated = DateTime.Now,
                                DateModified = DateTime.Now,
                                CreatedUserId = userId,
                                Name = "MavroImport-Chapter-" + chapter.ChapterName
                            }
                        };
                        db.ChapterMediaPublishedRels.AddOrUpdate(rel);
                        db.SaveChanges();

                        var context = new MediaPublishedContext()
                        {
                            ContextText = buffer,
                            MimeTypeId = 7,
                            DocumentExtension = ".pdf",
                            FileStreamID = Guid.NewGuid(),
                            FileName = "MavroImport-Chapter-" + chapter.ChapterName + ".pdf",
                            MediaPublishedId = rel.MediaPublishedId
                        };
                        db.MediaPublishedContexts.Add(context);
                        db.SaveChanges();

                        Console.WriteLine("Created publication {0}", rel.MediaPublished);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void ExtractLoadPersonPublications()
        {
            // Read file
            var engine = new FileHelperEngine<MavroRecord>();
            var results = engine.ReadFile(@"C:\temp\beholderArchiveUrl.csv").Where(r => r.RecordType == "PERSON");

            var records = results as IList<MavroRecord> ?? results.ToList();
            using (var db = new AppContext())
            {
                foreach (var record in records.Take(1))
                {
                    var beholderPerson = db.BeholderPeople.Find(Convert.ToInt32(record.Id));
                    var commonPerson = db.CommonPeople.Find(beholderPerson.PersonId);

                    Console.WriteLine("Creating item for Person: {0}: BeholderId: {1}", commonPerson.FullName, beholderPerson.Id);
                    using (var client = new WebClient())
                    {
                        byte[] buffer = client.DownloadData(record.Url);

                        const int userId = 1;

                        var rel = new PersonMediaPublishedRel()
                        {

                            PersonId = beholderPerson.Id,
                            RelationshipTypeId = 99,
                            MediaPublished = new MediaPublished()
                            {
                                MediaTypeId = 4,
                                ConfidentialityTypeId = 4,
                                DateCreated = DateTime.Now,
                                DateModified = DateTime.Now,
                                CreatedUserId = userId,
                                Name = "MavroImport-Person-" + commonPerson.LName
                            }
                        };
                        db.PersonMediaPublishedRels.AddOrUpdate(rel);
                        db.SaveChanges();

                        var context = new MediaPublishedContext()
                        {
                            ContextText = buffer,
                            MimeTypeId = 7,
                            DocumentExtension = ".pdf",
                            FileStreamID = Guid.NewGuid(),
                            FileName = "MavroImport-Person-" + commonPerson.FullName + ".pdf",
                            MediaPublishedId = rel.MediaPublishedId
                        };
                        db.MediaPublishedContexts.Add(context);
                        db.SaveChanges();

                    }
                }
            }
        }