Skip to content

Commit acf2ad7

Browse files
committed
Refactor sharing capability handling to improve timeout management and encapsulate logic in a dedicated method
1 parent 96b62de commit acf2ad7

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/Commands/Admin/NewTenantSite.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,7 @@ protected override void ExecuteCmdlet()
7272

7373
if (newSiteId != Guid.Empty && Wait && SharingCapability.HasValue)
7474
{
75-
var props = Tenant.GetSitePropertiesByUrl(Url, true);
76-
Tenant.Context.Load(props);
77-
Tenant.Context.ExecuteQueryRetry();
78-
79-
props.SharingCapability = SharingCapability.Value;
80-
81-
var op = props.Update();
82-
AdminContext.Load(op, i => i.IsComplete, i => i.PollingInterval);
83-
AdminContext.ExecuteQueryRetry();
75+
SetSharingCapability(Url, SharingCapability.Value);
8476
}
8577
}
8678
else
@@ -111,8 +103,9 @@ protected override void ExecuteCmdlet()
111103
{
112104
throw new TimeoutException("Wait for site creation operation to complete has timed out.");
113105
}
114-
Task.Delay(TimeSpan.FromMilliseconds(spoOperation.PollingInterval)).GetAwaiter().GetResult();
106+
Task.Delay(TimeSpan.FromMilliseconds(spoOperation.PollingInterval)).GetAwaiter().GetResult();
115107
spoOperation.RefreshLoad();
108+
116109
if (((Cmdlet)this).Stopping)
117110
{
118111
((Cmdlet)this).WriteWarning("Cmdlet execution interrupted by user, stopping wait for site creation operation to complete.");
@@ -123,21 +116,25 @@ protected override void ExecuteCmdlet()
123116
}
124117
}
125118

126-
if (SharingCapability.HasValue)
119+
if (Wait && SharingCapability.HasValue)
127120
{
128-
var props = Tenant.GetSitePropertiesByUrl(Url, true);
129-
Tenant.Context.Load(props);
130-
Tenant.Context.ExecuteQueryRetry();
131-
132-
props.SharingCapability = SharingCapability.Value;
133-
134-
var op = props.Update();
135-
AdminContext.Load(op, i => i.IsComplete, i => i.PollingInterval);
136-
AdminContext.ExecuteQueryRetry();
121+
SetSharingCapability(Url, SharingCapability.Value);
137122
}
138123
}
139124
}
140125

126+
private void SetSharingCapability(string url, SharingCapabilities sharingCapability)
127+
{
128+
var props = Tenant.GetSitePropertiesByUrl(url, true);
129+
Tenant.Context.Load(props);
130+
Tenant.Context.ExecuteQueryRetry();
131+
132+
props.SharingCapability = sharingCapability;
133+
var op = props.Update();
134+
AdminContext.Load(op, i => i.IsComplete, i => i.PollingInterval);
135+
AdminContext.ExecuteQueryRetry();
136+
}
137+
141138
private bool TimeoutFunction(TenantOperationMessage message)
142139
{
143140
if (message == TenantOperationMessage.CreatingSiteCollection)

0 commit comments

Comments
 (0)