本文整理匯總了C#中System.Data.DataTable.WriteXmlSchema方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.WriteXmlSchema方法的具體用法?C# DataTable.WriteXmlSchema怎麽用?C# DataTable.WriteXmlSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.WriteXmlSchema方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ConvertBetweenDataTableToXML
public string ConvertBetweenDataTableToXML(DataTable dtNeedCoveret)
{
System.IO.TextWriter tw = new System.IO.StringWriter();
//if TableName is empty, WriteXml() will throw Exception.
dtNeedCoveret.TableName = dtNeedCoveret.TableName.Length == 0 ? "Table" : dtNeedCoveret.TableName;
dtNeedCoveret.WriteXml(tw);
dtNeedCoveret.WriteXmlSchema(tw);
return tw.ToString();
}
示例2: Main
static void Main(string[] args)
{
// Создание Таблицы DataTable с именем "Cars"
DataTable tablCars = new DataTable("Cars");
// Создание столбцов
DataColumn carsId = new DataColumn("Id", typeof(int));
DataColumn carsName = new DataColumn("Name", typeof(string));
DataColumn carsCountry = new DataColumn("Country", typeof(string));
DataColumn carsPrice = new DataColumn("Price", typeof(double));
tablCars.Columns.AddRange(new DataColumn[] { carsId, carsName, carsCountry, carsPrice });
// Создание строки с данными
DataRow newRow1 = tablCars.NewRow();
newRow1["Name"] = "BMW"; newRow1["Country"] = "Germany";
newRow1["Price"] = "50000";
tablCars.Rows.Add(newRow1);
DataRow newRow2 = tablCars.NewRow();
newRow2["Name"] = "Audi"; newRow2["Country"] = "Germany";
newRow2["Price"] = "37500";
tablCars.Rows.Add(newRow2);
// Сохранить ТАБЛИЦЫ tablCars в виде XML
tablCars.WriteXml("Cars.xml");
tablCars.WriteXmlSchema("CarsSchema.xsd");
// Создание Таблицы DataTable с именем "Drivers"
DataTable tablDrivers = new DataTable("Drivers");
// Создание столбцов
DataColumn drId = new DataColumn("Id", typeof(int));
DataColumn drName = new DataColumn("Name", typeof(string));
DataColumn drAge = new DataColumn("Age", typeof(string));
tablDrivers.Columns.AddRange(new DataColumn[] { drId, drName, drAge });
// Создание строки с данными
DataRow newRow3 = tablDrivers.NewRow();
newRow3["Name"] = "Ivan"; newRow3["Age"] = "33";
tablDrivers.Rows.Add(newRow3);
DataSet dataSet = new DataSet("AutoPark");
dataSet.Tables.AddRange(new DataTable[] { tablCars, tablDrivers});
// Сохранить DATASET в виде XML
dataSet.WriteXmlSchema("AutoParkSchema.xsd");
dataSet.WriteXml("AutoPark.xml");
// Очистить DataSet.
dataSet.Clear();
Console.WriteLine("XML успешно сформированы!");
Console.ReadKey();
}
示例3: Execute
public int Execute()
{
using (var conn = this.GetConnection())
{
conn.Open();
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(this.Command, conn);
adapter.SelectCommand.CommandType = this.CommandType;
adapter.Fill(dt);
dt.TableName = "tmp";
dt.WriteXml(this.SaveTo);
dt.WriteXmlSchema(this.SaveTo + ".schema");
}
return 0;
}
示例4: GetXmlSchema
private string GetXmlSchema(DataTable dt)
{
using (var writer = new StringWriter())
{
dt.WriteXmlSchema(writer);
return dt.ToString();
}
}
示例5: ReadWriteXmlSchemaExp_TableNameConflict
public void ReadWriteXmlSchemaExp_TableNameConflict ()
{
DataTable dtw = new DataTable ("Table1");
StringWriter writer1 = new StringWriter ();
dtw.WriteXmlSchema (writer1);
DataTable dtr = new DataTable ("Table2");
StringReader reader1 = new StringReader (writer1.ToString());
try {
dtr.ReadXmlSchema (reader1);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
}
示例6: ReadWriteXmlSchemaExp_NoFileName
public void ReadWriteXmlSchemaExp_NoFileName ()
{
DataTable dtw = new DataTable ();
try {
dtw.WriteXmlSchema (string.Empty);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
}
示例7: ReadWriteXmlSchemaExp_NoTableName
public void ReadWriteXmlSchemaExp_NoTableName ()
{
DataTable dtw = new DataTable ();
MemoryStream ms = new MemoryStream ();
try {
dtw.WriteXmlSchema (ms);
Assert.Fail ("#1");
} catch (InvalidOperationException) {
}
}
示例8: WriteXmlSchema_Hierarchy
public void WriteXmlSchema_Hierarchy ()
{
DataSet ds = new DataSet ();
DataTable table1 = new DataTable ();
DataColumn idColumn = table1.Columns.Add ("ID", typeof (Int32));
table1.Columns.Add ("Name", typeof (String));
table1.PrimaryKey = new DataColumn[] { idColumn };
DataTable table2 = new DataTable ();
table2.Columns.Add (new DataColumn ("OrderID", typeof (Int32)));
table2.Columns.Add (new DataColumn ("CustomerID", typeof (Int32)));
table2.Columns.Add (new DataColumn ("OrderDate", typeof (DateTime)));
table2.PrimaryKey = new DataColumn[] { table2.Columns[0] };
ds.Tables.Add (table1);
ds.Tables.Add (table2);
ds.Relations.Add ("CustomerOrder",
new DataColumn[] { table1.Columns[0] },
new DataColumn[] { table2.Columns[1] }, true);
StringWriter writer1 = new StringWriter ();
table1.WriteXmlSchema (writer1, false);
string expected1 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\n <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"Table1\" msdata:UseCurrentLocale=\"true\">\n <xs:complexType>\n <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\n <xs:element name=\"Table1\">\n <xs:complexType>\n <xs:sequence>\n <xs:element name=\"ID\" type=\"xs:int\" />\n <xs:element name=\"Name\" type=\"xs:string\" minOccurs=\"0\" />\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n </xs:choice>\n </xs:complexType>\n <xs:unique name=\"Constraint1\" msdata:PrimaryKey=\"true\">\n <xs:selector xpath=\".//Table1\" />\n <xs:field xpath=\"ID\" />\n </xs:unique>\n </xs:element>\n</xs:schema>";
Assert.AreEqual (expected1, writer1.ToString().Replace("\r\n", "\n"), "#1");
StringWriter writer2 = new StringWriter ();
table1.WriteXmlSchema (writer2, true);
string expected2 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\n <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"Table1\" msdata:UseCurrentLocale=\"true\">\n <xs:complexType>\n <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\n <xs:element name=\"Table1\">\n <xs:complexType>\n <xs:sequence>\n <xs:element name=\"ID\" type=\"xs:int\" />\n <xs:element name=\"Name\" type=\"xs:string\" minOccurs=\"0\" />\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n <xs:element name=\"Table2\">\n <xs:complexType>\n <xs:sequence>\n <xs:element name=\"OrderID\" type=\"xs:int\" />\n <xs:element name=\"CustomerID\" type=\"xs:int\" minOccurs=\"0\" />\n <xs:element name=\"OrderDate\" type=\"xs:dateTime\" minOccurs=\"0\" />\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n </xs:choice>\n </xs:complexType>\n <xs:unique name=\"Constraint1\" msdata:PrimaryKey=\"true\">\n <xs:selector xpath=\".//Table1\" />\n <xs:field xpath=\"ID\" />\n </xs:unique>\n <xs:unique name=\"Table2_Constraint1\" msdata:ConstraintName=\"Constraint1\" msdata:PrimaryKey=\"true\">\n <xs:selector xpath=\".//Table2\" />\n <xs:field xpath=\"OrderID\" />\n </xs:unique>\n <xs:keyref name=\"CustomerOrder\" refer=\"Constraint1\">\n <xs:selector xpath=\".//Table2\" />\n <xs:field xpath=\"CustomerID\" />\n </xs:keyref>\n </xs:element>\n</xs:schema>";
Assert.AreEqual (expected2, writer2.ToString ().Replace("\r\n", "\n"), "#2");
}
示例9: TestWriteXmlSchema3
public void TestWriteXmlSchema3()
{
DataTable dt = new DataTable("TestWriteXmlSchema");
dt.Columns.Add("Col1", typeof(int));
dt.Columns.Add("Col2", typeof(int));
DataRow dr = dt.NewRow();
dr[0] = 10;
dr[1] = 20;
dt.Rows.Add (dr);
DataTable dt1 = new DataTable("HelloWorld");
dt1.Columns.Add("T1", typeof(int));
dt1.Columns.Add("T2", typeof(int));
DataRow dr1 = dt1.NewRow();
dr1[0] = 10;
dr1[1] = 20;
dt1.Rows.Add(dr1);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.Tables.Add(dt1);
DataRelation rel = new DataRelation("Relation1", dt.Columns["Col1"], dt1.Columns["T1"]);
ds.Relations.Add(rel);
TextWriter writer = new StringWriter ();
dt.WriteXmlSchema (writer, true);
string TextString = writer.ToString ();
string substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?>", substring, "test#01");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual ("<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">", substring, "test#02");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"TestWriteXmlSchema\" msdata:UseCurrentLocale=\"true\">", substring, "test#03");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:complexType>", substring, "test#04");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">", substring, "test#05");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"TestWriteXmlSchema\">", substring, "test#06");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:complexType>", substring, "test#07");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:sequence>", substring, "test#08");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"Col1\" type=\"xs:int\" minOccurs=\"0\" />", substring, "test#09");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"Col2\" type=\"xs:int\" minOccurs=\"0\" />", substring, "test#10");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:sequence>", substring, "test#11");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:complexType>", substring, "test#12");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:element>", substring, "test#13");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"HelloWorld\">", substring, "test#14");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:complexType>", substring, "test#15");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:sequence>", substring, "test#16");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"T1\" type=\"xs:int\" minOccurs=\"0\" />", substring, "test#17");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"T2\" type=\"xs:int\" minOccurs=\"0\" />", substring, "test#18");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:sequence>", substring, "test#19");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
//.........這裏部分代碼省略.........
示例10: TestWriteXmlSchema1
public void TestWriteXmlSchema1 ()
{
DataTable dt = new DataTable("TestWriteXmlSchema");
dt.Columns.Add("Col1", typeof(int));
dt.Columns.Add("Col2", typeof(int));
DataRow dr = dt.NewRow();
dr[0] = 10;
dr[1] = 20;
dt.Rows.Add (dr);
DataTable dt1 = new DataTable("HelloWorld");
dt1.Columns.Add("T1", typeof(int));
dt1.Columns.Add("T2", typeof(int));
DataRow dr1 = dt1.NewRow();
dr1[0] = 10;
dr1[1] = 20;
dt1.Rows.Add(dr1);
TextWriter writer = new StringWriter ();
dt.WriteXmlSchema (writer);
string TextString = writer.ToString ();
string substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?>", substring, "test#01");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual ("<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">", substring, "test#02");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"TestWriteXmlSchema\" msdata:UseCurrentLocale=\"true\">", substring, "test#03");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:complexType>", substring, "test#04");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">", substring, "test#05");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"TestWriteXmlSchema\">", substring, "test#06");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:complexType>", substring, "test#07");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:sequence>", substring, "test#08");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"Col1\" type=\"xs:int\" minOccurs=\"0\" />", substring, "test#09");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" <xs:element name=\"Col2\" type=\"xs:int\" minOccurs=\"0\" />", substring, "test#10");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:sequence>", substring, "test#11");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:complexType>", substring, "test#12");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:element>", substring, "test#13");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:choice>", substring, "test#14");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:complexType>", substring, "test#15");
substring = TextString.Substring (0, TextString.IndexOf(EOL));
TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length);
Assert.AreEqual (" </xs:element>", substring, "test#16");
Assert.AreEqual ("</xs:schema>", TextString, "test#17");
}
示例11: DataToXml
/// <summary>
/// Sérialise une DataTable en XML
/// </summary>
/// <param name="tab">La DataTable à sérialiser</param>
/// <param name="fileName">Le nom du fichier XML</param>
/// <param name="filePath">Le chemin du fichier XML</param>
/// <param name="withSchema">Inclure le schéma ? (vrai par défaut)</param>
public static void DataToXml(DataTable tab, string fileName, string filePath, bool withSchema = true)
{
if (withSchema)
{
tab.WriteXmlSchema(ToolBoxUtilities.SchemaPath(fileName, filePath));
tab.WriteXml(ToolBoxUtilities.XmlPath(fileName, filePath));
}
else
tab.WriteXml(ToolBoxUtilities.XmlPath(fileName, filePath));
}
示例12: ExportXml
private static string ExportXml(string folder, DataTable table, bool writeXml, bool writeXsd)
{
string path = folder;
string xml = "";
string xsd = "";
if (table == null)
{
return "";
}
if (table.TableName == "")
{
table.TableName = "Table";
}
if (!path.EndsWith(@"\"))
{
path += @"\";
}
if (writeXsd)
{
xsd = path + table.TableName + ".xsd";
table.WriteXmlSchema(xsd);
}
if (writeXml)
{
xml = path + table.TableName + ".xml";
table.WriteXml(xml);
path = xml;
}
else
{
path = xsd;
}
return path;
}
示例13: GetDataTable
//.........這裏部分代碼省略.........
dt.Columns.Add(DataNames.Published, typeof(DateTime));
dt.Columns.Add(DataNames.Pos, typeof(int));
dt.Columns.Add(DataNames.State, typeof(int));
dt.Columns.Add(DataNames.IsPublished, typeof(bool));
dt.Columns.Add(DataNames.EnableComments, typeof(bool));
dt.Columns.Add(DataNames.Slug, typeof(string));
dt.Columns.Add(DataNames.Path, typeof(string));
dt.Columns.Add(DataNames.Tags, typeof(string));
dt.Columns.Add(DataNames.Categories, typeof(string));
dt.Columns.Add(DataNames.Owner, typeof(string));
dt.Columns.Add(DataNames.Modifier, typeof(string));
dt.Columns.Add(DataNames.Ratings, typeof(double));
dt.Columns.Add(DataNames.Reads, typeof(int));
dt.Columns.Add(DataNames.TotalAttachs, typeof(int));
dt.Columns.Add(DataNames.TotalVotes, typeof(int));
dt.Columns.Add(DataNames.TotalComms, typeof(int));
dt.Columns.Add(DataNames.TotalShares, typeof(int));
dt.Columns.Add(DataNames.Version, typeof(int));
dt.Columns.Add(DataNames.HasChildren, typeof(bool));
dt.PrimaryKey = new DataColumn[] { idColumn };
#endregion
var vfs = this.FieldRefs.Count == 0 ? this.Parent.Fields.Select(f => f).ToList() : this.FieldRefs.Select(f => f.Field).ToList();
foreach (var f in vfs)
dt.Columns.Add(f.Name, f.SystemType);
foreach (var item in items)
{
var itemWrapper = new ContentDataItemDecorator(item, Context);
int[] cats = null;
if (item.Categories != null)
cats = item.Categories.Select(c => c.ID).ToArray();
#region add new row
var row = dt.NewRow();
row[DataNames.ID] = item.ID;
row[DataNames.ParentID] = item.ParentItemID;
row[DataNames.Privacy] = item.Privacy;
row[DataNames.Created] = item.Created;
row[DataNames.Pos] = item.Pos;
if (item.Modified.HasValue)
row[DataNames.Modified] = item.Modified;
if (item.Published.HasValue)
row[DataNames.Published] = item.Published;
row[DataNames.IsPublished] = item.IsPublished;
row[DataNames.Modifier] = item.Modifier;
row[DataNames.State] = item.ModerateState;
row[DataNames.Tags] = item.Tags;
row[DataNames.Slug] = item.Slug;
row[DataNames.Path] = item.Path;
row[DataNames.Categories] = cats != null ? (string.Join(",", Context.Where<Category>(c => cats.Contains(c.ID)).Select(c => c.Name).ToArray())) : "";
row[DataNames.EnableComments] = item.EnableComments;
row[DataNames.Owner] = item.Owner;
row[DataNames.Ratings] = item.Ratings;
row[DataNames.Reads] = item.Reads;
row[DataNames.TotalAttachs] = item.TotalAttachments;
row[DataNames.TotalVotes] = item.TotalVotes;
row[DataNames.TotalComms] = itemWrapper.TotalComments;
row[DataNames.TotalShares] = Parent.AllowResharing ? itemWrapper.Reshares().Count() : 0;
row[DataNames.Version] = itemWrapper.Version;
row[DataNames.HasChildren] = Parent.IsHierarchy ? itemWrapper.Children().Count() > 0 : false;
foreach (var v in vfs)
{
var raw = itemWrapper.Value(v.Name).Raw;
if (raw == null)
row[v.Name] = DBNull.Value;
else
row[v.Name] = raw;
}
dt.Rows.Add(row);
#endregion
}
dt.AcceptChanges();
dt.DefaultView.Sort = this.Sort;
dt.DefaultView.RowFilter = FormatFilter(this.Filter);
//At first we need to apply the first filter for this table
cacheTable = dt.DefaultView.ToTable();
cacheTable.PrimaryKey = new DataColumn[] { cacheTable.Columns[DataNames.ID] };
cacheTable.WriteXml(viewDataFile);
cacheTable.WriteXmlSchema(schema, true);
}
else
{
dt.ReadXmlSchema(schema);
dt.ReadXml(viewDataFile);
cacheTable = dt;
}
//AddToCache(dt);
return cacheTable;
}
示例14: EscribeLog
public static void EscribeLog(string Mensaje, TipoImagen Imagen)
{
try
{
switch (Imagen)
{
case TipoImagen.Informacion:
LogManager.WriteEntry(Mensaje, EventLogEntryType.Information);
break;
case TipoImagen.Advertencia:
LogManager.WriteEntry(Mensaje, EventLogEntryType.Warning);
break;
case TipoImagen.TipoError:
LogManager.WriteEntry(Mensaje, EventLogEntryType.Error);
break;
}
if (!System.IO.Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\XbeeManagementLog"))
{
System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\XbeeManagementLog");
}
string NombreLog = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\XbeeManagementLog\\logXbee" + System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString();
//pregunta si existe
if (System.IO.File.Exists(NombreLog + ".xml") == false)
{
using (DataTable dtLogRegistrados = new DataTable())
{
dtLogRegistrados.TableName = "RegistrosLog";
dtLogRegistrados.Columns.Add("Fecha");
dtLogRegistrados.Columns.Add("Mensaje");
dtLogRegistrados.Columns.Add("Imagen");
DataRow dtRow = default(DataRow);
dtRow = dtLogRegistrados.NewRow();
dtRow[0] = System.DateTime.Now;
dtRow[1] = Mensaje;
dtRow[2] = Imagen;
dtLogRegistrados.Rows.Add(dtRow);
dtLogRegistrados.WriteXmlSchema(NombreLog + ".xsd");
dtLogRegistrados.WriteXml(NombreLog + ".xml");
}
}
else
{
DataSet ds = new DataSet();
ds.ReadXml(NombreLog + ".xml");
using (DataTable dtLogRegistrados = new DataTable())
{
dtLogRegistrados.TableName = "RegistrosLog";
dtLogRegistrados.Columns.Add("Fecha");
dtLogRegistrados.Columns.Add("Mensaje");
dtLogRegistrados.Columns.Add("Imagen");
foreach (DataRow _item in ds.Tables[0].Rows)
{
DataRow _dtRow = default(DataRow);
_dtRow = dtLogRegistrados.NewRow();
_dtRow[0] = _item["Fecha"];
_dtRow[1] = _item["Mensaje"];
_dtRow[2] = _item["Imagen"];
dtLogRegistrados.Rows.Add(_dtRow);
}
DataRow dtRow = default(DataRow);
dtRow = dtLogRegistrados.NewRow();
dtRow[0] = System.DateTime.Now;
dtRow[1] = Mensaje;
dtRow[2] = Imagen;
dtLogRegistrados.Rows.Add(dtRow);
dtLogRegistrados.WriteXmlSchema(NombreLog + ".xsd");
dtLogRegistrados.WriteXml(NombreLog + ".xml");
}
}
}
catch (Exception ex)
{
// Diagnostics.EventLog.WriteEntry(EventLogIndigo.Source, ex.Message)
}
}
示例15: WriteDataTableDescription
static void WriteDataTableDescription (DataTable Dt, String AddOn)
{
String DataTableName = Dt.TableName;
String FileName = System.IO.Path.Combine (ProtokollDirectory, RunTimeIndicator + "_6_" + DataTableName + "_" + AddOn + "_.xml");
Dt.WriteXmlSchema (FileName);
}