Skip to content

Commit

Permalink
修复了一些小BUG,增加了一些视觉效果
Browse files Browse the repository at this point in the history
  • Loading branch information
macworld committed Apr 20, 2014
1 parent 5b604d0 commit 626d1b6
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 303 deletions.
4 changes: 3 additions & 1 deletion CommonLib/0.CommonLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="Log\Log.config" />
<None Include="Log\Log.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Properties\CommonLibSettings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>CommonLibSettings.Designer.cs</LastGenOutput>
Expand Down
51 changes: 5 additions & 46 deletions CommonLib/Log/Log.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,19 @@
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<log4net>
<logger name="ZWFLogger">
<appender name="WindowsFormAppender" type="CommonLib.WindowsFormAppender">
<userName value="DebugWindowOfZWF"/>
<enabled value="false" />
<visible value="false"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
</layout>
</appender>
<logger name="WinLogger">
<appender name="WindowsMessageQueueAppender" type="CommonLib.WindowsMessageQueueAppender">
<windowClass value=""/>
<windowName value="MainWindow"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
</layout>
</appender>
</logger>

<logger name="YXCLogger">
<appender name="WindowsFormAppender" type="CommonLib.WindowsFormAppender">
<userName value="DebugWindowOfYXC"/>
<enabled value="false" />
<visible value="false"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
</layout>
</appender>
</logger>

<logger name="LWHLogger">
<appender name="WindowsFormAppender" type="CommonLib.WindowsFormAppender">
<userName value="DebugWindowOfLWH"/>
<enabled value="false" />
<visible value="false"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
</layout>
</appender>
</logger>

<logger name="WJLogger">
<appender name="WindowsFormAppender" type="CommonLib.WindowsFormAppender">
<userName value="DebugWindowOfWJ"/>
<enabled value="false" />
<visible value="false"/>
<windowName value="EasyWebSever (Beta)"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
</layout>
</appender>
</logger>
<logger name="AppLogger">
<appender name="ConsoleAppender" type="Log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
</layout>
</appender>

Expand All @@ -68,7 +27,7 @@
<datePattern value="yyyyMMdd"/>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
<conversionPattern value="[%date{yyyy.MM.dd-HH:mm:ss}] %message%newline" />
</layout>
</appender>
</logger>
Expand Down
10 changes: 7 additions & 3 deletions FileManager/FileBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public void Run()
FileWatcher.getInstance().Run();
FileSystem.GetInstance().ResetSeverDirectory();
Logger log = new Logger("AppLogger");
log.Info("FileBuffer & FileWatcher start to run");
log.Info("FileBuffer Module started");
isRun = true;
}
else
{
Logger log = new Logger("AppLogger");
log.Info("FileBuffer has already run");
log.Info("FileBuffer has already started");
}
}
/// <summary>
Expand All @@ -88,7 +88,7 @@ public void Stop()
isRun = false;
FileWatcher.getInstance().Stop();
Logger log = new Logger("AppLogger");
log.Info("FileBuffer & FileWatcher was stopped");
log.Info("FileBuffer Module stopped");
clear();
}
else
Expand Down Expand Up @@ -192,6 +192,8 @@ private bool SaveFile(Byte[] fileByteStream, string url)
}
urlToPageDic.Add(url, urlPages);//added to the dictionnary which is used as a page table
fileLengthDictionary.Add(url, fileLength);//add to the dictionnary when it has been saved in the memory
Logger log = new Logger("AppLogger");
log.Debug("Add file: " + url + " in buffer");
}
}
return true;
Expand Down Expand Up @@ -223,6 +225,8 @@ private bool ReleaseFileLRU(long fileLength)
/// <returns>when the file is not stored in the buffer,return false</returns>
private bool RemoveFileInBuffer(string url)
{
Logger log = new Logger("AppLogger");
log.Debug("File changed, remove file data in buffer: "+ url);
lock (LockRDConflict)//avoid the conflict when read the file which has been deleted
{
if (!LruList.Remove(url))//when the url is not in the LruList
Expand Down
7 changes: 4 additions & 3 deletions SocketManager/SocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ public bool Start(IPEndPoint localEndPoint)
try
{
listenSocket.Bind(localEndPoint);
log.Info("Start listening at port " + Properties.SocketManager.Default.ListenPort);
}
catch (Exception e)
{
log.Fatal("Socket binding error: " + e.Message);
log.Error("Socket binding error: " + e.Message);
return false;
}

Expand Down Expand Up @@ -208,7 +209,7 @@ private void ProcessAccept(SocketAsyncEventArgs e)
{
if(stop) return;
Interlocked.Increment(ref m_numConnectedSockets);
log.Info("Client connection accepted. There are"+m_numConnectedSockets+"clients connected to the server");
// log.Info("Client connection accepted. There are"+m_numConnectedSockets+"clients connected to the server");
// Get the socket for the accepted client connection and put it into the
//ReadEventArg object user token
SocketAsyncEventArgs readEventArgs = m_readWritePool.Pop();
Expand Down Expand Up @@ -321,7 +322,7 @@ private void CloseClientSocket(SocketAsyncEventArgs e)
// decrement the counter keeping track of the total number of clients connected to the server
Interlocked.Decrement(ref m_numConnectedSockets);
m_maxNumberAcceptedClients.Release();
log.Info("A client has been disconnected from the server. There are "+m_numConnectedSockets+" clients connected to the server");
//log.Info("A client has been disconnected from the server. There are "+m_numConnectedSockets+" clients connected to the server");
// Free the SocketAsyncEventArg so they can be reused by another client
m_readWritePool.Push(e);
}
Expand Down
5 changes: 3 additions & 2 deletions ezHttp/5.ezHttpWpfVer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Log.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="..\CommonLib\Log\Log.config">
<Link>Log.config</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
20 changes: 7 additions & 13 deletions ezHttp/BizLogic/LogLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public struct COPYDATASTRUCT
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
(PresentationSource.FromVisual(this) as HwndSource).AddHook(new HwndSourceHook(this.WndProc));
var a = (PresentationSource.FromVisual(this) as HwndSource);
a.AddHook(new HwndSourceHook(this.WndProc));
}

IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
Expand All @@ -54,7 +55,6 @@ IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool hand

COPYDATASTRUCT data = (COPYDATASTRUCT)System.Runtime.InteropServices.Marshal.PtrToStructure(lParam, typeof(COPYDATASTRUCT));
TextBlock tempBlock = new TextBlock();

string str = "";
for (int i = 0; i < data.cbData / 2; i++)
str += data.Message[i];
Expand All @@ -63,19 +63,19 @@ IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool hand
switch(type)
{
case LOG_DEBUG:
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(50,50,50));
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(20,80,100));
break;
case LOG_ERROR:
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(224, 119, 119));
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(0xaa, 00, 00));
break;
case LOG_FATAL:
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(224, 119, 119));
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(0x66, 00, 119));
break;
case LOG_INFO:
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(138, 201, 238));
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(0, 0x66, 0));
break;
case LOG_WARN:
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(224, 194, 19));
tempBlock.Foreground = new SolidColorBrush(Color.FromRgb(0xcc, 0x66, 00));
break;
default:
break;
Expand All @@ -94,19 +94,14 @@ IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool hand
{
listbox_log.Items.RemoveAt(0);
}

}
return hwnd;
}


private void text_clear_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
MessageBoxResult result = MessageBox.Show("Are you sure to clear the log", "Remind", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
listbox_log.Items.Clear();
}
}

private void text_clear_MouseEnter(object sender, MouseEventArgs e)
Expand All @@ -133,7 +128,6 @@ private void text_view_log_MouseLeftButtonUp(object sender, MouseButtonEventArgs
{

System.Diagnostics.Process.Start("NOTEPAD.EXE", "log.txt");

}
}
}
3 changes: 1 addition & 2 deletions ezHttp/BizLogic/MainLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ internal static bool StartService()
if (socketServer.Start() == false)
{
Logger log=new Logger("AppLogger");
log.Fatal("Filed to start service");
return false;
}

socketServer.OnDataReceived += new SocketServer.ConnetionChangedEventHandler(OnReceivedHttpReq);
fileBuffer.Run();
return true;;
return true;
}

internal static void RestartService()
Expand Down
21 changes: 9 additions & 12 deletions ezHttp/BizLogic/SettingsLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace ezHttp
public partial class MainWindow : Window
{
Color apply_color = Color.FromRgb(17, 17, 17);
Color remind_success_color = Color.FromRgb(50, 50, 150);
Color remind_success_color = Color.FromRgb(0x66,0x99,0x33);
Color remind_error_color = Color.FromRgb(247, 59, 59);
private void InitSettings()
{
textbox_serverDirectory.Text = FileManager.Properties.FileManagerSettings.Default.ServerDirectory;
textbox_filebuffer.Text = FileManager.Properties.FileManagerSettings.Default.PageSize *
FileManager.Properties.FileManagerSettings.Default.MaxPageNum / 1024 / 1024 + "MB";
FileManager.Properties.FileManagerSettings.Default.MaxPageNum / 1024 / 1024 + " MB";
textbox_listenport.Text = Convert.ToString(SocketManager.Properties.SocketManager.Default.ListenPort);
textbox_maxconnection.Text = Convert.ToString(SocketManager.Properties.SocketManager.Default.MaxConnections);
textbox_homedic.Text = Convert.ToString(HttpParser.Properties.HttpParserSettings.Default.WelcomeFilePath);
Expand Down Expand Up @@ -138,7 +138,7 @@ private bool DetectDirectory(string ServerDirectory)
{
if (!Directory.Exists(ServerDirectory))
{
text_remind.Text = "Please Use A ServerDirectory Which Is Existed";
text_remind.Text = "Server Directory exist";
text_remind.Foreground = new SolidColorBrush(remind_error_color);
SetUnChanged();
return false;
Expand All @@ -151,11 +151,11 @@ private bool DetectDirectory(string ServerDirectory)

private bool DetectFileBuffer(ref string FileBuffer)
{
if (FileBuffer.Length >= 2)
if (FileBuffer.Length >= 3)
{
if (FileBuffer.Substring(FileBuffer.Length - 2) == "MB")
if (FileBuffer.Substring(FileBuffer.Length - 3) == " MB")
{
FileBuffer = FileBuffer.Substring(0, FileBuffer.Length - 2);
FileBuffer = FileBuffer.Substring(0, FileBuffer.Length - 3);
}
if (Convert.ToInt32(FileBuffer) >= 4096)
{
Expand Down Expand Up @@ -185,7 +185,7 @@ private bool DetectHomeDic(string ServerDirectory,string HomeDic)
string filepath=ServerDirectory+HomeDic;
if(!File.Exists(filepath))
{
text_remind.Text = "You should enter an existed file as home page.";
text_remind.Text = "HomePage doesn't exist.";
text_remind.Foreground = new SolidColorBrush(remind_error_color);
SetUnChanged();
return false;
Expand All @@ -208,15 +208,12 @@ private bool DetectMaxConnection(string MaxConnection)

private void textbox_filebuffer_GotFocus(object sender, RoutedEventArgs e)
{
textbox_filebuffer.Text = textbox_filebuffer.Text.Substring(0,textbox_filebuffer.Text.Length - 2);
textbox_filebuffer.Text = textbox_filebuffer.Text.Substring(0,textbox_filebuffer.Text.Length - 3);
}

private void textbox_filebuffer_LostFocus(object sender, RoutedEventArgs e)
{
if (textbox_filebuffer.Text.Length >= 2 & textbox_filebuffer.Text.Substring(textbox_filebuffer.Text.Length-2)!="MB")
{
textbox_filebuffer.Text += "MB";
}
textbox_filebuffer.Text += " MB";

}
//to ensure user can only enter number
Expand Down
Loading

0 comments on commit 626d1b6

Please sign in to comment.