From 0aee8ad04846bf6cddeb8bf3a0612cba2d4ca3c8 Mon Sep 17 00:00:00 2001 From: mgroves Date: Thu, 3 Feb 2011 07:09:03 -0500 Subject: [PATCH] working on bug 666601 --- MonoStockPortfolio.Core/AndroidSqliteBase.cs | 2 +- .../MonoStockPortfolio.Core.csproj | 7 +- .../AndroidSqlitePortfolioRepository.cs | 10 +- .../Services/PortfolioService.cs | 2 +- .../StockData/DummyStockDataProvider.cs | 14 +++ .../StockData/YahooFinanceStockData.cs | 29 ----- .../StockData/YahooStockDataProvider.cs | 105 ------------------ .../MonoStockPortfolio.Entities.csproj | 1 - MonoStockPortfolio.sln | 5 - .../Activites/ConfigActivity.cs | 2 +- .../Activites/EditPortfolioActivity.cs | 2 +- .../EditPortfolioActivity.designer.cs | 4 +- .../Activites/EditPositionActivity.cs | 2 +- .../EditPositionActivity.designer.cs | 8 +- MonoStockPortfolio/Activites/MainActivity.cs | 8 +- .../Activites/MainActivity.designer.cs | 4 +- .../Activites/PortfolioActivity.cs | 10 +- .../Activites/PortfolioActivity.designer.cs | 6 +- MonoStockPortfolio/Framework/IoCAttribute.cs | 6 +- .../Framework/ServiceLocator.cs | 58 +++++++++- MonoStockPortfolio/MonoStockPortfolio.csproj | 27 +++-- .../Resources/Resource.Designer.cs | 20 ++-- 22 files changed, 129 insertions(+), 203 deletions(-) create mode 100644 MonoStockPortfolio.Core/StockData/DummyStockDataProvider.cs delete mode 100644 MonoStockPortfolio.Core/StockData/YahooFinanceStockData.cs delete mode 100644 MonoStockPortfolio.Core/StockData/YahooStockDataProvider.cs diff --git a/MonoStockPortfolio.Core/AndroidSqliteBase.cs b/MonoStockPortfolio.Core/AndroidSqliteBase.cs index b75834e..ba939a6 100644 --- a/MonoStockPortfolio.Core/AndroidSqliteBase.cs +++ b/MonoStockPortfolio.Core/AndroidSqliteBase.cs @@ -40,7 +40,7 @@ namespace MonoStockPortfolio.Core public override void OnUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - Log.W("Upgrade", "Nothing to upgrade"); + Log.Warn("Upgrade", "Nothing to upgrade"); } } } \ No newline at end of file diff --git a/MonoStockPortfolio.Core/MonoStockPortfolio.Core.csproj b/MonoStockPortfolio.Core/MonoStockPortfolio.Core.csproj index fcad5df..83bcaf2 100644 --- a/MonoStockPortfolio.Core/MonoStockPortfolio.Core.csproj +++ b/MonoStockPortfolio.Core/MonoStockPortfolio.Core.csproj @@ -31,11 +31,7 @@ 4 - - ..\libs\FileHelpers.dll - - @@ -52,9 +48,8 @@ + - - diff --git a/MonoStockPortfolio.Core/PortfolioRepositories/AndroidSqlitePortfolioRepository.cs b/MonoStockPortfolio.Core/PortfolioRepositories/AndroidSqlitePortfolioRepository.cs index efeb042..a39a3f6 100644 --- a/MonoStockPortfolio.Core/PortfolioRepositories/AndroidSqlitePortfolioRepository.cs +++ b/MonoStockPortfolio.Core/PortfolioRepositories/AndroidSqlitePortfolioRepository.cs @@ -66,7 +66,7 @@ namespace MonoStockPortfolio.Core.PortfolioRepositories } catch (SQLiteException) { - Log.E("DeletePortfolio", "SQLiteException => Id = " + portfolioId); + Log.Error("DeletePortfolio", "SQLiteException => Id = " + portfolioId); } finally { @@ -147,23 +147,23 @@ namespace MonoStockPortfolio.Core.PortfolioRepositories private void UpdateExistingPortfolio(Portfolio portfolio) { var portfolioID = portfolio.ID ?? -1; - Log.E("UpdateExistingPortfolio", "Portfolios updated: " + Db.Update(PORTFOLIO_TABLE_NAME, GetPortfolioContentValues(portfolio), "id = " + portfolioID, null)); + Log.Error("UpdateExistingPortfolio", "Portfolios updated: " + Db.Update(PORTFOLIO_TABLE_NAME, GetPortfolioContentValues(portfolio), "id = " + portfolioID, null)); } private void InsertNewPortfolio(Portfolio portfolio) { - Log.E("InsertNewPortfolio", "Portfolios inserted: " + Db.Insert(PORTFOLIO_TABLE_NAME, null, GetPortfolioContentValues(portfolio))); + Log.Error("InsertNewPortfolio", "Portfolios inserted: " + Db.Insert(PORTFOLIO_TABLE_NAME, null, GetPortfolioContentValues(portfolio))); } private void UpdateExistingPosition(Position position) { var positionID = position.ID ?? -1; - Log.E("UpdateExistingPosition", "Positions updated: " + Db.Update(POSITION_TABLE_NAME, GetPositionContentValues(position), "id = " + positionID, null)); + Log.Error("UpdateExistingPosition", "Positions updated: " + Db.Update(POSITION_TABLE_NAME, GetPositionContentValues(position), "id = " + positionID, null)); } private void InsertNewPosition(Position position) { - Log.E("InsertNewPosition", "Positions inserted: " + Db.Insert(POSITION_TABLE_NAME, null, GetPositionContentValues(position))); + Log.Error("InsertNewPosition", "Positions inserted: " + Db.Insert(POSITION_TABLE_NAME, null, GetPositionContentValues(position))); } private static ContentValues GetPortfolioContentValues(Portfolio portfolio) diff --git a/MonoStockPortfolio.Core/Services/PortfolioService.cs b/MonoStockPortfolio.Core/Services/PortfolioService.cs index 2edd6ec..8780cfd 100644 --- a/MonoStockPortfolio.Core/Services/PortfolioService.cs +++ b/MonoStockPortfolio.Core/Services/PortfolioService.cs @@ -50,7 +50,7 @@ namespace MonoStockPortfolio.Core.Services } catch (Exception ex) { - Log.E("GetDetailedItems", ex.ToString()); + Log.Error("GetDetailedItems", ex.ToString()); throw; } } diff --git a/MonoStockPortfolio.Core/StockData/DummyStockDataProvider.cs b/MonoStockPortfolio.Core/StockData/DummyStockDataProvider.cs new file mode 100644 index 0000000..f8a2027 --- /dev/null +++ b/MonoStockPortfolio.Core/StockData/DummyStockDataProvider.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using MonoStockPortfolio.Entities; + +namespace MonoStockPortfolio.Core.StockData +{ + public class DummyStockDataProvider : IStockDataProvider + { + public IEnumerable GetStockQuotes(IEnumerable enumerable) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/MonoStockPortfolio.Core/StockData/YahooFinanceStockData.cs b/MonoStockPortfolio.Core/StockData/YahooFinanceStockData.cs deleted file mode 100644 index 16462d4..0000000 --- a/MonoStockPortfolio.Core/StockData/YahooFinanceStockData.cs +++ /dev/null @@ -1,29 +0,0 @@ -using FileHelpers; - -namespace MonoStockPortfolio.Core.StockData -{ - [DelimitedRecord(",")] - public class YahooFinanceStockData - { - [FieldQuoted(QuoteMode.OptionalForBoth)] - public string Ticker; - - public decimal LastTradePrice; - - [FieldQuoted(QuoteMode.OptionalForBoth)] - public string Name; - - public string Volume; - - public decimal Change; - - [FieldQuoted(QuoteMode.OptionalForBoth)] - public string LastTradeTime; - - [FieldQuoted(QuoteMode.OptionalForBoth)] - public string RealTimeLastTradeWithTime; - - [FieldQuoted(QuoteMode.OptionalForBoth)] - public string ChangeRealTime; - } -} \ No newline at end of file diff --git a/MonoStockPortfolio.Core/StockData/YahooStockDataProvider.cs b/MonoStockPortfolio.Core/StockData/YahooStockDataProvider.cs deleted file mode 100644 index 871c317..0000000 --- a/MonoStockPortfolio.Core/StockData/YahooStockDataProvider.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using Android.Util; -using FileHelpers; -using MonoStockPortfolio.Entities; - -namespace MonoStockPortfolio.Core.StockData -{ - public class YahooStockDataProvider : IStockDataProvider - { - private const string LAST_TRADE_PRICE_ONLY = "l1"; - private const string NAME = "n"; - private const string VOLUME = "v"; - private const string TICKER_SYMBOL = "s"; - private const string CHANGE = "c1"; - private const string LAST_TRADE_TIME = "t1"; - private const string REAL_TIME_LAST_TRADE_WITH_TIME = "k1"; - private const string REAL_TIME_CHANGE = "c6"; - - // http://www.gummy-stuff.org/Yahoo-data.htm - // http://finance.yahoo.com/d/quotes.csv?s= a BUNCH of - // STOCK SYMBOLS separated by "+" &f=a bunch of special tags - public IEnumerable GetStockQuotes(IEnumerable tickers) - { - string url = "http://finance.yahoo.com/d/quotes.csv?s="; - url += string.Join("+", tickers.ToArray()); - url += "&f="; - url += TICKER_SYMBOL; - url += LAST_TRADE_PRICE_ONLY; - url += NAME; - url += VOLUME; - url += CHANGE; - url += LAST_TRADE_TIME; - url += REAL_TIME_LAST_TRADE_WITH_TIME; - url += REAL_TIME_CHANGE; - - string resultCsv = ScrapeUrl(url); - - var yahooQuoteData = ParseCsvIntoStockQuotes(resultCsv); - - foreach (var quote in yahooQuoteData) - { - yield return MapYahooData(quote); - } - } - - private static StockQuote MapYahooData(YahooFinanceStockData data) - { - if(data == null) - { - return null; - } - var stock = new StockQuote(); - stock.Name = data.Name; - stock.LastTradePrice = data.LastTradePrice; - stock.Ticker = data.Ticker; - stock.Volume = data.Volume; - stock.Change = data.Change; - stock.LastTradeTime = data.LastTradeTime; - stock.RealTimeLastTradePrice = decimal.Parse(data.RealTimeLastTradeWithTime - .Replace("", "") - .Replace("", "") - .Replace("N/A -", "") - .Trim() - ); - stock.ChangeRealTime = data.ChangeRealTime; - return stock; - } - - private static IList ParseCsvIntoStockQuotes(string csv) - { - var engine = new FileHelperEngine(typeof(YahooFinanceStockData)); - var stockQuotes = engine.ReadString(csv) as YahooFinanceStockData[]; - if(stockQuotes == null) - { - throw new ArgumentException("Could not parse CSV input"); - } - return stockQuotes; - } - - private static string ScrapeUrl(string url) - { - try - { - string resultCsv; - var req = WebRequest.Create(url); - var resp = req.GetResponse(); - using (var sr = new StreamReader(resp.GetResponseStream())) - { - resultCsv = sr.ReadToEnd(); - sr.Close(); - } - return resultCsv; - } - catch (Exception ex) - { - Log.E("ScrapeUrlException", ex.ToString()); - throw; - } - } - } -} \ No newline at end of file diff --git a/MonoStockPortfolio.Entities/MonoStockPortfolio.Entities.csproj b/MonoStockPortfolio.Entities/MonoStockPortfolio.Entities.csproj index a64137f..a5c0882 100644 --- a/MonoStockPortfolio.Entities/MonoStockPortfolio.Entities.csproj +++ b/MonoStockPortfolio.Entities/MonoStockPortfolio.Entities.csproj @@ -31,7 +31,6 @@ 4 - diff --git a/MonoStockPortfolio.sln b/MonoStockPortfolio.sln index 8c834bf..734f6db 100644 --- a/MonoStockPortfolio.sln +++ b/MonoStockPortfolio.sln @@ -8,11 +8,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{643BA3D4-E libs\FileHelpers.dll = libs\FileHelpers.dll EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{4EE7F6AD-B8A9-4402-800E-E4C8AE0FF8FB}" - ProjectSection(SolutionItems) = preProject - assets\UInotes.txt = assets\UInotes.txt - EndProjectSection -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoStockPortfolio.Core", "MonoStockPortfolio.Core\MonoStockPortfolio.Core.csproj", "{251E7BB4-CFE2-4DE4-9E2A-AAE1AF41C8CB}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoStockPortfolio.Entities", "MonoStockPortfolio.Entities\MonoStockPortfolio.Entities.csproj", "{05A57650-3B41-46FF-9EAD-9112B5EFBEED}" diff --git a/MonoStockPortfolio/Activites/ConfigActivity.cs b/MonoStockPortfolio/Activites/ConfigActivity.cs index b3c0b01..e4b5f32 100644 --- a/MonoStockPortfolio/Activites/ConfigActivity.cs +++ b/MonoStockPortfolio/Activites/ConfigActivity.cs @@ -21,7 +21,7 @@ namespace MonoStockPortfolio.Activites { base.OnCreate(bundle); - AddPreferencesFromResource(Resource.layout.config); + AddPreferencesFromResource(Resource.Layout.config); _stockItemsConfig = StockItemPreference.BuildList(_repo.GetStockItems()).ToArray(); diff --git a/MonoStockPortfolio/Activites/EditPortfolioActivity.cs b/MonoStockPortfolio/Activites/EditPortfolioActivity.cs index 6afcf8a..cf9203c 100644 --- a/MonoStockPortfolio/Activites/EditPortfolioActivity.cs +++ b/MonoStockPortfolio/Activites/EditPortfolioActivity.cs @@ -16,7 +16,7 @@ namespace MonoStockPortfolio.Activites { base.OnCreate(bundle); - SetContentView(Resource.layout.addportfolio); + SetContentView(Resource.Layout.addportfolio); WireUpEvents(); diff --git a/MonoStockPortfolio/Activites/EditPortfolioActivity.designer.cs b/MonoStockPortfolio/Activites/EditPortfolioActivity.designer.cs index 460f96a..bc6555d 100644 --- a/MonoStockPortfolio/Activites/EditPortfolioActivity.designer.cs +++ b/MonoStockPortfolio/Activites/EditPortfolioActivity.designer.cs @@ -8,7 +8,7 @@ namespace MonoStockPortfolio.Activites public static string Extra_PortfolioID { get { return "monoStockPortfolio.EditPortfolioActivity.PortfolioID"; } } public long ThisPortfolioId { get { return Intent.GetLongExtra(Extra_PortfolioID, -1); } } - protected Button SaveButton { get { return FindViewById