internal void SaveFile(string newFilename = null) { if (newFilename == null) { newFilename = this.Filename; } if (string.IsNullOrWhiteSpace(newFilename)) { throw new InvalidOperationException("Invalid filename"); } TaxmlSaver saver = new TaxmlSaver(); LocalTermStore termStore = this.ctlListView.TermStore; if (termStore == null) { throw new InvalidOperationException("No term store is loaded"); } saver.SaveToFile(newFilename, termStore); this.Filename = newFilename; this.Modified = false; this.UpdateUI(); }
private void RewriteTaxmlAndAssertOutput(string inputResourceName, string outputResourceName, [CallerMemberName] string testGroupName = "") { string inputTaxmlString = this.GetTestResource(inputResourceName, testGroupName); LocalTermStore termStore = TaxmlLoader.LoadFromString(inputTaxmlString); string outputTaxmlString = TaxmlSaver.SaveToString(termStore); this.AssertXmlMatchesResource(outputTaxmlString, outputResourceName, testGroupName); }
protected override void BeginProcessing() { base.BeginProcessing(); ExportImportHelpers.WriteStartupBanner(this.AppLog); // Validate parameters string targetFilename = this.GetTargetFilename(); this.AppLog.WriteInfo("TAXML output will be written to " + targetFilename); this.AppLog.WriteLine(); ExportImportHelpers.ValidateSiteUrl(this.SiteUrl); // Fetch objects from SharePoint this.AppLog.WriteInfo("Connecting to SharePoint site: " + this.SiteUrl); Client15Connector clientConnector = ExportImportHelpers.CreateClientConnector( this.SiteUrl, this.Credential, this.CloudCredential, this.AppLog); clientConnector.DownloadedItem += this.clientConnector_DownloadedItem; List <LocalTermStore> fetchedTermStores = clientConnector.FetchTermStores(); Guid?optionalTermStoreId = null; if (this.MyInvocation.BoundParameters.ContainsKey(ExportTaxmlCommand.PropertyName_TermStoreId)) { optionalTermStoreId = this.TermStoreId; } LocalTermStore termStore = ExportImportHelpers.SelectTermStore(fetchedTermStores, optionalTermStoreId); this.AppLog.WriteInfo("Fetching items from TermStore \"" + termStore.Name + "\""); ClientConnectorDownloadOptions options = new ClientConnectorDownloadOptions(); if (this.GroupIdFilter != null && this.GroupIdFilter.Length > 0) { options.EnableGroupIdFilter(this.GroupIdFilter); } LocalTermStore outputTermStore = new LocalTermStore(termStore.Id, termStore.Name); clientConnector.Download(outputTermStore, options); this.AppLog.WriteInfo("Finished fetching items."); // Write output this.AppLog.WriteLine(); this.AppLog.WriteInfo("Writing TAXML output: " + targetFilename); TaxmlSaver saver = new TaxmlSaver(); saver.SaveToFile(targetFilename, outputTermStore); this.AppLog.WriteLine(); this.AppLog.WriteInfo("The operation completed successfully."); this.AppLog.WriteLine(); }
/// <summary> /// Retrieve the taxonomy objects that were created in SharePoint, /// and return them as a TAXML string. /// </summary> private static string DownloadTestDataAsTaxml(Client15Connector connector) { Debug.WriteLine("DownloadTestDataAsTaxml()"); ClientConnectorDownloadOptions options = new ClientConnectorDownloadOptions(); options.EnableGroupIdFilter(SampleData.TestGroupIds); LocalTermStore outputTermStore = new LocalTermStore(SampleData.TermStoreId, ""); connector.Download(outputTermStore, options); return(TaxmlSaver.SaveToString(outputTermStore)); }
public void CreateObjectsWithId() { var termStore = new LocalTermStore(new Guid("11111111-2222-3333-4444-000000000001"), "Service"); var termGroup = termStore.AddTermGroup(new Guid("11111111-2222-3333-4444-000000000002"), "Test Group"); var termSet = termGroup.AddTermSet(new Guid("11111111-2222-3333-4444-000000000003"), "Test TermSet"); var term = termSet.AddTerm(new Guid("11111111-2222-3333-4444-000000000004"), "Test Term"); var reusedTerm = termSet.AddTermLinkUsingId(new Guid("11111111-2222-3333-4444-000000000005"), "NameHint"); Assert.AreEqual(reusedTerm.TermLinkNameHint, "NameHint"); string taxml = TaxmlSaver.SaveToString(termStore); this.AssertXmlMatchesResource(taxml, "ExpectedOutput"); }
public void CreateObjectsWithoutId() { var termStore = new LocalTermStore(Guid.Empty, "Service"); var termGroup = termStore.AddTermGroup(Guid.Empty, "Test Group"); var termSet = termGroup.AddTermSet(Guid.Empty, "Test TermSet"); var term = termSet.AddTerm(Guid.Empty, "Test Term"); var reusedTerm = termSet.AddTermLinkUsingPath("My Group;My TermSet;MyTerm"); Assert.AreEqual(reusedTerm.TermLinkNameHint, "MyTerm"); string taxml = TaxmlSaver.SaveToString(termStore); this.AssertXmlMatchesResource(taxml, "ExpectedOutput"); }
protected override void BeginProcessing() { base.BeginProcessing(); ExportImportHelpers.WriteStartupBanner(this.AppLog); string inputFilename = ExportImportHelpers.GetAbsolutePath(this.CsvPath, this.SessionState); string outputFilename = ExportImportHelpers.GetAbsolutePath(this.TaxmlPath, this.SessionState); if (string.IsNullOrEmpty(System.IO.Path.GetExtension(outputFilename)) && !outputFilename.EndsWith(".")) { outputFilename += ".taxml"; } // Validate parameters if (!File.Exists(inputFilename)) { if (!File.Exists(inputFilename)) { throw new FileNotFoundException("The CSV input file does not exist: " + inputFilename); } } this.AppLog.WriteInfo("Reading CSV input from " + inputFilename); SharePointCsvLoader loader = new SharePointCsvLoader(); LocalTermStore termStore = loader.LoadFromFile(inputFilename); this.AppLog.WriteInfo("Writing output to " + outputFilename); TaxmlSaver taxmlSaver = new TaxmlSaver(); taxmlSaver.SaveToFile(outputFilename, termStore); this.AppLog.WriteLine(); this.AppLog.WriteInfo("The operation completed successfully."); this.AppLog.WriteLine(); }