/// <summary> Constructor for a new instance of the Retrieve_SobekCM_Items_Processor </summary> /// <param name="Item_List"> List of items to retrieve </param> /// <param name="Destination"> Destination (directory) for the retrieved items </param> /// <param name="Retrieval_Type"> Type of retrieval to perform ( i.e, METS, complete package, MarcXML report, etc.. ) </param> public Retrieve_SobekCM_Items_Processor(DataTable Item_List, string Destination, Retrieval_Type_Enum Retrieval_Type ) { itemList = Item_List; destination = Destination; retrievalType = Retrieval_Type; }
/// <summary> Constructor for a new instance of the Retrieve_SobekCM_Items_Processor </summary> /// <param name="Item_List"> List of items to retrieve </param> /// <param name="Destination"> Destination (directory) for the retrieved items </param> /// <param name="Retrieval_Type"> Type of retrieval to perform ( i.e, METS, complete package, MarcXML report, etc.. ) </param> public Retrieve_SobekCM_Items_Processor(DataTable Item_List, string Destination, Retrieval_Type_Enum Retrieval_Type) { itemList = Item_List; destination = Destination; retrievalType = Retrieval_Type; }
private void okButton_Button_Pressed(object sender, EventArgs e) { if (sobekcmQueryTextBox.Text.Trim().Length == 0) { MessageBox.Show("Please include a " + SobekCM_Library_Settings.System_Abbreviation + " URL for a browse or search. \n\nFor example: 'http://ufdc.ufl.edu/l/foto/results/?t=flint hall' ", "Missing URL", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((destinationTextBox.Text.Trim().Length == 0) || (!Directory.Exists(destinationTextBox.Text))) { MessageBox.Show("Please select a valid destination for the " + SobekCM_Library_Settings.System_Abbreviation + " packages. ", "Missing or Invalid Destination", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string sobekcm_url = sobekcmQueryTextBox.Text.Trim().ToLower(); string destination = destinationTextBox.Text.Trim(); sobekcmQueryTextBox.ReadOnly = true; destinationTextBox.ReadOnly = true; completeRadioButton.Enabled = false; metsOnlyRadioButton.Enabled = false; marcXmlRadioButton.Enabled = false; browseButton.Enabled = false; okButton.Button_Enabled = false; exitButton.Button_Enabled = false; sobekcm_url = sobekcm_url.Replace("/l/", "/xml/").Replace("/dataset/", "/xml/").Replace("/json/", "/xml/"); if (sobekcm_url.IndexOf("http://") < 0) { sobekcm_url = sobekcm_url + "http://"; } if (sobekcm_url.IndexOf("/xml/") < 0) { if (sobekcm_url.IndexOf(SobekCM_Library_Settings.System_Base_URL.ToLower()) == 0) { sobekcm_url = sobekcm_url.Replace(SobekCM_Library_Settings.System_Base_URL.ToLower(), SobekCM_Library_Settings.System_Base_URL.ToLower() + "xml/"); } else { // Hopefully this is at the root of the web server.. we can try to inset XML in there int index = sobekcm_url.IndexOf("/", 7); sobekcm_url = sobekcm_url.Substring(0, index) + "/xml/" + sobekcm_url.Substring(index + 1); } } string web_stream = Get_Html_Page(sobekcm_url); if (web_stream.Length == 0) { MessageBox.Show("Invalid " + SobekCM_Library_Settings.System_Abbreviation + " Query URL was supplied.\n\nPerform requested search or browse directly in " + SobekCM_Library_Settings.System_Abbreviation + " and \nthen copy the URL into the " + SobekCM_Library_Settings.System_Abbreviation + " query box.", "Invalid " + SobekCM_Library_Settings.System_Abbreviation + " Query Supplied", MessageBoxButtons.OK, MessageBoxIcon.Warning); sobekcmQueryTextBox.ReadOnly = false; destinationTextBox.ReadOnly = false; completeRadioButton.Enabled = true; metsOnlyRadioButton.Enabled = true; browseButton.Enabled = true; okButton.Button_Enabled = true; exitButton.Button_Enabled = true; marcXmlRadioButton.Enabled = true; return; } // Temporary folder string temp_folder = Environment.GetFolderPath(Environment.SpecialFolder.Personal); temp_folder = temp_folder + "\\SMaRT Temporary"; try { if (!Directory.Exists(temp_folder)) { Directory.CreateDirectory(temp_folder); } } catch { MessageBox.Show("Unable to create necessary directory:\n\n\t" + temp_folder, "Unable to create temporary folder", MessageBoxButtons.OK, MessageBoxIcon.Warning); sobekcmQueryTextBox.ReadOnly = false; destinationTextBox.ReadOnly = false; completeRadioButton.Enabled = true; metsOnlyRadioButton.Enabled = true; marcXmlRadioButton.Enabled = true; browseButton.Enabled = true; okButton.Button_Enabled = true; exitButton.Button_Enabled = true; return; } // Save the data to the temp folder try { StreamWriter writer = new StreamWriter(temp_folder + "\\" + SobekCM_Library_Settings.System_Abbreviation.ToLower() + "_download.xml", false); writer.Write(web_stream); writer.Flush(); writer.Close(); } catch { MessageBox.Show("Unable to save the downloaded data to the temporary folder:\n\n\t" + temp_folder + "\\" + SobekCM_Library_Settings.System_Abbreviation.ToLower() + "_download.xml", "Unable to create temporary file", MessageBoxButtons.OK, MessageBoxIcon.Warning); sobekcmQueryTextBox.ReadOnly = false; destinationTextBox.ReadOnly = false; completeRadioButton.Enabled = true; metsOnlyRadioButton.Enabled = true; marcXmlRadioButton.Enabled = true; browseButton.Enabled = true; okButton.Button_Enabled = true; exitButton.Button_Enabled = true; return; } // Load this data into a dataset DataTable itemList = null; try { itemList = Read_Item_Xml(temp_folder + "\\" + SobekCM_Library_Settings.System_Abbreviation.ToLower() + "_download.xml"); } catch { MessageBox.Show("Unable to load the xml data into a dataset for processing. ", "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); sobekcmQueryTextBox.ReadOnly = false; destinationTextBox.ReadOnly = false; completeRadioButton.Enabled = true; metsOnlyRadioButton.Enabled = true; marcXmlRadioButton.Enabled = true; browseButton.Enabled = true; okButton.Button_Enabled = true; exitButton.Button_Enabled = true; return; } // If there were no matching items, show a message if ((itemList == null) || (itemList.Rows.Count == 0)) { MessageBox.Show("No items match your query! ", "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); sobekcmQueryTextBox.ReadOnly = false; destinationTextBox.ReadOnly = false; completeRadioButton.Enabled = true; metsOnlyRadioButton.Enabled = true; marcXmlRadioButton.Enabled = true; browseButton.Enabled = true; okButton.Button_Enabled = true; exitButton.Button_Enabled = true; return; } // Ensure the user knows what they are doing here DialogResult continue_test = MessageBox.Show("You are about to download " + itemList.Rows.Count + " packages from " + SobekCM_Library_Settings.System_Abbreviation.ToLower() + ". \n\nAre you sure you would like to continue?", "Confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (continue_test != DialogResult.Yes) { sobekcmQueryTextBox.ReadOnly = false; destinationTextBox.ReadOnly = false; completeRadioButton.Enabled = true; metsOnlyRadioButton.Enabled = true; marcXmlRadioButton.Enabled = true; browseButton.Enabled = true; okButton.Button_Enabled = true; exitButton.Button_Enabled = true; return; } // Set the maximum on the progress bar progressBar1.Maximum = itemList.Rows.Count; // Determine the type of retrieval requested Retrieval_Type_Enum retrievalType = Retrieval_Type_Enum.METS_Only; if (completeRadioButton.Checked) { retrievalType = Retrieval_Type_Enum.Complete; } if (marcXmlRadioButton.Checked) { retrievalType = Retrieval_Type_Enum.MARC_XML; } // Show progress bars progressBar1.Show(); if (retrievalType == Retrieval_Type_Enum.Complete) { progressBar2.Show(); } // Create the processor Retrieve_SobekCM_Items_Processor processor = new Retrieve_SobekCM_Items_Processor(itemList, destination, retrievalType); processor.New_Progress += processor_New_Progress; processor.File_Progress += processor_File_Progress; processor.Progress_Complete += processor_Progress_Complete; // Create the thread for this processingThread = new Thread(processor.Start); processingThread.Start(); }