Skip to content

Commit

Permalink
Merge branch 'develop2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Jan 3, 2018
2 parents 149f2f0 + f12784d commit 8daec9b
Show file tree
Hide file tree
Showing 29 changed files with 370 additions and 259 deletions.
1 change: 1 addition & 0 deletions MailRuCloud/MailRuCloudApi/Base/Auth/OAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using YaR.MailRuCloud.Api.Base.Requests;
using YaR.MailRuCloud.Api.Base.Requests.Types;
using YaR.MailRuCloud.Api.Base.Requests.WebBin;
using YaR.MailRuCloud.Api.Common;
using YaR.MailRuCloud.Api.Extensions;

namespace YaR.MailRuCloud.Api.Base.Auth
Expand Down
1 change: 1 addition & 0 deletions MailRuCloud/MailRuCloudApi/Base/Auth/WebAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using YaR.MailRuCloud.Api.Base.Requests;
using YaR.MailRuCloud.Api.Base.Requests.Types;
using YaR.MailRuCloud.Api.Base.Requests.WebV2;
using YaR.MailRuCloud.Api.Common;
using YaR.MailRuCloud.Api.Extensions;

namespace YaR.MailRuCloud.Api.Base.Auth
Expand Down
12 changes: 1 addition & 11 deletions MailRuCloud/MailRuCloudApi/Base/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public Folder(string fullPath)
/// <summary>
/// Initializes a new instance of the <see cref="Folder" /> class.
/// </summary>
/// <param name="foldersCount">Number of folders.</param>
/// <param name="filesCount">Number of files.</param>
/// <param name="size">Folder size.</param>
/// <param name="fullPath">Full folder path.</param>
/// <param name="publicLink">Public folder link.</param>
Expand Down Expand Up @@ -73,14 +71,7 @@ public IEnumerable<IEntry> Entries
/// Gets folder name.
/// </summary>
/// <value>Folder name.</value>
public string Name
{
get
{
string z = WebDavPath.Name(FullPath); //FullPath == "/" ? "" : FullPath.TrimEnd('/').Remove(0, FullPath.LastIndexOf('/') + 1);
return z;
}
}
public string Name => WebDavPath.Name(FullPath);

/// <summary>
/// Gets folder size.
Expand Down Expand Up @@ -114,7 +105,6 @@ public string FullPath
public FileAttributes Attributes { get; set; } = FileAttributes.Directory;

public bool IsFile => false;
public bool CryptRequired => Files.Any(f => f.Name == CryptFileInfo.FileName);

public PublishInfo ToPublishInfo()
{
Expand Down
3 changes: 2 additions & 1 deletion MailRuCloud/MailRuCloudApi/Base/Repos/MobileRequestRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using YaR.MailRuCloud.Api.Base.Requests.WebBin;
using YaR.MailRuCloud.Api.Base.Requests.WebBin.Types;
using YaR.MailRuCloud.Api.Base.Streams;
using YaR.MailRuCloud.Api.Common;
using YaR.MailRuCloud.Api.Extensions;
using YaR.MailRuCloud.Api.Links;

Expand Down Expand Up @@ -201,7 +202,7 @@ public async Task<RenameResult> Rename(string fullPath, string newName)
{
string target = WebDavPath.Combine(WebDavPath.Parent(fullPath), newName);

await new RenameRequest(HttpSettings, Authent, _metaServer.Value.Url, fullPath, target)
await new MoveRequest(HttpSettings, Authent, _metaServer.Value.Url, fullPath, target)
.MakeRequestAsync();
var res = new RenameResult { IsSuccess = true };
return res;
Expand Down
60 changes: 60 additions & 0 deletions MailRuCloud/MailRuCloudApi/Base/Repos/ShardManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using YaR.MailRuCloud.Api.Base.Auth;
using YaR.MailRuCloud.Api.Base.Requests;
using YaR.MailRuCloud.Api.Base.Requests.Types;
using YaR.MailRuCloud.Api.Base.Requests.WebM1;
using YaR.MailRuCloud.Api.Common;
using YaR.MailRuCloud.Api.Extensions;

namespace YaR.MailRuCloud.Api.Base.Repos
{
class ShardManager
{
//TODO: refact required

private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(ShardManager));

public ShardManager(HttpCommonSettings httpsettings, IAuth auth)
{
_metaServer = new Cached<Requests.WebBin.MobMetaServerRequest.Result>(old =>
{
Logger.Debug("Requesting new meta server");
var server = new Requests.WebBin.MobMetaServerRequest(httpsettings).MakeRequestAsync().Result;
return server;
},
value => TimeSpan.FromSeconds(MetaServerExpiresSec));

BannedShards = new Cached<List<ShardInfo>>(old => new List<ShardInfo>(),
value => TimeSpan.FromMinutes(2));

CachedShards = new Cached<Dictionary<ShardType, ShardInfo>>(old => new ShardInfoRequest(httpsettings, auth).MakeRequestAsync().Result.ToShardInfo(),
value => TimeSpan.FromSeconds(ShardsExpiresInSec));

DownloadServersPending = new Pending<Cached<Requests.WebBin.MobDownloadServerRequest.Result>>(8,
() => new Cached<Requests.WebBin.MobDownloadServerRequest.Result>(old =>
{
Logger.Debug("Requesting new download server");
var server = new Requests.WebBin.MobDownloadServerRequest(httpsettings).MakeRequestAsync().Result;
return server;
},
value => TimeSpan.FromSeconds(DownloadServerExpiresSec)
));
}


public Pending<Cached<Requests.WebBin.MobDownloadServerRequest.Result>> DownloadServersPending { get; }

public ShardInfo MetaServer => new ShardInfo {Url = _metaServer.Value.Url, Count = _metaServer.Value.Unknown};
private readonly Cached<Requests.WebBin.MobMetaServerRequest.Result> _metaServer;

public Cached<Dictionary<ShardType, ShardInfo>> CachedShards { get; }

public Cached<List<ShardInfo>> BannedShards { get; }


private const int ShardsExpiresInSec = 30 * 60;
private const int MetaServerExpiresSec = 20 * 60;
private const int DownloadServerExpiresSec = 3 * 60;
}
}
Loading

0 comments on commit 8daec9b

Please sign in to comment.