Skip to content

Commit

Permalink
Merge branch 'develop2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Dec 15, 2017
2 parents 2abd4c9 + 8fd28d7 commit 149f2f0
Show file tree
Hide file tree
Showing 71 changed files with 453 additions and 386 deletions.
11 changes: 3 additions & 8 deletions MailRuCloud/MailRuCloudApi/Base/Account.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;
using System.Threading.Tasks;
using YaR.MailRuCloud.Api.Base.Requests.Repo;
using YaR.MailRuCloud.Api.Base.Repos;
using YaR.MailRuCloud.Api.Base.Requests.Types;

namespace YaR.MailRuCloud.Api.Base
Expand All @@ -11,8 +11,6 @@ public class Account
{
private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(Account));

private readonly CloudApi _cloudApi;

/// <summary>
/// Default cookies.
/// </summary>
Expand All @@ -23,14 +21,11 @@ public class Account
/// <summary>
/// Initializes a new instance of the <see cref="Account" /> class.
/// </summary>
/// <param name="cloudApi"></param>
/// <param name="login">Login name as email.</param>
/// <param name="password">Password related with this login</param>
/// <param name="twoFaHandler"></param>
public Account(CloudApi cloudApi, string login, string password, ITwoFaHandler twoFaHandler)
public Account(string login, string password, ITwoFaHandler twoFaHandler)
{
_cloudApi = cloudApi;

Credentials = new Credentials(login, password);

WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
Expand All @@ -46,7 +41,7 @@ public Account(CloudApi cloudApi, string login, string password, ITwoFaHandler t
internal IRequestRepo RequestRepo => _requestRepo ??
//(_requestRepo = new MobileRequestRepo(_cloudApi.Account.Proxy, _cloudApi.Account.Credentials));
//(_requestRepo = new WebV2RequestRepo(_cloudApi.Account.Proxy, new WebAuth(_cloudApi.Account.Proxy, _cloudApi.Account.Credentials,OnAuthCodeRequired)));
(_requestRepo = new WebM1RequestRepo(_cloudApi.Account.Proxy, _cloudApi.Account.Credentials, OnAuthCodeRequired));
(_requestRepo = new WebM1RequestRepo(Proxy, Credentials, OnAuthCodeRequired));
//MixedRepo(_cloudApi));

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;

namespace YaR.MailRuCloud.Api.Base.Requests.Repo
namespace YaR.MailRuCloud.Api.Base.Auth
{
internal interface IAuth
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Net;
using System.Threading.Tasks;
using YaR.MailRuCloud.Api.Base.Requests;
using YaR.MailRuCloud.Api.Base.Requests.Types;
using YaR.MailRuCloud.Api.Base.Requests.WebBin;
using YaR.MailRuCloud.Api.Extensions;

namespace YaR.MailRuCloud.Api.Base.Requests.Repo
namespace YaR.MailRuCloud.Api.Base.Auth
{
internal class OAuth : IAuth
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
using System.Net;
using System.Security.Authentication;
using System.Threading.Tasks;
using YaR.MailRuCloud.Api.Base.Requests;
using YaR.MailRuCloud.Api.Base.Requests.Types;
using YaR.MailRuCloud.Api.Base.Requests.WebV2;
using YaR.MailRuCloud.Api.Extensions;

namespace YaR.MailRuCloud.Api.Base.Requests.Repo
namespace YaR.MailRuCloud.Api.Base.Auth
{
class WebAuth : IAuth
{
Expand Down
75 changes: 0 additions & 75 deletions MailRuCloud/MailRuCloudApi/Base/CloudApi.cs

This file was deleted.

67 changes: 67 additions & 0 deletions MailRuCloud/MailRuCloudApi/Base/Pending.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YaR.MailRuCloud.Api.Base
{
class Pending<T> where T : class
{
private readonly List<PendingItem<T>> _items = new List<PendingItem<T>>();
private readonly int _maxLocks;
private readonly Func<T> _valueFactory;

public Pending(int maxLocks, Func<T> valueFactory)
{
_maxLocks = maxLocks;
_valueFactory = valueFactory;
}

private readonly object _lock = new object();

public T Next(T current)
{
lock (_lock)
{
var item = null == current
? _items.FirstOrDefault(it => it.LockCount < _maxLocks)
: _items.SkipWhile(it => !it.Equals(current)).Skip(1).FirstOrDefault(it => it.LockCount < _maxLocks);

if (null == item)
_items.Add(item = new PendingItem <T>{Item = _valueFactory(), LockCount = 0});

item.LockCount++;

return item.Item;
}
}

public void Free(T value)
{
if (null == value)
return;

lock (_lock)
{
foreach (var item in _items)
if (item.Item.Equals(value))
{
if (item.LockCount <= 0)
throw new Exception("Pending item count <= 0");
if (item.LockCount > 0)
item.LockCount--;
}
}
}




}

class PendingItem<T>
{
public T Item { get; set; }
public int LockCount { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using YaR.MailRuCloud.Api.Base.Auth;
using YaR.MailRuCloud.Api.Base.Requests;
using YaR.MailRuCloud.Api.Base.Requests.Types;
using YaR.MailRuCloud.Api.Base.Threads;
using YaR.MailRuCloud.Api.Base.Streams;
using YaR.MailRuCloud.Api.Links;

namespace YaR.MailRuCloud.Api.Base.Requests.Repo
namespace YaR.MailRuCloud.Api.Base.Repos
{
interface IRequestRepo
{

IAuth Authent { get; }

//IWebProxy Proxy { get; }
HttpCommonSettings HttpSettings { get; }

int PendingDownloads { get; set; }

Stream GetDownloadStream(File file, long? start = null, long? end = null);
HttpWebRequest UploadRequest(ShardInfo shard, File file, UploadMultipartBoundary boundary);

void BanShardInfo(ShardInfo banShard);
//TODO: internal functionality, remove
Task<ShardInfo> GetShardInfo(ShardType shardType);

Task<CreateFolderResult> CreateFolder(string path);
Task<AddFileResult> AddFile(string fileFullPath, string fileHash, FileSize fileSize, DateTime dateTime, ConflictResolver? conflictResolver);


Task<IEntry> FolderInfo(string path, Link ulink, int offset = 0, int limit = int.MaxValue);

Task<FolderInfoResult> ItemInfo(string path, bool isWebLink = false, int offset = 0, int limit = int.MaxValue);

HttpWebRequest UploadRequest(ShardInfo shard, File file, UploadMultipartBoundary boundary);
HttpWebRequest DownloadRequest(long instart, long inend, File file, ShardInfo shard);
Task<AccountInfoResult> AccountInfo();

Task<CloneItemResult> CloneItem(string fromUrl, string toPath);

Task<CopyResult> Copy(string sourceFullPath, string destinationPath, ConflictResolver? conflictResolver = null);

Task<CopyResult> Move(string sourceFullPath, string destinationPath, ConflictResolver? conflictResolver = null);
Task<CreateFolderResult> CreateFolder(string path);

Task<IEntry> FolderInfo(string path, Link ulink, int offset = 0, int limit = int.MaxValue);
Task<AddFileResult> AddFile(string fileFullPath, string fileHash, FileSize fileSize, DateTime dateTime, ConflictResolver? conflictResolver);

Task<FolderInfoResult> ItemInfo(string path, bool isWebLink = false, int offset = 0, int limit = int.MaxValue);
Task<CloneItemResult> CloneItem(string fromUrl, string toPath);

Task<AccountInfoResult> AccountInfo();
Task<CopyResult> Copy(string sourceFullPath, string destinationPath, ConflictResolver? conflictResolver = null);

Task<CopyResult> Move(string sourceFullPath, string destinationPath, ConflictResolver? conflictResolver = null);

Task<PublishResult> Publish(string fullPath);

Expand All @@ -49,8 +48,5 @@ interface IRequestRepo
Task<RemoveResult> Remove(string fullPath);

Task<RenameResult> Rename(string fullPath, string newName);

//Task<Dictionary<ShardType, ShardInfo>> ShardInfo();

}
}
4 changes: 4 additions & 0 deletions MailRuCloud/MailRuCloudApi/Base/Repos/MixedRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace YaR.MailRuCloud.Api.Base.Repos
{

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System;
using System.IO;
using System.Net;
using System.Net.Mime;
using System.Threading.Tasks;
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.WebBin;
using YaR.MailRuCloud.Api.Base.Requests.WebBin.Types;
using YaR.MailRuCloud.Api.Base.Threads;
using YaR.MailRuCloud.Api.Base.Streams;
using YaR.MailRuCloud.Api.Extensions;
using YaR.MailRuCloud.Api.Links;

namespace YaR.MailRuCloud.Api.Base.Requests.Repo
namespace YaR.MailRuCloud.Api.Base.Repos
{
class MobileRequestRepo : IRequestRepo
{
Expand Down Expand Up @@ -57,13 +60,17 @@ public MobileRequestRepo(IWebProxy proxy, IAuth auth)


public IAuth Authent { get; }
public CookieContainer Cookies { get; }

public HttpWebRequest UploadRequest(ShardInfo shard, File file, UploadMultipartBoundary boundary)
{
throw new NotImplementedException();
}

public Stream GetDownloadStream(File file, long? start = null, long? end = null)
{
throw new NotImplementedException();
}

public HttpWebRequest DownloadRequest(long instart, long inend, File file, ShardInfo shard)
{
string url = $"{_downloadServer.Value.Url}{Uri.EscapeDataString(file.FullPath)}?token={Authent.AccessToken}&client_id={HttpSettings.ClientId}";
Expand Down
Loading

0 comments on commit 149f2f0

Please sign in to comment.