Permalink
Browse files

Issue #263 - WIP

  • Loading branch information...
AdamNaj committed Dec 19, 2014
1 parent 69d7e43 commit f16096afc7a0437e2d0210c3c8b42eff400838ee
@@ -124,6 +124,9 @@
<Compile Include="Gutters\GutterStatusRenderer.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\Modules\GetSpeModuleFeature.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\Modules\GetSpeModule.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\UpdatePackages\NewUpdatePackageCommandCommand.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\UpdatePackages\ExportUpdatePackageCommand.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\UpdatePackages\GetUpdatePackageDiffCommandsCommand.cs" />
<Compile Include="PowerShellIntegrations\Modules\IntegrationPoint.cs" />
<Compile Include="PowerShellIntegrations\Settings\TemplateNames.cs" />
<Compile Include="PowerShellIntegrations\SpeTimer.cs" />
@@ -203,7 +206,7 @@
<Compile Include="PowerShellIntegrations\Commandlets\Interactive\ShowResultsCommand.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="PowerShellIntegrations\Commandlets\Packages\InstallUpdatePackageCommand.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\UpdatePackages\InstallUpdatePackageCommand.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\Remoting\ConvertFromCliXmlCommand.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\Remoting\ConvertToCliXmlCommand.cs" />
<Compile Include="PowerShellIntegrations\Commandlets\Scheduler\StartTaskScheduleCommand.cs" />
@@ -27,6 +27,7 @@ public void ProcessRequest(HttpContext context)
!string.IsNullOrEmpty(password) &&
AuthenticationManager.Login(userName, password, false);
authenticated = Context.IsLoggedIn;
Database scriptDb = !authenticated || string.IsNullOrEmpty(scriptDbParam)
? Context.Database
: Database.GetDatabase(scriptDbParam);
@@ -47,10 +48,12 @@ public void ProcessRequest(HttpContext context)
{
String script = scriptItem.Fields[ScriptItemFieldNames.Script].Value;
Item item = Context.Database.GetRootItem();
if (item != null)
session.SetItemLocationContext(item);
if (Context.Database != null)
{
Item item = Context.Database.GetRootItem();
if (item != null)
session.SetItemLocationContext(item);
}
session.SetExecutedScript(scriptItem);
context.Response.ContentType = "text/plain";
@@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Configuration;
using System.Management.Automation;
using System.Xml;
using Cognifide.PowerShell.PowerShellIntegrations.Commandlets.Packages;
using log4net;
using log4net.Config;
using Sitecore.Update;
using Sitecore.Update.Engine;
using Sitecore.Update.Interfaces;
namespace Cognifide.PowerShell.PowerShellIntegrations.Commandlets.UpdatePackages
{
//[Cmdlet(VerbsData.Export, "UpdatePackage")]
public class ExportUpdatePackageCommand : BasePackageCommand
{
private List<ICommand> commands;
[Parameter(Position = 0)]
public string Name { get; set; }
[Parameter(Position = 1, Mandatory = true)]
public ICommand Command { get; set; }
[Parameter(Position = 0)]
public string Path { get; set; }
[Parameter]
public string Readme { get; set; }
[Parameter]
public string LicenseFileName { get; set; }
[Parameter]
public string Tag { get; set; }
protected override void BeginProcessing()
{
commands = new List<ICommand>();
base.BeginProcessing();
}
protected override void EndProcessing()
{
// Use default logger
ILog log = LogManager.GetLogger("root");
XmlConfigurator.Configure((XmlElement) ConfigurationManager.GetSection("log4net"));
PerformInstallAction(
() =>
{
var diff = new DiffInfo(
commands,
string.IsNullOrEmpty(Name) ? "Sitecore PowerShell Extensions Generated Update Package" : Name,
Readme,
Tag);
var fileName = Path;
if (string.IsNullOrEmpty(fileName))
{
fileName = string.Format("{0}.update",Name);
}
if (!System.IO.Path.IsPathRooted(fileName))
{
fileName = FullPackageProjectPath(fileName);
}
PackageGenerator.GeneratePackage(diff, string.Empty, fileName);
});
}
protected override void ProcessRecord()
{
commands.Add(Command);
}
}
}
@@ -0,0 +1,128 @@
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Management.Automation;
using System.Xml;
using Cognifide.PowerShell.PowerShellIntegrations.Commandlets.Packages;
using log4net;
using log4net.Config;
using Sitecore.Update.Commands;
using Sitecore.Update.Configuration;
using Sitecore.Update.Data;
using Sitecore.Update.Interfaces;
namespace Cognifide.PowerShell.PowerShellIntegrations.Commandlets.UpdatePackages
{
//[Cmdlet(VerbsCommon.Get, "UpdatePackageDiffCommands")]
[OutputType(new[] { typeof(ICommand) })]
public class GetUpdatePackageDiffCommandsCommand : BasePackageCommand
{
[Parameter(Position = 0, Mandatory = true)]
public string SourcePath { get; set; }
[Parameter(Position = 0)]
public string TargetPath { get; set; }
protected override void ProcessRecord()
{
// Use default logger
ILog log = LogManager.GetLogger("root");
XmlConfigurator.Configure((XmlElement) ConfigurationManager.GetSection("log4net"));
PerformInstallAction(
() =>
{
var targetManager = Factory.Instance.GetSourceDataManager();
var sourceManager = Factory.Instance.GetTargetDataManager();
sourceManager.SerializationPath = SourcePath;
targetManager.SerializationPath = TargetPath;
IDataIterator sourceDataIterator = sourceManager.ItemIterator;
IDataIterator targetDataIterator = targetManager.ItemIterator;
var engine = new DataEngine();
var commands = new List<ICommand>();
commands.AddRange(GenerateDiff(sourceDataIterator, targetDataIterator));
//if an item is found to be deleted AND added, we can be sure it's a move
var deleteCommands = commands.OfType<DeleteItemCommand>();
var shouldBeUpdateCommands =
commands.OfType<AddItemCommand>()
.Select(a => new
{
Added = a,
Deleted = deleteCommands.FirstOrDefault(d => d.ItemID == a.ItemID)
}).Where(u => u.Deleted != null).ToList();
foreach (var command in shouldBeUpdateCommands)
{
commands.AddRange(command.Deleted.GenerateUpdateCommand(command.Added));
commands.Remove(command.Added);
commands.Remove(command.Deleted);
//now, this one is an assumption, but would go wrong without the assumption anyway: this assumption is in fact safer
//if the itempath of a delete command starts with this delete command, it will be moved along to the new node, not deleted, just leave it alone
commands.RemoveAll(
c =>
c is DeleteItemCommand &&
((DeleteItemCommand) c).ItemPath.StartsWith(command.Deleted.ItemPath));
}
engine.ProcessCommands(ref commands);
WriteObject(commands,true);
});
}
protected static IList<ICommand> GenerateDiff(IDataIterator sourceIterator, IDataIterator targetIterator)
{
List<ICommand> commands = new List<ICommand>();
IDataItem sourceDataItem = sourceIterator.Next();
IDataItem targetDataItem = targetIterator.Next();
while (sourceDataItem != null || targetDataItem != null)
{
int compareResult = Compare(sourceDataItem, targetDataItem);
commands.AddRange((sourceDataItem ?? targetDataItem).GenerateDiff(sourceDataItem, targetDataItem, compareResult));
if (compareResult < 0)
{
sourceDataItem = sourceIterator.Next();
}
else
{
if (compareResult > 0)
{
targetDataItem = targetIterator.Next();
}
else
{
if (compareResult == 0)
{
targetDataItem = targetIterator.Next();
sourceDataItem = sourceIterator.Next();
}
}
}
}
return commands;
}
protected static int Compare(IDataItem sourceItem, IDataItem targetItem)
{
if (sourceItem == null && targetItem == null)
{
return 0;
}
if (sourceItem == null)
{
return 1;
}
if (targetItem == null)
{
return -1;
}
return sourceItem.CompareTo(targetItem);
}
}
}
@@ -2,6 +2,7 @@
using System.Configuration;
using System.Management.Automation;
using System.Xml;
using Cognifide.PowerShell.PowerShellIntegrations.Commandlets.Packages;
using log4net;
using log4net.Config;
using Sitecore.Update;
@@ -10,7 +11,7 @@
using Sitecore.Update.Metadata;
using Sitecore.Update.Utils;
namespace Cognifide.PowerShell.PowerShellIntegrations.Commandlets.Packages
namespace Cognifide.PowerShell.PowerShellIntegrations.Commandlets.UpdatePackages
{
[Cmdlet(VerbsLifecycle.Install, "UpdatePackage")]
[OutputType(new[] {typeof (ContingencyEntry)})]
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Management.Automation;
using System.Xml;
using log4net;
using log4net.Config;
using Sitecore.Update;
using Sitecore.Update.Commands;
using Sitecore.Update.Configuration;
using Sitecore.Update.Data;
using Sitecore.Update.Data.Items;
using Sitecore.Update.Engine;
using Sitecore.Update.Interfaces;
using Sitecore.Update.Installer;
using Sitecore.Update.Installer.Utils;
using Sitecore.Update.Metadata;
using Sitecore.Update.Utils;
namespace Cognifide.PowerShell.PowerShellIntegrations.Commandlets.Packages
{
//[Cmdlet(VerbsCommon.New, "UpdatePackageCommand")]
[OutputType(new[] { typeof(ICommand) })]
public class NewUpdatePackageCommand : BasePackageCommand
{
[Parameter]
public ICommand Command { get; set; }
[Parameter(Position = 0)]
public string Path { get; set; }
[Parameter(Position = 0)]
public string Name { get; set; }
[Parameter]
public string Readme { get; set; }
[Parameter]
public string LicenseFileName { get; set; }
[Parameter]
public string Tag { get; set; }
private List<ICommand> commands;
protected override void BeginProcessing()
{
}
protected override void ProcessRecord()
{
}
}
}
@@ -42,6 +42,24 @@ public override void Process(PreprocessRequestArgs arguments)
WebUtil.RewriteUrl(
new UrlString {Path = "/Console/Services/RemoteScriptCall.ashx", Query = query}.ToString());
}
if (localPath.StartsWith("/-/script/v2"))
{
Assert.ArgumentNotNull(arguments.Context, "context");
Uri url = arguments.Context.Request.Url;
string[] sourceArray = url.LocalPath.TrimStart('/').Split('/');
if (sourceArray.Length < 4)
{
return;
}
int length = sourceArray.Length - 4;
var destinationArray = new string[length];
Array.Copy(sourceArray, 4, destinationArray, 0, length);
string scriptPath = string.Format("/{0}", string.Join("/", destinationArray));
string query = url.Query.TrimStart('?');
query += string.Format("{0}script={1}&sc_database={2}", string.IsNullOrEmpty(query) ? "?" : "&", scriptPath, sourceArray[3]);
WebUtil.RewriteUrl(
new UrlString { Path = "/Console/Services/RemoteScriptCall.ashx", Query = query }.ToString());
}
}
catch (Exception exception)
{
View
@@ -1,7 +1,7 @@
The MIT License (MIT)
=======
Copyright (c) 2010-2013 Adam Najmanowicz
Copyright (c) 2010-2015 Adam Najmanowicz, Michael West, Michael Reynolds
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@@ -19,3 +19,27 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Includes code from Sitecore Courier.
Sitecore Courier License:
=======
The MIT License (MIT) Copyright (c) 2014 Alexander Doroshenko
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN

0 comments on commit f16096a

Please sign in to comment.