/// <summary>
 /// This function will run on different thread than UI. Make sure to use Invoke for interface update.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 void queueTimer_DoWork(object sender, QueueTimerEventArgs e)
 {
     if (!IsSuspended())
     {
         CheckAll();
     }
 }
Beispiel #2
0
 /// <summary>
 /// This function will run on different thread than UI. Make sure to use Invoke for interface update.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 void queueTimer_DoWork(object sender, QueueTimerEventArgs e)
 {
     if (IsSuspended())
     {
         return;
     }
     CheckAll();
     UpdateDisplayedList();
 }
Beispiel #3
0
 /// <summary>
 /// This function will run on different thread than UI. Make sure to use Invoke for interface update.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 void queueTimer_DoWork(object sender, QueueTimerEventArgs e)
 {
     if (IsSuspended())
     {
         return;
     }
     CheckAll();
     // Update list will affect Warnings list, which is bound to MainDataGrid on UI,
     // therefore use Invoke to make sure that it runs on the same thread as UI.
     ControlsHelper.Invoke(() => {
         UpdateDisplayedList();
     });
 }
Beispiel #4
0
        private void TasksTimer_BeforeRemove(object sender, QueueTimerEventArgs e)
        {
            var item = e.Item as CloudItem;

            // If check online task failed then...
            if (Equals(CheckUpateItem, item) && !e.Keep)
            {
                CurrentLogItem.Message += " Failed";
                if (item.Error != null)
                {
                    CurrentLogItem.Message += ": " + item.Error.Message;
                }
            }
        }
Beispiel #5
0
        void RefreshBackgroundImage(object sender, QueueTimerEventArgs e)
        {
            int deadZone     = 0;
            int antiDeadZone = 0;
            int sensitivity  = 0;

            Invoke(((MethodInvoker) delegate()
            {
                deadZone = (int)DeadZoneNumericUpDown.Value;
                antiDeadZone = (int)AntiDeadZoneNumericUpDown.Value;
                sensitivity = (int)SensitivityNumericUpDown.Value;
            }));
            var borders = MainPictureBox.BorderStyle == System.Windows.Forms.BorderStyle.None ? 0 : 2;
            var w       = MainPictureBox.Width - borders;
            var h       = MainPictureBox.Height - borders;
            var bmp     = new Bitmap(w, h);
            var g       = Graphics.FromImage(bmp);

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            var dInputBrush = new SolidBrush(System.Drawing.Color.Gray);
            var dInputPen   = new Pen(dInputBrush);
            var xInputBrush = new SolidBrush(System.Drawing.Color.Red);
            var nInputBrush = new SolidBrush(System.Drawing.Color.FromArgb(32, 128, 128, 128));
            var nInputPen   = new Pen(nInputBrush);
            var radius      = 0.5f;

            g.DrawLine(nInputPen, 0, h, w, 0);
            for (float i = 0; i < w; i += 0.5f)
            {
                var m = (float)w;
                // Get value range [-1;1].
                float value       = i / (m - 1f) * 2f - 1f;
                short dInputValue = SharpDX.XInput.XInput.ConvertToShort(value);
                short result      = SharpDX.XInput.XInput.GetThumbValue(dInputValue, deadZone, antiDeadZone, sensitivity);
                var   resultInt   = ((SharpDX.XInput.XInput.ConvertToFloat(result) + 1f) / 2f * m);
                var   x1          = i;
                var   y1          = m - resultInt - 1f;
                g.FillEllipse(xInputBrush, x1, y1, radius * 2f, radius * 2f);
            }
            Invoke(((MethodInvoker) delegate()
            {
                LastBackgroundImage = bmp;
                MainPictureBox.BackgroundImage = Enabled ? LastBackgroundImage : null;
            }));
        }
Beispiel #6
0
 void updateTimer_DoWork(object sender, QueueTimerEventArgs e)
 {
     CreateBacgroundPicture();
 }
Beispiel #7
0
        /// <summary>
        /// This function will run on different thread than UI. Make sure to use Invoke for interface update.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        void queueTimer_DoWork(object sender, QueueTimerEventArgs e)
        {
            var item = e.Item as CloudItem;

            if (item == null)
            {
                return;
            }
            item.Try++;
            Invoke((Action) delegate()
            {
                MainForm.Current.AddTask(TaskName.CloudCommand);
            });
            Exception error = null;

            try
            {
                var ws = new WebServiceClient();
                ws.Url = SettingsManager.Options.InternetDatabaseUrl;
                CloudMessage result = null;
                var          o      = SettingsManager.Options;
                // Check if user public keys are present.
                o.CheckAndFixUserRsaKeys();
                // If cloud RSA keys are missing then...
                if (string.IsNullOrEmpty(o.CloudRsaPublicKey))
                {
                    // Step 1: Get Server's Public RSA key for encryption.
                    var msg = new CloudMessage(CloudAction.GetPublicRsaKey);
                    CloudHelper.ApplySecurity(item.Message);
                    msg.Values.Add(CloudKey.RsaPublicKey, o.UserRsaPublicKey);
                    // Retrieve public RSA key.
                    var results = ws.Execute(msg);
                    if (results.ErrorCode == 0)
                    {
                        o.CloudRsaPublicKey = results.Values.GetValue <string>(CloudKey.RsaPublicKey);
                        SettingsManager.OptionsData.Save();
                    }
                    else
                    {
                        error = new Exception(result.ErrorMessage);
                    }
                }
                // If no errors till this point then...
                if (error == null)
                {
                    // Add security.
                    CloudHelper.ApplySecurity(item.Message, o.UserRsaPublicKey, o.CloudRsaPublicKey, o.Username, o.Password);
                    // Add computer Id
                    item.Message.Values.Add(CloudKey.ComputerId, o.ComputerId, true);
                    result = ws.Execute(item.Message);
                    if (result.ErrorCode > 0)
                    {
                        error = new Exception(result.ErrorMessage);
                    }
                    else
                    {
                        Invoke((Action) delegate()
                        {
                            ProcessResult(item.Message, result);
                        });
                    }
                }
                ws.Dispose();
            }
            catch (Exception ex)
            {
                error = ex;
            }
            Invoke((Action) delegate()
            {
                MainForm.Current.RemoveTask(TaskName.CloudCommand);
            });
            var success = error == null;

            item.Error = error;
            item.State = success ? CloudState.Done : CloudState.Error;
            // If error or have not finished.
            e.Keep = !success;
            // error and no more retries left then...
            if (!success && item.Try >= item.Retries)
            {
                // Order to remove task.
                e.Keep = false;
            }
            // Exit thread (queue will be processed later)
            e.Cancel = !success;
        }
Beispiel #8
0
        /// <summary>
        /// This function will run on different thread than UI. Make sure to use Invoke for interface update.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        void queueTimer_DoWork(object sender, QueueTimerEventArgs e)
        {
            var item = e.Item as CloudItem;

            if (item == null)
            {
                return;
            }
            item.Try++;
            MainForm.Current.AddTask(TaskName.CloudCommand);
            Exception error = null;

            try
            {
                var ws = new WebServiceClient();
                ws.Url = SettingsManager.Options.InternetDatabaseUrl;
                CloudMessage result = null;
                var          o      = SettingsManager.Options;
                // Check if user public keys are present.
                o.CheckAndFixUserRsaKeys();
                // If cloud RSA keys are missing then...
                if (string.IsNullOrEmpty(o.CloudRsaPublicKey))
                {
                    // Step 1: Get Server's Public RSA key for encryption.
                    var msg = new CloudMessage(CloudAction.GetPublicRsaKey);
                    // Retrieve public RSA key.
                    var results = ws.Execute(msg);
                    if (results.ErrorCode == 0)
                    {
                        o.CloudRsaPublicKey = results.Values.GetValue <string>(CloudKey.RsaPublicKey);
                        SettingsManager.OptionsData.Save();
                    }
                    else
                    {
                        error = new Exception(result.ErrorMessage);
                    }
                }
                // If no errors till this point then...
                if (error == null)
                {
                    // Add security.
                    CloudHelper.ApplySecurity(item.Message, o.UserRsaPublicKey, o.CloudRsaPublicKey, o.Username, o.Password);
                    // Add computer and profile ID.
                    item.Message.Values.Add(CloudKey.ComputerId, o.ComputerId, true, true);
                    item.Message.Values.Add(CloudKey.ProfileId, o.ProfileId, true, true);
                    // Add version so it will be possible distinguish between Library (v3.x) and Virtual (v4.x) settings.
                    item.Message.Values.Add(CloudKey.ClientVersion, Application.ProductVersion, false, true);
                    // Call web service.
                    result = ws.Execute(item.Message);
                    if (result.ErrorCode != 0)
                    {
                        // If unable to decrypt error then...
                        if (result.ErrorCode == (int)CloudErrorCode.UnableToDecrypt)
                        {
                            // Get server's RSA Public key.
                            var cloudRsaPublicKey = result.Values.GetValue <string>(CloudKey.RsaPublicKey, null);
                            // If key was set then update local key.
                            if (!string.IsNullOrEmpty(cloudRsaPublicKey))
                            {
                                o.CloudRsaPublicKey = cloudRsaPublicKey;
                            }
                        }
                        error = new Exception(result.ErrorMessage);
                    }
                    else
                    {
                        ProcessResult(item.Message, result);
                    }
                }
                ws.Dispose();
            }
            catch (Exception ex)
            {
                error = ex;
            }
            MainForm.Current.RemoveTask(TaskName.CloudCommand);
            var success = error == null;

            item.Error = error;
            item.State = success ? CloudState.Done : CloudState.Error;
            // If error or have not finished.
            e.Keep = !success;
            // error and no more retries left then...
            if (!success && item.Try >= item.Retries)
            {
                // Order to remove task.
                e.Keep = false;
            }
            // Exit thread (queue will be processed later)
            e.Cancel = !success;
        }
Beispiel #9
0
        /// <summary>
        /// This function will run on different thread than UI. Make sure to use Invoke for interface update.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        void queueTimer_DoWork(object sender, QueueTimerEventArgs e)
        {
            var item = e.Item as CloudItem;

            if (item == null)
            {
                return;
            }
            item.Try++;
            Invoke((Action) delegate()
            {
                MainForm.Current.AddTask(TaskName.SaveToCloud);
            });
            Exception error = null;

            try
            {
                var ws = new WebServiceClient();
                ws.Url = SettingsManager.Options.InternetDatabaseUrl;
                CloudMessage result = null;
                var          o      = SettingsManager.Options;
                // Check if user public keys are present.
                o.CheckAndFixUserRsaKeys();
                // If cloud RSA keys are missing then...
                if (string.IsNullOrEmpty(o.CloudRsaPublicKey))
                {
                    // Step 1: Get Server's Public RSA key for encryption.
                    var msg = CloudHelper.NewMessage(CloudAction.GetPublicRsaKey);
                    msg.Values.Add(CloudKey.RsaPublicKey, o.UserRsaPublicKey);
                    // Retrieve public RSA key.
                    var results = ws.Execute(msg);
                    if (results.ErrorCode == 0)
                    {
                        o.CloudRsaPublicKey = results.Values.GetValue <string>(CloudKey.RsaPublicKey);
                        SettingsManager.OptionsData.Save();
                    }
                    else
                    {
                        error = new Exception(result.ErrorMessage);
                    }
                }
                // If no errors till this point then...
                if (error == null)
                {
                    // Add security.
                    var command = CloudHelper.NewMessage(item.Action, o.UserRsaPublicKey, o.CloudRsaPublicKey, o.Username, o.Password);
                    command.Values.Add(CloudKey.ComputerId, o.ComputerId, true);
                    // If item is UserGame then...
                    if (item.Item.GetType() == typeof(UserGame))
                    {
                        command.UserGames = new List <UserGame>()
                        {
                            (UserGame)item.Item
                        };
                    }
                    // If item is UserDevice then...
                    else if (item.Item.GetType() == typeof(UserDevice))
                    {
                        command.UserDevices = new List <UserDevice>()
                        {
                            (UserDevice)item.Item
                        };
                    }
                    result = ws.Execute(command);
                    if (result.ErrorCode > 0)
                    {
                        error = new Exception(result.ErrorMessage);
                    }
                }
                ws.Dispose();
            }
            catch (Exception ex)
            {
                error = ex;
            }
            Invoke((Action) delegate()
            {
                MainForm.Current.RemoveTask(TaskName.SaveToCloud);
            });
            item.Error = error;
            item.State = error == null ? CloudState.Done : CloudState.Error;
            e.Keep     = error != null;
            e.Break    = error != null;
        }