Beispiel #1
0
        public void SaveActivity(int index, SavedActivity activity)
        {
            if (index < 0 || index > 5)
            {
                return;
            }

            SetupActivities();

            if (activity == null)
            {
                activity = new SavedActivity();
            }
            if (string.IsNullOrEmpty(activity.Name))
            {
                activity.Name = index == 0 ? "Default" : $"Activity {index}";
            }

            // Save new activity
            Activities[index] = activity;

            // Clamp current activity index
            if (Activity < 0)
            {
                Activity = 0;
            }
            else if (Activity >= Activities.Length)
            {
                Activity = Activities.Length - 1;
            }

            Save();
        }
        public async Task <IActionResult> PutSavedActivity([FromRoute] int id, [FromBody] SavedActivity savedActivity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != savedActivity.SavedActivityId)
            {
                return(BadRequest());
            }

            _context.Entry(savedActivity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SavedActivityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        private void SaveActivity1Button_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mainWindow = Util.GetMainWindow();

            if (mainWindow != null && !string.IsNullOrEmpty(Activity1.Text))
            {
                SavedActivity activity = new SavedActivity
                {
                    Name     = Activity1.Text,
                    Activity = new Activity
                    {
                        ClientID       = mainWindow.ClientID.Text,
                        Details        = mainWindow.Details.Text,
                        State          = mainWindow.State.Text,
                        LargeImageKey  = mainWindow.LargeImageKey.Text,
                        LargeImageText = mainWindow.LargeImageText.Text,
                        SmallImageKey  = mainWindow.SmallImageKey.Text,
                        SmallImageText = mainWindow.SmallImageText.Text,
                        ShowTimestamp  = mainWindow.ShowTimestampCheckbox.IsChecked ?? false,
                        ResetTimestamp = mainWindow.ResetTimestampCheckbox.IsChecked ?? false
                    }
                };
                SaveActivity(1, activity);
            }
        }
        public async Task <IActionResult> PostSavedActivity([FromBody] SavedActivity savedActivity)
        {
            var user = await GetCurrentUserAsync();

            savedActivity.User = user;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.SavedActivity.Add(savedActivity);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (SavedActivityExists(savedActivity.SavedActivityId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetSavedActivity", new { id = savedActivity.SavedActivityId }, savedActivity));
        }
Beispiel #5
0
 private void SaveActivity(int number, SavedActivity activity)
 {
     if (Config.Current != null)
     {
         Config.Current.SaveActivity(number, activity);
         CooldownButtons();
     }
 }
Beispiel #6
0
 public static ulong Add(SavedActivity activity)
 {
     return(DbUtils.ConnectAndExecute(conn => {
         var query = "INSERT INTO engine4_advancedactivity_savefeeds(user_id,action_type,action_id) " +
                     "VALUES (@user_id,@action_type,@action_id)";
         var cmd = new MySqlCommand(query, conn);
         cmd.Parameters.AddWithValue("user_id", activity.user_id);
         cmd.Parameters.AddWithValue("action_type", activity.action_type);
         cmd.Parameters.AddWithValue("action_id", activity.action_id);
         var rc = cmd.ExecuteNonQuery();
         return (ulong)(rc > 0? 1:0);
     }));
 }
Beispiel #7
0
        private RichPresence CreatePresence()
        {
            if (Config.Current == null)
            {
                return(new RichPresence());
            }
            SavedActivity savedActivity = Config.Current.GetActivity();
            Activity      activity      = savedActivity?.Activity;

            if (activity == null)
            {
                return(new RichPresence());
            }

            // Create presence from config
            RichPresence presence = new RichPresence();
            Assets       assets   = new Assets();

            if (!string.IsNullOrEmpty(activity.Details) && activity.Details.Length > 2)
            {
                presence.Details = activity.Details;
            }
            if (!string.IsNullOrEmpty(activity.State) && activity.State.Length > 2)
            {
                presence.State = activity.State;
            }
            if (!string.IsNullOrEmpty(activity.LargeImageKey))
            {
                assets.LargeImageKey = activity.LargeImageKey;
            }
            if (!string.IsNullOrEmpty(activity.LargeImageText))
            {
                assets.LargeImageText = activity.LargeImageText;
            }
            if (!string.IsNullOrEmpty(activity.SmallImageKey))
            {
                assets.SmallImageKey = activity.SmallImageKey;
            }
            if (!string.IsNullOrEmpty(activity.SmallImageText))
            {
                assets.SmallImageText = activity.SmallImageText;
            }
            presence.Assets = assets;
            if (activity.ShowTimestamp)
            {
                presence.Timestamps = new Timestamps(_timestamp);
            }

            return(presence);
        }
        public async Task <IActionResult> GetSavedActivity([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            SavedActivity savedActivity = await _context.SavedActivity.SingleOrDefaultAsync(m => m.SavedActivityId == id);

            if (savedActivity == null)
            {
                return(NotFound());
            }

            return(Ok(savedActivity));
        }
Beispiel #9
0
        public async Task <IActionResult> SaveActivity([FromRoute] int id)
        {
            var activity = _context.Activity.Single(a => a.ActivityId == id);

            if (activity == null)
            {
                return(BadRequest());
            }
            var user = await GetCurrentUserAsync();

            SavedActivity savedActivity = new SavedActivity
            {
                User       = user,
                ActivityId = id
            };

            _context.SavedActivity.Add(savedActivity);
            await _context.SaveChangesAsync();

            return(Ok(savedActivity));
        }
Beispiel #10
0
        public void SetupActivities()
        {
            if (Activities == null)
            {
                Activities = new SavedActivity[0];
            }

            List <SavedActivity> activityList = Activities.ToList();

            // Ensure there is always 1 default activity and 5 custom activities saved
            for (int i = 0; i <= 5; i++)
            {
                if (activityList.Count <= i)
                {
                    activityList.Add(new SavedActivity
                    {
                        Name     = i == 0 ? "Default" : $"Activity {i}",
                        Activity = new Activity()
                    });
                }
                else if (activityList[i] == null)
                {
                    activityList[i] = new SavedActivity
                    {
                        Name     = i == 0 ? "Default" : $"Activity {i}",
                        Activity = new Activity()
                    };
                }
                else if (string.IsNullOrEmpty(activityList[i].Name))
                {
                    activityList[i].Name = $"Activity {i}";
                }
            }

            Activities = activityList.ToArray();
        }