Skip to content

Commit

Permalink
Merge pull request #519 from Sitecore/rc/1.8.0
Browse files Browse the repository at this point in the history
Rc/1.8.0
  • Loading branch information
AndreyFilchenkov authored Dec 25, 2020
2 parents f577a61 + 34ab673 commit cc4de25
Show file tree
Hide file tree
Showing 133 changed files with 2,814 additions and 2,094 deletions.
18 changes: 16 additions & 2 deletions src/SIM.Adapters/WebServer/Website.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Website

public long ID { get; }

private string name;

#endregion

#region Constructors
Expand Down Expand Up @@ -161,9 +163,21 @@ public virtual string Name
{
get
{
using (WebServerManager.WebServerContext context = WebServerManager.CreateContext())
try
{
if (string.IsNullOrEmpty(name))
{
using (WebServerManager.WebServerContext context = WebServerManager.CreateContext())
{
name = GetName(context);
}
}
return name;
}
catch(Exception ex)
{
return GetName(context);
Log.Error(ex, ex.Message);
return "Error";
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions src/SIM.Base/RangeObservableCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SIM
{
public class RangeObservableCollection<T> : ObservableCollection<T>
{
public RangeObservableCollection(IEnumerable<T> list) : base(list)
{

}

public RangeObservableCollection():base()
{

}
private bool _suppressNotification = false;

protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
if (!_suppressNotification)
base.OnCollectionChanged(e);
}

public void AddRange(IEnumerable<T> list)
{
if (list == null)
throw new ArgumentNullException("list");

_suppressNotification = true;

foreach (T item in list)
{
Add(item);
}
_suppressNotification = false;
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}
}
1 change: 1 addition & 0 deletions src/SIM.Base/SIM.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="IAdvancedSettingsStorage.cs" />
<Compile Include="IProfile.cs" />
<Compile Include="IValidateable.cs" />
<Compile Include="RangeObservableCollection.cs" />
<Compile Include="RenderInDataGreedAttribute.cs" />
<Compile Include="Safe.cs" />
<Compile Include="Parameters.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
[TestClass]
public class SqlAdapter_Tests
{
private const string DefaultEnvSqlPath = @"C:\Sitecore\etc\sim2\env\default\SqlServer.txt";
//These tests require the "C:\Sitecore\etc\sim\env\default\SqlServer.txt" file to be present.
//This file contains one line which is a connection string to the SQL server.
//If such file is not present, it should be created by the build task before running integration tests.
private const string DefaultEnvSqlPath = @"C:\Sitecore\etc\sim\env\default\SqlServer.txt";

[NotNull]
private SqlAdapter Adapter { get; } = new SqlAdapter(new SqlConnectionString(File.ReadAllText(DefaultEnvSqlPath)));
Expand Down
37 changes: 33 additions & 4 deletions src/SIM.Instances/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Instance : Website, IXmlSerializable
public Instance([NotNull] int id)
: base(id)
{
this.SitecoreEnvironment = SitecoreEnvironmentHelper.GetExistingOrNewSitecoreEnvironment(this.Name);
}


Expand Down Expand Up @@ -260,10 +261,7 @@ public virtual string PackagesFolderPath


[NotNull]
public virtual SitecoreEnvironment SitecoreEnvironment
{
get { return SitecoreEnvironmentHelper.GetExistingOrNewSitecoreEnvironment(this.Name); }
}
public virtual SitecoreEnvironment SitecoreEnvironment { get; }

[NotNull]
public virtual Product Product
Expand Down Expand Up @@ -466,6 +464,37 @@ public virtual IReadOnlyCollection<FileInfo> ModulesFiles
}
}

public InstanceType Type
{
get
{
if (Product == Product.Undefined || Product.Release == null)
{
return InstanceType.SitecoreMember;
}

if (Product.Release.Version.MajorMinorInt < 90)
{
return InstanceType.Sitecore8AndEarlier;
}

if (Product.Release.Version.MajorMinorInt >= 90)
{
return InstanceType.Sitecore9AndLater;
}

return InstanceType.Unknown;
}
}

public enum InstanceType
{
Sitecore8AndEarlier,
Sitecore9AndLater,
SitecoreMember,
Unknown
}

#endregion

#region Public methods
Expand Down
93 changes: 70 additions & 23 deletions src/SIM.Instances/InstanceManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
namespace SIM.Instances
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using SIM.Extensions;

namespace SIM.Instances
{
using System;
using System.Collections.Generic;
Expand All @@ -10,13 +15,17 @@
using Sitecore.Diagnostics.Base.Extensions.EnumerableExtensions;
using Sitecore.Diagnostics.Logging;
using SIM.SitecoreEnvironments;
using System.Collections.ObjectModel;

#region

#endregion

public class InstanceManager
{
public InstanceManager()
{
}
#region Fields

private IDictionary<string, Instance> _CachedInstances;
Expand Down Expand Up @@ -91,11 +100,14 @@ private set

public static InstanceManager Default { get; } = new InstanceManager();

public RangeObservableCollection<Instance> InstancesObservableCollection { get; } = new RangeObservableCollection<Instance>();


#endregion

#endregion

#region Public Methods
#region Methods

#region Public methods

Expand Down Expand Up @@ -131,7 +143,8 @@ public void Initialize([CanBeNull] string defaultRootFolder = null)
Instances = GetInstances();
}
}



public void InitializeWithSoftListRefresh([CanBeNull] string defaultRootFolder = null)
{
SitecoreEnvironmentHelper.RefreshEnvironments();
Expand Down Expand Up @@ -160,6 +173,60 @@ public void InitializeWithSoftListRefresh([CanBeNull] string defaultRootFolder =
}
}

public Instance GetInstance(long id)
{
using (new ProfileSection("Get instance by id"))
{
ProfileSection.Argument("id", id);

var instance = new Instance((int)id);

return ProfileSection.Result(instance);
}
}

public void AddNewInstance(string instanceName, bool isSitecore8Instance)
{
using (WebServerManager.WebServerContext context = WebServerManager.CreateContext())
{
SiteCollection sites = context.Sites;
List<Instance> instances = new List<Instance>();

if (isSitecore8Instance)
{

Site site = sites.FirstOrDefault(s => s.Name == instanceName);
if (site != null)
{
instances.Add(new Instance((int)site.Id));
}
}
else
{
SitecoreEnvironment environment =
SitecoreEnvironmentHelper.SitecoreEnvironments.FirstOrDefault(e => e.Name == instanceName);
if (environment != null && environment.Members != null && environment.Members.Count != 0)
{
foreach (var member in environment.Members.Where(x=>x.Type== SitecoreEnvironmentMember.Types.Site.ToString()))
{
Site site = sites.FirstOrDefault(s => s.Name == member.Name);
if (site != null)
{
instances.Add(new Instance((int)site.Id));
}
}
}
}

foreach (var instance in instances)
{
this.InstancesObservableCollection.Add(instance);
this.PartiallyCachedInstances?.Add(instance.Name, instance);
this.Instances = this.Instances.Add(instance);
}
}
}

#endregion

#region Private methods
Expand Down Expand Up @@ -188,12 +255,6 @@ private IDictionary<string, Instance> GetPartiallyCachedInstances(IEnumerable<Si
}
}

#endregion

#endregion

#region Methods

private IEnumerable<Site> GetOperableSites([NotNull] WebServerManager.WebServerContext context, [CanBeNull] string defaultRootFolder = null)
{
Assert.IsNotNull(context, "Context cannot be null");
Expand Down Expand Up @@ -244,20 +305,6 @@ private void OnInstancesListUpdated()

#endregion

#region Public methods

public Instance GetInstance(long id)
{
using (new ProfileSection("Get instance by id"))
{
ProfileSection.Argument("id", id);

var instance = new Instance((int)id);

return ProfileSection.Result(instance);
}
}

#endregion
}
}
2 changes: 1 addition & 1 deletion src/SIM.Products/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Product : IXmlSerializable

private const string ProductNamePattern = @"([a-zA-Z][a-zA-Z\d\-\s\._]*[a-zA-Z])";

private const string ProductRevisionPattern = @"(\d\d\d\d\d\d([\d\w\s_\-\!\(\)]*|[\d\w\s_\-\!\(\)]+\.[\d\w\s_\-\!\(\)]+))"; // @"(\d\d\d\d\d\d)";
private const string ProductRevisionPattern = @"(\d\d\d\d\d\d([\d\w\s_\-\!\(\)]*|[\d\w\s_\-\!\(\)]+\.[\d\w\s_\-\.\!]+\)))";

private const string ProductVersionPattern = @"(\d{1,2}\.\d(\.?\d?))";

Expand Down
1 change: 1 addition & 0 deletions src/SIM.Sitecore9Installer/SIM.Sitecore9Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="Validation\Validators\AppPoolSiteValidator.cs" />
<Compile Include="Validation\Validators\CmDdsPatchSiteNameValidator.cs" />
<Compile Include="Validation\Validators\PathExistsValidator.cs" />
<Compile Include="Validation\Validators\SolrVersionValidator.cs" />
<Compile Include="Validation\Validators\SolrServiceValidator.cs" />
<Compile Include="Validation\Validators\SqlPefixValidator.cs" />
<Compile Include="Validation\Validators\SqlVersionValidator.cs" />
Expand Down
6 changes: 3 additions & 3 deletions src/SIM.Sitecore9Installer/Tasker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,16 @@ private string GetTaskRealName(JProperty taskDefinition)
private void InjectLocalDeploymentRoot(string taskFilePath)
{
JObject doc = JObject.Parse(File.ReadAllText(taskFilePath));
JToken node = doc["Variables"]["Site.PhysicalPath"];
JToken node = doc["Variables"]?["Site.PhysicalPath"];//have to use null propagation since there need not be a variables section at all like in case of SXA-SingleDeveloper.json
if (node != null)
{
JObject deployRoot = new JObject();
deployRoot["Type"] = "string";
deployRoot["Description"] = "The path to installtion root folder.";
deployRoot["Description"] = "The path to installation root folder.";
deployRoot["DefaultValue"] = "";
doc["Parameters"]["DeployRoot"] = deployRoot;

((JValue) node).Value = "[joinpath(parameter('DeployRoot'), parameter('SiteName'))]";
((JValue)node).Value = "[joinpath(parameter('DeployRoot'), parameter('SiteName'))]";

using (StreamWriter wr = new StreamWriter(taskFilePath))
{
Expand Down
Loading

0 comments on commit cc4de25

Please sign in to comment.