1package desktopvirtualization
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// UserSessionsClient is the client for the UserSessions methods of the Desktopvirtualization service.
30type UserSessionsClient struct {
31	BaseClient
32}
33
34// NewUserSessionsClient creates an instance of the UserSessionsClient client.
35func NewUserSessionsClient(subscriptionID string) UserSessionsClient {
36	return NewUserSessionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewUserSessionsClientWithBaseURI creates an instance of the UserSessionsClient client using a custom endpoint.  Use
40// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewUserSessionsClientWithBaseURI(baseURI string, subscriptionID string) UserSessionsClient {
42	return UserSessionsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Delete remove a userSession.
46// Parameters:
47// resourceGroupName - the name of the resource group. The name is case insensitive.
48// hostPoolName - the name of the host pool within the specified resource group
49// sessionHostName - the name of the session host within the specified host pool
50// userSessionID - the name of the user session within the specified session host
51// force - force flag to login off userSession.
52func (client UserSessionsClient) Delete(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionID string, force *bool) (result autorest.Response, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/UserSessionsClient.Delete")
55		defer func() {
56			sc := -1
57			if result.Response != nil {
58				sc = result.Response.StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	if err := validation.Validate([]validation.Validation{
64		{TargetValue: client.SubscriptionID,
65			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
66		{TargetValue: resourceGroupName,
67			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
68				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
69				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
70		{TargetValue: hostPoolName,
71			Constraints: []validation.Constraint{{Target: "hostPoolName", Name: validation.MaxLength, Rule: 24, Chain: nil},
72				{Target: "hostPoolName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
73		{TargetValue: sessionHostName,
74			Constraints: []validation.Constraint{{Target: "sessionHostName", Name: validation.MaxLength, Rule: 48, Chain: nil},
75				{Target: "sessionHostName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
76		{TargetValue: userSessionID,
77			Constraints: []validation.Constraint{{Target: "userSessionID", Name: validation.MaxLength, Rule: 24, Chain: nil},
78				{Target: "userSessionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
79		return result, validation.NewError("desktopvirtualization.UserSessionsClient", "Delete", err.Error())
80	}
81
82	req, err := client.DeletePreparer(ctx, resourceGroupName, hostPoolName, sessionHostName, userSessionID, force)
83	if err != nil {
84		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Delete", nil, "Failure preparing request")
85		return
86	}
87
88	resp, err := client.DeleteSender(req)
89	if err != nil {
90		result.Response = resp
91		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Delete", resp, "Failure sending request")
92		return
93	}
94
95	result, err = client.DeleteResponder(resp)
96	if err != nil {
97		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Delete", resp, "Failure responding to request")
98		return
99	}
100
101	return
102}
103
104// DeletePreparer prepares the Delete request.
105func (client UserSessionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionID string, force *bool) (*http.Request, error) {
106	pathParameters := map[string]interface{}{
107		"hostPoolName":      autorest.Encode("path", hostPoolName),
108		"resourceGroupName": autorest.Encode("path", resourceGroupName),
109		"sessionHostName":   autorest.Encode("path", sessionHostName),
110		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
111		"userSessionId":     autorest.Encode("path", userSessionID),
112	}
113
114	const APIVersion = "2019-01-23-preview"
115	queryParameters := map[string]interface{}{
116		"api-version": APIVersion,
117	}
118	if force != nil {
119		queryParameters["force"] = autorest.Encode("query", *force)
120	}
121
122	preparer := autorest.CreatePreparer(
123		autorest.AsDelete(),
124		autorest.WithBaseURL(client.BaseURI),
125		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions/{userSessionId}", pathParameters),
126		autorest.WithQueryParameters(queryParameters))
127	return preparer.Prepare((&http.Request{}).WithContext(ctx))
128}
129
130// DeleteSender sends the Delete request. The method will close the
131// http.Response Body if it receives an error.
132func (client UserSessionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
133	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
134}
135
136// DeleteResponder handles the response to the Delete request. The method always
137// closes the http.Response Body.
138func (client UserSessionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
139	err = autorest.Respond(
140		resp,
141		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
142		autorest.ByClosing())
143	result.Response = resp
144	return
145}
146
147// Disconnect disconnect a userSession.
148// Parameters:
149// resourceGroupName - the name of the resource group. The name is case insensitive.
150// hostPoolName - the name of the host pool within the specified resource group
151// sessionHostName - the name of the session host within the specified host pool
152// userSessionID - the name of the user session within the specified session host
153func (client UserSessionsClient) Disconnect(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionID string) (result autorest.Response, err error) {
154	if tracing.IsEnabled() {
155		ctx = tracing.StartSpan(ctx, fqdn+"/UserSessionsClient.Disconnect")
156		defer func() {
157			sc := -1
158			if result.Response != nil {
159				sc = result.Response.StatusCode
160			}
161			tracing.EndSpan(ctx, sc, err)
162		}()
163	}
164	if err := validation.Validate([]validation.Validation{
165		{TargetValue: client.SubscriptionID,
166			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
167		{TargetValue: resourceGroupName,
168			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
169				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
170				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
171		{TargetValue: hostPoolName,
172			Constraints: []validation.Constraint{{Target: "hostPoolName", Name: validation.MaxLength, Rule: 24, Chain: nil},
173				{Target: "hostPoolName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
174		{TargetValue: sessionHostName,
175			Constraints: []validation.Constraint{{Target: "sessionHostName", Name: validation.MaxLength, Rule: 48, Chain: nil},
176				{Target: "sessionHostName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
177		{TargetValue: userSessionID,
178			Constraints: []validation.Constraint{{Target: "userSessionID", Name: validation.MaxLength, Rule: 24, Chain: nil},
179				{Target: "userSessionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
180		return result, validation.NewError("desktopvirtualization.UserSessionsClient", "Disconnect", err.Error())
181	}
182
183	req, err := client.DisconnectPreparer(ctx, resourceGroupName, hostPoolName, sessionHostName, userSessionID)
184	if err != nil {
185		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Disconnect", nil, "Failure preparing request")
186		return
187	}
188
189	resp, err := client.DisconnectSender(req)
190	if err != nil {
191		result.Response = resp
192		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Disconnect", resp, "Failure sending request")
193		return
194	}
195
196	result, err = client.DisconnectResponder(resp)
197	if err != nil {
198		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Disconnect", resp, "Failure responding to request")
199		return
200	}
201
202	return
203}
204
205// DisconnectPreparer prepares the Disconnect request.
206func (client UserSessionsClient) DisconnectPreparer(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionID string) (*http.Request, error) {
207	pathParameters := map[string]interface{}{
208		"hostPoolName":      autorest.Encode("path", hostPoolName),
209		"resourceGroupName": autorest.Encode("path", resourceGroupName),
210		"sessionHostName":   autorest.Encode("path", sessionHostName),
211		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
212		"userSessionId":     autorest.Encode("path", userSessionID),
213	}
214
215	const APIVersion = "2019-01-23-preview"
216	queryParameters := map[string]interface{}{
217		"api-version": APIVersion,
218	}
219
220	preparer := autorest.CreatePreparer(
221		autorest.AsPost(),
222		autorest.WithBaseURL(client.BaseURI),
223		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions/{userSessionId}/disconnect", pathParameters),
224		autorest.WithQueryParameters(queryParameters))
225	return preparer.Prepare((&http.Request{}).WithContext(ctx))
226}
227
228// DisconnectSender sends the Disconnect request. The method will close the
229// http.Response Body if it receives an error.
230func (client UserSessionsClient) DisconnectSender(req *http.Request) (*http.Response, error) {
231	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
232}
233
234// DisconnectResponder handles the response to the Disconnect request. The method always
235// closes the http.Response Body.
236func (client UserSessionsClient) DisconnectResponder(resp *http.Response) (result autorest.Response, err error) {
237	err = autorest.Respond(
238		resp,
239		azure.WithErrorUnlessStatusCode(http.StatusOK),
240		autorest.ByClosing())
241	result.Response = resp
242	return
243}
244
245// Get get a userSession.
246// Parameters:
247// resourceGroupName - the name of the resource group. The name is case insensitive.
248// hostPoolName - the name of the host pool within the specified resource group
249// sessionHostName - the name of the session host within the specified host pool
250// userSessionID - the name of the user session within the specified session host
251func (client UserSessionsClient) Get(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionID string) (result UserSession, err error) {
252	if tracing.IsEnabled() {
253		ctx = tracing.StartSpan(ctx, fqdn+"/UserSessionsClient.Get")
254		defer func() {
255			sc := -1
256			if result.Response.Response != nil {
257				sc = result.Response.Response.StatusCode
258			}
259			tracing.EndSpan(ctx, sc, err)
260		}()
261	}
262	if err := validation.Validate([]validation.Validation{
263		{TargetValue: client.SubscriptionID,
264			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
265		{TargetValue: resourceGroupName,
266			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
267				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
268				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
269		{TargetValue: hostPoolName,
270			Constraints: []validation.Constraint{{Target: "hostPoolName", Name: validation.MaxLength, Rule: 24, Chain: nil},
271				{Target: "hostPoolName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
272		{TargetValue: sessionHostName,
273			Constraints: []validation.Constraint{{Target: "sessionHostName", Name: validation.MaxLength, Rule: 48, Chain: nil},
274				{Target: "sessionHostName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
275		{TargetValue: userSessionID,
276			Constraints: []validation.Constraint{{Target: "userSessionID", Name: validation.MaxLength, Rule: 24, Chain: nil},
277				{Target: "userSessionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
278		return result, validation.NewError("desktopvirtualization.UserSessionsClient", "Get", err.Error())
279	}
280
281	req, err := client.GetPreparer(ctx, resourceGroupName, hostPoolName, sessionHostName, userSessionID)
282	if err != nil {
283		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Get", nil, "Failure preparing request")
284		return
285	}
286
287	resp, err := client.GetSender(req)
288	if err != nil {
289		result.Response = autorest.Response{Response: resp}
290		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Get", resp, "Failure sending request")
291		return
292	}
293
294	result, err = client.GetResponder(resp)
295	if err != nil {
296		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "Get", resp, "Failure responding to request")
297		return
298	}
299
300	return
301}
302
303// GetPreparer prepares the Get request.
304func (client UserSessionsClient) GetPreparer(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionID string) (*http.Request, error) {
305	pathParameters := map[string]interface{}{
306		"hostPoolName":      autorest.Encode("path", hostPoolName),
307		"resourceGroupName": autorest.Encode("path", resourceGroupName),
308		"sessionHostName":   autorest.Encode("path", sessionHostName),
309		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
310		"userSessionId":     autorest.Encode("path", userSessionID),
311	}
312
313	const APIVersion = "2019-01-23-preview"
314	queryParameters := map[string]interface{}{
315		"api-version": APIVersion,
316	}
317
318	preparer := autorest.CreatePreparer(
319		autorest.AsGet(),
320		autorest.WithBaseURL(client.BaseURI),
321		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions/{userSessionId}", pathParameters),
322		autorest.WithQueryParameters(queryParameters))
323	return preparer.Prepare((&http.Request{}).WithContext(ctx))
324}
325
326// GetSender sends the Get request. The method will close the
327// http.Response Body if it receives an error.
328func (client UserSessionsClient) GetSender(req *http.Request) (*http.Response, error) {
329	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
330}
331
332// GetResponder handles the response to the Get request. The method always
333// closes the http.Response Body.
334func (client UserSessionsClient) GetResponder(resp *http.Response) (result UserSession, err error) {
335	err = autorest.Respond(
336		resp,
337		azure.WithErrorUnlessStatusCode(http.StatusOK),
338		autorest.ByUnmarshallingJSON(&result),
339		autorest.ByClosing())
340	result.Response = autorest.Response{Response: resp}
341	return
342}
343
344// List list userSessions.
345// Parameters:
346// resourceGroupName - the name of the resource group. The name is case insensitive.
347// hostPoolName - the name of the host pool within the specified resource group
348// sessionHostName - the name of the session host within the specified host pool
349func (client UserSessionsClient) List(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string) (result UserSessionListPage, err error) {
350	if tracing.IsEnabled() {
351		ctx = tracing.StartSpan(ctx, fqdn+"/UserSessionsClient.List")
352		defer func() {
353			sc := -1
354			if result.usl.Response.Response != nil {
355				sc = result.usl.Response.Response.StatusCode
356			}
357			tracing.EndSpan(ctx, sc, err)
358		}()
359	}
360	if err := validation.Validate([]validation.Validation{
361		{TargetValue: client.SubscriptionID,
362			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
363		{TargetValue: resourceGroupName,
364			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
365				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
366				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
367		{TargetValue: hostPoolName,
368			Constraints: []validation.Constraint{{Target: "hostPoolName", Name: validation.MaxLength, Rule: 24, Chain: nil},
369				{Target: "hostPoolName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
370		{TargetValue: sessionHostName,
371			Constraints: []validation.Constraint{{Target: "sessionHostName", Name: validation.MaxLength, Rule: 48, Chain: nil},
372				{Target: "sessionHostName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
373		return result, validation.NewError("desktopvirtualization.UserSessionsClient", "List", err.Error())
374	}
375
376	result.fn = client.listNextResults
377	req, err := client.ListPreparer(ctx, resourceGroupName, hostPoolName, sessionHostName)
378	if err != nil {
379		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "List", nil, "Failure preparing request")
380		return
381	}
382
383	resp, err := client.ListSender(req)
384	if err != nil {
385		result.usl.Response = autorest.Response{Response: resp}
386		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "List", resp, "Failure sending request")
387		return
388	}
389
390	result.usl, err = client.ListResponder(resp)
391	if err != nil {
392		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "List", resp, "Failure responding to request")
393		return
394	}
395	if result.usl.hasNextLink() && result.usl.IsEmpty() {
396		err = result.NextWithContext(ctx)
397		return
398	}
399
400	return
401}
402
403// ListPreparer prepares the List request.
404func (client UserSessionsClient) ListPreparer(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string) (*http.Request, error) {
405	pathParameters := map[string]interface{}{
406		"hostPoolName":      autorest.Encode("path", hostPoolName),
407		"resourceGroupName": autorest.Encode("path", resourceGroupName),
408		"sessionHostName":   autorest.Encode("path", sessionHostName),
409		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
410	}
411
412	const APIVersion = "2019-01-23-preview"
413	queryParameters := map[string]interface{}{
414		"api-version": APIVersion,
415	}
416
417	preparer := autorest.CreatePreparer(
418		autorest.AsGet(),
419		autorest.WithBaseURL(client.BaseURI),
420		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions", pathParameters),
421		autorest.WithQueryParameters(queryParameters))
422	return preparer.Prepare((&http.Request{}).WithContext(ctx))
423}
424
425// ListSender sends the List request. The method will close the
426// http.Response Body if it receives an error.
427func (client UserSessionsClient) ListSender(req *http.Request) (*http.Response, error) {
428	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
429}
430
431// ListResponder handles the response to the List request. The method always
432// closes the http.Response Body.
433func (client UserSessionsClient) ListResponder(resp *http.Response) (result UserSessionList, err error) {
434	err = autorest.Respond(
435		resp,
436		azure.WithErrorUnlessStatusCode(http.StatusOK),
437		autorest.ByUnmarshallingJSON(&result),
438		autorest.ByClosing())
439	result.Response = autorest.Response{Response: resp}
440	return
441}
442
443// listNextResults retrieves the next set of results, if any.
444func (client UserSessionsClient) listNextResults(ctx context.Context, lastResults UserSessionList) (result UserSessionList, err error) {
445	req, err := lastResults.userSessionListPreparer(ctx)
446	if err != nil {
447		return result, autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "listNextResults", nil, "Failure preparing next results request")
448	}
449	if req == nil {
450		return
451	}
452	resp, err := client.ListSender(req)
453	if err != nil {
454		result.Response = autorest.Response{Response: resp}
455		return result, autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "listNextResults", resp, "Failure sending next results request")
456	}
457	result, err = client.ListResponder(resp)
458	if err != nil {
459		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "listNextResults", resp, "Failure responding to next results request")
460	}
461	return
462}
463
464// ListComplete enumerates all values, automatically crossing page boundaries as required.
465func (client UserSessionsClient) ListComplete(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string) (result UserSessionListIterator, err error) {
466	if tracing.IsEnabled() {
467		ctx = tracing.StartSpan(ctx, fqdn+"/UserSessionsClient.List")
468		defer func() {
469			sc := -1
470			if result.Response().Response.Response != nil {
471				sc = result.page.Response().Response.Response.StatusCode
472			}
473			tracing.EndSpan(ctx, sc, err)
474		}()
475	}
476	result.page, err = client.List(ctx, resourceGroupName, hostPoolName, sessionHostName)
477	return
478}
479
480// ListByHostPool list userSessions.
481// Parameters:
482// resourceGroupName - the name of the resource group. The name is case insensitive.
483// hostPoolName - the name of the host pool within the specified resource group
484// filter - oData filter expression. Valid properties for filtering are userprincipalname and sessionstate.
485func (client UserSessionsClient) ListByHostPool(ctx context.Context, resourceGroupName string, hostPoolName string, filter string) (result UserSessionListPage, err error) {
486	if tracing.IsEnabled() {
487		ctx = tracing.StartSpan(ctx, fqdn+"/UserSessionsClient.ListByHostPool")
488		defer func() {
489			sc := -1
490			if result.usl.Response.Response != nil {
491				sc = result.usl.Response.Response.StatusCode
492			}
493			tracing.EndSpan(ctx, sc, err)
494		}()
495	}
496	if err := validation.Validate([]validation.Validation{
497		{TargetValue: client.SubscriptionID,
498			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
499		{TargetValue: resourceGroupName,
500			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
501				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
502				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
503		{TargetValue: hostPoolName,
504			Constraints: []validation.Constraint{{Target: "hostPoolName", Name: validation.MaxLength, Rule: 24, Chain: nil},
505				{Target: "hostPoolName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
506		return result, validation.NewError("desktopvirtualization.UserSessionsClient", "ListByHostPool", err.Error())
507	}
508
509	result.fn = client.listByHostPoolNextResults
510	req, err := client.ListByHostPoolPreparer(ctx, resourceGroupName, hostPoolName, filter)
511	if err != nil {
512		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "ListByHostPool", nil, "Failure preparing request")
513		return
514	}
515
516	resp, err := client.ListByHostPoolSender(req)
517	if err != nil {
518		result.usl.Response = autorest.Response{Response: resp}
519		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "ListByHostPool", resp, "Failure sending request")
520		return
521	}
522
523	result.usl, err = client.ListByHostPoolResponder(resp)
524	if err != nil {
525		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "ListByHostPool", resp, "Failure responding to request")
526		return
527	}
528	if result.usl.hasNextLink() && result.usl.IsEmpty() {
529		err = result.NextWithContext(ctx)
530		return
531	}
532
533	return
534}
535
536// ListByHostPoolPreparer prepares the ListByHostPool request.
537func (client UserSessionsClient) ListByHostPoolPreparer(ctx context.Context, resourceGroupName string, hostPoolName string, filter string) (*http.Request, error) {
538	pathParameters := map[string]interface{}{
539		"hostPoolName":      autorest.Encode("path", hostPoolName),
540		"resourceGroupName": autorest.Encode("path", resourceGroupName),
541		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
542	}
543
544	const APIVersion = "2019-01-23-preview"
545	queryParameters := map[string]interface{}{
546		"api-version": APIVersion,
547	}
548	if len(filter) > 0 {
549		queryParameters["$filter"] = autorest.Encode("query", filter)
550	}
551
552	preparer := autorest.CreatePreparer(
553		autorest.AsGet(),
554		autorest.WithBaseURL(client.BaseURI),
555		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/userSessions", pathParameters),
556		autorest.WithQueryParameters(queryParameters))
557	return preparer.Prepare((&http.Request{}).WithContext(ctx))
558}
559
560// ListByHostPoolSender sends the ListByHostPool request. The method will close the
561// http.Response Body if it receives an error.
562func (client UserSessionsClient) ListByHostPoolSender(req *http.Request) (*http.Response, error) {
563	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
564}
565
566// ListByHostPoolResponder handles the response to the ListByHostPool request. The method always
567// closes the http.Response Body.
568func (client UserSessionsClient) ListByHostPoolResponder(resp *http.Response) (result UserSessionList, err error) {
569	err = autorest.Respond(
570		resp,
571		azure.WithErrorUnlessStatusCode(http.StatusOK),
572		autorest.ByUnmarshallingJSON(&result),
573		autorest.ByClosing())
574	result.Response = autorest.Response{Response: resp}
575	return
576}
577
578// listByHostPoolNextResults retrieves the next set of results, if any.
579func (client UserSessionsClient) listByHostPoolNextResults(ctx context.Context, lastResults UserSessionList) (result UserSessionList, err error) {
580	req, err := lastResults.userSessionListPreparer(ctx)
581	if err != nil {
582		return result, autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "listByHostPoolNextResults", nil, "Failure preparing next results request")
583	}
584	if req == nil {
585		return
586	}
587	resp, err := client.ListByHostPoolSender(req)
588	if err != nil {
589		result.Response = autorest.Response{Response: resp}
590		return result, autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "listByHostPoolNextResults", resp, "Failure sending next results request")
591	}
592	result, err = client.ListByHostPoolResponder(resp)
593	if err != nil {
594		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "listByHostPoolNextResults", resp, "Failure responding to next results request")
595	}
596	return
597}
598
599// ListByHostPoolComplete enumerates all values, automatically crossing page boundaries as required.
600func (client UserSessionsClient) ListByHostPoolComplete(ctx context.Context, resourceGroupName string, hostPoolName string, filter string) (result UserSessionListIterator, err error) {
601	if tracing.IsEnabled() {
602		ctx = tracing.StartSpan(ctx, fqdn+"/UserSessionsClient.ListByHostPool")
603		defer func() {
604			sc := -1
605			if result.Response().Response.Response != nil {
606				sc = result.page.Response().Response.Response.StatusCode
607			}
608			tracing.EndSpan(ctx, sc, err)
609		}()
610	}
611	result.page, err = client.ListByHostPool(ctx, resourceGroupName, hostPoolName, filter)
612	return
613}
614
615// SendMessageMethod send a message to a user.
616// Parameters:
617// resourceGroupName - the name of the resource group. The name is case insensitive.
618// hostPoolName - the name of the host pool within the specified resource group
619// sessionHostName - the name of the session host within the specified host pool
620// userSessionID - the name of the user session within the specified session host
621// sendMessage - object containing message includes title and message body
622func (client UserSessionsClient) SendMessageMethod(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionID string, sendMessage *SendMessage) (result autorest.Response, err error) {
623	if tracing.IsEnabled() {
624		ctx = tracing.StartSpan(ctx, fqdn+"/UserSessionsClient.SendMessageMethod")
625		defer func() {
626			sc := -1
627			if result.Response != nil {
628				sc = result.Response.StatusCode
629			}
630			tracing.EndSpan(ctx, sc, err)
631		}()
632	}
633	if err := validation.Validate([]validation.Validation{
634		{TargetValue: client.SubscriptionID,
635			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
636		{TargetValue: resourceGroupName,
637			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
638				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
639				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
640		{TargetValue: hostPoolName,
641			Constraints: []validation.Constraint{{Target: "hostPoolName", Name: validation.MaxLength, Rule: 24, Chain: nil},
642				{Target: "hostPoolName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
643		{TargetValue: sessionHostName,
644			Constraints: []validation.Constraint{{Target: "sessionHostName", Name: validation.MaxLength, Rule: 48, Chain: nil},
645				{Target: "sessionHostName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
646		{TargetValue: userSessionID,
647			Constraints: []validation.Constraint{{Target: "userSessionID", Name: validation.MaxLength, Rule: 24, Chain: nil},
648				{Target: "userSessionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
649		return result, validation.NewError("desktopvirtualization.UserSessionsClient", "SendMessageMethod", err.Error())
650	}
651
652	req, err := client.SendMessageMethodPreparer(ctx, resourceGroupName, hostPoolName, sessionHostName, userSessionID, sendMessage)
653	if err != nil {
654		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "SendMessageMethod", nil, "Failure preparing request")
655		return
656	}
657
658	resp, err := client.SendMessageMethodSender(req)
659	if err != nil {
660		result.Response = resp
661		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "SendMessageMethod", resp, "Failure sending request")
662		return
663	}
664
665	result, err = client.SendMessageMethodResponder(resp)
666	if err != nil {
667		err = autorest.NewErrorWithError(err, "desktopvirtualization.UserSessionsClient", "SendMessageMethod", resp, "Failure responding to request")
668		return
669	}
670
671	return
672}
673
674// SendMessageMethodPreparer prepares the SendMessageMethod request.
675func (client UserSessionsClient) SendMessageMethodPreparer(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionID string, sendMessage *SendMessage) (*http.Request, error) {
676	pathParameters := map[string]interface{}{
677		"hostPoolName":      autorest.Encode("path", hostPoolName),
678		"resourceGroupName": autorest.Encode("path", resourceGroupName),
679		"sessionHostName":   autorest.Encode("path", sessionHostName),
680		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
681		"userSessionId":     autorest.Encode("path", userSessionID),
682	}
683
684	const APIVersion = "2019-01-23-preview"
685	queryParameters := map[string]interface{}{
686		"api-version": APIVersion,
687	}
688
689	preparer := autorest.CreatePreparer(
690		autorest.AsContentType("application/json; charset=utf-8"),
691		autorest.AsPost(),
692		autorest.WithBaseURL(client.BaseURI),
693		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions/{userSessionId}/sendMessage", pathParameters),
694		autorest.WithQueryParameters(queryParameters))
695	if sendMessage != nil {
696		preparer = autorest.DecoratePreparer(preparer,
697			autorest.WithJSON(sendMessage))
698	}
699	return preparer.Prepare((&http.Request{}).WithContext(ctx))
700}
701
702// SendMessageMethodSender sends the SendMessageMethod request. The method will close the
703// http.Response Body if it receives an error.
704func (client UserSessionsClient) SendMessageMethodSender(req *http.Request) (*http.Response, error) {
705	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
706}
707
708// SendMessageMethodResponder handles the response to the SendMessageMethod request. The method always
709// closes the http.Response Body.
710func (client UserSessionsClient) SendMessageMethodResponder(resp *http.Response) (result autorest.Response, err error) {
711	err = autorest.Respond(
712		resp,
713		azure.WithErrorUnlessStatusCode(http.StatusOK),
714		autorest.ByClosing())
715	result.Response = resp
716	return
717}
718