Permalink
Browse files

let resharper optimize some code

  • Loading branch information...
lformella committed Nov 12, 2012
1 parent d0036e5 commit dddbbef0588ee9d2ad0cdd6cd54f2b9238c71472
Showing with 844 additions and 919 deletions.
  1. +2 −4 Core.Test/Helper.cs
  2. +2 −3 Core.Test/Object.cs
  3. +2 −2 Core.Test/Objects.cs
  4. +1 −9 Core/AObject.cs
  5. +14 −24 Core/AObjects.cs
  6. +8 −6 Core/Bot.cs
  7. +5 −5 Core/Channel.cs
  8. +5 −6 Core/Extensions.cs
  9. +1 −1 Core/File.cs
  10. +5 −3 Core/Files.cs
  11. +1 −4 Core/Helper.cs
  12. +5 −7 Core/Server.cs
  13. +1 −4 Core/Servers.cs
  14. +9 −10 Server.Cmd/Cmd.cs
  15. +37 −44 Server.Plugin.Backend.File/BackendPlugin.cs
  16. +37 −38 Server.Plugin.Backend.MySql/BackendPlugin.cs
  17. +12 −12 Server.Plugin.General.Jabber/Plugin.cs
  18. +21 −25 Server.Plugin.General.Webserver/BrowserConnection.cs
  19. +79 −83 Server.Plugin.General.Webserver/FileLoader.cs
  20. +6 −7 Server.Plugin.General.Webserver/Json.cs
  21. +14 −13 Server.Plugin.General.Webserver/Plugin.cs
  22. +6 −6 Server.Test/Helper/Filesystem.cs
  23. +6 −9 Server.Test/Helper/Process.cs
  24. +48 −51 Server.Test/Irc/AParser.cs
  25. +6 −6 Server.Test/Irc/Notice.cs
  26. +2 −2 Server.Test/Irc/Parser.cs
  27. +34 −35 Server.Test/Irc/PrivateMessage.cs
  28. +26 −31 Server/BotConnection.cs
  29. +18 −19 Server/Connection/Connection.cs
  30. +124 −127 Server/Helper/FileActions.cs
  31. +1 −1 Server/Helper/FileHandler.cs
  32. +1 −1 Server/Helper/FileHandlerProcess.cs
  33. +14 −12 Server/Helper/FileSystem.cs
  34. +17 −12 Server/Helper/Process.cs
  35. +4 −4 Server/Irc/AParser.cs
  36. +9 −9 Server/Irc/IntValue.cs
  37. +13 −13 Server/Irc/Nickserv.cs
  38. +37 −39 Server/Irc/Notice.cs
  39. +16 −16 Server/Irc/Parser.cs
  40. +51 −56 Server/Irc/PrivateMessage.cs
  41. +33 −37 Server/Main.cs
  42. +5 −6 Server/Plugin/APlugin.cs
  43. +5 −5 Server/ServerConnection.cs
  44. +29 −34 Server/Servers.cs
  45. +11 −9 Server/Settings.cs
  46. +39 −45 Server/Statistic.cs
  47. +3 −3 Server/Worker/ALoopWorker.cs
  48. +3 −3 Server/Worker/AWorker.cs
  49. +11 −12 Server/Worker/BotWatchdogWorker.cs
  50. +5 −6 Server/Worker/SnapshotWorker.cs
View
@@ -21,8 +21,6 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-using System;
-
using NUnit.Framework;
namespace XG.Core.Test
@@ -33,8 +31,8 @@ public class Helper
[Test]
public void ShrinkFileName()
{
- string fileName = "This_(is).-an_Evil)(File-_-name_[Test].txt";
- Int64 fileSize = 440044;
+ const string fileName = "This_(is).-an_Evil)(File-_-name_[Test].txt";
+ const long fileSize = 440044;
string result = Core.Helper.ShrinkFileName(fileName, fileSize);
Assert.AreEqual("thisisanevilfilenametesttxt.440044/", result);
View
@@ -35,7 +35,7 @@ public class Object
[Test]
public void Test()
{
- Core.Object obj = new Core.Object();
+ var obj = new Core.Object();
obj.Changed += delegate { _modified = true; };
AssertModified(obj, false);
@@ -48,8 +48,7 @@ public void Test()
obj.Connected = true;
AssertModified(obj, true);
- Core.Object parent = new Core.Object();
- parent.Guid = Guid.NewGuid();
+ var parent = new Core.Object {Guid = Guid.NewGuid()};
Assert.AreEqual(Guid.Empty, obj.ParentGuid);
obj.Parent = parent;
View
@@ -35,13 +35,13 @@ public class Objects
[Test]
public void Test()
{
- Core.Objects parent = new Core.Objects();
+ var parent = new Core.Objects();
parent.Added += delegate { _childAdded = true; };
parent.Guid = Guid.NewGuid();
AssertChildAdded(false);
- Core.Object obj = new Core.Object();
+ var obj = new Core.Object();
Assert.AreEqual(Guid.Empty, obj.ParentGuid);
parent.Add(obj);
View
@@ -92,14 +92,7 @@ public virtual AObject Parent
if (_parent != value)
{
_parent = value;
- if (_parent != null)
- {
- _parentGuid = _parent.Guid;
- }
- else
- {
- _parentGuid = Guid.Empty;
- }
+ _parentGuid = _parent != null ? _parent.Guid : Guid.Empty;
}
}
}
@@ -172,7 +165,6 @@ public virtual bool Enabled
public DateTime EnabledTime
{
get { return _enabledTime; }
- private set { throw new NotSupportedException("You can not set this Property."); }
}
#endregion
View
@@ -67,14 +67,7 @@ protected void FireRemoved(AObjects aObjects, AObject aObject)
protected object ObjectLock
{
- get
- {
- if (_objectLock == null)
- {
- _objectLock = new object();
- }
- return _objectLock;
- }
+ get { return _objectLock ?? (_objectLock = new object()); }
}
readonly List<AObject> _children;
@@ -105,10 +98,9 @@ protected bool Add(AObject aObject)
aObject.EnabledChanged += FireEnabledChanged;
aObject.Changed += FireChanged;
- if (aObject is AObjects)
+ var aObjects = aObject as AObjects;
+ if (aObjects != null)
{
- AObjects aObjects = (AObjects) aObject;
-
aObjects.Added += FireAdded;
aObjects.Removed += FireRemoved;
}
@@ -137,10 +129,9 @@ protected bool Remove(AObject aObject)
aObject.EnabledChanged -= FireEnabledChanged;
aObject.Changed -= FireChanged;
- if (aObject is AObjects)
+ var aObjects = aObject as AObjects;
+ if (aObjects != null)
{
- AObjects aObjects = (AObjects) aObject;
-
aObjects.Added -= FireAdded;
aObjects.Removed -= FireRemoved;
}
@@ -161,10 +152,9 @@ public void AttachChildEvents()
tObject.EnabledChanged += FireEnabledChanged;
tObject.Changed += FireChanged;
- if (tObject is AObjects)
+ var tObjects = tObject as AObjects;
+ if (tObjects != null)
{
- AObjects tObjects = (AObjects) tObject;
-
tObjects.Added += FireAdded;
tObjects.Removed += FireRemoved;
@@ -192,10 +182,9 @@ public virtual AObject WithGuid(Guid aGuid)
tObjectReturn = tObject;
break;
}
- else if (tObject is AObjects)
+ var tObjects = tObject as AObjects;
+ if (tObjects != null)
{
- AObjects tObjects = (AObjects) tObject;
-
tObjectReturn = tObjects.WithGuid(aGuid);
if (tObjectReturn != null)
{
@@ -208,13 +197,14 @@ public virtual AObject WithGuid(Guid aGuid)
public virtual AObject Named(string aName)
{
- AObject tObject = null;
try
{
- tObject = All.First(obj => obj.Name.Trim().ToLower() == aName.Trim().ToLower());
+ return All.First(obj => obj.Name.Trim().ToLower() == aName.Trim().ToLower());
+ }
+ catch (Exception)
+ {
+ return null;
}
- catch {}
- return tObject;
}
public AObject Next(AObject aObject)
View
@@ -85,7 +85,7 @@ public States State
[NonSerialized]
IPAddress _ip = IPAddress.None;
- public IPAddress IP
+ public IPAddress Ip
{
get { return _ip; }
set { SetProperty(ref _ip, value); }
@@ -208,7 +208,7 @@ public double Speed
public IEnumerable<Packet> Packets
{
- get { return base.All.Cast<Packet>(); }
+ get { return All.Cast<Packet>(); }
}
public Packet Packet(int aId)
@@ -217,18 +217,20 @@ public Packet Packet(int aId)
{
return Packets.First(pack => pack.Id == aId);
}
- catch {}
- return null;
+ catch (Exception)
+ {
+ return null;
+ }
}
public void AddPacket(Packet aPacket)
{
- base.Add(aPacket);
+ Add(aPacket);
}
public void RemovePacket(Packet aPacket)
{
- base.Remove(aPacket);
+ Remove(aPacket);
}
public Packet OldestActivePacket()
View
@@ -45,7 +45,7 @@ public override bool Connected
{
foreach (AObject obj in All)
{
- obj.Connected = value;
+ obj.Connected = false;
}
}
base.Connected = value;
@@ -74,22 +74,22 @@ public int ErrorCode
public IEnumerable<Bot> Bots
{
- get { return base.All.Cast<Bot>(); }
+ get { return All.Cast<Bot>(); }
}
public Bot Bot(string aName)
{
- return (Bot) base.Named(aName);
+ return base.Named(aName) as Bot;
}
public void AddBot(Bot aBot)
{
- base.Add(aBot);
+ Add(aBot);
}
public void RemoveBot(Bot aBot)
{
- base.Remove(aBot);
+ Remove(aBot);
}
#endregion
View
@@ -30,7 +30,7 @@ public static class Extensions
{
public static string ToAscii(this string aString)
{
- StringBuilder output = new StringBuilder(string.Empty);
+ var output = new StringBuilder(string.Empty);
if (!string.IsNullOrEmpty(aString))
{
for (int i = 0; i < aString.Length; i++)
@@ -43,16 +43,15 @@ public static string ToAscii(this string aString)
public static Int64 ToTimestamp(this DateTime aDate)
{
- DateTime date = new DateTime(1970, 1, 1);
- TimeSpan ts = new TimeSpan(aDate.Ticks - date.Ticks);
+ var date = new DateTime(1970, 1, 1);
+ var ts = new TimeSpan(aDate.Ticks - date.Ticks);
return (Convert.ToInt64(ts.TotalSeconds));
}
public static DateTime ToDate(this Int64 aTimestamp)
{
- DateTime date = new DateTime(1970, 1, 1);
- date.AddSeconds(aTimestamp);
- return date;
+ var date = new DateTime(1970, 1, 1);
+ return date.AddSeconds(aTimestamp);
}
public static bool IsEqualWith(this byte[] aBytes1, byte[] aBytes2)
View
@@ -72,7 +72,7 @@ public Int64 Size
[DataMember]
public List<FilePart> Parts
{
- get { return base.All.Cast<FilePart>().ToList(); }
+ get { return All.Cast<FilePart>().ToList(); }
private set { throw new NotSupportedException("You can not set this Property."); }
}
View
@@ -41,8 +41,10 @@ public File File(string tmpPath)
{
return All.First(file => file.TmpPath == tmpPath);
}
- catch {}
- return null;
+ catch (Exception)
+ {
+ return null;
+ }
}
public void Add(File aFile)
@@ -52,7 +54,7 @@ public void Add(File aFile)
public void Add(string aName, Int64 aSize)
{
- File tFile = new File(aName, aSize);
+ var tFile = new File(aName, aSize);
if (File(tFile.TmpPath) == null)
{
Add(tFile);
View
@@ -149,10 +149,7 @@ public static string ShrinkFileName(string aName, Int64 aSize)
{
return Regex.Replace(aName, "(\\(|\\)|\\[|\\]|\\{|\\}|-|_|\\.)", "").ToLower() + "." + aSize + "/";
}
- else
- {
- return "";
- }
+ return "";
}
}
}
View
@@ -44,7 +44,7 @@ public override bool Connected
{
foreach (AObject obj in All)
{
- obj.Connected = value;
+ obj.Connected = false;
}
}
base.Connected = value;
@@ -83,7 +83,7 @@ public SocketErrorCode ErrorCode
public IEnumerable<Channel> Channels
{
- get { return base.All.Cast<Channel>(); }
+ get { return All.Cast<Channel>(); }
}
public Channel Channel(string aName)
@@ -111,7 +111,7 @@ public Bot Bot(string aName)
public void AddChannel(Channel aChannel)
{
- base.Add(aChannel);
+ Add(aChannel);
}
public void AddChannel(string aChannel)
@@ -123,16 +123,14 @@ public void AddChannel(string aChannel)
}
if (Channel(aChannel) == null)
{
- Channel tChannel = new Channel();
- tChannel.Name = aChannel;
- tChannel.Enabled = Enabled;
+ var tChannel = new Channel {Name = aChannel, Enabled = Enabled};
AddChannel(tChannel);
}
}
public void RemoveChannel(Channel aChannel)
{
- base.Remove(aChannel);
+ Remove(aChannel);
}
#endregion
View
@@ -50,10 +50,7 @@ public void Add(string aServer)
aServer = aServer.Trim().ToLower();
if (Server(aServer) == null)
{
- Server tServer = new Server();
- tServer.Name = aServer;
- tServer.Port = 6667;
- tServer.Enabled = true;
+ var tServer = new Server {Name = aServer, Port = 6667, Enabled = true};
Add(tServer);
}
}
Oops, something went wrong.

0 comments on commit dddbbef

Please sign in to comment.