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();
        }
예제 #2
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();
        }