Skip to content

Commit

Permalink
updates CB, Service(DvPrinter, CBSocket, ThreadHandler)
Browse files Browse the repository at this point in the history
#14

# CB에서 VM수정
- UI 문구
- CB의 본질적인 목적이 무엇일까 생각해보자.

# DvPrinter
- ToInt64()로 바꾸니, Overflow 해결
- PRINT_OPT에 따라 pji.Cancle() 적용.
* 지금 제대로 작동하지는 않는다.

# CBSocket
- (189) Money가 0보다 작으면, Cancle()시키려는 의도.
- Todo : UI에서 MessageBox 보여줘야함.

# ThreadHandler
- PrintedOpt 변수에 대한 설명 주석 추가
  • Loading branch information
jongwuner committed Dec 5, 2019
1 parent 4eed7c0 commit 42b2c34
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void ExecuteCloseWindow(object obj)
// Close 버튼
App.SendPacketToServer(new DataPacket());

if (System.Windows.Forms.MessageBox.Show("로그아웃 하시겠습니까?", "TYPRESS Logout", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (System.Windows.Forms.MessageBox.Show("프린트를 중단하고, 로그아웃 하시겠습니까?", "TYPRESS Logout", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
System.Windows.Forms.MessageBox.Show("로그아웃을 하였습니다 :)");
System.Environment.Exit(1);
Expand Down
41 changes: 27 additions & 14 deletions Server-Service/MyService/DvPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ namespace MyService

class DvPrinter
{
public enum PRINTOPT
{
PRINT_OPT_LISTEN = 0,
PRINT_OPT_CANCLE = 1,
PRINT_OPT_PRINT = 2
}
#region Monitor private variables
private IntPtr _printerHandle = IntPtr.Zero;
private IntPtr _changeHandle = IntPtr.Zero;
Expand Down Expand Up @@ -231,6 +237,7 @@ private void OnFunctionCalledPrinterEnd(INktHook hhook, INktProcess proc, INktHo
#region PrintStart
public void MonitorStart()
{
System.Diagnostics.Debugger.Launch();
// out _printerHandle을 통해, 이름이 _spoolerName인 프린터의 제어권을 얻어온다.
OpenPrinter(_spoolerName, out _printerHandle, 0);

Expand Down Expand Up @@ -291,7 +298,7 @@ public void PrinterNotifyWaitCallback(Object state, bool timedOut)

Console.WriteLine("pdwChange : {0} / pNotifiyInfo : {1}", pdwChange, pNotifyInfo);
//If the Printer Change Notification Call did not give data, exit code
if ((bResult == false) || (((int)pNotifyInfo) == 0)) return;
if ((bResult == false) || (pNotifyInfo.ToInt64() == 0)) return;

//If the Change Notification was not relgated to job, exit code
//Job이 ADDJOB, 이딴게 맞는지 한번 보는 것!!
Expand All @@ -302,21 +309,11 @@ public void PrinterNotifyWaitCallback(Object state, bool timedOut)
if (!bJobRelatedChange) return;
#endregion

#region Interrupt Catch!!!!!!
if (bJobRelatedChange == ((pdwChange & PRINTER_CHANGES.PRINTER_CHANGE_ADD_JOB) == PRINTER_CHANGES.PRINTER_CHANGE_ADD_JOB))
{
Console.WriteLine("☆☆☆☆☆☆☆☆ Login Auth ☆☆☆☆☆☆☆☆");
// if(로그인 여부 -> Login 성공 -> CB) 프린터 계속 진행.
// if(종료) 함수종료.

}
#endregion


#region populate Notification Information
//Now, let us initialize and populate the Notify Info data
PRINTER_NOTIFY_INFO info = (PRINTER_NOTIFY_INFO)Marshal.PtrToStructure(pNotifyInfo, typeof(PRINTER_NOTIFY_INFO));
int pData = (int)pNotifyInfo + Marshal.SizeOf(typeof(PRINTER_NOTIFY_INFO));
Int64 pData = pNotifyInfo.ToInt64() + Marshal.SizeOf(typeof(PRINTER_NOTIFY_INFO));
PRINTER_NOTIFY_INFO_DATA[] data = new PRINTER_NOTIFY_INFO_DATA[info.Count];
for (uint i = 0; i < info.Count; i++)
{
Expand Down Expand Up @@ -347,10 +344,26 @@ public void PrinterNotifyWaitCallback(Object state, bool timedOut)

if (bJobRelatedChange == ((pdwChange & PRINTER_CHANGES.PRINTER_CHANGE_ADD_JOB) == PRINTER_CHANGES.PRINTER_CHANGE_ADD_JOB))
{
Console.WriteLine("★★★★★★★★ Print Out [First] ★★★★★★★★");
//Console.WriteLine("★★★★★★★★ Print Out [First] ★★★★★★★★");
// Print 시작 ~ 종료까지 Thread 대기 걸고.
// Print Real Page Count 넣어야 한다.
pji.Cancel();

// while(ThreadHandler.PrintedOpt == 0 && cnt <= 60){
// Thread.Sleep(1000);
// cnt++;
//
// }
// if(cnt >= 60) pji.Cancle();
// if(ThreadHandler.PrintedOpt == 1) pji.Cancle();
//
int ThreadTimer = 0;
while (ThreadHandler.PrintedOpt == (int)PRINTOPT.PRINT_OPT_LISTEN && ThreadTimer <= 60)
{
Thread.Sleep(1000);
ThreadTimer++;
}
if(ThreadHandler.PrintedOpt == (int)PRINTOPT.PRINT_OPT_CANCLE || ThreadTimer >= 60) pji.Cancel();
ThreadHandler.PrintedOpt = (int)PRINTOPT.PRINT_OPT_LISTEN;
}
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ServerOpenCB(object port)
//System.Diagnostics.Debugger.Launch();
//while (ThreadHandler.MainPacket.IsLogin && !Exit)
//{
ReceivePacketFromClientCBClientDBUpdate();
ReceivePacketFromClientCBClientDBUpdate();
//}
}
catch (SocketException socketEx)
Expand Down Expand Up @@ -172,19 +172,21 @@ public static void ReceivePacketFromClientCBClientDBUpdate()
//}

// 마일리지, 인쇄수 Update
if(packet.Opt == 0)
if(packet.Opt == 0) // Close
{
ThreadHandler.MainPacket = new DataPacket();
ThreadHandler.PrintedOpt = 1; // 1 : Cancle
return;
}

int c = 0;
while (packet.Opt == 1 && DvPrinter.PageCntData == 0 && c < 60)
while (packet.Opt == 1 && DvPrinter.PageCntData == 0 && c < 60) // Print
{
c++;
Thread.Sleep(1000);
}
if (c >= 60) return;
if (packet.Money < 0) return;

packet = UpdateMileage(packet, DvPrinter.PageCntData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ThreadHandler
public static DataPacket MainPacket = new DataPacket();
public static PrintedPacket PrintPacket = new PrintedPacket();

public static int PrintedOpt; // 0 : 수신중 / 1 : Pass / 2 : Cancle
public DvPrinter dv = new DvPrinter();
public SocketHandler LoginSocketHandler = new SocketHandler();
public SocketHandler MainSocketHandler = new SocketHandler();
Expand Down
3 changes: 3 additions & 0 deletions Server-Service/MyService/MyService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Net" />
<Reference Include="System.Printing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -95,6 +96,8 @@
<Compile Include="Handler\Handler_Socket\SocketHandler5002CB.cs" />
<Compile Include="Handler\Handler_Socket\SocketHandler5003Print.cs" />
<Compile Include="Handler\Handler_View\ViewHandler.cs" />
<Compile Include="PrintJobChangeEventArgs.cs" />
<Compile Include="PrintSpoolAPI.cs" />
<Compile Include="ProjectInstaller.cs">
<SubType>Component</SubType>
</Compile>
Expand Down

0 comments on commit 42b2c34

Please sign in to comment.