示例#1
0
        public static UserConfigOptionsModel LoadConfigData()
        {
            var response = new UserConfigOptionsModel();

            var configFilename = ConfigurationManager.AppSettings["UserConfigFileName"];
            var currentDir     = Directory.GetCurrentDirectory();

            var di = new DirectoryInfo(currentDir).GetFiles().Where(x => x.Name == configFilename).ToList();

            if (!di.Any())
            {
                response = GetDefaultUserOptions(currentDir);

                using (var fileStream = new FileStream(String.Format("{0}\\{1}", currentDir, configFilename), FileMode.Create))
                    using (var fileWriter = new StreamWriter(fileStream))
                    {
                        fileWriter.Write(response.ToXML());
                    }
            }
            else
            {
                using (var fileStream = new FileStream(String.Format("{0}\\{1}", currentDir, configFilename), FileMode.Open))
                    using (var fileReader = new StreamReader(fileStream))
                    {
                        var xmlData = fileReader.ReadToEnd();

                        response = UserConfigOptionsModel.LoadFromXMLString(xmlData);
                        response.CurrentWorkingDirectory = currentDir;
                    }
            }

            return(response);
        }
示例#2
0
        public static void Execute(UserConfigOptionsModel userConfigOptions)
        {
            var ioService    = new IoDetectionService(userConfigOptions);
            var slackService = new SlackApiService(userConfigOptions);

            Thread.Sleep(userConfigOptions.PauseTimeBetweenScansSec * 1000);

            var userIsIdle = ioService.CheckUserIdleStatus();
            var receivedIm = false;

            if (userIsIdle)
            {
                ioService.WiggleMouse();

                receivedIm = ioService.AnalyzeScreen();

                if (receivedIm)
                {
                    slackService.SendMessage(String.Empty);
                }
                else if (userConfigOptions.TestingFlag.ToLower() == "true".ToLower())
                {
                    slackService.SendMessage("*TEST MESSAGE*");
                }
            }
        }
示例#3
0
        public static void SaveUserConfigOptions(UserConfigOptionsModel userConfigOptions)
        {
            var configFilename = ConfigurationManager.AppSettings["UserConfigFileName"];

            using (var fileStream = new FileStream(String.Format("{0}\\{1}", userConfigOptions.CurrentWorkingDirectory, configFilename), FileMode.Create))
                using (var fileWriter = new StreamWriter(fileStream))
                {
                    fileWriter.Write(userConfigOptions.ToXML());
                }
        }
示例#4
0
        public static ConfigForm GetInstance(UserConfigOptionsModel userConfigOptions)
        {
            if (_configForm == null)
            {
                _configForm             = new ConfigForm(userConfigOptions);
                _configForm.FormClosed += delegate { _configForm = null; }; // When the form gets closed: run the code in the delegate
            }

            _configForm.BringToFront();

            return(_configForm);
        }
示例#5
0
 private static void WriteToLog(UserConfigOptionsModel userConfigOptions, HttpResponseMessage errorResponse, Exception ex, FileMode fm, string logFile)
 {
     using (var fileStream = new FileStream(String.Format("{0}\\{1}", userConfigOptions.CurrentWorkingDirectory, logFile), fm))
         using (var fileWriter = new StreamWriter(fileStream))
         {
             if (errorResponse != null)
             {
                 fileWriter.WriteLine(String.Format("{0}: HTTP Error {1} {2}. Request Message: {3}. Response Content: {4} Exception: {5}", DateTime.Now.ToString(), (int)errorResponse.StatusCode, errorResponse.StatusCode, errorResponse.RequestMessage, errorResponse.Content.ReadAsStringAsync().Result, WriteAllExceptionMessages(ex)));
             }
             else
             {
                 fileWriter.WriteLine(String.Format("{0}: {1}", DateTime.Now.ToString(), WriteAllExceptionMessages(ex)));
             }
         }
 }
示例#6
0
        public static void WriteToSlackApiLog(UserConfigOptionsModel userConfigOptions, HttpResponseMessage errorResponse, Exception ex)
        {
            var logFile = ConfigurationManager.AppSettings["GhostBotLogFileName"];

            var di = new DirectoryInfo(userConfigOptions.CurrentWorkingDirectory).GetFiles().Where(x => x.Name == logFile).ToList();

            if (di.Any())
            {
                WriteToLog(userConfigOptions, errorResponse, ex, FileMode.Append, logFile);
            }
            else
            {
                WriteToLog(userConfigOptions, errorResponse, ex, FileMode.Create, logFile);
            }
        }
示例#7
0
        public GhostBotGui(UserConfigOptionsModel userConfigOptions)
        {
            UserConfigOptions = userConfigOptions;

            // Create a simple tray menu with only one item.
            _trayMenu = new ContextMenu();

            BuildTrayMenu();

            // Create a tray icon.
            _trayIcon      = new NotifyIcon();
            _trayIcon.Text = "GhostBot";
            _trayIcon.Icon = new Icon(SystemIcons.Shield, 40, 40);

            // Add menu to tray icon and show it.
            _trayIcon.ContextMenu = _trayMenu;
            _trayIcon.Visible     = true;
        }
示例#8
0
        private static UserConfigOptionsModel GetDefaultUserOptions(string currentWorkingDirectory)
        {
            var response = new UserConfigOptionsModel();

            response.CurrentWorkingDirectory = currentWorkingDirectory;

            response.ResourceLocation     = String.Format("{0}\\{1}", currentWorkingDirectory, ConfigurationManager.AppSettings["DefaultBaseResourceLocation"]);
            response.SingleScreenLocation = ConfigurationManager.AppSettings["DefaultSingleScreenResources"];
            response.MultiScreenLocation  = ConfigurationManager.AppSettings["DefaultMultiScreenResources"];
            response.MenuLocation         = ConfigurationManager.AppSettings["DefaultStartMenuLocation"];

            response.SlackBaseUrl    = ConfigurationManager.AppSettings["DefaultSlackBaseUrl"];
            response.SlackChannel    = ConfigurationManager.AppSettings["DefaultTargetSlackChannel"];
            response.GhostBotMessage = ConfigurationManager.AppSettings["DefaultGhostBotBaseMessage"];

            response.PauseTimeBetweenScansSec = int.Parse(ConfigurationManager.AppSettings["DefaultPauseTimeInSec"]);
            response.IdleThresholdSec         = int.Parse(ConfigurationManager.AppSettings["DefaultIdleThresholdInSec"]);

            response.TestingFlag = ConfigurationManager.AppSettings["DefaultTestingFlag"];

            return(response);
        }
 public IoDetectionService(UserConfigOptionsModel userConfigOptions)
 {
     UserConfigOptions = userConfigOptions;
 }
示例#10
0
 public SlackApiService(UserConfigOptionsModel userConfigOptions)
 {
     UserConfigOptions = userConfigOptions;
 }
示例#11
0
        private ConfigForm(UserConfigOptionsModel userConfigOptions)
        {
            UserConfigOptions = userConfigOptions;

            InitializeComponent();
        }