private void DownloaderWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (e.Argument == null)
                    return;

                basePath = Environment.CurrentDirectory;
                dhtNodeFile = System.IO.Path.Combine(basePath, "DhtNodes");
                downloadsPath = System.IO.Path.Combine(basePath, "Downloads");
                torrentsPath = System.IO.Path.Combine(basePath, "Torrents");
                fastResumeFile = System.IO.Path.Combine(torrentsPath, "fastresume.data");
                torrents = new List<TorrentManager>();     // The list where all the torrentManagers will be stored that the engine gives us
                listener = new Top10Listener(10);

                string torrentpath = e.Argument.ToString();

                int port = 6969;
                Torrent torrent = null;

                // Create the settings which the engine will use
                // downloadsPath - this is the path where we will save all the files to
                // port - this is the port we listen for connections on
                EngineSettings engineSettings = new EngineSettings(downloadsPath, port);
                engineSettings.PreferEncryption = false;
                engineSettings.AllowedEncryption = EncryptionTypes.All;

                //engineSettings.GlobalMaxUploadSpeed = 30 * 1024;
                //engineSettings.GlobalMaxDownloadSpeed = 100 * 1024;
                //engineSettings.MaxReadRate = 1 * 1024 * 1024;

                // Create the default settings which a torrent will have.
                // 4 Upload slots - a good ratio is one slot per 5kB of upload speed
                // 50 open connections - should never really need to be changed
                // Unlimited download speed - valid range from 0 -> int.Max
                // Unlimited upload speed - valid range from 0 -> int.Max
                TorrentSettings torrentDefaults = new TorrentSettings(4, 150, 0, 0);

                // Create an instance of the engine.
                engine = new ClientEngine(engineSettings);
                engine.ChangeListenEndpoint(new IPEndPoint(IPAddress.Any, port));
                byte[] nodes = null;
                try
                {
                    nodes = File.ReadAllBytes(dhtNodeFile);
                }
                catch
                {
                    Console.WriteLine("No existing dht nodes could be loaded");
                }

                DhtListener dhtListner = new DhtListener(new IPEndPoint(IPAddress.Any, port));
                DhtEngine dht = new DhtEngine(dhtListner);
                engine.RegisterDht(dht);
                dhtListner.Start();
                engine.DhtEngine.Start(nodes);

                // If the SavePath does not exist, we want to create it.
                if (!Directory.Exists(engine.Settings.SavePath))
                    Directory.CreateDirectory(engine.Settings.SavePath);

                // If the torrentsPath does not exist, we want to create it
                if (!Directory.Exists(torrentsPath))
                    Directory.CreateDirectory(torrentsPath);

                BEncodedDictionary fastResume;
                try
                {
                    fastResume = BEncodedValue.Decode<BEncodedDictionary>(File.ReadAllBytes(fastResumeFile));
                }
                catch
                {
                    fastResume = new BEncodedDictionary();
                }

                // Load the .torrent from the file into a Torrent instance
                // You can use this to do preprocessing should you need to
                torrent = Torrent.Load(torrentpath);

                // When any preprocessing has been completed, you create a TorrentManager
                // which you then register with the engine.
                TorrentManager manager = new TorrentManager(torrent, downloadsPath, torrentDefaults);
                //if (fastResume.ContainsKey(torrent.InfoHash.ToHex()))
                //    manager.LoadFastResume(new FastResume((BEncodedDictionary)fastResume[torrent.infoHash.ToHex()]));
                engine.Register(manager);

                // Store the torrent manager in our list so we can access it later
                torrents.Add(manager);
                manager.PeersFound += new EventHandler<PeersAddedEventArgs>(manager_PeersFound);

                // Every time a piece is hashed, this is fired.
                manager.PieceHashed += delegate (object o, PieceHashedEventArgs ec)
                {
                    lock (listener)
                        listener.WriteLine(string.Format("Piece Hashed: {0} - {1}", ec.PieceIndex, ec.HashPassed ? "Pass" : "Fail"));
                };

                // Every time the state changes (Stopped -> Seeding -> Downloading -> Hashing) this is fired
                manager.TorrentStateChanged += delegate (object o, TorrentStateChangedEventArgs ev)
                {
                    lock (listener)
                        listener.WriteLine("OldState: " + ev.OldState.ToString() + " NewState: " + ev.NewState.ToString());
                };

                // Every time the tracker's state changes, this is fired
                //foreach (TrackerTier tier in manager.TrackerManager)
                //{
                //    //foreach (MonoTorrent.Client.Tracker.Tracker t in tier.Trackers)
                //    //{
                //    //    t.AnnounceComplete += delegate (object sender, AnnounceResponseEventArgs e)
                //    //    {
                //    //        listener.WriteLine(string.Format("{0}: {1}", e.Successful, e.Tracker.ToString()));
                //    //    };
                //    //}
                //}
                // Start the torrentmanager. The file will then hash (if required) and begin downloading/seeding
                manager.Start();

                // While the torrents are still running, print out some stats to the screen.
                // Details for all the loaded torrent managers are shown.
                bool running = true;
                StringBuilder sb = new StringBuilder(1024);
                while (running)
                {
                    //if ((i++) % 10 == 0)
                    //{
                    sb.Remove(0, sb.Length);
                    running = torrents.Exists(delegate (TorrentManager m) { return m.State != TorrentState.Stopped; });

                    //AppendFormat(sb, "Total Download Rate: {0:0.00}kB/sec", engine.TotalDownloadSpeed / 1024.0);
                    downloadspeed = (engine.TotalDownloadSpeed / 1024.0).ToString();
                    //AppendFormat(sb, "Total Upload Rate:   {0:0.00}kB/sec", engine.TotalUploadSpeed / 1024.0);
                    //AppendFormat(sb, "Disk Read Rate:      {0:0.00} kB/s", engine.DiskManager.ReadRate / 1024.0);
                    //AppendFormat(sb, "Disk Write Rate:     {0:0.00} kB/s", engine.DiskManager.WriteRate / 1024.0);
                    //AppendFormat(sb, "Total Read:         {0:0.00} kB", engine.DiskManager.TotalRead / 1024.0);
                    //AppendFormat(sb, "Total Written:      {0:0.00} kB", engine.DiskManager.TotalWritten / 1024.0);
                    //AppendFormat(sb, "Open Connections:    {0}", engine.ConnectionManager.OpenConnections);

                    //AppendSeperator(sb);
                    //AppendFormat(sb, "State:           {0}", manager.State);
                    //AppendFormat(sb, "Name:            {0}", manager.Torrent == null ? "MetaDataMode" : manager.Torrent.Name);
                    //AppendFormat(sb, "Progress:           {0:0.00}", manager.Progress);
                    //progress = manager.Progress.ToString();
                    //AppendFormat(sb, "Download Speed:     {0:0.00} kB/s", manager.Monitor.DownloadSpeed / 1024.0);
                    //AppendFormat(sb, "Upload Speed:       {0:0.00} kB/s", manager.Monitor.UploadSpeed / 1024.0);
                    //AppendFormat(sb, "Total Downloaded:   {0:0.00} MB", manager.Monitor.DataBytesDownloaded / (1024.0 * 1024.0));
                    //AppendFormat(sb, "Total Uploaded:     {0:0.00} MB", manager.Monitor.DataBytesUploaded / (1024.0 * 1024.0));
                    MonoTorrent.Client.Tracker.Tracker tracker = manager.TrackerManager.CurrentTracker;
                    //AppendFormat(sb, "Tracker Status:     {0}", tracker == null ? "<no tracker>" : tracker.State.ToString());
                    //AppendFormat(sb, "Warning Message:    {0}", tracker == null ? "<no tracker>" : tracker.WarningMessage);
                    //AppendFormat(sb, "Failure Message:    {0}", tracker == null ? "<no tracker>" : tracker.FailureMessage);
                    //if (manager.PieceManager != null)
                    //    AppendFormat(sb, "Current Requests:   {0}", manager.PieceManager.CurrentRequestCount());

                    //foreach (PeerId p in manager.GetPeers())
                    //    AppendFormat(sb, "\t{2} - {1:0.00}/{3:0.00}kB/sec - {0}", p.Peer.ConnectionUri,
                    //                                                              p.Monitor.DownloadSpeed / 1024.0,
                    //                                                              p.AmRequestingPiecesCount,
                    //                                                              p.Monitor.UploadSpeed / 1024.0);

                    //AppendFormat(sb, "", null);
                    //if (manager.Torrent != null)
                    //    foreach (TorrentFile file in manager.Torrent.Files)
                    //        AppendFormat(sb, "{1:0.00}% - {0}", file.Path, file.BitField.PercentComplete);

                    //Console.Clear();
                    //Console.WriteLine(sb.ToString());
                    //listener.ExportTo(Console.Out);
                    //}
                    DownloaderWorker.ReportProgress(Convert.ToInt32(manager.Progress), manager.State.ToString());
                    System.Threading.Thread.Sleep(500);
                }
            }
            catch (Exception ex)
            {

            }
        }
Пример #2
0
 private string GetUnconfirmedReportNumbers(List<string> reportNumbersProcessed)
 {
     StringBuilder result = new StringBuilder();
     foreach (string reportNumber in this.m_ReportNumbersToProcess)
     {
         if (reportNumbersProcessed.Exists(x => x == reportNumber) == false)
         {
             result.Append(reportNumber + " ");
         }
     }
     return result.ToString();
 }
Пример #3
0
        //removes an entry from the time table
        public void removeTimelineEntry(TimeSpan startTime, TimeSpan endTime, string text)
        {
            if (startTime.Days != endTime.Days)
            {
                TimeSpan endTimeSplit = new TimeSpan(startTime.Days, 23, 59, 0);
                removeTimelineEntry(startTime, endTimeSplit, text);

                TimeSpan startTimeSplit = new TimeSpan(endTime.Days, 0, 0, 0);
                removeTimelineEntry(startTimeSplit, endTime, text);
            }

            var entries = new List<TimelineEntry>();

            entries.AddRange(this.TuesdayEntries);
            entries.AddRange(this.MondayEntries);
            entries.AddRange(this.WednesdayEntries);
            entries.AddRange(this.ThursdayEntries);
            entries.AddRange(this.FridayEntries);
            entries.AddRange(this.SaturdayEntries);
            entries.AddRange(this.SundayEntries);

            if (entries.Exists(e => e.StartTime == startTime && e.EndTime == endTime && e.Text == text))
            {
                if (startTime.Days == 2)
                    this.TuesdayEntries.Remove(this.TuesdayEntries.First(e => e.StartTime == startTime && e.EndTime == endTime && e.Text == text));

                if (startTime.Days == 3)
                    this.WednesdayEntries.Remove(this.WednesdayEntries.First(e => e.StartTime == startTime && e.EndTime == endTime && e.Text == text));

                if (startTime.Days == 4)
                    this.ThursdayEntries.Remove(this.ThursdayEntries.First(e => e.StartTime == startTime && e.EndTime == endTime && e.Text == text));

                if (startTime.Days == 5)
                    this.FridayEntries.Remove(this.FridayEntries.First(e => e.StartTime == startTime && e.EndTime == endTime && e.Text == text));

                if (startTime.Days == 6)
                    this.SaturdayEntries.Remove(this.SaturdayEntries.First(e => e.StartTime == startTime && e.EndTime == endTime && e.Text == text));

                if (startTime.Days == 0 || startTime.Days == 7)
                    this.SundayEntries.Remove(this.SundayEntries.First(e => e.StartTime == startTime && e.EndTime == endTime && e.Text == text));

                if (startTime.Days == 1)
                    this.MondayEntries.Remove(this.MondayEntries.First(e => e.StartTime == startTime && e.EndTime == endTime && e.Text == text));
            }
        }
Пример #4
0
        private CustomCoordinateList GetCoordinates(DashboardHelper dashboardHelper, string latVar, string longVar, string timeVar)
        {
            List<string> columnNames = new List<string>();
            if (dashboardHelper.IsUsingEpiProject)
                columnNames.Add("UniqueKey");
            columnNames.Add(latVar);
            if (!columnNames.Exists(delegate(string s) { return s.Equals(longVar); }))
                columnNames.Add(longVar);
            if (!string.IsNullOrEmpty(timeVar))
            {
                if (!columnNames.Exists(delegate(string s) { return s.Equals(timeVar); }))
                    columnNames.Add(timeVar);
            }
            DataTable data = dashboardHelper.GenerateTable(columnNames);

            minTime = DateTime.MaxValue;
            maxTime = DateTime.MinValue;
            minX = double.MaxValue;
            maxX = double.MinValue;
            minY = double.MaxValue;
            maxY = double.MinValue;

            CustomCoordinateList coordinateList = new CustomCoordinateList();
            if (data != null)
            {
                foreach (DataRow row in data.Rows)
                {
                    if (row[latVar] != DBNull.Value && row[longVar] != DBNull.Value)
                    {
                        double latitude = double.Parse(row[latVar].ToString());
                        double longitude = double.Parse(row[longVar].ToString());
                        if (latitude <= 90 && latitude >= -90 && longitude <= 180 && longitude >= -180)
                        {
                            int uniqueKey = 0;
                            if (dashboardHelper.IsUsingEpiProject)
                                uniqueKey = (int)row["UniqueKey"];
                            if (string.IsNullOrEmpty(timeVar))
                            {
                                coordinateList.Coordinates.Add(new CustomCoordinate(uniqueKey, latitude, longitude, null));
                            }
                            else if (!data.Columns.Contains(timeVar))
                            {
                                coordinateList.Coordinates.Add(new CustomCoordinate(uniqueKey, latitude, longitude, null));
                            }
                            else
                            {
                                if (row[timeVar] != DBNull.Value)
                                {
                                    DateTime time = (DateTime)row[timeVar];
                                    minTime = minTime < time ? minTime : time;
                                    maxTime = maxTime > time ? maxTime : time;

                                    coordinateList.Coordinates.Add(new CustomCoordinate(uniqueKey, latitude, longitude, time));
                                }
                                else
                                {
                                    coordinateList.Coordinates.Add(new CustomCoordinate(uniqueKey, latitude, longitude, null));
                                }
                            }
                            minY = Math.Min(minY, latitude);
                            maxY = Math.Max(maxY, latitude);
                            minX = Math.Min(minX, longitude);
                            maxX = Math.Max(maxX, longitude);
                        }
                    }
                }
            }
            return coordinateList;
        }
Пример #5
0
        //Scan Media Button
        private void scanMedia_Click(object sender, RoutedEventArgs e)
        {
            //string filter = string.Empty;
            //if (Path.Contains("Wheel"))
            //    filter = "*.png";

            //di = new DirectoryInfo(Path);
            //fi = di.GetFiles(filter);
            //foreach (var item in fi)
            //{
            //    List<string> FilesList = new List<string>();
            //}

            try
            {
                string filter = string.Empty;
                DirectoryInfo di = new DirectoryInfo("Media\\" + systemName + "\\Wheel Images");
                if (di.FullName.Contains("Wheel"))
                    filter = "*.png";

                FileInfo[] fi = di.GetFiles(filter);
                listWheels = new List<MediaFiles>();

                List<Table> tab = new List<Table>(tables);
                foreach (FileInfo file in fi)
                {
                    bool exist = tab.Exists(x => x.Description == System.IO.Path.GetFileNameWithoutExtension(file.Name));
                    if (!exist)
                    {
                        listWheels.Add(new MediaFiles(file, "", false, "Wheels"));
                    }
                    else
                    { }

                }

                CollectionViewSource ItemCollectionViewSourceWheelFiles;
                ItemCollectionViewSourceWheelFiles = (CollectionViewSource)(FindResource("ItemCollectionViewSourceWheelFiles"));
                ItemCollectionViewSourceWheelFiles.Source = listWheels;

                di = new DirectoryInfo("Media\\" + systemName + "\\Table Images");
                fi = di.GetFiles("*.png");
                listTImgs = new List<MediaFiles>();
                foreach (var file in fi)
                {
                    bool exist = tab.Exists(x => x.Description == System.IO.Path.GetFileNameWithoutExtension(file.Name));
                    if (!exist)
                    {
                        listTImgs.Add(new MediaFiles(file, "", false, "Table Image"));
                    }
                    else
                    { }

                }

                di = new DirectoryInfo("Media\\" + systemName + "\\Table Videos");
                fi = di.GetFiles("*.mp4");
                listTVids = new List<MediaFiles>();
                foreach (var file in fi)
                {
                    bool exist = tab.Exists(x => x.Description == System.IO.Path.GetFileNameWithoutExtension(file.Name));
                    if (!exist)
                    {
                        listTImgs.Add(new MediaFiles(file, "", false, "Table Vids"));
                    }
                    else
                    { }

                }

                if (DataGridMedia.Items.Count > 0)
                {
                    foreach (var item in DataGridMedia.Items)
                    {
                        var t = item as Table;

                        if (File.Exists("Media\\" + systemName + "\\Wheel Images\\" + t.Description + ".png"))
                        {
                            t.HaveWheels = true;
                        }

                        if (File.Exists("Media\\" + systemName + "\\Backglass Images\\" + t.Description + ".png"))
                        {
                            t.HaveBGImage = true;
                        }

                        if (File.Exists("Media\\" + systemName + "\\Backglass Videos\\" + t.Description + ".f4v"))
                        {
                            t.HaveBGVids = true;
                        }

                        if (File.Exists("Media\\" + systemName + "\\Backglass Videos\\" + t.Description + ".mp4"))
                        {
                            t.HaveBGVids = true;
                        }

                        if (File.Exists("Media\\" + systemName + "\\DMD Images\\" + t.Description + ".png"))
                        {
                            t.HaveDmdImg = true;
                        }

                        if (File.Exists("Media\\" + systemName + "\\DMD Videos\\" + t.Description + ".f4v"))
                        {
                            t.HaveDmdVids = true;
                        }
                        if (File.Exists("Media\\" + systemName + "\\DMD Videos\\" + t.Description + ".mp4"))
                        {
                            t.HaveDmdVids = true;
                        }

                        if (File.Exists("Media\\" + systemName + "\\Real DMD Images\\" + t.Description + ".png"))
                        {
                            t.HaveRealDmdImg = true;
                        }

                        if (File.Exists("Media\\" + systemName + "\\Real DMD Videos\\" + t.Description + ".f4v"))
                        {
                            t.HaveRealDmdVids = true;
                        }
                        if (File.Exists("Media\\" + systemName + "\\Real DMD Videos\\" + t.Description + ".mp4"))
                        {
                            t.HaveRealDmdVids = true;
                        }
                        if (File.Exists("Media\\" + systemName + "\\Table Audio\\" + t.Description + ".mp3"))
                        {
                            t.HaveTableAudio = true;
                        }
                        if (File.Exists("Media\\" + systemName + "\\Table Images\\" + t.Description + ".png"))
                        {
                            t.HaveTableImage = true;
                        }
                        if (File.Exists("Media\\" + systemName + "\\Table Videos\\" + t.Description + ".f4v"))
                        {
                            t.HaveTableVideo = true;
                        }
                        if (File.Exists("Media\\" + systemName + "\\Table Videos\\" + t.Description + ".mp4"))
                        {
                            t.HaveTableVideo = true;
                        }

                        if (File.Exists("Media\\" + systemName + "\\Table Images Desktop\\" + t.Description + ".png"))
                        {
                            t.HaveTableImageDT = true;
                        }
                        if (File.Exists("Media\\" + systemName + "\\Table Videos Desktop\\" + t.Description + ".f4v"))
                        {
                            t.HaveTableVideoDT = true;
                        }
                        if (File.Exists("Media\\" + systemName + "\\Table Videos Desktop\\" + t.Description + ".mp4"))
                        {
                            t.HaveTableVideoDT = true;
                        }
                    }

                }
            }
            catch (Exception)
            {

                throw;
            }
        }
Пример #6
0
        public void ScanTablePath(string path)
        {
            string ext = string.Empty;
            string ext2 = string.Empty;
            DirectoryInfo di = new DirectoryInfo(path);
            if (systemName == "Visual Pinball")
            {
                ext = ".vpt";
                ext2 = ".vpx";
            }
            else if (systemName == "Future Pinball")
                ext = ".fpt";
            else if (systemName == "P-ROC")
            {
                ext = ".vpt";
                ext2 = ".vpx";
            }

            FileInfo[] fi;
            DirectoryInfo[] dia;
            List<Table> tab = new List<Table>(tables);
            oddTables = new ObservableCollection<OddTables>();

            fi = di.GetFiles("*.*");

            string tableExt = string.Empty;
            foreach (FileInfo file in fi)
            {
                tableExt = System.IO.Path.GetExtension(file.Name);
                if (ext == tableExt || ext2 == tableExt)
                {
                    bool exist = tab.Exists(x => x.Name == System.IO.Path.GetFileNameWithoutExtension(file.Name));
                    if (!exist)
                    {
                        oddTables.Add(new OddTables(file.Name, file.LastWriteTime));
                    }
                }
            }

            populateOddTables();
        }
        /// <summary>
        /// Filter by Card text content
        /// </summary>
        /// <param name="searchStr">The search STR.</param>
        /// <param name="actualStr">The actual STR.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev08, 2009-07-16</remarks>
        private bool CardSearchFilterText(string searchStr, List<string> actualStrings)
        {
            if (string.IsNullOrEmpty(searchStr))        //nothing typed --> show all
                return true;

            return actualStrings.Exists(s => s.ToLower().Contains(searchStr.ToLower()));
        }
        //Event Handler: Click on Browse button
        private void MediaPathButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Media files (image, video, audio)|*.jpg;*.gif;*.png;*.aac;*.wma;*.m4a;*.ogg;*.flac;*.wav;*.mp3;*.avi;*.mpg;*.mov|All Files (*.*)|*.*";
            ofd.FilterIndex = 1;
            if (ofd.ShowDialog() == true)
            {
                
                FileInfo info = new FileInfo(ofd.FileName);
                Boolean valid = false;
                List<String> validVideoExt = new List<String> {".avi", ".mpg", ".mov"};
                List<String> validAudioExt = new List<String> {".aac", ".wma", ".m4a", ".ogg", ".flac", ".wav", ".mp3"};
                List<String> validImageExt = new List<String> {".jpg", ".gif", ".png"};

                //Clearing previous fields
                ClearFields();

                //Is it a video file?
                if (validVideoExt.Exists(delegate(String ext) { return (ext == info.Extension); }))
                {
                    MediaVideoQualityLabel.IsEnabled    = true;
                    MediaVideoQuality.IsEnabled         = true;
                    MediaVideoQuality.Visibility        = System.Windows.Visibility.Visible;
                    MediaVideoQualityLabel.Visibility   = System.Windows.Visibility.Visible;
                    MediaVideoQuality.IsChecked         = false;
                    valid = true;
                    _mediaType = MediaType.Video;
                }
                //Is it an audio file?
                if (validAudioExt.Exists(delegate(String ext) { return (ext == info.Extension); }))
                {
                    MediaAudioType.Text                 = info.Extension;
                    MediaAudioTypeLabel.Visibility      = System.Windows.Visibility.Visible;
                    MediaAudioType.Visibility           = System.Windows.Visibility.Visible;
                    valid = true;
                    _mediaType = MediaType.Audio;
                }
                //Is it an image file?
                if (validImageExt.Exists(delegate(String ext) { return (ext == info.Extension); }))
                {
                    valid = true;
                    _mediaType = MediaType.Image;
                }
                
                //If we have a valid file, we can fill both path and size.
                if (valid)
                {
                    MediaPath.Text = ofd.FileName;
                    MediaSize.Text = info.Length.ToFileSize();
                    Submit.IsEnabled = true;
                }
                
            }
            ofd = null;
        }