Archived
1
0
Fork 0

fix horrible oversight in IDisposable code

This commit is contained in:
flash 2017-11-13 10:42:07 +01:00
parent af80136e57
commit b39def528d
7 changed files with 57 additions and 81 deletions

View file

@ -21,10 +21,7 @@ namespace Maki
=> Dispose(false);
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
=> Dispose(true);
protected void Dispose(bool disposing)
{
@ -34,6 +31,9 @@ namespace Maki
IsDisposed = true;
Collection.ToList().ForEach(x => Remove(x));
Collection.Clear();
if (disposing)
GC.SuppressFinalize(this);
}
public virtual void Add(T item)

View file

@ -896,7 +896,7 @@ namespace Maki
UserManager.Dispose();
if (disposing)
GC.SuppressFinalize(true);
GC.SuppressFinalize(this);
}
~Discord()

View file

@ -6,171 +6,151 @@ namespace Maki
/// Discord Permission Flags
/// </summary>
[Flags]
public enum DiscordPermission
public enum DiscordPermission : long
{
/// <summary>
/// Allows creation of instant invites
/// </summary>
CreateInstantInvite = 1,
CreateInstantInvite = 0x1,
/// <summary>
/// Allows kicking members
/// </summary>
KickMembers = 1 << 1,
KickMembers = 0x2,
/// <summary>
/// Allows banning members
/// </summary>
BanMembers = 1 << 2,
BanMembers = 0x4,
/// <summary>
/// Allows all permissions and bypasses channel permission overwrites
/// </summary>
Administrator = 1 << 3,
Administrator = 0x8,
/// <summary>
/// Allows management and editing of channels
/// </summary>
ManageChannels = 1 << 4,
ManageChannels = 0x10,
/// <summary>
/// Allows management and editing of the guild
/// </summary>
ManageGuild = 1 << 5,
ManageGuild = 0x20,
/// <summary>
/// Allows for the addition of reactions to messages
/// </summary>
AddReactions = 1 << 6,
AddReactions = 0x40,
/// <summary>
/// Allows viewing the audit log
/// </summary>
ViewAuditLog = 1 << 7,
ViewAuditLog = 0x80,
/// <summary>
/// Allows reading messages in a channel. The channel will not appear for users without this permission
/// </summary>
ReadMessages = 1 << 10,
ReadMessages = 0x400,
/// <summary>
/// Allows for sending messages in a channel.
/// </summary>
SendMessages = 1 << 11,
SendMessages = 0x800,
/// <summary>
/// Allows for sending of /tts messages
/// </summary>
SendTTSMessages = 1 << 12,
SendTTSMessages = 0x1000,
/// <summary>
/// Allows for deletion of other users messages
/// </summary>
ManageMessages = 1 << 13,
ManageMessages = 0x2000,
/// <summary>
/// Links sent by this user will be auto-embedded
/// </summary>
EmbedLinks = 1 << 14,
EmbedLinks = 0x4000,
/// <summary>
/// Allows for uploading images and files
/// </summary>
AttachFiles = 1 << 15,
AttachFiles = 0x8000,
/// <summary>
/// Allows for reading of message history
/// </summary>
ReadMessageHistory = 1 << 16,
ReadMessageHistory = 0x10000,
/// <summary>
/// Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all online users in a channel
/// </summary>
MentionEveryone = 1 << 17,
MentionEveryone = 0x20000,
/// <summary>
/// Allows the usage of custom emojis from other servers
/// </summary>
ExternalEmojis = 1 << 18,
ExternalEmojis = 0x40000,
/// <summary>
/// Allows for joining of a voice channel
/// </summary>
VoiceConnect = 1 << 20,
VoiceConnect = 0x100000,
/// <summary>
/// Allows for speaking in a voice channel
/// </summary>
VoiceSpeak = 1 << 21,
VoiceSpeak = 0x200000,
/// <summary>
/// Allows for muting members in a voice channel
/// </summary>
VoiceMuteMembers = 1 << 22,
VoiceMuteMembers = 0x400000,
/// <summary>
/// Allows for deafening of members in a voice channel
/// </summary>
VoiceDeafenMembers = 1 << 23,
VoiceDeafenMembers = 0x800000,
/// <summary>
/// Allows for moving of members between voice channels
/// </summary>
VoiceMoveMembers = 1 << 24,
VoiceMoveMembers = 0x1000000,
/// <summary>
/// Allows for using voice-activity-detection in a voice channel
/// </summary>
VoiceUseVAD = 1 << 25,
VoiceUseVAD = 0x2000000,
/// <summary>
/// Allows for modification of own nickname
/// </summary>
ChangeNickname = 1 << 26,
ChangeNickname = 0x4000000,
/// <summary>
/// Allows for modification of other users nicknames
/// </summary>
ManageNicknames = 1 << 27,
ManageNicknames = 0x8000000,
/// <summary>
/// Allows management and editing of roles
/// </summary>
ManageRoles = 1 << 28,
ManageRoles = 0x10000000,
/// <summary>
/// Allows management and editing of webhooks
/// </summary>
ManageWebhooks = 1 << 29,
ManageWebhooks = 0x20000000,
/// <summary>
/// Allows management and editing of emojis
/// </summary>
ManageEmojis = 1 << 30,
ManageEmojis = 0x40000000,
/// <summary>
/// Blank permissions
/// </summary>
None = 0,
/// <summary>
/// All Guild related permissions
/// </summary>
AllGuild = CreateInstantInvite | KickMembers | BanMembers | Administrator | ManageChannels | ManageGuild | AddReactions | ViewAuditLog | ChangeNickname | ManageNicknames | ManageRoles | ManageWebhooks | ManageEmojis,
/// <summary>
/// All text channel permissions
/// </summary>
AllText = CreateInstantInvite | ManageChannels | ViewAuditLog | ReadMessages | SendMessages | SendTTSMessages | ManageMessages | EmbedLinks | AttachFiles | ReadMessageHistory | MentionEveryone | ExternalEmojis | ManageRoles | ManageWebhooks | ManageEmojis,
/// <summary>
/// All voice channel permissions
/// </summary>
AllVoice = CreateInstantInvite | ManageChannels | ViewAuditLog | VoiceConnect | VoiceSpeak | VoiceMuteMembers | VoiceDeafenMembers | VoiceMoveMembers | VoiceUseVAD | ManageRoles,
/// <summary>
/// All permissions
/// </summary>
All = CreateInstantInvite | KickMembers | BanMembers | Administrator | ManageChannels | ManageGuild | AddReactions | ViewAuditLog | ReadMessages | SendMessages | SendTTSMessages | ManageMessages | EmbedLinks | AttachFiles | ReadMessageHistory | MentionEveryone | ExternalEmojis | VoiceConnect | VoiceSpeak | VoiceMuteMembers | VoiceDeafenMembers | VoiceMoveMembers | VoiceUseVAD | ChangeNickname | ManageNicknames | ManageRoles | ManageWebhooks | ManageEmojis,
}
}

View file

@ -11,20 +11,20 @@ namespace Maki.Gateway
/// <summary>
/// Subject shard
/// </summary>
private readonly GatewayShard shard;
private readonly GatewayShard Shard;
/// <summary>
/// Interval timer for repeating the request
/// </summary>
private Timer timer = null;
private Timer Timer = null;
/// <summary>
/// Constructor
/// </summary>
/// <param name="s">Parent GatewayShard instance</param>
public GatewayHeartbeatManager(GatewayShard s)
/// <param name="shard">Parent GatewayShard instance</param>
public GatewayHeartbeatManager(GatewayShard shard)
{
shard = s;
Shard = shard;
}
/// <summary>
@ -32,10 +32,10 @@ namespace Maki.Gateway
/// </summary>
public void Start()
{
if (timer != null)
if (Timer != null)
Stop();
timer = new Timer(Handler, null, TimeSpan.Zero, shard.HeartbeatInterval);
Timer = new Timer(Handler, null, TimeSpan.Zero, Shard.HeartbeatInterval);
}
/// <summary>
@ -44,7 +44,7 @@ namespace Maki.Gateway
/// <param name="state"></param>
private void Handler(object state)
{
shard.Send(GatewayOPCode.Heartbeat, shard.LastSequence);
Shard.Send(GatewayOPCode.Heartbeat, Shard.LastSequence);
}
/// <summary>
@ -52,11 +52,11 @@ namespace Maki.Gateway
/// </summary>
public void Stop()
{
if (timer == null)
if (Timer == null)
return;
timer.Dispose();
timer = null;
Timer.Dispose();
Timer = null;
}
}
}

View file

@ -418,23 +418,21 @@ namespace Maki.Gateway
private void Dispose(bool disposing)
{
if (!IsDisposed)
{
IsDisposed = true;
Disconnect();
}
if (IsDisposed)
return;
IsDisposed = true;
Disconnect();
if (disposing)
GC.SuppressFinalize(this);
}
~GatewayShard()
{
Dispose(false);
}
=> Dispose(false);
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
=> Dispose(true);
#endregion

View file

@ -286,7 +286,7 @@ namespace Maki.Gateway
Disconnect();
if (disposing)
GC.SuppressFinalize(true);
GC.SuppressFinalize(this);
}
~GatewayShardClient()

View file

@ -53,7 +53,6 @@ namespace Maki.Rest
get
{
if (RawResponseValue == null)
{
using (MemoryStream ms = new MemoryStream())
{
byte[] bytes = new byte[4096];
@ -66,7 +65,6 @@ namespace Maki.Rest
RawResponseValue = new byte[ms.Length];
ms.Read(RawResponseValue, 0, RawResponseValue.Length);
}
}
return RawResponseValue;
}
@ -261,7 +259,7 @@ namespace Maki.Rest
HttpWebResponse?.Close();
if (disposing)
GC.SuppressFinalize(true);
GC.SuppressFinalize(this);
}
~WebRequest()