Пример #1
0
        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();
        }
Пример #2
0
        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);
        }