protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int report_uid; int new_state; if (int.TryParse(Request.QueryString["report_uid"], out report_uid) == false) { return; } if (int.TryParse(Request.QueryString["state"], out new_state) == false) { new_state = 1; } using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Outputs"); DB.UpdateReportState(report_uid, new_state); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
/// <summary> /// 将内部数据转换成Json文本,并保存至文件 /// </summary> /// <param name="jsonPath">输出文件路径</param> public void SaveToXmlFile(string filePath, Encoding encoding, bool exportArray) { if (m_data == null) { throw new Exception("JsonExporter内部数据为空。"); } FileStream fileStream = new FileStream(filePath, FileMode.Create); System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(fileStream, encoding); writer.WriteStartDocument(); writer.WriteStartElement("Root"); foreach (var obj in m_data.Values) { writer.WriteStartElement("Item"); WriteXmlNode(writer, obj); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); fileStream.Close(); }
/// <summary> /// Creates XML string which represents search patient result</summary> /// <param name="parameters">query parameter</param> protected override string ReturnSearchPatientResult(Dictionary <string, string> parameters) { using (System.Xml.XmlWriter xmlWriter = new System.Xml.XmlTextWriter(XmlExchangeFile, Encoding.UTF8)) { try { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("ndd"); xmlWriter.WriteStartElement("Command"); xmlWriter.WriteAttributeString("Type", Commands.SearchPatientsResult.Command); xmlWriter.WriteEndElement();//command xmlWriter.WriteStartElement("Patients"); _benchForm.AddGuiPatient(xmlWriter); _benchForm.AddGuiPatient(xmlWriter); _benchForm.AddGuiPatient(xmlWriter); xmlWriter.WriteEndElement();//Patients xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); return(XmlExchangeFile); } finally { xmlWriter.Close(); } } }
public static void CreateEmptyXmlRepository() { if (!System.IO.File.Exists(Util.GetXML_RepoPath())) { System.Xml.XmlTextWriter text = new System.Xml.XmlTextWriter(Util.GetXML_RepoPath(), null); text.Formatting = System.Xml.Formatting.Indented; text.Indentation = 4; text.WriteStartDocument(); text.WriteStartElement("root"); text.WriteStartElement("book"); text.WriteStartAttribute("folder"); text.WriteEndAttribute(); text.WriteStartElement("page"); text.WriteStartAttribute("src"); text.WriteEndAttribute(); text.WriteEndElement(); text.WriteEndElement(); text.WriteEndElement(); text.WriteEndDocument(); text.Flush(); text.Close(); } }
public static void OutputFunctionNames(bool compact, string k_test_results_path, string file_name, string[] script_functions) { using (var t = new System.Xml.XmlTextWriter(System.IO.Path.Combine(k_test_results_path, file_name), System.Text.Encoding.ASCII)) { t.Indentation = 1; t.IndentChar = '\t'; t.Formatting = System.Xml.Formatting.Indented; t.WriteStartDocument(); t.WriteStartElement("Functions"); for (int x = 0; x < script_functions.Length; x++) { if (script_functions[x] != "123") { t.WriteStartElement("entry"); t.WriteAttributeString("key", "0x" + x.ToString("X3")); t.WriteAttributeString("value", script_functions[x]); t.WriteEndElement(); } else if (!compact) { t.WriteStartElement("entry"); t.WriteAttributeString("key", "0x" + x.ToString("X3")); t.WriteAttributeString("value", "UNKNOWN"); t.WriteEndElement(); } } t.WriteEndElement(); t.WriteEndDocument(); } }
private void CreateRSS() { //...XmlTextWriter RSSFeed = new XmlTextWriter(MapPath("./" + "RSS.rss"), System.Text.Encoding.UTF8); System.Xml.XmlTextWriter RSSFeed = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8); // Write the rss tags like title, version, // Channel, title, link description copyright etc. RSSFeed.WriteStartDocument(); RSSFeed.WriteStartElement("rss"); RSSFeed.WriteAttributeString("version", "2.0"); RSSFeed.WriteStartElement("channel"); RSSFeed.WriteElementString("title", "Mehdi Naseri RSS"); RSSFeed.WriteElementString("description", "This Website has been made by: Mehdi Naseri"); RSSFeed.WriteElementString("link", "http://naseri.somee.com"); RSSFeed.WriteElementString("pubDate", DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss +0000")); RSSFeed.WriteElementString("copyright", "Copyright Mehdi Naseri 2012"); //Items of RSS for (int i = 0; i < 3; i++) { RSSFeed.WriteStartElement("item"); RSSFeed.WriteElementString("title", string.Format("Title " + (i + 1).ToString())); RSSFeed.WriteElementString("description", string.Format("Description " + (i + 1).ToString())); RSSFeed.WriteElementString("link", "http://naseri.somee.com/RSS.aspx"); //RSSFeed.WriteElementString("pubDate", "Mon, 06 Sep 2009 16:45:00 +0000"); RSSFeed.WriteElementString("pubDate", DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss +0000")); RSSFeed.WriteEndElement(); } RSSFeed.WriteEndElement(); RSSFeed.WriteEndElement(); RSSFeed.WriteEndDocument(); RSSFeed.Flush(); RSSFeed.Close(); Response.End(); }
public IRequest Marshall(CreateTopicRequest publicRequest) { MemoryStream stream = new MemoryStream(); System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8); writer.WriteStartDocument(); writer.WriteStartElement(MNSConstants.XML_ROOT_TOPIC, MNSConstants.MNS_XML_NAMESPACE); var attrs = publicRequest.Attributes; if (attrs.IsSetMaximumMessageSize()) { writer.WriteElementString(MNSConstants.XML_ELEMENT_MAXIMUM_MESSAGE_SIZE, attrs.MaximumMessageSize.ToString()); } if (attrs.IsSetLoggingEnabled()) { writer.WriteElementString(MNSConstants.XML_ELEMENT_LOGGING_ENABLED, attrs.LoggingEnabled.ToString()); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); IRequest request = new DefaultRequest(publicRequest, MNSConstants.MNS_SERVICE_NAME); request.HttpMethod = HttpMethod.PUT.ToString(); request.ContentStream = stream; request.ResourcePath = MNSConstants.MNS_TOPIC_PRE_RESOURCE + publicRequest.TopicName; return(request); }
private void buttonSyncPatient_Click(object sender, EventArgs e) { if (_ReceiveMsgMethod == null) { return; } StringBuilder sb = new System.Text.StringBuilder(); using (System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(new System.IO.StringWriter(sb, CultureInfo.InvariantCulture))) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("ndd"); AddCommand(Commands.TestResult.Command, xmlWriter, Commands.ShowTest.OrderID, textBoxOrderID.Text); xmlWriter.WriteStartElement("Patients"); AddGuiPatient(xmlWriter); xmlWriter.WriteEndElement();//Patients xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); } CallReceiveMsgMethod(sb.ToString()); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int callstack_uid; if (int.TryParse(Request.QueryString["callstack_uid"], out callstack_uid) == false) callstack_uid = 1; using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Callstack"); DB.LoadCallstack(callstack_uid, delegate(int depth, string funcname, string fileline) { writer.WriteStartElement("Singlestep"); writer.WriteAttributeString("depth", depth.ToString()); this.WriteCData(writer, "Funcname", funcname); this.WriteCData(writer, "Fileline", fileline); writer.WriteEndElement(); } ); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
/// <summary> /// Returns the list of features this plug-in supports: like Worklist, CurveData, Attachment_Type, Attachment_Path</summary> protected virtual string ReturnSupportedFeatures() { //- Example - //<?xml version="1.0" encoding="utf-16"?> //<ndd> // <Command Type="SupportedFeatures"> // <Parameter Name="SearchPatients"></Parameter> // </Command> //</ndd> StringBuilder sb = new System.Text.StringBuilder(); using (System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(new System.IO.StringWriter(sb, CultureInfo.InvariantCulture))) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("ndd"); xmlWriter.WriteStartElement("Command"); xmlWriter.WriteAttributeString("Type", Commands.SupportedFeatures.Command); foreach (string strFeature in GetSupportedFeatures()) { xmlWriter.WriteStartElement("Parameter"); xmlWriter.WriteAttributeString("Name", strFeature); xmlWriter.WriteValue("True"); xmlWriter.WriteEndElement();//parameter } xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); return(sb.ToString()); } }
private void saveButton_Click(object sender, System.EventArgs e) { if (System.IO.File.Exists(jmjcmptst)) { System.IO.StreamReader sr = new System.IO.StreamReader(jmjcmptst); saveFileDialog1.InitialDirectory = sr.ReadToEnd(); sr.Close(); } if (saveFileDialog1.ShowDialog(this) != DialogResult.OK) { return; } System.IO.File.Delete(jmjcmptst); System.IO.StreamWriter sw = new System.IO.StreamWriter(jmjcmptst); sw.Write(System.IO.Path.GetDirectoryName(saveFileDialog1.FileName)); sw.Flush(); sw.Close(); sw = new System.IO.StreamWriter(saveFileDialog1.FileName); System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(sw); xw.WriteStartDocument(); xw.WriteStartElement("JMJComponentTestCase"); xw.WriteElementString("component_wrapper_class", "EncounterPRO.OS.Component." + ddlWrapperClass.Text); xw.WriteElementString("component_class", tClass.Text); xw.WriteElementString("component_version", tAssembly.Text); xw.WriteElementString("component_attributes_xml", tComponentAttributes.Text); xw.WriteElementString("credential_attributes_xml", tCredentialAttributes.Text); xw.WriteElementString("context_xml", tClinicalContext.Text); xw.WriteEndElement(); xw.WriteEndDocument(); xw.Flush(); xw.Close(); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Project"); writer.WriteStartElement("Items"); Dictionary<int, sProject> projectList; DB.LoadProject(out projectList); foreach (KeyValuePair<int, sProject> item in projectList) { writer.WriteStartElement("Item"); writer.WriteAttributeString("uid", item.Key.ToString()); writer.WriteAttributeString("name", item.Value.name); writer.WriteEndElement(); } writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int callstack_uid; if (int.TryParse(Request.QueryString["callstack_uid"], out callstack_uid) == false) { callstack_uid = 1; } using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Callstack"); DB.LoadCallstack(callstack_uid, delegate(int depth, string funcname, string fileline) { writer.WriteStartElement("Singlestep"); writer.WriteAttributeString("depth", depth.ToString()); this.WriteCData(writer, "Funcname", funcname); this.WriteCData(writer, "Fileline", fileline); writer.WriteEndElement(); } ); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
public void Load(DCompilerConfiguration compiler) { configuration = compiler; if (compiler == null) { txtBinPath.Text = txtCompiler.Text = txtConsoleAppLinker.Text = txtSharedLibLinker.Text = txtStaticLibLinker.Text = null; text_DefaultLibraries.Buffer.Clear(); text_Includes.Buffer.Clear(); releaseArgumentsDialog.Load(null, false); debugArgumentsDialog.Load(null, true); btnMakeDefault.Sensitive = false; return; } //for now, using Executable target compiler command for all targets source compiling LinkTargetConfiguration targetConfig; targetConfig = compiler.GetOrCreateTargetConfiguration(DCompileTarget.Executable); txtBinPath.Text = compiler.BinPath; txtCompiler.Text = compiler.SourceCompilerCommand; check_enableLibPrefixing.Active = compiler.EnableGDCLibPrefixing; //linker targets targetConfig = compiler.GetOrCreateTargetConfiguration(DCompileTarget.Executable); txtConsoleAppLinker.Text = targetConfig.Linker; targetConfig = compiler.GetOrCreateTargetConfiguration(DCompileTarget.SharedLibrary); txtSharedLibLinker.Text = targetConfig.Linker; targetConfig = compiler.GetOrCreateTargetConfiguration(DCompileTarget.StaticLibrary); txtStaticLibLinker.Text = targetConfig.Linker; releaseArgumentsDialog.Load(compiler, false); debugArgumentsDialog.Load(compiler, true); text_DefaultLibraries.Buffer.Text = string.Join(Environment.NewLine, compiler.DefaultLibraries); text_Includes.Buffer.Text = string.Join(Environment.NewLine, compiler.IncludePaths); btnMakeDefault.Active = configuration.Vendor == defaultCompilerVendor; btnMakeDefault.Sensitive = true; using (var buf = new StringWriter()) using (var xml = new System.Xml.XmlTextWriter(buf)) { xml.Formatting = System.Xml.Formatting.Indented; xml.WriteStartDocument(); xml.WriteStartElement("patterns"); compiler.ArgumentPatterns.SaveTo(xml); xml.WriteEndDocument(); tb_ArgPatterns.Buffer.Text = buf.ToString(); } }
public void WriteAccounts() { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(xml_path, System.Text.Encoding.Default); writer.Formatting = System.Xml.Formatting.Indented; writer.Indentation = 2; writer.IndentChar = ' '; writer.WriteStartDocument(true); writer.WriteStartElement("GalleryRemote"); foreach (GalleryAccount account in accounts) { writer.WriteStartElement("Account"); writer.WriteElementString("Name", account.Name); writer.WriteElementString("Url", account.Url); writer.WriteElementString("Username", account.Username); writer.WriteElementString("Password", account.Password); writer.WriteElementString("Version", account.Version.ToString()); writer.WriteEndElement(); //Account } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }
void saveConfiguration() { using (var cfg = new System.Xml.XmlTextWriter(ConfigFile, Encoding.UTF8)) { cfg.Formatting = System.Xml.Formatting.Indented; cfg.WriteStartDocument(); cfg.WriteStartElement("SporeMasterConfig"); cfg.WriteStartElement("Packages"); foreach (var p in PackageList.Items) { cfg.WriteElementString("Package", (p as ListBoxItem).Content as string); } cfg.WriteEndElement(); cfg.WriteStartElement("FullTextIndexExtensions"); foreach (var ext in FilesEditor.fullTextExtensions) { cfg.WriteElementString("Extension", ext); } cfg.WriteEndElement(); cfg.WriteElementString("WinMerge", FilesEditor.WinMergeEXE); cfg.WriteElementString("UnpackedFolderFormat", UnpackedFolderFormat); cfg.WriteEndElement(); cfg.WriteEndDocument(); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int callstack_uid; if (int.TryParse(Request.QueryString["callstack_uid"], out callstack_uid) == false) { callstack_uid = 1; } using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Callstack"); string callstack; if (DB.LoadCallstackPreview(callstack_uid, out callstack)) { writer.WriteCData(callstack); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
private void SendCommand(string command, Dictionary <string, string> cmdParameters) { StringBuilder sb = new System.Text.StringBuilder(); using (System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(new System.IO.StringWriter(sb, CultureInfo.InvariantCulture))) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("ndd"); AddCommand(command, xmlWriter, cmdParameters); xmlWriter.WriteStartElement("Patients"); AddGuiPatient(xmlWriter); xmlWriter.WriteEndElement();//Patients xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); } _emrPlugIn.SendMessage(sb.ToString()); // ndd internal code if (textBoxPatientID.Text.StartsWith("Exception", StringComparison.CurrentCultureIgnoreCase)) { throw new Exception("This Exception is for testing purpose"); } }
public IRequest Marshall(SubscribeRequest publicRequest) { MemoryStream stream = new MemoryStream(); System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8); writer.WriteStartDocument(); writer.WriteStartElement(MNSConstants.XML_ROOT_SUBSCRIPTION, MNSConstants.MNS_XML_NAMESPACE); writer.WriteElementString(MNSConstants.XML_ELEMENT_ENDPOINT, publicRequest.EndPoint); if (publicRequest.IsSetFilterTag()) { writer.WriteElementString(MNSConstants.XML_ELEMENT_FILTER_TAG, publicRequest.FilterTag); } if (publicRequest.IsSetStrategy()) { writer.WriteElementString(MNSConstants.XML_ELEMENT_NOTIFY_STRATEGY, publicRequest.Strategy.ToString()); } if (publicRequest.IsSetContentFormat()) { writer.WriteElementString(MNSConstants.XML_ELEMENT_NOTIFY_CONTENT_FORMAT, publicRequest.ContentFormat.ToString()); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); IRequest request = new DefaultRequest(publicRequest, MNSConstants.MNS_SERVICE_NAME); request.HttpMethod = HttpMethod.PUT.ToString(); request.ContentStream = stream; request.ResourcePath = MNSConstants.MNS_TOPIC_PRE_RESOURCE + publicRequest.TopicName + MNSConstants.MNS_SUBSCRIBE_PRE_RESOURCE + publicRequest.SubscriptionName; return(request); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int report_uid; int new_state; if (int.TryParse(Request.QueryString["report_uid"], out report_uid) == false) { return; } if (int.TryParse(Request.QueryString["state"], out new_state) == false) new_state = 1; using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Outputs"); DB.UpdateReportState(report_uid, new_state); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Project"); writer.WriteStartElement("Items"); Dictionary <int, sProject> projectList; DB.LoadProject(out projectList); foreach (KeyValuePair <int, sProject> item in projectList) { writer.WriteStartElement("Item"); writer.WriteAttributeString("uid", item.Key.ToString()); writer.WriteAttributeString("name", item.Value.name); writer.WriteEndElement(); } writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
/// <summary> /// 保存配置到配置文件 /// </summary> /// <param name="fileName">配置文件名</param> public virtual void SaveConfig(String fileName) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(fileName, Encoding.UTF8); try { writer.Formatting = System.Xml.Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("Jeelu.WordSegmentor"); foreach (CfgItem item in GetCfgItems()) { writer.WriteComment(item.Comment); writer.WriteStartElement("Item"); writer.WriteAttributeString("Name", item.Pi.Name); writer.WriteAttributeString("Value", item.Pi.GetValue(this, null).ToString()); writer.WriteEndElement(); //Item } writer.WriteEndElement(); //Jeelu.WordSegmentor writer.WriteEndDocument(); writer.Flush(); writer.Close(); } catch (Exception e) { WriteLog(String.Format("Save config fail, errmsg:{0}", e.Message)); } }
private void SendCommand(string command, Dictionary <string, string> cmdParameters, Dictionary <string, string> data, string token = "", string h_w_e = "") { //MessageBox.Show("Entra en SEND COMMAND: " + command + ":" + cmdParameters["OrderID"]); StringBuilder sb = new System.Text.StringBuilder(); using (System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(new System.IO.StringWriter(sb, CultureInfo.InvariantCulture))) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("ndd"); AddCommand(command, xmlWriter, cmdParameters); if (command.Equals("AddToWorklist") || command.Equals("RemoveWorklist")) //if (command.Equals("AddToWorklist")) { xmlWriter.WriteStartElement("Patients"); AddGuiPatient(xmlWriter, data, command, token, h_w_e); xmlWriter.WriteEndElement();//Patients } xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); Console.Write(xmlWriter); } SendMessage(sb.ToString()); // ndd internal code //if (textBoxPatientID.Text.StartsWith("Exception", StringComparison.CurrentCultureIgnoreCase)) // throw new Exception("This Exception is for testing purpose"); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int callstack_uid; string author = Request.QueryString["author"]; string comment = Request.QueryString["comment"]; if (int.TryParse(Request.QueryString["callstack_uid"], out callstack_uid) == false) { return; } using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Outputs"); bool res = DB.InsertCallstackComment(callstack_uid, author, comment); writer.WriteAttributeString("result", res.ToString()); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
/// <summary>ファイルのルートノードを閉じ、ファイルを閉じます。再度書き込みをしたい場合は、openFile()関数から再び始めて下さい。</summary> public void closeFile() { if (xtw != null) { xtw.WriteEndElement(); xtw.WriteEndDocument(); xtw.Close(); } }
protected virtual void SaveToFile(DataSet pDataSet) { if (m_FileName == null) { throw new ApplicationException("FileName is null"); } byte[] completeByteArray; using (System.IO.MemoryStream fileMemStream = new System.IO.MemoryStream()) { System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(fileMemStream, System.Text.Encoding.UTF8); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("filedataset", c_DataNamespace); xmlWriter.WriteStartElement("header", c_DataNamespace); //File Version xmlWriter.WriteAttributeString(c_FileVersion, c_FileVersionNumber.ToString()); //Data Version xmlWriter.WriteAttributeString(c_DataVersion, GetDataVersion().ToString()); //Data Format xmlWriter.WriteAttributeString(c_DataFormat, ((int)mSaveDataFormat).ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("data", c_DataNamespace); byte[] xmlByteArray; using (System.IO.MemoryStream xmlMemStream = new System.IO.MemoryStream()) { StreamDataSet.Write(xmlMemStream, pDataSet, mSaveDataFormat); //pDataSet.WriteXml(xmlMemStream); xmlByteArray = xmlMemStream.ToArray(); xmlMemStream.Close(); } xmlWriter.WriteBase64(xmlByteArray, 0, xmlByteArray.Length); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); completeByteArray = fileMemStream.ToArray(); fileMemStream.Close(); } //se tutto ?andato a buon fine scrivo effettivamente il file using (System.IO.FileStream fileStream = new System.IO.FileStream(m_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { fileStream.Write(completeByteArray, 0, completeByteArray.Length); fileStream.Close(); } }
protected virtual void OnButtonSaveGamesFileClicked(object sender, System.EventArgs e) { var saveDialog = new FileChooserDialog("Save Games File", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept); SetUniqueFileName(saveDialog, Nexus.Settings.Default.GamesFileDirectory, "game_config.xml"); saveDialog.DoOverwriteConfirmation = true; try { if (saveDialog.Run() == (int)ResponseType.Accept) { // Save games file using (var writer = new System.Xml.XmlTextWriter(saveDialog.Filename, System.Text.Encoding.UTF8)) { writer.Formatting = System.Xml.Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("games"); gameStore.Foreach(delegate(TreeModel model, TreePath path, TreeIter iter) { // Save individual game info var gameInfo = (IGameInfo)model.GetValue(iter, 3); writer.WriteStartElement("game"); writer.WriteAttributeString("name", gameInfo.GameName); writer.WriteAttributeString("description", gameInfo.GameDescription); gameInfo.Save(writer); writer.WriteEndElement(); return(false); }); // games writer.WriteEndElement(); writer.WriteEndDocument(); Nexus.Settings.Default.GamesFileDirectory = System.IO.Path.GetDirectoryName(saveDialog.Filename); } } } catch (Exception ex) { logger.Error("OnButtonSaveGamesFileClicked", ex); ShowErrorDialog(ex); } finally { saveDialog.Destroy(); } }
// Lecture de la configuration public static void WriteConfig() { string config_file = "config.xml"; var newconf = new System.Xml.XmlTextWriter(config_file, null); newconf.WriteStartDocument(); newconf.WriteStartElement("config"); newconf.WriteElementString("last_update", LastUpdate.ToShortDateString()); newconf.WriteElementString("auth_token", AuthToken); newconf.WriteEndElement(); newconf.WriteEndDocument(); newconf.Close(); }
public static void CreateDefaultXmlSettings() { if (!System.IO.File.Exists(Util.GetXML_SettingsPath())) { System.Xml.XmlTextWriter text = new System.Xml.XmlTextWriter(Util.GetXML_SettingsPath(), null); text.Formatting = System.Xml.Formatting.Indented; text.Indentation = 4; text.WriteStartDocument(); text.WriteStartElement("settings"); #region KEYS text.WriteStartElement("keys"); #region PAGING text.WriteStartElement("paging"); text.WriteAttributeString("forward", "18"); text.WriteAttributeString("back", "118"); text.WriteEndElement(); #endregion #region ZOOMING text.WriteStartElement("zooming"); text.WriteAttributeString("plus", "141"); text.WriteAttributeString("minus", "143"); text.WriteEndElement(); #endregion #region CLOSE_PROGRAMM text.WriteStartElement("escape"); text.WriteAttributeString("value", "13"); text.WriteEndElement(); #endregion #region HELP text.WriteStartElement("help"); text.WriteAttributeString("value", "90"); text.WriteEndElement(); #endregion text.WriteEndElement(); #endregion text.WriteEndElement(); text.WriteEndDocument(); text.Flush(); text.Close(); } }
public override void Terminate() { base.Terminate(); if (_StreamWriter != null) { _StreamWriter.WriteEndElement(); _StreamWriter.WriteEndDocument(); _StreamWriter.Close(); _StreamWriter = null; } }
// Lecture de la configuration static void ReadConfig() { string config_file = "config.xml"; if (!System.IO.File.Exists(config_file)) { var newconf = new System.Xml.XmlTextWriter(config_file, null); newconf.WriteStartDocument(); newconf.WriteStartElement("config"); newconf.WriteElementString("last_update", "0"); newconf.WriteElementString("auth_token", ""); newconf.WriteEndElement(); newconf.WriteEndDocument(); newconf.Close(); } var conf = new System.Xml.XmlTextReader(config_file); string CurrentElement = ""; while (conf.Read()) { switch(conf.NodeType) { case System.Xml.XmlNodeType.Element: CurrentElement = conf.Name; break; case System.Xml.XmlNodeType.Text: if (CurrentElement == "last_update") LastUpdate = DateTime.Parse(conf.Value); if (CurrentElement == "auth_token") AuthToken = conf.Value; break; } } conf.Close(); // On vérifie que le token est encore valide if (AuthToken.Length > 0) { var flickr = new Flickr(Program.ApiKey, Program.SharedSecret); try { Auth auth = flickr.AuthCheckToken(AuthToken); Username = auth.User.UserName; } catch (FlickrApiException ex) { //MessageBox.Show(ex.Message, "Authentification requise", // MessageBoxButtons.OK, MessageBoxIcon.Exclamation); AuthToken = ""; } } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int project_uid; if (int.TryParse(Request.QueryString["project"], out project_uid) == false) { project_uid = 1; } using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Report"); writer.WriteAttributeString("project", project_uid.ToString()); writer.WriteStartElement("Items"); DB.LoadReportDeleted(project_uid, delegate(int report_uid, string login_id, string ipaddr, DateTime reported_time, string relative_time, int callstack_uid, string funcname, string version, string filename, string assigned, string uservoice, int num_comments) { writer.WriteStartElement("Item"); writer.WriteAttributeString("report_uid", report_uid.ToString()); writer.WriteAttributeString("login_id", login_id); writer.WriteAttributeString("ipaddr", ipaddr); writer.WriteAttributeString("reported_time", reported_time.ToString()); writer.WriteAttributeString("relative_time", relative_time); writer.WriteAttributeString("callstack_uid", callstack_uid.ToString()); writer.WriteAttributeString("assigned", assigned); writer.WriteAttributeString("num_comments", num_comments.ToString()); this.WriteCData(writer, "Funcname", funcname); this.WriteCData(writer, "Version", version); this.WriteCData(writer, "Filename", filename); this.WriteCData(writer, "Uservoice", uservoice); writer.WriteEndElement(); } ); writer.WriteEndElement(); // Items writer.WriteEndElement(); // Report writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
private void SaveSettingsForm_Closed(object sender, EventArgs e) { // Save Settings System.Xml.XmlTextWriter tw = new System.Xml.XmlTextWriter(configFile, System.Text.Encoding.UTF8); tw.WriteStartDocument(); tw.WriteStartElement("Form"); WriteControlSettings(tw, this.Controls); tw.WriteEndElement(); tw.WriteEndDocument(); tw.Flush(); tw.Close(); }
public string GetXML() { System.IO.StringWriter strW = new System.IO.StringWriter(); using (System.Xml.XmlTextWriter xml = new System.Xml.XmlTextWriter(strW)) { xml.WriteStartDocument(); xml.WriteStartElement(ObjectName); #region SYSTEM PROPERTIES xml.WriteStartElement("__TimeStamp"); xml.WriteAttributeString("Type", typeof(DateTime).ToString()); xml.WriteAttributeString("Value", TimeStamp.ToString()); //xml.WriteValue(TimeStamp); xml.WriteEndElement(); #endregion #region OBJECT PROPERTIES LoggableProperties.ForEach(prop => { xml.WriteStartElement(prop.Name); xml.WriteAttributeString("Type", prop.PropInfo.PropertyType.ToString()); xml.WriteAttributeString("Value", prop.Value); //xml.WriteValue(prop.Value); xml.WriteEndElement(); }); #endregion xml.WriteEndElement(); xml.WriteEndDocument(); xml.Flush(); xml.Close(); } strW.Dispose(); //System.IO.StringReader sr = new System.IO.StringReader(strW.ToString()); //System.Xml.XmlTextReader xml = new System.Xml.XmlTextReader(sr); return(strW.ToString()); }
//e.g. Worklist, CurveData, Attachment_Type, Attachment_Path protected virtual string ReturnSearchPatientResult(Dictionary <string, string> parameters) { using (System.Xml.XmlWriter xmlWriter = new System.Xml.XmlTextWriter(XmlExchangeFile, Encoding.UTF8)) { try { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("ndd"); xmlWriter.WriteStartElement("Command"); xmlWriter.WriteAttributeString("Type", Commands.SearchPatientsResult.Command); xmlWriter.WriteEndElement();//command xmlWriter.WriteStartElement("Patients"); xmlWriter.WriteStartElement("Patient"); xmlWriter.WriteAttributeString("ID", "SearchPatient-ID"); xmlWriter.WriteElementString("LastName", "Search Last"); xmlWriter.WriteElementString("FirstName", "Search First"); xmlWriter.WriteStartElement("PatientDataAtPresent"); xmlWriter.WriteElementString("DateOfBirth", "1956-07-28"); xmlWriter.WriteElementString("Gender", "Female"); xmlWriter.WriteElementString("Height", "1.82"); xmlWriter.WriteElementString("Weight", "64"); xmlWriter.WriteElementString("Ethnicity", "Caucasian"); xmlWriter.WriteEndElement(); //PatientDataAtPresent xmlWriter.WriteEndElement(); //Patient xmlWriter.WriteEndElement(); //Patients xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); // xmlWriter.WriteString(@" //<ndd> //<command>Test xml data</command><Patients> // <Patient ID=""PSM-11213""> // <LastName>Smith</LastName> // <FirstName>Peter</FirstName></Patient> //</Patients> //</ndd>"); xmlWriter.Flush(); xmlWriter.Close(); return(XmlExchangeFile); } finally { xmlWriter.Close(); } } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int project_uid; if (int.TryParse(Request.QueryString["project"], out project_uid) == false) project_uid = 1; using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Report"); writer.WriteAttributeString("project", project_uid.ToString()); writer.WriteStartElement("Items"); DB.LoadReportDeleted(project_uid, delegate(int report_uid, string login_id, string ipaddr, DateTime reported_time, string relative_time, int callstack_uid, string funcname, string version, string filename, string assigned, string uservoice, int num_comments) { writer.WriteStartElement("Item"); writer.WriteAttributeString("report_uid", report_uid.ToString()); writer.WriteAttributeString("login_id", login_id); writer.WriteAttributeString("ipaddr", ipaddr); writer.WriteAttributeString("reported_time", reported_time.ToString()); writer.WriteAttributeString("relative_time", relative_time); writer.WriteAttributeString("callstack_uid", callstack_uid.ToString()); writer.WriteAttributeString("assigned", assigned); writer.WriteAttributeString("num_comments", num_comments.ToString()); this.WriteCData(writer, "Funcname", funcname); this.WriteCData(writer, "Version", version); this.WriteCData(writer, "Filename", filename); this.WriteCData(writer, "Uservoice", uservoice); writer.WriteEndElement(); } ); writer.WriteEndElement(); // Items writer.WriteEndElement(); // Report writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
/// <summary> /// Saves movie quotes to an xml file /// </summary> /// <param name="movie">IIMDbMovie object</param> /// <param name="xmlPath">path to save xml file to</param> /// <param name="overwrite">set to true to overwrite existing xml file</param> public static void SaveQuotes( IIMDbMovie movie, string xmlPath, bool overwrite) { System.Xml.XmlTextWriter xmlWr; try { if (File.Exists(xmlPath) == false || overwrite) if (movie.Quotes.Count > 0) { xmlWr = new System.Xml.XmlTextWriter(xmlPath, Encoding.Default) {Formatting = System.Xml.Formatting.Indented}; xmlWr.WriteStartDocument(); xmlWr.WriteStartElement("Quotes"); foreach (IList<IIMDbQuote> quoteBlock in movie.Quotes) { xmlWr.WriteStartElement("QuoteBlock"); foreach (IIMDbQuote quote in quoteBlock) { xmlWr.WriteStartElement("Quote"); xmlWr.WriteElementString("Character", quote.Character); xmlWr.WriteElementString("QuoteText", quote.Text); xmlWr.WriteEndElement(); } xmlWr.WriteEndElement(); } xmlWr.WriteEndElement(); xmlWr.WriteEndDocument(); xmlWr.Flush(); xmlWr.Close(); } } catch (Exception ex) { throw ex; } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int project_uid; int report_uid; string version; if (int.TryParse(Request.QueryString["project"], out project_uid) == false) project_uid = 1; if (int.TryParse(Request.QueryString["report_uid"], out report_uid) == false) { return; } version = Request.QueryString["version"]; if (version != null) { version.Trim(); if (version.Length == 0) version = null; } using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Outputs"); DB.ReserveReparse(project_uid, report_uid, version); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int callstack_uid; if (int.TryParse(Request.QueryString["callstack_uid"], out callstack_uid) == false) callstack_uid = 1; using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Comment"); writer.WriteAttributeString("callstack_uid", callstack_uid.ToString()); DB.ForEachCallstackComment CommentWriter = delegate(string author, string comment, DateTime created) { writer.WriteStartElement("Item"); writer.WriteAttributeString("author", author); writer.WriteAttributeString("created", created.ToString()); writer.WriteCData(comment); writer.WriteEndElement(); }; DB.LoadCallstackComment(callstack_uid, CommentWriter); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
/// <summary> /// Saves movie goofs to an xml file /// </summary> /// <param name="movie">IIMDbMovie object</param> /// <param name="xmlPath">path to save xml file to</param> /// <param name="overwrite">set to true to overwrite existing xml file</param> public void SaveGoofs( IIMDbMovie movie, string xmlPath, bool overwrite) { System.Xml.XmlTextWriter xmlWr; try { if (System.IO.File.Exists(xmlPath) == false || overwrite) if (movie.Goofs.Count > 0) { xmlWr = new System.Xml.XmlTextWriter(xmlPath, Encoding.Default); xmlWr.Formatting = System.Xml.Formatting.Indented; xmlWr.WriteStartDocument(); xmlWr.WriteStartElement("Goofs"); foreach (IIMDbGoof goof in movie.Goofs) { xmlWr.WriteStartElement("Goof"); xmlWr.WriteElementString("Category", goof.Category); xmlWr.WriteElementString("Description", goof.Description); xmlWr.WriteEndElement(); } xmlWr.WriteEndElement(); xmlWr.WriteEndDocument(); xmlWr.Flush(); xmlWr.Close(); xmlWr = null; } } catch (Exception ex) { throw ex; } }
/// <summary> /// Saves movie trivia to an xml file /// </summary> /// <param name="movie">IIMDbMovie object</param> /// <param name="xmlPath">path to save xml file to</param> /// <param name="overwrite">set to true to overwrite existing xml file</param> public void SaveTrivia( IIMDbMovie movie, string xmlPath, bool overwrite) { System.Xml.XmlTextWriter xmlWr; try { if (System.IO.File.Exists(xmlPath) == false || overwrite) if (movie.Trivia.Count > 0) { xmlWr = new System.Xml.XmlTextWriter(xmlPath, Encoding.Default); xmlWr.Formatting = System.Xml.Formatting.Indented; xmlWr.WriteStartDocument(); xmlWr.WriteStartElement("Trivias"); foreach (string trivia in movie.Trivia) { xmlWr.WriteElementString("Trivia", trivia); } xmlWr.WriteEndElement(); xmlWr.WriteEndDocument(); xmlWr.Flush(); xmlWr.Close(); xmlWr = null; } } catch (Exception ex) { throw ex; } }
public void Save() { System.Xml.XmlTextWriter settingsXML = new System.Xml.XmlTextWriter("settings.xml", System.Text.Encoding.UTF8); settingsXML.WriteStartDocument(); settingsXML.WriteStartElement("settings"); settingsXML.WriteStartElement("display"); settingsXML.WriteStartAttribute("fullscreen"); settingsXML.WriteValue(fullscreen); settingsXML.WriteStartAttribute("resolutionX"); settingsXML.WriteValue(resolutionX); settingsXML.WriteStartAttribute("resolutionY"); settingsXML.WriteValue(resolutionY); settingsXML.WriteEndElement(); settingsXML.WriteEndElement(); settingsXML.WriteEndDocument(); settingsXML.Close(); }
public void ToXml (System.IO.Stream stream) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter (stream, null); writer.WriteStartDocument (); writer.WriteStartElement ("world"); writer.WriteStartElement ("locks"); ToXmlHelper helper = new ToXmlHelper (this, writer); this.ForeachLock (new PackageMatchDelegate (helper.ForeachLock)); writer.WriteEndElement (); this.ToXml (writer); writer.WriteEndElement (); writer.WriteEndDocument (); writer.Flush (); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int callstack_uid; short fromDate = 60; short toDate = 0; if (int.TryParse(Request.QueryString["callstack_uid"], out callstack_uid) == false) callstack_uid = 1; using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Counts"); TrendCountList trendCount = new TrendCountList(); DB.LoadTrendCount(callstack_uid, fromDate, toDate, delegate(string version, string date, int count) { //dailyCountList[date] = count; DailyCountList dcl; if (trendCount.TryGetValue(version, out dcl) == false) { trendCount[version] = new DailyCountList(); for (int i = fromDate; i >= toDate; i--) { TimeSpan days = new TimeSpan(i, 0, 0, 0); DateTime saveDate = DateTime.Now.Subtract(days); string simulated_date = string.Format("{0:0000}-{1:00}-{2:00}", saveDate.Year, saveDate.Month, saveDate.Day); trendCount[version][simulated_date] = 0; } } trendCount[version][date] = count; } ); foreach (KeyValuePair<string, DailyCountList> trend in trendCount) { writer.WriteStartElement("Version"); writer.WriteAttributeString("name", trend.Key.Replace("\0", "")); foreach (KeyValuePair<string, int> v in trend.Value) { writer.WriteStartElement("Count"); writer.WriteAttributeString("date", v.Key); writer.WriteAttributeString("count", v.Value.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
private void SaveWatchList() { // Sort all the watchlists if (this.WatchLists != null) { foreach (StockWatchList watchList in this.WatchLists) { watchList.StockList.Sort(); } // Save watch list file string watchListsFileName = Settings.Default.RootFolder + @"\WatchLists.xml"; System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings(); settings.Indent = true; settings.NewLineOnAttributes = true; using (FileStream fs = new FileStream(watchListsFileName, FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(List<StockWatchList>)); System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(fs, null); xmlWriter.Formatting = System.Xml.Formatting.Indented; xmlWriter.WriteStartDocument(); serializer.Serialize(xmlWriter, this.WatchLists); xmlWriter.WriteEndDocument(); } } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int project_uid; int pageNo; int pageSize; bool seperate_version; string specific_version; int hideResolved = 0; int fromDate; int toDate; if (int.TryParse(Request.QueryString["project"], out project_uid) == false) project_uid = 1; if (int.TryParse(Request.QueryString["pageNo"], out pageNo) == false) pageNo = 1; if (int.TryParse(Request.QueryString["pageSize"], out pageSize) == false) pageSize = 30; if (int.TryParse(Request.QueryString["from"], out fromDate) == false) fromDate = 0; if (int.TryParse(Request.QueryString["to"], out toDate) == false) toDate = 0; if (bool.TryParse(Request.QueryString["sv"], out seperate_version) == false) seperate_version = false; specific_version = Request.QueryString["ver"]; if (specific_version != null) { specific_version.Trim(); if (specific_version.Length <= 0) specific_version = null; } string temp1 = Request.QueryString["hideResolved"]; string temp2 = Request.QueryString["hideExamination"]; Boolean check1 = false; Boolean check2 = false; if (temp1 != null) check1 = Boolean.Parse(temp1); if (temp2 != null) check2 = Boolean.Parse(temp2); if (check1 && check2) hideResolved = 3; else if (check1) hideResolved = 1; else if (check2) hideResolved = 2; using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Callstack"); writer.WriteAttributeString("project", project_uid.ToString()); writer.WriteAttributeString("pageNo", pageNo.ToString()); writer.WriteAttributeString("pageSize", pageSize.ToString()); writer.WriteAttributeString("req", specific_version); writer.WriteStartElement("Items"); DB.ForEachCallstackGroup ItemWriter = delegate(int count, int callstack_uid, string funcname, string version, DateTime latest_time, string relative_time, string assigned, int num_comments) { writer.WriteStartElement("Item"); writer.WriteAttributeString("count", count.ToString()); writer.WriteAttributeString("callstack_uid", callstack_uid.ToString()); writer.WriteAttributeString("latest_time", latest_time.ToString()); writer.WriteAttributeString("relative_time", relative_time); writer.WriteAttributeString("assigned", assigned); writer.WriteAttributeString("num_comments", num_comments.ToString()); this.WriteCData(writer, "Funcname", funcname); this.WriteCData(writer, "Version", version); writer.WriteEndElement(); }; int totalPageSize = 0; DB.LoadCallstackList(project_uid, pageNo, pageSize, fromDate, toDate, seperate_version, specific_version, hideResolved, ItemWriter, out totalPageSize); writer.WriteEndElement(); // Items writer.WriteStartElement("Outputs"); this.WriteCData(writer, "TotalPageSize", totalPageSize.ToString()); writer.WriteEndElement(); // Outputs writer.WriteEndElement(); // Callstack writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
void saveConfiguration() { using (var cfg = new System.Xml.XmlTextWriter(ConfigFile, Encoding.UTF8)) { cfg.Formatting = System.Xml.Formatting.Indented; cfg.WriteStartDocument(); cfg.WriteStartElement("SporeMasterConfig"); cfg.WriteStartElement("Packages"); foreach (var p in PackageList.Items) cfg.WriteElementString("Package", (p as ListBoxItem).Content as string); cfg.WriteEndElement(); cfg.WriteStartElement("FullTextIndexExtensions"); foreach (var ext in FilesEditor.fullTextExtensions) cfg.WriteElementString("Extension", ext); cfg.WriteEndElement(); cfg.WriteElementString("WinMerge", FilesEditor.WinMergeEXE); cfg.WriteElementString("UnpackedFolderFormat", UnpackedFolderFormat); cfg.WriteEndElement(); cfg.WriteEndDocument(); } }
public void SaveResources() { using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Controller.ResourcesFile, Encoding.UTF8)) { writer.Formatting = System.Xml.Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("resources"); foreach (Resource resource in _resourceList.Values) { if (resource != Root) resource.WriteXML(writer); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
public static void Export( IDocument document, string filePath ) { // Write XML using standard .NET Framework tools. Maps elements to // a customized schema System.Xml.XmlTextWriter xwriter = new System.Xml.XmlTextWriter( filePath, System.Text.Encoding.UTF8 ); try { xwriter.WriteStartDocument( true ); exportDocument( xwriter, document ); xwriter.WriteEndDocument(); } finally { xwriter.Close(); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.NoCache); int project_uid; int pageNo; int pageSize; int filterType; string filterValue; int hideResolved = 0; if (int.TryParse(Request.QueryString["project"], out project_uid) == false) project_uid = 1; if (int.TryParse(Request.QueryString["pageNo"], out pageNo) == false) pageNo = 1; if (int.TryParse(Request.QueryString["pageSize"], out pageSize) == false) pageSize = 30; if (int.TryParse(Request.QueryString["filterType"], out filterType) == false) filterType = 0; filterValue = Request.QueryString["filterValue"]; if (filterValue == null) filterValue = ""; string temp1 = Request.QueryString["hideResolved"]; string temp2 = Request.QueryString["hideExamination"]; Boolean check1 = false; Boolean check2 = false; if (temp1 != null) check1 = Boolean.Parse(temp1); if (temp2 != null) check2 = Boolean.Parse(temp2); if (check1 && check2) hideResolved = 3; else if (check1) hideResolved = 1; else if (check2) hideResolved = 2; using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("Report"); writer.WriteAttributeString("project", project_uid.ToString()); writer.WriteAttributeString("pageNo", pageNo.ToString()); writer.WriteAttributeString("pageSize", pageSize.ToString()); writer.WriteStartElement("Items"); int totalPageSize = 0; DB.LoadReport(project_uid, pageNo, pageSize, delegate(int report_uid, string login_id, string ipaddr, DateTime reported_time, string relative_time, int callstack_uid, string funcname, string version, string filename, string assigned, string uservoice, int num_comments) { writer.WriteStartElement("Item"); writer.WriteAttributeString("report_uid", report_uid.ToString()); writer.WriteAttributeString("login_id", login_id); writer.WriteAttributeString("ipaddr", ipaddr); writer.WriteAttributeString("reported_time", reported_time.ToString()); writer.WriteAttributeString("relative_time", relative_time); writer.WriteAttributeString("callstack_uid", callstack_uid.ToString()); writer.WriteAttributeString("assigned", assigned); writer.WriteAttributeString("num_comments", num_comments.ToString()); this.WriteCData(writer, "Funcname", funcname); this.WriteCData(writer, "Version", version); this.WriteCData(writer, "Filename", filename); this.WriteCData(writer, "Uservoice", uservoice); writer.WriteEndElement(); }, out totalPageSize, (DB.ReportWhereFilter)filterType, filterValue, hideResolved ); writer.WriteEndElement(); // Items writer.WriteStartElement("Outputs"); this.WriteCData(writer, "TotalPageSize", totalPageSize.ToString()); writer.WriteEndElement(); // Outputs writer.WriteEndElement(); // Report writer.WriteEndDocument(); writer.Flush(); writer.Close(); } }
protected virtual void SaveToFile(DataSet pDataSet) { if (m_FileName == null) throw new ApplicationException("FileName is null"); byte[] completeByteArray; using (System.IO.MemoryStream fileMemStream = new System.IO.MemoryStream()) { System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(fileMemStream, System.Text.Encoding.UTF8); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("filedataset", c_DataNamespace); xmlWriter.WriteStartElement("header", c_DataNamespace); //File Version xmlWriter.WriteAttributeString(c_FileVersion, c_FileVersionNumber.ToString()); //Data Version xmlWriter.WriteAttributeString(c_DataVersion, GetDataVersion().ToString()); //Data Format xmlWriter.WriteAttributeString(c_DataFormat, ((int)mSaveDataFormat).ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("data", c_DataNamespace); byte[] xmlByteArray; using (System.IO.MemoryStream xmlMemStream = new System.IO.MemoryStream()) { StreamDataSet.Write(xmlMemStream, pDataSet, mSaveDataFormat); //pDataSet.WriteXml(xmlMemStream); xmlByteArray = xmlMemStream.ToArray(); xmlMemStream.Close(); } xmlWriter.WriteBase64(xmlByteArray, 0, xmlByteArray.Length); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); completeByteArray = fileMemStream.ToArray(); fileMemStream.Close(); } //se tutto è andato a buon fine scrivo effettivamente il file using (System.IO.FileStream fileStream = new System.IO.FileStream(m_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { fileStream.Write(completeByteArray, 0, completeByteArray.Length); fileStream.Close(); } }
/// <summary> /// Create RSSRoot and write it to stream. /// </summary> /// <param name="rSSRoot"></param> /// <returns></returns> public static bool PublishRSS(RSSRoot rSSRoot) { bool blnResult = true; if(rSSRoot == null) return(false); if(rSSRoot.Channel == null) return(false); System.Xml.XmlTextWriter oXmlTextWriter = new System.Xml.XmlTextWriter(rSSRoot.OutputStream, System.Text.Encoding.UTF8); oXmlTextWriter.WriteStartDocument(); oXmlTextWriter.WriteStartElement("rss"); oXmlTextWriter.WriteAttributeString("version", "2.0"); oXmlTextWriter.WriteStartElement("channel"); oXmlTextWriter.WriteElementString("link", rSSRoot.Channel.Link); oXmlTextWriter.WriteElementString("title", rSSRoot.Channel.Title); oXmlTextWriter.WriteElementString("description", rSSRoot.Channel.Description); if(rSSRoot.Channel.Docs != "") oXmlTextWriter.WriteElementString("docs", rSSRoot.Channel.Docs); if(rSSRoot.Channel.PubDate != "") { System.DateTime sDateTime = System.Convert.ToDateTime(rSSRoot.Channel.PubDate); oXmlTextWriter.WriteElementString("pubDate", sDateTime.ToString("ddd, dd MMM yyyy HH:mm:ss G\\MT")); } if(rSSRoot.Channel.Generator != "") oXmlTextWriter.WriteElementString("generator", rSSRoot.Channel.Generator); if(rSSRoot.Channel.WebMaster != "") oXmlTextWriter.WriteElementString("webMaster", rSSRoot.Channel.WebMaster); if(rSSRoot.Channel.Copyright != "") oXmlTextWriter.WriteElementString("copyright", rSSRoot.Channel.Copyright); if(rSSRoot.Channel.LastBuildDate != "") { System.DateTime sDateTime = System.Convert.ToDateTime(rSSRoot.Channel.LastBuildDate); oXmlTextWriter.WriteElementString("lastBuildDate", sDateTime.ToString("ddd, dd MMM yyyy HH:mm:ss G\\MT")); } if(rSSRoot.Channel.ManagingEditor != "") oXmlTextWriter.WriteElementString("managingEditor", rSSRoot.Channel.ManagingEditor); oXmlTextWriter.WriteElementString("language", rSSRoot.Channel.Language.ToString().Replace("_", "-")); if(rSSRoot.Image != null) { oXmlTextWriter.WriteStartElement("image"); oXmlTextWriter.WriteElementString("url", rSSRoot.Image.URL); oXmlTextWriter.WriteElementString("link", rSSRoot.Image.Link); oXmlTextWriter.WriteElementString("title", rSSRoot.Image.Title); if(rSSRoot.Image.Description != "") oXmlTextWriter.WriteElementString("description", rSSRoot.Image.Description); if(rSSRoot.Image.Width != 0) oXmlTextWriter.WriteElementString("width", rSSRoot.Image.Width.ToString()); if(rSSRoot.Image.Height != 0) oXmlTextWriter.WriteElementString("height", rSSRoot.Image.Height.ToString()); oXmlTextWriter.WriteEndElement(); } foreach(RSSItem itmCurrent in rSSRoot.Items) { oXmlTextWriter.WriteStartElement("item"); if(itmCurrent.Link != "") oXmlTextWriter.WriteElementString("link", itmCurrent.Link); if(itmCurrent.Title != "") oXmlTextWriter.WriteElementString("title", itmCurrent.Title); if(itmCurrent.Author != "") oXmlTextWriter.WriteElementString("author", itmCurrent.Author); if(itmCurrent.PubDate != "") { System.DateTime sDateTime = System.Convert.ToDateTime(itmCurrent.PubDate); oXmlTextWriter.WriteElementString("pubDate", sDateTime.ToString("ddd, dd MMM yyyy HH:mm:ss G\\MT")); } if(itmCurrent.Comment != "") oXmlTextWriter.WriteElementString("comment", itmCurrent.Comment); if(itmCurrent.Description != "") oXmlTextWriter.WriteElementString("description", itmCurrent.Description); oXmlTextWriter.WriteEndElement(); } oXmlTextWriter.WriteEndElement(); oXmlTextWriter.WriteEndElement(); oXmlTextWriter.WriteEndDocument(); oXmlTextWriter.Flush(); oXmlTextWriter.Close(); return(blnResult); }
private void GenerateControlSchemas(UPnPDevice d, System.IO.DirectoryInfo dirInfo, bool cleanSchema) { System.IO.MemoryStream ms = new MemoryStream(); System.Xml.XmlTextWriter X = new System.Xml.XmlTextWriter(ms,System.Text.Encoding.UTF8); X.Formatting = System.Xml.Formatting.Indented; foreach(UPnPDevice ed in d.EmbeddedDevices) { GenerateControlSchemas(ed,dirInfo,cleanSchema); } foreach(UPnPService s in d.Services) { Hashtable h = new Hashtable(); int j=1; foreach(string sn in s.GetSchemaNamespaces()) { h[sn] = "CT"+j.ToString(); ++j; } X.WriteStartDocument(); X.WriteStartElement("xsd","schema","http://www.w3.org/2001/XMLSchema"); X.WriteAttributeString("targetNamespace",s.ServiceURN); X.WriteAttributeString("xmlns",s.ServiceURN); X.WriteAttributeString("xmlns","upnp",null,"http://www.upnp.org/Schema/DataTypes"); IDictionaryEnumerator NE = h.GetEnumerator(); while(NE.MoveNext()) { X.WriteAttributeString("xmlns",NE.Value.ToString(),null,NE.Key.ToString()); } foreach(UPnPAction a in s.Actions) { X.WriteStartElement("xsd","element",null); X.WriteAttributeString("name",a.Name); X.WriteAttributeString("type",a.Name+"Type"); X.WriteEndElement(); X.WriteStartElement("xsd","element",null); X.WriteAttributeString("name",a.Name+"Response"); X.WriteAttributeString("type",a.Name+"ResponseType"); X.WriteEndElement(); if (!cleanSchema) { X.WriteComment("Note: Some schema validation tools may consider the following xsd:any element ambiguous in this placement"); X.WriteStartElement("xsd","any",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("minOccurs","0"); X.WriteAttributeString("maxOccurs","unbounded"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // ANY } X.WriteStartElement("xsd","complexType",null); X.WriteAttributeString("name",a.Name+"Type"); X.WriteStartElement("xsd","sequence",null); foreach(UPnPArgument arg in a.Arguments) { if (arg.Direction=="in") { X.WriteStartElement("xsd","element",null); X.WriteAttributeString("name",arg.Name); if (arg.RelatedStateVar.ComplexType==null) { // Simple Types X.WriteStartElement("xsd","complexType",null); X.WriteStartElement("xsd","simpleContent",null); X.WriteStartElement("xsd","extension",null); X.WriteAttributeString("base","upnp:"+arg.RelatedStateVar.ValueType); if (!cleanSchema) { X.WriteStartElement("xsd","anyAttribute",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // anyAttribute } X.WriteEndElement(); // Extension X.WriteEndElement(); // simpleConent X.WriteEndElement(); // complexType } else { // Complex Types X.WriteAttributeString("type",h[arg.RelatedStateVar.ComplexType.Name_NAMESPACE].ToString()+":"+arg.RelatedStateVar.ComplexType.Name_LOCAL); } X.WriteEndElement(); // element } } if (!cleanSchema) { X.WriteStartElement("xsd","any",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("minOccurs","0"); X.WriteAttributeString("maxOccurs","unbounded"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // any } X.WriteEndElement(); // sequence if (!cleanSchema) { X.WriteStartElement("xsd","anyAttribute",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // anyAttribute } X.WriteEndElement(); // complexType // ActionResponse X.WriteStartElement("xsd","complexType",null); X.WriteAttributeString("name",a.Name+"ResponseType"); X.WriteStartElement("xsd","sequence",null); foreach(UPnPArgument arg in a.Arguments) { if (arg.Direction=="out" || arg.IsReturnValue) { X.WriteStartElement("xsd","element",null); X.WriteAttributeString("name",arg.Name); if (arg.RelatedStateVar.ComplexType==null) { // Simple X.WriteStartElement("xsd","complexType",null); X.WriteStartElement("xsd","simpleContent",null); X.WriteStartElement("xsd","extension",null); X.WriteAttributeString("base","upnp:"+arg.RelatedStateVar.ValueType); if (!cleanSchema) { X.WriteStartElement("xsd","anyAttribute",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // anyAttribute } X.WriteEndElement(); // extension X.WriteEndElement(); // simpleContent X.WriteEndElement(); // complexType } else { // Complex X.WriteAttributeString("type",h[arg.RelatedStateVar.ComplexType.Name_NAMESPACE].ToString()+":"+arg.RelatedStateVar.ComplexType.Name_LOCAL); } X.WriteEndElement(); // Element } } // After all arguments if (!cleanSchema) { X.WriteStartElement("xsd","any",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("minOccurs","0"); X.WriteAttributeString("maxOccurs","unbounded"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // any } X.WriteEndElement(); // sequence if (!cleanSchema) { X.WriteStartElement("xsd","anyAttribute",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // anyAttribute } X.WriteEndElement(); // complexType } X.WriteEndElement(); //schema X.WriteEndDocument(); StreamWriter writer3; DText PP = new DText(); PP.ATTRMARK = ":"; PP[0] = s.ServiceURN; writer3 = File.CreateText(dirInfo.FullName + "\\"+PP[PP.DCOUNT()-1]+".xsd"); System.Text.UTF8Encoding U = new System.Text.UTF8Encoding(); X.Flush(); ms.Flush(); writer3.Write(U.GetString(ms.ToArray(),2,ms.ToArray().Length-2)); writer3.Close(); ms = new MemoryStream(); X = new System.Xml.XmlTextWriter(ms,System.Text.Encoding.UTF8); X.Formatting = System.Xml.Formatting.Indented; } }
private void SaveAnalysis(string analysisFileName) { if (this.currentStockSerie == null) return; string tmpFileName = analysisFileName + ".tmp"; bool success = true; // Save stock analysis to XML XmlSerializer serializer = new XmlSerializer(typeof(StockAnalysis)); System.Xml.XmlTextWriter xmlWriter; try { // Save analysis file using (FileStream fs = new FileStream(tmpFileName, FileMode.Create)) { xmlWriter = new System.Xml.XmlTextWriter(fs, null); xmlWriter.Formatting = System.Xml.Formatting.Indented; xmlWriter.WriteStartDocument(); StockDictionary.WriteAnalysisToXml(xmlWriter); xmlWriter.WriteEndDocument(); } } catch (System.Exception exception) { success = false; if (exception.InnerException != null) { MessageBox.Show(exception.InnerException.Message, "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(exception.Message, "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (success) { if (File.Exists(analysisFileName)) { File.Delete(analysisFileName); } File.Move(tmpFileName, analysisFileName); } }
public void WriteAccounts() { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter (xml_path, System.Text.Encoding.Default); writer.Formatting = System.Xml.Formatting.Indented; writer.Indentation = 2; writer.IndentChar = ' '; writer.WriteStartDocument (true); writer.WriteStartElement ("GalleryRemote"); foreach (GalleryAccount account in accounts) { writer.WriteStartElement ("Account"); writer.WriteElementString ("Name", account.Name); writer.WriteElementString ("Url", account.Url); writer.WriteElementString ("Username", account.Username); writer.WriteElementString ("Password", account.Password); writer.WriteElementString ("Version", account.Version.ToString()); writer.WriteEndElement (); //Account } writer.WriteEndElement (); writer.WriteEndDocument (); writer.Close (); }
private bool saveToFile() { string outPath = this.config.OutSavePath; if (outPath != null) { Logger.Trace("Saving work file to: " + outPath); System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(outPath, null); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("root"); extendedSimMatrix.WriteXml(xmlWriter); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); } else { Logger.Trace("File not saved as no file path has been provided."); } return true; }
/// <summary> Writes the mapping of all mapped classes of the specified assembly in the specified stream. </summary> /// <param name="stream">Where the xml is written.</param> /// <param name="assembly">Assembly used to extract user-defined types containing a valid attribute (can be [Class] or [xSubclass]).</param> public virtual void Serialize(System.IO.Stream stream, System.Reflection.Assembly assembly) { if(stream == null) throw new System.ArgumentNullException("stream"); if(assembly == null) throw new System.ArgumentNullException("assembly"); System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter( stream, System.Text.Encoding.UTF8 ); writer.Formatting = System.Xml.Formatting.Indented; writer.WriteStartDocument(); if(WriteDateComment) writer.WriteComment( string.Format( "Generated from NHibernate.Mapping.Attributes on {0}.", System.DateTime.Now.ToString("u") ) ); WriteHibernateMapping(writer, null); // Write imports (classes decorated with the [ImportAttribute]) foreach(System.Type type in assembly.GetTypes()) { object[] imports = type.GetCustomAttributes(typeof(ImportAttribute), false); foreach(ImportAttribute import in imports) { writer.WriteStartElement("import"); if(import.Class != null && import.Class != string.Empty) writer.WriteAttributeString("class", import.Class); else // Assume that it is the current type that must be imported writer.WriteAttributeString("class", HbmWriterHelper.GetNameWithAssembly(type)); if(import.Rename != null && import.Rename != string.Empty) writer.WriteAttributeString("rename", import.Rename); writer.WriteEndElement(); } } // Write classes and x-subclasses (classes must come first if inherited by "external" subclasses) int classCount = 0; System.Collections.ArrayList mappedClassesNames = new System.Collections.ArrayList(); foreach(System.Type type in assembly.GetTypes()) { if( ! IsClass(type) ) continue; HbmWriter.WriteClass(writer, type); mappedClassesNames.Add(HbmWriterHelper.GetNameWithAssembly(type)); classCount++; } System.Collections.ArrayList subclasses = new System.Collections.ArrayList(); System.Collections.Specialized.StringCollection extendedClassesNames = new System.Collections.Specialized.StringCollection(); foreach(System.Type type in assembly.GetTypes()) { if( ! IsSubclass(type) ) continue; bool map = true; System.Type t = type; while( (t=t.DeclaringType) != null ) if (IsClass(t) || AreSameSubclass(type, t)) // If a base class is also mapped... (Note: A x-subclass can only contain x-subclasses of the same family) { map = false; // This class's mapping is already included in the mapping of the base class break; } if(map) { subclasses.Add(type); if( IsSubclass(type, typeof(SubclassAttribute)) ) extendedClassesNames.Add((type.GetCustomAttributes(typeof(SubclassAttribute), false)[0] as SubclassAttribute).Extends); else if( IsSubclass(type, typeof(JoinedSubclassAttribute)) ) extendedClassesNames.Add((type.GetCustomAttributes(typeof(JoinedSubclassAttribute), false)[0] as JoinedSubclassAttribute).Extends); else if( IsSubclass(type, typeof(UnionSubclassAttribute)) ) extendedClassesNames.Add((type.GetCustomAttributes(typeof(UnionSubclassAttribute), false)[0] as UnionSubclassAttribute).Extends); } } classCount += subclasses.Count; MapSubclasses(subclasses, extendedClassesNames, mappedClassesNames, writer); writer.WriteEndElement(); // </hibernate-mapping> writer.WriteEndDocument(); writer.Flush(); if(classCount == 0) throw new MappingException("The following assembly contains no mapped classes: " + assembly.FullName); if( ! Validate ) return; // Validate the generated XML stream try { writer.BaseStream.Position = 0; System.Xml.XmlTextReader tr = new System.Xml.XmlTextReader(writer.BaseStream); System.Xml.XmlValidatingReader vr = new System.Xml.XmlValidatingReader(tr); // Open the Schema System.IO.Stream schema = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("NHibernate.Mapping.Attributes.nhibernate-mapping.xsd"); vr.Schemas.Add("urn:nhibernate-mapping-2.2", new System.Xml.XmlTextReader(schema)); vr.ValidationType = System.Xml.ValidationType.Schema; vr.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(XmlValidationHandler); _stop = false; while(vr.Read() && !_stop) // Read to validate (stop at the first error) ; } catch(System.Exception ex) { Error.Append(ex.ToString()).Append(System.Environment.NewLine + System.Environment.NewLine); } }
private void GenerateEventSchemas(UPnPDevice d, System.IO.DirectoryInfo dirInfo, bool cleanSchema) { System.IO.MemoryStream ms = new MemoryStream(); System.Xml.XmlTextWriter X = new System.Xml.XmlTextWriter(ms,System.Text.Encoding.UTF8); X.Formatting = System.Xml.Formatting.Indented; foreach(UPnPDevice ed in d.EmbeddedDevices) { GenerateEventSchemas(ed,dirInfo,cleanSchema); } foreach(UPnPService s in d.Services) { Hashtable h = new Hashtable(); int j=1; foreach(string sn in s.GetSchemaNamespaces()) { h[sn] = "CT"+j.ToString(); ++j; } X.WriteStartDocument(); X.WriteStartElement("xsd","schema","http://www.w3.org/2001/XMLSchema"); X.WriteAttributeString("targetNamespace","urn:schemas-upnp-org:event-1-0"); X.WriteAttributeString("xmlns","upnp",null,"http://www.upnp.org/Schema/DataTypes"); X.WriteAttributeString("xmlns","urn:schemas-upnp-org:event-1-0"); foreach(UPnPStateVariable v in s.GetStateVariables()) { if (v.SendEvent) { X.WriteStartElement("xsd","element",null); // Element1 X.WriteAttributeString("name","propertyset"); X.WriteAttributeString("type","propertysetType"); if (!cleanSchema) { X.WriteComment("Note: Some schema validation tools may consider the following xsd:any element to be ambiguous in its placement"); X.WriteStartElement("xsd","any",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("minOccurs","0"); X.WriteAttributeString("maxOccurs","unbounded"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); //ANY } X.WriteStartElement("xsd","complexType",null); X.WriteAttributeString("name","propertysetType"); X.WriteStartElement("xsd","sequence",null); X.WriteStartElement("xsd","element",null); // Element2 X.WriteAttributeString("name","property"); X.WriteAttributeString("maxOccurs","unbounded"); X.WriteStartElement("xsd","complexType",null); X.WriteStartElement("xsd","sequence",null); X.WriteStartElement("xsd","element",null); // Element3 X.WriteAttributeString("name",v.Name); if (v.ComplexType==null) { // Simple Type X.WriteStartElement("xsd","complexType",null); X.WriteStartElement("xsd","simpleContent",null); X.WriteStartElement("xsd","extension",null); X.WriteAttributeString("base","upnp:"+v.ValueType); if (!cleanSchema) { X.WriteStartElement("xsd","anyAttribute",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // anyAttribute } X.WriteEndElement(); // extension X.WriteEndElement(); // simpleContent X.WriteEndElement(); // complexType } else { // Complex Type X.WriteAttributeString("type",h[v.ComplexType.Name_NAMESPACE].ToString()+":"+v.ComplexType.Name_LOCAL); } X.WriteEndElement(); // Element3 if (!cleanSchema) { X.WriteStartElement("xsd","any",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("minOccurs","0"); X.WriteAttributeString("maxOccurs","unbounded"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // any } X.WriteEndElement(); // sequence if (!cleanSchema) { X.WriteStartElement("xsd","anyAttribute",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // anyAttribute } X.WriteEndElement(); // complexType X.WriteEndElement(); // Element2 if (!cleanSchema) { X.WriteStartElement("xsd","any",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("minOccurs","0"); X.WriteAttributeString("maxOccurs","unbounded"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // any } X.WriteEndElement(); // sequence if (!cleanSchema) { X.WriteStartElement("xsd","anyAttribute",null); X.WriteAttributeString("namespace","##other"); X.WriteAttributeString("processContents","lax"); X.WriteEndElement(); // anyAttribute } X.WriteEndElement(); // complexType; X.WriteEndElement(); // Element1 } } X.WriteEndElement(); // schema X.WriteEndDocument(); StreamWriter writer3; DText PP = new DText(); PP.ATTRMARK = ":"; PP[0] = s.ServiceURN; writer3 = File.CreateText(dirInfo.FullName + "\\"+PP[PP.DCOUNT()-1]+"_Events.xsd"); System.Text.UTF8Encoding U = new System.Text.UTF8Encoding(); X.Flush(); ms.Flush(); writer3.Write(U.GetString(ms.ToArray(),2,ms.ToArray().Length-2)); writer3.Close(); ms = new MemoryStream(); X = new System.Xml.XmlTextWriter(ms,System.Text.Encoding.UTF8); X.Formatting = System.Xml.Formatting.Indented; } }
public void Load (DCompilerConfiguration compiler) { configuration = compiler; if (compiler == null) { txtBinPath.Text = txtCompiler.Text = txtConsoleAppLinker.Text = txtSharedLibLinker.Text = txtStaticLibLinker.Text = null; text_DefaultLibraries.Buffer.Clear (); text_Includes.Buffer.Clear (); releaseArgumentsDialog.Load (null, false); debugArgumentsDialog.Load (null, true); btnMakeDefault.Sensitive = false; return; } //for now, using Executable target compiler command for all targets source compiling LinkTargetConfiguration targetConfig; targetConfig = compiler.GetOrCreateTargetConfiguration (DCompileTarget.Executable); txtBinPath.Text = compiler.BinPath; txtCompiler.Text = compiler.SourceCompilerCommand; check_enableLibPrefixing.Active = compiler.EnableGDCLibPrefixing; //linker targets targetConfig = compiler.GetOrCreateTargetConfiguration (DCompileTarget.Executable); txtConsoleAppLinker.Text = targetConfig.Linker; targetConfig = compiler.GetOrCreateTargetConfiguration (DCompileTarget.SharedLibrary); txtSharedLibLinker.Text = targetConfig.Linker; targetConfig = compiler.GetOrCreateTargetConfiguration (DCompileTarget.StaticLibrary); txtStaticLibLinker.Text = targetConfig.Linker; releaseArgumentsDialog.Load (compiler, false); debugArgumentsDialog.Load (compiler, true); text_DefaultLibraries.Buffer.Text = string.Join (Environment.NewLine, compiler.DefaultLibraries); text_Includes.Buffer.Text = string.Join (Environment.NewLine, compiler.IncludePaths); btnMakeDefault.Active = configuration.Vendor == defaultCompilerVendor; btnMakeDefault.Sensitive = true; using (var buf = new StringWriter ()) using (var xml = new System.Xml.XmlTextWriter (buf)) { xml.Formatting = System.Xml.Formatting.Indented; xml.WriteStartDocument(); xml.WriteStartElement("patterns"); compiler.ArgumentPatterns.SaveTo (xml); xml.WriteEndDocument(); tb_ArgPatterns.Buffer.Text = buf.ToString (); } }