Пример #1
0
        public static Client15Connector CreateClientConnector(string siteUrl,
                                                              PSCredential credential, SwitchParameter cloudCredential, AppLog appLog)
        {
            Client15Connector clientConnector = new Client15Connector(siteUrl);

            if (credential != null)
            {
                if (cloudCredential.IsPresent)
                {
                    clientConnector.SetCredentialsForCloud(credential.UserName, credential.Password,
                                                           (message) => { appLog.WriteVerbose(message); }
                                                           );
                }
                else
                {
                    clientConnector.SetCredentialsForOnPrem(credential.UserName, credential.Password);
                }
            }
            else
            {
                if (cloudCredential.IsPresent)
                {
                    throw new InvalidOperationException(
                              "The -CloudCredential switch cannot be used without specifying a credential object");
                }
            }
            return(clientConnector);
        }
        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();
        }
Пример #3
0
 private void Disconnect()
 {
     if (this.connector == null)
     {
         return;
     }
     //this.connector.Dispose();
     this.connector = null;
     // (don't call UpdateUI() here because we may be disposing)
 }
Пример #4
0
        /// <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));
        }
Пример #5
0
        private void btnConnectDisconnect_Click(object sender, EventArgs e)
        {
            if (this.IsConnected)
            {
                this.Disconnect();
                this.UpdateUI();
                return;
            }

            if (!this.chkSkipLoginPrompt.Checked)
            {
                using (LoginForm form = new LoginForm(this.loginInfo))
                {
                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        return; // don't connect
                    }
                }
            }

            try
            {
                this.connector = new Client15Connector(this.txtServerUrl.Text);
                this.loginInfo.SetCredentials(this.connector);

                List <LocalTermStore> termStores = this.connector.FetchTermStores();

                this.txtTermStore.Items.Clear();
                this.txtTermStore.Items.AddRange(termStores.Cast <object>().ToArray());
                this.txtTermStore.SelectedIndex = 0;

                // Only save the credentials if the connection succeeded
                this.SaveSettings();
                this.loginInfo.SaveToSettings();
            }
            catch
            {
                try
                {
                    this.Disconnect();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Discarding exception: " + ex.Message);
                }
                throw;
            }
            finally
            {
                this.UpdateUI();
            }
        }
Пример #6
0
        public void SetCredentials(Client15Connector connector)
        {
            switch (this.AuthenticationMode)
            {
            case AuthenticationMode.WindowsCredentials:
                return;

            case AuthenticationMode.FormsAuthentication:
                connector.SetCredentialsForOnPrem(this.UserName, LoginInfo.MakeSecureString(this.Password));
                return;

            case AuthenticationMode.CloudAuthentication:
                connector.SetCredentialsForCloud(this.UserName, LoginInfo.MakeSecureString(this.Password));
                return;

            default:
                throw new NotImplementedException("Cloud login not implemented");
            }
        }
Пример #7
0
 public ClientTestConnectorHook(Client15Connector connector)
 {
     this.connector = connector;
     this.connector.ExecutingQuery += this.connector_ExecutingQuery;
 }
Пример #8
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();
        }
Пример #9
0
 public FunctionalTests()
 {
     this.connector            = new Client15Connector(TestConfiguration.SharePointSiteUrl);
     this.connector.GetNewGuid = this.GetDeterministicGuid;
 }