public void CheckCorrectAddElement() { var xmlCreator = new XmlCreator(); xmlCreator.AddToRoot(new XElement("test", "value")); Assert.AreEqual(1, xmlCreator.Document.Elements("fet").Elements("test").Count()); }
static void Main(string[] args) { IKernel kernel = new StandardKernel(new ConfigModule()); IDataRetriever source = kernel.Get <IDataRetriever>(); XmlCreator.Create(source.LoadData(), Path.Combine(Directory.GetCurrentDirectory(), ConfigurationManager.AppSettings["targetFilePath"])); }
public void FetVersionTest() { var version = "1.0.0"; var xmlCreator = new XmlCreator(version); Assert.AreEqual(version, xmlCreator.Root.Attribute("version").Value); }
ActionResult ExportXmlReport(ReportInfo ri) { if (ri.XmlSchemaPathes == null) { throw new RequestModelException("The xml-schemes are not specified"); } foreach (var path in ri.XmlSchemaPathes) { if (!System.IO.File.Exists(path)) { throw new RequestModelException($"File not found '{path}'"); } } if (String.IsNullOrEmpty(ri.Encoding)) { throw new RequestModelException("The xml encoding is not specified"); } var xmlCreator = new XmlCreator(ri.XmlSchemaPathes, ri.DataModel, ri.Encoding) { Validate = ri.Validate }; var bytes = xmlCreator.CreateXml(); if (xmlCreator.HasErrors) { throw new Exception(xmlCreator.ErrorMessage); } return(File(bytes, "text/xml", $"{ri.Name}.xml")); }
static void Main(string[] args) { var boy = new Person { Id = "A123", Name = "a", PhoneNumber = 123, PlaceOfBirth = "Bangalore", DateAndTimeOfBirth = DateTime.Now, Gender = Gender.Male, SessionId = "bjf" }; var girl = new Person { Id = "B456", Name = "b", PhoneNumber = 456, PlaceOfBirth = "Bangalore", DateAndTimeOfBirth = DateTime.Now, Gender = Gender.Female, SessionId = "ckvj" }; var xmlRequestBody = XmlCreator.Create(boy, girl); var matchResponse = MatchMakerClient.GetMatch(xmlRequestBody); var compatibilityReportPath = XmlParser.ExtractCompatibilityReportPath(matchResponse); Console.WriteLine(compatibilityReportPath); }
static void Main() { var configPath = @"D:\Projects\cs\lab4\ServiceLayer\ServiceConfig.json"; var configProvider = new ConfigProvider(configPath); var serviceModel = configProvider.GetConfig <ServiceModel>(); var connectionString = serviceModel.ConnectionString; var targetPath = serviceModel.TargetXmlPath; var errorLogger = new Logger(); int id = 5; try { PersonalInfo personalInfo = new PersonalInfo();//////// personalInfo.Name = "testName"; personalInfo.PhoneNumber = "testPhone"; LoginInfo loginInfo = new LoginInfo(connectionString, id); AddressInfo addressInfo = new AddressInfo();/////// addressInfo.Address = "testAddress"; XmlModel obj = new XmlModel(personalInfo, loginInfo, addressInfo); XmlCreator creator = new XmlCreator(); creator.CreateXmlFile(obj, targetPath); } catch (Exception e) { errorLogger.AddError(e, DateTime.Now); } }
public void MultipleAlertXmlIsSerializedCorrectly() { var orangeAlertElement = XmlCreator.Create(CreateMultipleAlertXmlAlert()); var document = new XDocument(orangeAlertElement); string alertAsString; var writerSettings = new XmlWriterSettings { Indent = true, Encoding = Encoding.UTF8, NewLineChars = "\n" }; using (var memoryStream = new MemoryStream()) { var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8); using (var writer = XmlWriter.Create(streamWriter, writerSettings)) { document.Save(writer); } memoryStream.Seek(0, SeekOrigin.Begin); alertAsString = new StreamReader(memoryStream, Encoding.UTF8).ReadToEnd(); } var expectedResult = Xml.MultipleAlertXml.Replace("\r\n", "\n"); Assert.Equal(expectedResult, alertAsString); }
public SettingsViewModel() { SaveCommand = new DelegateCommand(OnSaveCommand); BrowseCommand = new DelegateCommand(OnBrowseCommand); userSettings = new UserSettingsModel(); xmlCreator = new XmlCreator(); filePath = Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["UserSettingsFilePath"]); int directoryIndex = filePath.LastIndexOf(@"\"); if (!File.Exists(filePath)) { Directory.CreateDirectory(filePath.Substring(0, directoryIndex)); xmlCreator.CreateDefaultUserSettingsXmlFile(filePath); } xmlReader = new XmlReader(); xmlReader.ObtainUserDetailsFromXmlFile(filePath, userSettings); DefaultSettings = new SettingsBindableModel { DefaultServerAddress = userSettings.DefaultServerAddress, DefaultServerPort = userSettings.DefaultServerPort, DefaultOutputDirectory = userSettings.DefaultOutputDirectory, DefaultFileName = userSettings.DefaultFileName, AutomaticallySaveToFile = userSettings.AutomaticallySaveToFile, AutomaticallyExpandQuickCommands = userSettings.AutomaticallyExpandQuickCommands, }; LastSaved = "Never."; }
public void XmlNodeReturnedHasSentTime() { var alertElement = XmlCreator.Create(Alert); var sentElement = alertElement.Element(XmlCreator.Cap12Namespace + "sent"); Assert.NotNull(sentElement); Assert.Equal("2014-06-10T10:35:23-03:00", sentElement.Value); }
public void XmlNodeReturnedHasStatus() { var alertElement = XmlCreator.Create(Alert); var statusElement = alertElement.Element(XmlCreator.Cap12Namespace + "status"); Assert.NotNull(statusElement); Assert.Equal("Test", statusElement.Value); }
public void XmlNodeReturnedHasSender() { var alertElement = XmlCreator.Create(Alert); var senderElement = alertElement.Element(XmlCreator.Cap12Namespace + "sender"); Assert.NotNull(senderElement); Assert.Equal(Sender, senderElement.Value); }
protected override void OnStart(string[] args) { logger = new Logger(); Thread loggerThread = new Thread(new ThreadStart(logger.Start)); loggerThread.Start(); var personService = new PersonService(logger.con); var personsInfo = personService.personRepository.GetAll(); XmlCreator persons = new XmlCreator(logger.target); persons.XmlGenerate(personsInfo); }
public ActionResult ImportTournament(HttpPostedFileBase fileUpload) { if (fileUpload == null) { return(View("Error")); } var xmlWorker = new XmlCreator(DataContext); xmlWorker.ImportTournaments(fileUpload); return(RedirectToAction("Index", "Home")); }
public void CheckCorrectAddElementArray() { var xmlCreator = new XmlCreator(); var list = new List <XElement> { new XElement("test", "value"), new XElement("test", "value2") }; xmlCreator.AddToRoot(list.ToArray()); Assert.AreEqual(2, xmlCreator.Document.Elements("fet").Elements("test").Count()); }
public ActionResult ExportTournament(int id) { var xmlCreator = new XmlCreator(DataContext); var data = xmlCreator.GetTournamentXml(id); var context = new DataContext(); var tournament = context.Tournaments.Include("Sport").Single(x => x.Id == id); var name = string.Format("{1} ({0}).xml", tournament.Sport.Name, tournament.Name); Response.AddHeader("Content-Disposition", "attachment; filename=" + name); return(File(data, "application/xml")); }
public IActionResult Create(string xml) { // Create document string documentPath = XmlCreator.Create(xml); // Read file using XmlReader XmlParser.ParseFile(documentPath); // Read file using XmlDocument XmlParser.ParseDocument(documentPath); return(Json("Document is now available on " + documentPath)); }
private XmlDocument CreateXmlDoc() { var doc = XmlCreator.CreateXml( Constants.Saml.AuthResponseId, elementId, "id486364ad7bf040b0a3b6f35cc39c1ceb", "localhost:44388", "*****@*****.**", "https://localhost:44300", "https://localhost:44300/identity/AuthServices/Acs"); return(doc); }
private void AllElementsFilledXmlParseAndCreate() { string xmlContent = Xml.AllElementsFilledAlert; XDocument originalDocument = XDocument.Parse(xmlContent); Alert alert = XmlParser.Parse(xmlContent).First(); XElement createdElement = XmlCreator.Create(alert); XDocument createdDocument = new XDocument(); createdDocument.Add(createdElement); Assert.Equal(createdDocument.ToString(), originalDocument.ToString()); }
private void ThunderStorm12AllDatesXmlParseAndCreate() { string xmlContent = Xml.Thunderstorm12AllDatesXml; XDocument originalDocument = XDocument.Parse(xmlContent); Alert alert = XmlParser.Parse(xmlContent).First(); XElement createdElement = XmlCreator.Create(alert); XDocument createdDocument = new XDocument(); createdDocument.Add(createdElement); Assert.Equal(createdDocument.ToString(), originalDocument.ToString()); }
private void MultipleCircleXmlParseAndCreate() { string xmlContent = Xml.MultipleCircleXml; XDocument originalDocument = XDocument.Parse(xmlContent); Alert alert = XmlParser.Parse(xmlContent).First(); XElement createdElement = XmlCreator.Create(alert); XDocument createdDocument = new XDocument(); createdDocument.Add(createdElement); Assert.Equal(createdDocument.ToString(), originalDocument.ToString()); }
public void OrangeAlertXmlParseAndCreate() { string xmlContent = Xml.OrangeAlertXml; XDocument originalDocument = XDocument.Parse(xmlContent); Alert alert = XmlParser.Parse(xmlContent).First(); XElement createdElement = XmlCreator.Create(alert); XDocument createdDocument = new XDocument(); createdDocument.Add(createdElement); Assert.Equal(createdDocument.ToString(), originalDocument.ToString()); }
private void SevereThunderStormCap11ParseAndCreate() { string xmlContent = Xml.SevereThundertromCap11; string xmlContentToCap12 = xmlContent.Replace(XmlCreator.Cap11Namespace.ToString(), XmlCreator.Cap12Namespace.ToString()); XDocument originalDocument = XDocument.Parse(xmlContentToCap12); Alert alert = XmlParser.Parse(xmlContent).First(); XElement createdElement = XmlCreator.Create(alert); XDocument createdDocument = new XDocument(); createdDocument.Add(createdElement); Assert.Equal(createdDocument.ToString(), originalDocument.ToString()); }
private void MultipleParameterXmlParseAndCreate() { string xmlContent = Xml.MultipleParameterTestXml; string correctedXmlContent = xmlContent.Replace("Very Likely", "Likely"); XDocument originalDocument = XDocument.Parse(correctedXmlContent); Alert alert = XmlParser.Parse(xmlContent).First(); XElement createdElement = XmlCreator.Create(alert); XDocument createdDocument = new XDocument(); createdDocument.Add(createdElement); Assert.Equal(createdDocument.ToString(), originalDocument.ToString()); }
public void MultipleInfoAndAlertParseAndCreate() { string xmlContent = Xml.MultipleAlertAndInfoThunderstorm; string xmlContentToCap12 = xmlContent.Replace(XmlCreator.Cap11Namespace.ToString(), XmlCreator.Cap12Namespace.ToString()); XDocument originalDocument = XDocument.Parse(xmlContentToCap12); IEnumerable <Alert> alerts = XmlParser.Parse(xmlContent); IEnumerable <XElement> createdElements = XmlCreator.Create(alerts); XDocument createdDocument = new XDocument(); createdDocument.Add(new XElement(originalDocument.Root.Name, createdElements)); Assert.Equal(createdDocument.ToString(), originalDocument.ToString()); }
protected override void OnStart(string[] args) { var config = new LibraryForFiles(); List <Option> options = config.GetOptions(); try { var personService = new PersonService(@"Data Source=ASUS;Initial Catalog=AdventureWorks2019;Integrated Security=True"); var personsInfo = personService.personRepository.GetAll(); XmlCreator persons = new XmlCreator(options[0].Target); persons.XmlGenerate(personsInfo); } catch (Exception excep) { throw excep; } }
/// <summary> /// Generates a .FET file for use in the algorithm. /// </summary> /// <param name="outputDir">Output directory for the FET file.</param> /// <returns>Filename of the generated .FET file.</returns> public string GenerateFetFile(string outputDir) { // Init XML creator var xmlCreator = new XmlCreator(FetVersion); // Create FET file xmlCreator.AddToRoot(DaysList.Create()); xmlCreator.AddToRoot(HoursList.Create()); xmlCreator.AddToRoot(TeachersList.Create()); xmlCreator.AddToRoot(SubjectsList.Create()); xmlCreator.AddToRoot(YearsList.Create()); xmlCreator.AddToRoot(ActivitiesList.Create()); xmlCreator.AddToRoot(TimeConstraintsList.Create()); xmlCreator.AddToRoot(SpaceConstraintsList.Create()); xmlCreator.AddToRoot(RoomsList.Create()); return(xmlCreator.Save(outputDir)); }
private static void Main(string[] args) { Console.WriteLine("Select output version:\n\n" + "Simple/s - Simple XML version\n" + "Extended/e - Extended XML version"); var version = Version.Unknown; var isVersionProvided = false; while (!isVersionProvided) { var selectedVersion = Console.ReadLine(); if (Enum.TryParse(selectedVersion, true, out version)) { isVersionProvided = true; } else { Console.WriteLine("Please select valid option..."); } } if (version != Version.Unknown) { IXmlStrategy strategy = null; switch (version) { case Version.S: case Version.Simple: strategy = new SimpleXmlStrategy(); break; case Version.E: case Version.Extended: strategy = new ExtendedXmlStrategy(); break; } var x = new XmlCreator(strategy, @"C:\xmlOutput"); x.GenerateFile(); } }
/// <summary> /// Инициализирует новый экземпляр <see cref="SmsProNikitaClient"/> класса. /// </summary> /// <param name="login">Логин выдаваемый при создании аккаунта</param> /// <param name="password">Пароль</param> /// <param name="sender">Имя отправителя, отображаемое в телефоне получателя. Может состоять либо из 11 латинских букв, цифр и знаков точка и тире, либо из 14 цифр.</param> /// <param name="webProxy">webProxy</param> /// <exception cref="ArgumentException"> /// Логин не может быть пустым - login /// или /// Пароль не может быть пустым - password /// или /// Имя отправителя не может быть пустым - sender /// </exception> public SmsProNikitaClient(string login, string password, string sender, IWebProxy webProxy = null) { if (string.IsNullOrWhiteSpace(login)) { throw new ArgumentException("Логин не может быть пустым", "login"); } if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentException("Пароль не может быть пустым", "password"); } if (string.IsNullOrWhiteSpace(sender)) { throw new ArgumentException("Имя отправителя не может быть пустым", "sender"); } _config = new SmsProNikitaConfig(login, password, sender); _xmlCreator = new XmlCreator(_config); _httpService = webProxy != null ? new HttpService(webProxy) : new HttpService(); }
/// <summary> /// The write to. /// </summary> /// <param name="target"> /// The target. /// </param> public void WriteTo(XmlWriter target) { target.WriteStartElement(nodeName.LocalName, nodeName.NamespaceName); try { HL7Writer.WriteHL7(target, XmlCreator.CreateMsh(parameters)); HL7Writer.WriteHL7(target, XmlCreator.CreateMsa(parameters, batchFatalReference)); if (errors != null) { foreach (var obj2 in errors) { HL7Writer.WriteHL7(target, obj2); } } } finally { target.WriteEndElement(); } }
async Task ExecuteXmlCommand(RequestCommand cmd, ExpandoObject dataToExec, HttpResponseBase response) { List <String> xmlSchemaPathes = null; if (cmd.xmlSchemas != null) { xmlSchemaPathes = new List <String>(); foreach (var schema in cmd.xmlSchemas) { xmlSchemaPathes.Add(Host.MakeFullPath(false, cmd.Path, schema + ".xsd")); } } if (xmlSchemaPathes == null) { throw new RequestModelException("The xml-schemes are not specified"); } foreach (var path in xmlSchemaPathes) { if (!System.IO.File.Exists(path)) { throw new RequestModelException($"File not found '{path}'"); } } IDataModel dm = await DbContext.LoadModelAsync(cmd.CurrentSource, cmd.XmlProcedure, dataToExec); var xmlCreator = new XmlCreator(xmlSchemaPathes, dm, "UTF-8") { Validate = cmd.validate }; var bytes = xmlCreator.CreateXml(); response.ContentType = "text/xml"; var chars = Encoding.UTF8.GetString(bytes).ToCharArray(); response.Write(chars, 0, chars.Length); }