internal void SetCurrentFolder(AuthToken authToken, string folderPath, TimeSpan timeout)
        {
            var oldFolderId = authToken.OrganizationUnitId;

            authToken.OrganizationUnitId = default;
            try
            {
                using (var api = AuthenticatedCmdlet.MakeApi_19_10(authToken, timeout))
                {
                    var folders = HandleHttpResponseException(() => api.Folders.GetFoldersWithHttpMessagesAsync(filter: $"FullyQualifiedName eq '{Uri.EscapeDataString(folderPath)}'")).Value;
                    if (folders.Count != 1)
                    {
                        throw new Exception($"The folder path '{folderPath}' does not select exactly one Folder");
                    }

                    var folder = folders.Single();
                    authToken.CurrentFolder      = Folder.FromDto(folder);
                    authToken.OrganizationUnit   = default;
                    authToken.OrganizationUnitId = folder.Id;
                }
            }
            catch
            {
                authToken.OrganizationUnitId = oldFolderId;
                throw;
            }
        }
Exemplo n.º 2
0
        internal void FindAndSetDefaultFolder(AuthToken authToken, TimeSpan timeout)
        {
            using (var api = AuthenticatedCmdlet.MakeApi_19_10(authToken, timeout))
            {
                // 19.10 Folders OData endpoint does not support `in (...)`
                foreach (var folderName in new[] { "Default", "Shared" })
                {
                    var folders = HandleHttpResponseException(() => api.Folders.GetFoldersWithHttpMessagesAsync(
                                                                  filter: $"FullyQualifiedName eq '{folderName}'")).Value;
                    var folder = folders.FirstOrDefault();

                    if (folder != null)
                    {
                        SetCurrentFolder(authToken, folder.FullyQualifiedName, timeout);
                        break;
                    }
                }
            }
        }
        internal static long?GetDefaultCredentialStore(this AuthenticatedCmdlet cmdlet, string resourceType)
        {
            var id = cmdlet.HandleHttpResponseException(() => cmdlet.Api_19_10.CredentialStores.GetDefaultStoreForResourceTypeByResourcetypeWithHttpMessagesAsync(resourceType));

            return(id.Value);
        }