Merge pull request #1365 from umbraco/temp-packaging

U4-8670 Ensure the create package system in the back office allows for specifying correct metadata
This commit is contained in:
Warren Buckley
2016-07-07 13:08:19 +01:00
committed by GitHub
19 changed files with 634 additions and 408 deletions

View File

@@ -17,6 +17,35 @@ namespace Umbraco.Core
/// </summary>
public class XmlHelper
{
/// <summary>
/// Creates or sets an attribute on the XmlNode if an Attributes collection is available
/// </summary>
/// <param name="xml"></param>
/// <param name="n"></param>
/// <param name="name"></param>
/// <param name="value"></param>
public static void SetAttribute(XmlDocument xml, XmlNode n, string name, string value)
{
if (xml == null) throw new ArgumentNullException("xml");
if (n == null) throw new ArgumentNullException("n");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
if (n.Attributes == null)
{
return;
}
if (n.Attributes[name] == null)
{
var a = xml.CreateAttribute(name);
a.Value = value;
n.Attributes.Append(a);
}
else
{
n.Attributes[name].Value = value;
}
}
/// <summary>
/// Gets a value indicating whether a specified string contains only xml whitespace characters.
/// </summary>
@@ -338,6 +367,9 @@ namespace Umbraco.Core
/// <returns>a XmlAttribute</returns>
public static XmlAttribute AddAttribute(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (string.IsNullOrEmpty(name)) throw new ArgumentException("Value cannot be null or empty.", "name");
var temp = xd.CreateAttribute(name);
temp.Value = value;
return temp;
@@ -352,11 +384,37 @@ namespace Umbraco.Core
/// <returns>a XmlNode</returns>
public static XmlNode AddTextNode(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
temp.AppendChild(xd.CreateTextNode(value));
return temp;
}
/// <summary>
/// Sets or Creates a text XmlNode with the specified name and value
/// </summary>
/// <param name="xd">The xmldocument.</param>
/// <param name="parent">The node to set or create the child text node on</param>
/// <param name="name">The node name.</param>
/// <param name="value">The node value.</param>
/// <returns>a XmlNode</returns>
public static XmlNode SetTextNode(XmlDocument xd, XmlNode parent, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (parent == null) throw new ArgumentNullException("parent");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
var child = parent.SelectSingleNode(name);
if (child != null)
{
child.InnerText = value;
return child;
}
return AddTextNode(xd, name, value);
}
/// <summary>
/// Creates a cdata XmlNode with the specified name and value
/// </summary>
@@ -366,11 +424,37 @@ namespace Umbraco.Core
/// <returns>A XmlNode</returns>
public static XmlNode AddCDataNode(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
temp.AppendChild(xd.CreateCDataSection(value));
return temp;
}
/// <summary>
/// Sets or Creates a cdata XmlNode with the specified name and value
/// </summary>
/// <param name="xd">The xmldocument.</param>
/// <param name="parent">The node to set or create the child text node on</param>
/// <param name="name">The node name.</param>
/// <param name="value">The node value.</param>
/// <returns>a XmlNode</returns>
public static XmlNode SetCDataNode(XmlDocument xd, XmlNode parent, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (parent == null) throw new ArgumentNullException("parent");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
var child = parent.SelectSingleNode(name);
if (child != null)
{
child.InnerXml = "<![CDATA[" + value + "]]>"; ;
return child;
}
return AddCDataNode(xd, name, value);
}
/// <summary>
/// Gets the value of a XmlNode
/// </summary>

View File

@@ -24,6 +24,15 @@ function packageResource($q, $http, umbDataFormatter, umbRequestHelper) {
'Failed to get installed packages');
},
deleteCreatedPackage: function (packageId) {
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
"packageInstallApiBaseUrl",
"DeleteCreatedPackage", { packageId: packageId })),
'Failed to get installed packages');
},
uninstall: function(packageId) {
return umbRequestHelper.resourcePromise(
$http.post(

View File

@@ -22,22 +22,26 @@ function FormsController($scope, $route, $cookieStore, packageResource) {
$scope.state = "Installng package";
packageResource
.fetch("CD44CF39-3D71-4C19-B6EE-948E1FAF0525")
.then(function(pack){
$scope.state = "importing";
return packageResource.import(pack);
}, $scope.error)
.then(function(pack){
$scope.state = "Installing";
return packageResource.installFiles(pack);
}, $scope.error)
.then(function(pack){
$scope.state = "Restarting, please wait...";
return packageResource.installData(pack);
}, $scope.error)
.then(function(pack){
$scope.state = "All done, your browser will now refresh";
return packageResource.cleanUp(pack);
}, $scope.error)
.then(function(pack) {
$scope.state = "importing";
return packageResource.import(pack);
},
$scope.error)
.then(function(pack) {
$scope.state = "Installing";
return packageResource.installFiles(pack);
},
$scope.error)
.then(function(pack) {
$scope.state = "Restarting, please wait...";
return packageResource.installData(pack);
},
$scope.error)
.then(function(pack) {
$scope.state = "All done, your browser will now refresh";
return packageResource.cleanUp(pack);
},
$scope.error)
.then($scope.complete, $scope.error);
};
@@ -50,6 +54,8 @@ function FormsController($scope, $route, $cookieStore, packageResource) {
$scope.error = function(err){
$scope.state = undefined;
$scope.error = err;
//This will return a rejection meaning that the promise change above will stop
return $q.reject();
};

View File

@@ -0,0 +1,33 @@
/**
* @ngdoc controller
* @name Umbraco.Editors.Packages.DeleteController
* @function
*
* @description
* The controller for deleting content
*/
function PackageDeleteController($scope, packageResource, treeService, navigationService) {
$scope.performDelete = function() {
//mark it for deletion (used in the UI)
$scope.currentNode.loading = true;
packageResource.deleteCreatedPackage($scope.currentNode.id).then(function () {
$scope.currentNode.loading = false;
//get the root node before we remove it
var rootNode = treeService.getTreeRoot($scope.currentNode);
//TODO: Need to sync tree, etc...
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
});
};
$scope.cancel = function() {
navigationService.hideDialog();
};
}
angular.module("umbraco").controller("Umbraco.Editors.Packages.DeleteController", PackageDeleteController);

View File

@@ -0,0 +1,13 @@
<div class="umb-dialog umb-pane" ng-controller="Umbraco.Editors.Packages.DeleteController">
<div class="umb-dialog-body" auto-scale="90">
<p class="umb-abstract">
<localize key="defaultdialogs_confirmdelete">Are you sure you want to delete</localize> <strong>{{currentNode.name}}</strong> ?
</p>
<umb-confirm on-confirm="performDelete" on-cancel="cancel">
</umb-confirm>
</div>
</div>

View File

@@ -1,7 +1,7 @@
(function () {
"use strict";
function PackagesInstallLocalController($scope, $route, $location, Upload, umbRequestHelper, packageResource, $cookieStore, $timeout) {
function PackagesInstallLocalController($scope, $route, $location, Upload, umbRequestHelper, packageResource, $cookieStore, $timeout, $q) {
var vm = this;
vm.state = "upload";
@@ -95,16 +95,11 @@
}
function installPackage() {
vm.installState.status = "Installing";
vm.installState.status = "Importing";
//TODO: If any of these fail, will they keep calling the next one?
packageResource
.installFiles(vm.localPackage)
.then(function(pack) {
vm.installState.status = "Importing...";
return packageResource.import(pack);
},
installError)
.import(vm.localPackage)
.then(function(pack) {
vm.installState.status = "Installing...";
return packageResource.installFiles(pack);
@@ -116,7 +111,7 @@
},
installError)
.then(function(pack) {
vm.installState.status = "All done, your browser will now refresh";
vm.installState.status = "All done, your browser will now refresh, please wait...";
return packageResource.cleanUp(pack);
},
installError)
@@ -135,9 +130,10 @@
},
installError);
}
function installError() {
//TODO: Need to do something about this?
//This will return a rejection meaning that the promise change above will stop
return $q.reject();
}
}

View File

@@ -10,8 +10,8 @@
<div class="umb-package-list__item" ng-repeat="installedPackage in vm.installedPackages">
<div class="umb-package-list__item-icon">
<i ng-if="!installedPackage.icon" class="icon-box"></i>
<img ng-if="installedPackage.icon" ng-src="{{installedPackage.icon}}" />
<i ng-if="!installedPackage.iconUrl" class="icon-box"></i>
<img ng-if="installedPackage.iconUrl" ng-src="{{installedPackage.iconUrl}}" />
</div>
<div class="umb-package-list__item-content">
@@ -45,8 +45,8 @@
<form novalidate name="uninstallForm">
<div class="umb-package-icon">
<i ng-if="!vm.package.icon" class="icon-box"></i>
<img ng-if="vm.package.icon" ng-src="{{vm.package.icon}}" alt="" />
<i ng-if="!vm.package.iconUrl" class="icon-box"></i>
<img ng-if="vm.package.iconUrl" ng-src="{{vm.package.iconUrl}}" alt="" />
</div>

View File

@@ -35,13 +35,28 @@
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" EnableClientScript="false"
ControlToValidate="packageVersion">*</asp:RequiredFieldValidator>
</cc2:PropertyPanel>
<cc2:PropertyPanel runat="server" ID="pp_icon" Text="Package Icon URL">
<asp:TextBox ID="iconUrl" runat="server" Width="230px" CssClass="guiInputText"></asp:TextBox>
</cc2:PropertyPanel>
<cc2:PropertyPanel runat="server" ID="pp_file" Text="Package file (.zip):">
<asp:Button ID="bt_submitButton" runat="server" Text="Submit to repository" Visible="false" />
<asp:Literal ID="packageUmbFile" runat="server" />
</cc2:PropertyPanel>
</cc2:Pane>
<cc2:Pane ID="Pane5" runat="server">
<cc2:PropertyPanel runat="server" ID="pp_umbracoVersion" Text="Umbraco Target Version">
<asp:TextBox ID="umbracoVersion" runat="server" Width="230px" CssClass="guiInputText"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" EnableClientScript="false"
ControlToValidate="umbracoVersion">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="VersionValidator" runat="server" EnableClientScript="false"
ControlToValidate="umbracoVersion" ValidationExpression="^\d+\.\d+\.\d+$">Invalid version number (eg. 7.5.0)</asp:RegularExpressionValidator>
</cc2:PropertyPanel>
</cc2:Pane>
<cc2:Pane ID="Pane1_1" runat="server">
<cc2:PropertyPanel runat="server" ID="pp_author" Text="Author Name">
<cc2:PropertyPanel runat="server" ID="pp_author" Text="Author Name" >
<asp:TextBox ID="packageAuthorName" runat="server" Width="230px" CssClass="guiInputText"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" EnableClientScript="false"
ControlToValidate="packageAuthorName">*</asp:RequiredFieldValidator>
@@ -52,6 +67,7 @@
ControlToValidate="packageAuthorUrl">*</asp:RequiredFieldValidator>
</cc2:PropertyPanel>
</cc2:Pane>
<cc2:Pane ID="Pane1_2" runat="server">
<cc2:PropertyPanel runat="server" ID="pp_licens" Text="License Name:">
<asp:TextBox ID="packageLicenseName" runat="server" Width="230px" CssClass="guiInputText"></asp:TextBox>

View File

@@ -40,6 +40,9 @@ using Settings = umbraco.cms.businesslogic.packager.Settings;
namespace Umbraco.Web.Editors
{
/// <summary>
/// A controller used for installing packages and managing all of the data in the packages section in the back office
/// </summary>
[PluginController("UmbracoApi")]
[UmbracoApplicationAuthorize(Core.Constants.Applications.Developer)]
public class PackageInstallController : UmbracoAuthorizedJsonController
@@ -206,7 +209,6 @@ namespace Umbraco.Web.Editors
global::umbraco.BusinessLogic.Actions.Action.ReRegisterActionsAndHandlers();
}
public IEnumerable<InstalledPackageModel> GetInstalled()
{
return data.GetAllPackages(IOHelper.MapPath(Settings.InstalledPackagesSettings))
@@ -219,10 +221,29 @@ namespace Umbraco.Web.Editors
Url = pack.Url,
License = pack.License,
LicenseUrl = pack.LicenseUrl,
Files = pack.Files
Files = pack.Files,
IconUrl = pack.IconUrl
}).ToList();
}
/// <summary>
/// Deletes a created package
/// </summary>
/// <param name="packageId"></param>
/// <returns></returns>
[HttpPost]
[HttpDelete]
public IHttpActionResult DeleteCreatedPackage(int packageId)
{
var package = CreatedPackage.GetById(packageId);
if (package == null)
return NotFound();
package.Delete();
return Ok();
}
private void PopulateFromPackageData(LocalPackageInstallModel model)
{
var ins = new global::umbraco.cms.businesslogic.packager.Installer(Security.CurrentUser.Id);

View File

@@ -29,5 +29,8 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "licenseUrl")]
public string LicenseUrl { get; set; }
[DataMember(Name = "iconUrl")]
public string IconUrl { get; set; }
}
}

View File

@@ -93,15 +93,22 @@ namespace Umbraco.Web.Trees
{
var menu = new MenuItemCollection();
// Root actions
menu.Items.Add<ActionNew>(Services.TextService.Localize(string.Format("actions/{0}", ActionNew.Instance.Alias)))
.ConvertLegacyMenuItem(null, Constants.Trees.Packages, queryStrings.GetValue<string>("application"));
if (id == "created")
// Root actions
if (id == "-1")
{
menu.Items.Add<ActionNew>(Services.TextService.Localize(string.Format("actions/{0}", ActionNew.Instance.Alias)))
.ConvertLegacyMenuItem(null, Constants.Trees.Packages, queryStrings.GetValue<string>("application"));
}
else if (id == "created")
{
menu.Items.Add<RefreshNode, ActionRefresh>(
Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), true);
}
else
{
//it's a package node
menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
}
return menu;
}

View File

@@ -77,6 +77,8 @@ namespace umbraco.presentation.developer.packages
packageReadme.Text = pack.Readme;
packageVersion.Text = pack.Version;
packageUrl.Text = pack.Url;
iconUrl.Text = pack.IconUrl;
umbracoVersion.Text = pack.UmbracoVersion != null ? pack.UmbracoVersion.ToString(3) : string.Empty;
/*ACTIONS XML*/
tb_actions.Text = pack.Actions;
@@ -253,6 +255,8 @@ namespace umbraco.presentation.developer.packages
pack.Name = packageName.Text;
pack.Url = packageUrl.Text;
pack.Version = packageVersion.Text;
pack.IconUrl = iconUrl.Text;
pack.UmbracoVersion = Version.Parse(umbracoVersion.Text);
pack.ContentLoadChildNodes = packageContentSubdirs.Checked;
@@ -374,9 +378,11 @@ namespace umbraco.presentation.developer.packages
// Tab setup
packageInfo = TabView1.NewTabPage("Package Properties");
packageInfo.Controls.Add(Pane1);
packageInfo.Controls.Add(Pane5);
packageInfo.Controls.Add(Pane1_1);
packageInfo.Controls.Add(Pane1_2);
packageInfo.Controls.Add(Pane1_3);
packageContents = TabView1.NewTabPage("Package Contents");
packageContents.Controls.Add(Pane2);

View File

@@ -38,7 +38,15 @@ namespace umbraco.presentation.developer.packages {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::umbraco.uicontrols.PropertyPanel pp_name;
protected global::umbraco.uicontrols.PropertyPanel pp_icon;
protected global::umbraco.uicontrols.PropertyPanel pp_umbracoVersion;
protected global::System.Web.UI.WebControls.TextBox iconUrl;
protected global::System.Web.UI.WebControls.TextBox umbracoVersion;
protected global::umbraco.uicontrols.Pane Pane5;
protected global::System.Web.UI.WebControls.RegularExpressionValidator VersionValidator;
protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator7;
/// <summary>
/// packageName control.
/// </summary>

View File

@@ -194,15 +194,8 @@ namespace umbraco.cms.businesslogic.packager
// Check if the file is a valid package
if (fi.Extension.ToLower() == ".umb")
{
try
{
tempDir = UnPack(fi.FullName, deleteFile);
LoadConfig(tempDir);
}
catch (Exception unpackE)
{
throw new Exception("Error unpacking extension...", unpackE);
}
tempDir = UnPack(fi.FullName, deleteFile);
LoadConfig(tempDir);
}
else
throw new Exception("Error - file isn't a package (doesn't have a .umb extension). Check if the file automatically got named '.zip' upon download.");
@@ -234,6 +227,7 @@ namespace umbraco.cms.businesslogic.packager
var packReadme = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/readme"));
var packLicense = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/license "));
var packUrl = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/url "));
var iconUrl = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/iconUrl"));
var enableSkins = false;
var skinRepoGuid = "";
@@ -255,6 +249,7 @@ namespace umbraco.cms.businesslogic.packager
insPack.Data.Readme = packReadme;
insPack.Data.License = packLicense;
insPack.Data.Url = packUrl;
insPack.Data.IconUrl = iconUrl;
//skinning
insPack.Data.EnableSkins = enableSkins;
@@ -285,31 +280,22 @@ namespace umbraco.cms.businesslogic.packager
foreach (XmlNode n in Config.DocumentElement.SelectNodes("//file"))
{
//we enclose the whole file-moving to ensure that the entire installer doesn't crash
try
{
var destPath = GetFileName(basePath, XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")));
var sourceFile = GetFileName(tempDir, XmlHelper.GetNodeValue(n.SelectSingleNode("guid")));
var destFile = GetFileName(destPath, XmlHelper.GetNodeValue(n.SelectSingleNode("orgName")));
var destPath = GetFileName(basePath, XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")));
var sourceFile = GetFileName(tempDir, XmlHelper.GetNodeValue(n.SelectSingleNode("guid")));
var destFile = GetFileName(destPath, XmlHelper.GetNodeValue(n.SelectSingleNode("orgName")));
// Create the destination directory if it doesn't exist
if (Directory.Exists(destPath) == false)
Directory.CreateDirectory(destPath);
//If a file with this name exists, delete it
else if (File.Exists(destFile))
File.Delete(destFile);
// Create the destination directory if it doesn't exist
if (Directory.Exists(destPath) == false)
Directory.CreateDirectory(destPath);
//If a file with this name exists, delete it
else if (File.Exists(destFile))
File.Delete(destFile);
// Move the file
File.Move(sourceFile, destFile);
// Move the file
File.Move(sourceFile, destFile);
//PPH log file install
insPack.Data.Files.Add(XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")) + "/" + XmlHelper.GetNodeValue(n.SelectSingleNode("orgName")));
}
catch (Exception ex)
{
LogHelper.Error<Installer>("Package install error", ex);
}
//PPH log file install
insPack.Data.Files.Add(XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")) + "/" + XmlHelper.GetNodeValue(n.SelectSingleNode("orgName")));
}
// log that a user has install files
@@ -527,7 +513,7 @@ namespace umbraco.cms.businesslogic.packager
RequirementsType = reqNode != null && reqNode.Attributes != null && reqNode.Attributes["type"] != null
? Enum<RequirementsType>.Parse(reqNode.Attributes["type"].Value, true)
: RequirementsType.Legacy;
var iconNode = Config.DocumentElement.SelectSingleNode("/umbPackage/info/author/iconUrl");
var iconNode = Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/iconUrl");
if (iconNode != null)
{
IconUrl = iconNode.FirstChild.Value;
@@ -638,17 +624,17 @@ namespace umbraco.cms.businesslogic.packager
}
}
try
var readmeNode = Config.DocumentElement.SelectSingleNode("/umbPackage/info/readme");
if (readmeNode != null)
{
ReadMe = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/readme"));
ReadMe = XmlHelper.GetNodeValue(readmeNode);
}
catch { }
try
var controlNode = Config.DocumentElement.SelectSingleNode("/umbPackage/control");
if (controlNode != null)
{
Control = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/control"));
Control = XmlHelper.GetNodeValue(controlNode);
}
catch { }
}
/// <summary>

View File

@@ -1,10 +1,13 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using umbraco.BusinessLogic;
using umbraco.DataLayer;
namespace umbraco.cms.businesslogic.packager
{
[Obsolete("This class is not used and will be removed in future versions")]
[EditorBrowsable(EditorBrowsableState.Never)]
public class Package
{
protected static ISqlHelper SqlHelper

View File

@@ -32,8 +32,10 @@ namespace umbraco.cms.businesslogic.packager
public static CreatedPackage MakeNew(string name)
{
var pack = new CreatedPackage();
pack.Data = data.MakeNew(name, IOHelper.MapPath(Settings.CreatedPackagesSettings));
var pack = new CreatedPackage
{
Data = data.MakeNew(name, IOHelper.MapPath(Settings.CreatedPackagesSettings))
};
var e = new NewEventArgs();
pack.OnNew(e);

View File

@@ -6,89 +6,96 @@ using System.Collections.Generic;
namespace umbraco.cms.businesslogic.packager
{
public class PackageInstance
public class PackageInstance
{
public int Id { get; set; }
public int Id { get; set; }
public string RepositoryGuid { get; set; }
public string RepositoryGuid { get; set; }
public string PackageGuid { get; set; }
public string PackageGuid { get; set; }
public bool HasUpdate { get; set; }
public bool HasUpdate { get; set; }
public bool EnableSkins { get; set; }
public bool EnableSkins { get; set; }
public Guid SkinRepoGuid { get; set; }
public Guid SkinRepoGuid { get; set; }
public string Name { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public string Url { get; set; }
public string Folder { get; set; }
public string Folder { get; set; }
public string PackagePath { get; set; }
public string PackagePath { get; set; }
public string Version { get; set; }
public string Version { get; set; }
/// <summary>
/// The minimum umbraco version that this package requires
/// </summary>
public Version UmbracoVersion { get; set; }
public string Author { get; set; }
public string Author { get; set; }
public string AuthorUrl { get; set; }
public string AuthorUrl { get; set; }
public string License { get; set; }
public string License { get; set; }
public string LicenseUrl { get; set; }
public string LicenseUrl { get; set; }
public string Readme { get; set; }
public string Readme { get; set; }
public bool ContentLoadChildNodes { get; set; }
public bool ContentLoadChildNodes { get; set; }
public string ContentNodeId { get; set; }
public string ContentNodeId { get; set; }
public List<string> Macros { get; set; }
public List<string> Macros { get; set; }
public List<string> Languages { get; set; }
public List<string> Languages { get; set; }
public List<string> DictionaryItems { get; set; }
public List<string> DictionaryItems { get; set; }
public List<string> Templates { get; set; }
public List<string> Templates { get; set; }
public List<string> Documenttypes { get; set; }
public List<string> Documenttypes { get; set; }
public List<string> Stylesheets { get; set; }
public List<string> Stylesheets { get; set; }
public List<string> Files { get; set; }
public List<string> Files { get; set; }
public string LoadControl { get; set; }
public string LoadControl { get; set; }
public string Actions { get; set; }
public string Actions { get; set; }
public List<string> DataTypes { get; set; }
public List<string> DataTypes { get; set; }
public string IconUrl { get; set; }
public PackageInstance()
public PackageInstance()
{
SkinRepoGuid = Guid.Empty;
Name = "";
Url = "";
Folder = "";
PackagePath = "";
Version = "";
Author = "";
AuthorUrl = "";
License = "";
LicenseUrl = "";
Readme = "";
ContentNodeId = "";
Macros = new List<string>();
Languages = new List<string>();
DictionaryItems = new List<string>();
Templates = new List<string>();
Documenttypes = new List<string>();
Stylesheets = new List<string>();
Files = new List<string>();
LoadControl = "";
DataTypes = new List<string>();
SkinRepoGuid = Guid.Empty;
Name = string.Empty;
Url = string.Empty;
Folder = string.Empty;
PackagePath = string.Empty;
Version = string.Empty;
UmbracoVersion = null;
Author = string.Empty;
AuthorUrl = string.Empty;
License = string.Empty;
LicenseUrl = string.Empty;
Readme = string.Empty;
ContentNodeId = string.Empty;
IconUrl = string.Empty;
Macros = new List<string>();
Languages = new List<string>();
DictionaryItems = new List<string>();
Templates = new List<string>();
Documenttypes = new List<string>();
Stylesheets = new List<string>();
Files = new List<string>();
LoadControl = string.Empty;
DataTypes = new List<string>();
EnableSkins = false;
ContentLoadChildNodes = false;
}

View File

@@ -18,6 +18,7 @@ using umbraco.cms.businesslogic.template;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.macro;
using ICSharpCode.SharpZipLib.Zip;
using Umbraco.Core;
using Umbraco.Core.IO;
namespace umbraco.cms.businesslogic.packager {
@@ -41,17 +42,19 @@ namespace umbraco.cms.businesslogic.packager {
XmlNode package = doc.CreateElement("package");
package.AppendChild(_node("name", pack.Name, doc));
package.AppendChild(_node("version", pack.Version, doc));
package.AppendChild(_node("iconUrl", pack.IconUrl, doc));
XmlNode license = _node("license", pack.License, doc);
license.Attributes.Append(_attribute("url", pack.LicenseUrl, doc));
package.AppendChild(license);
package.AppendChild(_node("url", pack.Url, doc));
XmlNode Requirements = doc.CreateElement("requirements");
Requirements.AppendChild(_node("major", "3", doc));
Requirements.AppendChild(_node("minor", "0", doc));
Requirements.AppendChild(_node("patch", "0", doc));
//NOTE: The defaults are 3.0.0 - I'm just leaving that here since that's the way it's been //SD
Requirements.AppendChild(_node("major", pack.UmbracoVersion == null ? "3" : pack.UmbracoVersion.Major.ToInvariantString(), doc));
Requirements.AppendChild(_node("minor", pack.UmbracoVersion == null ? "0" : pack.UmbracoVersion.Minor.ToInvariantString(), doc));
Requirements.AppendChild(_node("patch", pack.UmbracoVersion == null ? "0" : pack.UmbracoVersion.Build.ToInvariantString(), doc));
package.AppendChild(Requirements);
info.AppendChild(package);

View File

@@ -4,20 +4,24 @@ using System.Xml.XPath;
using System.Collections.Generic;
using System.IO;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
namespace umbraco.cms.businesslogic.packager
{
/// <summary>
/// This is the xml data for installed packages. This is not the same xml as a pckage format!
/// </summary>
public class data
{
private static XmlDocument _source;
public static XmlDocument Source
{
get
{
return _source;
return _source;
}
}
@@ -39,46 +43,49 @@ namespace umbraco.cms.businesslogic.packager
Directory.CreateDirectory(IOHelper.MapPath(Settings.InstalledPackagesStorage));
}
StreamWriter sw = File.CreateText(dataSource);
sw.Write(umbraco.cms.businesslogic.Packager.FileResources.PackageFiles.Packages);
sw.Flush();
sw.Close();
using (StreamWriter sw = File.CreateText(dataSource))
{
sw.Write(umbraco.cms.businesslogic.Packager.FileResources.PackageFiles.Packages);
sw.Flush();
}
}
if (_source == null)
{
_source = new XmlDocument();
_source = new XmlDocument();
}
//error checking here
if (File.Exists(dataSource))
{
var isEmpty = false;
using (var sr = new StreamReader(dataSource))
{
if (sr.ReadToEnd().IsNullOrWhiteSpace())
{
isEmpty = true;
}
}
if (isEmpty)
{
File.WriteAllText(dataSource, @"<?xml version=""1.0"" encoding=""utf-8""?><packages></packages>");
}
}
//error checking here
if (File.Exists(dataSource))
{
var isEmpty = false;
using (var sr = new StreamReader(dataSource))
{
if (sr.ReadToEnd().IsNullOrWhiteSpace())
{
isEmpty = true;
}
}
if (isEmpty)
{
File.WriteAllText(dataSource, @"<?xml version=""1.0"" encoding=""utf-8""?><packages></packages>");
}
}
_source.Load(dataSource);
}
public static XmlNode GetFromId(int Id, string dataSource, bool reload)
{
if(reload)
if (reload)
Reload(dataSource);
return Source.SelectSingleNode("/packages/package [@id = '" + Id.ToString().ToUpper() + "']");
}
public static XmlNode GetFromGuid(string guid, string dataSource, bool reload) {
public static XmlNode GetFromGuid(string guid, string dataSource, bool reload)
{
if (reload)
Reload(dataSource);
@@ -87,301 +94,317 @@ namespace umbraco.cms.businesslogic.packager
public static PackageInstance MakeNew(string Name, string dataSource)
{
PackageInstance retVal = new PackageInstance();
Reload(dataSource);
try
int maxId = 1;
// Find max id
foreach (XmlNode n in Source.SelectNodes("packages/package"))
{
Reload(dataSource);
int _maxId = 1;
// Find max id
foreach (XmlNode n in Source.SelectNodes("packages/package"))
{
if (int.Parse(n.Attributes.GetNamedItem("id").Value) >= _maxId)
_maxId = int.Parse(n.Attributes.GetNamedItem("id").Value) + 1;
}
XmlElement instance = Source.CreateElement("package");
instance.Attributes.Append(xmlHelper.addAttribute(Source, "id", _maxId.ToString()));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "version", ""));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "url", ""));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "name", Name));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "folder", System.Guid.NewGuid().ToString()));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "packagepath", ""));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "repositoryGuid", ""));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "packageGuid", System.Guid.NewGuid().ToString()));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "hasUpdate", "false"));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "enableSkins", "false"));
instance.Attributes.Append(xmlHelper.addAttribute(Source, "skinRepoGuid", ""));
XmlElement license = Source.CreateElement("license");
license.InnerText = "MIT License";
license.Attributes.Append(xmlHelper.addAttribute(Source, "url", "http://opensource.org/licenses/MIT"));
instance.AppendChild(license);
XmlElement author = Source.CreateElement("author");
author.InnerText = "";
author.Attributes.Append(xmlHelper.addAttribute(Source, "url", ""));
instance.AppendChild(author);
instance.AppendChild(xmlHelper.addTextNode(Source, "readme", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "actions", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "datatypes", ""));
XmlElement content = Source.CreateElement("content");
content.InnerText = "";
content.Attributes.Append(xmlHelper.addAttribute(Source, "nodeId", ""));
content.Attributes.Append(xmlHelper.addAttribute(Source, "loadChildNodes", "false"));
instance.AppendChild(content);
instance.AppendChild(xmlHelper.addTextNode(Source, "templates", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "stylesheets", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "documenttypes", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "macros", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "files", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "languages", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "dictionaryitems", ""));
instance.AppendChild(xmlHelper.addTextNode(Source, "loadcontrol", ""));
Source.SelectSingleNode("packages").AppendChild(instance);
Source.Save(dataSource);
retVal = data.Package(_maxId, dataSource);
}
catch (Exception ex)
{
LogHelper.Error<data>("An error occurred", ex);
if (int.Parse(n.Attributes.GetNamedItem("id").Value) >= maxId)
maxId = int.Parse(n.Attributes.GetNamedItem("id").Value) + 1;
}
XmlElement instance = Source.CreateElement("package");
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "id", maxId.ToString()));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "version", ""));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "url", ""));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "name", Name));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "folder", Guid.NewGuid().ToString()));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "packagepath", ""));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "repositoryGuid", ""));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "iconUrl", ""));
//set to current version
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "umbVersion", UmbracoVersion.Current.ToString(3)));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "packageGuid", Guid.NewGuid().ToString()));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "hasUpdate", "false"));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "enableSkins", "false"));
instance.Attributes.Append(XmlHelper.AddAttribute(Source, "skinRepoGuid", ""));
XmlElement license = Source.CreateElement("license");
license.InnerText = "MIT License";
license.Attributes.Append(XmlHelper.AddAttribute(Source, "url", "http://opensource.org/licenses/MIT"));
instance.AppendChild(license);
XmlElement author = Source.CreateElement("author");
author.InnerText = "";
author.Attributes.Append(XmlHelper.AddAttribute(Source, "url", ""));
instance.AppendChild(author);
instance.AppendChild(XmlHelper.AddTextNode(Source, "readme", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "actions", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "datatypes", ""));
XmlElement content = Source.CreateElement("content");
content.InnerText = "";
content.Attributes.Append(XmlHelper.AddAttribute(Source, "nodeId", ""));
content.Attributes.Append(XmlHelper.AddAttribute(Source, "loadChildNodes", "false"));
instance.AppendChild(content);
instance.AppendChild(XmlHelper.AddTextNode(Source, "templates", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "stylesheets", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "documenttypes", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "macros", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "files", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "languages", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "dictionaryitems", ""));
instance.AppendChild(XmlHelper.AddTextNode(Source, "loadcontrol", ""));
Source.SelectSingleNode("packages").AppendChild(instance);
Source.Save(dataSource);
var retVal = data.Package(maxId, dataSource);
return retVal;
}
public static PackageInstance Package(int id, string datasource) {
return ConvertXmlToPackage( GetFromId(id, datasource, true) );
public static PackageInstance Package(int id, string datasource)
{
return ConvertXmlToPackage(GetFromId(id, datasource, true));
}
public static PackageInstance Package(string guid, string datasource) {
try
{
XmlNode node = GetFromGuid(guid, datasource, true);
if (node != null)
return ConvertXmlToPackage(node);
else
return new PackageInstance();
}
catch (Exception ex)
{
LogHelper.Error<data>("An error occurred", ex);
return new PackageInstance();
}
public static PackageInstance Package(string guid, string datasource)
{
XmlNode node = GetFromGuid(guid, datasource, true);
if (node != null)
return ConvertXmlToPackage(node);
else
return new PackageInstance();
}
public static List<PackageInstance> GetAllPackages(string dataSource) {
public static List<PackageInstance> GetAllPackages(string dataSource)
{
Reload(dataSource);
XmlNodeList nList = data.Source.SelectNodes("packages/package");
List<PackageInstance> retVal = new List<PackageInstance>();
for (int i = 0; i < nList.Count; i++)
{
try
{
retVal.Add(ConvertXmlToPackage(nList[i]));
}
catch (Exception ex)
{
LogHelper.Error<data>("An error occurred in GetAllPackages", ex);
}
}
return retVal;
}
private static PackageInstance ConvertXmlToPackage(XmlNode n) {
PackageInstance retVal = new PackageInstance();
if (n != null) {
retVal.Id = int.Parse(safeAttribute("id",n));
retVal.Name = safeAttribute("name",n);
retVal.Folder = safeAttribute("folder", n);
retVal.PackagePath = safeAttribute("packagepath", n);
retVal.Version = safeAttribute("version", n);
retVal.Url = safeAttribute("url", n);
retVal.RepositoryGuid = safeAttribute("repositoryGuid", n);
retVal.PackageGuid = safeAttribute("packageGuid", n);
retVal.HasUpdate = bool.Parse(safeAttribute("hasUpdate",n));
bool _enableSkins = false;
bool.TryParse(safeAttribute("enableSkins", n), out _enableSkins);
retVal.EnableSkins = _enableSkins;
retVal.SkinRepoGuid = string.IsNullOrEmpty(safeAttribute("skinRepoGuid", n)) ? Guid.Empty : new Guid(safeAttribute("skinRepoGuid", n));
retVal.License = safeNodeValue(n.SelectSingleNode("license"));
retVal.LicenseUrl = n.SelectSingleNode("license").Attributes.GetNamedItem("url").Value;
retVal.Author = safeNodeValue(n.SelectSingleNode("author"));
retVal.AuthorUrl = safeAttribute("url", n.SelectSingleNode("author"));
retVal.Readme = safeNodeValue(n.SelectSingleNode("readme"));
retVal.Actions = safeNodeInnerXml(n.SelectSingleNode("actions"));
retVal.ContentNodeId = safeAttribute("nodeId", n.SelectSingleNode("content"));
retVal.ContentLoadChildNodes = bool.Parse(safeAttribute("loadChildNodes",n.SelectSingleNode("content")));
retVal.Macros = new List<string>(safeNodeValue(n.SelectSingleNode("macros")).Trim(',').Split(','));
retVal.Macros = new List<string>(safeNodeValue(n.SelectSingleNode("macros")).Trim(',').Split(','));
retVal.Templates = new List<string>(safeNodeValue(n.SelectSingleNode("templates")).Trim(',').Split(','));
retVal.Stylesheets = new List<string>(safeNodeValue(n.SelectSingleNode("stylesheets")).Trim(',').Split(','));
retVal.Documenttypes = new List<string>(safeNodeValue(n.SelectSingleNode("documenttypes")).Trim(',').Split(','));
retVal.Languages = new List<string>(safeNodeValue(n.SelectSingleNode("languages")).Trim(',').Split(','));
retVal.DictionaryItems = new List<string>(safeNodeValue(n.SelectSingleNode("dictionaryitems")).Trim(',').Split(','));
retVal.DataTypes = new List<string>(safeNodeValue(n.SelectSingleNode("datatypes")).Trim(',').Split(','));
XmlNodeList xmlFiles = n.SelectNodes("files/file");
retVal.Files = new List<string>();
for (int i = 0; i < xmlFiles.Count; i++)
retVal.Files.Add(xmlFiles[i].InnerText);
retVal.LoadControl = safeNodeValue(n.SelectSingleNode("loadcontrol"));
for (int i = 0; i < nList.Count; i++)
{
try
{
retVal.Add(ConvertXmlToPackage(nList[i]));
}
catch (Exception ex)
{
LogHelper.Error<data>("An error occurred in GetAllPackages", ex);
}
}
return retVal;
}
public static void Delete(int Id, string dataSource)
{
private static PackageInstance ConvertXmlToPackage(XmlNode n)
{
PackageInstance retVal = new PackageInstance();
if (n != null)
{
retVal.Id = int.Parse(SafeAttribute("id", n));
retVal.Name = SafeAttribute("name", n);
retVal.Folder = SafeAttribute("folder", n);
retVal.PackagePath = SafeAttribute("packagepath", n);
retVal.Version = SafeAttribute("version", n);
retVal.Url = SafeAttribute("url", n);
retVal.RepositoryGuid = SafeAttribute("repositoryGuid", n);
retVal.PackageGuid = SafeAttribute("packageGuid", n);
retVal.HasUpdate = bool.Parse(SafeAttribute("hasUpdate", n));
retVal.IconUrl = SafeAttribute("iconUrl", n);
var umbVersion = SafeAttribute("umbVersion", n);
Version parsedVersion;
if (umbVersion.IsNullOrWhiteSpace() == false && Version.TryParse(umbVersion, out parsedVersion))
{
retVal.UmbracoVersion = parsedVersion;
}
bool enableSkins = false;
bool.TryParse(SafeAttribute("enableSkins", n), out enableSkins);
retVal.EnableSkins = enableSkins;
retVal.SkinRepoGuid = string.IsNullOrEmpty(SafeAttribute("skinRepoGuid", n)) ? Guid.Empty : new Guid(SafeAttribute("skinRepoGuid", n));
retVal.License = SafeNodeValue(n.SelectSingleNode("license"));
retVal.LicenseUrl = n.SelectSingleNode("license").Attributes.GetNamedItem("url").Value;
retVal.Author = SafeNodeValue(n.SelectSingleNode("author"));
retVal.AuthorUrl = SafeAttribute("url", n.SelectSingleNode("author"));
retVal.Readme = SafeNodeValue(n.SelectSingleNode("readme"));
retVal.Actions = SafeNodeInnerXml(n.SelectSingleNode("actions"));
retVal.ContentNodeId = SafeAttribute("nodeId", n.SelectSingleNode("content"));
retVal.ContentLoadChildNodes = bool.Parse(SafeAttribute("loadChildNodes", n.SelectSingleNode("content")));
retVal.Macros = new List<string>(SafeNodeValue(n.SelectSingleNode("macros")).Trim(',').Split(','));
retVal.Macros = new List<string>(SafeNodeValue(n.SelectSingleNode("macros")).Trim(',').Split(','));
retVal.Templates = new List<string>(SafeNodeValue(n.SelectSingleNode("templates")).Trim(',').Split(','));
retVal.Stylesheets = new List<string>(SafeNodeValue(n.SelectSingleNode("stylesheets")).Trim(',').Split(','));
retVal.Documenttypes = new List<string>(SafeNodeValue(n.SelectSingleNode("documenttypes")).Trim(',').Split(','));
retVal.Languages = new List<string>(SafeNodeValue(n.SelectSingleNode("languages")).Trim(',').Split(','));
retVal.DictionaryItems = new List<string>(SafeNodeValue(n.SelectSingleNode("dictionaryitems")).Trim(',').Split(','));
retVal.DataTypes = new List<string>(SafeNodeValue(n.SelectSingleNode("datatypes")).Trim(',').Split(','));
XmlNodeList xmlFiles = n.SelectNodes("files/file");
retVal.Files = new List<string>();
for (int i = 0; i < xmlFiles.Count; i++)
retVal.Files.Add(xmlFiles[i].InnerText);
retVal.LoadControl = SafeNodeValue(n.SelectSingleNode("loadcontrol"));
}
return retVal;
}
public static void Delete(int Id, string dataSource)
{
Reload(dataSource);
// Remove physical xml file if any
// Remove physical xml file if any
//PackageInstance p = new PackageInstance(Id);
//TODO DELETE PACKAGE FOLDER...
//p.Folder
XmlNode n = data.GetFromId(Id, dataSource, true);
XmlNode n = data.GetFromId(Id, dataSource, true);
if (n != null)
{
data.Source.SelectSingleNode("/packages").RemoveChild(n);
data.Source.Save(dataSource);
data.Source.Save(dataSource);
}
}
public static void UpdateValue(XmlNode n, string Value)
{
if (n.FirstChild != null)
n.FirstChild.Value = Value;
else
{
}
public static void UpdateValue(XmlNode n, string Value)
{
if (n.FirstChild != null)
n.FirstChild.Value = Value;
else
{
n.AppendChild(Source.CreateTextNode(Value));
}
//Save();
}
public static void Save(PackageInstance package, string dataSource)
{
try
{
Reload(dataSource);
XmlNode _xmlDef = GetFromId(package.Id, dataSource, false);
_xmlDef.Attributes.GetNamedItem("name").Value = package.Name;
_xmlDef.Attributes.GetNamedItem("version").Value = package.Version;
_xmlDef.Attributes.GetNamedItem("url").Value = package.Url;
_xmlDef.Attributes.GetNamedItem("packagepath").Value = package.PackagePath;
_xmlDef.Attributes.GetNamedItem("repositoryGuid").Value = package.RepositoryGuid;
_xmlDef.Attributes.GetNamedItem("packageGuid").Value = package.PackageGuid;
_xmlDef.Attributes.GetNamedItem("hasUpdate").Value = package.HasUpdate.ToString();
_xmlDef.Attributes.GetNamedItem("enableSkins").Value = package.EnableSkins.ToString();
_xmlDef.Attributes.GetNamedItem("skinRepoGuid").Value = package.SkinRepoGuid.ToString();
_xmlDef.SelectSingleNode("license").FirstChild.Value = package.License;
_xmlDef.SelectSingleNode("license").Attributes.GetNamedItem("url").Value = package.LicenseUrl;
_xmlDef.SelectSingleNode("author").InnerText = package.Author;
_xmlDef.SelectSingleNode("author").Attributes.GetNamedItem("url").Value = package.AuthorUrl;
_xmlDef.SelectSingleNode("readme").InnerXml = "<![CDATA[" + package.Readme + "]]>";
if(_xmlDef.SelectSingleNode("actions") == null)
_xmlDef.AppendChild(xmlHelper.addTextNode(Source, "actions", ""));
_xmlDef.SelectSingleNode("actions").InnerXml = package.Actions;
_xmlDef.SelectSingleNode("content").Attributes.GetNamedItem("nodeId").Value = package.ContentNodeId.ToString();
_xmlDef.SelectSingleNode("content").Attributes.GetNamedItem("loadChildNodes").Value = package.ContentLoadChildNodes.ToString();
_xmlDef.SelectSingleNode("macros").InnerText = joinList(package.Macros, ',');
_xmlDef.SelectSingleNode("templates").InnerText = joinList(package.Templates, ',');
_xmlDef.SelectSingleNode("stylesheets").InnerText = joinList(package.Stylesheets, ',');
_xmlDef.SelectSingleNode("documenttypes").InnerText = joinList(package.Documenttypes, ',');
_xmlDef.SelectSingleNode("languages").InnerText = joinList(package.Languages, ',');
_xmlDef.SelectSingleNode("dictionaryitems").InnerText = joinList(package.DictionaryItems, ',');
_xmlDef.SelectSingleNode("datatypes").InnerText = joinList(package.DataTypes, ',');
_xmlDef.SelectSingleNode("files").InnerXml = "";
foreach (string fileStr in package.Files) {
if(!string.IsNullOrEmpty(fileStr.Trim()))
_xmlDef.SelectSingleNode("files").AppendChild(xmlHelper.addTextNode(data.Source, "file", fileStr));
}
_xmlDef.SelectSingleNode("loadcontrol").InnerText = package.LoadControl;
Source.Save(dataSource);
}
catch(Exception F)
{
LogHelper.Error<data>("An error occurred", F);
}
}
//Save();
}
private static string safeAttribute(string name, XmlNode n) {
try {
return n.Attributes.GetNamedItem(name).Value;
} catch {
return "";
public static void Save(PackageInstance package, string dataSource)
{
Reload(dataSource);
var xmlDef = GetFromId(package.Id, dataSource, false);
XmlHelper.SetAttribute(Source, xmlDef, "name", package.Name);
XmlHelper.SetAttribute(Source, xmlDef, "version", package.Version);
XmlHelper.SetAttribute(Source, xmlDef, "url", package.Url);
XmlHelper.SetAttribute(Source, xmlDef, "packagepath", package.PackagePath);
XmlHelper.SetAttribute(Source, xmlDef, "repositoryGuid", package.RepositoryGuid);
XmlHelper.SetAttribute(Source, xmlDef, "packageGuid", package.PackageGuid);
XmlHelper.SetAttribute(Source, xmlDef, "hasUpdate", package.HasUpdate.ToString());
XmlHelper.SetAttribute(Source, xmlDef, "enableSkins", package.EnableSkins.ToString());
XmlHelper.SetAttribute(Source, xmlDef, "skinRepoGuid", package.SkinRepoGuid.ToString());
XmlHelper.SetAttribute(Source, xmlDef, "iconUrl", package.IconUrl);
XmlHelper.SetAttribute(Source, xmlDef, "umbVersion", package.UmbracoVersion.ToString(3));
var licenseNode = xmlDef.SelectSingleNode("license");
if (licenseNode == null)
{
licenseNode = Source.CreateElement("license");
xmlDef.AppendChild(licenseNode);
}
licenseNode.InnerText = package.License;
XmlHelper.SetAttribute(Source, licenseNode, "url", package.LicenseUrl);
var authorNode = xmlDef.SelectSingleNode("author");
if (authorNode == null)
{
authorNode = Source.CreateElement("author");
xmlDef.AppendChild(authorNode);
}
authorNode.InnerText = package.Author;
XmlHelper.SetAttribute(Source, authorNode, "url", package.AuthorUrl);
XmlHelper.SetCDataNode(Source, xmlDef, "readme", package.Readme);
XmlHelper.SetTextNode(Source, xmlDef, "actions", package.Actions);
var contentNode = xmlDef.SelectSingleNode("content");
if (contentNode == null)
{
contentNode = Source.CreateElement("content");
xmlDef.AppendChild(contentNode);
}
XmlHelper.SetAttribute(Source, contentNode, "nodeId", package.ContentNodeId);
XmlHelper.SetAttribute(Source, contentNode, "loadChildNodes", package.ContentLoadChildNodes.ToString());
XmlHelper.SetTextNode(Source, xmlDef, "macros", JoinList(package.Macros, ','));
XmlHelper.SetTextNode(Source, xmlDef, "templates", JoinList(package.Templates, ','));
XmlHelper.SetTextNode(Source, xmlDef, "stylesheets", JoinList(package.Stylesheets, ','));
XmlHelper.SetTextNode(Source, xmlDef, "documenttypes", JoinList(package.Documenttypes, ','));
XmlHelper.SetTextNode(Source, xmlDef, "languages", JoinList(package.Languages, ','));
XmlHelper.SetTextNode(Source, xmlDef, "dictionaryitems", JoinList(package.DictionaryItems, ','));
XmlHelper.SetTextNode(Source, xmlDef, "datatypes", JoinList(package.DataTypes, ','));
var filesNode = xmlDef.SelectSingleNode("files");
if (filesNode == null)
{
filesNode = Source.CreateElement("files");
xmlDef.AppendChild(filesNode);
}
filesNode.InnerXml = "";
foreach (var fileStr in package.Files)
{
if (string.IsNullOrWhiteSpace(fileStr) == false)
filesNode.AppendChild(XmlHelper.AddTextNode(Source, "file", fileStr));
}
XmlHelper.SetTextNode(Source, xmlDef, "loadcontrol", package.LoadControl);
Source.Save(dataSource);
}
private static string SafeAttribute(string name, XmlNode n)
{
return n.Attributes == null || n.Attributes[name] == null ? string.Empty : n.Attributes[name].Value;
}
private static string SafeNodeValue(XmlNode n)
{
try
{
return XmlHelper.GetNodeValue(n);
}
catch
{
return string.Empty;
}
}
private static string safeNodeValue(XmlNode n) {
try {
return xmlHelper.GetNodeValue(n);
} catch {
return "";
}
}
private static string safeNodeInnerXml(XmlNode n) {
try {
private static string SafeNodeInnerXml(XmlNode n)
{
try
{
return n.InnerXml;
} catch {
return "";
}
catch
{
return string.Empty;
}
}
private static string joinList(List<string> list, char seperator) {
private static string JoinList(List<string> list, char seperator)
{
string retVal = "";
foreach (string str in list) {
retVal += str + seperator.ToString();
foreach (string str in list)
{
retVal += str + seperator;
}
return retVal.Trim(seperator);
}
public data()
{
public data()
{
}
}
}
}