Esempio n. 1
0
        public static Configuration CreateDefault(FamiliarCommandLineArguments args)
        {
            var hostName    = Environment.MachineName;
            var userName    = WindowsIdentity.GetCurrent().Name;
            var random      = new Random().Next(0x10000);
            var sessionSeed = $"{hostName}/{userName}/{random:X}";
            var sessionId   = CreateSessionId(sessionSeed);

            var configData = new ConfigurationData
            {
                HostName    = hostName,
                UserName    = userName,
                Random      = random,
                SessionId   = sessionId,
                WhenCreated = DateTime.Now
            };

            var configFile = GetDefaultConfigFile(args);

            _trace.TraceInformation("Writing configuration file: {0}", configFile);

            using (var stream = new FileStream(configFile.FullName, FileMode.CreateNew))
            {
                Serializer.SaveToStream(stream, configData);
            }

            return(new Configuration(configData, configFile));
        }
Esempio n. 2
0
        public static Configuration LoadDefault(FamiliarCommandLineArguments args)
        {
            var configFile = GetDefaultConfigFile(args);

            if (!configFile.Exists)
            {
                return(null);
            }

            return(LoadFromFile(configFile));
        }
Esempio n. 3
0
        public MainWindow(FamiliarCommandLineArguments args, int parentPid, IntPtr targetWindow)
        {
            // Safe initializations. Do not put anything here that can throw an exception.
            // Defer to loaded.

            _trace = DiagnosticsCenter.GetTraceSource(nameof(MainWindow));

            _args        = args;
            _pid         = parentPid;
            _machineName = Environment.MachineName;

            var inputLanguage = InputLanguage.CurrentInputLanguage;

            _trace.TraceVerbose("Input language {0}: {1}", nameof(inputLanguage.LayoutName), inputLanguage.LayoutName);

            var culture = inputLanguage.Culture;

            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.DisplayName), culture.DisplayName);
            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.EnglishName), culture.EnglishName);
            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.IsNeutralCulture), culture.IsNeutralCulture);
            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.Name), culture.Name);
            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.KeyboardLayoutId), culture.KeyboardLayoutId);
            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.NativeName), culture.NativeName);
            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.ThreeLetterISOLanguageName), culture.ThreeLetterISOLanguageName);
            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.ThreeLetterWindowsLanguageName), culture.ThreeLetterWindowsLanguageName);
            _trace.TraceVerbose("Input language culture {0}: {1}", nameof(culture.TwoLetterISOLanguageName), culture.TwoLetterISOLanguageName);

            var textInfo = culture.TextInfo;

            _trace.TraceVerbose("Input language culture text info {0}: {1}", nameof(textInfo.ANSICodePage), textInfo.ANSICodePage);
            _trace.TraceVerbose("Input language culture text info {0}: {1}", nameof(textInfo.CultureName), textInfo.CultureName);
            _trace.TraceVerbose("Input language culture text info {0}: {1}", nameof(textInfo.EBCDICCodePage), textInfo.EBCDICCodePage);
            _trace.TraceVerbose("Input language culture text info {0}: {1}", nameof(textInfo.MacCodePage), textInfo.MacCodePage);
            _trace.TraceVerbose("Input language culture text info {0}: {1}", nameof(textInfo.OEMCodePage), textInfo.OEMCodePage);

            _parentProcess         = Process.GetProcessById(parentPid);
            _parentProcessObserver = new Thread(ParentProcessObserver);
            _parentProcessObserver.IsBackground = true;

            _targetWindow = targetWindow;

            _consoleWindowObserver = new Thread(ConsoleWindowObserver);
            // Set priority a bit higher than normal so this thread get cycles when our app is not active.
            //_consoleWindowObserver.Priority = ThreadPriority.AboveNormal; // Commented to avoid issues on 2016 server.
            _consoleWindowObserver.IsBackground = true;

            InitializeComponent();

            _trace.TraceVerbose("Main window object created.");
        }
Esempio n. 4
0
        private static FileInfo GetDefaultConfigFile(FamiliarCommandLineArguments args)
        {
            DirectoryInfo dbDirectory = null;

            if (args.Database != null)
            {
                dbDirectory = new DirectoryInfo(args.Database);
            }

            if (dbDirectory == null)
            {
                dbDirectory = DefaultDbDirectory;
            }

            if (!dbDirectory.Exists)
            {
                _trace.TraceWarning("Local database directory does not exist: {0}\r\nTrying to create...", dbDirectory.FullName);
                dbDirectory.Create();
            }

            var path = Path.Combine(dbDirectory.FullName, Constants.ConfigFileName);

            return(new FileInfo(path));
        }