/// <summary> /// Method to generate a list of Sources in a ValuesDataSet /// This is done as a separate method since Values can could contain other VariableValue Types /// /// </summary> /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param> /// <returns></returns> public static List <SourceType> datasetSources(ValuesDataSet ds) { /* generate a list * create a distinct DataSet * - new data view * - set filter (no nulls) * - use toTable with unique to get unique list * foreach to generate qualifiers * */ string COLUMN = "SourceID"; string TABLENAME = "sources"; List <SourceType> list = new List <SourceType>(); try { DataView view = new DataView(ds.DataValues); view.RowFilter = COLUMN + " is not Null"; DataTable ids = view.ToTable(TABLENAME, true, new string[] { COLUMN }); foreach (DataRow r in ids.Rows) { try { Object aId = r[COLUMN]; // edit here ValuesDataSet.SourcesRow source = ds.Sources.FindBySourceID((int)aId); if (source != null) { SourceType t = new SourceType(); t.sourceID = source.SourceID; t.sourceIDSpecified = true; if (!String.IsNullOrEmpty(source.Organization)) { t.Organization = source.Organization; } t.SourceDescription = source.SourceDescription; if (!source.IsSourceLinkNull()) { t.SourceLink = source.SourceLink; } // create a contact // only one for now ContactInformationType contact = new ContactInformationType(); contact.TypeOfContact = "main"; if (!String.IsNullOrEmpty(source.ContactName)) { contact.ContactName = source.ContactName; } if (!String.IsNullOrEmpty(source.Email)) { contact.Email = source.Email; } if (!String.IsNullOrEmpty(source.Phone)) { contact.Phone = source.Phone; } StringBuilder address = new StringBuilder(); if (!String.IsNullOrEmpty(source.Address)) { address.Append(source.Address + System.Environment.NewLine); } if (!String.IsNullOrEmpty(source.City) && !String.IsNullOrEmpty(source.State) && !String.IsNullOrEmpty(source.ZipCode)) { address.AppendFormat(",{0}, {1} {2}", source.City, source.State, source.ZipCode); } contact.Address = address.ToString(); //ContactInformationType[] contacts = new ContactInformationType[1]; // contacts[0] = contact; // t.ContactInformation = contacts; t.ContactInformation = contact; list.Add(t); } } catch (Exception e) { log.Error("Error generating a qualifier " + r.ToString() + e.Message); } } return(list); } catch (Exception e) { log.Error("Error generating a qualifiers " + e.Message); // non fatal exceptions return(null); } }
/// <summary> /// Method to generate a list of Sources in a ValuesDataSet /// This is done as a separate method since Values can could contain other VariableValue Types /// /// </summary> /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param> /// <returns></returns> public static List <SourceType> datasetSources(ValuesDataSet ds, string valuesWhereClause) { /* generate a list * create a distinct DataSet * - new data view * - set filter (no nulls) * - use toTable with unique to get unique list * foreach to generate qualifiers * */ string COLUMN = "SourceID"; string TABLENAME = "sources"; List <SourceType> list = new List <SourceType>(); try { DataView view = new DataView(ds.DataValues); view.RowFilter = valuesWhereClause; DataTable ids = view.ToTable(TABLENAME, true, new string[] { COLUMN }); foreach (DataRow r in ids.Rows) { try { //Object aId = r[COLUMN]; if (r[COLUMN] == DBNull.Value) { continue; } int?aId = Convert.ToInt32(r[COLUMN]); ValuesDataSet.SourcesRow source = ds.Sources.FindBySourceID((int)aId.Value); if (source != null) { SourceType t = new SourceType(); t.sourceID = source.SourceID; t.sourceIDSpecified = true; t.sourceCode = source.SourceID.ToString(); if (!String.IsNullOrEmpty(source.Organization)) { t.organization = source.Organization; } t.sourceDescription = source.SourceDescription; if (!source.IsSourceLinkNull()) { t.sourceLink = new string[] { source.SourceLink }; } // create a contact // only one for now ContactInformationType contact = new ContactInformationType(); contact.typeOfContact = "main"; if (!String.IsNullOrEmpty(source.ContactName)) { contact.contactName = source.ContactName; } if (!String.IsNullOrEmpty(source.Email)) { contact.email = new string[] { source.Email }; } if (!String.IsNullOrEmpty(source.Phone)) { contact.phone = new string[] { source.Phone }; } StringBuilder address = new StringBuilder(); if (!String.IsNullOrEmpty(source.Address)) { address.Append(source.Address + System.Environment.NewLine); } if (!String.IsNullOrEmpty(source.City) && !String.IsNullOrEmpty(source.State) && !String.IsNullOrEmpty(source.ZipCode)) { address.AppendFormat(",{0}, {1} {2}", source.City, source.State, source.ZipCode); } contact.address = new string[] { address.ToString() }; t.contactInformation = new ContactInformationType[] { contact }; if (!String.IsNullOrEmpty(source.Citation)) { t.citation = source.Citation; } if (source.MetadataID != 0 && source.ISOMetadataRow != null) { MetaDataType m = new MetaDataType(); m.topicCategory = source.ISOMetadataRow.TopicCategory; m.title = source.ISOMetadataRow.Title; m.@abstract = source.ISOMetadataRow.Abstract; m.profileVersion = source.ISOMetadataRow.ProfileVersion; if (!source.ISOMetadataRow.IsMetadataLinkNull()) { m.metadataLink = source.ISOMetadataRow.MetadataLink; } t.metadata = m; } list.Add(t); } } catch (Exception e) { log.Error("Error generating a qualifier " + r.ToString() + e.Message); } } return(list); } catch (Exception e) { log.Error("Error generating a qualifiers " + e.Message); // non fatal exceptions return(null); } }