private async void ValidateXMLButton_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker
            {
                ViewMode = Windows.Storage.Pickers.PickerViewMode.List,
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.ComputerFolder
            };

            picker.FileTypeFilter.Add(".xml");
            Windows.Storage.StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFile tempXml = await localFolder.CreateFileAsync("temp.xml", CreationCollisionOption.ReplaceExisting);

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                var path = file.Path;
                await file.CopyAndReplaceAsync(tempXml);

                try
                {
                    FactoryOrchestratorXML.Load(tempXml.Path);

                    ContentDialog successLoadDialog = new ContentDialog
                    {
                        Title           = resourceLoader.GetString("XmlValidatedTitle"),
                        Content         = string.Format(CultureInfo.CurrentCulture, resourceLoader.GetString("XmlValidatedContent"), path),
                        CloseButtonText = resourceLoader.GetString("Ok")
                    };

                    _ = await successLoadDialog.ShowAsync();
                }
                catch (Exception ex)
                {
                    var           msg = ex.AllExceptionsToString().Replace(tempXml.Path, path, StringComparison.OrdinalIgnoreCase);
                    ContentDialog failedLoadDialog = new ContentDialog
                    {
                        Title           = resourceLoader.GetString("XmlFailedTitle"),
                        Content         = msg,
                        CloseButtonText = resourceLoader.GetString("Ok")
                    };

                    _ = await failedLoadDialog.ShowAsync();
                }
            }
        }
Пример #2
0
 public void TestDuplicateGuidInXml()
 {
     string[] expectedGuids = { "ba3fa48b-b555-490d-9082-3d93dca22e70", "7bac1a15-0e62-4d49-8a54-27077409d229", "ba3fa48b-b555-490d-9082-3d93dca22e72" };
     try
     {
         var path = Path.Combine(Directory.GetCurrentDirectory(), "DuplicateGuids.xml");
         FactoryOrchestratorXML.Load(path);
         Assert.Fail("XML should not have loaded successfully!");
     }
     catch (FactoryOrchestratorXmlException e)
     {
         Assert.AreEqual(e.InnerException.GetType(), typeof(XmlSchemaValidationException));
         foreach (var guid in expectedGuids)
         {
             Assert.IsTrue(e.InnerException.Message.Contains(guid, StringComparison.OrdinalIgnoreCase), $"guid {guid} should be in error string!");
         }
     }
 }