Ejemplo n.º 1
0
        public static void AddTrackToInstallQueue(string trackName)
        {
            try
            {
                if (Sharing.UploadTracksQueueIsEmpty)
                {
                    var track = Reflex.GetTracks().Where(t => t.TrackName == trackName).SingleOrDefault();

                    if (track != null)
                    {
                        if (m_trackQueue.Any(q => q.TrackType == track.TrackType && q.SlotNumber == track.SlotNumber) == false)
                        {
                            m_trackQueue.Enqueue(track);
                            Log.Add(Trackmanagement.LogMessageType.LogInfo, string.Format("Added '{0}' ({1} Slot {2}) to the install queue.", track.TrackName, track.TrackType, track.SlotNumber));
                        }
                        else
                        {
                            Log.Add(Trackmanagement.LogMessageType.LogWarning, string.Format("There is already a track being installed to '{0} Slot {1}'. Wait for the current install process to finish before installing '{2}'.", track.TrackType, track.SlotNumber, track.TrackName));
                        }
                    }
                    else
                    {
                        Log.Add(Trackmanagement.LogMessageType.LogWarning, string.Format("Unable to find '{0}'. Install operation cancelled.", trackName));
                    }
                }
                else
                {
                    Log.Add(Trackmanagement.LogMessageType.LogWarning, string.Format("Your tracks are being processed for sharing. Wait for the upload operation to complete before installing {0}.", trackName));
                }
            }
            catch (Exception e)
            {
                ExceptionLogger.LogException(e);
            }
        }
Ejemplo n.º 2
0
 public static void EnqueueRandomRandomTracks(string trackType)
 {
     try
     {
         if (Sharing.UploadTracksQueueIsEmpty)
         {
             if (m_trackQueue.IsEmpty)
             {
                 Random rnd = new Random();
                 for (int i = 0; i < Reflex.SlotCount; ++i)
                 {
                     int slot        = i + 1;
                     var randomTrack = Reflex.GetTracks().Where(t => t.TrackType == trackType && t.SlotNumber == slot).Select(t => t.TrackName).OrderBy(item => rnd.Next()).FirstOrDefault();
                     if (randomTrack != null)
                     {
                         AddTrackToInstallQueue(randomTrack);
                     }
                 }
             }
             else
             {
                 Log.Add(Trackmanagement.LogMessageType.LogWarning, string.Format("Please wait for the current install operation to complete before selecting random {0} tracks.", trackType));
             }
         }
         else
         {
             Log.Add(Trackmanagement.LogMessageType.LogWarning, string.Format("Your tracks are being processed for sharing. Wait for the upload operation to complete before installing new random {0} tracks.", trackType));
         }
     }
     catch (Exception e)
     {
         ExceptionLogger.LogException(e);
     }
 }
Ejemplo n.º 3
0
        public static void ProcessDownloadQueue()
        {
            try
            {
                if (m_trackQueue.TryPeek(out Track track))
                {
                    var localTracks = Reflex.GetTracksOnDisk();
                    if (localTracks.Contains(track.TrackName) == false)
                    {
                        Log.Add(Trackmanagement.LogMessageType.LogInfo, string.Format("Downloading '{0}' from server.", track.TrackName));
                        DownloadFile(track.TrackUrl, string.Format(@"{0}\{1}{2}", Reflex.LocalTrackPath, track.TrackName, Path.GetExtension(track.TrackUrl)));
                    }

                    Log.Add(Trackmanagement.LogMessageType.LogInfo, string.Format("Installing '{0}' to databse folder.", track.TrackName));
                    InstallTrack(track);

                    //We here instead of at the top of the loop because there are concurrent processes checking to ensure the queue is empty.
                    //We don't want external processes to think installation is complete before it really is.
                    m_trackQueue.TryDequeue(out Track dummy);
                    if (m_trackQueue.IsEmpty)
                    {
                        Log.Add(Trackmanagement.LogMessageType.LogInfo, "Installation Complete!");
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionLogger.LogException(e);
            }
        }
Ejemplo n.º 4
0
        public static void ToggleFavorite(string trackName)
        {
            lock (m_locker)
            {
                var track = Reflex.GetTracks().Where(t => t.TrackName == trackName).SingleOrDefault();
                if (track != null)
                {
                    var existing = m_tracks.Where(t => t.Name == track.TrackName && t.Type == track.TrackType).SingleOrDefault();
                    if (existing != null)
                    {
                        existing.Favorite = !existing.Favorite;
                    }
                    else
                    {
                        m_tracks.Add(new LocalTrack
                        {
                            Name           = track.TrackName,
                            Type           = track.TrackType,
                            Image          = string.Format("{0}\\{1}{2}", Reflex.LocalImagePath, track.TrackName, Path.GetExtension(track.ThumbnailUrl)).Replace("\\", "/"),
                            Data           = "",
                            Author         = track.Author,
                            Slot           = track.SlotNumber,
                            CreationTime   = track.CreationTime,
                            TotalDownloads = track.RatingVoteCount, //GNARLY_TODO: covert to downloads
                            MyDownloads    = 1,
                            Favorite       = true,
                            Installed      = false
                        });
                    }
                    SaveTracks();
                }
            }

            Reflex.FlushDisplayTracks();
        }
Ejemplo n.º 5
0
 private static void PollSharedTracks()
 {
     if (Reflex.OverlayIsVisible() && TimeUtility.DateTimeToUnixTimeStamp(DateTime.UtcNow) > m_nextPollTime)
     {
         lock (m_sharedTrackLocker)
         {
             m_sharedTracks = HttpUtility.Get <SharedReflexTracks[]>("https://spptqssmj8.execute-api.us-east-1.amazonaws.com/test/share");
         }
         m_nextPollTime = TimeUtility.DateTimeToUnixTimeStamp(DateTime.UtcNow) + TrackSharing.ServerPollingRateInSeconds;
     }
 }
Ejemplo n.º 6
0
        public static string DownloadImage(string trackName)
        {
            string path = string.Empty;

            try
            {
                var track = Reflex.GetTracks().Where(t => t.TrackName.Trim() == trackName.Trim()).Single();
                DownloadFile(track.ThumbnailUrl, string.Format(@"{0}\{1}{2}", Reflex.LocalImagePath, trackName, Path.GetExtension(track.ThumbnailUrl)));
            }
            catch (Exception e)
            {
                ExceptionLogger.LogException(e);
            }
            return(path);
        }
        private Trackmanagement.Track[] FilterTracks(Trackmanagement.SortRequest request)
        {
            var tracks = Reflex.GetDisplayTracks();

            if (request.TrackType != "All Track Types")
            {
                tracks = tracks.Where(t => t.Type == request.TrackType).ToArray();
            }

            if (request.Slot != "All Slots")
            {
                int slot = Convert.ToInt32(request.Slot);
                tracks = tracks.Where(t => t.Slot == slot).ToArray();
            }
            return(tracks);
        }
Ejemplo n.º 8
0
        public static void HandleTrackInstall(ReflexUtility.Track track, string dataPath)
        {
            //Uninstall the track in the current slot if it exists.
            lock (m_locker)
            {
                var currentlyInstalledTrack = m_tracks.Where(t => t.Installed == true && t.Type == track.TrackType && t.Slot == track.SlotNumber).SingleOrDefault();
                if (currentlyInstalledTrack != null)
                {
                    currentlyInstalledTrack.Installed = false;
                }

                var localTrack = m_tracks.Where(t => t.Name == track.TrackName && t.Type == track.TrackType).SingleOrDefault();
                if (localTrack != null)
                {
                    localTrack.TotalDownloads = track.RatingVoteCount;
                    ++localTrack.MyDownloads;
                    localTrack.Installed = true;
                }
                else
                {
                    m_tracks.Add(new LocalTrack
                    {
                        Name           = track.TrackName,
                        Type           = track.TrackType,
                        Image          = string.Format("{0}\\{1}{2}", Reflex.LocalImagePath, track.TrackName, Path.GetExtension(track.ThumbnailUrl)).Replace("\\", "/"),
                        Data           = dataPath.Replace("\\", "/"),
                        Author         = track.Author,
                        Slot           = track.SlotNumber,
                        CreationTime   = track.CreationTime,
                        TotalDownloads = track.RatingVoteCount, //GNARLY_TODO: covert to downloads
                        MyDownloads    = 1,
                        Favorite       = false,
                        Installed      = true
                    });
                }
            }

            Reflex.FlushDisplayTracks();
        }
Ejemplo n.º 9
0
        public static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Checking for updates...");
                ApplicationUpdater updater = new ApplicationUpdater();
                if (updater.IsActiveVersion() == false)
                {
                    updater.DownloadAndLaunchUpdater();
                    return;
                }
                Sharing.Initialize();
                Reflex reflex = new Reflex();
                reflex.ValidateInstallation();
                reflex.DownloadImages();
                LocalSettings.Load();
                reflex.InitializeTrackList();
                reflex.InstallRandomTracksOnFirstRun();

                if (args.Length == 0)
                {
                    var    managementService = new TrackManagementService();
                    Server server            = new Server
                    {
                        Services = { Trackmanagement.TrackManager.BindService(managementService) },
                        Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
                    };
                    server.Start();

                    Console.WriteLine("Track management server listening on port " + Port);

                    if (System.Diagnostics.Process.GetProcessesByName("MXReflex").Length == 0)
                    {
                        Console.WriteLine("Waiting for you to launch MX vs. ATV Reflex...");
                    }

                    while (true)
                    {
                        reflex.Process();
                    }
                }
                else
                {
                    if (args.Length == 1 && args[0] == "-downloadalltracks")
                    {
                        reflex.DownloadAllTracks();
                    }
                    else
                    {
                        Console.Error.WriteLine(string.Format("Invalid arguments provided to application ({0})", string.Join(",", args)));
                        Console.WriteLine("Usage:");
                        Console.WriteLine("\t-Normal execution mode (UI Overlay): TrackManager.exe");
                        Console.WriteLine("\t-Download all tracks mode: TrackManager.exe -downloadalltracks");
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionLogger.LogException(e);
            }

            Console.WriteLine("Press any key to close this window.");
            Console.ReadKey();
        }
 public override Task <Trackmanagement.Empty> SetOverlayVisible(Trackmanagement.ToggleMessage request, ServerCallContext context)
 {
     Reflex.SetOverlayVisibility(request.Toggle);
     return(Task.FromResult(new Trackmanagement.Empty()));
 }