프로젝트

일반

사용자정보

개정판 5c3caba6

ID5c3caba68a67e3acf84385db4109dd07208e071c
상위 b2d0f316
하위 e755dd44

백흠경이(가) 5달 전에 추가함

Fix: 이미지 위에 객체를 생성할 때 객체가 이미지 뒤에 숨는 오류

Change-Id: If491e582f33be01f3e4e2b21594ed51122f48054

차이점 보기:

KCOM/AbstractDatabase.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Web;
5
using System.Data;
6
using System.Data.Common;
7

  
8
namespace KCOM
9
{
10
    public class ColInfo
11
    {
12
        public string Name { get; set; }
13
        public string DataType { get; set; }
14
    }
15

  
16
    /// <summary>
17
    /// Abstract base class for encapsulating provider independant database interactin logic.
18
    /// </summary>
19
    /// <remarks>Version 2.0</remarks>
20
    /// <typeparam name="CONNECTION_TYPE"><see cref="DbConnection"/> derived Connection type.</typeparam>
21
    /// <typeparam name="COMMAND_TYPE"><see cref="DbCommand"/> derived Command type.</typeparam>
22
    /// <typeparam name="ADAPTER_TYPE"><see cref="DbDataAdapater"/> derived Data Adapter type.</typeparam>
23
    public abstract class AbstractDatabase<CONNECTION_TYPE, COMMAND_TYPE, ADAPTER_TYPE> : IDisposable, IAbstractDatabase
24
        where CONNECTION_TYPE : DbConnection, new()
25
        where COMMAND_TYPE : DbCommand
26
        where ADAPTER_TYPE : DbDataAdapter, new()
27
    {
28
        #region : Connection :
29

  
30
        /// <summary>Gets the Connection object associated with the current instance.</summary>
31
        public DbConnection Connection
32
        {
33
            get
34
            {
35
                if (internal_currentConnection == null)
36
                {
37
                    internal_currentConnection = new CONNECTION_TYPE() { ConnectionString = GetConnectionString() };
38
                }
39
                return internal_currentConnection;
40
            }
41
        }
42
        private DbConnection internal_currentConnection = null;
43

  
44
        /// <summary>When overridden in derived classes returns the connection string for the database.</summary>
45
        /// <returns>The connection string for the database.</returns>
46
        protected abstract string GetConnectionString();
47

  
48
        #endregion
49

  
50
        #region : Commands :
51

  
52
        /// <summary>Gets a DbCommand object with the specified <see cref="DbCommand.CommandText"/>.</summary>
53
        /// <param name="sqlString">The SQL string.</param>
54
        /// <returns>A DbCommand object with the specified <see cref="DbCommand.CommandText"/>.</returns>
55
        public DbCommand GetSqlStringCommand(string sqlString)
56
        {
57
            if (this.Connection.State != ConnectionState.Open)
58
                this.Connection.Open();
59

  
60
            DbCommand cmd = this.Connection.CreateCommand();
61
            cmd.CommandType = CommandType.Text;
62
            cmd.CommandText = sqlString;
63
            cmd.CommandTimeout = 600; // 15.11.04 added by soohyun - Extend Time out of query
64
            return cmd;
65
        }
66

  
67
        /// <summary>Gets a DbCommand object with the specified <see cref="DbCommand.CommandText"/>.</summary>
68
        /// <param name="sqlStringFormat">The SQL string format.</param>
69
        /// <param name="args">The format arguments.</param>
70
        /// <returns>A DbCommand object with the specified <see cref="DbCommand.CommandText"/>.</returns>
71
        public DbCommand GetSqlStringCommand(string sqlStringFormat, params object[] args)
72
        {
73
            return GetSqlStringCommand(string.Format(sqlStringFormat, args));
74
        }
75

  
76
        /// <summary>Gets a DbCommand object for the specified Stored Procedure.</summary>
77
        /// <param name="storedProcName">The name of the stored procedure.</param>
78
        /// <returns>A DbCommand object for the specified Stored Procedure.</returns>
79
        public DbCommand GetStoredProcedureCommand(string storedProcName)
80
        {
81
            if (this.Connection.State != ConnectionState.Open)
82
                this.Connection.Open();
83

  
84
            DbCommand cmd = this.Connection.CreateCommand();
85
            cmd.CommandType = CommandType.StoredProcedure;
86
            cmd.CommandText = storedProcName;
87
            return cmd;
88
        }
89

  
90
        #region : Parameters :
91

  
92
        /// <summary>Adds an input parameter to the given <see cref="DbCommand"/>.</summary>
93
        /// <param name="cmd">The command object the parameter should be added to.</param>
94
        /// <param name="paramName">The identifier of the parameter.</param>
95
        /// <param name="paramType">The type of the parameter.</param>
96
        /// <param name="value">The value of the parameter.</param>
97
        /// <returns>The <see cref="DbParameter"/> that was created.</returns>
98
        public DbParameter AddInParameter(DbCommand cmd, string paramName, DbType paramType, object value)
99
        {
100
            return AddParameter(cmd, paramName, paramType, ParameterDirection.Input, value);
101
        }
102

  
103
        /// <summary>Adds an input parameter to the given <see cref="DbCommand"/>.</summary>
104
        /// <param name="cmd">The command object the parameter should be added to.</param>
105
        /// <param name="paramName">The identifier of the parameter.</param>
106
        /// <param name="paramType">The type of the parameter.</param>
107
        /// <param name="size">The maximum size in bytes, of the data table column to be affected.</param>
108
        /// <param name="value">The value of the parameter.</param>
109
        /// <returns>The <see cref="DbParameter"/> that was created.</returns>
110
        public DbParameter AddInParameter(DbCommand cmd, string paramName, DbType paramType, int size, object value)
111
        {
112
            DbParameter param = AddInParameter(cmd, paramName, paramType, value);
113
            param.Size = size;
114
            cmd.Parameters.Add(param);
115
            return param;
116
        }
117

  
118
        /// <summary>Adds the out parameter to the given <see cref="DbCommand"/></summary>
119
        /// <param name="cmd">The command object the parameter should be added to.</param>
120
        /// <param name="paramName">The identifier of the parameter.</param>
121
        /// <param name="paramType">The type of the parameter.</param>
122
        /// <param name="value">The value of the parameter.</param>
123
        /// <returns>The <see cref="DbParameter"/> that was created.</returns>
124
        public DbParameter AddOutParameter(DbCommand cmd, string paramName, DbType paramType, object value)
125
        {
126
            return AddParameter(cmd, paramName, paramType, ParameterDirection.Output, value);
127
        }
128

  
129
        /// <summary>Adds a parameter to the given <see cref="DbCommand"/>.</summary>
130
        /// <param name="cmd">The command object the parameter should be added to.</param>
131
        /// <param name="paramName">The identifier of the parameter.</param>
132
        /// <param name="paramType">The type of the parameter.</param>
133
        /// <param name="direction"><see cref="ParameterDirection"/> of the parameter.</param>
134
        /// <param name="value">The value of the parameter.</param>
135
        /// <returns>The <see cref="DbParameter"/> that was created.</returns>
136
        public DbParameter AddParameter(DbCommand cmd, string paramName,
137
                                            DbType paramType,
138
                                            ParameterDirection direction,
139
                                            object value)
140
        {
141
            DbParameter param = cmd.CreateParameter();
142
            param.DbType = paramType;
143
            param.ParameterName = paramName;
144
            param.Value = value;
145
            param.Direction = direction;
146
            cmd.Parameters.Add(param);
147
            return param;
148
        }
149

  
150
        /// <summary>Adds a parameter to the given <see cref="DbCommand"/>.</summary>
151
        /// <param name="cmd">The command object the parameter should be added to.</param>
152
        /// <param name="paramName">The identifier of the parameter.</param>
153
        /// <param name="paramType">The type of the parameter.</param>
154
        /// <param name="direction"><see cref="ParameterDirection"/> of the parameter.</param>
155
        /// <param name="size">The maximum size in bytes, of the data table column to be affected.</param>
156
        /// <param name="value">The value of the parameter.</param>
157
        /// <returns>The <see cref="DbParameter"/> that was created.</returns>
158
        public DbParameter AddParameter(DbCommand cmd, string paramName,
159
                                            DbType paramType,
160
                                            ParameterDirection direction,
161
                                            int size,
162
                                            object value)
163
        {
164
            DbParameter param = AddParameter(cmd, paramName, paramType, direction, value);
165
            param.Size = size;
166
            return param;
167
        }
168

  
169
        #endregion
170

  
171
        #region : Executes :
172

  
173
        /// <summary>Executes the specified command against the current connection.</summary>
174
        /// <param name="cmd">The command to be executed.</param>
175
        /// <returns>Result returned by the database engine.</returns>
176
        public int ExecuteNonQuery(DbCommand cmd)
177
        {
178
            if (this.Connection.State != ConnectionState.Open)
179
                this.Connection.Open();
180

  
181
            return cmd.ExecuteNonQuery();
182
        }
183

  
184
        public int ExecuteNonQuery(string sSql)
185
        {
186
            if (this.Connection.State != ConnectionState.Open)
187
                this.Connection.Open();
188

  
189
            return GetSqlStringCommand(sSql).ExecuteNonQuery();
190
        }
191

  
192
        /// <summary>Executes the specified command against the current connection.</summary>
193
        /// <param name="cmd">The command to be executed.</param>
194
        /// <param name="txn">The database transaction inside which the command should be executed.</param>
195
        /// <returns>Result returned by the database engine.</returns>
196
        public int ExecuteNonQuery(DbCommand cmd, DbTransaction txn)
197
        {
198
            if (this.Connection.State != ConnectionState.Open)
199
                this.Connection.Open();
200

  
201
            cmd.Transaction = txn;
202
            return cmd.ExecuteNonQuery();
203
        }
204

  
205
        /// <summary>Executes the specified command against the current connection.</summary>
206
        /// <param name="cmd">The command to be executed.</param>
207
        /// <returns>Result returned by the database engine.</returns>
208
        public DbDataReader ExecuteReader(DbCommand cmd)
209
        {
210
            if (this.Connection.State != ConnectionState.Open)
211
                this.Connection.Open();
212

  
213
            return cmd.ExecuteReader();
214
        }
215

  
216
        /// <summary>Executes the specified command against the current connection.</summary>
217
        /// <param name="cmd">The command to be executed.</param>
218
        /// <param name="behavior">One of the <see cref="System.Data.CommandBehavior"/> values.</param>
219
        /// <returns>Result returned by the database engine.</returns>
220
        public DbDataReader ExecuteReader(DbCommand cmd, CommandBehavior behavior)
221
        {
222
            if (this.Connection.State != ConnectionState.Open)
223
                this.Connection.Open();
224

  
225
            return cmd.ExecuteReader(behavior);
226
        }
227

  
228
        /// <summary>Executes the specified command against the current connection.</summary>
229
        /// <param name="cmd">The command to be executed.</param>
230
        /// <returns>Result returned by the database engine.</returns>
231
        public T ExecuteScalar<T>(DbCommand cmd, T defaultValue)
232
        {
233
            if (this.Connection.State != ConnectionState.Open)
234
                this.Connection.Open();
235

  
236
            object retVal = cmd.ExecuteScalar();
237
            if (null == retVal || DBNull.Value == retVal)
238
                return defaultValue;
239
            else
240
                return (T)retVal;
241
        }
242

  
243
        /// <summary>Executes the specified command against the current connection.</summary>
244
        /// <param name="cmd">The command to be executed.</param>
245
        /// <returns>Result returned by the database engine.</returns>
246
        public DataSet ExecuteDataSet(DbCommand cmd, DbTransaction txn = null)
247
        {
248
            ADAPTER_TYPE adapter = new ADAPTER_TYPE();
249
            if (null != txn) cmd.Transaction = txn;
250
            adapter.SelectCommand = (COMMAND_TYPE)cmd;
251

  
252
            DataSet retVal = new DataSet()
253
            {
254
                Locale = System.Globalization.CultureInfo.InvariantCulture
255
            };
256
            adapter.Fill(retVal);
257
            return retVal;
258
        }
259

  
260
        #endregion
261

  
262
        #endregion
263

  
264
        /// <summary>Begins a transaction.</summary>
265
        /// <returns>Created transaction.</returns>
266
        public DbTransaction BeginTransaction()
267
        {
268
            if (this.Connection.State != ConnectionState.Open)
269
                this.Connection.Open();
270
            return Connection.BeginTransaction();
271
        }
272

  
273
        #region : Consturction / Destruction :
274

  
275
        /// <summary>Disposes the resources associated with the current database connection.</summary>
276
        ~AbstractDatabase()
277
        {
278
            Dispose();
279
        }
280

  
281
        #region IDisposable Members
282

  
283
        /// <summary>Disposes the resources associated with the current database connection.</summary>
284
        public void Dispose()
285
        {
286
            if (null != internal_currentConnection)
287
            {
288
                internal_currentConnection.Dispose();
289
                internal_currentConnection = null;
290
            }
291
        }
292

  
293
        #endregion
294

  
295
        #endregion
296
    }
297
}
KCOM/AppSQLiteDatabase.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Data;
6
using System.Data.Common;
7
using System.Data.SQLite;
8
using System.Globalization;
9

  
10
namespace KCOM
11
{
12
	class AppSQLiteDatabase : AbstractDatabase<SQLiteConnection , SQLiteCommand , SQLiteDataAdapter>
13
	{
14
		public string FilePath{get;set;}
15

  
16
        /// <summary>
17
        /// sqlite connection string
18
        /// </summary>
19
        /// <author>humkyung</author>
20
        /// <date>2019.02.10</date>
21
        /// <returns></returns>
22
        protected override string  GetConnectionString()
23
		{
24
            return string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", this.FilePath);
25
		}
26
    }
27
}
KCOM/IAbstractDatabase.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Web;
5
using System.Text;
6
using System.Data;
7
using System.Data.Common;
8

  
9
namespace KCOM
10
{
11
    public interface IAbstractDatabase : IDisposable
12
    {
13
        DbConnection Connection { get; }
14
        DbCommand GetSqlStringCommand(string sqlString);
15
        DbCommand GetSqlStringCommand(string sqlStringFormat, params object[] args);
16
        DbCommand GetStoredProcedureCommand(string storedProcName);
17

  
18
        DbParameter AddInParameter(DbCommand cmd, string paramName, DbType paramType, object value);
19
        DbParameter AddInParameter(DbCommand cmd, string paramName, DbType paramType, int size, object value);
20
        DbParameter AddOutParameter(DbCommand cmd, string paramName, DbType paramType, object value);
21
        DbParameter AddParameter(DbCommand cmd, string paramName,
22
                                            DbType paramType,
23
                                            ParameterDirection direction,
24
                                            object value);
25
        DbParameter AddParameter(DbCommand cmd, string paramName,
26
                                            DbType paramType,
27
                                            ParameterDirection direction,
28
                                            int size,
29
                                            object value);
30

  
31
        int ExecuteNonQuery(DbCommand cmd);
32
        int ExecuteNonQuery(string sSql);
33
        int ExecuteNonQuery(DbCommand cmd, DbTransaction txn);
34
        DbDataReader ExecuteReader(DbCommand cmd);
35
        DbDataReader ExecuteReader(DbCommand cmd, CommandBehavior behavior);
36
        DataSet ExecuteDataSet(DbCommand cmd, DbTransaction txn = null);
37

  
38
        DbTransaction BeginTransaction();
39
    }
40
}
KCOM/Views/MainMenu.xaml.cs
2757 2757

  
2758 2758
            foreach (var item in ViewerDataModel.Instance.MarkupControls_USER)
2759 2759
            {
2760
                if (item as ArrowTextControl != null)
2760
                if (item is ArrowTextControl ArrTextCtrl)
2761 2761
                {
2762
                    (item as ArrowTextControl).Base_TextBox.IsHitTestVisible = false;
2762
                    ArrTextCtrl.Base_TextBox.IsHitTestVisible = false;
2763 2763
                }
2764
                else if (item as TextControl != null)
2764
                else if (item is TextControl TextCtrl)
2765 2765
                {
2766
                    (item as TextControl).Base_TextBox.IsHitTestVisible = false;
2766
                    TextCtrl.Base_TextBox.IsHitTestVisible = false;
2767 2767
                }
2768 2768
            }
2769 2769

  
2770 2770
            //if (currentControl != null)
2771 2771
            {
2772
                var text_item_ = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as TextControl) != null && (data as TextControl).IsEditingMode == true).FirstOrDefault();
2772
                var text_item_ = ViewerDataModel.Instance.MarkupControls_USER.FirstOrDefault(data => (data as TextControl) != null && (data as TextControl).IsEditingMode);
2773 2773
                if (text_item_ != null)
2774 2774
                {
2775 2775
                    (text_item_ as TextControl).Base_TextBlock.Visibility = Visibility.Visible;
......
2778 2778
                    currentControl = null;
2779 2779
                }
2780 2780

  
2781
                var Arrowtext_item_ = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as ArrowTextControl) != null && (data as ArrowTextControl).IsEditingMode == true).FirstOrDefault();
2781
                var Arrowtext_item_ = ViewerDataModel.Instance.MarkupControls_USER.FirstOrDefault(data => (data as ArrowTextControl) != null && (data as ArrowTextControl).IsEditingMode);
2782 2782
                if (Arrowtext_item_ != null && ((Arrowtext_item_ as ArrowTextControl).IsNew == false))
2783 2783
                {
2784 2784
                    (Arrowtext_item_ as ArrowTextControl).IsEditingMode = false;
......
2793 2793
                Ang = 360 - rotate.Angle;
2794 2794
            }
2795 2795

  
2796
            if (e.OriginalSource is System.Windows.Controls.Image)
2796
            if (e.OriginalSource is System.Windows.Controls.Image imgctrl)
2797 2797
            {
2798
                (e.OriginalSource as System.Windows.Controls.Image).Focus();
2798
                imgctrl.Focus();
2799 2799
            }
2800 2800
            /*
2801 2801
            if (mouseHandlingMode == MouseHandlingMode.DragSymbol && e.LeftButton == MouseButtonState.Pressed)
......
2897 2897
                    isLeftMouseButtonDownOnWindow = true;
2898 2898
                }
2899 2899

  
2900
                var control = ViewerDataModel.Instance.MarkupControls_USER.Where(data => data.IsMouseEnter).FirstOrDefault();
2901

  
2900
                var control = ViewerDataModel.Instance.MarkupControls_USER.FirstOrDefault(data => data.IsMouseEnter);
2902 2901
                if (control == null)
2903 2902
                {
2904 2903
                    ViewerDataModel.Instance.SetAngleVisible(Visibility.Collapsed);
......
3063 3062
                        init_user = true;
3064 3063
                    }
3065 3064
                }
3066
                if (init_user && gridViewMarkup.SelectedItems.Where(d => (d as MarkupInfoItem).UserID == App.ViewInfo.UserID).FirstOrDefault() == null && e.LeftButton == MouseButtonState.Pressed)
3065
                if (init_user && gridViewMarkup.SelectedItems.FirstOrDefault(d => (d as MarkupInfoItem).UserID == App.ViewInfo.UserID) == null && e.LeftButton == MouseButtonState.Pressed)
3067 3066
                {
3068 3067
                    // 기존의 코멘트가 존재합니다. 사용자 리스트에서 먼저 선택해주세요
3069 3068
                    RadWindow.Alert(new DialogParameters
......
3090 3089
                        {
3091 3090
                            if (e.LeftButton == MouseButtonState.Pressed)
3092 3091
                            {
3093
                                if (currentControl is CoordinateControl)
3092
                                if (currentControl is CoordinateControl coord)
3094 3093
                                {
3095
                                    if (IsGetoutpoint((currentControl as CoordinateControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3094
                                    if (IsGetoutpoint(coord.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3096 3095
                                    {
3097 3096
                                        return;
3098 3097
                                    }
......
3106 3105
                                {
3107 3106
                                    this.ParentOfType<MainWindow>().dzTopMenu._SaveEvent(null, null);
3108 3107
                                    if (ViewerDataModel.Instance.MyMarkupList.Where(d => d.PageNumber == Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber
3109
                                     && d.Data_Type == Convert.ToInt32(MarkupToPDF.Controls.Common.ControlType.Coordinate)).Count() > 0)
3108
                                     && d.Data_Type == Convert.ToInt32(MarkupToPDF.Controls.Common.ControlType.Coordinate)).Any())
3110 3109
                                    {
3111 3110
                                        currentControl = null;
3112 3111
                                        this.cursor = Cursors.Arrow;
......
3127 3126
                                        currentControl.IsNew = true;
3128 3127

  
3129 3128
                                        ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3130

  
3131
                                        currentControl.SetValue(Canvas.ZIndexProperty, 3);
3129
                                        currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3132 3130
                                    }
3133 3131
                                }
3134 3132
                            }
......
3139 3137
                        {
3140 3138
                            if (e.LeftButton == MouseButtonState.Pressed)
3141 3139
                            {
3142
                                if (currentControl is InsideWhiteControl)
3140
                                if (currentControl is InsideWhiteControl whitectrl)
3143 3141
                                {
3144
                                    if (IsGetoutpoint((currentControl as InsideWhiteControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3142
                                    if (IsGetoutpoint(whitectrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3145 3143
                                    {
3146 3144
                                        return;
3147 3145
                                    }
......
3165 3163
                                    currentControl.IsNew = true;
3166 3164
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3167 3165

  
3168
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
3166
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3169 3167
                                }
3170 3168
                            }
3171 3169
                        }
......
3201 3199
                                    currentControl.IsNew = true;
3202 3200
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3203 3201

  
3204
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
3202
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3205 3203
                                }
3206 3204
                            }
3207 3205
                        }
......
3237 3235
                                    currentControl.IsNew = true;
3238 3236
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3239 3237

  
3240
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
3238
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3241 3239
                                }
3242 3240
                            }
3243 3241
                        }
......
3247 3245
                        {
3248 3246
                            if (e.LeftButton == MouseButtonState.Pressed)
3249 3247
                            {
3250
                                if (currentControl is RectangleControl)
3248
                                if (currentControl is RectangleControl rectctrl)
3251 3249
                                {
3252 3250
                                    //20180906 LJY TEST IsRotationDrawingEnable
3253
                                    if (IsGetoutpoint((currentControl as RectangleControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3251
                                    if (IsGetoutpoint(rectctrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3254 3252
                                    {
3255 3253
                                        return;
3256 3254
                                    }
......
3273 3271
                                    currentControl.IsNew = true;
3274 3272
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3275 3273

  
3276
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
3274
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3277 3275
                                }
3278 3276
                            }
3279 3277
                        }
......
3283 3281
                        {
3284 3282
                            if (e.LeftButton == MouseButtonState.Pressed)
3285 3283
                            {
3286
                                if (currentControl is RectCloudControl)
3284
                                if (currentControl is RectCloudControl rectcloudctrl)
3287 3285
                                {
3288 3286
                                    //20180906 LJY TEST IsRotationDrawingEnable
3289
                                    if (IsGetoutpoint((currentControl as RectCloudControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3287
                                    if (IsGetoutpoint(rectcloudctrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3290 3288
                                    {
3291 3289
                                        return;
3292 3290
                                    }
......
3310 3308
                                    currentControl.CommentID = Commons.shortGuid();
3311 3309
                                    currentControl.IsNew = true;
3312 3310
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3311
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3313 3312
                                }
3314 3313
                            }
3315 3314
                        }
......
3319 3318
                        {
3320 3319
                            if (e.LeftButton == MouseButtonState.Pressed)
3321 3320
                            {
3322
                                if (currentControl is CircleControl)
3321
                                if (currentControl is CircleControl circlectrl)
3323 3322
                                {
3324 3323
                                    //20180906 LJY TEST IsRotationDrawingEnable
3325
                                    if (IsGetoutpoint((currentControl as CircleControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3324
                                    if (IsGetoutpoint(circlectrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3326 3325
                                    {
3327 3326
                                        return;
3328 3327
                                    }
......
3344 3343
                                    currentControl.CommentID = Commons.shortGuid();
3345 3344
                                    currentControl.IsNew = true;
3346 3345
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3346
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3347 3347
                                }
3348 3348
                            }
3349 3349
                        }
......
3353 3353
                        {
3354 3354
                            if (e.LeftButton == MouseButtonState.Pressed)
3355 3355
                            {
3356
                                if (currentControl is TriControl)
3356
                                if (currentControl is TriControl trictrl)
3357 3357
                                {
3358
                                    var content = currentControl as TriControl;
3359
                                    if (content.MidPoint == new Point(0, 0))
3358
                                    if (trictrl.MidPoint == new Point(0, 0))
3360 3359
                                    {
3361
                                        content.MidPoint = new Point(CanvasDrawingMouseDownPoint.X, CanvasDrawingMouseDownPoint.Y);
3360
                                        trictrl.MidPoint = new Point(CanvasDrawingMouseDownPoint.X, CanvasDrawingMouseDownPoint.Y);
3362 3361
                                    }
3363 3362
                                    else
3364 3363
                                    {
3365 3364
                                        //20180906 LJY TEST IsRotationDrawingEnable
3366
                                        if (IsGetoutpoint((currentControl as TriControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3365
                                        if (IsGetoutpoint(trictrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3367 3366
                                        {
3368 3367
                                            return;
3369 3368
                                        }
......
3385 3384
                                    currentControl.CommentID = Commons.shortGuid();
3386 3385
                                    currentControl.IsNew = true;
3387 3386
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3387
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3388 3388
                                }
3389 3389
                            }
3390 3390
                        }
......
3397 3397
                        {
3398 3398
                            if (e.LeftButton == MouseButtonState.Pressed)
3399 3399
                            {
3400
                                if (currentControl is LineControl)
3400
                                if (currentControl is LineControl linectrl)
3401 3401
                                {
3402 3402
                                    //20180906 LJY TEST IsRotationDrawingEnable
3403
                                    if (IsGetoutpoint((currentControl as LineControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3403
                                    if (IsGetoutpoint(linectrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3404 3404
                                    {
3405 3405
                                        return;
3406 3406
                                    }
......
3423 3423
                                    currentControl.IsNew = true;
3424 3424
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3425 3425
                                    ViewerDataModel.Instance.SetAngleVisible(Visibility.Visible);
3426
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3426 3427
                                }
3427 3428
                            }
3428 3429
                        }
3429 3430
                        break;
3430 3431
                    case ControlType.PolygonControl:
3431 3432
                        {
3432
                            if (currentControl is PolygonControl)
3433
                            if (currentControl is PolygonControl polygonctrl)
3433 3434
                            {
3434
                                var control = currentControl as PolygonControl;
3435

  
3436 3435
                                if (e.RightButton == MouseButtonState.Pressed)
3437 3436
                                {
3438
                                    control.IsCompleted = true;
3437
                                    polygonctrl.IsCompleted = true;
3439 3438
                                }
3440 3439

  
3441
                                if (!control.IsCompleted)
3440
                                if (!polygonctrl.IsCompleted)
3442 3441
                                {
3443
                                    control.PointSet.Add(control.EndPoint);
3442
                                    polygonctrl.PointSet.Add(polygonctrl.EndPoint);
3444 3443
                                }
3445 3444
                                else
3446 3445
                                {
3447 3446
                                    //20180906 LJY TEST IsRotationDrawingEnable
3448
                                    if (IsGetoutpoint((currentControl as PolygonControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3447
                                    if (IsGetoutpoint(polygonctrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3449 3448
                                    {
3450 3449
                                        return;
3451 3450
                                    }
3452 3451

  
3453
                                    var firstPoint = control.PointSet.First();
3454
                                    control.DashSize = ViewerDataModel.Instance.DashSize;
3455
                                    control.LineSize = ViewerDataModel.Instance.LineSize;
3456
                                    control.PointSet.Add(firstPoint);
3452
                                    var firstPoint = polygonctrl.PointSet.First();
3453
                                    polygonctrl.DashSize = ViewerDataModel.Instance.DashSize;
3454
                                    polygonctrl.LineSize = ViewerDataModel.Instance.LineSize;
3455
                                    polygonctrl.PointSet.Add(firstPoint);
3457 3456

  
3458
                                    control.ApplyOverViewData();
3457
                                    polygonctrl.ApplyOverViewData();
3459 3458

  
3460 3459
                                    CreateCommand.Instance.Execute(currentControl);
3461
                                    control.UpdateControl();
3460
                                    polygonctrl.UpdateControl();
3462 3461
                                    currentControl = null;
3463 3462
                                }
3464 3463
                            }
......
3482 3481
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3483 3482
                                    polygonControl.ApplyTemplate();
3484 3483
                                    polygonControl.Visibility = Visibility.Visible;
3484
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3485 3485
                                }
3486 3486
                            }
3487 3487
                        }
......
3540 3540
                                    //polygonControl.PointC.pointSet.Add(canvasDrawingMouseDownPoint);
3541 3541
                                    polygonControl.PointSet.Add(CanvasDrawingMouseDownPoint);
3542 3542
                                    polygonControl.PointSet.Add(CanvasDrawingMouseDownPoint);
3543
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3543 3544
                                    //}
3544 3545
                                }
3545 3546
                            }
......
3549 3550
                        {
3550 3551
                            if (e.LeftButton == MouseButtonState.Pressed)
3551 3552
                            {
3552
                                if (currentControl is ArcControl)
3553
                                if (currentControl is ArcControl arcctrl)
3553 3554
                                {
3554 3555
                                    //20180906 LJY TEST IsRotationDrawingEnable
3555
                                    if (IsGetoutpoint((currentControl as ArcControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3556
                                    if (IsGetoutpoint(arcctrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3556 3557
                                    {
3557 3558
                                        return;
3558 3559
                                    }
......
3574 3575
                                    currentControl.IsNew = true;
3575 3576
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3576 3577
                                    ViewerDataModel.Instance.SetAngleVisible(Visibility.Visible);
3578
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3577 3579
                                }
3578 3580
                            }
3579 3581
                            else if (e.RightButton == MouseButtonState.Pressed)
......
3592 3594
                            {
3593 3595
                                //if (IsDrawingEnable(canvasZoomPanningMouseDownPoint))
3594 3596
                                //{
3595
                                if (currentControl is ArrowArcControl)
3597
                                if (currentControl is ArrowArcControl arrowarcctrl)
3596 3598
                                {
3597 3599
                                    //20180906 LJY TEST IsRotationDrawingEnable
3598
                                    if (IsGetoutpoint((currentControl as ArrowArcControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3600
                                    if (IsGetoutpoint(arrowarcctrl.PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3599 3601
                                    {
3600 3602
                                        return;
3601 3603
                                    }
......
3617 3619
                                    currentControl.IsNew = true;
3618 3620
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3619 3621
                                    ViewerDataModel.Instance.SetAngleVisible(Visibility.Visible);
3622
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3620 3623
                                }
3621 3624
                                //}
3622 3625
                            }
......
3677 3680
                                    currentControl.IsNew = true;
3678 3681
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3679 3682
                                    ViewerDataModel.Instance.SetAngleVisible(Visibility.Visible);
3683
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3680 3684
                                }
3681 3685
                                //}
3682 3686
                            }
......
3699 3703
                                else
3700 3704
                                {
3701 3705
                                    //20180906 LJY TEST IsRotationDrawingEnable
3702
                                    if (IsGetoutpoint((currentControl as CloudControl).PointSet.Where(data => IsRotationDrawingEnable(data) == true).FirstOrDefault()))
3706
                                    if (IsGetoutpoint((currentControl as CloudControl).PointSet.FirstOrDefault(data => IsRotationDrawingEnable(data) == true)))
3703 3707
                                    {
3704 3708
                                        return;
3705 3709
                                    }
......
3726 3730
                                        PointC = new StylusPointSet()
3727 3731
                                    };
3728 3732

  
3729
                                    //if (IsDrawingEnable(canvasZoomPanningMouseDownPoint))
3730
                                    //{
3731 3733
                                    var polygonControl = (currentControl as CloudControl);
3732 3734
                                    currentControl.CommentID = Commons.shortGuid();
3733 3735
                                    currentControl.MarkupInfoID = App.Custom_ViewInfoId;
......
3736 3738

  
3737 3739
                                    polygonControl.PointSet.Add(CanvasDrawingMouseDownPoint);
3738 3740
                                    polygonControl.PointSet.Add(CanvasDrawingMouseDownPoint);
3739

  
3740
                                    //}
3741
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3741 3742
                                }
3742 3743
                            }
3743 3744
                        }
......
3800 3801

  
3801 3802
                                        //20180903 LJY 회전된 방향으로 화면에 출력되지 않는 문제 수정
3802 3803
                                        (currentControl as ImgControl).CommentAngle -= rotate.Angle;
3804
                                        currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3803 3805
                                    }
3804 3806
                                }
3805 3807
                            }
......
3851 3853
                                    {
3852 3854
                                        (currentControl as ImgControl).CommentAngle -= rotate.Angle;
3853 3855
                                    }
3856
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3854 3857
                                }
3855 3858
                                //}
3856 3859
                            }
......
3872 3875
                                    currentControl.IsNew = true;
3873 3876
                                    currentControl.MarkupInfoID = App.Custom_ViewInfoId;
3874 3877
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3875
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
3878
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3876 3879
                                    currentControl.SetValue(TextControl.CanvasXProperty, CanvasDrawingMouseDownPoint.X);
3877 3880
                                    currentControl.SetValue(TextControl.CanvasYProperty, CanvasDrawingMouseDownPoint.Y);
3878 3881

  
......
3925 3928
                                    currentControl.CommentID = Commons.shortGuid();
3926 3929
                                    currentControl.IsNew = true;
3927 3930
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3928
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
3931
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3929 3932
                                    currentControl.SetValue(TextControl.CanvasXProperty, CanvasDrawingMouseDownPoint.X);
3930 3933
                                    currentControl.SetValue(TextControl.CanvasYProperty, CanvasDrawingMouseDownPoint.Y);
3931 3934

  
......
3978 3981
                                    currentControl.MarkupInfoID = App.Custom_ViewInfoId;
3979 3982
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
3980 3983

  
3981
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
3984
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
3982 3985
                                    currentControl.SetValue(TextControl.CanvasXProperty, CanvasDrawingMouseDownPoint.X);
3983 3986
                                    currentControl.SetValue(TextControl.CanvasYProperty, CanvasDrawingMouseDownPoint.Y);
3984 3987

  
......
4071 4074
                                        System.Diagnostics.Debug.WriteLine(ex.ToString());
4072 4075
                                    }
4073 4076

  
4074
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
4077
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4075 4078
                                    currentControl.SetValue(ArrowTextControl.StartPointProperty, CanvasDrawingMouseDownPoint);
4076 4079
                                    currentControl.SetValue(ArrowTextControl.EndPointProperty, CanvasDrawingMouseDownPoint);
4077 4080
                                    (currentControl as ArrowTextControl).TextSize = ViewerDataModel.Instance.TextSize;
......
4124 4127
                                    currentControl.IsNew = true;
4125 4128
                                    currentControl.MarkupInfoID = App.Custom_ViewInfoId;
4126 4129
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
4127
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
4130
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4128 4131
                                    currentControl.SetValue(ArrowTextControl.StartPointProperty, CanvasDrawingMouseDownPoint);
4129 4132
                                    currentControl.SetValue(ArrowTextControl.EndPointProperty, CanvasDrawingMouseDownPoint);
4130 4133
                                    (currentControl as ArrowTextControl).TextSize = ViewerDataModel.Instance.TextSize;
......
4175 4178
                                    currentControl.MarkupInfoID = App.Custom_ViewInfoId;
4176 4179
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
4177 4180

  
4178
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
4181
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4179 4182

  
4180 4183
                                    currentControl.SetValue(ArrowTextControl.StartPointProperty, CanvasDrawingMouseDownPoint);
4181 4184

  
......
4228 4231
                                    currentControl.MarkupInfoID = App.Custom_ViewInfoId;
4229 4232
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
4230 4233

  
4231
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
4234
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4232 4235

  
4233 4236
                                    currentControl.SetValue(ArrowTextControl.StartPointProperty, CanvasDrawingMouseDownPoint);
4234 4237
                                    currentControl.SetValue(ArrowTextControl.EndPointProperty, CanvasDrawingMouseDownPoint);
......
4284 4287
                                    currentControl.MarkupInfoID = App.Custom_ViewInfoId;
4285 4288
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
4286 4289

  
4287
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
4290
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4288 4291
                                    currentControl.SetValue(ArrowTextControl.StartPointProperty, CanvasDrawingMouseDownPoint);
4289 4292
                                    currentControl.SetValue(ArrowTextControl.EndPointProperty, CanvasDrawingMouseDownPoint);
4290 4293
                                    (currentControl as ArrowTextControl).TextSize = ViewerDataModel.Instance.TextSize;
......
4333 4336
                                    currentControl.IsNew = true;
4334 4337
                                    currentControl.MarkupInfoID = App.Custom_ViewInfoId;
4335 4338
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
4336
                                    currentControl.SetValue(Canvas.ZIndexProperty, 3);
4339
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4337 4340

  
4338 4341
                                    currentControl.SetValue(ArrowTextControl.StartPointProperty, CanvasDrawingMouseDownPoint);
4339 4342
                                    currentControl.SetValue(ArrowTextControl.EndPointProperty, CanvasDrawingMouseDownPoint);
......
4422 4425

  
4423 4426
                                    //20180903 LJY 회전된 방향으로 화면에 출력되지 않는 문제 수정
4424 4427
                                    (currentControl as SignControl).CommentAngle -= rotate.Angle;
4428
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4425 4429
                                }
4426 4430
                                //}
4427 4431
                            }
......
4469 4473
                                    currentControl.IsNew = true;
4470 4474
                                    (currentControl as RectangleControl).DashSize = ViewerDataModel.Instance.DashSize;
4471 4475
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
4476
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4472 4477
                                }
4473 4478
                                //}
4474 4479
                            }
......
4508 4513

  
4509 4514
                                    //20180903 LJY 회전된 방향으로 화면에 출력되지 않는 문제 수정
4510 4515
                                    (currentControl as SymControl).CommentAngle -= rotate.Angle;
4516
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4511 4517
                                }
4512 4518
                                //}
4513 4519
                            }
......
4550 4556
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl);
4551 4557
                                    //20180903 LJY 회전된 방향으로 화면에 출력되지 않는 문제 수정
4552 4558
                                    (currentControl as SymControlN).CommentAngle -= rotate.Angle;
4559
                                    currentControl.SetValue(Canvas.ZIndexProperty, currentControl.ZIndex);
4553 4560
                                }
4554 4561
                                //}
4555 4562
                            }
MarkupToPDF/Common/CommentUserInfo.cs
35 35
        public long GroupID { get; set; }
36 36

  
37 37
        [Description("ZIndex 값이 높을 수록 앞쪽으로 배치된다.")]
38
        public int ZIndex { get; set; } = 0;
38
        public int ZIndex { get; set; } = 10;
39 39

  
40 40
        private SolidColorBrush _TempBorderBrush { get; set; }
41 41
        private SolidColorBrush _HoverBorderBrush { get; } = new SolidColorBrush(Color.FromRgb(255, 0, 255));
MarkupToPDF/Serialize/S_Control/Base/S_BaseControl.cs
75 75
        public string Version { get; set; }
76 76

  
77 77
        [DataMember]
78
        public int ZIndex { get; set; };
78
        public int ZIndex { get; set; } = 10;
79 79
    }
80 80
}
Rhino.Licensing/AbstractLicenseValidator.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Globalization;
4
using System.Net.NetworkInformation;
5
using System.Security.Cryptography;
6
using System.Security.Cryptography.Xml;
7
using System.ServiceModel;
8
using System.Threading;
9
using System.Xml;
10
//using log4net;
11
using Rhino.Licensing.Discovery;
12

  
13
namespace Rhino.Licensing
14
{
15
    /// <summary>
16
    /// Base license validator.
17
    /// </summary>
18
    public abstract class AbstractLicenseValidator
19
    {
20
        /// <summary>
21
        /// License validator logger
22
        /// </summary>
23
        //protected static readonly ILog Log = LogManager.GetLogger(typeof(LicenseValidator));
24

  
25
        /// <summary>
26
        /// Standard Time servers
27
        /// </summary>
28
        protected static readonly string[] TimeServers =
29
        {
30
            "time.nist.gov",
31
            "time-nw.nist.gov",
32
            "time-a.nist.gov",
33
            "time-b.nist.gov",
34
            "time-a.timefreq.bldrdoc.gov",
35
            "time-b.timefreq.bldrdoc.gov",
36
            "time-c.timefreq.bldrdoc.gov",
37
            "utcnist.colorado.edu",
38
            "nist1.datum.com",
39
            "nist1.dc.certifiedtime.com",
40
            "nist1.nyc.certifiedtime.com",
41
            "nist1.sjc.certifiedtime.com"
42
        };
43

  
44
        private readonly string licenseServerUrl;
45
        private readonly Guid clientId;
46
        private readonly string publicKey;
47
        private readonly Timer nextLeaseTimer;
48
        private bool disableFutureChecks;
49
        private bool currentlyValidatingSubscriptionLicense;
50
        private readonly DiscoveryHost discoveryHost;
51
        private DiscoveryClient discoveryClient;
52
        private Guid senderId;
53

  
54
        /// <summary>
55
        /// Fired when license data is invalidated
56
        /// </summary>
57
        public event Action<InvalidationType> LicenseInvalidated;
58

  
59
        /// <summary>
60
        /// Fired when license is expired
61
        /// </summary>
62
        public event Action<DateTime> LicenseExpired;
63

  
64
        /// <summary>
65
        /// Event that's raised when duplicate licenses are found
66
        /// </summary>
67
        public event EventHandler<DiscoveryHost.ClientDiscoveredEventArgs> MultipleLicensesWereDiscovered;
68

  
69
        /// <summary>
70
        /// Disable the <see cref="ExpirationDate"/> validation with the time servers
71
        /// </summary>
72
        public bool DisableTimeServersCheck
73
        {
74
            get; set;
75
        }
76
        
77
        /// <summary>
78
        /// Gets the expiration date of the license
79
        /// </summary>
80
        public DateTime ExpirationDate
81
        {
82
            get; private set;
83
        }
84

  
85
        /// <summary>
86
        /// Lease timeout
87
        /// </summary>
88
        public TimeSpan LeaseTimeout { get; set; }
89

  
90
        /// <summary>
91
        /// How to behave when using the same license multiple times
92
        /// </summary>
93
        public MultipleLicenseUsage MultipleLicenseUsageBehavior { get; set; }
94

  
95
        /// <summary>
96
        /// Gets or Sets the endpoint address of the subscription service
97
        /// </summary>
98
        public string SubscriptionEndpoint
99
        {
100
            get; set;
101
        }
102

  
103
        /// <summary>
104
        /// Gets the Type of the license
105
        /// </summary>
106
        public LicenseType LicenseType
107
        {
108
            get; private set;
109
        }
110

  
111
        /// <summary>
112
        /// Gets the Id of the license holder
113
        /// </summary>
114
        public Guid UserId
115
        {
116
            get; private set;
117
        }
118

  
119
        /// <summary>
120
        /// Gets the name of the license holder
121
        /// </summary>
122
        public string Name
123
        {
124
            get; private set;
125
        }
126

  
127
        /// <summary>
128
        /// Gets or Sets Floating license support
129
        /// </summary>
130
        public bool DisableFloatingLicenses
131
        {
132
            get; set;
133
        }
134

  
135
        /// <summary>
136
        /// Whether the client discovery server is enabled. This detects duplicate licenses used on the same network.
137
        /// </summary>
138
        public bool DiscoveryEnabled { get; private set; }
139

  
140
        /// <summary>
141
        /// Gets extra license information
142
        /// </summary>
143
        public IDictionary<string, string> LicenseAttributes
144
        {
145
            get; private set;
146
        }
147

  
148
        /// <summary>
149
        /// Gets or Sets the license content
150
        /// </summary>
151
        protected abstract string License
152
        {
153
            get; set;
154
        }
155

  
156
        /// <summary>
157
        /// Creates a license validator with specfied public key.
158
        /// </summary>
159
        /// <param name="publicKey">public key</param>
160
        /// <param name="enableDiscovery">Whether to enable the client discovery server to detect duplicate licenses used on the same network.</param>
161
        protected AbstractLicenseValidator(string publicKey, bool enableDiscovery = false)
162
        {
163
            LeaseTimeout = TimeSpan.FromMinutes(5);
164
            LicenseAttributes = new Dictionary<string, string>();
165
            nextLeaseTimer = new Timer(LeaseLicenseAgain);
166
            this.publicKey = publicKey;
167

  
168
            DiscoveryEnabled = enableDiscovery;
169

  
170
            if (DiscoveryEnabled)
171
            {
172
                senderId = Guid.NewGuid();
173
                discoveryHost = new DiscoveryHost();
174
                discoveryHost.ClientDiscovered += DiscoveryHostOnClientDiscovered;
175
                discoveryHost.Start();
176
            }
177
        }
178

  
179
        /// <summary>
180
        /// Creates a license validator using the client information
181
        /// and a service endpoint address to validate the license.
182
        /// </summary>
183
        protected AbstractLicenseValidator(string publicKey, string licenseServerUrl, Guid clientId)
184
            : this(publicKey)
185
        {
186
            this.licenseServerUrl = licenseServerUrl;
187
            this.clientId = clientId;
188
        }
189

  
190
        private void LeaseLicenseAgain(object state)
191
        {
192
            var client = discoveryClient;
193
            if (client != null)
194
                client.PublishMyPresence();
195

  
196
            if (HasExistingLicense())
197
                return;
198

  
199
            RaiseLicenseInvalidated();
200
        }
201

  
202
        private void RaiseLicenseInvalidated()
203
        {
204
            var licenseInvalidated = LicenseInvalidated;
205
            if (licenseInvalidated == null)
206
                throw new InvalidOperationException("License was invalidated, but there is no one subscribe to the LicenseInvalidated event");
207

  
208
            licenseInvalidated(LicenseType == LicenseType.Floating ? InvalidationType.CannotGetNewLicense :
209
                                                                     InvalidationType.TimeExpired);
210
        }
211

  
212
        private void RaiseMultipleLicenseDiscovered(DiscoveryHost.ClientDiscoveredEventArgs args)
213
        {
214
            var onMultipleLicensesWereDiscovered = MultipleLicensesWereDiscovered;
215
            if (onMultipleLicensesWereDiscovered != null)
216
            {
217
                onMultipleLicensesWereDiscovered(this, args);
218
            }
219
        }
220

  
221
        private void DiscoveryHostOnClientDiscovered(object sender, DiscoveryHost.ClientDiscoveredEventArgs clientDiscoveredEventArgs)
222
        {
223
            if (senderId == clientDiscoveredEventArgs.SenderId) // we got our own notification, ignore it
224
                return;
225

  
226
            if (UserId != clientDiscoveredEventArgs.UserId) // another license, we don't care
227
                return;
228

  
229
            // same user id, different senders
230
            switch (MultipleLicenseUsageBehavior)
231
            {
232
                case MultipleLicenseUsage.AllowForSameUser:
233
                    if (Environment.UserName == clientDiscoveredEventArgs.UserName)
234
                        return;
235
                    break;
236
            }
237

  
238
            RaiseLicenseInvalidated();
239
            RaiseMultipleLicenseDiscovered(clientDiscoveredEventArgs);
240
        }
241

  
242
        /// <summary>
243
        /// Validates loaded license
244
        /// </summary>
245
        public virtual void AssertValidLicense()
246
        {
247
            LicenseAttributes.Clear();
248
            if (HasExistingLicense())
249
            {
250
                if (DiscoveryEnabled)
251
                {
252
                    discoveryClient = new DiscoveryClient(senderId, UserId, Environment.MachineName, Environment.UserName);
253
                    discoveryClient.PublishMyPresence();
254
                }
255
                return;
256
            }
257

  
258
            //Log.WarnFormat("Could not validate existing license\r\n{0}", License);
259
            throw new LicenseNotFoundException();
260
        }
261

  
262
        private bool HasExistingLicense()
263
        {
264
            try
265
            {
266
                if (TryLoadingLicenseValuesFromValidatedXml() == false)
267
                {
268
                    //Log.WarnFormat("Failed validating license:\r\n{0}", License);
269
                    return false;
270
                }
271
                //Log.InfoFormat("License expiration date is {0}", ExpirationDate);
272
                
273
                bool result;
274
                if (LicenseType == LicenseType.Subscription)
275
                {
276
                    result = ValidateSubscription();
277
                }
278
                else
279
                {
280
                    result = DateTime.UtcNow < ExpirationDate;
281
                }
282

  
283
                if (result &&
284
                    !DisableTimeServersCheck)
285
                {
286
                    ValidateUsingNetworkTime();
287
                }
288

  
289
                if (!result)
290
                {
291
                    if (LicenseExpired == null)
292
                        throw new LicenseExpiredException("Expiration Date : " + ExpirationDate);
293

  
294
                    DisableFutureChecks();
295
                    LicenseExpired(ExpirationDate);
296
                }
297

  
298
                return true;
299
            }
300
            catch (RhinoLicensingException)
301
            {
302
                throw;
303
            }
304
            catch (Exception)
305
            {
306
                return false;
307
            }
308
        }
309

  
310
        private bool ValidateSubscription()
311
        {
312
            if ((ExpirationDate - DateTime.UtcNow).TotalDays > 4)
313
                return true;
314

  
315
            if (currentlyValidatingSubscriptionLicense)
316
                return DateTime.UtcNow < ExpirationDate;
317

  
318
            if (SubscriptionEndpoint == null)
319
                throw new InvalidOperationException("Subscription endpoints are not supported for this license validator");
320

  
321
            try
322
            {
323
                TryGettingNewLeaseSubscription();
324
            }
325
            catch (Exception e)
326
            {
327
                //Log.Error("Could not re-lease subscription license", e);
328
                throw new Exception("Could not re-lease subscription license", e);
329
            }
330

  
331
            return ValidateWithoutUsingSubscriptionLeasing();
332
        }
333

  
334
        private bool ValidateWithoutUsingSubscriptionLeasing()
335
        {
336
            currentlyValidatingSubscriptionLicense = true;
337
            try
338
            {
339
                return HasExistingLicense();
340
            }
341
            finally
342
            {
343
                currentlyValidatingSubscriptionLicense = false;
344
            }
345
        }
346

  
347
        private void TryGettingNewLeaseSubscription()
348
        {
349
            var service = ChannelFactory<ISubscriptionLicensingService>.CreateChannel(new BasicHttpBinding(), new EndpointAddress(SubscriptionEndpoint));
350
            try
351
            {
352
                var newLicense = service.LeaseLicense(License);
353
                TryOverwritingWithNewLicense(newLicense);
354
            }
355
            finally
356
            {
357
                var communicationObject = service as ICommunicationObject;
358
                if (communicationObject != null)
359
                {
360
                    try
361
                    {
362
                        communicationObject.Close(TimeSpan.FromMilliseconds(200));
363
                    }
364
                    catch
365
                    {
366
                        communicationObject.Abort();
367
                    }
368
                }
369
            }
370
        }
371

  
372
        /// <summary>
373
        /// Loads the license file.
374
        /// </summary>
375
        /// <param name="newLicense"></param>
376
        /// <returns></returns>
377
        protected bool TryOverwritingWithNewLicense(string newLicense)
378
        {
379
            if (string.IsNullOrEmpty(newLicense))
380
                return false;
381
            try
382
            {
383
                var xmlDocument = new XmlDocument();
384
                xmlDocument.LoadXml(newLicense);
385
            }
386
            catch (Exception e)
387
            {
388
                // Log.Error("New license is not valid XML\r\n" + newLicense, e);
389
                System.Diagnostics.Debug.WriteLine("New license is not valid XML\r\n" + newLicense, e);
390
                //throw new Exception("New license is not valid XML\r\n" + newLicense, e);
391
                return false;
392
            }
393
            License = newLicense;
394
            return true;
395
        }
396

  
397
        private void ValidateUsingNetworkTime()
398
        {
399
            if (!NetworkInterface.GetIsNetworkAvailable())
400
                return;
401

  
402
            var sntp = new SntpClient(GetTimeServers());
403
            sntp.BeginGetDate(time =>
404
            {
405
                if (time > ExpirationDate)
406
                    RaiseLicenseInvalidated();
407
            }
408
            , () =>
409
            {
410
                /* ignored */
411
            });
412
        }
413

  
414
        /// <summary>
415
        /// Extension point to return different time servers
416
        /// </summary>
417
        /// <returns></returns>
418
        protected virtual string[] GetTimeServers()
419
        {
420
            return TimeServers;
421
        }
422

  
423
        /// <summary>
424
        /// Removes existing license from the machine.
425
        /// </summary>
426
        public virtual void RemoveExistingLicense()
427
        {
428
        }
429

  
430
        /// <summary>
431
        /// Loads license data from validated license file.
432
        /// </summary>
433
        /// <returns></returns>
434
        public bool TryLoadingLicenseValuesFromValidatedXml()
435
        {
436
            try
437
            {
438
                var doc = new XmlDocument();
439
                doc.LoadXml(License);
440

  
441
                if (TryGetValidDocument(publicKey, doc) == false)
442
                {
443
                    //Log.WarnFormat("Could not validate xml signature of:\r\n{0}", License);
444
                    return false;
445
                }
446

  
447
                if (doc.FirstChild == null)
448
                {
449
                    //Log.WarnFormat("Could not find first child of:\r\n{0}", License);
450
                    return false;
451
                }
452

  
453
                if (doc.SelectSingleNode("/floating-license") != null)
454
                {
455
                    var node = doc.SelectSingleNode("/floating-license/license-server-public-key/text()");
456
                    if (node == null)
457
                    {
458
                        //Log.WarnFormat("Invalid license, floating license without license server public key:\r\n{0}", License);
459
                        throw new InvalidOperationException(
460
                            "Invalid license file format, floating license without license server public key");
461
                    }
462
                    return ValidateFloatingLicense(node.InnerText);
463
                }
464

  
465
                var result = ValidateXmlDocumentLicense(doc);
466
                if (result && disableFutureChecks == false)
467
                {
468
                    nextLeaseTimer.Change(LeaseTimeout, LeaseTimeout);
469
                }
470
                return result;
471
            }
472
            catch (RhinoLicensingException)
473
            {
474
                throw;
475
            }
476
            catch (Exception e)
477
            {
478
                //Log.Error("Could not validate license", e);
479
                System.Diagnostics.Debug.WriteLine("Could not validate license", e);
480
                return false;
481
            }
482
        }
483

  
484
        private bool ValidateFloatingLicense(string publicKeyOfFloatingLicense)
485
        {
486
            if (DisableFloatingLicenses)
487
            {
488
               // Log.Warn("Floating licenses have been disabled");
489
                System.Diagnostics.Debug.WriteLine("Floating licenses have been disabled");
490

  
491
                return false;
492
            }
493
            if (licenseServerUrl == null)
494
            {
495
                //Log.Warn("Could not find license server url");
496
                throw new InvalidOperationException("Floating license encountered, but licenseServerUrl was not set");
497
            }
498
            
499
            var success = false;
500
            var licensingService = ChannelFactory<ILicensingService>.CreateChannel(new WSHttpBinding(), new EndpointAddress(licenseServerUrl));
501
            try
502
            {
503
                   var leasedLicense = licensingService.LeaseLicense(
504
                    Environment.MachineName,
505
                    Environment.UserName,
506
                    clientId);
507
                ((ICommunicationObject)licensingService).Close();
508
                success = true;
509
                if (leasedLicense == null)
510
                {
511
                    //Log.WarnFormat("Null response from license server: {0}", licenseServerUrl);
512
                    throw new FloatingLicenseNotAvailableException();
513
                }
514

  
515
                var doc = new XmlDocument();
516
                doc.LoadXml(leasedLicense);
517

  
518
                if (TryGetValidDocument(publicKeyOfFloatingLicense, doc) == false)
519
                {
520
                    //Log.WarnFormat("Could not get valid license from floating license server {0}", licenseServerUrl);
521
                    throw new FloatingLicenseNotAvailableException();
522
                }
523

  
524
                var validLicense = ValidateXmlDocumentLicense(doc);
525
                if (validLicense)
526
                {
527
                    //setup next lease
528
                    var time = (ExpirationDate.AddMinutes(-5) - DateTime.UtcNow);
529
                    System.Diagnostics.Debug.WriteLine("Will lease license again at {0}", time);
530
                    //Log.DebugFormat("Will lease license again at {0}", time);
531
                    if (disableFutureChecks == false)
532
                        nextLeaseTimer.Change(time, time);
533
                }
534
                return validLicense;
535
            }
536
            finally
537
            {
538
                if (success == false)
539
                    ((ICommunicationObject)licensingService).Abort();
540
            }
541
        }
542

  
543
        internal bool ValidateXmlDocumentLicense(XmlDocument doc)
544
        {
545
            var id = doc.SelectSingleNode("/license/@id");
546
            if (id == null)
547
            {
548
                //Log.WarnFormat("Could not find id attribute in license:\r\n{0}", License);
549
                return false;
550
            }
551

  
552
            UserId = new Guid(id.Value);
553

  
554
            var date = doc.SelectSingleNode("/license/@expiration");
... 이 차이점은 표시할 수 있는 최대 줄수를 초과해서 이 차이점은 잘렸습니다.

내보내기 Unified diff

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