Skip to content

Commit

Permalink
Merge pull request #516 from Orckestra/dev
Browse files Browse the repository at this point in the history
C1 CMS v6.3
  • Loading branch information
napernik authored Jan 25, 2018
2 parents 797473b + 50fd382 commit 146aa7c
Show file tree
Hide file tree
Showing 65 changed files with 1,225 additions and 680 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Workflow.Activities;
using Composite.C1Console.Actions;
using Composite.C1Console.Forms.CoreUiControls;
using Composite.C1Console.Workflow;
using Composite.Core.IO;
using Composite.Data;
using Composite.Data.Types;
using Composite.Data.Validation.ClientValidationRules;
using Composite.Data.Transactions;
using System.Transactions;


namespace Composite.Plugins.Elements.ElementProviders.MediaFileProviderElementProvider
{
[AllowPersistingWorkflow(WorkflowPersistingType.Never)]
public sealed partial class AddNewMediaFileWorkflow : Composite.C1Console.Workflow.Activities.FormsWorkflow
{
private static readonly string LogTitle = typeof (AddNewMediaFileWorkflow).Name;

public AddNewMediaFileWorkflow()
{
InitializeComponent();
Expand All @@ -29,24 +25,23 @@ public AddNewMediaFileWorkflow()

private void Initialize()
{
if (this.EntityToken is MediaRootFolderProviderEntityToken)
if (this.EntityToken is MediaRootFolderProviderEntityToken token)
{
MediaRootFolderProviderEntityToken token = (MediaRootFolderProviderEntityToken)this.EntityToken;
_storeId = token.Id;
_folderPath = "/";
}
else
{
DataEntityToken token = (DataEntityToken)this.EntityToken;
IMediaFileFolder parentFolder = (IMediaFileFolder)token.Data;
var dataEntityToken = (DataEntityToken)this.EntityToken;
var parentFolder = (IMediaFileFolder)dataEntityToken.Data;
_storeId = parentFolder.StoreId;
_folderPath = parentFolder.Path;
}
}


[NonSerialized]
private string _folderPath = null;
private string _folderPath;
internal string FolderPath
{
get
Expand All @@ -63,7 +58,7 @@ internal string FolderPath


[NonSerialized]
private string _storeId = null;
private string _storeId;
internal string StoreId
{
get
Expand All @@ -81,22 +76,16 @@ internal string StoreId

private IMediaFile GetExistingFile(string folderPath, string filename)
{
IMediaFile existingFile =
(from file in DataFacade.GetData<IMediaFile>()
where (string.Compare(file.FolderPath, folderPath, StringComparison.OrdinalIgnoreCase) == 0) &&
(string.Compare(file.FileName, filename, StringComparison.OrdinalIgnoreCase) == 0)
select file).FirstOrDefault();

return existingFile;
return DataFacade.GetData<IMediaFile>().FirstOrDefault(file =>
string.Compare(file.FolderPath, folderPath, StringComparison.OrdinalIgnoreCase) == 0 &&
string.Compare(file.FileName, filename, StringComparison.OrdinalIgnoreCase) == 0);
}



private void initializeCodeActivity_InitializeBindings_ExecuteCode(object sender, EventArgs e)
{
UploadedFile file = new UploadedFile();

this.Bindings.Add("UploadedFile", file);
this.Bindings.Add("UploadedFile", new UploadedFile());
this.Bindings.Add("AllowOverwrite", false);
this.Bindings.Add("Title", "");
this.Bindings.Add("Description", "");
Expand All @@ -109,7 +98,7 @@ private void ValidateStep1Bindings_Next(object sender, ConditionalEventArgs e)
{
UploadedFile uploadedFile = this.GetBinding<UploadedFile>("UploadedFile");

if (uploadedFile.HasFile == false)
if (!uploadedFile.HasFile)
{
this.ShowFieldMessage("UploadedFile", "${Composite.Management, Website.Forms.Administrative.AddNewMediaFile.MissingUploadedFile.Message}");
e.Result = false;
Expand All @@ -124,15 +113,15 @@ private void ValidateStep1Bindings_Next(object sender, ConditionalEventArgs e)
private void ValidateStep1Bindings_Finish(object sender, ConditionalEventArgs e)
{
ValidateStep1Bindings_Next(sender, e);
if (e.Result == false) return;
if (!e.Result) return;

UploadedFile uploadedFile = this.GetBinding<UploadedFile>("UploadedFile");
string filename = uploadedFile.FileName;

bool allowOverwrite = this.GetBinding<bool>("AllowOverwrite");

IMediaFile existingFile = GetExistingFile(this.FolderPath, filename);
if ((existingFile != null) && (allowOverwrite == false))
if (existingFile != null && !allowOverwrite)
{
this.ShowFieldMessage("UploadedFile", "${Composite.Management, Website.Forms.Administrative.AddNewMediaFile.FileExists.Message}");
e.Result = false;
Expand All @@ -154,13 +143,13 @@ private void ValidateStep1Bindings_Finish(object sender, ConditionalEventArgs e)

private void step2CodeActivity_UpdateBindings_ExecuteCode(object sender, EventArgs e)
{
if (this.BindingExist("Filename") == false)
if (!this.BindingExist("Filename"))
{
UploadedFile uploadedFile = this.GetBinding<UploadedFile>("UploadedFile");
this.Bindings.Add("Filename", uploadedFile.FileName);

this.BindingsValidationRules.Add("Title", new List<ClientValidationRule> { new StringLengthClientValidationRule(0, 256) });
}
}
}


Expand All @@ -172,7 +161,7 @@ private void ValidateStep2Bindings(object sender, ConditionalEventArgs e)
bool allowOverwrite = this.GetBinding<bool>("AllowOverwrite");

IMediaFile existingFile = GetExistingFile(this.FolderPath, filename);
if ((existingFile != null) && (allowOverwrite == false))
if (existingFile != null && !allowOverwrite)
{
this.ShowFieldMessage("Filename", "${Composite.Management, Website.Forms.Administrative.AddNewMediaFile.FileExists.Message}");
e.Result = false;
Expand All @@ -194,41 +183,37 @@ private void ValidateStep2Bindings(object sender, ConditionalEventArgs e)

private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
{
AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);
var addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);
DataEntityToken focusEntityToken;

UploadedFile uploadedFile = this.GetBinding<UploadedFile>("UploadedFile");
string filename;
if (this.BindingExist("Filename"))
{
filename = this.GetBinding<string>("Filename");
}
else
{
filename = uploadedFile.FileName;
}
var filename = this.BindingExist("Filename")
? this.GetBinding<string>("Filename")
: uploadedFile.FileName;

using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
using (var transactionScope = TransactionsFacade.CreateNewScope())
{
IMediaFileStore store = DataFacade.GetData<IMediaFileStore>(x => x.Id == this.StoreId).First();

IMediaFile existingFile = GetExistingFile(this.FolderPath, filename);

if (existingFile == null)
{
WorkflowMediaFile mediaFile = new WorkflowMediaFile();
mediaFile.FileName = System.IO.Path.GetFileName(filename);
mediaFile.FolderPath = this.FolderPath;
mediaFile.Title = this.GetBinding<string>("Title");
mediaFile.Description = this.GetBinding<string>("Description");
mediaFile.Tags = this.GetBinding<string>("Tags");
mediaFile.Culture = C1Console.Users.UserSettings.ActiveLocaleCultureInfo.Name;
mediaFile.Length = uploadedFile.ContentLength;
mediaFile.MimeType = MimeTypeInfo.GetMimeType(uploadedFile);

using (System.IO.Stream readStream = uploadedFile.FileStream)
var mediaFile = new WorkflowMediaFile
{
FileName = System.IO.Path.GetFileName(filename),
FolderPath = this.FolderPath,
Title = this.GetBinding<string>("Title"),
Description = this.GetBinding<string>("Description"),
Tags = this.GetBinding<string>("Tags"),
Culture = C1Console.Users.UserSettings.ActiveLocaleCultureInfo.Name,
Length = uploadedFile.ContentLength,
MimeType = MimeTypeInfo.GetMimeType(uploadedFile)
};

using (var readStream = uploadedFile.FileStream)
{
using (System.IO.Stream writeStream = mediaFile.GetNewWriteStream())
using (var writeStream = mediaFile.GetNewWriteStream())
{
readStream.CopyTo(writeStream);
}
Expand All @@ -249,9 +234,9 @@ private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs
fileData.MimeType = MimeTypeInfo.GetMimeType(uploadedFile);
fileData.Length = uploadedFile.ContentLength;

using (System.IO.Stream readStream = uploadedFile.FileStream)
using (var readStream = uploadedFile.FileStream)
{
using (System.IO.Stream writeStream = existingFile.GetNewWriteStream())
using (var writeStream = existingFile.GetNewWriteStream())
{
readStream.CopyTo(writeStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public ViewAvailablePackageInfoWorkflowWorkflow()

private void AddOnDescriptionExists(object sender, ConditionalEventArgs e)
{
PackageDescription packageDescription;
this.TryGetBinding(BindingNames.PackageDescription, out packageDescription);
this.TryGetBinding(BindingNames.PackageDescription, out PackageDescription packageDescription);
e.Result = packageDescription != null;
}

Expand Down Expand Up @@ -84,7 +83,6 @@ where description.Id.ToString() == castedToken.Id

var purchasableSubscriptions = packageDescription.AvailableInSubscriptions.Where(f => f.Purchasable).ToList();

bool showTrialInformation = false;
var licenses = GetSubscriptionLicenses(packageDescription.AvailableInSubscriptions);

var validLicense = licenses.Where(l => !l.Expired)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Workflow.Activities;
using Composite.C1Console.Events;
using Composite.Data;
using Composite.Data.ProcessControlled;
using Composite.Data.Types;
using Composite.Data.Transactions;
using Composite.C1Console.Workflow;
using Composite.Core.Collections.Generic;
using Texts = Composite.Core.ResourceSystem.LocalizationFiles.Composite_Plugins_PageElementProvider;
Expand Down Expand Up @@ -168,12 +165,10 @@ private void PageHasMultpleVersions(object sender, ConditionalEventArgs e)

private void HasPageDeletionBeenConfirmed(object sender, ConditionalEventArgs e)
{
Func<string, bool> isTrueBinding = bindingName =>
Bindings.ContainsKey(bindingName)
&& (bool) Bindings[bindingName];
bool IsTrueBinding(string bindingName) => Bindings.ContainsKey(bindingName) && (bool) Bindings[bindingName];

e.Result = isTrueBinding(BindingNames.DeleteAllVersions)
|| isTrueBinding(BindingNames.DeleteChildrenConfirmed);
e.Result = IsTrueBinding(BindingNames.DeleteAllVersions)
|| IsTrueBinding(BindingNames.DeleteChildrenConfirmed);
}

private void DeleteCurrentVersion(object sender, EventArgs e)
Expand Down
26 changes: 19 additions & 7 deletions Composite/AspNet/Razor/CompositeC1WebPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,25 @@ public IHtmlString Function(string name, object parameters)
return Function(name, Functions.ObjectToDictionary(parameters));
}

/// <summary>
/// Executes a C1 Function.
/// </summary>
/// <param name="name">Function name.</param>
/// <param name="parameters">The parameters.</param>
/// <returns></returns>
public IHtmlString Function(string name, IDictionary<string, object> parameters)
/// <summary>
/// Executes a C1 Function.
/// </summary>
/// <param name="name">Function name.</param>
/// <param name="parameters">The parameters.</param>
/// /// <param name="functionContextContainer">The FunctionContextContainer used to execute the function.</param>
/// <returns></returns>
public IHtmlString Function(string name, object parameters, FunctionContextContainer functionContextContainer)
{
return Function(name, Functions.ObjectToDictionary(parameters), functionContextContainer);
}

/// <summary>
/// Executes a C1 Function.
/// </summary>
/// <param name="name">Function name.</param>
/// <param name="parameters">The parameters.</param>
/// <returns></returns>
public IHtmlString Function(string name, IDictionary<string, object> parameters)
{
return Function(name, parameters, GetFunctionContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Composite.C1Console.Security.Compatibility
[ApplicationStartup(AbortStartupOnException = false)]
public static class LegacySerializedEntityTokenUpgrader
{
const string LogTitle = nameof(LegacySerializedEntityTokenUpgrader);
const string _configFilename = "LegacySerializedEntityTokenUpgrader.config";
static readonly XName _docRoot = "UpgradeSettings";
private static ILog _log;
Expand All @@ -38,7 +39,7 @@ public static void OnInitialized(ILog log)
}
catch (Exception ex)
{
_log.LogError(nameof(LegacySerializedEntityTokenUpgrader), ex);
_log.LogError(LogTitle, ex);

throw;
}
Expand Down Expand Up @@ -156,7 +157,7 @@ private static void UpgradeStoredData()
}
catch (Exception ex)
{
_log.LogError(nameof(LegacySerializedEntityTokenUpgrader), "Failed to upgrade old token {0} from data type {1} as EntityToken.\n{2}", token, dataType.FullName, ex);
_log.LogError(LogTitle, $"Failed to upgrade old token '{token}' from data type '{dataType.FullName}' as EntityToken.\n{ex}");
}
}

Expand All @@ -176,11 +177,11 @@ private static void UpgradeStoredData()
}
catch (Exception ex)
{
_log.LogError(nameof(LegacySerializedEntityTokenUpgrader), "Failed to upgrade old token {0} from data type {1} as DataSourceId.\n{2}", token, dataType.FullName, ex);
_log.LogError(LogTitle, $"Failed to upgrade old token '{token}' from data type '{dataType.FullName}' as DataSourceId.\n{ex}");
}
}

if (rowChange) DataFacade.Update(rowItem);
if (rowChange) DataFacade.Update(rowItem, true, false, false);
}
}
}
Expand Down
Loading

0 comments on commit 146aa7c

Please sign in to comment.