Beispiel #1
0
 public static bool Handle(Exception ex)
 {
     if (ex is DbModelException)
     {
         var ex1 = ex as DbModelException;
         if (string.IsNullOrEmpty(ex1.MessageId))
         {
             string msgId = SqlExceptionMessage.Get(ex);
             if (msgId != null)
             {
                 ErrorForm.ShowError(msgId);//, null, ex);
             }
             else
             {
                 ErrorForm.ShowError(ex1.Message, ex1);
             }
         }
         else
         {
             ErrorForm.ShowError(ex1.MessageId);
         }
         return(true);
     }
     if (ex is SqlException)
     {
         string msgId = SqlExceptionMessage.Get(ex as SqlException);
         if (msgId != null)
         {
             ErrorForm.ShowError(msgId);//, null, ex);
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
        private bool ConnectToArchiveDatabase()
        {
            try
            {
                if (m_StoredUserPermissions == null)
                {
                    m_StoredUserPermissions = EidssUserContext.User.Permissions;
                }
                var credentials = new ConnectionCredentials(null, "Archive");
                ConnectionManager.DefaultInstance.SetCredentials(null, null, null, null, null, "Archive");
                DbManagerFactory.SetSqlFactory(credentials.ConnectionString);
                if (credentials.IsCorrect)
                {
                    using (var manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
                    {
                        if (!manager.TestConnection())
                        {
                            ErrorForm.ShowError("errArchiveConnectionError");
                            return(false);
                        }
                    }
                }
                else
                {
                    ErrorForm.ShowError("errArchiveConnectionError");
                    return(false);
                }

                var readOnlyPermissions = new Dictionary <string, bool>();
                foreach (string key in m_StoredUserPermissions.Keys)
                {
                    if (key.StartsWith(EIDSSPermissionObject.HumanCaseDeduplication.ToString()) ||
                        key.StartsWith(EIDSSPermissionObject.NotificationSubscription.ToString())
                        )
                    {
                        continue;
                    }
                    readOnlyPermissions.Add(key, key.EndsWith(".Select") ? m_StoredUserPermissions[key] : false);
                }
                EidssUserContext.User.Permissions = readOnlyPermissions;
                BaseFormManager.ArchiveMode       = true;
                return(true);
            }
            catch (Exception e)
            {
                if (!SqlExceptionHandler.Handle(e))
                {
                    ErrorForm.ShowError("errArchiveConnectionError", e);
                }
                return(false);
            }
        }
Beispiel #3
0
        public static bool IsMutexCreated(string mutexName)
        {
            if (mutexName == null)
            {
                return(false);
            }
            Dbg.Debug("trying to create mutex:" + mutexName);
            try
            {
                Mutex mutex = Mutex.OpenExisting(mutexName, MutexRights.FullControl);
                if (mutex != null)
                {
                    return(false);
                }
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                //не найден, можно продолжать работу
            }
            catch (UnauthorizedAccessException)
            {
                return(false);
            }
            bool newMutexCreated = false;

            try
            {
                m_Mutex = new Mutex(true, mutexName, out newMutexCreated);
            }
            catch (Exception ex)
            {
                ErrorForm.ShowError(StandardError.UnprocessedError, ex);
                Application.Exit();
            }

            if (newMutexCreated)
            {
                Dbg.Debug("new mutex is created:" + mutexName);
                return(true);
            }
            Dbg.Debug("mutex with name " + mutexName + " exits already");
            return(false);
        }
Beispiel #4
0
        private bool ReloadMenu()
        {
            m_LangageInitialized = false;
            ResetLanguage(ModelUserContext.CurrentLanguage);

            try
            {
                WinClientContext.SiteCaption = "( " + EidssSiteContext.Instance.SiteType + " - " +
                                               EidssSiteContext.Instance.SiteID + ") " +
                                               EidssSiteContext.Instance.SiteABR;
            }
            catch (Exception ex)
            {
                ErrorForm.ShowError(
                    EidssMessages.Get("errSiteNotDefined",
                                      "EIDSS site is not defined. Please reinstall the application with correct Site ID"),
                    ex);
                ExitApp(true);
                return(false);
            }
            return(true);
        }
Beispiel #5
0
 private void RunEpiInfo()
 {
     if (!String.IsNullOrEmpty(BaseSettings.EpiInfoPath) && File.Exists(BaseSettings.EpiInfoPath))
     {
         try
         {
             var pi         = new ProcessStartInfo(BaseSettings.EpiInfoPath);
             var epiInfoDir = Path.GetDirectoryName(BaseSettings.EpiInfoPath);
             if (epiInfoDir != null)
             {
                 pi.WorkingDirectory = epiInfoDir;
             }
             Process.Start(pi);
         }
         catch (Exception e)
         {
             ErrorForm.ShowError("errEpiInfoLaunch", "Error during launching Epi Info.", e);
         }
     }
     else
     {
         ErrorForm.ShowWarningFormat("msgInvalidEpiInfoPath", "Wrong path to EPI Info in configuration file <{0}>.", BaseSettings.EpiInfoPath);
     }
 }