public bool PlayMovie() { bool wasItgood = false; DownloadEngine downloader = new DownloadEngine(_source.MediaPath); downloader.UserAgent = OMLEngine.Trailers.AppleTrailers.QUICKTIME_USER_AGENT_STRING; downloader.Log += new DownloadEngine.DownloadEventsHandler(reportDownloadStatus); Application.DeferredInvokeOnWorkerThread(delegate { OMLApplication.Current.IsBusy = true; downloader.Download(); }, delegate { OMLApplication.Current.IsBusy = false; if (!string.IsNullOrEmpty(downloader.DownloadedFile)) { if (AddInHost.Current.MediaCenterEnvironment.PlayMedia(MediaType.Video, downloader.DownloadedFile, false)) { Utilities.DebugLine("UrlPlayer.PlayMovie: movie {0} Playing", _source); OMLApplication.Current.NowPlayingMovieName = _source.Name; OMLApplication.Current.NowPlayingStatus = PlayState.Playing; AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged -= MoviePlayerFactory.Transport_PropertyChanged; AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged += MoviePlayerFactory.Transport_PropertyChanged; AddInHost.Current.MediaCenterEnvironment.MediaExperience.GoToFullScreen(); wasItgood = true; } } }, null); return(wasItgood); }
/// Download and save to Database private void Download(DateTime date, DownloadEngine download, Formatting formatting, PeregrineOperation peregrine, MACD macd, Stochastic stochastic, TechnicalIndicators indicators, Transactions transactions, WebClient web, WebURIs uRIs, string Database) { List <string> Symbols = transactions.DatabaseSymbolListQuery(Database, stocks); transactions.TruncateStockTable(Database, "Clean Data"); // clears data from the clean data table. int count = 1; foreach (var stock in Symbols) { Console.Clear(); Console.WriteLine($"Downloading {stock} || {count} of {Symbols.Count}"); download.ToDatabase(date, formatting, peregrine, transactions, web, uRIs, stock, Database); count++; } Console.WriteLine("I'm Done"); //count = 1; //calls the list of stocks that have been data verified //List<string> CleanData = transactions.DatabaseSymbolListQuery(Database, stocks); //foreach (var stock in CleanData) //{ // Console.Clear(); // Console.WriteLine($"Doing Math {stock} || {count} of {CleanData.Count}"); // List<Results> results = MathPredictsTheFuture(download, macd, stochastic, transactions, indicators, stock); // transactions.SaveToTableResult(Database, results); // saves the calculations to the Results table in the database // count++; //} //// calls the stocks from the results list //List<PeregrineResults> todaysResults = transactions.DailyResultsQuery(peregrine.Database); //transactions.TruncateStockTable(database, peregrineresults); // clears the web results table. This table feeds the model for the ASP.Net interface. //transactions.SaveToTableWebResult(peregrine.Database, todaysResults); //Console.WriteLine("Peregrine Results Updated"); }
/// Prediction Algo via Technical Indicators public List <Results> MathPredictsTheFuture(DownloadEngine download, MACD macd, Stochastic stochastic, Transactions transactions, TechnicalIndicators indicators, string stock) { DateTime date = transactions.DatabaseDateQuery(database, stock)[0]; // 50 Day Average - queries database and calculates the 50 day average double FiftyDayAverage = indicators.FiftyDayAvg(stock, transactions); // MACD - determines if a stock is bearish or bullish. Uses 12 and 26 period exponental moving average List <MACD> todaysMACD = macd.TodaysMACD(stock, transactions); // Stochastic List <Stochastic> todayStoch = stochastic.StochasticToday(Database, stock); List <Results> results = new List <Results>() { new Results { Date = date, CIK = download.DatabaseCIKQuery(Database, stock), Symbol = stock, LastClose = transactions.CloseQuery(Database, stock), FiftyDayAvg = FiftyDayAverage, mACD = todaysMACD[0].MACDValue, MACDSignal = todaysMACD[0].MACDSignal, EMA12 = todaysMACD[0].EMA12, EMA26 = todaysMACD[0].EMA26, StochasticFast = todayStoch[0].Fast, StochasticSlow = todayStoch[0].Slow, StochasticSignal = todayStoch[0].Signal } }; return(results); }
public static ActionResult DownloadAndInstallMEncoder(Session session) { sessionObj = session; DownloadEngine meEngine = new DownloadEngine(CustomActions.MEncoderUrl); meEngine.Log += (s) => { int pct = Convert.ToInt32((Convert.ToDouble(Int32.Parse(s)) / Convert.ToDouble(meEngine.TotalBytes)) * 100); CustomActions.LogToSession(string.Format("MEncoder: {0}", pct)); }; bool meDownloaded = meEngine.Download(); if (!meDownloaded) { CustomActions.LogToSession("MEncoder Failed to download"); return(ActionResult.Failure); } CustomActions.LogToSession(string.Format("File is: {0}", meEngine.DownloadedFile)); try { File.Copy(meEngine.DownloadedFile, CustomActions.MEncoderPath, true); } catch (Exception ex) { CustomActions.LogToSession(string.Format("MEncoder Error: {0}", ex.Message)); return(ActionResult.Failure); } return(ActionResult.Success); }
public SingleDownloadForm(List <string> mirrors) { InitializeComponent(); engine = new DownloadEngine(mirrors); engine.DownloadError += Engine_DownloadError; lblSaveTo.Text = Program.Config.DefaultDownloadPath; }
public static ActionResult DownloadSQLServer(Session session) { sessionObj = session; string type = Environment.GetEnvironmentVariable(@"PROCESSOR_ARCHITECTURE"); string sqlUrl = type.ToUpperInvariant().Contains("86") ? CustomActions.SqlServerX86Url : CustomActions.SqlServer64Url; DownloadEngine sqlEngine = new DownloadEngine(sqlUrl); sqlEngine.Log += (s) => { int pct = Convert.ToInt32((Convert.ToDouble(Int32.Parse(s)) / Convert.ToDouble(sqlEngine.TotalBytes)) * 100); CustomActions.LogToSession(string.Format("SqlServer: {0}", pct)); }; bool sqlDownloaded = sqlEngine.Download(); if (!sqlDownloaded) { CustomActions.LogToSession("SqlServer Failed to download"); return(ActionResult.Failure); } CustomActions.LogToSession(string.Format("File is: {0}", sqlEngine.DownloadedFile)); session["SQLSERVERFILE"] = sqlEngine.DownloadedFile; return(ActionResult.Success); }
private void DownloadTimer(DownloadEngine download, Formatting formatting, PeregrineOperation peregrine, MACD macd, Stochastic stochastic, TechnicalIndicators indicators, Transactions transactions, WebClient web, WebURIs uRIs, string Database, string downloadTime) { var DailyTime = downloadTime; //Time when method needs to be called var timeParts = DailyTime.Split(new char[1] { ':' }); var dateNow = DateTime.Now; var date = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, int.Parse(timeParts[0]), int.Parse(timeParts[1]), int.Parse(timeParts[2])); TimeSpan ts; if (date > dateNow) { ts = date - dateNow; } else { date = date.AddDays(1); ts = date - dateNow; } while (date != dateNow) { Console.WriteLine($"Waiting for {downloadTime}"); //waits certan time and run the code Task.Delay(ts).ContinueWith((x) => Download(date, download, formatting, peregrine, macd, stochastic, indicators, transactions, web, uRIs, Database)); Console.Read(); } }
public AbstractCommand(int cuid, Request req, DownloadEngine e, Socket s = null) { this.cuid = cuid; this.req = req; checkSocketIsReadable = checkSocketIsWritable = false; this.e = e; this.socket = s; this.checkPoint = TimeSpan.Zero; }
public HttpProxyRequestCommand(int cuid, ref Request req, ref DownloadEngine e, ref Socket s) { this.cuid = cuid; this.req = req; this.e = e; this.socket = s; this.checkSocketIsWritable = true; e.deleteSocketForReadCheck(socket); e.deleteSocketForWriteCheck(socket); }
public void TestDownload() { DownloadEngine downloader = new DownloadEngine(@"http://open-media-library.googlecode.com/files/Open_Media_Library_User_Manual%280.3b%29.pdf"); downloader.Log += new DownloadEngine.DownloadEventsHandler(downloader_Log); if (downloader.Download()) { Assert.IsTrue(File.Exists(downloader.DownloadedFile)); FileInfo fi = new FileInfo(downloader.DownloadedFile); Assert.AreEqual(fi.Length, downloader.TotalBytes); } }
public static ActionResult DownloadAndInstallMediaInfo(Session session) { sessionObj = session; string type = Environment.GetEnvironmentVariable(@"PROCESSOR_ARCHITECTURE"); string miUrl = type.ToUpperInvariant().Contains("86") ? CustomActions.MediaInfoX86Url : CustomActions.MediaInfoX64Url; CustomActions.LogToSession(string.Format("MediaInfo: Selected {0} based on detected processor architecture of {1}", miUrl, Environment.GetEnvironmentVariable(@"PROCESSOR_ARCHITECTURE"))); DownloadEngine miEngine = new DownloadEngine(miUrl); miEngine.Bytes += (i) => { if (i > 0) { int pct = Convert.ToInt32((Convert.ToDouble(i) / Convert.ToDouble(miEngine.TotalBytes)) * 100); CustomActions.LogToSession(string.Format("MediaInfo: ({0}) {1}b of {2}b", pct, i, miEngine.TotalBytes)); } }; CustomActions.LogToSession("MediaInfo: Beginning download"); bool miDownloaded = false; try { miDownloaded = miEngine.Download(true); } catch (Exception ex) { CustomActions.LogToSession(string.Format("MediaInfo: Error {0}", ex.Message)); return(ActionResult.Failure); } if (!miDownloaded) { CustomActions.LogToSession("MediaInfo: Failed to download"); return(ActionResult.Failure); } CustomActions.LogToSession(string.Format("MediaInfo: Downloaded File Location {0}", miEngine.DownloadedFile)); CustomActions.LogToSession(string.Format("MediaInfo: Final destination is {0}", CustomActions.MediaInfoLocalPath)); try { CustomActions.LogToSession("MediaInfo: copying into final location"); File.Copy(miEngine.DownloadedFile, CustomActions.MediaInfoLocalPath, true); } catch (Exception ex) { CustomActions.LogToSession(string.Format("MediaInfo Error: {0}", ex.Message)); return(ActionResult.Failure); } return(ActionResult.Success); }
public void Run(string downloadTime) { DateTime date = DateTime.Now; DownloadEngine download = new DownloadEngine(); Formatting formatting = new Formatting(); PeregrineOperation peregrine = new PeregrineOperation(); MACD macd = new MACD(); Stochastic stochastic = new Stochastic(); TechnicalIndicators indicators = new TechnicalIndicators(); Transactions transactions = new Transactions(); WebClient web = new WebClient(); // provides the ability to download from the internet WebURIs uRIs = new WebURIs(); // refers to an instance of the Wall Street Journal URL DownloadTimer(download, formatting, peregrine, macd, stochastic, indicators, transactions, web, uRIs, Database, downloadTime); }
private void ProcessSingleFileUpdate(System.Version newVersion, bool updateGAC, string type, string url, string assemblyFile) { System.Version currentVersion = VersionOfAssembly(assemblyFile); if (currentVersion != null && (currentVersion < newVersion)) { DownloadEngine downloader = new DownloadEngine(url); if (downloader.Download()) { string newfile = downloader.DownloadedFile; if (updateGAC) { RemoveOldGACEntry(assemblyFile); downloader = null; } switch (type) { case "Full": break; case "Replace": File.Move(assemblyFile, assemblyFile + currentVersion); File.Move(downloader.DownloadedFile, assemblyFile); break; case "Restart": File.Move(assemblyFile, assemblyFile + currentVersion); File.Move(downloader.DownloadedFile, assemblyFile); break; default: break; } if (updateGAC) { AddNewGACEntry(assemblyFile); } } } }
public static ActionResult DownloadAndInstallUserManual(Session session) { sessionObj = session; DownloadEngine umEngine = new DownloadEngine(CustomActions.UserManualUrl); umEngine.Log += (s) => { int pct = Convert.ToInt32((Convert.ToDouble(Int32.Parse(s)) / Convert.ToDouble(umEngine.TotalBytes)) * 100); CustomActions.LogToSession(string.Format("PDF: {0}", pct)); }; bool umDownloaded = umEngine.Download(); if (!umDownloaded) { CustomActions.LogToSession("Open_Media_Library_User_Manual Failed to download"); return(ActionResult.Failure); } CustomActions.LogToSession(string.Format("File is: {0}", umEngine.DownloadedFile)); try { if (Directory.Exists(CustomActions.UserManualHelpPath)) { CustomActions.LogToSession(string.Format(@"Creating folder: {0}", CustomActions.UserManualHelpPath)); Directory.CreateDirectory(CustomActions.UserManualHelpPath); CustomActions.LogToSession("setting access controls"); // DirectoryInfo dInfo = new DirectoryInfo(CustomActions.UserManualHelpPath); // System.Security.AccessControl.DirectorySecurity dSec = dInfo.GetAccessControl(); // dSec.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule( // "Users", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow // )); // dInfo.SetAccessControl(dSec); } CustomActions.LogToSession("Copying file"); File.Copy(umEngine.DownloadedFile, CustomActions.UserManualPath, true); } catch (Exception ex) { CustomActions.LogToSession(string.Format("Open_Media_Library_User_Manual Error: {0}", ex.Message)); return(ActionResult.Failure); } return(ActionResult.Success); }
public static void Main() { var engine = new DownloadEngine(); engine.Run(); }
public static Command createInitiateConnectionCommand(int cuid, ref Request req, ref DownloadEngine e) { if (req.Protocol == "http") { return(new HttpInitiateConnectionCommand(cuid, req, e)); } else { //这个协议目前还不支持 return(null); } }
/// <summary> /// responses to various button click scenarios /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { //get the sender button Button btSender = (Button)sender; //for controller use content and others their name switch (btSender != btController ? btSender.Name : btSender.Content.ToString()) { case "btTarget": new Thread((dwnlSource) => { try { //find the file name from the url and use it SaveFileDialog selectTarget = new SaveFileDialog(); selectTarget.FileName = Download.FindFileName((string)dwnlSource); selectTarget.Title = "Select a file to save download"; string dwnlTarget = selectTarget.ShowDialog() == true ? selectTarget.FileName : ""; //set file path in application thread Application.Current.Dispatcher.Invoke(() => txtTarget.Text = dwnlTarget); } catch (Exception ex) { //show exception message MessageBox.Show(ex.Message, "Download Failed"); } }).Start(txtSource.Text); break; case "Start": //disable items on window to prevent inconsistency if (txtSource.Text.Length != 0 && txtTarget.Text.Length != 0) { //disable UI txtSource.IsEnabled = txtTarget.IsEnabled = btTarget.IsEnabled = btSender.IsEnabled = false; //get the source and target url string dwnlSource = txtSource.Text; string dwnlTarget = txtTarget.Text; new Thread(() => { try { //create a new download job download = new Download(dwnlSource, dwnlTarget); //run the rest in application thread Application.Current.Dispatcher.Invoke(() => { //stop the download tracker and engine if they exist if (downloadTracker != null) { downloadTracker.Stop(); } if (downloadEngine != null) { downloadEngine.Abort().Join(); } //create the tracker, engine downloadTracker = new DispatcherTimer(); downloadTracker.Interval = TimeSpan.FromSeconds(1); downloadTracker.Tick += Tracker; downloadTracker.Start(); //create the engine downloadEngine = new DownloadEngine(download, downloadTracker); downloadEngine.Start(); }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Download Failed"); //reset the UI in application thread Application.Current.Dispatcher.Invoke(() => ResetUI()); } }).Start(); } else { MessageBox.Show("Need Download source and target path", "Incomplete Data"); } break; case "Pause": downloadEngine.Abort(); break; case "Resume": downloadEngine.Start(); break; } }
public HttpInitiateConnectionCommand(int cuid, ref Request req, ref DownloadEngine e) { this.cuid = cuid; this.req = req; this.e = e; }
public DownloadCommand(int cuid, Request req, DownloadEngine e, Socket s) : base(cuid, req, e, s) { }