Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Sep 12, 2017
2 parents db6ebb5 + a9a6571 commit f9877dc
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 69 deletions.
4 changes: 0 additions & 4 deletions WDMRC.2FA/AuthCodeConsole.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MailRuCloudApi.TwoFA
{
Expand Down
10 changes: 1 addition & 9 deletions WDMRC.2FA/AuthCodeForm.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms;

namespace MailRuCloudApi.TwoFA
{
Expand Down
20 changes: 7 additions & 13 deletions WDMRC.2FA/AuthCodeWindow.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;

namespace MailRuCloudApi.TwoFA
Expand All @@ -16,23 +10,23 @@ public AuthCodeWindow()

public string Get(string login, bool isAutoRelogin)
{
string result = string.Empty;

Application.EnableVisualStyles();

using (NotifyIcon notify = new NotifyIcon())
using (AuthCodeForm prompt = new AuthCodeForm())
{
var prompt1 = prompt;

notify.Visible = true;
notify.Icon = SystemIcons.Exclamation;
notify.BalloonTipTitle = "WebDAV Mail.Ru 2 Factor Auth";
notify.BalloonTipText = $"Auth code required for {login}";
notify.BalloonTipIcon = ToolTipIcon.Info;

notify.Click += (sender, args) =>
prompt?.Activate();
notify.BalloonTipClicked += (sender, args) =>
prompt?.Activate();
notify.Click += (sender, args) =>
prompt1?.Activate();
notify.BalloonTipClicked += (sender, args) =>
prompt1?.Activate();

notify.ShowBalloonTip(30000);

Expand Down
4 changes: 2 additions & 2 deletions WDMRC.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.1.3")]
[assembly: AssemblyFileVersion("1.6.1.3")]
[assembly: AssemblyVersion("1.6.1.4")]
[assembly: AssemblyFileVersion("1.6.1.4")]


[assembly: log4net.Config.XmlConfigurator(Watch = true)]
6 changes: 1 addition & 5 deletions WebDavMailRuCloudStore/Cloud.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Concurrent;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using MailRuCloudApi;
using MailRuCloudApi.Api;
using NWebDav.Server.Handlers;
using NWebDav.Server.Http;

namespace YaR.WebDavMailRu.CloudStore
Expand All @@ -30,8 +27,7 @@ public static MailRuCloud Instance(IHttpContext context)
HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.Session.Principal.Identity;
string key = identity.Name + identity.Password;

MailRuCloud cloud;
if (CloudCache.TryGetValue(key, out cloud))
if (CloudCache.TryGetValue(key, out var cloud))
{
if (cloud.CloudApi.Account.Expires <= DateTime.Now)
CloudCache.TryRemove(key, out cloud);
Expand Down
28 changes: 9 additions & 19 deletions WebDavMailRuCloudStore/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public static Task<bool> Remove(this MailRuCloud cloud, IStoreItem item)
{
if (null == item) return Task.FromResult(false);

var storeItem = item as MailruStoreItem;
if (storeItem != null)
if (item is MailruStoreItem storeItem)
return cloud.Remove(storeItem.FileInfo);
var storeCollection = item as MailruStoreCollection;
if (storeCollection != null)
if (item is MailruStoreCollection storeCollection)
return cloud.Remove(storeCollection.DirectoryInfo);

throw new ArgumentException(string.Empty, nameof(item));
Expand All @@ -28,11 +26,9 @@ public static Task<bool> Rename(this MailRuCloud cloud, IStoreItem item, string
{
if (null == item) return Task.FromResult(false);

var storeItem = item as MailruStoreItem;
if (storeItem != null)
if (item is MailruStoreItem storeItem)
return cloud.Rename(storeItem.FileInfo, destinationName);
var storeCollection = item as MailruStoreCollection;
if (storeCollection != null)
if (item is MailruStoreCollection storeCollection)
return cloud.Rename(storeCollection.DirectoryInfo, destinationName);

throw new ArgumentException(string.Empty, nameof(item));
Expand All @@ -42,11 +38,9 @@ public static Task<bool> Move(this MailRuCloud cloud, IStoreItem item, string de
{
if (null == item) return Task.FromResult(false);

var storeItem = item as MailruStoreItem;
if (storeItem != null)
if (item is MailruStoreItem storeItem)
return cloud.Move(storeItem.FileInfo, destinationName);
var storeCollection = item as MailruStoreCollection;
if (storeCollection != null)
if (item is MailruStoreCollection storeCollection)
return cloud.Move(storeCollection.DirectoryInfo, destinationName);

throw new ArgumentException(string.Empty, nameof(item));
Expand All @@ -56,11 +50,9 @@ public static string GetFullPath(this IStoreItem item)
{
if (null == item) return string.Empty;

var storeItem = item as MailruStoreItem;
if (storeItem != null)
if (item is MailruStoreItem storeItem)
return storeItem.FullPath;
var storeCollection = item as MailruStoreCollection;
if (storeCollection != null)
if (item is MailruStoreCollection storeCollection)
return storeCollection.FullPath;

throw new ArgumentException(string.Empty, nameof(item));
Expand All @@ -69,9 +61,7 @@ public static string GetFullPath(this IStoreItem item)

public static long ContentLength(this IHttpRequest request)
{
long res;
long.TryParse(request.GetHeaderValue("Content-Length"), out res);

long.TryParse(request.GetHeaderValue("Content-Length"), out var res);
return res;
}

Expand Down
3 changes: 1 addition & 2 deletions WebDavMailRuCloudStore/Mailru/RequestHandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class RequestHandlerFactory : IRequestHandlerFactory

public IRequestHandler GetRequestHandler(IHttpContext httpContext)
{
IRequestHandler requestHandler;
if (!RequestHandlers.TryGetValue(httpContext.Request.HttpMethod, out requestHandler))
if (!RequestHandlers.TryGetValue(httpContext.Request.HttpMethod, out var requestHandler))
return null;

return requestHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,7 @@ public async Task<StoreItemResult> MoveItemAsync(string sourceName, IStoreCollec
return new StoreItemResult(DavStatusCode.NotFound);


var destinationStoreCollection = destinationCollection as MailruStoreCollection;

if (destinationStoreCollection != null)
if (destinationCollection is MailruStoreCollection destinationStoreCollection)
{
if (!destinationStoreCollection.IsWritable)
return new StoreItemResult(DavStatusCode.PreconditionFailed);
Expand Down Expand Up @@ -482,8 +480,7 @@ public override int GetHashCode()

public override bool Equals(object obj)
{
var storeCollection = obj as MailruStoreCollection;
if (storeCollection == null)
if (!(obj is MailruStoreCollection storeCollection))
return false;
return storeCollection._directoryInfo.FullPath.Equals(_directoryInfo.FullPath, StringComparison.CurrentCultureIgnoreCase);
}
Expand Down
7 changes: 2 additions & 5 deletions WebDavMailRuCloudStore/Mailru/StoreBase/MailruStoreItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Threading.Tasks;
using MailRuCloudApi;
Expand Down Expand Up @@ -223,8 +222,7 @@ public async Task<StoreItemResult> CopyAsync(IStoreCollection destination, strin
{
try
{
var collection = destination as MailruStoreCollection;
if (collection != null)
if (destination is MailruStoreCollection collection)
{
if (!collection.IsWritable)
return new StoreItemResult(DavStatusCode.PreconditionFailed);
Expand Down Expand Up @@ -273,8 +271,7 @@ public override int GetHashCode()

public override bool Equals(object obj)
{
var storeItem = obj as MailruStoreItem;
if (storeItem == null)
if (!(obj is MailruStoreItem storeItem))
return false;
return storeItem._fileInfo.FullPath.Equals(_fileInfo.FullPath, StringComparison.CurrentCultureIgnoreCase);
}
Expand Down
8 changes: 4 additions & 4 deletions WebDavMailRuCloudStore/TwoFaHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public static class TwoFaHandlers
{
static TwoFaHandlers()
{
_handlerTypes = GetHandlers().ToList();
HandlerTypes = GetHandlers().ToList();
}

private static List<Type> _handlerTypes;
private static readonly List<Type> HandlerTypes;


public static ITwoFaHandler Get(string name)
{
var type = _handlerTypes.FirstOrDefault(t => t.Name == name);
var type = HandlerTypes.FirstOrDefault(t => t.Name == name);
if (null == type) return null;

var inst = (ITwoFaHandler)Activator.CreateInstance(type);
Expand All @@ -28,7 +28,7 @@ public static ITwoFaHandler Get(string name)

private static IEnumerable<Type> GetHandlers()
{
foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(typeof(TwoFaHandlers).Assembly.Location), "MailRuCloudApi.TwoFA*.dll", SearchOption.TopDirectoryOnly))
foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(typeof(TwoFaHandlers).Assembly.Location) ?? throw new InvalidOperationException(), "MailRuCloudApi.TwoFA*.dll", SearchOption.TopDirectoryOnly))
{
Assembly assembly = Assembly.LoadFile(file);
foreach (var type in assembly.ExportedTypes)
Expand Down

0 comments on commit f9877dc

Please sign in to comment.