프로젝트

일반

사용자정보

개정판 1305c420

ID1305c42004d7598340bf61fb7995c730bc5d2f50
상위 bae83c92
하위 cf1cc862

김태성이(가) 3년 이상 전에 추가함

license 추가

Change-Id: I8e7a4286cba7bd95a3475917a96e7b3560c67cb0

차이점 보기:

FinalService/KCOM_FinalService/DatabaseLoadTest/DatabaseLoadTest.csproj
62 62
  </ItemGroup>
63 63
  <ItemGroup>
64 64
    <PackageReference Include="EntityFramework">
65
      <Version>6.4.4</Version>
65
      <Version>5.0.0</Version>
66 66
    </PackageReference>
67 67
    <PackageReference Include="EntityFramework.ko">
68
      <Version>6.2.0</Version>
68
      <Version>5.0.0</Version>
69 69
    </PackageReference>
70 70
  </ItemGroup>
71 71
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
FinalService/KCOM_FinalService/FinalPDFClient/MainWindow.xaml.cs
89 89
                {
90 90
                    markupToPDF.MakeFinalPDF((object)addResult.FinalPDF);
91 91
                  
92

  
93 92
                }
94 93
            }
95 94
            catch (Exception ex)
FinalService/KCOM_FinalService/FinalProcess/App.config
1
<?xml version="1.0" encoding="utf-8"?>
2
<configuration>
3
    <startup> 
4
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
5
    </startup>
6
</configuration>
FinalService/KCOM_FinalService/FinalProcess/FinalProcess.csproj
1
<?xml version="1.0" encoding="utf-8"?>
2
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4
  <PropertyGroup>
5
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7
    <ProjectGuid>{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}</ProjectGuid>
8
    <OutputType>Exe</OutputType>
9
    <RootNamespace>FinalProcess</RootNamespace>
10
    <AssemblyName>FinalProcess</AssemblyName>
11
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12
    <FileAlignment>512</FileAlignment>
13
    <Deterministic>true</Deterministic>
14
    <TargetFrameworkProfile />
15
  </PropertyGroup>
16
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17
    <PlatformTarget>x64</PlatformTarget>
18
    <DebugSymbols>true</DebugSymbols>
19
    <DebugType>full</DebugType>
20
    <Optimize>false</Optimize>
21
    <OutputPath>..\ProcessPublish\</OutputPath>
22
    <DefineConstants>DEBUG;TRACE</DefineConstants>
23
    <ErrorReport>prompt</ErrorReport>
24
    <WarningLevel>4</WarningLevel>
25
  </PropertyGroup>
26
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27
    <PlatformTarget>x64</PlatformTarget>
28
    <DebugType>pdbonly</DebugType>
29
    <Optimize>false</Optimize>
30
    <OutputPath>..\..\ProcessPublish\</OutputPath>
31
    <DefineConstants>DEBUG;TRACE</DefineConstants>
32
    <ErrorReport>prompt</ErrorReport>
33
    <WarningLevel>4</WarningLevel>
34
  </PropertyGroup>
35
  <ItemGroup>
36
    <Reference Include="System" />
37
    <Reference Include="System.Core" />
38
    <Reference Include="System.Data.Entity" />
39
    <Reference Include="System.Windows.Forms" />
40
    <Reference Include="System.Xml.Linq" />
41
    <Reference Include="System.Data.DataSetExtensions" />
42
    <Reference Include="Microsoft.CSharp" />
43
    <Reference Include="System.Data" />
44
    <Reference Include="System.Net.Http" />
45
    <Reference Include="System.Xml" />
46
  </ItemGroup>
47
  <ItemGroup>
48
    <Compile Include="Program.cs" />
49
    <Compile Include="Properties\AssemblyInfo.cs" />
50
  </ItemGroup>
51
  <ItemGroup>
52
    <None Include="App.config" />
53
    <None Include="Log.config">
54
      <SubType>Designer</SubType>
55
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
56
    </None>
57
  </ItemGroup>
58
  <ItemGroup>
59
    <PackageReference Include="EntityFramework">
60
      <Version>5.0.0</Version>
61
    </PackageReference>
62
    <PackageReference Include="EntityFramework.ko">
63
      <Version>5.0.0</Version>
64
    </PackageReference>
65
    <PackageReference Include="iTextSharp">
66
      <Version>5.5.13.2</Version>
67
    </PackageReference>
68
    <PackageReference Include="log4net">
69
      <Version>2.0.12</Version>
70
    </PackageReference>
71
  </ItemGroup>
72
  <ItemGroup>
73
    <ProjectReference Include="..\IFinalPDF\IFinalPDF.csproj">
74
      <Project>{784438be-2074-41ae-a692-24e1a4a67fe3}</Project>
75
      <Name>IFinalPDF</Name>
76
    </ProjectReference>
77
    <ProjectReference Include="..\KCOMDataModel\KCOMDataModel.csproj">
78
      <Project>{629dc8cd-d458-47ef-8f02-cd12c7001c3e}</Project>
79
      <Name>KCOMDataModel</Name>
80
    </ProjectReference>
81
    <ProjectReference Include="..\MarkupToPDF\MarkupToPDF.csproj">
82
      <Project>{a714bd67-8aac-4ed8-8ecf-7853c3549a68}</Project>
83
      <Name>MarkupToPDF</Name>
84
    </ProjectReference>
85
  </ItemGroup>
86
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
87
</Project>
FinalService/KCOM_FinalService/FinalProcess/Log.config
1
<?xml version="1.0" encoding="utf-8"?>
2
<configuration>
3
  <configSections>
4
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
5
  </configSections>
6
  <log4net>
7
    <!--<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
8
      <applicationName value="ServiceStation"/>
9
      <layout type="log4net.Layout.PatternLayout">
10
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
11
      </layout>
12
    </appender>-->
13
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
14
      <file type="log4net.Util.PatternString" value="${programdata}\FinalService\Process\Log\"/>
15
      <appendtofile value="true"/>
16
      <datepattern value="'Final_'yyyy-MM-dd'.log'"/>
17
      <staticlogfilename value="false"/>
18
      <rollingstyle value="Date"/>
19
      <layout type="log4net.Layout.PatternLayout">
20
        <conversionpattern value="%d [%t] %-5p - %m%n"/>
21
      </layout>
22
    </appender>
23
    <root>
24
      <level value="All" />
25
      <!-- <appender-ref ref="EventLogAppender" />-->
26
      <appender-ref ref="RollingFileAppender" />
27
    </root>
28
  </log4net>
29
</configuration>
FinalService/KCOM_FinalService/FinalProcess/Program.cs
1
using IFinalPDF;
2
using KCOMDataModel.DataModel;
3
using log4net;
4
using MarkupToPDF;
5
using System;
6
using System.Collections.Generic;
7
using System.Linq;
8
using System.Text;
9
using System.Threading.Tasks;
10
using System.Windows.Forms;
11

  
12
namespace FinalProcess
13
{
14
    class Program
15
    {
16
        protected static ILog logger;
17
        public static FINAL_PDF finalPdf = null;
18
        public static string RemoteAddress = null;
19

  
20
        static void Main(string[] args)
21
        {
22
            try
23
            {
24
                logger = LogManager.GetLogger(typeof(Program));
25
      
26
                if (args.Length == 2)
27
                {
28
                    string finalID = args[0];
29
                    RemoteAddress = args[1];
30
               
31
                    logger.Info($"FinalProcess Final ID :{args[0]}");
32

  
33
                    MarkupToPDF.MarkupToPDF _markuptoPDF = new MarkupToPDF.MarkupToPDF();
34
                    _markuptoPDF.FinalMakeError += new EventHandler<MarkupToPDF.MakeFinalErrorArgs>(_markuptoPDF_FinalMakeError);
35
                    _markuptoPDF.StatusChanged += new EventHandler<MarkupToPDF.StatusChangedEventArgs>(_markuptoPDF_StatusChange);
36

  
37
                    using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
38
                    {
39
                        var items = _entity.FINAL_PDF.Where(x => x.ID == finalID);
40

  
41
                        if(items.Count() > 0)
42
                        {
43
                            finalPdf = items.First();
44
                        }
45
                    }
46

  
47
                    if (finalPdf != null)
48
                    {
49
                        var result = _markuptoPDF.MakeFinalPDF(finalPdf);
50

  
51
                        using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
52
                        {
53
                            var items = _entity.FINAL_PDF.Where(x => x.ID == finalID);
54

  
55
                            if (items.Count() > 0)
56
                            {
57
                                if (result.Error == null)
58
                                {
59
                                    items.First().STATUS = 4;
60
                                    items.First().END_DATETIME = DateTime.Now;
61
                                }
62
                            }
63
                        }
64
                    }
65
                }
66
            }
67
            catch (Exception ex)
68
            {
69
                logger.Error($"FinalProcess Final ID :{args[0]}", ex);
70
            }
71
            finally
72
            {
73
                GC.Collect();
74
                GC.WaitForPendingFinalizers();
75
                GC.Collect();
76

  
77
                Application.Exit();
78
            }
79
        }
80

  
81
        public static void StatusChange(FinalStatus status,string ex)
82
        {
83
            using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
84
            {
85
                var items = _entity.FINAL_PDF.Where(x => x.ID == finalPdf.ID);
86

  
87
                if (items.Count() > 0)
88
                {
89
                    items.First().STATUS = (int)status;
90

  
91
                    if(!string.IsNullOrWhiteSpace(ex))
92
                    {
93
                        if (items.First().EXCEPTION.Length < int.MaxValue - ex.Length)
94
                        {
95
                            items.First().EXCEPTION = items.First().EXCEPTION + ex;
96
                        }
97
                    }
98

  
99
                    _entity.SaveChanges();
100
                }
101
            }
102
        }
103

  
104

  
105
        private static void _markuptoPDF_StatusChange(object sender, StatusChangedEventArgs e)
106
        {
107
            StatusChange(FinalStatus.Error, e.Error);
108
        }
109

  
110
        private static void _markuptoPDF_FinalMakeError(object sender, MakeFinalErrorArgs e)
111
        {
112
            StatusChange(FinalStatus.Error, e.Message);
113
        }
114
    }
115
}
FinalService/KCOM_FinalService/FinalProcess/Properties/AssemblyInfo.cs
1
using System.Reflection;
2
using System.Runtime.CompilerServices;
3
using System.Runtime.InteropServices;
4

  
5
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 
6
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
7
// 이러한 특성 값을 변경하세요.
8
[assembly: AssemblyTitle("FinalProcess")]
9
[assembly: AssemblyDescription("")]
10
[assembly: AssemblyConfiguration("")]
11
[assembly: AssemblyCompany("")]
12
[assembly: AssemblyProduct("FinalProcess")]
13
[assembly: AssemblyCopyright("Copyright ©  2021")]
14
[assembly: AssemblyTrademark("")]
15
[assembly: AssemblyCulture("")]
16

  
17
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 
18
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
19
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
20
[assembly: ComVisible(false)]
21

  
22
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
23
[assembly: Guid("6cd6e8fe-a661-4b9e-ae63-b7826921ee9b")]
24

  
25
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
26
//
27
//      주 버전
28
//      부 버전 
29
//      빌드 번호
30
//      수정 버전
31
//
32
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로
33
// 지정되도록 할 수 있습니다.
34
// [assembly: AssemblyVersion("1.0.*")]
35
[assembly: AssemblyVersion("1.0.0.0")]
36
[assembly: AssemblyFileVersion("1.0.0.0")]
37
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log.config", Watch = true)]
FinalService/KCOM_FinalService/IFinalPDF/InterfaceFinalPDF.cs
9 9
    {
10 10

  
11 11
        FinalPDFResult Notify(string ProjectNo, string FinalID);
12
        void Finish(string ProjectNo, string FinalID, string OriginFileName, string FinalPDFPath, string remodeFilePath);
12 13

  
14
        void Error(string ProjectNo, string FinalID, string Error);
13 15
    }
14 16

  
15 17
    [Serializable]
FinalService/KCOM_FinalService/KCOM_FinalService.sln
37 37
EndProject
38 38
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseLoadTest", "DatabaseLoadTest\DatabaseLoadTest.csproj", "{99E36DFB-0C2C-432D-BC33-7CF6D4B947C2}"
39 39
EndProject
40
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FinalProcess", "FinalProcess\FinalProcess.csproj", "{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}"
41
EndProject
40 42
Global
41 43
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
42 44
		Debug|Any CPU = Debug|Any CPU
......
219 221
		{99E36DFB-0C2C-432D-BC33-7CF6D4B947C2}.Release|x64.Build.0 = Release|Any CPU
220 222
		{99E36DFB-0C2C-432D-BC33-7CF6D4B947C2}.Release|x86.ActiveCfg = Release|Any CPU
221 223
		{99E36DFB-0C2C-432D-BC33-7CF6D4B947C2}.Release|x86.Build.0 = Release|Any CPU
224
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
225
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
226
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Debug|x64.ActiveCfg = Debug|Any CPU
227
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Debug|x64.Build.0 = Debug|Any CPU
228
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Debug|x86.ActiveCfg = Debug|Any CPU
229
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Debug|x86.Build.0 = Debug|Any CPU
230
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
231
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Release|Any CPU.Build.0 = Release|Any CPU
232
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Release|x64.ActiveCfg = Release|Any CPU
233
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Release|x64.Build.0 = Release|Any CPU
234
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Release|x86.ActiveCfg = Release|Any CPU
235
		{6CD6E8FE-A661-4B9E-AE63-B7826921EE9B}.Release|x86.Build.0 = Release|Any CPU
222 236
	EndGlobalSection
223 237
	GlobalSection(SolutionProperties) = preSolution
224 238
		HideSolutionNode = FALSE
FinalService/KCOM_FinalService/KCOM_FinalService/KCOM_FinalService.csproj
38 38
    </StartupObject>
39 39
  </PropertyGroup>
40 40
  <ItemGroup>
41
    <Reference Include="log4net, Version=2.0.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
42
      <HintPath>..\packages\log4net.2.0.11\lib\net45\log4net.dll</HintPath>
41
    <Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
42
      <HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
43 43
    </Reference>
44 44
    <Reference Include="System" />
45 45
    <Reference Include="System.Configuration" />
FinalService/KCOM_FinalService/KCOM_FinalService/Remoting/RemFinalPDFStation - 복사본.cs
1
using IFinalPDF;
2
using KCOM_FinalService.Common;
3
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5
using MarkupToPDF;
6
using System;
7
using System.Collections.Concurrent;
8
using System.Collections.Generic;
9
using System.IO;
10
using System.Linq;
11
using System.Reflection;
12
using System.Runtime.Remoting.Channels.Tcp;
13
using System.Threading;
14
using System.Threading.Tasks;
15

  
16
namespace KCOM_FinalService.Remoting
17
{
18
    public class RemFinalPDFStation : InterfaceFinalPDF, IDisposable
19
    {
20
        #region Properties
21

  
22
        Logger _Logger = null;
23

  
24
        TcpChannel _Channel = null;
25
        
26
        string _NoticeMessageBase = null;
27
        string _NoticeTitleBase = null;
28
        string _MyIP = null;
29
        int _TypeName = 1;
30
        readonly Properties.Settings _SettingPlace = null;
31

  
32
        ConcurrentQueue<FINAL_PDF> WaitingQueue = new ConcurrentQueue<FINAL_PDF>();
33
        List<FINAL_PDF> WorkingList = new List<FINAL_PDF>();
34
        #endregion
35

  
36
        public RemFinalPDFStation(Logger eventLog,int MultipleFinalCount)
37
        {
38
            _Logger = eventLog;
39

  
40
            Init();
41
        }
42

  
43
        public RemFinalPDFStation(Logger eventLog)
44
        {
45
            _Logger = eventLog;
46

  
47
            Init();
48
        }
49

  
50
        public RemFinalPDFStation(Logger eventLog,string RemotingPort)
51
        {
52
            _Logger = eventLog;
53

  
54
            int port = -1;
55

  
56
            if (int.TryParse(RemotingPort, out port))
57
            {
58
                if (Properties.Settings.Default.RemotingPort != port)
59
                {
60
                    Properties.Settings.Default.RemotingPort = port;
61
                    Properties.Settings.Default.Save();
62
                }
63

  
64
                Init();
65
            }
66
            else
67
            {
68
                _Logger.Write($"RemotingPort Parse Error : {RemotingPort}",LogLevel.Error);
69

  
70
            }
71
        }
72

  
73
        public void Init()
74
        {
75
            try
76
            {
77
                using (KCOMDataModel.DataModel.KCOMEntities _systemEntity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
78
                {
79
#if DEBUG
80
                    _TypeName = 1; //FINAL은 현재 타입이 1임
81
#else
82
                    _TypeName = 1;
83
                    ///TODO: check below code
84
                    ///_TypeName = _systemEntity.SERVICE_PROPERTIES.Where(data => data.SERVICE_ADDRESS == _MyIP).FirstOrDefault().SERVICET_TYPE;
85
#endif
86
                }
87

  
88
                string endpoint = "remFinalPDF";
89

  
90
                string port = CommonLib.Common.GetConfigString("Remoting", "Port", "");
91

  
92
                if (string.IsNullOrEmpty(port))
93
                {
94
                    _Channel = new TcpChannel(Properties.Settings.Default.RemotingPort);
95
                }
96
                else
97
                {
98
                    _Channel = new TcpChannel(int.Parse(port));
99
                }
100

  
101
                System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(_Channel, false);
102
                System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemFinalPDFObject), endpoint, System.Runtime.Remoting.WellKnownObjectMode.Singleton);
103

  
104
                foreach (var item in _Channel.GetUrlsForUri(endpoint))
105
                {
106
                    _Logger.Write($"Final Service Open Channel - {item}",LogLevel.Info);
107
                } 
108
            }
109
            catch (Exception ex)
110
            {
111
                _Logger.Write(ex);
112
            }
113

  
114
            IFinalPDF.Cache.Attach(this);
115
        }
116

  
117
        private void SetFinalState(string finalID, FinalStatus status,string log = null)
118
        {
119
            using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
120
            {
121
                var finalList = _entity.FINAL_PDF.Where(final => final.ID == finalID);
122

  
123
                if (finalList.Count() > 0)
124
                {
125
                    if (status == FinalStatus.Create)
126
                    {
127
                        var sb = new System.Text.StringBuilder();
128
                        sb.AppendLine("V3");
129
                        sb.AppendLine(finalList.First().EXCEPTION);
130

  
131
                        finalList.First().EXCEPTION = sb.ToString();
132
                        finalList.First().START_DATETIME = DateTime.Now;
133
                    }
134
                    if (status == FinalStatus.Success)
135
                    {
136
                        
137
                        finalList.First().END_DATETIME = DateTime.Now;
138
                    }
139
                    if(status == FinalStatus.PdfStamp)
140
                    {
141
                        if (!string.IsNullOrWhiteSpace(log))
142
                        {
143
                            var sb = new System.Text.StringBuilder();
144
                            sb.AppendLine(log);
145
                            sb.AppendLine(finalList.First().EXCEPTION);
146

  
147
                            finalList.First().EXCEPTION = log;
148
                        }
149
                    }
150

  
151
                    finalList.First().STATUS = (int)status;
152
                    _entity.SaveChanges();
153
                }
154
            };
155
        }
156

  
157
        public void Dispose()
158
        {
159
            if (_Channel != null)
160
            {
161
                System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(_Channel);
162
            }
163
        }
164

  
165
        /// <summary>
166
        /// 큐에 finalpdf를 넣고 작업 실행한다
167
        /// </summary>
168
        /// <param name="pdf"></param>
169
        private void MakeMergedPDF(object pdf)
170
        {
171
            /// 동시 수행 작업 갯수가 정해진 값보다 작을 경우 쓰레드를 생성하여 작업을 수행한다
172
            if (WorkingList.Count < Properties.Settings.Default.MultipleFinalCount)
173
            {
174
                /// 작업중인 동일한 merged pdf가 없을 경우 작업 수행
175
                IEnumerable<FINAL_PDF> matched = WorkingList.Where(item => item.DOCUMENT_ID == ((FINAL_PDF)pdf).DOCUMENT_ID);
176
                if (matched.Count() == 0)
177
                {
178
                    lock(WorkingList)
179
                    {
180
                        WorkingList.Add(pdf as FINAL_PDF);
181
                        Thread.Sleep(1000);
182
                    };
183

  
184
                    Thread thread = new Thread(new ParameterizedThreadStart(FinalPDFDequeueandProcessing));
185
                    thread.SetApartmentState(ApartmentState.STA);
186
                    thread.Start(pdf); 
187
                }
188
                else
189
                {
190
                    WaitingQueue.Enqueue((FINAL_PDF)pdf);
191
                }
192
            }
193
            else
194
            {
195
                WaitingQueue.Enqueue((FINAL_PDF)pdf);
196
            }
197
        }
198
        
199
        /// <summary>
200
        /// 실제 Merged PDF를 생성한다
201
        /// </summary>
202
        private void FinalPDFDequeueandProcessing(object pdf)
203
        {
204
            Task tDeq = Task.Factory.StartNew(() =>
205
            {
206
                try
207
                {
208
                    if(pdf != null)
209
                    {
210
                        var finalpdf = (FINAL_PDF)pdf;
211

  
212
                        _Logger.Write($"ID:{finalpdf.ID} / ProjectNo:{finalpdf.PROJECT_NO} / DocumentId:{finalpdf.DOCUMENT_ID} / MarkupInfoId:{finalpdf.MARKUPINFO_ID} / CreateUser:{finalpdf.CREATE_USER_ID}",LogLevel.Info);
213
                    }
214

  
215
                    if (((FINAL_PDF)pdf).STATUS == (int)FinalStatus.Insert)
216
                    {
217
                        /// 작업중이라고 데이타베이스에 저장한다
218
                        ((FINAL_PDF)pdf).STATUS = (int)(FinalStatus.Wait);
219
                        using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
220
                        {
221
                            var selectItem = _entity.FINAL_PDF.Where(data => data.ID == ((FINAL_PDF)pdf).ID).FirstOrDefault();
222
                            selectItem.STATUS = (int)(FinalStatus.Wait);
223
                            _entity.SaveChanges();
224
                        }
225
                    }
226

  
227
                    /// 작업 수행
228
                    MarkupToPDF.MarkupToPDF _markuptoPDF = new MarkupToPDF.MarkupToPDF();
229
                    _markuptoPDF.FinalMakeError += new EventHandler<MarkupToPDF.MakeFinalErrorArgs>(_markuptoPDF_FinalMakeError);
230
                    _markuptoPDF.StatusChanged += new EventHandler<MarkupToPDF.StatusChangedEventArgs>(_markuptoPDF_StatusChange);
231
                    _markuptoPDF.EndFinal += new EventHandler<MarkupToPDF.EndFinalEventArgs>(_markuptoPDF_EndFinal);
232
                    Thread _stathread = new Thread(new ParameterizedThreadStart(_markuptoPDF.MakeFinalPDF))
233
                    {
234
                        Name = ((FINAL_PDF)pdf).ID.ToString()
235
                    };
236
                    SetFinalState(((FINAL_PDF)pdf).ID, IFinalPDF.FinalStatus.Create);
237
                    _stathread.SetApartmentState(ApartmentState.STA);
238
                    _stathread.Start(pdf);
239
                }
240
                catch (Exception ex)
241
                {
242
                    _Logger.Write(ex);
243
                }
244
            });
245
        }
246
        /// <summary>
247
        /// callback for WebService
248
        /// </summary>
249
        /// <param name="ProjectNo"></param>
250
        /// <param name="FinalID"></param>
251
        /// <returns></returns>
252
        public FinalPDFResult Notify(string ProjectNo, string FinalID)
253
        {
254
            try
255
            {
256
                using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
257
                {
258
                    FINAL_PDF finalpdf = _entity.FINAL_PDF.Where(final =>final.PROJECT_NO == ProjectNo && final.ID == FinalID).FirstOrDefault();
259
                    if (finalpdf != null)
260
                    {
261
                        ThreadPool.QueueUserWorkItem(this.MakeMergedPDF, finalpdf);
262
                    }
263
                    else
264
                    {
265
                        throw new ArgumentException(string.Format("ProjectNo : {0}, FinalID : {1}", ProjectNo, FinalID));
266
                    }
267
                }
268
            }
269
            catch(Exception ex)
270
            {
271
                _Logger.Write(ex);
272
                throw ex;
273
            }
274

  
275
            return new FinalPDFResult();
276
        }
277

  
278

  
279
        private void _markuptoPDF_StatusChange(object sender, StatusChangedEventArgs e)
280
        {
281
            var _T = WorkingList.Where(t => t == (sender as MarkupToPDF.MarkupToPDF).FinalItem);
282

  
283
            if (_T.Count() > 0)
284
            {
285
                FINAL_PDF _item = _T.First();
286
                SetFinalState(_item.ID, FinalStatus.PdfStamp,e.Message);
287
                _Logger.Write($"PdfStamp Final ID : {_item.ID} message : {e.Message} ",LogLevel.Info);
288
            }
289
        }
290

  
291
        /// <summary>
292
        /// final pdf 종료
293
        /// </summary>
294
        /// <param name="sender"></param>
295
        /// <param name="e"></param>
296
        void _markuptoPDF_EndFinal(object sender, MarkupToPDF.EndFinalEventArgs e)
297
        {
298
            _Logger.Write($"End Final FinalID:{e.FinalPDF.ID} / Output:{e.FinalPDFPath} / Message :{e.Message}", LogLevel.Info);
299

  
300
            var _T = WorkingList.Where(t => t == (sender as MarkupToPDF.MarkupToPDF).FinalItem);
301
            if (_T.Count() > 0)
302
            {
303
                FINAL_PDF _item = _T.First();
304
                SetFinalState(_item.ID, FinalStatus.PdfStamp);
305

  
306
                try
307
                {
308
                    string soapurl = CommonLib.Common.GetConfigString("UpLoadServiceUrl", "URL", "");
309

  
310
                    string finalpdfroot = CommonLib.Common.GetConfigString("FinalPDFRootUrl", "URL", "");
311

  
312
                    string pdfpath = e.FinalPDFRemotePath;
313

  
314
                    if (!string.IsNullOrEmpty(finalpdfroot))
315
                    {
316
                        string filename = Path.GetFileName(e.FinalPDFPath);
317
                        pdfpath = !string.IsNullOrEmpty(finalpdfroot) ? finalpdfroot + filename : filename;
318
                    }
319

  
320
                    if (!string.IsNullOrEmpty(soapurl) && (Program.UploadFinalPDFInst != null) && (Program.UploadFinalPDFMethod != null))
321
                    {
322
                        object[] parameters = new object[] { pdfpath, e.OriginPDFName, e.FinalPDF, soapurl };
323

  
324
                        _Logger.Write("UploadPDF.dll Path :" + Program.UploadFinalAssmPath,LogLevel.Info);
325

  
326
                        _Logger.Write("Call Upload Final .." + pdfpath + " finalPDFPath : " + e.FinalPDFPath + " FinalPDFRemotePath : " + e.FinalPDFRemotePath + ",CreateUser:" + e.FinalPDF.CREATE_USER_ID + ",CreateUser:" + e.FinalPDF.DOCUMENT_ID + ",pdfname:" + e.OriginPDFName + ",finalPDF ID : " + e.FinalPDF.ID + ",soapUri:" + soapurl,LogLevel.Info);
327
                        
328
                     KeyValuePair<bool, string> result = (KeyValuePair<bool, string>)(Program.UploadFinalPDFMethod.Invoke(Program.UploadFinalPDFInst, parameters));
329

  
330
                        if (result.Key)
331
                        {
332
                            SetFinalState(_item.ID, FinalStatus.Success);
333
                        }
334
                        else
335
                        {
336
                            SetFinalState(_item.ID, FinalStatus.Error);
337
                            _Logger.Write("Upload error  .." + pdfpath  + ",pdfname:" + e.OriginPDFName + " Msg : " + result.Value, LogLevel.Error);
338
                        }
339
                    }
340
                    else
341
                    {
342
                        ///TODO: 저장할 폴더 위치를 configuration으로 빼주세요
343

  
344
                        string savepath = CommonLib.Common.GetConfigString("DebugSavePath", "URL", "");
345

  
346
                        string sFolder = _item.DOCUMENT_ID.All(char.IsDigit) ? (Convert.ToInt32(_item.DOCUMENT_ID) / 100).ToString() : _item.DOCUMENT_ID.Substring(0, 5);
347
                        string saveFolder = String.Format(savepath, _item.PROJECT_NO, sFolder, _item.DOCUMENT_ID);
348
                        if (!System.IO.Directory.Exists(saveFolder))
349
                        {
350
                            System.IO.Directory.CreateDirectory(saveFolder);
351
                        }
352

  
353
                        _Logger.Write(String.Format("saveFolder : {0}", saveFolder), LogLevel.Info);
354

  
355
                        try
356
                        {
357
                            System.IO.File.Copy(e.FinalPDFPath, saveFolder + e.OriginPDFName, true);
358

  
359
                            _Logger.Write($"End Final SaveFile :{saveFolder + e.OriginPDFName}", LogLevel.Info);
360
                        }
361
                        catch (Exception ex)
362
                        {
363
                            _Logger.Write(ex);
364
                        }
365

  
366
                        using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(_item.PROJECT_NO).ToString()))
367
                        {
368
                            var item = _entity.DOCUMENT_ITEM.Where(d => d.DOCUMENT_ID == _item.DOCUMENT_ID).FirstOrDefault();
369
                            ///TODO: RESULT FILE 경로 위치를 configuration으로 빼주세요
370
                            string resultpath = CommonLib.Common.GetConfigString("DebugResultUrlPath", "URL", "");
371

  
372
                            try
373
                            {
374
                                item.RESULT_FILE = String.Format(resultpath, _item.PROJECT_NO, sFolder, _item.DOCUMENT_ID, e.OriginPDFName);
375
                            }
376
                            catch (Exception ex)
377
                            {
378
                                _Logger.Write(new Exception($"DebugResultUrlPath의 Index를 확인 하세요.{resultpath}",ex));
379
                            }
380

  
381
                            _Logger.Write($"End FinalId:{item.ID} RESULT_FILE_PATH:{item.RESULT_FILE}",LogLevel.Info);
382
                            _entity.SaveChanges();
383
                            SetFinalState(_item.ID, FinalStatus.Success);
384
                        }
385

  
386
#if DEBUG
387
                        //this.WaitingQueue.Enqueue(_item);
388
#endif
389
                    }
390

  
391
                    (sender as MarkupToPDF.MarkupToPDF).FinalMakeError -= new EventHandler<MarkupToPDF.MakeFinalErrorArgs>(_markuptoPDF_FinalMakeError);
392
                    (sender as MarkupToPDF.MarkupToPDF).StatusChanged -= new EventHandler<MarkupToPDF.StatusChangedEventArgs>(_markuptoPDF_StatusChange);
393
                    (sender as MarkupToPDF.MarkupToPDF).EndFinal -= new EventHandler<MarkupToPDF.EndFinalEventArgs>(_markuptoPDF_EndFinal);
394
                    (sender as MarkupToPDF.MarkupToPDF).Dispose();
395
                }
396
                catch (Exception ex)
397
                {
398
                    SetFinalState(_item.ID, FinalStatus.Error);
399
                    _Logger.Write(ex);
400
                }
401
                finally
402
                {
403
                    WorkingList.Remove(_T.First());
404

  
405
                }
406

  
407
                /// 대기중인 merged pdf가 있을 경우 merged pdf를 생성한다
408
                if (this.WaitingQueue.Count > 0)
409
                {
410
                    FINAL_PDF pdf;
411
                    if(this.WaitingQueue.TryDequeue(out pdf))
412
                    {
413
                        ThreadPool.QueueUserWorkItem(this.MakeMergedPDF, pdf);
414
                    }
415
                }
416
            }
417
        }
418

  
419
        public static void sendReqLog(string name, string text)
420
        {
421
#if DEBUG
422
            try
423
            {
424
                string Msg = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\t" + name + "\t" + text + "\r\n";
425
                string Dir = Path.Combine(@"D:\finalpdf\error");
426

  
427
                if (Directory.Exists(Dir) == false)
428
                {
429
                    Directory.CreateDirectory(Dir);
430
                }
431

  
432
                int min = DateTime.Now.Minute / 1;
433

  
434
                string path = Dir + "/" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd HH-") + min + ".txt";
435
                File.AppendAllText(path, Msg);
436
            }
437
            catch (Exception e)
438
            {
439
                //  Debug.WriteLine(e);
440
            }
441
#endif
442
        }
443

  
444

  
445
        private void SetError(string FinalID, string Msg)
446
        {
447
            FINAL_PDF instanceFinal = null;
448

  
449
            try
450
            {
451
                using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
452
                {
453
                    instanceFinal = _entity.FINAL_PDF.Where(data => data.ID == FinalID).FirstOrDefault();
454

  
455
                    if (instanceFinal != null)
456
                    {
457
                        instanceFinal.STATUS = (int)FinalStatus.Error;
458
                        instanceFinal.EXCEPTION = DateTime.Now.ToShortDateString() + " " + Msg;
459
                        _entity.SaveChanges();
460
                    }
461
                }
462
            }
463
            catch (Exception ex)
464
            {
465
                _Logger.Write(ex);
466
            }
467
        }
468

  
469
        void _markuptoPDF_FinalMakeError(object sender, MarkupToPDF.MakeFinalErrorArgs e)
470
        {
471
            _Logger.Write($"FinalID:{e.FinalID} / Message :{e.Message}",LogLevel.Info);
472

  
473
            SetError(e.FinalID, e.Message);
474

  
475
            var _T = WorkingList.Where(t => t == (sender as MarkupToPDF.MarkupToPDF).FinalItem);
476
            if (_T.Count() > 0)
477
            {
478
                FINAL_PDF _Item = _T.First();
479
                (sender as MarkupToPDF.MarkupToPDF).FinalMakeError -= new EventHandler<MarkupToPDF.MakeFinalErrorArgs>(_markuptoPDF_FinalMakeError);
480
                (sender as MarkupToPDF.MarkupToPDF).StatusChanged -= new EventHandler<MarkupToPDF.StatusChangedEventArgs>(_markuptoPDF_StatusChange);
481
                (sender as MarkupToPDF.MarkupToPDF).EndFinal -= new EventHandler<MarkupToPDF.EndFinalEventArgs>(_markuptoPDF_EndFinal);
482
                (sender as MarkupToPDF.MarkupToPDF).Dispose();
483
                WorkingList.Remove(_Item);
484
            }
485

  
486
            /// 대기중인 merged pdf가 있을 경우 merged pdf를 생성한다
487
            if (this.WaitingQueue.Count > 0)
488
            {
489
                FINAL_PDF pdf;
490
                if (this.WaitingQueue.TryDequeue(out pdf))
491
                {
492
                    ThreadPool.QueueUserWorkItem(this.MakeMergedPDF, pdf);
493
                }
494
            }
495
        }
496
    }
497
}
FinalService/KCOM_FinalService/KCOM_FinalService/Remoting/RemFinalPDFStation.cs
6 6
using System;
7 7
using System.Collections.Concurrent;
8 8
using System.Collections.Generic;
9
using System.Diagnostics;
9 10
using System.IO;
10 11
using System.Linq;
11 12
using System.Reflection;
......
103 104

  
104 105
                foreach (var item in _Channel.GetUrlsForUri(endpoint))
105 106
                {
107
                    RemoteAddress = item;
106 108
                    _Logger.Write($"Final Service Open Channel - {item}",LogLevel.Info);
107 109
                } 
108 110
            }
......
114 116
            IFinalPDF.Cache.Attach(this);
115 117
        }
116 118

  
119
        private string RemoteAddress = null;
120

  
121

  
117 122
        private void SetFinalState(string finalID, FinalStatus status,string log = null)
118 123
        {
119 124
            using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
......
178 183
                    lock(WorkingList)
179 184
                    {
180 185
                        WorkingList.Add(pdf as FINAL_PDF);
181
                        Thread.Sleep(100);
186
                        Thread.Sleep(1000);
182 187
                    };
188
                    FinalPDFDequeueandProcessing(pdf as FINAL_PDF);
183 189

  
184
                    Thread thread = new Thread(new ParameterizedThreadStart(FinalPDFDequeueandProcessing));
185
                    thread.SetApartmentState(ApartmentState.STA);
186
                    thread.Start(pdf); 
187 190
                }
188 191
                else
189 192
                {
......
199 202
        /// <summary>
200 203
        /// 실제 Merged PDF를 생성한다
201 204
        /// </summary>
202
        private void FinalPDFDequeueandProcessing(object pdf)
205
        private void FinalPDFDequeueandProcessing(FINAL_PDF pdf)
203 206
        {
204
            Task tDeq = Task.Factory.StartNew(() =>
207
            try
205 208
            {
206
                try
209
                if(pdf != null)
207 210
                {
208
                    if(pdf != null)
209
                    {
210
                        var finalpdf = (FINAL_PDF)pdf;
211
                    _Logger.Write($"init ID:{pdf.ID} / ProjectNo:{pdf.PROJECT_NO} / DocumentId:{pdf.DOCUMENT_ID} / MarkupInfoId:{pdf.MARKUPINFO_ID} / CreateUser:{pdf.CREATE_USER_ID}",LogLevel.Info);
212
                }
211 213

  
212
                        _Logger.Write($"ID:{finalpdf.ID} / ProjectNo:{finalpdf.PROJECT_NO} / DocumentId:{finalpdf.DOCUMENT_ID} / MarkupInfoId:{finalpdf.MARKUPINFO_ID} / CreateUser:{finalpdf.CREATE_USER_ID}",LogLevel.Info);
213
                    }
214
                if (pdf.STATUS == (int)FinalStatus.Insert)
215
                {
216
                    /// 작업중이라고 데이타베이스에 저장한다
217
                    pdf.STATUS = (int)(FinalStatus.Wait);
214 218

  
215
                    if (((FINAL_PDF)pdf).STATUS == (int)FinalStatus.Insert)
219
                    using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
216 220
                    {
217
                        /// 작업중이라고 데이타베이스에 저장한다
218
                        ((FINAL_PDF)pdf).STATUS = (int)(FinalStatus.Wait);
219
                        using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
220
                        {
221
                            var selectItem = _entity.FINAL_PDF.Where(data => data.ID == ((FINAL_PDF)pdf).ID).FirstOrDefault();
222
                            selectItem.STATUS = (int)(FinalStatus.Wait);
223
                            _entity.SaveChanges();
224
                        }
221
                        var selectItem = _entity.FINAL_PDF.Where(data => data.ID == pdf.ID).FirstOrDefault();
222
                        selectItem.STATUS = (int)(FinalStatus.Wait);
223
                        _entity.SaveChanges();
225 224
                    }
226 225

  
227
                    /// 작업 수행
228
                    MarkupToPDF.MarkupToPDF _markuptoPDF = new MarkupToPDF.MarkupToPDF();
229
                    _markuptoPDF.FinalMakeError += new EventHandler<MarkupToPDF.MakeFinalErrorArgs>(_markuptoPDF_FinalMakeError);
230
                    _markuptoPDF.StatusChanged += new EventHandler<MarkupToPDF.StatusChangedEventArgs>(_markuptoPDF_StatusChange);
231
                    _markuptoPDF.EndFinal += new EventHandler<MarkupToPDF.EndFinalEventArgs>(_markuptoPDF_EndFinal);
232
                    Thread _stathread = new Thread(new ParameterizedThreadStart(_markuptoPDF.MakeFinalPDF))
226
                    Process Process = new Process();
227

  
228
                    ProcessStartInfo startInfo = new ProcessStartInfo
233 229
                    {
234
                        Name = ((FINAL_PDF)pdf).ID.ToString()
230
                        UseShellExecute = false,
231
                        FileName = "Markus.Service.ConvertProcess.exe",
232
                        WindowStyle = ProcessWindowStyle.Hidden,
233
                        CreateNoWindow = true,
234
                        ErrorDialog = false,
235
                        RedirectStandardError = false,
236
                        Arguments = $"{pdf.ID} {RemoteAddress}"
237
                        //Arguments = $"{convertitem.ConvertID.ToString()} {convertitem.ProjectNumber} {AESEncrypter.Encrypt(MarkusDBConnectionString)} {gServiceHostAddress} {DownloadTempFolder} {MultiThreadMaxPages}"
235 238
                    };
236
                    SetFinalState(((FINAL_PDF)pdf).ID, IFinalPDF.FinalStatus.Create);
237
                    _stathread.SetApartmentState(ApartmentState.STA);
238
                    _stathread.Start(pdf);
239
                }
240
                catch (Exception ex)
241
                {
242
                    _Logger.Write(ex);
239

  
240
                    Process.StartInfo = startInfo;
241
                    Process.EnableRaisingEvents = false;
242

  
243
                    if (Process.Start())
244
                    {
245
                        _Logger.Write($"Process Run - ID:{pdf.ID} / ProjectNo:{pdf.PROJECT_NO} / DocumentId:{pdf.DOCUMENT_ID} / MarkupInfoId:{pdf.MARKUPINFO_ID} / CreateUser:{pdf.CREATE_USER_ID}", LogLevel.Info);
246
                    }
247
                    else
248
                    {
249
                        _Logger.Write($"Process Run Error - ID:{pdf.ID}", LogLevel.Error);
250
                    }
243 251
                }
244
            });
252
            }
253
            catch (Exception ex)
254
            {
255
                _Logger.Write(ex);
256
            }
245 257
        }
246 258
        /// <summary>
247 259
        /// callback for WebService
......
493 505
                }
494 506
            }
495 507
        }
508

  
509
        public void Finish(string ProjectNo, string FinalID,string OriginFileName,string FinalPDFPath, string remodeFilePath)
510
        {
511
            _Logger.Write($"End Final FinalID:{FinalID} / Output:{FinalPDFPath}", LogLevel.Info);
512

  
513
            var _T = WorkingList.Where(t => t.ID == FinalID);
514

  
515
            if (_T.Count() > 0)
516
            {
517
                FINAL_PDF _item = _T.First();
518
                SetFinalState(_item.ID, FinalStatus.PdfStamp);
519

  
520
                try
521
                {
522
                    string soapurl = CommonLib.Common.GetConfigString("UpLoadServiceUrl", "URL", "");
523

  
524
                    string finalpdfroot = CommonLib.Common.GetConfigString("FinalPDFRootUrl", "URL", "");
525

  
526
                    string pdfpath = remodeFilePath;
527

  
528
                    if (!string.IsNullOrEmpty(finalpdfroot))
529
                    {
530
                        string filename = Path.GetFileName(FinalPDFPath);
531
                        pdfpath = !string.IsNullOrEmpty(finalpdfroot) ? finalpdfroot + filename : filename;
532
                    }
533

  
534
                    if (!string.IsNullOrEmpty(soapurl) && (Program.UploadFinalPDFInst != null) && (Program.UploadFinalPDFMethod != null))
535
                    {
536
                        object[] parameters = new object[] { FinalPDFPath, OriginFileName, _item, soapurl };
537

  
538
                        _Logger.Write("UploadPDF.dll Path :" + Program.UploadFinalAssmPath, LogLevel.Info);
539

  
540
                        _Logger.Write("Call Upload Final .." + pdfpath + " finalPDFPath : " + FinalPDFPath + " FinalPDFRemotePath : " + remodeFilePath + ",CreateUser:" + e.FinalPDF.CREATE_USER_ID + ",CreateUser:" + _item.DOCUMENT_ID + ",pdfname:" + OriginFileName + ",finalPDF ID : " + _item.ID + ",soapUri:" + soapurl, LogLevel.Info);
541

  
542
                        KeyValuePair<bool, string> result = (KeyValuePair<bool, string>)(Program.UploadFinalPDFMethod.Invoke(Program.UploadFinalPDFInst, parameters));
543

  
544
                        if (result.Key)
545
                        {
546
                            SetFinalState(_item.ID, FinalStatus.Success);
547
                        }
548
                        else
549
                        {
550
                            SetFinalState(_item.ID, FinalStatus.Error);
551
                            _Logger.Write("Upload error  .." + pdfpath + ",pdfname:" + e.OriginPDFName + " Msg : " + result.Value, LogLevel.Error);
552
                        }
553
                    }
554
                    else
555
                    {
556
                        ///TODO: 저장할 폴더 위치를 configuration으로 빼주세요
557

  
558
                        string savepath = CommonLib.Common.GetConfigString("DebugSavePath", "URL", "");
559

  
560
                        string sFolder = _item.DOCUMENT_ID.All(char.IsDigit) ? (Convert.ToInt32(_item.DOCUMENT_ID) / 100).ToString() : _item.DOCUMENT_ID.Substring(0, 5);
561
                        string saveFolder = String.Format(savepath, _item.PROJECT_NO, sFolder, _item.DOCUMENT_ID);
562
                        if (!System.IO.Directory.Exists(saveFolder))
563
                        {
564
                            System.IO.Directory.CreateDirectory(saveFolder);
565
                        }
566

  
567
                        _Logger.Write(String.Format("saveFolder : {0}", saveFolder), LogLevel.Info);
568

  
569
                        try
570
                        {
571
                            System.IO.File.Copy(pdfpath, saveFolder + OriginFileName, true);
572

  
573
                            _Logger.Write($"End Final SaveFile :{saveFolder + OriginFileName}", LogLevel.Info);
574
                        }
575
                        catch (Exception ex)
576
                        {
577
                            _Logger.Write(ex);
578
                        }
579

  
580
                        using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(_item.PROJECT_NO).ToString()))
581
                        {
582
                            var item = _entity.DOCUMENT_ITEM.Where(d => d.DOCUMENT_ID == _item.DOCUMENT_ID).FirstOrDefault();
583
                            ///TODO: RESULT FILE 경로 위치를 configuration으로 빼주세요
584
                            string resultpath = CommonLib.Common.GetConfigString("DebugResultUrlPath", "URL", "");
585

  
586
                            try
587
                            {
588
                                item.RESULT_FILE = String.Format(resultpath, _item.PROJECT_NO, sFolder, _item.DOCUMENT_ID, OriginFileName);
589
                            }
590
                            catch (Exception ex)
591
                            {
592
                                _Logger.Write(new Exception($"DebugResultUrlPath의 Index를 확인 하세요.{resultpath}", ex));
593
                            }
594

  
595
                            _Logger.Write($"End FinalId:{item.ID} RESULT_FILE_PATH:{item.RESULT_FILE}", LogLevel.Info);
596
                            _entity.SaveChanges();
597
                            SetFinalState(_item.ID, FinalStatus.Success);
598
                        }
599
                    }
600
                }
601
                catch (Exception ex)
602
                {
603
                    SetFinalState(_item.ID, FinalStatus.Error);
604
                    _Logger.Write(ex);
605
                }
606
                finally
607
                {
608
                    WorkingList.Remove(_T.First());
609

  
610
                }
611

  
612
                /// 대기중인 merged pdf가 있을 경우 merged pdf를 생성한다
613
                if (this.WaitingQueue.Count > 0)
614
                {
615
                    FINAL_PDF pdf;
616
                    if (this.WaitingQueue.TryDequeue(out pdf))
617
                    {
618
                        ThreadPool.QueueUserWorkItem(this.MakeMergedPDF, pdf);
619
                    }
620
                }
621
            }
622
        }
623

  
624
        public void Error(string ProjectNo, string FinalID, string Error)
625
        {
626
            _Logger.Write($"FinalID:{FinalID} / Message :{Error}", LogLevel.Info);
627

  
628
            using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
629
            {
630
                var items = _entity.FINAL_PDF.Where(x => x.ID == FinalID);
631

  
632
                if (items.Count() > 0)
633
                {
634
                   var  finalPdf = items.First();
635

  
636
                    SetError(FinalID, Error);
637

  
638
                    var _T = WorkingList.Where(t => t.ID == finalPdf.ID);
639

  
640
                    if (_T.Count() > 0)
641
                    {
642
                        FINAL_PDF _Item = _T.First();
643
                        WorkingList.Remove(_Item);
644
                    }
645

  
646
                    /// 대기중인 merged pdf가 있을 경우 merged pdf를 생성한다
647
                    if (this.WaitingQueue.Count > 0)
648
                    {
649
                        FINAL_PDF pdf;
650
                        if (this.WaitingQueue.TryDequeue(out pdf))
651
                        {
652
                            ThreadPool.QueueUserWorkItem(this.MakeMergedPDF, pdf);
653
                        }
654
                    }
655
                }
656
            }
657

  
658
        }
496 659
    }
497 660
}
FinalService/KCOM_FinalService/KCOM_FinalService/packages.config
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<packages>
3
  <package id="log4net" version="2.0.11" targetFramework="net461" />
3
  <package id="log4net" version="2.0.12" targetFramework="net461" />
4 4
</packages>
FinalService/KCOM_FinalService/KCOM_FinalServiceConsole/KCOM_FinalServiceConsole.csproj
77 77
    <Reference Include="EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
78 78
      <HintPath>..\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll</HintPath>
79 79
    </Reference>
80
    <Reference Include="log4net, Version=2.0.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
81
      <HintPath>..\packages\log4net.2.0.11\lib\net45\log4net.dll</HintPath>
80
    <Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
81
      <HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
82 82
    </Reference>
83 83
    <Reference Include="System" />
84 84
    <Reference Include="System.ComponentModel.DataAnnotations" />
FinalService/KCOM_FinalService/KCOM_FinalServiceConsole/packages.config
2 2
<packages>
3 3
  <package id="EntityFramework" version="5.0.0" targetFramework="net461" />
4 4
  <package id="EntityFramework.ko" version="5.0.0" targetFramework="net461" />
5
  <package id="log4net" version="2.0.11" targetFramework="net461" />
5
  <package id="log4net" version="2.0.12" targetFramework="net461" />
6 6
</packages>
FinalService/KCOM_FinalService/MarkupToPDF/EventMember.cs
17 17

  
18 18
    }
19 19

  
20
    public class EndFinalResult
21
    {
22
        public string Message { get; set; }
23
        public string Error { get; set; }
24
        public string FinalPDFPath { get; set; }
25
        public string FinalPDFRemotePath { get; set; }
26

  
27
        public string OriginPDFName { get; set; }
28

  
29
    }
30

  
20 31
    public class StatusChangedEventArgs : EventArgs
21 32
    {
22 33
        public string Message { get; set; }
FinalService/KCOM_FinalService/MarkupToPDF/MarkupToPDF - 복사본.cs
1
using IFinalPDF;
2
using iTextSharp.text.pdf;
3
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5
using MarkupToPDF.Controls.Common;
6
using MarkupToPDF.Serialize.Core;
7
using MarkupToPDF.Serialize.S_Control;
8
using Markus.Fonts;
9
using System;
10
using System.Collections.Generic;
11
using System.Configuration;
12
using System.IO;
13
using System.Linq;
14
using System.Net;
15
using System.Runtime.InteropServices;
16
using System.Text;
17
using System.Web;
18
using System.Windows;
19
using System.Windows.Media;
20

  
21
namespace MarkupToPDF
22
{
23
    public class MarkupToPDF : IDisposable
24
    {
25

  
26
        #region 초기 데이터
27
        private static iTextSharp.text.Rectangle mediaBox;
28
        private FileInfo PdfFilePath = null;
29
        private FileInfo FinalPDFPath = null;
30
        private string _FinalPDFStorgeLocal = null;
31
        private string _FinalPDFStorgeRemote = null;
32
        private string OriginFileName = null;
33
        public FINAL_PDF FinalItem;
34
        public DOCINFO DocInfoItem = null;
35
        public List<DOCPAGE> DocPageItem = null;
36
        public MARKUP_INFO MarkupInfoItem = null;
37
        public List<MARKUP_DATA> MarkupDataSet = null;
38
        //private string _PrintPDFStorgeLocal = null;
39
        //private string _PrintPDFStorgeRemote = null;
40
        public event EventHandler<MakeFinalErrorArgs> FinalMakeError;
41
        public event EventHandler<EndFinalEventArgs> EndFinal;
42
        public event EventHandler<StatusChangedEventArgs> StatusChanged;
43

  
44
        private iTextSharp.text.Rectangle pdfSize { get; set; }
45
        private double pageW = 0;
46
        private double pageH = 0;
47

  
48
        //private const double zoomLevel = 3.0;
49
        private const double zoomLevel = 1.0; // 지금은 3배수로 곱하지 않고 있음
50
        #endregion
51

  
52
        #region 메서드        
53
        public static bool IsLocalIPAddress(string host)
54
        {
55
            try
56
            {
57
                IPAddress[] hostIPs = Dns.GetHostAddresses(host);
58
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
59

  
60
                foreach (IPAddress hostIP in hostIPs)
61
                {
62
                    if (IPAddress.IsLoopback(hostIP)) return true;
63

  
64
                    foreach (IPAddress localIP in localIPs)
65
                    {
66
                        if (hostIP.Equals(localIP)) return true;
67
                    }
68
                }
69
            }
70
            catch { }
71
            return false;
72
        }
73

  
74
        private void SetNotice(string finalID, string message)
75
        {
76
            if (FinalMakeError != null)
77
            {
78
                FinalMakeError(this, new MakeFinalErrorArgs { FinalID = finalID, Message = message });
79
            }
80
        }
81

  
82
        private string GetFileName(string hrefLink)
83
        {
84
            try
85
            {
86
                if (hrefLink.Contains("vpcs_doclib"))
87
                {
88
                    return System.IO.Path.GetFileName(hrefLink.Replace("/", "\\"));
89
                }
90
                else
91
                {
92
                    Uri fileurl = new Uri(hrefLink);
93
                    int index = hrefLink.IndexOf("?");
94
                    string filename = HttpUtility.ParseQueryString(fileurl.Query).Get("fileName");
95
                    return filename;
96
                }
97
            }
98
            catch (Exception ex)
99
            {
100
                throw ex;
101
            }
102
        }
103

  
104
        public Point GetPdfPointSystem(Point point)
105
        {
106
            /// 주어진 좌표를 pdf의 (Left, Top - Bottom(?)) 좌표에 맞추어 변환한다.
107
            /// Rotation 90 일 경우 pdfsize box 와 media box 가 달라 다른 계산식 적용
108
            if (pdfSize.Rotation == 90)
109
            {
110
                return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Top - (float)(point.Y / scaleHeight) - pdfSize.Bottom);
111
            }
112
            else
113
            {
114
                return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Height - (float)(point.Y / scaleHeight) + pdfSize.Bottom);
115
            }  
116
        }
117

  
118
        public double GetPdfSize(double size)
119
        {
120
            return (size / scaleWidth);
121
        }
122

  
123
        public List<Point> GetPdfPointSystem(List<Point> point)
124
        {
125
            List<Point> dummy = new List<Point>();
126
            foreach (var item in point)
127
            {
128
                dummy.Add(GetPdfPointSystem(item));
129
            }
130
            return dummy;
131
        }
132

  
133
        public double returnAngle(Point start, Point end)
134
        {
135
            double angle = MathSet.getAngle(start.X, start.Y, end.X, end.Y);
136
            //angle *= -1;
137

  
138
            angle += 90;
139
            //if (angle < 0)
140
            //{
141
            //    angle = angle + 360;
142
            //}
143
            return angle;
144
        }
145

  
146
        #endregion
147

  
148
        public bool AddStamp(string stampData)
149
        {
150
            bool result = false;
151

  
152
            try
153
            {
154
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
155
                {
156
                    var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
157

  
158
                    if(stamp.Count() > 0)
159
                    {
160
                        var xamldata = Serialize.Core.JsonSerializerHelper.CompressStamp(stampData);
161

  
162
                        stamp.First().VALUE = xamldata;
163
                        _entity.SaveChanges();
164
                        result = true;
165
                    }
166
                }
167
            }
168
            catch (Exception)
169
            {
170

  
171
                throw;
172
            }
173

  
174
            return result;
175

  
176
        }
177

  
178
        /// <summary>
179
        /// local에서 final 생성하는 경우 이 함수로 추가 후 실행
180
        /// </summary>
181
        /// <param name="finalpdf"></param>
182
        /// <returns></returns>
183
        public AddFinalPDFResult AddFinalPDF(string ProjectNo,string DocumentID,string UserID)
184
        {
185
            //var list = Markus.Fonts.FontHelper.GetFontStream("Arial Unicode MS");
186
            //System.Diagnostics.Debug.WriteLine(list);
187

  
188
            AddFinalPDFResult result = new AddFinalPDFResult { Success = false };
189

  
190
            try
191
            {
192
                FINAL_PDF addItem = new FINAL_PDF{
193
                    ID = CommonLib.Guid.shortGuid(),
194
                    PROJECT_NO = ProjectNo,
195
                    DOCUMENT_ID = DocumentID,
196
                    CREATE_USER_ID = UserID,
197
                    CREATE_DATETIME = DateTime.Now,
198
                    STATUS = 4
199
                };
200

  
201
                using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
202
                {
203
                    var docitems = _entity.DOCINFO.Where(x => x.PROJECT_NO == ProjectNo && x.DOCUMENT_ID == DocumentID);
204

  
205
                    if(docitems.Count() > 0)
206
                    {
207
                        addItem.DOCINFO_ID = docitems.First().ID;
208
                        result.Success = true;
209
                    }
210
                    else
211
                    {
212
                        result.Exception = "docInfo Not Found.";
213
                        result.Success = false;
214
                    }
215

  
216
                    var markupInfoItems = _entity.MARKUP_INFO.Where(x =>x.DOCINFO_ID == addItem.DOCINFO_ID);
217

  
218
                    if (markupInfoItems.Count() > 0)
219
                    {
220
                        addItem.MARKUPINFO_ID = markupInfoItems.First().ID;
221
                        result.Success = true;
222
                    }
223
                    else
224
                    {
225
                        result.Exception = "Markup Info Not Found.";
226
                        result.Success = false;
227
                    }
228
                }
229

  
230
                if (result.Success)
231
                {
232
                    using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
233
                    {
234
                        var finalList = _entity.FINAL_PDF.Where(final => final.ID == addItem.ID);
... 이 차이점은 표시할 수 있는 최대 줄수를 초과해서 이 차이점은 잘렸습니다.

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)