Пример #1
0
        /// <summary> Saves all the pertinent information from a received Florida Digital Archive (FDA) ingest report </summary>
        /// <param name="Report"> Object containing all the data from the received FDA report </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public static bool FDA_Report_Save(FDA_Report_Data Report)
        {
            // Try to get the bibid and vid from the package name
            string bibid = String.Empty;
            string vid   = String.Empty;

            if ((Report.Package.Length == 16) && (Report.Package[10] == '_'))
            {
                bibid = Report.Package.Substring(0, 10);
                vid   = Report.Package.Substring(11, 5);
            }

            // If the package name was bib id without VID
            if (Report.Package.Length == 10)
            {
                bibid = Report.Package;
            }

            // Save the report information to the database
            int reportid = FDA_Report_Save(Report.Package, Report.IEID, Report.Report_Type_String, Report.Date, Report.Account, Report.Project, Report.Warnings, Report.Message_Note, bibid, vid);

            // If no error, continue
            return(reportid > 0);
        }
Пример #2
0
        /// <summary> Process all reports under the provided directory according to pre-established flags  </summary>
        /// <param name="SourceDirectory"> Directory under which to look for FDA reports to process </param>
        public void Process(string SourceDirectory)
        {
            // Get list of XML files
            string[] xml_files = recurse ? get_reports_recursively(SourceDirectory) : Directory.GetFiles(SourceDirectory, "*.xml");

            // Loop through each file
            Success_Count = 0;
            Error_Count   = 0;
            foreach (string thisXML in xml_files)
            {
                if ((thisXML.IndexOf(".brief.xml") < 0) || (include_brief))
                {
                    // Ensure the report still exists
                    if (File.Exists(thisXML))
                    {
                        try
                        {
                            // Read the XML report
                            FDA_Report_Data data = FDA_Report_Reader.Read(thisXML);

                            if (data == null)
                            {
                                Error_Count++;
                            }
                            else
                            {
                                // If this is a valid report, save it to the collection
                                if (data.Report_Type != FDA_Report_Type.INVALID)
                                {
                                    // Increment success count
                                    Success_Count++;
                                    //OnNewProgress(++success_count, 2 * (xml_files.Length + 2));

                                    // Set the flags for this item
                                    bool database_successful = true;

                                    // Rewrite this if it is INGEST or DISSEMINATION and user asked to
                                    if (((write_brief_always) || ((write_brief_on_warning) && (data.Warnings > 0))) &&
                                        ((data.Report_Type == FDA_Report_Type.INGEST) || (data.Report_Type == FDA_Report_Type.DISSEMINATION)))
                                    {
                                        // Write the brief report
                                        FDA_Report_Writer.Write(data, data.FileName);
                                    }

                                    // Did the user ask to save to the database?
                                    if (save_to_db)
                                    {
                                        // Ensure the database connection is correct
                                        FDA_Database_Gateway.Connection_String = Engine_Database.Connection_String;
                                        FDA_Database_Gateway.DatabaseType      = Engine_Database.DatabaseType;

                                        // Save to the database
                                        if (!FDA_Database_Gateway.FDA_Report_Save(data))
                                        {
                                            // If unsuccessful, set unsuccessful flag
                                            database_successful = false;
                                            Error_Count++;
                                        }
                                    }

                                    // Move to the web space
                                    string possible_bib_vid = data.Package;
                                    if ((possible_bib_vid.Length == 16) && (possible_bib_vid[10] == '_'))
                                    {
                                        string bibid         = possible_bib_vid.Substring(0, 10);
                                        string vid           = possible_bib_vid.Substring(11, 5);
                                        string assocFilePath = bibid.Substring(0, 2) + "\\" + bibid.Substring(2, 2) + "\\" + bibid.Substring(4, 2) + "\\" + bibid.Substring(6, 2) + "\\" + bibid.Substring(8) + "\\" + vid;

                                        // Determine the destination folder for this resource
                                        string serverPackageFolder = Engine_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + assocFilePath;

                                        // Make sure a directory exists here
                                        if (!Directory.Exists(serverPackageFolder))
                                        {
                                            Directory.CreateDirectory(serverPackageFolder);
                                        }

                                        // Copy the file
                                        string fileName = (new FileInfo(data.FileName)).Name;
                                        File.Copy(data.FileName, serverPackageFolder + "\\" + fileName.Replace(".brief", ""), true);
                                    }

                                    // If the user asked to delete the file and all work was successul,
                                    // and this was not an error, delete the original report
                                    if ((delete) && (database_successful))
                                    {
                                        try
                                        {
                                            File.Delete(data.FileName);
                                        }
                                        catch
                                        {
                                            Error_Count++;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                            Error_Count++;
                        }
                    }
                }

                // Show status for this part
                //OnNewProgress(success_count++, 2 * (xml_files.Length + 2));
            }

            // Show status for this part
            //OnNewProgress(xml_files.Length + 2, xml_files.Length + 2);
        }