public static LocalTermStore SelectTermStore(List <LocalTermStore> termStores, Guid?termStoreId) { LocalTermStore termStore = null; if (termStores.Count == 0) { throw new KeyNotFoundException("The server does not have any term stores" + " -- is the Managed Metadata Service running?"); } if (termStoreId != null) { termStore = termStores.FirstOrDefault(x => x.Id == termStoreId); if (termStore == null) { throw new KeyNotFoundException("The server does not have a term store with ID \"" + termStoreId.Value + "\""); } } else { if (termStores.Count > 1) { throw new InvalidOperationException("Multiple term stores exist on the server." + " Use the \"-TermStoreId\" option to specify a term store."); } termStore = termStores[0]; } return(termStore); }
internal void LoadTermStore(LocalTermStore termStore) { this.ctlListView.TermStore = termStore; this.Filename = "Untitled"; this.Modified = false; this.UpdateUI(); }
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 btnUpload_Click(object sender, EventArgs e) { MainForm mainForm = this.MainForm; if (mainForm == null) { throw new InvalidOperationException("No main form"); } DocumentView documentView = mainForm.SelectedDocumentView; if (documentView == null || documentView.TermStore == null) { throw new InvalidOperationException("No document is selected"); } LocalTermStore selectedTermStore = this.txtTermStore.SelectedItem as LocalTermStore; if (selectedTermStore == null) { throw new InvalidOperationException("No selection"); } this.connector.Upload(documentView.TermStore, selectedTermStore.Id); }
public DownloadTaxonomyForm(LocalTermStore termStore) { this.termStore = termStore; this.InitializeComponent(); this.txtTermStoreName.Text = termStore.Name; }
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(); }
public void LoadFile(string filenameToLoad) { TaxmlLoader loader = new TaxmlLoader(); LocalTermStore termStore = loader.LoadFromFile(filenameToLoad); this.ctlListView.TermStore = termStore; this.Filename = filenameToLoad; this.Modified = false; this.UpdateUI(); }
public UploadController(Client15Connector clientConnector, LocalTermStore localTermStore, TermStore clientTermStore, ClientConnectorUploadOptions options) { this.clientConnector = clientConnector; this.localTermStore = localTermStore; this.clientTermStore = clientTermStore; this.options = options; this.queuedUploaders = new PriorityQueue <TaxonomyItemUploader>(new TaxonomyItemUploaderComparer()); }
/// <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 DefaultLanguageInheritance() { var guids = new Guid[] { new Guid("ff000000-0000-0000-0000-000000000000"), new Guid("ff000000-0000-0000-0000-000000000001"), new Guid("ff000000-0000-0000-0000-000000000002"), new Guid("ff000000-0000-0000-0000-000000000003"), new Guid("ff000000-0000-0000-0000-000000000004") }; var termStore = new LocalTermStore(guids[0], "MMS", 1030); var termGroup = termStore.AddTermGroup(guids[1], "Group"); var termSet = termGroup.AddTermSet(guids[2], "TermSet"); var term0 = termSet.AddTerm(guids[3], "term0"); var term1 = term0.AddTerm(guids[4], "term1"); Assert.AreEqual(termStore.DefaultLanguageLcid, 1030); Assert.AreEqual(termGroup.DefaultLanguageLcid, 1030); Assert.AreEqual(termSet.DefaultLanguageLcid, 1030); Assert.AreEqual(term0.DefaultLanguageLcid, 1030); Assert.AreEqual(term1.DefaultLanguageLcid, 1030); try { // cannot change termSet's default language because the // value is being inherited from the parent termSet.DefaultLanguageLcid = 1029; Assert.Fail("Exception not thrown"); } catch (Exception ex) { Assert.AreEqual(ex.GetType(), typeof(InvalidOperationException)); } termStore.DefaultLanguageLcid = 1031; Assert.AreEqual(termStore.DefaultLanguageLcid, 1031); Assert.AreEqual(termGroup.DefaultLanguageLcid, 1031); Assert.AreEqual(termSet.DefaultLanguageLcid, 1031); Assert.AreEqual(term0.DefaultLanguageLcid, 1031); Assert.AreEqual(term1.DefaultLanguageLcid, 1031); termSet.ParentItem = null; termSet.DefaultLanguageLcid = 1032; Assert.AreEqual(termStore.DefaultLanguageLcid, 1031); Assert.AreEqual(termGroup.DefaultLanguageLcid, 1031); Assert.AreEqual(termSet.DefaultLanguageLcid, 1032); Assert.AreEqual(term0.DefaultLanguageLcid, 1032); Assert.AreEqual(term1.DefaultLanguageLcid, 1032); }
private void lblTermStoreManager_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string url = Utilities.CombineUrl(this.txtServerUrl.Text, "/_layouts/TermStoreManager.aspx"); LocalTermStore selectedTermStore = this.txtTermStore.SelectedItem as LocalTermStore; if (selectedTermStore != null) { url += "?tsid=" + selectedTermStore.Id.ToString().Replace("-", ""); } Process.Start(url); }
public void Upload(LocalTermStore termStore, Guid overrideTermStoreId, ClientConnectorUploadOptions options = null) { if (options == null) { options = new ClientConnectorUploadOptions(); } TermStore clientTermStore = this.FetchClientTermStore(overrideTermStoreId); var uploadController = new UploadController(this, termStore, clientTermStore, options); uploadController.PerformUpload(); }
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"); }
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 Download(LocalTermStore termStore, ClientConnectorDownloadOptions options = null) { if (options == null) { options = new ClientConnectorDownloadOptions(); } TermStore clientTermStore = this.FetchClientTermStore(termStore.Id); // Load full data for the TermStore object var downloaderContext = new TaxonomyItemDownloaderContext(this, options); TermStoreDownloader termStoreDownloader = new TermStoreDownloader(downloaderContext, clientTermStore); termStoreDownloader.SetLocalObject(termStore); termStoreDownloader.FetchItem(); }
private void btnDownload_Click(object sender, EventArgs e) { LocalTermStore selectedTermStore = this.txtTermStore.SelectedItem as LocalTermStore; if (selectedTermStore == null) { throw new InvalidOperationException("No selection"); } MainForm mainForm = this.MainForm; if (mainForm == null) { throw new InvalidOperationException("No main form"); } DocumentView documentView = null; using (DownloadTaxonomyForm downloadForm = new DownloadTaxonomyForm(selectedTermStore)) { downloadForm.ShowDialog(this); using (DownloadProgressForm progressForm = new DownloadProgressForm()) { progressForm.ShowDialog(delegate() { // @@ Improve this progressForm.ProgressBar.Style = ProgressBarStyle.Marquee; ClientConnectorDownloadOptions options = downloadForm.GetTaxonomyReadOptions(); LocalTermStore termStoreCopy = new LocalTermStore(selectedTermStore.Id, selectedTermStore.Name); this.connector.Download(termStoreCopy, options); documentView = new DocumentView(); documentView.LoadTermStore(termStoreCopy); } ); } } if (documentView != null) { mainForm.AddTab(documentView); } }
public void UploadBatchingTest() { Debug.WriteLine("START UploadBatchingTest()"); // Clean up any previous data SampleData.DeleteTestGroups(); string initialInputTaxml = this.GetTestResource("Input"); LocalTermStore initialTermStore = TaxmlLoader.LoadFromString(initialInputTaxml); this.connector.Upload(initialTermStore, SampleData.TermStoreId); string initialOutputTaxml = FunctionalTests.DownloadTestDataAsTaxml(this.connector); this.AssertXmlMatchesResource(initialOutputTaxml, "Output"); Debug.WriteLine("END UploadBatchingTest()"); }
public void SiblingTermNameConflictsWhenRenaming() { var guids = new Guid[] { new Guid("ff000000-0000-0000-0000-000000000000"), new Guid("ff000000-0000-0000-0000-000000000001"), new Guid("ff000000-0000-0000-0000-000000000002"), new Guid("ff000000-0000-0000-0000-000000000003"), new Guid("ff000000-0000-0000-0000-000000000004") }; var termStore = new LocalTermStore(guids[0], "MMS", 1030); termStore.SetAvailableLanguageLcids(new[] { 1030, 1031, 1033 }); var termGroup = termStore.AddTermGroup(guids[1], "Group"); var termSet = termGroup.AddTermSet(guids[2], "TermSet"); // Synonyms (i.e. non-default labels) cannot conflict with each other var term1 = LocalTerm.CreateTerm(guids[3], "Apple", 1030); termSet.AddTerm(term1); var term2 = LocalTerm.CreateTerm(guids[4], "Banana", 1030); termSet.AddTerm(term2); try { term2.Name = "Apple"; Assert.Fail("Exception not thrown"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "The term name \"Apple\" is already in use by a sibling term (LCID=1030)"); Assert.AreEqual(term2.Name, "Banana"); // term2 should not have been changed } }
public void UploadWithTermLinkSourcePath_NotFoundError() { Debug.WriteLine("START UploadWithTermLinkSourcePath_NotFoundError()"); // Clean up any previous data SampleData.DeleteTestGroups(); SampleData.CreateMinimal(); try { string initialInputTaxml = this.GetTestResource("Input"); LocalTermStore initialTermStore = TaxmlLoader.LoadFromString(initialInputTaxml); this.connector.Upload(initialTermStore, SampleData.TermStoreId); Assert.Fail("The expected exception was not thrown"); } catch (InvalidOperationException ex) { Assert.IsTrue(ex.Message.StartsWith("Unable to find term specified by the TermLinkSourcePath:")); } Debug.WriteLine("END UploadWithTermLinkSourcePath_NotFoundError()"); }
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(); }
private void DoCreateUpdateModify(string testGroupName) { // Clean up any previous data SampleData.DeleteTestGroups(); var options = new ClientConnectorUploadOptions(); // options.MaximumBatchSize = 1; //--------------------------------------------------------------- // Initial creation of the objects Debug.WriteLine("Part 1: Upload that initially creates objects"); string initialInputTaxml = this.GetTestResource("InitialInput", testGroupName); LocalTermStore initialTermStore = TaxmlLoader.LoadFromString(initialInputTaxml); initialTermStore.SyncAction = new SyncAction() { IfMissing = SyncActionIfMissing.Create, IfPresent = SyncActionIfPresent.Error, IfElsewhere = SyncActionIfElsewhere.Error }; this.connector.Upload(initialTermStore, SampleData.TermStoreId, options); string initialOutputTaxml = FunctionalTests.DownloadTestDataAsTaxml(this.connector); this.AssertXmlMatchesResource(initialOutputTaxml, "InitialOutput", testGroupName); //--------------------------------------------------------------- // Perform a second upload of the exact same content, to verify that // no changes were committed to the term store Debug.WriteLine("Part 2: Duplicate upload that doesn't change anything"); initialTermStore.SyncAction = new SyncAction() { IfMissing = SyncActionIfMissing.Error, IfPresent = SyncActionIfPresent.Update, IfElsewhere = SyncActionIfElsewhere.Error }; DateTime changeTimeBefore = this.GetChangeTimeForTermStore(); this.connector.Upload(initialTermStore, SampleData.TermStoreId, options); DateTime changeTimeAfter = this.GetChangeTimeForTermStore(); Assert.AreEqual(changeTimeAfter, changeTimeBefore); //--------------------------------------------------------------- // Upload a modified input that changes every property Debug.WriteLine("Part 3: Upload that makes modifications"); string modifiedInputTaxml = this.GetTestResource("ModifiedInput", testGroupName); LocalTermStore modifiedTermStore = TaxmlLoader.LoadFromString(modifiedInputTaxml); modifiedTermStore.SyncAction = new SyncAction() { IfMissing = SyncActionIfMissing.Error, IfPresent = SyncActionIfPresent.Update, IfElsewhere = SyncActionIfElsewhere.Error }; this.connector.Upload(modifiedTermStore, SampleData.TermStoreId, options); string modifiedOutputTaxml = FunctionalTests.DownloadTestDataAsTaxml(this.connector); this.AssertXmlMatchesResource(modifiedOutputTaxml, "ModifiedOutput", testGroupName); }
protected override void BeginProcessing() { base.BeginProcessing(); ExportImportHelpers.WriteStartupBanner(this.AppLog); string inputFilename = ExportImportHelpers.GetAbsolutePath(this.Path, this.SessionState); // Validate parameters if (!File.Exists(inputFilename)) { // If the "taxml" extension was omitted, try adding it if (string.IsNullOrEmpty(System.IO.Path.GetExtension(inputFilename)) && !inputFilename.EndsWith(".")) { inputFilename += ".taxml"; } if (!File.Exists(inputFilename)) { throw new FileNotFoundException("The TAXML input file does not exist: " + inputFilename); } } ExportImportHelpers.ValidateSiteUrl(this.SiteUrl); this.AppLog.WriteInfo("Reading TAXML input from " + inputFilename); TaxmlLoader loader = new TaxmlLoader(); LocalTermStore loadedTermStore = loader.LoadFromFile(inputFilename); this.AppLog.WriteInfo("Connecting to SharePoint site: " + this.SiteUrl); Client15Connector clientConnector = ExportImportHelpers.CreateClientConnector( this.SiteUrl, this.Credential, this.CloudCredential, this.AppLog); clientConnector.UploadingItem += this.clientConnector_UploadingItem; List <LocalTermStore> fetchedTermStores = clientConnector.FetchTermStores(); Guid?optionalTermStoreId = null; if (this.MyInvocation.BoundParameters.ContainsKey(ImportTaxmlCommand.PropertyName_TermStoreId)) { optionalTermStoreId = this.TermStoreId; } LocalTermStore fetchedTermStore = ExportImportHelpers.SelectTermStore(fetchedTermStores, optionalTermStoreId); this.AppLog.WriteLine(); this.AppLog.WriteInfo("Starting operation..."); this.AppLog.WriteLine(); var options = new ClientConnectorUploadOptions(); if (this.MyInvocation.BoundParameters.ContainsKey(ImportTaxmlCommand.PropertyName_MaximumBatchSize)) { options.MaximumBatchSize = this.MaximumBatchSize; } clientConnector.Upload(loadedTermStore, fetchedTermStore.Id, options); var progressRecord = new ProgressRecord(0, ImportTaxmlCommand.ProgressRecordTitle, "Finished."); progressRecord.RecordType = ProgressRecordType.Completed; this.WriteProgress(progressRecord); this.AppLog.WriteLine(); this.AppLog.WriteInfo("The operation completed successfully."); this.AppLog.WriteLine(); }
public void SiblingTermNameConflictsWhenAdding() { var guids = new Guid[] { new Guid("ff000000-0000-0000-0000-000000000000"), new Guid("ff000000-0000-0000-0000-000000000001"), new Guid("ff000000-0000-0000-0000-000000000002"), new Guid("ff000000-0000-0000-0000-000000000003"), new Guid("ff000000-0000-0000-0000-000000000004"), new Guid("ff000000-0000-0000-0000-000000000005"), new Guid("ff000000-0000-0000-0000-000000000006"), new Guid("ff000000-0000-0000-0000-000000000007"), new Guid("ff000000-0000-0000-0000-000000000008") }; var termStore = new LocalTermStore(guids[0], "MMS", 1030); termStore.SetAvailableLanguageLcids(new[] { 1030, 1031, 1033 }); var termGroup = termStore.AddTermGroup(guids[1], "Group"); var termSet = termGroup.AddTermSet(guids[2], "TermSet"); // Synonyms (i.e. non-default labels) cannot conflict with each other var term1 = LocalTerm.CreateTerm(guids[3], "Apple", 1030); term1.AddLabel("No Conflict", 1030, setAsDefaultLabel: false); termSet.AddTerm(term1); var term2 = LocalTerm.CreateTerm(guids[4], "Banana", 1030); term2.AddLabel("No Conflict", 1030, setAsDefaultLabel: false); termSet.AddTerm(term2); // Default labels do not conflict unless the language is the same var term3 = LocalTerm.CreateTerm(guids[5], "Coconut", 1030); term3.SetName("Durian", 1033); termSet.AddTerm(term3); var term4 = LocalTerm.CreateTerm(guids[6], "Durian", 1030); term4.SetName("Coconut", 1033); termSet.AddTerm(term4); // Default labels do conflict if the language is the same // failedTerm5 should conflict with term3 var failedTerm5 = LocalTerm.CreateTerm(guids[7], "Elderberry", 1030); failedTerm5.SetName("Durian", 1033); try { termSet.AddTerm(failedTerm5); Assert.Fail("Exception not thrown"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "The term name \"Durian\" is already in use by a sibling term (LCID=1033)"); Assert.AreEqual(termSet.Terms.Count, 4); // failedTerm5 should not have been added } // If a default label is missing for one of the LCIDs, we fallback to the default language, // which can cause a conflict var term5 = LocalTerm.CreateTerm(guids[7], "Feijoa", 1030); term5.SetName("Guava", 1031); termSet.AddTerm(term5); // failedTerm6 should conflict with term5 because for LCID=1031, it will fallback to use // the default language which is "Guava" var failedTerm6 = LocalTerm.CreateTerm(guids[8], "Guava", 1030); try { termSet.AddTerm(failedTerm6); Assert.Fail("Exception not thrown"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "The term name \"Guava\" is already in use by a sibling term (LCID=1031)"); Assert.IsNull(failedTerm6.ParentItem); // failedTerm6 should not have been added } }