-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathInstanceDetails.xaml.cs
More file actions
787 lines (643 loc) · 22.2 KB
/
InstanceDetails.xaml.cs
File metadata and controls
787 lines (643 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
namespace SIM.Tool.Windows.UserControls.Install
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Xml;
using SIM.Adapters.SqlServer;
using SIM.Adapters.WebServer;
using SIM.Instances;
using SIM.Products;
using SIM.Tool.Base;
using SIM.Tool.Base.Pipelines;
using SIM.Tool.Base.Profiles;
using SIM.Tool.Base.Wizards;
using Sitecore.Diagnostics.Base;
using JetBrains.Annotations;
using Sitecore.Diagnostics.Logging;
using SIM.Extensions;
using SIM.Tool.Windows.UserControls.Helpers;
#region
#endregion
[UsedImplicitly]
public partial class InstanceDetails : IWizardStep, IFlowControl
{
#region Fields
[NotNull]
private readonly ICollection<string> _AllFrameworkVersions = Environment.Is64BitOperatingSystem ? new[]
{
"v2.0", "v2.0 32bit", "v4.0", "v4.0 32bit"
} : new[]
{
"v2.0", "v4.0"
};
private InstallWizardArgs _InstallParameters = null;
private IEnumerable<Product> _StandaloneProducts;
private string maximumAllowedVersion = "8.2.7";
#endregion
#region Constructors
public InstanceDetails()
{
InitializeComponent();
NetFramework.ItemsSource = _AllFrameworkVersions;
}
#endregion
#region Public properties
public static bool InstallEverywhere
{
get
{
return WindowsSettings.AppInstallEverywhere.Value;
}
}
#endregion
#region Public Methods
public bool OnMovingBack(WizardArgs wizardArg)
{
return true;
}
public bool OnMovingNext(WizardArgs wizardArgs)
{
var productRevision = ProductRevision;
Assert.IsNotNull(productRevision, nameof(productRevision));
Product product = productRevision.SelectedValue as Product;
Assert.IsNotNull(product, nameof(product));
if (product.Name == "Sitecore CMS" && product.TwoVersion.StartsWith("9.0"))
{
var agreementAcceptedFilePath = Path.Combine(ApplicationManager.TempFolder, "sitecore9.txt");
if (!File.Exists(agreementAcceptedFilePath))
{
if (MessageBox.Show("XCONNECT IS NOT SUPPORTED\r\n\r\nCMS-MODE WILL BE ENABLED IF YOU PROCEED\r\n\r\nThis means all xDB and xConnect features will be unavailable as well as all components and modules that utilize these subsystems.\r\n\r\nUse Sitecore Installation Framework (SIF) to install Sitecore 9 with all features\r\n\r\nDo you want to proceed?", "Sitecore 9.0 CMS-only support", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
{
return false;
}
File.WriteAllText(agreementAcceptedFilePath, @"acknowledged");
}
}
var rootName = GetValidRootName();
var rootPath = GetValidRootPath(rootName);
if (rootPath == null)
return false;
var name = GetValidWebsiteName();
if (name == null)
return false;
var hostNames = GetValidHostNames();
var sqlPrefix = GetValidSqlPrefix();
var attachSql = AttachSql.IsChecked ?? true;
var connectionString = ProfileManager.GetConnectionString();
SqlServerManager.Instance.ValidateConnectionString(connectionString);
var licensePath = ProfileManager.Profile.License;
Assert.IsNotNull(licensePath, @"The license file isn't set in the Settings window");
FileSystem.FileSystem.Local.File.AssertExists(licensePath, "The {0} file is missing".FormatWith(licensePath));
var appPoolInfo = GetAppPoolInfo();
var args = (InstallWizardArgs)wizardArgs;
args.InstanceName = name;
args.InstanceHostNames = hostNames;
args.InstanceSqlPrefix = sqlPrefix;
args.InstanceAttachSql = attachSql;
args.InstanceWebRootPath = GetWebRootPath(rootPath);
args.InstanceRootName = rootName;
args.InstanceRootPath = rootPath;
args.InstanceProduct = product;
args.InstanceConnectionString = connectionString;
args.LicenseFileInfo = new FileInfo(licensePath);
args.InstanceAppPoolInfo = appPoolInfo;
args.Product = product;
return true;
}
[NotNull]
private AppPoolInfo GetAppPoolInfo()
{
var netFramework = NetFramework;
Assert.IsNotNull(netFramework, nameof(netFramework));
var framework = netFramework.SelectedValue.ToString();
var frameworkArr = framework.Split(' ');
Assert.IsTrue(frameworkArr.Length > 0, "impossible");
var force32Bit = frameworkArr.Length == 2;
var mode = Mode;
Assert.IsNotNull(mode, nameof(mode));
var modeItem = (ListBoxItem) mode.SelectedValue;
Assert.IsNotNull(modeItem, nameof(modeItem));
var isClassic = ((string) modeItem.Content).EqualsIgnoreCase("Classic");
var appPoolInfo = new AppPoolInfo
{
FrameworkVersion = frameworkArr[0].EmptyToNull() ?? "v2.0",
Enable32BitAppOnWin64 = force32Bit,
ManagedPipelineMode = !isClassic
};
return appPoolInfo;
}
private static string GetWebRootPath(string rootPath)
{
var webRootPath = Path.Combine(rootPath, "Website");
return webRootPath;
}
[NotNull]
private string GetValidRootName()
{
var rootName = RootName;
Assert.IsNotNull(rootName, nameof(rootName));
var root = rootName.Text.EmptyToNull();
Assert.IsNotNull(rootName, "Root folder name must not be emoty");
return root;
}
[CanBeNull]
private string GetValidRootPath(string root)
{
var location = locationFolder.Text.EmptyToNull();
Assert.IsNotNull(location, @"The location folder isn't set");
var rootPath = Path.Combine(location, root);
var locationIsPhysical = FileSystem.FileSystem.Local.Directory.HasDriveLetter(rootPath);
Assert.IsTrue(locationIsPhysical, "The location folder path must be physical i.e. contain a drive letter. Please choose another location folder");
var webRootPath = GetWebRootPath(rootPath);
var rootFolderExists = FileSystem.FileSystem.Local.Directory.Exists(rootPath);
if (!rootFolderExists || InstanceManager.Default.Instances == null)
return rootPath;
if (InstanceManager.Default.Instances.Any(i => i != null && i.WebRootPath.EqualsIgnoreCase(webRootPath)))
{
Alert("There is another instance with the same root path, please choose another folder");
return null;
}
if (WindowHelper.ShowMessage("The folder with the same name already exists. Would you like to delete it?", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.OK) != MessageBoxResult.OK)
{
return null;
}
FileSystem.FileSystem.Local.Directory.DeleteIfExists(rootPath);
return rootPath;
}
[CanBeNull]
private string GetValidWebsiteName()
{
var instanceName = InstanceName;
Assert.IsNotNull(instanceName, nameof(instanceName));
var name = instanceName.Text.EmptyToNull();
Assert.IsNotNull(name, @"Instance name isn't set");
var websiteExists = WebServerManager.WebsiteExists(name);
if (websiteExists)
{
using (var context = WebServerManager.CreateContext())
{
var site = context.Sites.Single(s => s != null && s.Name.EqualsIgnoreCase(name));
var path = WebServerManager.GetWebRootPath(site);
if (FileSystem.FileSystem.Local.Directory.Exists(path))
{
Alert("The website with the same name already exists, please choose another instance name.");
return null;
}
if (
WindowHelper.ShowMessage(
$"A website with the name {name} already exists. Would you like to remove it?",
MessageBoxButton.OKCancel, MessageBoxImage.Asterisk) != MessageBoxResult.OK)
{
return null;
}
site.Delete();
context.CommitChanges();
}
}
websiteExists = WebServerManager.WebsiteExists(name);
Assert.IsTrue(!websiteExists, "The website with the same name already exists, please choose another instance name.");
return name;
}
[NotNull]
private string GetValidSqlPrefix()
{
var prefix = SqlPrefix.Text.EmptyToNull();
Assert.IsNotNull(prefix, @"Sql prefix isn't set");
return prefix;
}
[NotNull]
private string[] GetValidHostNames()
{
var hostName = HostNames;
Assert.IsNotNull(hostName, "HostNames is null");
var hostNamesString = hostName.Text.EmptyToNull();
Assert.IsNotNull(hostNamesString, "Host names can not be empty");
var hostNames = hostNamesString.Split(new[] { '\r', '\n', ',', '|', ';' }, StringSplitOptions.RemoveEmptyEntries);
Assert.IsTrue(hostNames.Any(), "Host names can not be empty");
foreach (var host in hostNames)
{
var hostExists = WebServerManager.HostBindingExists(host);
Assert.IsTrue(!hostExists, $"Website with the host name '{host}' already exists");
}
return hostNames;
}
#endregion
#region Methods
#region Protected methods
protected void Alert([NotNull] string message, [NotNull] params object[] args)
{
Assert.ArgumentNotNull(message, nameof(message));
Assert.ArgumentNotNull(args, nameof(args));
WindowHelper.ShowMessage(message.FormatWith(args), "Conflict is found", MessageBoxButton.OK, MessageBoxImage.Stop);
}
#endregion
#region Private methods
private void Init()
{
using (new ProfileSection("Initializing InstanceDetails", this))
{
DataContext = new Model();
_StandaloneProducts = ProductManager.StandaloneProducts.Where(p=> IsAllowedProductVersion(p)).ToArray();
}
}
private bool IsAllowedProductVersion([NotNull] Product product)
{
Version productVersion;
if (!Version.TryParse(product.TriVersion, out productVersion))
{
Log.Warn($"'{product.TriVersion}' cannot be parsed to System.Version.");
return false;
}
var maxAllowedVersion = Version.Parse(this.maximumAllowedVersion);
return productVersion <= maxAllowedVersion;
}
private void InstanceNameTextChanged([CanBeNull] object sender, [CanBeNull] TextChangedEventArgs e)
{
using (new ProfileSection("Instance name text changed", this))
{
var name = InstanceName.Text;
RootName.Text = name;
SqlPrefix.Text = name;
HostNames.Text = string.Join("\r\n", GenerateHostNames(name));
}
}
private void InstanceName_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
if (!NameCharsHelper.IsValidNameChar(e.Text, "site name"))
{
e.Handled = true;
}
}
[NotNull]
private IEnumerable<string> GenerateHostNames([NotNull]string name)
{
var prefix = GetPrefix(name);
var value = ProductHelper.Settings.CoreProductHostNameSuffix.Value;
var suffixes = value.Split(",;|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (var suffix in suffixes)
{
var append = suffix;
if (append == "<empty>")
{
append = "";
}
var hostName = prefix;
if (!hostName.EndsWith(append, StringComparison.InvariantCultureIgnoreCase))
{
// convert to www1.sc820 => [ www1.sc820, www1.sc820.local, www1.sc820.siteco.re ]
hostName += append;
}
yield return hostName;
}
}
private static string GetPrefix(string name)
{
if (ProductHelper.Settings.CoreProductReverseHostName.Value)
{
// convert sc820.www1 into www1.sc820
return string.Join(".", name.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Reverse());
}
return name;
}
private void PickLocationFolder([CanBeNull] object sender, [CanBeNull] RoutedEventArgs e)
{
WindowHelper.PickFolder("Choose location folder", locationFolder, null);
}
private void ProductNameChanged([CanBeNull] object sender, [CanBeNull] SelectionChangedEventArgs e)
{
var productName = ProductName;
Assert.IsNotNull(productName, nameof(productName));
var grouping = productName.SelectedValue as IGrouping<string, Product>;
if (grouping == null)
{
return;
}
var productVersion = ProductVersion;
Assert.IsNotNull(productVersion, nameof(productVersion));
productVersion.DataContext = grouping.Where(x => x != null).GroupBy(p => p.ShortVersion).Where(x => x != null).OrderBy(p => p.Key);
SelectFirst(productVersion);
}
private void ProductRevisionChanged([CanBeNull] object sender, [CanBeNull] SelectionChangedEventArgs e)
{
using (new ProfileSection("Product revision changed", this))
{
var product = ProductRevision.SelectedValue as Product;
if (product == null)
{
return;
}
var name = product.DefaultInstanceName;
InstanceName.Text = name;
var frameworkVersions = new ObservableCollection<string>(_AllFrameworkVersions);
var m = product.Manifest;
if (m != null)
{
var node = (XmlElement)m.SelectSingleNode("/manifest/*/limitations");
if (node != null)
{
foreach (XmlElement limitation in node.ChildNodes)
{
var lname = limitation.Name;
switch (lname.ToLower())
{
case "framework":
{
var supportedVersions = limitation.SelectElements("supportedVersion");
if (supportedVersions != null)
{
ICollection<string> supportedVersionNames = supportedVersions.Select(supportedVersion => supportedVersion.InnerText).ToArray();
for (int i = frameworkVersions.Count - 1; i >= 0; i--)
{
if (!supportedVersionNames.Contains(frameworkVersions[i]))
{
frameworkVersions.RemoveAt(i);
}
}
}
break;
}
}
}
}
}
var netFramework = NetFramework;
Assert.IsNotNull(netFramework, nameof(netFramework));
netFramework.ItemsSource = frameworkVersions;
netFramework.SelectedIndex = 0;
}
}
private void ProductVersionChanged([CanBeNull] object sender, [CanBeNull] SelectionChangedEventArgs e)
{
var productVersion = ProductVersion;
Assert.IsNotNull(productVersion, nameof(productVersion));
var grouping = productVersion.SelectedValue as IGrouping<string, Product>;
if (grouping == null)
{
return;
}
ProductRevision.DataContext = grouping.OrderBy(p => p.Revision);
SelectLast(ProductRevision);
}
private void Select([NotNull] Selector element, [NotNull] string value)
{
Assert.ArgumentNotNull(element, nameof(element));
Assert.ArgumentNotNull(value, nameof(value));
if (element.Items.Count <= 0)
{
return;
}
for (int i = 0; i < element.Items.Count; ++i)
{
object item0 = element.Items[i];
IGrouping<string, Product> item1 = item0 as IGrouping<string, Product>;
if (item1 != null)
{
var key = item1.Key;
if (key.EqualsIgnoreCase(value))
{
element.SelectedIndex = i;
break;
}
}
else
{
Product item2 = item0 as Product;
if (item2 != null)
{
var key = item2.Revision;
if (key.EqualsIgnoreCase(value))
{
element.SelectedIndex = i;
break;
}
}
}
}
}
private void SelectByValue([NotNull] Selector element, string value)
{
Assert.ArgumentNotNull(element, nameof(element));
if (string.IsNullOrEmpty(value))
{
SelectLast(element);
return;
}
if (element.Items.Count > 0)
{
if (element.Items[0].GetType() == typeof(Product))
{
foreach (Product item in element.Items)
{
if (item.Name.EqualsIgnoreCase(value, true))
{
element.SelectedItem = item;
break;
}
if (item.Revision.EqualsIgnoreCase(value, true))
{
element.SelectedItem = item;
break;
}
}
}
else
{
foreach (var item in element.Items)
{
if (item is ContentControl)
{
if ((item as ContentControl).Content.ToString().EqualsIgnoreCase(value, true))
{
element.SelectedItem = item;
break;
}
}
if (item is string)
{
if ((item as string).EqualsIgnoreCase(value, true))
{
element.SelectedItem = item;
break;
}
}
}
}
}
}
private void SelectFirst([NotNull] Selector element)
{
Assert.ArgumentNotNull(element, nameof(element));
if (element.Items.Count > 0)
{
element.SelectedIndex = 0;
}
}
private void SelectLast([NotNull] Selector element)
{
Assert.ArgumentNotNull(element, nameof(element));
if (element.Items.Count > 0)
{
element.SelectedIndex = element.Items.Count - 1;
}
}
private void SelectProductByValue([CanBeNull] Selector element, [NotNull] string value)
{
Assert.ArgumentNotNull(value, nameof(value));
if (element == null)
{
return;
}
if (string.IsNullOrEmpty(value))
{
SelectLast(element);
return;
}
var items = element.Items;
Assert.IsNotNull(items, nameof(items));
if (items.Count > 0)
{
foreach (IGrouping<string, Product> item in items)
{
if (item.First().Name.EqualsIgnoreCase(value, true))
{
element.SelectedItem = item;
break;
}
if (item.First().TwoVersion.EqualsIgnoreCase(value, true))
{
element.SelectedItem = item;
break;
}
}
}
}
private void WindowLoaded(object sender, RoutedEventArgs e)
{
using (new ProfileSection("Window loaded", this))
{
var args = _InstallParameters;
Assert.IsNotNull(args, nameof(args));
var product = args.Product;
if (product != null)
{
return;
}
SelectProductByValue(ProductName, WindowsSettings.AppInstallationDefaultProduct.Value);
SelectProductByValue(ProductVersion, WindowsSettings.AppInstallationDefaultProductVersion.Value);
SelectByValue(ProductRevision, WindowsSettings.AppInstallationDefaultProductRevision.Value);
var netFramework = NetFramework;
Assert.IsNotNull(netFramework, nameof(netFramework));
if (string.IsNullOrEmpty(WindowsSettings.AppInstallationDefaultFramework.Value))
{
netFramework.SelectedIndex = 0;
}
else
{
SelectByValue(netFramework, WindowsSettings.AppInstallationDefaultFramework.Value);
}
var mode = Mode;
Assert.IsNotNull(mode, nameof(mode));
if (string.IsNullOrEmpty(WindowsSettings.AppInstallationDefaultPoolMode.Value))
{
mode.SelectedIndex = 0;
}
else
{
SelectByValue(mode, WindowsSettings.AppInstallationDefaultPoolMode.Value);
}
}
}
#endregion
#endregion
#region Nested type: Model
public class Model
{
#region Fields
[CanBeNull]
[UsedImplicitly]
public readonly Product[] _Products = ProductManager.StandaloneProducts.ToArray();
[NotNull]
private string _Name;
#endregion
#region Properties
[NotNull]
[UsedImplicitly]
public string Name
{
get
{
return _Name;
}
set
{
Assert.IsNotNull(value.EmptyToNull(), "Name must not be empty");
_Name = value;
}
}
[UsedImplicitly]
public IGrouping<string, Product> SelectedProductGroup1 { get; set; }
#endregion
}
#endregion
#region IWizardStep Members
void IWizardStep.InitializeStep(WizardArgs wizardArgs)
{
Init();
locationFolder.Text = ProfileManager.Profile.InstancesFolder;
ProductName.DataContext = _StandaloneProducts.GroupBy(p => p.Name);
var args = (InstallWizardArgs)wizardArgs;
_InstallParameters = args;
Product product = args.Product;
if (product != null)
{
Select(ProductName, product.Name);
Select(ProductVersion, product.ShortVersion);
Select(ProductRevision, product.Revision);
}
else
{
SelectFirst(ProductName);
}
AppPoolInfo info = args.InstanceAppPoolInfo;
if (info != null)
{
var frameworkValue = $"{info.FrameworkVersion} {(info.Enable32BitAppOnWin64 ? "32bit" : string.Empty)}";
SelectByValue(NetFramework, frameworkValue);
SelectByValue(Mode, info.ManagedPipelineMode ? "Integrated" : "Classic");
}
var name = args.InstanceName;
if (!string.IsNullOrEmpty(name))
{
InstanceName.Text = name;
}
var rootName = args.InstanceRootName;
if (!string.IsNullOrEmpty(rootName))
{
RootName.Text = rootName;
}
var hostNames = args.InstanceHostNames;
if (hostNames != null && hostNames.Any())
{
HostNames.Text = string.Join("\r\n", hostNames);
}
if (rootName == null)
return;
var location = args.InstanceRootPath.TrimEnd(rootName).Trim('/', '\\');
if (!string.IsNullOrEmpty(location))
{
locationFolder.Text = location;
}
}
bool IWizardStep.SaveChanges(WizardArgs wizardArgs)
{
return true;
}
#endregion
}
}