コード例 #1
0
        private void ImportAuthors(ILibrary libManager)
        {
            IDConversionDao idcDao           = new IDConversionDao();
            AuthorDao       authorDao        = new AuthorDao();
            var             anotherDbAuthors = authorDao.FindAll(_dataOpUnit.CurrentConnection, s_ANOTHER_DATABASE_ALIAS_NAME).ToList().ToViewModel();
            var             authors          = authorDao.FindAll(_dataOpUnit.CurrentConnection).ToList().ToViewModel();

            //同ID x 同値:対象ライブラリのエンティティをインポートしない。
            var alpha = from a in anotherDbAuthors
                        join oa in authors on a.ID equals oa.ID
                        where a.Name == oa.Name
                        select a;

            //同ID x 異値:対象ライブラリのエンティティを新規IDでインポートする。取込側ライブラリに新規IDと旧IDを記録する。
            var beta = from a in anotherDbAuthors.Except(alpha)
                       join oa in authors on a.ID equals oa.ID
                       where a.Name != oa.Name
                       select a;

            foreach (var add in beta)
            {
                var newGuid = Guid.NewGuid();
                idcDao.Insert(new Data.Entity.Migration.IDConversion("Author", newGuid, add.ID), _dataOpUnit.CurrentConnection);
                add.ID = newGuid;

                ImportAuthor(libManager, add);
            }

            //異ID x 同値:対象ライブラリのエンティティをインポートしない。取込側ライブラリに新規IDと旧IDを記録する。
            var gamma = from a in anotherDbAuthors.Except(alpha).Except(beta)
                        join oa in authors on a.Name equals oa.Name
                        where a.ID != oa.ID
                        select new { ForeignID = a.ID, DomesticID = oa.ID, Author = a };

            foreach (var add in gamma)
            {
                idcDao.Insert(new Data.Entity.Migration.IDConversion("Author", add.DomesticID, add.ForeignID), _dataOpUnit.CurrentConnection);
            }

            //異ID x 異値:対象ライブラリのエンティティを変更せずそのままインポートする。
            var delta = from a in anotherDbAuthors.Except(alpha).Except(beta).Except(gamma.Select(a => a.Author))
                        select a;

            foreach (var add in delta)
            {
                ImportAuthor(libManager, add);
            }
        }
コード例 #2
0
        private void ImportTags(ILibrary libManager)
        {
            IDConversionDao idcDao        = new IDConversionDao();
            TagDao          tagDao        = new TagDao();
            var             anotherDbTags = tagDao.FindAll(_dataOpUnit.CurrentConnection, s_ANOTHER_DATABASE_ALIAS_NAME).ToViewModel();
            var             tags          = tagDao.FindAll(_dataOpUnit.CurrentConnection).ToViewModel();

            //同ID x 同値:対象ライブラリのエンティティをインポートしない。
            var alpha = from t in anotherDbTags
                        join ot in tags on t.ID equals ot.ID
                        where t.Name == ot.Name
                        select t;

            //同ID x 異値:対象ライブラリのエンティティを新規IDでインポートする。取込側ライブラリに新規IDと旧IDを記録する。
            var beta = from t in anotherDbTags.Except(alpha)
                       join ot in tags on t.ID equals ot.ID
                       where t.Name != ot.Name
                       select t;

            foreach (var add in beta)
            {
                var newGuid = Guid.NewGuid();
                idcDao.Insert(new Data.Entity.Migration.IDConversion("Tag", newGuid, add.ID), _dataOpUnit.CurrentConnection);
                add.ID = newGuid;

                ImportTag(libManager, add);
            }

            //異ID x 同値:対象ライブラリのエンティティをインポートしない。取込側ライブラリに新規IDと旧IDを記録する。
            var gamma = from t in anotherDbTags.Except(alpha).Except(beta)
                        join ot in tags on t.Name equals ot.Name
                        where t.ID != ot.ID
                        select new { ForeignID = t.ID, DomesticID = ot.ID, Tag = t };

            foreach (var add in gamma)
            {
                idcDao.Insert(new Data.Entity.Migration.IDConversion("Tag", add.DomesticID, add.ForeignID), _dataOpUnit.CurrentConnection);
            }

            //異ID x 異値:対象ライブラリのエンティティを変更せずそのままインポートする。
            var delta = from t in anotherDbTags.Except(alpha).Except(beta).Except(gamma.Select(t => t.Tag))
                        select t;

            foreach (var add in delta)
            {
                ImportTag(libManager, add);
            }
        }
コード例 #3
0
        private IEnumerable <Task> GenerateTasksToImportBooks(ILibrary libManager)
        {
            List <Task> ret = new List <Task>();

            IDConversionDao idcDao         = new IDConversionDao();
            BookDao         bookDao        = new BookDao();
            var             anotherDbBooks = bookDao.FindAll(_dataOpUnit.CurrentConnection, s_ANOTHER_DATABASE_ALIAS_NAME).ToList().ToViewModel();
            var             books          = bookDao.FindAll(_dataOpUnit.CurrentConnection).ToList().ToViewModel();

            //同ID:対象ライブラリのエンティティを新規IDでインポートする。取込側ライブラリに新規IDと旧IDを記録する。
            var alpha = from b in anotherDbBooks
                        join ob in books on b.ID equals ob.ID
                        select b;

            foreach (var addBook in alpha)
            {
                var newGuid = Guid.NewGuid();
                idcDao.Insert(new Data.Entity.Migration.IDConversion("Book", newGuid, addBook.ID), _dataOpUnit.CurrentConnection);
                addBook.ID = newGuid;

                ret.AddRange(GenerateTasksToImportBook(libManager, addBook));
            }

            //異ID:対象ライブラリのエンティティを変更せずそのままインポートする。
            var beta = from b in anotherDbBooks.Except(alpha)
                       select b;

            foreach (var addBook in beta)
            {
                ret.AddRange(GenerateTasksToImportBook(libManager, addBook));
            }

            return(ret);
        }
コード例 #4
0
        private void ImportBooks(ILibrary libManager)
        {
            IDConversionDao idcDao         = new IDConversionDao();
            BookDao         bookDao        = new BookDao();
            var             anotherDbBooks = bookDao.FindAll(_dataOpUnit.CurrentConnection, s_ANOTHER_DATABASE_ALIAS_NAME).ToList().ToViewModel();
            var             books          = bookDao.FindAll(_dataOpUnit.CurrentConnection).ToList().ToViewModel();

            //同ID:対象ライブラリのエンティティを新規IDでインポートする。取込側ライブラリに新規IDと旧IDを記録する。
            var alpha = from b in anotherDbBooks
                        join ob in books on b.ID equals ob.ID
                        select b;

            foreach (var add in alpha)
            {
                var newGuid = Guid.NewGuid();
                idcDao.Insert(new Data.Entity.Migration.IDConversion("Book", newGuid, add.ID), _dataOpUnit.CurrentConnection);
                add.ID = newGuid;

                ImportBookWithContents(libManager, add);
            }

            //異ID:対象ライブラリのエンティティを変更せずそのままインポートする。
            var beta = from b in anotherDbBooks.Except(alpha)
                       select b;

            foreach (var add in beta)
            {
                ImportBookWithContents(libManager, add);
            }
        }
コード例 #5
0
        private void CopyPages(ILibrary libManager, BookViewModel parent)
        {
            IDConversionDao idcDao  = new IDConversionDao();
            PageDao         pageDao = new PageDao();

            var pages = pageDao.FindBy(new Dictionary <string, object>()
            {
                { "BookID", parent.ID }
            }, _dataOpUnit.CurrentConnection, s_ANOTHER_DATABASE_ALIAS_NAME).OrderBy(p => p.PageIndex).ToViewModel();

            foreach (var page in pages)
            {
                if (pageDao.FindBy(new Dictionary <string, object>()
                {
                    { "ID", page.ID }
                }, _dataOpUnit.CurrentConnection).Count() > 0)
                {
                    //対象ライブラリのエンティティを新規IDでインポートする。取込側ライブラリに新規IDと旧IDを記録する。
                    Guid newGuid = Guid.NewGuid();
                    idcDao.Insert(new Data.Entity.Migration.IDConversion("Page", newGuid, page.ID), _dataOpUnit.CurrentConnection);
                    page.ID = newGuid;

                    ImportPageWithContents(libManager, parent, page);
                }
                else
                {
                    //対象ライブラリのエンティティを変更せずそのままインポートする。
                    ImportPageWithContents(libManager, parent, page);
                }
            }
        }
コード例 #6
0
        private void ImportImage(PageViewModel parent, ImageViewModel image)
        {
            IDConversionDao idcDao   = new IDConversionDao();
            ImageDao        imageDao = new ImageDao();

            if (imageDao.FindBy(new Dictionary <string, object>()
            {
                { "ID", parent.ImageID }
            }, _dataOpUnit.CurrentConnection).Count() > 0)
            {
                //対象ライブラリのエンティティを新規IDでインポートする。取込側ライブラリに新規IDと旧IDを記録する。
                Guid newGuid = Guid.NewGuid();
                idcDao.Insert(new Data.Entity.Migration.IDConversion("Image", newGuid, image.ID), _dataOpUnit.CurrentConnection);
                image.ID = newGuid;
            }

            CopyFile(image, parent.BookID);
            imageDao.Insert(image.ToEntity(), _dataOpUnit.CurrentConnection);
            parent.Image = image;
        }