Skip to content

Commit

Permalink
Use BuiltIn Counters by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesWu committed Mar 22, 2016
1 parent e3b2dda commit 55352a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
7 changes: 6 additions & 1 deletion UniFTP.Client/UniFTP.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="FtpClient.cs" />
<Compile Include="Connection.cs" />
<Compile Include="FtpServerConnection.cs" />
<Compile Include="Helper.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Response.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion UniFTP.Server/FtpConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum CounterType
[Serializable]
public class FtpConfig
{
public FtpConfig(string homeDir = null, string name = "UniFTP", bool allowAnonymous = true, string owner = "UniFTP",string ownerGroup="UniFTP",string[] welcome = null,string[] loginWelcome = null,string[] logoutWelcome = null, CounterType counter = CounterType.System)
public FtpConfig(string homeDir = null, string name = "UniFTP", bool allowAnonymous = true, string owner = "UniFTP",string ownerGroup="UniFTP",string[] welcome = null,string[] loginWelcome = null,string[] logoutWelcome = null, CounterType counter = CounterType.BuiltIn)
{
HomeDir = homeDir;
//if (homeDir == null)
Expand Down
22 changes: 18 additions & 4 deletions UniFTP.Server/FtpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public class FtpServer : Server<FtpClientConnection>
public FtpConfig Config
{
get { return _config; }
set { _config = value; }
set
{
_config = value;
InitServer(_config != null ? _config.ServerName : "UniFTP");
}
}
/// <summary>
/// 用户组
Expand Down Expand Up @@ -367,13 +371,14 @@ public FtpServer(int port, string logHeader = null)
/// <param name="logHeader">日志头,也用作性能计数器的实例划分,请传入服务器名</param>
public FtpServer(int port, FtpConfig config = null, bool enableIPv6 = false, int ipv6Port = -1, string logHeader = null)
//: this(IPAddress.Any, port, enableIPv6, ipv6Port, logHeader)
: base(new[] { new IPEndPoint(IPAddress.Any, port) , enableIPv6 ? new IPEndPoint(IPAddress.IPv6Any, (ipv6Port > 0 ? ipv6Port : port)) : null }, logHeader)
: base(new[] { new IPEndPoint(IPAddress.Any, port), enableIPv6 ? new IPEndPoint(IPAddress.IPv6Any, (ipv6Port > 0 ? ipv6Port : port)) : null }, logHeader)
{
Config = config;
if (logHeader == null && config != null)
{
logHeader = config.ServerName;
}
Active = false;
InitServer(logHeader);
}

Expand All @@ -390,28 +395,37 @@ public FtpServer(IPAddress ipAddress, int port, bool enableIPv6 = false, int ipv
public FtpServer(IPEndPoint[] localEndPoints, string logHeader = "UniFTP")
: base(localEndPoints, logHeader)
{
Active = false;
InitServer(logHeader);
}

private void InitServer(string logHeader)
{
Active = false;
if (File.Exists("UniFTP.Server.log4net"))
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo("UniFTP.Server.log4net"));
}
UserGroups.Clear();
UserGroups.Add("anonymous", FtpUserGroup.Anonymous);
Users.Clear();
if (Config.AllowAnonymous)
{
Users.Add("anonymous", FtpUser.Anonymous);
}
OnLog += sender => { };
if (OnLog == null)
{
OnLog += sender => { };
}
ConnectionInfos = new List<FtpConnectionInfo>();
//foreach (var endPoint in localEndPoints)
//{
// //_performanceCounter.Initialize(endPoint.Port);
//}
SetCounter(logHeader);
}

private void SetCounter(string logHeader = "UniFTP")
{
try
{
switch (Config.CounterType)
Expand Down

0 comments on commit 55352a9

Please sign in to comment.