Example #1
0
        public static bool SoftInitialize()
        {
            // This method can be called to reinitialize (restart) the program.
            PgmInstanceInfo.ReInitialize();
            QTSysGlobal.TerminalKey             = Guid.Empty;
            QTSysGlobal.Log                     = new Logger(PgmInstanceInfo.ApplicationName, TLogfileLocation.LocalApplicationData);
            QTSysGlobal.Log.PrefferedLogStorage = LogStorage.LogFile;
            QTSysGlobal.Log.LogError            = true;
            QTSysGlobal.Log.LogWarning          = true;
            QTSysGlobal.Log.LogInformation      = true;
            QTSysGlobal.Log.LogDebugInformation = true;
            QTSysGlobal.Log.WriteEntry(LogTypeLevel.DebugInformation, "Enter SoftInitialize", "", "", "");
            //if (QTSysGlobal.ViewFactory != null)
            //    QTSysGlobal.ViewFactory.CloseAll();
            //QTSysGlobal.ViewFactory = new ViewFactoryBase();

            // Check single instance
            if (!QTSysGlobal.PgmInstanceInfo.IsSingleInstance)
            {
                QTSysGlobal.Log.WriteEntry(LogTypeLevel.Error, "Programmet är redan igång. Endast en instans av programmet kan köras", "", "", "");
                return(false);
            }


            // Read key.
            InstanceKey ik = new InstanceKey();

            if (!ik.ReadFile(PgmInstanceInfo.StartUpPath, out TerminalKey))
            {
                if (ik.ErrorCode == FileStreamErrorCode.StandardStreamRead)
                {
                    Log.WriteEntry(LogTypeLevel.Error, "Terminal id fil saknas", "", "", "");
                }
                else
                {
                    Log.WriteEntry(LogTypeLevel.Error, "Fel i terminal id filen", "", "", "");
                }
                return(false);
            }
            ik = null;

            // Read config.
            ClientConfig config = new ClientConfig(QTSysGlobal.PgmInstanceInfo.CompanyName, QTSysGlobal.PgmInstanceInfo.ApplicationName, ConfigRegistryHive.LocalMachine);

            if (!config.Read())
            {
                Log.WriteEntry(LogTypeLevel.Error, "Kunde ej läsa konfigurationen", "", "", "");
                return(false);
            }

            QTSysGlobal.Log.WriteEntry(LogTypeLevel.DebugInformation, "Exit SoftInitialize (before set logoptions)", "", "", "");
            // Reset Log options depending on configuration.
            QTSysGlobal.Log.PrefferedLogStorage = (LogStorage)config.LogOption.Storage;
            QTSysGlobal.Log.LogError            = config.LogOption.Error;
            QTSysGlobal.Log.LogWarning          = config.LogOption.Warning;
            QTSysGlobal.Log.LogInformation      = config.LogOption.Information;
            QTSysGlobal.Log.LogDebugInformation = config.LogOption.DebugInformation;
            QTSysGlobal.LogicAssemblyAPI        = new TLogicAssemblyAPI();
            QTSysGlobal.LogicAssemblyAPI.Initialize(QTSysGlobal.Log, config.HostAddress);
            SvcRecGlobal.CurrTimeTransRec = new ClientTimeTransRec();

            SvcRecGlobal.AdvancedTime = new AdvancedTimeQuestionClass();

            QTSysGlobal.Log.WriteEntry(LogTypeLevel.DebugInformation, "Exit SoftInitialize", "", "", "");
            PgmInstanceInfo.InitializedOk = true;
            return(PgmInstanceInfo.InitializedOk);
        }