Adds style cop (#109)
This commit is contained in:
parent
3e715bcb60
commit
556a17aba8
1725 changed files with 33831 additions and 38046 deletions
|
|
@ -1,22 +1,23 @@
|
|||
/***************************************************************************
|
||||
* Serialization.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: AsyncWriter.cs *
|
||||
* Created: 2020/12/30 - Updated: 2020/04/25 *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -29,7 +30,7 @@ namespace Server
|
|||
{
|
||||
public sealed class AsyncWriter : IGenericWriter
|
||||
{
|
||||
private readonly int BufferSize;
|
||||
private readonly int m_BufferSize;
|
||||
private BinaryWriter m_Bin;
|
||||
private bool m_Closed;
|
||||
private readonly FileStream m_File;
|
||||
|
|
@ -40,26 +41,26 @@ namespace Server
|
|||
private Thread m_WorkerThread;
|
||||
|
||||
private readonly Queue<MemoryStream> m_WriteQueue;
|
||||
private readonly bool PrefixStrings;
|
||||
private readonly bool m_PrefixStrings;
|
||||
|
||||
public AsyncWriter(string filename, bool prefix)
|
||||
: this(filename, 1048576, prefix) //1 mb buffer
|
||||
: this(filename, 1048576, prefix) // 1 mb buffer
|
||||
{
|
||||
}
|
||||
|
||||
public AsyncWriter(string filename, int buffSize, bool prefix)
|
||||
{
|
||||
PrefixStrings = prefix;
|
||||
m_PrefixStrings = prefix;
|
||||
m_Closed = false;
|
||||
m_WriteQueue = new Queue<MemoryStream>();
|
||||
BufferSize = buffSize;
|
||||
m_BufferSize = buffSize;
|
||||
|
||||
m_File = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
m_Mem = new MemoryStream(BufferSize + 1024);
|
||||
m_Mem = new MemoryStream(m_BufferSize + 1024);
|
||||
m_Bin = new BinaryWriter(m_Mem, Utility.UTF8WithEncoding);
|
||||
}
|
||||
|
||||
public static int ThreadCount{ get; private set; }
|
||||
public static int ThreadCount { get; private set; }
|
||||
|
||||
public MemoryStream MemStream
|
||||
{
|
||||
|
|
@ -95,13 +96,13 @@ namespace Server
|
|||
|
||||
private void OnWrite()
|
||||
{
|
||||
long curlen = m_Mem.Length;
|
||||
var curlen = m_Mem.Length;
|
||||
m_CurPos += curlen - m_LastPos;
|
||||
m_LastPos = curlen;
|
||||
if (curlen >= BufferSize)
|
||||
if (curlen >= m_BufferSize)
|
||||
{
|
||||
Enqueue(m_Mem);
|
||||
m_Mem = new MemoryStream(BufferSize + 1024);
|
||||
m_Mem = new MemoryStream(m_BufferSize + 1024);
|
||||
m_Bin = new BinaryWriter(m_Mem, Utility.UTF8WithEncoding);
|
||||
m_LastPos = 0;
|
||||
}
|
||||
|
|
@ -121,7 +122,7 @@ namespace Server
|
|||
|
||||
public void Write(string value)
|
||||
{
|
||||
if (PrefixStrings)
|
||||
if (m_PrefixStrings)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
|
|
@ -143,8 +144,8 @@ namespace Server
|
|||
|
||||
public void WriteDeltaTime(DateTime value)
|
||||
{
|
||||
long ticks = value.Ticks;
|
||||
long now = DateTime.UtcNow.Ticks;
|
||||
var ticks = value.Ticks;
|
||||
var now = DateTime.UtcNow.Ticks;
|
||||
|
||||
TimeSpan d;
|
||||
|
||||
|
|
@ -199,7 +200,7 @@ namespace Server
|
|||
|
||||
public void WriteEncodedInt(int value)
|
||||
{
|
||||
uint v = (uint)value;
|
||||
var v = (uint)value;
|
||||
|
||||
while (v >= 0x80)
|
||||
{
|
||||
|
|
@ -269,6 +270,7 @@ namespace Server
|
|||
m_Bin.Write(value, 0, length);
|
||||
OnWrite();
|
||||
}
|
||||
|
||||
public void Write(sbyte value)
|
||||
{
|
||||
m_Bin.Write(value);
|
||||
|
|
@ -351,7 +353,7 @@ namespace Server
|
|||
if (value == null)
|
||||
Write(0);
|
||||
else
|
||||
Write(value.Id);
|
||||
Write(value.Serial);
|
||||
}
|
||||
|
||||
public void WriteItem<T>(T value) where T : Item
|
||||
|
|
@ -387,7 +389,7 @@ namespace Server
|
|||
public void WriteItemList<T>(List<T> list, bool tidy) where T : Item
|
||||
{
|
||||
if (tidy)
|
||||
for (int i = 0; i < list.Count;)
|
||||
for (var i = 0; i < list.Count;)
|
||||
if (list[i].Deleted)
|
||||
list.RemoveAt(i);
|
||||
else
|
||||
|
|
@ -395,7 +397,7 @@ namespace Server
|
|||
|
||||
Write(list.Count);
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
Write(list[i]);
|
||||
}
|
||||
|
||||
|
|
@ -410,7 +412,7 @@ namespace Server
|
|||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (Item item in set) Write(item);
|
||||
foreach (var item in set) Write(item);
|
||||
}
|
||||
|
||||
public void WriteItemSet<T>(HashSet<T> set) where T : Item
|
||||
|
|
@ -424,7 +426,7 @@ namespace Server
|
|||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (T item in set) Write(item);
|
||||
foreach (var item in set) Write(item);
|
||||
}
|
||||
|
||||
public void Write(List<Mobile> list)
|
||||
|
|
@ -435,7 +437,7 @@ namespace Server
|
|||
public void Write(List<Mobile> list, bool tidy)
|
||||
{
|
||||
if (tidy)
|
||||
for (int i = 0; i < list.Count;)
|
||||
for (var i = 0; i < list.Count;)
|
||||
if (list[i].Deleted)
|
||||
list.RemoveAt(i);
|
||||
else
|
||||
|
|
@ -443,7 +445,7 @@ namespace Server
|
|||
|
||||
Write(list.Count);
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
Write(list[i]);
|
||||
}
|
||||
|
||||
|
|
@ -455,7 +457,7 @@ namespace Server
|
|||
public void WriteMobileList<T>(List<T> list, bool tidy) where T : Mobile
|
||||
{
|
||||
if (tidy)
|
||||
for (int i = 0; i < list.Count;)
|
||||
for (var i = 0; i < list.Count;)
|
||||
if (list[i].Deleted)
|
||||
list.RemoveAt(i);
|
||||
else
|
||||
|
|
@ -463,7 +465,7 @@ namespace Server
|
|||
|
||||
Write(list.Count);
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
Write(list[i]);
|
||||
}
|
||||
|
||||
|
|
@ -478,7 +480,7 @@ namespace Server
|
|||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (Mobile mob in set) Write(mob);
|
||||
foreach (var mob in set) Write(mob);
|
||||
}
|
||||
|
||||
public void WriteMobileSet<T>(HashSet<T> set) where T : Mobile
|
||||
|
|
@ -492,7 +494,7 @@ namespace Server
|
|||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (T mob in set) Write(mob);
|
||||
foreach (var mob in set) Write(mob);
|
||||
}
|
||||
|
||||
public void Write(List<BaseGuild> list)
|
||||
|
|
@ -503,7 +505,7 @@ namespace Server
|
|||
public void Write(List<BaseGuild> list, bool tidy)
|
||||
{
|
||||
if (tidy)
|
||||
for (int i = 0; i < list.Count;)
|
||||
for (var i = 0; i < list.Count;)
|
||||
if (list[i].Disbanded)
|
||||
list.RemoveAt(i);
|
||||
else
|
||||
|
|
@ -511,7 +513,7 @@ namespace Server
|
|||
|
||||
Write(list.Count);
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
Write(list[i]);
|
||||
}
|
||||
|
||||
|
|
@ -523,7 +525,7 @@ namespace Server
|
|||
public void WriteGuildList<T>(List<T> list, bool tidy) where T : BaseGuild
|
||||
{
|
||||
if (tidy)
|
||||
for (int i = 0; i < list.Count;)
|
||||
for (var i = 0; i < list.Count;)
|
||||
if (list[i].Disbanded)
|
||||
list.RemoveAt(i);
|
||||
else
|
||||
|
|
@ -531,7 +533,7 @@ namespace Server
|
|||
|
||||
Write(list.Count);
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
Write(list[i]);
|
||||
}
|
||||
|
||||
|
|
@ -546,7 +548,7 @@ namespace Server
|
|||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (BaseGuild guild in set) Write(guild);
|
||||
foreach (var guild in set) Write(guild);
|
||||
}
|
||||
|
||||
public void WriteGuildSet<T>(HashSet<T> set) where T : BaseGuild
|
||||
|
|
@ -560,7 +562,7 @@ namespace Server
|
|||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (T guild in set) Write(guild);
|
||||
foreach (var guild in set) Write(guild);
|
||||
}
|
||||
|
||||
private class WorkerThread
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue