Beispiel #1
0
        private static async Task <int> UploadDestination()
        {
            var ncc         = XDocument.Load(Path.Combine(DestPath, "ncc.html"));
            var titleUpdate = new DCSArchiveLibrary.Model.TitleUpdate
            {
                SourcePath         = DestPath,
                OriginCode         = "DDS",
                MaterialTypeCode   = "DTB",
                MaterialFormatCode = "D202",
                TitleNo            = destTitleNumber,
                Title   = Utils.GetMetaContent(ncc, "dc:title"),
                Creator = Utils.GetMetaContent(ncc, "dc:creator") ?? defaultCreator,
                MetadataFromDBBDokSys = false
            };

            var existingTitle = await clientApi.GetTitle(destTitleNumber);

            if (existingTitle != null)
            {
                titleUpdate.TitleID = existingTitle.ID;
                await clientApi.UpdateTitleFormat(titleUpdate);
            }
            else
            {
                await clientApi.CreateTitle(titleUpdate);
            }
            logger.Info("Uploaded synthesized DTB to DCSArchive");
            return(0);
        }
Beispiel #2
0
        private static async Task <int> SyncTitle(string titleNo)
        {
            var sourceTitle = await sourceClientApi.GetTitle(titleNo);

            if (sourceTitle == null)
            {
                Console.WriteLine($"Unexpectedly could not find source title {titleNo}");
                return(-1000);
            }
            if (sourceTitle.DirectoriesAsList.Count != 1)
            {
                Console.WriteLine($"Title {titleNo} has {sourceTitle.DirectoriesAsList.Count} directories. Only single dir titles are aupported");
                return(-1);
            }
            if (sourceTitle.ItemsAsList.Count != 1)
            {
                Console.WriteLine($"Title {titleNo} has {sourceTitle.ItemsAsList.Count} items. Only single item titles are aupported");
                return(-1);
            }
            var tempDir = Path.Combine(UncRoot, titleNo);
            var di      = Directory.CreateDirectory(tempDir);

            if (di.GetFiles().Any() || di.GetDirectories().Any())
            {
                Console.WriteLine($"Temp directory {tempDir} is not empty");
                return(-1000);
            }
            Console.WriteLine($"Created temp directory {tempDir}");
            try
            {
                CopyDirectory(sourceTitle.DirectoriesAsList.First().WebFullPath, tempDir);
                Console.WriteLine($"Downloaded source from {sourceTitle.DirectoriesAsList.First().WebFullPath}");
                var titleUpdate = new DCSArchiveLibrary.Model.TitleUpdate
                {
                    SourcePath         = tempDir,
                    OriginCode         = sourceTitle.OriginCode,
                    MaterialTypeCode   = sourceTitle.MaterialTypeCode,
                    MaterialFormatCode = sourceTitle.ItemsAsList.First().MaterialFormatCode,
                    TitleNo            = sourceTitle.TitleNo,
                    Title    = sourceTitle.Title,
                    Creator  = sourceTitle.Creator,
                    SubTitle = sourceTitle.Subtitle,
                    MetadataFromDBBDokSys = false
                };
                var existingTitle = await destClientApi.GetTitle(sourceTitle.TitleNo);

                if (existingTitle != null)
                {
                    titleUpdate.TitleID = existingTitle.ID;
                    await destClientApi.UpdateTitleFormat(titleUpdate);

                    Console.WriteLine($"Updated title {titleNo} in destination");
                }
                else
                {
                    await destClientApi.CreateTitle(titleUpdate);

                    Console.WriteLine($"Created title {titleNo} in destination");
                }
            }
            finally
            {
                try
                {
                    if (Directory.Exists(tempDir))
                    {
                        Directory.Delete(tempDir, true);
                        Console.WriteLine($"Deleted temp directory {tempDir}");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Could not delete temporary directory {tempDir} due to an unexpected {e.GetType()}: {e.Message}");
                }
            }
            return(0);
        }