-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
453 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ailRuCloudApi/Base/Requests/Repo/IAuth.cs → ...RuCloud/MailRuCloudApi/Base/Auth/IAuth.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ailRuCloudApi/Base/Requests/Repo/OAuth.cs → ...RuCloud/MailRuCloudApi/Base/Auth/OAuth.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace YaR.MailRuCloud.Api.Base.Repos | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.