本文整理汇总了C#中System.Xml.Serialization.XmlSerializer.CanDeserialize方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.Serialization.XmlSerializer.CanDeserialize方法的具体用法?C# System.Xml.Serialization.XmlSerializer.CanDeserialize怎么用?C# System.Xml.Serialization.XmlSerializer.CanDeserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.XmlSerializer
的用法示例。
在下文中一共展示了System.Xml.Serialization.XmlSerializer.CanDeserialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NameAndCasNmber
static public string[] NameAndCasNmber(string compoundName)
{
string[] retVal = new string[2];
gov.nih.nlm.chemspell.SpellAidService service = new gov.nih.nlm.chemspell.SpellAidService();
string response = service.getSugList(compoundName, "All databases");
var XMLReader = new System.Xml.XmlTextReader(new System.IO.StringReader(response));
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Synonym));
if (serializer.CanDeserialize(XMLReader))
{
Synonym synonym = (Synonym)serializer.Deserialize(XMLReader);
foreach (SynonymChemical chemical in synonym.Chemical)
{
int result = String.Compare(compoundName, chemical.Name, true);
if (result == 0)
{
retVal[0] = chemical.CAS;
retVal[1] = chemical.Name;
return retVal;
}
}
}
serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpellAid));
if (serializer.CanDeserialize(XMLReader))
{
SpellAid aid = (SpellAid)serializer.Deserialize(XMLReader);
bool different = true;
retVal[0] = aid.Chemical[0].CAS;
retVal[1] = aid.Chemical[0].Name;
for (int i = 0; i < aid.Chemical.Length - 1; i++)
{
if (retVal[0] != aid.Chemical[i + 1].CAS)
{
different = false;
retVal[0] = aid.Chemical[i].CAS;
retVal[1] = aid.Chemical[i].Name;
}
}
if (!different)
{
foreach (SpellAidChemical chemical in aid.Chemical)
{
int result = String.Compare(compoundName, 0, chemical.Name, 0, compoundName.Length, true);
if (result == 0 && compoundName.Length >= chemical.Name.Length)
{
retVal[0] = chemical.CAS;
retVal[1] = chemical.Name;
return retVal;
}
}
SelectChemicalForm form = new SelectChemicalForm(aid, compoundName);
form.ShowDialog();
retVal[0] = form.SelectedChemical.CAS;
retVal[1] = form.SelectedChemical.Name;
return retVal;
}
}
return retVal;
}
示例2: LoadExample
/// <summary>
/// Load embedded example
/// </summary>
/// <param name="name">Example file name</param>
public void LoadExample(string name)
{
try
{
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(_model.GetType());
using (System.Xml.XmlReader reader = new System.Xml.XmlTextReader(System.Windows.Application.GetResourceStream(new System.Uri("/examples/" + name, UriKind.Relative)).Stream))
{
if (x.CanDeserialize(reader))
_model = x.Deserialize(reader) as SettingsModel;
reader.Close();
}
// update all properties
InvokePropertyChanged(null);
}
catch
{
System.Windows.MessageBox.Show("Couldn't load L-System, please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}
}
示例3: LoadDefinition
/// <summary>
/// Load L-System definition file
/// </summary>
public void LoadDefinition()
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".ls"; // Default file extension
dlg.Filter = "L-System files(*.ls)|*.ls|All files (*.*)|*.*"; // Filter files by extension
// Show save file dialog box
bool? result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Load document
string filename = dlg.FileName;
try
{
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(_model.GetType());
using (System.Xml.XmlReader reader = new System.Xml.XmlTextReader(filename))
{
if (x.CanDeserialize(reader))
_model = x.Deserialize(reader) as SettingsModel;
reader.Close();
}
}
catch
{
System.Windows.MessageBox.Show("Couldn't load L-System, please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}
}
// update all properties
InvokePropertyChanged(null);
}
示例4: button2_Click
private void button2_Click(object sender, EventArgs e)
{
this.dataGridView1.Visible = false;
compoundName = this.textBox1.Text;
casNo = NISTChemicalList.casNumber(compoundName);
if (string.IsNullOrEmpty(casNo))
{
gov.nih.nlm.chemspell.SpellAidService service = new gov.nih.nlm.chemspell.SpellAidService();
string response = service.getSugList(compoundName, "All databases");
var XMLReader = new System.Xml.XmlTextReader(new System.IO.StringReader(response));
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Synonym));
if (serializer.CanDeserialize(XMLReader))
{
// Synonyms means more than one name for the same chemical/CAS Number.
Synonym synonym = (Synonym)serializer.Deserialize(XMLReader);
casNo = synonym.Chemical[0].CAS;
foreach (SynonymChemical chemical in synonym.Chemical)
{
if (casNo != chemical.CAS)
{
System.Windows.Forms.MessageBox.Show(compoundName + "has a synonym with a different CAS Number.");
return;
}
}
label2.Text = "The CAS Number of the chemical is: " + casNo + ". Now select the finished button to exit.";
return;
}
serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpellAid));
if (serializer.CanDeserialize(XMLReader))
{
SpellAid aid = (SpellAid)serializer.Deserialize(XMLReader);
//bool different = true;
chemicalList = new List<SpellAidChemical>();
foreach (SpellAidChemical chemical in aid.Chemical)
{
chemicalList.Add(chemical);
}
this.dataGridView1.DataSource = chemicalList;
this.dataGridView1.Visible = true;
this.label2.Text = "Select the desired chemical from the list below and click the 'Finished' button to exit.";
return;
// retVal[0] = aid.Chemical[0].CAS;
// retVal[1] = aid.Chemical[0].Name;
// for (int i = 0; i < aid.Chemical.Length - 1; i++)
// {
// if (retVal[0] != aid.Chemical[i + 1].CAS)
// {
// different = false;
// retVal[0] = aid.Chemical[i].CAS;
// retVal[1] = aid.Chemical[i].Name;
// }
// }
// if (!different)
// {
// foreach (SpellAidChemical chemical in aid.Chemical)
// {
// int result = String.Compare(compoundName, 0, chemical.Name, 0, compoundName.Length, true);
// if (result == 0 && compoundName.Length >= chemical.Name.Length)
// {
// retVal[0] = chemical.CAS;
// retVal[1] = chemical.Name;
// return retVal;
// }
// }
// SelectChemicalForm form = new SelectChemicalForm(aid, compoundName);
// form.ShowDialog();
// retVal[0] = form.SelectedChemical.CAS;
// retVal[1] = form.SelectedChemical.Name;
// return retVal;
// }
}
}
label2.Text = "The CAS Number of the chemical is: " + casNo + ". Now select the 'Finished' button to exit.";
return;
}
示例5: findCompound
private void findCompound(ref string compoundName, ref string CasNo)
{
gov.nih.nlm.chemspell.SpellAidService service = new gov.nih.nlm.chemspell.SpellAidService();
string response = service.getSugList(compoundName, "All databases");
response = response.Replace("&", "&");
var XMLReader = new System.Xml.XmlTextReader(new System.IO.StringReader(response));
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Synonym));
if (serializer.CanDeserialize(XMLReader))
{
// Synonyms means more than one name for the same chemical/CAS Number.
Synonym synonym = (Synonym)serializer.Deserialize(XMLReader);
CasNo = synonym.Chemical[0].CAS;
this.listBox1.BeginUpdate();
foreach (SynonymChemical chemical in synonym.Chemical)
{
this.listBox1.Items.Add(chemical.Name);
if (CasNo != chemical.CAS)
{
System.Windows.Forms.MessageBox.Show(compoundName + " has a synonym with a different CAS Number.");
return;
}
}
this.listBox1.EndUpdate();
return;
}
serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpellAid));
if (serializer.CanDeserialize(XMLReader))
{
SpellAid aid = (SpellAid)serializer.Deserialize(XMLReader);
Form3 selector = new Form3();
selector.chemicals = aid;
selector.ShowDialog();
compoundName = selector.SelectedChemical;
this.findCompound(ref compoundName, ref CasNo);
return;
}
CasNo = string.Empty;
}
示例6: ToxnetHSDBButton_Click_1
private void ToxnetHSDBButton_Click_1(object sender, EventArgs e)
{
string uriString = "https://toxgate.nlm.nih.gov/cgi-bin/sis/search2";
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uriString);
request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uriString);
string postData = "queryxxx=" + m_casNo;
postData += "&chemsyn=1";
postData += "&database=hsdb";
postData += "&Stemming=1";
postData += "&and=1";
postData += "&second_search=1";
postData += "&gateway=1";
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
System.Net.WebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
string responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
string s1 = responseString.Replace("<br>", "");
var XMLReader = new System.Xml.XmlTextReader(new System.IO.StringReader(s1));
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(QueryResult));
if (serializer.CanDeserialize(XMLReader))
{
// Synonyms means more than one name for the same chemical/CAS Number.
QueryResult result = (QueryResult)serializer.Deserialize(XMLReader);
uriString = "https://toxgate.nlm.nih.gov/cgi-bin/sis/search2/f?" + result.TemporaryFile;
string[] ids = result.Id.Split(' ');
System.Diagnostics.Process.Start("http://toxgate.nlm.nih.gov/cgi-bin/sis/search2/r?dbs+hsdb:@[email protected]+" + ids[0]);
}
}