Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Major Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptominer937 committed Jan 14, 2018
1 parent 18661ba commit 923e295
Show file tree
Hide file tree
Showing 202 changed files with 7,319 additions and 5,077 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MyDownloader.Core
{
Expand All @@ -26,4 +24,4 @@ public CalculatedSegment(long startPos, long endPos)
this.startPosition = startPos;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MyDownloader.Core.Common
{
public static class BoolFormatter
Expand All @@ -21,4 +17,4 @@ public static string ToString(bool v)
return No;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MyDownloader.Core.Common
{
Expand Down Expand Up @@ -35,4 +33,4 @@ public static string ToString(long size)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MyDownloader.Core.Common
Expand All @@ -17,4 +14,4 @@ public static string GetWithBackslash(string path)
return path;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MyDownloader.Core.Common
{
Expand All @@ -25,4 +23,4 @@ public static string ToString(TimeSpan ts)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace MyDownloader.Core.Concurrency
Expand All @@ -9,9 +7,9 @@ public class ObjectLocker : IDisposable
{
#region Fields

private object obj;
private object obj;

#endregion
#endregion Fields

#region Constructor

Expand All @@ -21,7 +19,7 @@ public ObjectLocker(object obj)
Monitor.Enter(this.obj);
}

#endregion
#endregion Constructor

#region IDisposable Members

Expand All @@ -30,6 +28,6 @@ public void Dispose()
Monitor.Exit(this.obj);
}

#endregion
}
}
#endregion IDisposable Members
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace MyDownloader.Core.Concurrency
{
public class ReaderWriterObjectLocker
{
#region BaseReleaser
class BaseReleaser

private class BaseReleaser
{
protected ReaderWriterObjectLocker locker;

Expand All @@ -17,10 +16,12 @@ public BaseReleaser(ReaderWriterObjectLocker locker)
this.locker = locker;
}
}
#endregion

#endregion BaseReleaser

#region ReaderReleaser
class ReaderReleaser : BaseReleaser, IDisposable

private class ReaderReleaser : BaseReleaser, IDisposable
{
public ReaderReleaser(ReaderWriterObjectLocker locker)
: base(locker)
Expand All @@ -34,12 +35,14 @@ public void Dispose()
locker.locker.ReleaseReaderLock();
}

#endregion
#endregion IDisposable Members
}
#endregion

#endregion ReaderReleaser

#region WriterReleaser
class WriterReleaser : BaseReleaser, IDisposable

private class WriterReleaser : BaseReleaser, IDisposable
{
public WriterReleaser(ReaderWriterObjectLocker locker)
: base(locker)
Expand All @@ -53,28 +56,34 @@ public void Dispose()
locker.locker.ReleaseWriterLock();
}

#endregion
#endregion IDisposable Members
}
#endregion

#endregion WriterReleaser

#region Fields

private ReaderWriterLock locker;
private IDisposable writerReleaser;
private IDisposable readerReleaser;
#endregion
private IDisposable readerReleaser;

#endregion Fields

#region Constructor

public ReaderWriterObjectLocker()
{
// TODO: update to ReaderWriterLockSlim on .net 3.5
locker = new ReaderWriterLock();

writerReleaser = new WriterReleaser(this);
readerReleaser = new ReaderReleaser(this);
}
#endregion
}

#endregion Constructor

#region Methods

public IDisposable LockForRead()
{
locker.AcquireReaderLock(-1);
Expand All @@ -87,7 +96,8 @@ public IDisposable LockForWrite()
locker.AcquireWriterLock(-1);

return writerReleaser;
}
#endregion
}

#endregion Methods
}
}
}
29 changes: 13 additions & 16 deletions 3rdparty/DownloadManager/MyDownloader.Core/DownloadManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using MyDownloader.Core.Concurrency;
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections;
using System.Threading;
using MyDownloader.Core.Concurrency;

namespace MyDownloader.Core
{
Expand All @@ -20,17 +17,17 @@ public static DownloadManager Instance
{
return instance;
}
}
}

#endregion
#endregion Singleton

#region Fields

private List<Downloader> downloads = new List<Downloader>();
private int addBatchCount;
private ReaderWriterObjectLocker downloadListSync = new ReaderWriterObjectLocker();

#endregion
#endregion Fields

#region Properties

Expand All @@ -54,7 +51,7 @@ public ReadOnlyCollection<Downloader> Downloads

public double TotalDownloadRate
{
get
get
{
double total = 0;

Expand All @@ -69,7 +66,7 @@ public double TotalDownloadRate
}
}

return total;
return total;
}
}

Expand All @@ -81,11 +78,13 @@ public int AddBatchCount
}
}

#endregion
#endregion Properties



#region Methods

void downloader_StateChanged(object sender, EventArgs e)
private void downloader_StateChanged(object sender, EventArgs e)
{
Downloader downloader = (Downloader)sender;

Expand Down Expand Up @@ -266,8 +265,6 @@ private void InternalSwap(int idx)
this.downloads.Insert(idx, it2);
}

#endregion


#endregion Methods
}
}
}
Loading

0 comments on commit 923e295

Please sign in to comment.