public bool ErrorLog(string ConnectionId, string ErrorMsg)
        {
            bool resultLog = false;

            try
            {
                if (!string.IsNullOrEmpty(ConnectionId) && !string.IsNullOrEmpty(ErrorMsg))
                {
                    using (var db = new LicensingEntities())
                    {
                        Guid connectionID = Guid.Parse(ConnectionId);

                        var connectionItems = db.Connection.Where(id => id.ConnectionID == connectionID);

                        if (connectionItems.Count() > 0)
                        {
                            var connectionItem = connectionItems.First();

                            connectionItem.ErrorLog = ErrorMsg;

                            db.SaveChanges();

                            resultLog = true;
                        }
                        else
                        {
                             var waitConnections = db.WaitConnection.Where(con => con.ConnectionID == connectionID);
                             if (waitConnections.Count() > 0)
                             {
                                 var waitConnectionItem = waitConnections.First();
                                 waitConnectionItem.ErrorLog = ErrorMsg;
                                 db.SaveChanges();

                                 resultLog = true;
                             }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                resultLog = false;
                System.Diagnostics.Debug.WriteLine(ex);
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            return resultLog;
        }
        public bool IsConnectionStop(string ConnectionId)
        {
            bool result = false;

            try
            {
                if (!string.IsNullOrEmpty(ConnectionId))
                {
                    Guid connection = Guid.Parse(ConnectionId);

                    using (var db = new LicensingEntities())
                    {
                        var Connections = db.Connection.Where(con => con.ConnectionID == connection);

                        if (Connections.Count() > 0)
                        {
                            var connectionItem = Connections.First();

                            if (connectionItem.StopCalled.HasValue)
                            {
                                if (!connectionItem.StopCalled.Value && !connectionItem.ReStarted)
                                {
                                    result = true;
                                    connectionItem.ReStarted = true;

                                    if (connectionItem.DisConnectedDateTime.HasValue)
                                    {
                                        DateTime disconnection = connectionItem.DisConnectedDateTime.Value;
                                        connectionItem.DisConnectedDateTime = disconnection.AddSeconds(110); // 110초 정도의        라이센스 아웃 시간  증가.
                                    }
                                    
                                    db.SaveChanges();
                                }
                                else
                                {
                                    result = false;
                                }

                            }
                            else
                            {
                                result = false;
                            }
                        }
                        else
                        {
                            var waitConnections = db.WaitConnection.Where(con => con.ConnectionID == connection);

                            if (waitConnections.Count() > 0)
                            {
                                var waitConnectionItem = waitConnections.First();

                                if (waitConnectionItem.StopCalled.HasValue)
                                {
                                    if (!waitConnectionItem.StopCalled.Value && !waitConnectionItem.ReStarted)
                                    {
                                        result = true;
                                        waitConnectionItem.ReStarted = true;
                                        db.SaveChanges();
                                    }
                                    else
                                    {
                                        result = false;
                                    }

                                }
                                else
                                {
                                    result = false;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                System.Diagnostics.Debug.WriteLine(ex);
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            return result;

        }
        public string LicenseUrl(string Company, string ProjectType)
        {
            string serverUrl = string.Empty;

            try
            {
                using (var db = new LicensingEntities())
                {
                    var licenses = db.Server.Where(server => server.Company.ToLower() == Company.ToLower()
                          && server.ProjectType.ToLower() == ProjectType.ToLower()).ToList();

                    if (licenses.Count() > 0)
                    {
                        var server = licenses.First();
                        if (!string.IsNullOrEmpty(server.Port))
                            serverUrl = server.ServerURL + "/" + server.Port;
                        else
                            serverUrl = server.ServerURL;
                    }
                    else
                    {
                        serverUrl = string.Empty;
                    }
                }

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            return serverUrl;
        }
        public int LicenseCount(string Company, string ProjectType)
        {
            int currentLicense = 0;
            try
            {
                using (var db = new LicensingEntities())
                {
                    var licenseCompanys = db.LicenseCompany.Where(LC =>
                                                LC.Company.ToLower() == Company.ToLower() &&
                                                LC.ProjectType.ToLower() == ProjectType.ToLower());

                    if (licenseCompanys.Count() > 0)
                    {
                        var Companys = licenseCompanys.First();

                        //현재 라이센스 유저 수를 가져와서
                        var licenseUsers = db.Connection.Where(li => li.ConnectedDateTime <= DateTime.UtcNow &&
                                 li.DisConnectedDateTime.HasValue == false &&
                                 li.StopCalled.HasValue == false &&
                                 li.Company.ToLower() == Company.ToLower() &&
                                 li.ProjectType.ToLower() == ProjectType.ToLower()).ToList();

                        IEnumerable<Connection> licenseCount = licenseUsers.Distinct(new ConnectionComparer());

                        currentLicense = licenseCount.Count();
                    }
                    else
                    {
                        currentLicense = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return currentLicense;
        }