Merge branch 'dev-v7' into 7.3.0
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
<dependency id="SharpZipLib" version="[0.86.0, 1.0.0)" />
|
||||
<dependency id="MySql.Data" version="[6.6.5]" />
|
||||
<dependency id="xmlrpcnet" version="[2.5.0, 3.0.0)" />
|
||||
<dependency id="ClientDependency" version="[1.8.2, 2.0.0)" />
|
||||
<dependency id="ClientDependency" version="[1.8.2.1, 2.0.0)" />
|
||||
<dependency id="ClientDependency-Mvc" version="[1.8.0, 2.0.0)" />
|
||||
<dependency id="AutoMapper" version="[3.0.0, 4.0.0)" />
|
||||
<dependency id="Newtonsoft.Json" version="[6.0.5, 7.0.0)" />
|
||||
|
||||
@@ -1,10 +1,42 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
public static class FileSystemExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to open the file at <code>filePath</code> up to <code>maxRetries</code> times,
|
||||
/// with a thread sleep time of <code>sleepPerRetryInMilliseconds</code> between retries.
|
||||
/// </summary>
|
||||
public static FileStream OpenReadWithRetry(this FileInfo file, int maxRetries = 5, int sleepPerRetryInMilliseconds = 50)
|
||||
{
|
||||
var retries = maxRetries;
|
||||
|
||||
while (retries > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.OpenRead(file.FullName);
|
||||
}
|
||||
catch(IOException)
|
||||
{
|
||||
retries--;
|
||||
|
||||
if (retries == 0)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
Thread.Sleep(sleepPerRetryInMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException("Retries must be greater than zero");
|
||||
}
|
||||
|
||||
public static long GetSize(this IFileSystem fs, string path)
|
||||
{
|
||||
using (var file = fs.OpenFile(path))
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using AutoMapper;
|
||||
using ClientDependency.Core;
|
||||
using Examine.LuceneEngine;
|
||||
using Examine.LuceneEngine.Providers;
|
||||
using Newtonsoft.Json;
|
||||
@@ -637,15 +638,20 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
private IEnumerable<EntityBasic> GetResultForKeys(IEnumerable<Guid> keys, UmbracoEntityTypes entityType)
|
||||
{
|
||||
if (keys.Any() == false) return Enumerable.Empty<EntityBasic>();
|
||||
var keysArray = keys.ToArray();
|
||||
if (keysArray.Any() == false) return Enumerable.Empty<EntityBasic>();
|
||||
|
||||
var objectType = ConvertToObjectType(entityType);
|
||||
if (objectType.HasValue)
|
||||
{
|
||||
var result = Services.EntityService.GetAll(objectType.Value, keys.ToArray())
|
||||
var entities = Services.EntityService.GetAll(objectType.Value, keysArray)
|
||||
.WhereNotNull()
|
||||
.Select(Mapper.Map<EntityBasic>);
|
||||
|
||||
// entities are in "some" order, put them back in order
|
||||
var xref = entities.ToDictionary(x => x.Id);
|
||||
var result = keysArray.Select(x => xref.ContainsKey(x) ? xref[x] : null).Where(x => x != null);
|
||||
|
||||
return result;
|
||||
}
|
||||
//now we need to convert the unknown ones
|
||||
@@ -664,15 +670,20 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
private IEnumerable<EntityBasic> GetResultForIds(IEnumerable<int> ids, UmbracoEntityTypes entityType)
|
||||
{
|
||||
if (ids.Any() == false) return Enumerable.Empty<EntityBasic>();
|
||||
var idsArray = ids.ToArray();
|
||||
if (idsArray.Any() == false) return Enumerable.Empty<EntityBasic>();
|
||||
|
||||
var objectType = ConvertToObjectType(entityType);
|
||||
if (objectType.HasValue)
|
||||
{
|
||||
var result = Services.EntityService.GetAll(objectType.Value, ids.ToArray())
|
||||
var entities = Services.EntityService.GetAll(objectType.Value, idsArray)
|
||||
.WhereNotNull()
|
||||
.Select(Mapper.Map<EntityBasic>);
|
||||
|
||||
// entities are in "some" order, put them back in order
|
||||
var xref = entities.ToDictionary(x => x.Id);
|
||||
var result = idsArray.Select(x => xref.ContainsKey(x) ? xref[x] : null).Where(x => x != null);
|
||||
|
||||
return result;
|
||||
}
|
||||
//now we need to convert the unknown ones
|
||||
|
||||
@@ -32,6 +32,7 @@ using umbraco;
|
||||
using umbraco.BusinessLogic.Actions;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Persistence.FaultHandling;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -404,7 +405,11 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
var mediaService = ApplicationContext.Services.MediaService;
|
||||
var f = mediaService.CreateMedia(fileName, parentId, mediaType);
|
||||
using (var fs = System.IO.File.OpenRead(file.LocalFileName))
|
||||
|
||||
var fileInfo = new FileInfo(file.LocalFileName);
|
||||
var fs = fileInfo.OpenReadWithRetry();
|
||||
if (fs == null) throw new InvalidOperationException("Could not acquire file stream");
|
||||
using (fs)
|
||||
{
|
||||
f.SetValue(Constants.Conventions.Media.File, fileName, fs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user