Skip to content

Commit

Permalink
Windows/WindowsPhone/WindowsStore: Updated projects after changes on …
Browse files Browse the repository at this point in the history
…other platforms.
  • Loading branch information
ycastonguay committed Sep 28, 2013
1 parent 84bc0eb commit e0d136a
Show file tree
Hide file tree
Showing 21 changed files with 382 additions and 82 deletions.
1 change: 1 addition & 0 deletions MPfm/MPfm.Core/MPfm.Core.WindowsStore.csproj
Expand Up @@ -107,6 +107,7 @@
<Compile Include="ByteArrayQueue.cs" />
<Compile Include="CacheStore.cs" />
<Compile Include="Conversion.cs" />
<Compile Include="DatabaseFieldMap.cs" />
<Compile Include="DatabaseFieldNameAttribute.cs" />
<Compile Include="Normalizer.cs" />
<Compile Include="OS.cs" />
Expand Down
153 changes: 99 additions & 54 deletions MPfm/MPfm.Library/Database/SQLiteGateway.cs
Expand Up @@ -100,15 +100,41 @@ public DbConnection GenerateConnection()
return connection;
}

///// <summary>
///// Returns the list of properties which have different database field names.
///// </summary>
///// <typeparam name="T">Object to scan (generic)</typeparam>
///// <returns>List of DatabaseFieldMap</returns>
//public List<DatabaseFieldMap> GetMap<T>()
//{
// // Create map by scanning properties
// List<DatabaseFieldMap> maps = new List<DatabaseFieldMap>();
// PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
// foreach (PropertyInfo propertyInfo in propertyInfos)
// {
// // Scan attributes
// object[] attributes = propertyInfo.GetCustomAttributes(true);
// foreach (object attribute in attributes)
// {
// // Try to cast into attribute map
// DatabaseFieldAttribute attrMap = attribute as DatabaseFieldAttribute;
// if (attrMap != null)
// maps.Add(new DatabaseFieldMap(propertyInfo.Name, attrMap.DatabaseFieldName, attrMap.SaveToDatabase));
// }
// }

// return maps;
//}

/// <summary>
/// Returns the list of properties which have different database field names.
/// </summary>
/// <typeparam name="T">Object to scan (generic)</typeparam>
/// <returns>Dictionary of DatabaseFieldName/PropertyName</returns>
public Dictionary<string, string> GetMap<T>()
/// <returns>List of DatabaseFieldMap</returns>
public List<DatabaseFieldMap> GetMap<T>()
{
// Create map by scanning properties
Dictionary<string, string> dictMap = new Dictionary<string, string>();
List<DatabaseFieldMap> maps = new List<DatabaseFieldMap>();
PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo propertyInfo in propertyInfos)
{
Expand All @@ -119,14 +145,11 @@ public DbConnection GenerateConnection()
// Try to cast into attribute map
DatabaseFieldAttribute attrMap = attribute as DatabaseFieldAttribute;
if (attrMap != null)
{
// Add item to dictionary
dictMap.Add(attrMap.DatabaseFieldName, propertyInfo.Name);
}
maps.Add(new DatabaseFieldMap(propertyInfo.Name, attrMap.DatabaseFieldName, attrMap.SaveToDatabase));
}
}

return dictMap;
return maps;
}

/// <summary>
Expand Down Expand Up @@ -412,7 +435,7 @@ public List<T> Select<T>(string sql) where T : new()
DbDataReader reader = null;
DbCommand command = null;
List<T> list = new List<T>();
Dictionary<string, string> dictMap = GetMap<T>();
var maps = GetMap<T>();

try
{
Expand Down Expand Up @@ -441,11 +464,10 @@ public List<T> Select<T>(string sql) where T : new()
object fieldValue = reader.GetValue(a);

// Check for map
string propertyName = fieldName;
if(dictMap.ContainsKey(fieldName))
{
propertyName = dictMap[fieldName];
}
string propertyName = fieldName;
var map = maps.FirstOrDefault(x => x.FieldName == fieldName);
if (map != null)
propertyName = map.PropertyName;

// Get property info and fill column if valid
PropertyInfo info = typeof(T).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty);
Expand Down Expand Up @@ -540,7 +562,7 @@ public int Update<T>(T obj, string tableName, Dictionary<string, object> where)
// Declare variables
DbConnection connection = null;
DbCommand command = null;
Dictionary<string, string> dictMap = GetMap<T>();
var maps = GetMap<T>();
StringBuilder sql = new StringBuilder();

try
Expand All @@ -556,21 +578,29 @@ public int Update<T>(T obj, string tableName, Dictionary<string, object> where)
PropertyInfo propertyInfo = propertyInfos[a];
if (propertyInfo.GetSetMethod() != null)
{
string fieldName = propertyInfo.Name;
if (dictMap.ContainsValue(propertyInfo.Name))
fieldName = dictMap.FindKeyByValue<string, string>(propertyInfo.Name);

// Add comma if an item was added previously
if(!addedOneItem)
addedOneItem = true;
else
sql.Append(", ");

// Add database field name
sql.Append("[" + fieldName + "]=");
object value = propertyInfo.GetValue(obj, null);
sql.Append(FormatSQLValue(value));
sql.Append("\n");
bool saveToDatabase = true;
string fieldName = propertyInfo.Name;
var map = maps.FirstOrDefault(x => x.PropertyName == propertyInfo.Name);
if (map != null)
{
fieldName = map.FieldName;
saveToDatabase = map.SaveToDatabase;
}

if (saveToDatabase)
{
// Add comma if an item was added previously
if (!addedOneItem)
addedOneItem = true;
else
sql.Append(", ");

// Add database field name
sql.Append("[" + fieldName + "]=");
object value = propertyInfo.GetValue(obj, null);
sql.Append(FormatSQLValue(value));
sql.Append("\n");
}
}
}

Expand Down Expand Up @@ -640,7 +670,7 @@ public int Insert<T>(T obj, string tableName)
// Declare variables
DbConnection connection = null;
DbCommand command = null;
Dictionary<string, string> dictMap = GetMap<T>();
var maps = GetMap<T>();
StringBuilder sql = new StringBuilder();

try
Expand All @@ -656,18 +686,27 @@ public int Insert<T>(T obj, string tableName)
PropertyInfo propertyInfo = propertyInfos[a];
if (propertyInfo.GetSetMethod() != null)
{
// Check mapping
bool saveToDatabase = true;
string fieldName = propertyInfo.Name;
if (dictMap.ContainsValue(propertyInfo.Name))
fieldName = dictMap.FindKeyByValue<string, string>(propertyInfo.Name);

// Add comma if an item was added previously
if(!addedOneItem)
addedOneItem = true;
else
sql.Append(", ");
var map = maps.FirstOrDefault(x => x.PropertyName == propertyInfo.Name);
if (map != null)
{
fieldName = map.FieldName;
saveToDatabase = map.SaveToDatabase;
}

sql.Append("[" + fieldName + "]");
sql.Append("\n");
if (saveToDatabase)
{
// Add comma if an item was added previously
if (!addedOneItem)
addedOneItem = true;
else
sql.Append(", ");

sql.Append("[" + fieldName + "]");
sql.Append("\n");
}
}
}
sql.AppendLine(") VALUES (");
Expand All @@ -679,20 +718,26 @@ public int Insert<T>(T obj, string tableName)
PropertyInfo propertyInfo = propertyInfos[a];
if (propertyInfo.GetSetMethod() != null)
{
// Check mapping
bool saveToDatabase = true;
string fieldName = propertyInfo.Name;
if (dictMap.ContainsValue(propertyInfo.Name))
fieldName = dictMap.FindKeyByValue<string, string>(propertyInfo.Name);

// Add comma if an item was added previously
if(!addedOneItem)
addedOneItem = true;
else
sql.Append(", ");

// Get value and determine how to add field value
object value = propertyInfo.GetValue(obj, null);
sql.Append(FormatSQLValue(value));
sql.Append("\n");
var map = maps.FirstOrDefault(x => x.PropertyName == propertyInfo.Name);
if (map != null)
saveToDatabase = map.SaveToDatabase;

if (saveToDatabase)
{
// Add comma if an item was added previously
if (!addedOneItem)
addedOneItem = true;
else
sql.Append(", ");

// Get value and determine how to add field value
object value = propertyInfo.GetValue(obj, null);
sql.Append(FormatSQLValue(value));
sql.Append("\n");
}
}
}
sql.AppendLine(") ");
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.Library/MPfm.Library.WindowsStore.csproj
Expand Up @@ -127,6 +127,7 @@
<Compile Include="Database\Interfaces\ISQLiteGateway.cs" />
<Compile Include="Database\DatabaseFacade.cs" />
<Compile Include="Objects\NetworkState.cs" />
<Compile Include="Objects\PlaylistAudioFile.cs" />
<Compile Include="Objects\PlaylistFile.cs" />
<Compile Include="Objects\History.cs" />
<Compile Include="Objects\Setting.cs" />
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.Library/MPfm.Library.csproj
Expand Up @@ -103,6 +103,7 @@
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Scripts\1.05-1.06.sql" />
<EmbeddedResource Include="Scripts\1.03-1.04.sql" />
<EmbeddedResource Include="Scripts\1.02-1.03.sql" />
<EmbeddedResource Include="Scripts\1.01-1.02.sql" />
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.Library/Services/LibraryService.cs
Expand Up @@ -119,7 +119,7 @@ public void RemoveAudioFilesWithBrokenFilePaths()
var task = ApplicationData.Current.LocalFolder.FileExistsAsync(files[a].FilePath);
bool exists = task.Result; // Blocks the thread until the value is returned
if(exists)
gateway.DeleteAudioFile(files[a].Id);
_gateway.DeleteAudioFile(files[a].Id);
#else
if (!File.Exists(files[a].FilePath))
_gateway.DeleteAudioFile(files[a].Id);
Expand Down
12 changes: 12 additions & 0 deletions MPfm/MPfm.MVP/MPfm.MVP.WindowsStore.csproj
Expand Up @@ -103,8 +103,16 @@
<Compile Include="Messages\ConnectionStatusChangedMessage.cs" />
<Compile Include="Messages\MobileLibraryBrowserItemClickedMessage.cs" />
<Compile Include="Messages\PlayerSetPositionMessage.cs" />
<Compile Include="Messages\PlaylistListUpdatedMessage.cs" />
<Compile Include="Messages\PlaylistUpdatedMessage.cs" />
<Compile Include="Models\PlaylistEntity.cs" />
<Compile Include="Navigation\MobileNavigationManager.cs" />
<Compile Include="Presenters\AddMarkerPresenter.cs" />
<Compile Include="Presenters\AddPlaylistPresenter.cs" />
<Compile Include="Presenters\AudioPreferencesPresenter.cs" />
<Compile Include="Presenters\Interfaces\IAddMarkerPresenter.cs" />
<Compile Include="Presenters\Interfaces\IAddPlaylistPresenter.cs" />
<Compile Include="Presenters\Interfaces\ISelectPlaylistPresenter.cs" />
<Compile Include="Presenters\MobileFirstRunPresenter.cs" />
<Compile Include="Presenters\DesktopFirstRunPresenter.cs" />
<Compile Include="Presenters\EditSongMetadataPresenter.cs" />
Expand All @@ -118,8 +126,11 @@
<Compile Include="Presenters\LibraryPreferencesPresenter.cs" />
<Compile Include="Presenters\Interfaces\ILibraryPreferencesPresenter.cs" />
<Compile Include="Presenters\Interfaces\IAudioPreferencesPresenter.cs" />
<Compile Include="Presenters\SelectPlaylistPresenter.cs" />
<Compile Include="Presenters\UpdateLibraryPresenter.cs" />
<Compile Include="Models\PlayerPositionEntity.cs" />
<Compile Include="Views\IAddMarkerView.cs" />
<Compile Include="Views\IAddPlaylistView.cs" />
<Compile Include="Views\IMobileFirstRunView.cs" />
<Compile Include="Views\IDesktopFirstRunView.cs" />
<Compile Include="Views\IEditSongMetadataView.cs" />
Expand All @@ -128,6 +139,7 @@
<Compile Include="Views\ILibraryPreferencesView.cs" />
<Compile Include="Views\IGeneralPreferencesView.cs" />
<Compile Include="Views\IAudioPreferencesView.cs" />
<Compile Include="Views\ISelectPlaylistView.cs" />
<Compile Include="Views\IUpdateLibraryView.cs" />
<Compile Include="Bootstrap\Bootstrapper.cs" />
<Compile Include="Presenters\PlayerPresenter.cs" />
Expand Down
9 changes: 6 additions & 3 deletions MPfm/MPfm.MVP/MPfm.MVP.csproj
Expand Up @@ -120,9 +120,11 @@
<Compile Include="Messages\MobileLibraryBrowserItemClickedMessage.cs" />
<Compile Include="Models\PlaylistEntity.cs" />
<Compile Include="Navigation\MobileNavigationManager.cs" />
<Compile Include="Presenters\AddMarkerPresenter.cs" />
<Compile Include="Presenters\AddPlaylistPresenter.cs" />
<Compile Include="Presenters\AudioPreferencesPresenter.cs" />
<Compile Include="Presenters\AddNewPlaylistPresenter.cs" />
<Compile Include="Presenters\Interfaces\IAddNewPlaylistPresenter.cs" />
<Compile Include="Presenters\Interfaces\IAddMarkerPresenter.cs" />
<Compile Include="Presenters\Interfaces\IAddPlaylistPresenter.cs" />
<Compile Include="Presenters\Interfaces\ISelectPlaylistPresenter.cs" />
<Compile Include="Presenters\SelectPlaylistPresenter.cs" />
<Compile Include="Presenters\MobileFirstRunPresenter.cs" />
Expand All @@ -140,7 +142,8 @@
<Compile Include="Presenters\Interfaces\IAudioPreferencesPresenter.cs" />
<Compile Include="Presenters\UpdateLibraryPresenter.cs" />
<Compile Include="Models\PlayerPositionEntity.cs" />
<Compile Include="Views\IAddNewPlaylistView.cs" />
<Compile Include="Views\IAddMarkerView.cs" />
<Compile Include="Views\IAddPlaylistView.cs" />
<Compile Include="Views\ISelectPlaylistView.cs" />
<Compile Include="Views\IMobileFirstRunView.cs" />
<Compile Include="Views\IDesktopFirstRunView.cs" />
Expand Down
5 changes: 5 additions & 0 deletions MPfm/MPfm.MVP/Services/PlayerService.cs
Expand Up @@ -140,6 +140,7 @@ public void PlayerCommandMessageReceived(PlayerCommandMessage m)
/// <returns>Tuple of 32-bit integers (left/right)</returns>
public Tuple<short[], short[]> GetMixerData(double seconds)
{
#if !WINDOWSSTORE && !WINDOWS_PHONE
int maxL = 0;
int maxR = 0;

Expand Down Expand Up @@ -180,6 +181,10 @@ public void PlayerCommandMessageReceived(PlayerCommandMessage m)
// }

return new Tuple<short[], short[]>(left, right);
#else
return new Tuple<short[], short[]>(new short[1], new short[1]);
#endif

}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions MPfm/MPfm.Player/WinRT/Player.cs
Expand Up @@ -36,6 +36,7 @@ public class Player : IPlayer
public bool IsEQEnabled { get; private set; }
public bool IsPaused { get; private set; }
public bool IsPlaying { get; private set; }
public bool UseFloatingPoint { get; set; }
public int MixerSampleRate { get; private set; }
public Playlist Playlist { get; private set; }
public RepeatType RepeatType { get; set; }
Expand Down Expand Up @@ -123,6 +124,11 @@ public int GetMixerData(int length, float[] sampleData)
return 0;
}

public int GetMixerData(int length, int[] sampleData)
{
return 0;
}

public long GetPosition()
{
return 0;
Expand Down
5 changes: 3 additions & 2 deletions MPfm/MPfm.Windows/Classes/Forms/frmMain.cs
Expand Up @@ -1483,7 +1483,7 @@ private void waveFormMarkersLoops_OnPositionChanged(PositionChangedData data)
/// <param name="e">Event arguments</param>
private void btnAddMarker_Click(object sender, EventArgs e)
{
OnAddMarker(MarkerTemplateNameType.None);
OnAddMarkerWithTemplate(MarkerTemplateNameType.None);
}

/// <summary>
Expand Down Expand Up @@ -2303,7 +2303,8 @@ public void RefreshPlayerTimeShifting(PlayerTimeShiftingEntity entity)

#region IMarkersView implementation

public Action<MarkerTemplateNameType> OnAddMarker { get; set; }
public Action OnAddMarker { get; set; }
public Action<MarkerTemplateNameType> OnAddMarkerWithTemplate { get; set; }
public Action<Marker> OnEditMarker { get; set; }
public Action<Marker> OnSelectMarker { get; set; }
public Action<Marker> OnDeleteMarker { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion MPfm/MPfm.WindowsStore/App.xaml.cs
Expand Up @@ -21,6 +21,7 @@
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;
using MPfm.WindowsStore.Classes;
using MPfm.WindowsStore.Classes.Pages;
using MPfm.WindowsStore.Common;

using System;
Expand Down Expand Up @@ -108,7 +109,8 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
// parameter
Debug.WriteLine("RootFrame.Content == null; trying to navigate to ItemsPage");
//if (!rootFrame.Navigate(typeof(ItemsPage), "AllGroups"))
if(!rootFrame.Navigate(typeof(Main), args.Arguments))
//if(!rootFrame.Navigate(typeof(TestPage), args.Arguments))
if(!rootFrame.Navigate(typeof(Main), "AllGroups"))
{
throw new Exception("Failed to create initial page");
}
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit e0d136a

Please sign in to comment.