Skip to content

Commit

Permalink
Merge branch 'feature/appupdater' into 2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
muratcakir committed May 5, 2014
2 parents 8401e3a + bbbe5e4 commit 721bd61
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 29 deletions.
4 changes: 2 additions & 2 deletions SmartStoreNET.Tasks.Targets
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
<Delete Files="$(StageFolder)\Administration\packages.config; $(StageFolder)\packages.config"/>

<!-- copy \Media\uploaded\ folder to stage -->
<RemoveDir Directories="$(StageFolder)\Media\uploaded\" />
<Copy SourceFiles="@(UploadedImages)" DestinationFolder="$(StageFolder)\Media\uploaded\%(RecursiveDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
<!--<RemoveDir Directories="$(StageFolder)\Media\uploaded\" />
<Copy SourceFiles="@(UploadedImages)" DestinationFolder="$(StageFolder)\Media\uploaded\%(RecursiveDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />-->

<!-- copy SQL Compact native binaries-->
<Copy SourceFiles="@(SqlCe-Native-Binaries-x86)" DestinationFolder="$(StageFolder)\bin\x86\%(RecursiveDir)" />
Expand Down
128 changes: 128 additions & 0 deletions src/Libraries/SmartStore.Core/Logging/TraceLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartStore.Core.Domain.Logging;
using SmartStore.Core.Domain.Customers;
using System.Diagnostics;

namespace SmartStore.Core.Logging
{
public class TraceLogger : DisposableObject, ILogger
{
private readonly TraceSource _traceSource;

public TraceLogger() : this("SmartStore.log")
{
}

public TraceLogger(string fileName)
{
Guard.ArgumentNotEmpty(() => fileName);

_traceSource = new TraceSource("SmartStore");
_traceSource.Switch = new SourceSwitch("LogSwitch", "Error");
_traceSource.Listeners.Remove("Default");

var console = new ConsoleTraceListener(false);
console.Filter = new EventTypeFilter(SourceLevels.All);
console.Name = "console";

var textListener = new TextWriterTraceListener(fileName);
textListener.Filter = new EventTypeFilter(SourceLevels.All);
textListener.TraceOutputOptions = TraceOptions.DateTime;

_traceSource.Listeners.Add(console);
_traceSource.Listeners.Add(textListener);

// Allow the trace source to send messages to
// listeners for all event types. Currently only
// error messages or higher go to the listeners.
// Messages must get past the source switch to
// get to the listeners, regardless of the settings
// for the listeners.
_traceSource.Switch.Level = SourceLevels.All;
}

public bool IsEnabled(LogLevel level)
{
return true;
}

public void DeleteLog(Log log)
{
// not supported
}

public void ClearLog()
{
// not supported
}

public void ClearLog(DateTime toUtc, LogLevel logLevel)
{
// not supported
}

public IPagedList<Log> GetAllLogs(DateTime? fromUtc, DateTime? toUtc, string message, LogLevel? logLevel, int pageIndex, int pageSize, int minFrequency)
{
// not supported
return null;
}

public Log GetLogById(int logId)
{
// not supported
return null;
}

public IList<Log> GetLogByIds(int[] logIds)
{
// not supported
return null;
}

public Log InsertLog(LogContext context)
{
var type = LogLevelToEventType(context.LogLevel);
_traceSource.TraceEvent(type, (int)type, "{0}: {1}".FormatCurrent(type.ToString().ToUpper(), context.ShortMessage));
return null;
}

public Log InsertLog(LogLevel logLevel, string shortMessage, string fullMessage = "", Customer customer = null)
{
var context = new LogContext()
{
LogLevel = logLevel,
ShortMessage = shortMessage,
FullMessage = fullMessage,
Customer = customer
};

return InsertLog(context);
}

private TraceEventType LogLevelToEventType(LogLevel level)
{
switch (level)
{
case LogLevel.Debug:
return TraceEventType.Verbose;
case LogLevel.Error:
return TraceEventType.Error;
case LogLevel.Fatal:
return TraceEventType.Critical;
case LogLevel.Warning:
return TraceEventType.Warning;
default:
return TraceEventType.Information;
}
}

protected override void OnDispose(bool disposing)
{
_traceSource.Flush();
_traceSource.Close();
}
}
}
28 changes: 19 additions & 9 deletions src/Libraries/SmartStore.Core/Packaging/FolderUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using System.Linq;
using System.IO;
using SmartStore.Core.Logging;
using SmartStore.Utilities;

namespace SmartStore.Core.Packaging
{

public interface IFolderUpdater
{
void Backup(DirectoryInfo existingFolder, DirectoryInfo backupfolder);
void Backup(DirectoryInfo existingFolder, DirectoryInfo backupfolder, params string[] ignorePatterns);
void Restore(DirectoryInfo backupfolder, DirectoryInfo existingFolder);
}

Expand All @@ -28,14 +29,15 @@ public FolderUpdater(ILogger logger)
_logger = logger;
}

public void Backup(DirectoryInfo existingFolder, DirectoryInfo backupfolder)
public void Backup(DirectoryInfo existingFolder, DirectoryInfo backupfolder, params string[] ignorePatterns)
{
CopyFolder(GetFolderContent(existingFolder), backupfolder);
var ignores = ignorePatterns.Select(x => new Wildcard(x));
CopyFolder(GetFolderContent(existingFolder, ignores), backupfolder);
}

public void Restore(DirectoryInfo backupfolder, DirectoryInfo existingFolder)
{
CopyFolder(GetFolderContent(backupfolder), existingFolder);
CopyFolder(GetFolderContent(backupfolder, Enumerable.Empty<Wildcard>()), existingFolder);
}

private void CopyFolder(FolderContent source, DirectoryInfo dest)
Expand Down Expand Up @@ -74,26 +76,34 @@ private void CopyFile(DirectoryInfo sourceFolder, string fileName, DirectoryInfo
File.Copy(sourceFile.FullName, destFile.FullName, true);
}

private FolderContent GetFolderContent(DirectoryInfo folder)
private FolderContent GetFolderContent(DirectoryInfo folder, IEnumerable<Wildcard> ignores)
{
var files = new List<string>();
GetFolderContent(folder, "", files);
GetFolderContent(folder, "", files, ignores);
return new FolderContent { Folder = folder, Files = files };
}

private void GetFolderContent(DirectoryInfo folder, string prefix, List<string> files)
private void GetFolderContent(DirectoryInfo folder, string prefix, List<string> files, IEnumerable<Wildcard> ignores)
{
if (!folder.Exists)
return;

if (ignores.Any(w => w.IsMatch(prefix)))
return;

foreach (var file in folder.GetFiles())
{
files.Add(Path.Combine(prefix, file.Name));
var path = Path.Combine(prefix, file.Name);
var ignore = ignores.Any(w => w.IsMatch(path));
if (!ignore)
{
files.Add(path);
}
}

foreach (var child in folder.GetDirectories())
{
GetFolderContent(child, Path.Combine(prefix, child.Name), files);
GetFolderContent(child, Path.Combine(prefix, child.Name), files, ignores);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/Libraries/SmartStore.Core/Packaging/NuGet/NugetLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public void Log(MessageLevel level, string message, params object[] args)
switch (level)
{
case MessageLevel.Debug:
//_logger.Debug(String.Format(message, args));
break;
case MessageLevel.Error:
_logger.Error(String.Format(message, args));
break;
case MessageLevel.Info:
_logger.Information(String.Format(message, args));
Expand All @@ -31,7 +35,7 @@ public void Log(MessageLevel level, string message, params object[] args)

public FileConflictResolution ResolveFileConflict(string message)
{
return FileConflictResolution.Ignore;
return FileConflictResolution.OverwriteAll;
}
}
}
9 changes: 8 additions & 1 deletion src/Libraries/SmartStore.Core/Packaging/PackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public PackageInfo Install(Stream packageStream, string location, string applica
return InstallPackage(package, packageRepository, location, applicationPath);
}

/// <summary>
/// Tries to install the package
/// </summary>
/// <param name="package">The package to install</param>
/// <param name="packageRepository">The repository</param>
/// <param name="location">The virtual location of the package file, usually <c>~/App_Data</c></param>
/// <param name="applicationPath">The virtual app root path, usually <c>~/</c></param>
/// <returns>An instance of <see cref="PackageInfo"/> type</returns>
protected PackageInfo InstallPackage(IPackage package, IPackageRepository packageRepository, string location, string applicationPath)
{

Expand Down Expand Up @@ -145,7 +153,6 @@ protected PackageInfo InstallPackage(IPackage package, IPackageRepository packag
/// <returns>The package information.</returns>
protected PackageInfo ExecuteInstall(IPackage package, IPackageRepository packageRepository, string sourceLocation, string targetPath)
{
// this logger is used to render NuGet's log on the notifier
var logger = new NugetLogger(_logger);

var project = new FileBasedProjectSystem(targetPath) { Logger = logger };
Expand Down
Loading

0 comments on commit 721bd61

Please sign in to comment.