mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-08 17:24:42 -05:00
Update to EF6
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Common.Debug;
|
||||
using Common.Debug;
|
||||
using Common.Internet;
|
||||
using FeedCenter.Properties;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
|
||||
27
Category.cs
Normal file
27
Category.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated from a template.
|
||||
//
|
||||
// Manual changes to this file may cause unexpected behavior in your application.
|
||||
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class Category
|
||||
{
|
||||
public Category()
|
||||
{
|
||||
this.Feeds = new HashSet<Feed>();
|
||||
}
|
||||
|
||||
public System.Guid ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual ICollection<Feed> Feeds { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using Common.Debug;
|
||||
using FeedCenter.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlServerCe;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Common.Debug;
|
||||
|
||||
using FeedCenter.Properties;
|
||||
|
||||
namespace FeedCenter.Data
|
||||
{
|
||||
public static class Database
|
||||
@@ -45,10 +43,10 @@ namespace FeedCenter.Data
|
||||
try
|
||||
{
|
||||
// Open the database file
|
||||
using (FileStream stream = new FileStream(databasePath, FileMode.Open, FileAccess.Read))
|
||||
using (var stream = new FileStream(databasePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
// Read the file using the binary reader
|
||||
BinaryReader reader = new BinaryReader(stream);
|
||||
var reader = new BinaryReader(stream);
|
||||
|
||||
// Seek to the version signature
|
||||
stream.Seek(16, SeekOrigin.Begin);
|
||||
@@ -81,7 +79,7 @@ namespace FeedCenter.Data
|
||||
Tracer.WriteLine("Creating database engine");
|
||||
|
||||
// Create the database engine
|
||||
using (SqlCeEngine engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath)))
|
||||
using (var engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath)))
|
||||
{
|
||||
Tracer.WriteLine("Creating database");
|
||||
|
||||
@@ -95,20 +93,20 @@ namespace FeedCenter.Data
|
||||
}
|
||||
}
|
||||
|
||||
private static int getVersion(SqlCeConnection connection)
|
||||
private static int GetVersion(SqlCeConnection connection)
|
||||
{
|
||||
string versionString = string.Empty;
|
||||
string versionString;
|
||||
|
||||
try
|
||||
{
|
||||
// Check the database version table
|
||||
using (SqlCeCommand command = new SqlCeCommand("SELECT Value FROM DatabaseVersion", connection))
|
||||
using (var command = new SqlCeCommand("SELECT Value FROM DatabaseVersion", connection))
|
||||
versionString = command.ExecuteScalar().ToString();
|
||||
}
|
||||
catch (SqlCeException)
|
||||
{
|
||||
// Check the setting table for the version
|
||||
using (SqlCeCommand command = new SqlCeCommand("SELECT Value FROM Setting WHERE Name = 'DatabaseVersion'", connection))
|
||||
using (var command = new SqlCeCommand("SELECT Value FROM Setting WHERE Name = 'DatabaseVersion'", connection))
|
||||
versionString = command.ExecuteScalar().ToString();
|
||||
}
|
||||
|
||||
@@ -125,7 +123,7 @@ namespace FeedCenter.Data
|
||||
Tracer.WriteLine("Getting database file version");
|
||||
|
||||
// Get the database file version
|
||||
SqlServerCeFileVersion fileVersion = GetFileVersion(DatabasePath);
|
||||
var fileVersion = GetFileVersion(DatabasePath);
|
||||
|
||||
Tracer.WriteLine("Database file version: {0}", fileVersion);
|
||||
|
||||
@@ -135,7 +133,7 @@ namespace FeedCenter.Data
|
||||
Tracer.WriteLine("Creating database engine");
|
||||
|
||||
// Create the database engine
|
||||
using (SqlCeEngine engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath)))
|
||||
using (var engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath)))
|
||||
{
|
||||
Tracer.WriteLine("Upgrading database");
|
||||
|
||||
@@ -147,13 +145,13 @@ namespace FeedCenter.Data
|
||||
Tracer.WriteLine("Getting database version");
|
||||
|
||||
// Create a database connection
|
||||
using (SqlCeConnection connection = new SqlCeConnection(string.Format("Data Source={0}", DatabasePath)))
|
||||
using (var connection = new SqlCeConnection(string.Format("Data Source={0}", DatabasePath)))
|
||||
{
|
||||
// Open the connection
|
||||
connection.Open();
|
||||
|
||||
// Get the database version
|
||||
int databaseVersion = getVersion(connection);
|
||||
var databaseVersion = GetVersion(connection);
|
||||
|
||||
// Create a dictionary of database upgrade scripts and their version numbers
|
||||
var scriptList = new Dictionary<int, string>();
|
||||
@@ -162,10 +160,10 @@ namespace FeedCenter.Data
|
||||
foreach (var property in typeof(Resources).GetProperties().Where(property => property.Name.StartsWith("DatabaseUpdate")))
|
||||
{
|
||||
// Get the name of the property
|
||||
string propertyName = property.Name;
|
||||
var propertyName = property.Name;
|
||||
|
||||
// Extract the version from the name
|
||||
int version = int.Parse(propertyName.Substring(propertyName.IndexOf("_", StringComparison.Ordinal) + 1));
|
||||
var version = int.Parse(propertyName.Substring(propertyName.IndexOf("_", StringComparison.Ordinal) + 1));
|
||||
|
||||
// Add to the script list
|
||||
scriptList[version] = propertyName;
|
||||
@@ -178,7 +176,7 @@ namespace FeedCenter.Data
|
||||
if (databaseVersion <= pair.Key)
|
||||
{
|
||||
// Get the script text
|
||||
string scriptText = Resources.ResourceManager.GetString(pair.Value);
|
||||
var scriptText = Resources.ResourceManager.GetString(pair.Value);
|
||||
|
||||
// Run the script
|
||||
ExecuteScript(scriptText);
|
||||
@@ -192,7 +190,7 @@ namespace FeedCenter.Data
|
||||
Tracer.WriteLine("Creating database engine");
|
||||
|
||||
// Create the database engine
|
||||
using (SqlCeEngine engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath)))
|
||||
using (var engine = new SqlCeEngine(string.Format("Data Source={0}", DatabasePath)))
|
||||
{
|
||||
Tracer.WriteLine("Shrinking database");
|
||||
|
||||
@@ -204,22 +202,22 @@ namespace FeedCenter.Data
|
||||
private static void ExecuteScript(string scriptText)
|
||||
{
|
||||
// Create a database connection
|
||||
using (SqlCeConnection connection = new SqlCeConnection(string.Format("Data Source={0}", DatabasePath)))
|
||||
using (var connection = new SqlCeConnection(string.Format("Data Source={0}", DatabasePath)))
|
||||
{
|
||||
// Open the connection
|
||||
connection.Open();
|
||||
|
||||
// Setup the delimiters
|
||||
string[] delimiters = new[] { "\r\nGO\r\n" };
|
||||
var delimiters = new[] { "\r\nGO\r\n" };
|
||||
|
||||
// Split the script at the delimiters
|
||||
string[] statements = scriptText.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
|
||||
var statements = scriptText.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// Loop over each statement in the script
|
||||
foreach (string statement in statements)
|
||||
foreach (var statement in statements)
|
||||
{
|
||||
// Execute the statement
|
||||
using (SqlCeCommand command = new SqlCeCommand(statement, connection))
|
||||
using (var command = new SqlCeCommand(statement, connection))
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace FeedCenter.Data
|
||||
return null;
|
||||
|
||||
// Get the first table
|
||||
DataTable firstTable = dataSet.Tables[0];
|
||||
var firstTable = dataSet.Tables[0];
|
||||
|
||||
// If the table has no rows then return nothing
|
||||
if (firstTable.Rows.Count == 0)
|
||||
@@ -43,13 +43,13 @@ namespace FeedCenter.Data
|
||||
public static void SetStatement(this SqlCeCommand command, string statement, params object[] parameters)
|
||||
{
|
||||
// Create a new array to hold the updated parameters
|
||||
object[] formattedParameters = new object[parameters.Length];
|
||||
var formattedParameters = new object[parameters.Length];
|
||||
|
||||
// Initialize our position
|
||||
int position = 0;
|
||||
var position = 0;
|
||||
|
||||
// Loop over each parameter
|
||||
foreach (object parameter in parameters)
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
// If the parameter is a DateTime then we need to reformat
|
||||
if (parameter == null)
|
||||
@@ -60,10 +60,10 @@ namespace FeedCenter.Data
|
||||
else if (parameter is DateTime)
|
||||
{
|
||||
// Cast the parameter back to a DateTime
|
||||
DateTime dateTime = (DateTime) parameter;
|
||||
var dateTime = (DateTime) parameter;
|
||||
|
||||
// Convert the DateTime to sortable format
|
||||
string formatted = dateTime.ToString("s");
|
||||
var formatted = dateTime.ToString("s");
|
||||
|
||||
// Set into the formatted array
|
||||
formattedParameters[position++] = formatted;
|
||||
@@ -101,7 +101,7 @@ namespace FeedCenter.Data
|
||||
public static void ExecuteNonQuery(this SqlCeConnection connection, string query, params object[] parameters)
|
||||
{
|
||||
// Create the command object
|
||||
SqlCeCommand command = connection.CreateCommand();
|
||||
var command = connection.CreateCommand();
|
||||
|
||||
// Set the statement based on the query and parameters
|
||||
command.SetStatement(query, parameters);
|
||||
@@ -115,16 +115,16 @@ namespace FeedCenter.Data
|
||||
public static DataSet ExecuteDataSet(this SqlCeConnection connection, string query, params object[] parameters)
|
||||
{
|
||||
// Create the command object
|
||||
SqlCeCommand command = connection.CreateCommand();
|
||||
var command = connection.CreateCommand();
|
||||
|
||||
// Set the statement based on the query and parameters
|
||||
command.SetStatement(query, parameters);
|
||||
|
||||
// Create a new data adapter
|
||||
using (SqlCeDataAdapter adapter = new SqlCeDataAdapter(command))
|
||||
using (var adapter = new SqlCeDataAdapter(command))
|
||||
{
|
||||
// Create the new data set
|
||||
using (DataSet dataSet = new DataSet())
|
||||
using (var dataSet = new DataSet())
|
||||
{
|
||||
//Tracer.WriteLine("Executing SQL query: {0}", command.CommandText);
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace FeedCenter.Data
|
||||
public static object ExecuteScalar(this SqlCeConnection connection, string query, params object[] parameters)
|
||||
{
|
||||
// Create the command object
|
||||
SqlCeCommand command = connection.CreateCommand();
|
||||
var command = connection.CreateCommand();
|
||||
|
||||
// Set the statement based on the query and parameters
|
||||
command.SetStatement(query, parameters);
|
||||
|
||||
22
Entities.cs
22
Entities.cs
@@ -1,5 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
@@ -11,7 +12,8 @@ namespace FeedCenter
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
ObjectStateManager.ObjectStateManagerChanged -= HandleObjectStateManagerObjectStateManagerChanged;
|
||||
var manager = ((IObjectContextAdapter) this).ObjectContext.ObjectStateManager;
|
||||
manager.ObjectStateManagerChanged -= HandleObjectStateManagerObjectStateManagerChanged;
|
||||
_hookedStateManager = false;
|
||||
}
|
||||
|
||||
@@ -36,7 +38,8 @@ namespace FeedCenter
|
||||
|
||||
if (!_hookedStateManager)
|
||||
{
|
||||
ObjectStateManager.ObjectStateManagerChanged += HandleObjectStateManagerObjectStateManagerChanged;
|
||||
var manager = ((IObjectContextAdapter) this).ObjectContext.ObjectStateManager;
|
||||
manager.ObjectStateManagerChanged += HandleObjectStateManagerObjectStateManagerChanged;
|
||||
_hookedStateManager = true;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +64,8 @@ namespace FeedCenter
|
||||
|
||||
if (!_hookedStateManager)
|
||||
{
|
||||
ObjectStateManager.ObjectStateManagerChanged += HandleObjectStateManagerObjectStateManagerChanged;
|
||||
var manager = ((IObjectContextAdapter) this).ObjectContext.ObjectStateManager;
|
||||
manager.ObjectStateManagerChanged += HandleObjectStateManagerObjectStateManagerChanged;
|
||||
_hookedStateManager = true;
|
||||
}
|
||||
}
|
||||
@@ -80,8 +84,8 @@ namespace FeedCenter
|
||||
{
|
||||
if (_allCategories == null)
|
||||
return;
|
||||
|
||||
Category category = e.Element as Category;
|
||||
|
||||
var category = e.Element as Category;
|
||||
|
||||
switch (e.Action)
|
||||
{
|
||||
@@ -93,7 +97,7 @@ namespace FeedCenter
|
||||
break;
|
||||
case CollectionChangeAction.Refresh:
|
||||
_allCategories.Clear();
|
||||
foreach (Category loopCategory in Categories)
|
||||
foreach (var loopCategory in Categories)
|
||||
_allCategories.Add(loopCategory);
|
||||
break;
|
||||
}
|
||||
@@ -103,7 +107,7 @@ namespace FeedCenter
|
||||
if (_allFeeds == null)
|
||||
return;
|
||||
|
||||
Feed feed = e.Element as Feed;
|
||||
var feed = e.Element as Feed;
|
||||
|
||||
switch (e.Action)
|
||||
{
|
||||
@@ -115,10 +119,10 @@ namespace FeedCenter
|
||||
break;
|
||||
case CollectionChangeAction.Refresh:
|
||||
_allFeeds.Clear();
|
||||
foreach (Feed loopfeed in Feeds)
|
||||
foreach (var loopfeed in Feeds)
|
||||
_allFeeds.Add(loopfeed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
59
Feed.cs
Normal file
59
Feed.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated from a template.
|
||||
//
|
||||
// Manual changes to this file may cause unexpected behavior in your application.
|
||||
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class Feed
|
||||
{
|
||||
public Feed()
|
||||
{
|
||||
this.Name = "";
|
||||
this.Title = "";
|
||||
this.Source = "";
|
||||
this.Link = "";
|
||||
this.Description = "";
|
||||
this.LastChecked = new DateTime(599266080000000000, DateTimeKind.Unspecified);
|
||||
this.CheckInterval = 60;
|
||||
this.Enabled = true;
|
||||
this.Authenticate = false;
|
||||
this.Username = "";
|
||||
this.Password = "";
|
||||
this.Domain = "";
|
||||
this.LastUpdated = new DateTime(599266080000000000, DateTimeKind.Unspecified);
|
||||
this.Actions = new HashSet<FeedAction>();
|
||||
this.Items = new HashSet<FeedItem>();
|
||||
}
|
||||
|
||||
public System.Guid ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Source { get; set; }
|
||||
public string Link { get; set; }
|
||||
public string Description { get; set; }
|
||||
public System.DateTime LastChecked { get; set; }
|
||||
public int CheckInterval { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public bool Authenticate { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Domain { get; set; }
|
||||
public FeedCenter.FeedReadResult LastReadResult { get; set; }
|
||||
public System.DateTime LastUpdated { get; set; }
|
||||
public FeedCenter.FeedItemComparison ItemComparison { get; set; }
|
||||
public System.Guid CategoryID { get; set; }
|
||||
public FeedCenter.MultipleOpenAction MultipleOpenAction { get; set; }
|
||||
|
||||
public virtual Category Category { get; set; }
|
||||
public virtual ICollection<FeedAction> Actions { get; set; }
|
||||
public virtual ICollection<FeedItem> Items { get; set; }
|
||||
}
|
||||
}
|
||||
26
FeedAction.cs
Normal file
26
FeedAction.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated from a template.
|
||||
//
|
||||
// Manual changes to this file may cause unexpected behavior in your application.
|
||||
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class FeedAction
|
||||
{
|
||||
public System.Guid ID { get; set; }
|
||||
public System.Guid FeedID { get; set; }
|
||||
public int Field { get; set; }
|
||||
public string Search { get; set; }
|
||||
public string Replace { get; set; }
|
||||
public int Sequence { get; set; }
|
||||
|
||||
public virtual Feed Feed { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -132,17 +132,26 @@
|
||||
<Reference Include="Common.Wpf.MarkupExtensions">
|
||||
<HintPath>..\Common.Wpf.MarkupExtensions\bin\Release\Common.Wpf.MarkupExtensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework">
|
||||
<HintPath>packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer">
|
||||
<HintPath>packages\EntityFramework.6.1.1\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServerCompact">
|
||||
<HintPath>packages\EntityFramework.SqlServerCompact.6.1.1\lib\net45\EntityFramework.SqlServerCompact.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.Entity" />
|
||||
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>bin\Debug\System.Data.SqlServerCe.dll</HintPath>
|
||||
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>packages\Microsoft.SqlServer.Compact.4.0.8854.1\lib\net40\System.Data.SqlServerCe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>bin\Debug\System.Data.SqlServerCe.Entity.dll</HintPath>
|
||||
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>packages\Microsoft.SqlServer.Compact.4.0.8854.1\lib\net40\System.Data.SqlServerCe.Entity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
@@ -168,12 +177,34 @@
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="BrowserCommon.cs" />
|
||||
<Compile Include="Category.cs">
|
||||
<DependentUpon>Model.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Data\Extensions.cs" />
|
||||
<Compile Include="Entities.cs" />
|
||||
<Compile Include="Feed.cs">
|
||||
<DependentUpon>Model.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FeedAction.cs">
|
||||
<DependentUpon>Model.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FeedErrorWindow.xaml.cs">
|
||||
<DependentUpon>FeedErrorWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FeedItem.cs">
|
||||
<DependentUpon>Model.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Feeds\Category.cs" />
|
||||
<Compile Include="Model.Context.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Model.Context.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Model.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Model.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Model.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
@@ -212,6 +243,9 @@
|
||||
<Compile Include="Options\UpdateOptionsPanel.xaml.cs">
|
||||
<DependentUpon>UpdateOptionsPanel.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Setting.cs">
|
||||
<DependentUpon>Model.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="SettingsStore.cs" />
|
||||
<Compile Include="SplashWindow.xaml.cs">
|
||||
<DependentUpon>SplashWindow.xaml</DependentUpon>
|
||||
@@ -326,6 +360,16 @@
|
||||
</EntityDeploy>
|
||||
<None Include="FeedCenter_1_TemporaryKey.pfx" />
|
||||
<None Include="FeedCenter_TemporaryKey.pfx" />
|
||||
<None Include="Model.Context.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>Model.Context.cs</LastGenOutput>
|
||||
<DependentUpon>Model.edmx</DependentUpon>
|
||||
</None>
|
||||
<None Include="Model.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>Model.cs</LastGenOutput>
|
||||
<DependentUpon>Model.edmx</DependentUpon>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\app.manifest" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
@@ -455,12 +499,17 @@
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
|
||||
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
|
||||
<Error Condition="!Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
|
||||
<Error Condition="Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
|
||||
</Target>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
|
||||
xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8854.1\NativeBinaries\x86\*.*" "$(TargetDir)x86"
|
||||
if not exist "$(TargetDir)amd64" md "$(TargetDir)amd64"
|
||||
xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8854.1\NativeBinaries\amd64\*.*" "$(TargetDir)amd64"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.ComponentModel;
|
||||
using FeedCenter.Options;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using FeedCenter.Options;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
@@ -38,9 +38,9 @@ namespace FeedCenter
|
||||
|
||||
private void HandleCollectionViewSourceFilter(object sender, FilterEventArgs e)
|
||||
{
|
||||
Feed feed = (Feed) e.Item;
|
||||
var feed = (Feed) e.Item;
|
||||
|
||||
e.Accepted = (feed.LastReadResult != (int) FeedReadResult.Success);
|
||||
e.Accepted = (feed.LastReadResult != FeedReadResult.Success);
|
||||
}
|
||||
|
||||
private void HandleEditFeedButtonClick(object sender, RoutedEventArgs e)
|
||||
@@ -58,18 +58,18 @@ namespace FeedCenter
|
||||
if (feedDataGrid.SelectedItem == null)
|
||||
return;
|
||||
|
||||
Feed feed = (Feed) feedDataGrid.SelectedItem;
|
||||
var feed = (Feed) feedDataGrid.SelectedItem;
|
||||
|
||||
FeedWindow feedWindow = new FeedWindow();
|
||||
var feedWindow = new FeedWindow();
|
||||
|
||||
feedWindow.Display(_database, feed, GetWindow(this));
|
||||
}
|
||||
|
||||
private void DeleteSelectedFeed()
|
||||
{
|
||||
Feed feed = (Feed) feedDataGrid.SelectedItem;
|
||||
var feed = (Feed) feedDataGrid.SelectedItem;
|
||||
|
||||
_database.Feeds.DeleteObject(feed);
|
||||
_database.Feeds.Remove(feed);
|
||||
|
||||
SetFeedButtonStates();
|
||||
}
|
||||
@@ -85,13 +85,13 @@ namespace FeedCenter
|
||||
|
||||
private void HandleOpenPageButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Feed feed = (Feed) feedDataGrid.SelectedItem;
|
||||
var feed = (Feed) feedDataGrid.SelectedItem;
|
||||
BrowserCommon.OpenLink(feed.Link);
|
||||
}
|
||||
|
||||
private void HandleOpenFeedButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Feed feed = (Feed) feedDataGrid.SelectedItem;
|
||||
var feed = (Feed) feedDataGrid.SelectedItem;
|
||||
BrowserCommon.OpenLink(feed.Source);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace FeedCenter
|
||||
{
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
|
||||
Feed feed = (Feed) feedDataGrid.SelectedItem;
|
||||
var feed = (Feed) feedDataGrid.SelectedItem;
|
||||
feed.Read(_database, true);
|
||||
|
||||
_collectionViewSource.View.Refresh();
|
||||
|
||||
38
FeedItem.cs
Normal file
38
FeedItem.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated from a template.
|
||||
//
|
||||
// Manual changes to this file may cause unexpected behavior in your application.
|
||||
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class FeedItem
|
||||
{
|
||||
public FeedItem()
|
||||
{
|
||||
this.Title = "";
|
||||
this.Link = "";
|
||||
this.Description = "";
|
||||
this.LastFound = new DateTime(599266080000000000, DateTimeKind.Unspecified);
|
||||
}
|
||||
|
||||
public System.Guid ID { get; set; }
|
||||
public System.Guid FeedID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Link { get; set; }
|
||||
public string Description { get; set; }
|
||||
public bool BeenRead { get; set; }
|
||||
public System.DateTime LastFound { get; set; }
|
||||
public bool New { get; set; }
|
||||
public string Guid { get; set; }
|
||||
public int Sequence { get; set; }
|
||||
|
||||
public virtual Feed Feed { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Xml;
|
||||
|
||||
using Common.Debug;
|
||||
using Common.Debug;
|
||||
using Common.Xml;
|
||||
using System.Xml;
|
||||
|
||||
namespace FeedCenter.FeedParsers
|
||||
{
|
||||
@@ -14,13 +13,13 @@ namespace FeedCenter.FeedParsers
|
||||
try
|
||||
{
|
||||
// Create the XML document
|
||||
XmlDocument document = new XmlDocument { XmlResolver = null };
|
||||
var document = new XmlDocument { XmlResolver = null };
|
||||
|
||||
// Load the XML document from the text
|
||||
document.LoadXml(feedText);
|
||||
|
||||
// Create the namespace manager
|
||||
XmlNamespaceManager namespaceManager = document.GetAllNamespaces();
|
||||
var namespaceManager = document.GetAllNamespaces();
|
||||
|
||||
// Get the root node
|
||||
XmlNode rootNode = document.DocumentElement;
|
||||
@@ -30,7 +29,7 @@ namespace FeedCenter.FeedParsers
|
||||
return FeedReadResult.UnknownError;
|
||||
|
||||
// Initialize the sequence number for items
|
||||
int sequence = 0;
|
||||
var sequence = 0;
|
||||
|
||||
// Loop over all nodes in the root node
|
||||
foreach (XmlNode node in rootNode.ChildNodes)
|
||||
@@ -81,7 +80,7 @@ namespace FeedCenter.FeedParsers
|
||||
protected override FeedItem ParseFeedItem(XmlNamespaceManager namespaceManager, XmlNode node)
|
||||
{
|
||||
// Create a new feed item
|
||||
FeedItem feedItem = new FeedItem();
|
||||
var feedItem = FeedItem.Create();
|
||||
|
||||
// Loop over all nodes in the feed node
|
||||
foreach (XmlNode childNode in node.ChildNodes)
|
||||
@@ -114,7 +113,7 @@ namespace FeedCenter.FeedParsers
|
||||
|
||||
if (string.IsNullOrEmpty(rel) || rel == "alternate")
|
||||
{
|
||||
string link = childNode.Attributes["href"].InnerText;
|
||||
var link = childNode.Attributes["href"].InnerText;
|
||||
|
||||
if (link.StartsWith("/"))
|
||||
{
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using Common.Debug;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
|
||||
using Common.Debug;
|
||||
|
||||
namespace FeedCenter.FeedParsers
|
||||
{
|
||||
[Serializable]
|
||||
internal class InvalidFeedFormatException : ApplicationException
|
||||
{
|
||||
internal InvalidFeedFormatException(Exception exception) : base(string.Empty, exception)
|
||||
{
|
||||
internal InvalidFeedFormatException(Exception exception)
|
||||
: base(string.Empty, exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace FeedCenter.FeedParsers
|
||||
try
|
||||
{
|
||||
// Create the XML document
|
||||
XmlDocument document = new XmlDocument { XmlResolver = null };
|
||||
var document = new XmlDocument { XmlResolver = null };
|
||||
|
||||
// Load the XML document from the text
|
||||
document.LoadXml(feedText);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Xml;
|
||||
|
||||
using Common.Debug;
|
||||
using Common.Debug;
|
||||
using Common.Xml;
|
||||
using System.Xml;
|
||||
|
||||
namespace FeedCenter.FeedParsers
|
||||
{
|
||||
@@ -14,13 +13,13 @@ namespace FeedCenter.FeedParsers
|
||||
try
|
||||
{
|
||||
// Create the XML document
|
||||
XmlDocument document = new XmlDocument { XmlResolver = null };
|
||||
var document = new XmlDocument { XmlResolver = null };
|
||||
|
||||
// Load the XML document from the text
|
||||
document.LoadXml(feedText);
|
||||
|
||||
// Create the namespace manager
|
||||
XmlNamespaceManager namespaceManager = document.GetAllNamespaces();
|
||||
XmlNamespaceManager namespaceManager = document.GetAllNamespaces();
|
||||
|
||||
// Get the root node
|
||||
XmlNode rootNode = document.DocumentElement;
|
||||
@@ -28,7 +27,7 @@ namespace FeedCenter.FeedParsers
|
||||
// If we didn't find a root node then bail
|
||||
if (rootNode == null)
|
||||
return FeedReadResult.UnknownError;
|
||||
|
||||
|
||||
// Get the channel node
|
||||
XmlNode channelNode = rootNode.SelectSingleNode("default:channel", namespaceManager);
|
||||
|
||||
@@ -83,7 +82,7 @@ namespace FeedCenter.FeedParsers
|
||||
protected override FeedItem ParseFeedItem(XmlNamespaceManager namespaceManager, XmlNode node)
|
||||
{
|
||||
// Create a new feed item
|
||||
FeedItem feedItem = new FeedItem();
|
||||
FeedItem feedItem = FeedItem.Create();
|
||||
|
||||
// Loop over all nodes in the feed node
|
||||
foreach (XmlNode childNode in node.ChildNodes)
|
||||
@@ -97,10 +96,10 @@ namespace FeedCenter.FeedParsers
|
||||
|
||||
case "link":
|
||||
feedItem.Link = childNode.InnerText.Trim();
|
||||
|
||||
|
||||
// RDF doesn't have a GUID node so we'll just use the link
|
||||
feedItem.Guid = feedItem.Link;
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case "description":
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Xml;
|
||||
|
||||
using Common.Debug;
|
||||
using Common.Debug;
|
||||
using Common.Xml;
|
||||
using System.Xml;
|
||||
|
||||
namespace FeedCenter.FeedParsers
|
||||
{
|
||||
@@ -14,7 +13,7 @@ namespace FeedCenter.FeedParsers
|
||||
try
|
||||
{
|
||||
// Create the XML document
|
||||
XmlDocument document = new XmlDocument { XmlResolver = null };
|
||||
var document = new XmlDocument { XmlResolver = null };
|
||||
|
||||
// Load the XML document from the text
|
||||
document.LoadXml(feedText);
|
||||
@@ -75,7 +74,7 @@ namespace FeedCenter.FeedParsers
|
||||
protected override FeedItem ParseFeedItem(XmlNamespaceManager namespaceManager, XmlNode node)
|
||||
{
|
||||
// Create a new feed item
|
||||
FeedItem feedItem = new FeedItem();
|
||||
FeedItem feedItem = FeedItem.Create();
|
||||
|
||||
// Loop over all nodes in the feed node
|
||||
foreach (XmlNode childNode in node.ChildNodes)
|
||||
|
||||
@@ -4,15 +4,11 @@ namespace FeedCenter
|
||||
{
|
||||
public partial class Category
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public Category()
|
||||
public static Category Create()
|
||||
{
|
||||
ID = Guid.NewGuid();
|
||||
return new Category { ID = Guid.NewGuid() };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public bool IsDefault
|
||||
{
|
||||
get { return Name == "< default >"; }
|
||||
|
||||
@@ -3,15 +3,23 @@ using Common.Xml;
|
||||
using FeedCenter.FeedParsers;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
#region Enumerations
|
||||
|
||||
public enum MultipleOpenAction
|
||||
{
|
||||
IndividualPages,
|
||||
SinglePage
|
||||
}
|
||||
|
||||
public enum FeedType
|
||||
{
|
||||
Unknown,
|
||||
@@ -20,7 +28,7 @@ namespace FeedCenter
|
||||
Atom
|
||||
}
|
||||
|
||||
public enum FeedItemComparison
|
||||
public enum FeedItemComparison : byte
|
||||
{
|
||||
Default,
|
||||
Title
|
||||
@@ -44,16 +52,26 @@ namespace FeedCenter
|
||||
|
||||
#endregion
|
||||
|
||||
public partial class Feed
|
||||
[ValueConversion(typeof(int), typeof(MultipleOpenAction))]
|
||||
public class MultipleOpenActionConverter : IValueConverter
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public Feed()
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
ID = Guid.NewGuid();
|
||||
return (MultipleOpenAction) value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (int) value;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Feed
|
||||
{
|
||||
public static Feed Create()
|
||||
{
|
||||
return new Feed { ID = Guid.NewGuid() };
|
||||
}
|
||||
|
||||
#region Event delegates
|
||||
|
||||
@@ -81,7 +99,7 @@ namespace FeedCenter
|
||||
|
||||
default:
|
||||
// Save as last result
|
||||
LastReadResult = (int) result;
|
||||
LastReadResult = result;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -268,7 +286,7 @@ namespace FeedCenter
|
||||
foreach (var itemToRemove in removedItems)
|
||||
{
|
||||
// Delete the item from the database
|
||||
database.FeedItems.DeleteObject(itemToRemove);
|
||||
database.FeedItems.Remove(itemToRemove);
|
||||
|
||||
// Remove the item from the list
|
||||
Items.Remove(itemToRemove);
|
||||
@@ -315,7 +333,7 @@ namespace FeedCenter
|
||||
get
|
||||
{
|
||||
// Cast the last read result to the proper enum
|
||||
var lastReadResult = (FeedReadResult) LastReadResult;
|
||||
var lastReadResult = LastReadResult;
|
||||
|
||||
// Build the name of the resource using the enum name and the value
|
||||
var resourceName = string.Format("{0}_{1}", typeof(FeedReadResult).Name, lastReadResult);
|
||||
|
||||
@@ -6,15 +6,11 @@ namespace FeedCenter
|
||||
{
|
||||
public partial class FeedItem
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public FeedItem()
|
||||
public static FeedItem Create()
|
||||
{
|
||||
ID = System.Guid.NewGuid();
|
||||
return new FeedItem { ID = System.Guid.NewGuid() };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public override string ToString()
|
||||
@@ -31,7 +27,7 @@ namespace FeedCenter
|
||||
break;
|
||||
|
||||
case Options.MultipleLineDisplay.FirstLine:
|
||||
|
||||
|
||||
// Find the first newline
|
||||
int newlineIndex = title.IndexOf("\n", StringComparison.Ordinal);
|
||||
|
||||
@@ -46,7 +42,7 @@ namespace FeedCenter
|
||||
title = Regex.Replace(title, @"[ ]{2,}", " ");
|
||||
|
||||
// Condense tabs to one space
|
||||
title = Regex.Replace(title, @"\t", " ");
|
||||
title = Regex.Replace(title, @"\t", " ");
|
||||
|
||||
// If the title is blank then put in the "no title" title
|
||||
if (title.Length == 0)
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
using System;
|
||||
using Common.Debug;
|
||||
using Common.Helpers;
|
||||
using Common.IO;
|
||||
using Common.Wpf.Extensions;
|
||||
using FeedCenter.Options;
|
||||
using FeedCenter.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Deployment.Application;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Web.UI;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
using Common.Debug;
|
||||
using Common.Helpers;
|
||||
using Common.IO;
|
||||
using Common.Internet;
|
||||
using Common.Wpf.Extensions;
|
||||
using FeedCenter.Options;
|
||||
using FeedCenter.Properties;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
@@ -180,14 +178,14 @@ namespace FeedCenter
|
||||
private void LoadWindowSettings()
|
||||
{
|
||||
// Get the last window location
|
||||
Point windowLocation = Settings.Default.WindowLocation;
|
||||
var windowLocation = Settings.Default.WindowLocation;
|
||||
|
||||
// Set the window into position
|
||||
Left = windowLocation.X;
|
||||
Top = windowLocation.Y;
|
||||
|
||||
// Get the last window size
|
||||
Size windowSize = Settings.Default.WindowSize;
|
||||
var windowSize = Settings.Default.WindowSize;
|
||||
|
||||
// Set the window into the previous size if it is valid
|
||||
if (!windowSize.Width.Equals(0) && !windowSize.Height.Equals(0))
|
||||
@@ -315,7 +313,7 @@ namespace FeedCenter
|
||||
private void InitializeFeed()
|
||||
{
|
||||
// Cache the feed count to save (a little) time
|
||||
int feedCount = _database.Feeds.Count();
|
||||
var feedCount = _database.Feeds.Count();
|
||||
|
||||
// Set button states
|
||||
previousToolbarButton.IsEnabled = (feedCount > 1);
|
||||
@@ -343,7 +341,7 @@ namespace FeedCenter
|
||||
|
||||
private void NextFeed()
|
||||
{
|
||||
int feedCount = _database.Feeds.Count();
|
||||
var feedCount = _database.Feeds.Count();
|
||||
|
||||
if (feedCount == 0)
|
||||
return;
|
||||
@@ -359,10 +357,10 @@ namespace FeedCenter
|
||||
else
|
||||
{
|
||||
// Keep track if we found something
|
||||
bool found = false;
|
||||
var found = false;
|
||||
|
||||
// Remember our starting position
|
||||
int startIndex = (_feedIndex == -1 ? 0 : _feedIndex);
|
||||
var startIndex = (_feedIndex == -1 ? 0 : _feedIndex);
|
||||
|
||||
// Increment the index and adjust if we've gone around the end
|
||||
_feedIndex = (_feedIndex + 1) % feedCount;
|
||||
@@ -402,7 +400,7 @@ namespace FeedCenter
|
||||
|
||||
private void PreviousFeed()
|
||||
{
|
||||
int feedCount = _database.Feeds.Count();
|
||||
var feedCount = _database.Feeds.Count();
|
||||
|
||||
if (feedCount == 0)
|
||||
return;
|
||||
@@ -422,10 +420,10 @@ namespace FeedCenter
|
||||
else
|
||||
{
|
||||
// Keep track if we found something
|
||||
bool found = false;
|
||||
var found = false;
|
||||
|
||||
// Remember our starting position
|
||||
int startIndex = (_feedIndex == -1 ? 0 : _feedIndex);
|
||||
var startIndex = (_feedIndex == -1 ? 0 : _feedIndex);
|
||||
|
||||
// Decrement the feed index
|
||||
_feedIndex--;
|
||||
@@ -473,7 +471,7 @@ namespace FeedCenter
|
||||
|
||||
private void UpdateOpenAllButton()
|
||||
{
|
||||
var multipleOpenAction = (MultipleOpenAction) _currentFeed.MultipleOpenAction;
|
||||
var multipleOpenAction = _currentFeed.MultipleOpenAction;
|
||||
|
||||
switch (multipleOpenAction)
|
||||
{
|
||||
@@ -509,7 +507,7 @@ namespace FeedCenter
|
||||
var sortedItems = _currentFeed.Items.Where(item => !item.BeenRead).OrderBy(item => item.Sequence);
|
||||
|
||||
// Loop over all items in the current feed
|
||||
foreach (FeedItem feedItem in sortedItems)
|
||||
foreach (var feedItem in sortedItems)
|
||||
{
|
||||
// Add the list item
|
||||
linkTextList.Items.Add(feedItem);
|
||||
@@ -575,7 +573,7 @@ namespace FeedCenter
|
||||
SetProgressMode(true, 1);
|
||||
|
||||
// Create the input class
|
||||
FeedReadWorkerInput workerInput = new FeedReadWorkerInput { ForceRead = forceRead, Feed = _currentFeed };
|
||||
var workerInput = new FeedReadWorkerInput { ForceRead = forceRead, Feed = _currentFeed };
|
||||
|
||||
// Start the worker
|
||||
_feedReadWorker.RunWorkerAsync(workerInput);
|
||||
@@ -595,7 +593,7 @@ namespace FeedCenter
|
||||
SetProgressMode(true, _database.Feeds.Count());
|
||||
|
||||
// Create the input class
|
||||
FeedReadWorkerInput workerInput = new FeedReadWorkerInput { ForceRead = forceRead, Feed = null };
|
||||
var workerInput = new FeedReadWorkerInput { ForceRead = forceRead, Feed = null };
|
||||
|
||||
// Start the worker
|
||||
_feedReadWorker.RunWorkerAsync(workerInput);
|
||||
@@ -610,7 +608,7 @@ namespace FeedCenter
|
||||
private void HandleFeedReadWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
// Get the state info
|
||||
FeedReadWorkerOutput workerOutput = (FeedReadWorkerOutput) e.Result;
|
||||
var workerOutput = (FeedReadWorkerOutput) e.Result;
|
||||
|
||||
// Reset the database to current settings
|
||||
ResetDatabase();
|
||||
@@ -628,7 +626,7 @@ namespace FeedCenter
|
||||
SetProgressMode(false, 0);
|
||||
|
||||
// Check for update information
|
||||
UpdateCheckInfo updateCheckInfo = workerOutput.UpdateResult;
|
||||
var updateCheckInfo = workerOutput.UpdateResult;
|
||||
|
||||
if (updateCheckInfo != null && updateCheckInfo.UpdateAvailable)
|
||||
newVersionLink.Visibility = Visibility.Visible;
|
||||
@@ -638,7 +636,7 @@ namespace FeedCenter
|
||||
|
||||
private void UpdateErrorLink()
|
||||
{
|
||||
var feedErrorCount = _database.Feeds.Count(f => f.LastReadResult != (int) FeedReadResult.Success);
|
||||
var feedErrorCount = _database.Feeds.Count(f => f.LastReadResult != FeedReadResult.Success);
|
||||
|
||||
// Set the visibility of the error link
|
||||
feedErrorsLink.Visibility = feedErrorCount == 0 ? Visibility.Collapsed : Visibility.Visible;
|
||||
@@ -652,22 +650,22 @@ namespace FeedCenter
|
||||
private static void HandleFeedReadWorkerStart(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
// Create a new database instance for just this thread
|
||||
FeedCenterEntities database = new FeedCenterEntities();
|
||||
var database = new FeedCenterEntities();
|
||||
|
||||
// Get the worker
|
||||
BackgroundWorker worker = (BackgroundWorker) sender;
|
||||
var worker = (BackgroundWorker) sender;
|
||||
|
||||
// Get the input information
|
||||
FeedReadWorkerInput workerInput = (FeedReadWorkerInput) e.Argument;
|
||||
var workerInput = (FeedReadWorkerInput) e.Argument;
|
||||
|
||||
// Create the output
|
||||
FeedReadWorkerOutput workerOutput = new FeedReadWorkerOutput();
|
||||
var workerOutput = new FeedReadWorkerOutput();
|
||||
|
||||
// Setup for progress
|
||||
int currentProgress = 0;
|
||||
var currentProgress = 0;
|
||||
|
||||
// Create the list of feeds to read
|
||||
List<Feed> feedsToRead = new List<Feed>();
|
||||
var feedsToRead = new List<Feed>();
|
||||
|
||||
// If we have a single feed then add it to the list - otherwise add them all
|
||||
if (workerInput.Feed != null)
|
||||
@@ -676,7 +674,7 @@ namespace FeedCenter
|
||||
feedsToRead.AddRange(database.Feeds);
|
||||
|
||||
// Loop over each feed and read it
|
||||
foreach (Feed feed in feedsToRead)
|
||||
foreach (var feed in feedsToRead)
|
||||
{
|
||||
// Read the feed
|
||||
feed.Read(database, workerInput.ForceRead);
|
||||
@@ -743,10 +741,10 @@ namespace FeedCenter
|
||||
return;
|
||||
|
||||
// Pad the command line with a trailing space just to be lazy in parsing
|
||||
string commandLine = e.Message + " ";
|
||||
var commandLine = e.Message + " ";
|
||||
|
||||
// Look for the feed URL in the command line
|
||||
int startPosition = commandLine.IndexOf("feed://", StringComparison.Ordinal);
|
||||
var startPosition = commandLine.IndexOf("feed://", StringComparison.Ordinal);
|
||||
|
||||
// If we found one then we should extract and process it
|
||||
if (startPosition > 0)
|
||||
@@ -755,10 +753,10 @@ namespace FeedCenter
|
||||
startPosition += 7;
|
||||
|
||||
// Starting at the URL position look for the next space
|
||||
int endPosition = commandLine.IndexOf(" ", startPosition, StringComparison.Ordinal);
|
||||
var endPosition = commandLine.IndexOf(" ", startPosition, StringComparison.Ordinal);
|
||||
|
||||
// Extract the feed URL
|
||||
string feedUrl = commandLine.Substring(startPosition, endPosition - startPosition);
|
||||
var feedUrl = commandLine.Substring(startPosition, endPosition - startPosition);
|
||||
|
||||
// Add the HTTP protocol by default
|
||||
feedUrl = "http://" + feedUrl;
|
||||
@@ -772,14 +770,12 @@ namespace FeedCenter
|
||||
private void HandleNewFeed(string feedUrl)
|
||||
{
|
||||
// Create and configure the new feed
|
||||
Feed feed = new Feed
|
||||
{
|
||||
Source = feedUrl,
|
||||
Category = _database.Categories.ToList().First(category => category.IsDefault),
|
||||
};
|
||||
var feed = Feed.Create();
|
||||
feed.Source = feedUrl;
|
||||
feed.Category = _database.Categories.ToList().First(category => category.IsDefault);
|
||||
|
||||
// Read the feed for the first time
|
||||
FeedReadResult feedReadResult = feed.Read(_database);
|
||||
var feedReadResult = feed.Read(_database);
|
||||
|
||||
// See if we read the feed okay
|
||||
if (feedReadResult == FeedReadResult.Success)
|
||||
@@ -788,7 +784,7 @@ namespace FeedCenter
|
||||
feed.Name = feed.Title;
|
||||
|
||||
// Add the feed to the feed table
|
||||
_database.Feeds.AddObject(feed);
|
||||
_database.Feeds.Add(feed);
|
||||
|
||||
// Save the changes
|
||||
_database.SaveChanges();
|
||||
@@ -802,15 +798,15 @@ namespace FeedCenter
|
||||
else
|
||||
{
|
||||
// Feed read failed - ceate a new feed window
|
||||
FeedWindow feedForm = new FeedWindow();
|
||||
var feedForm = new FeedWindow();
|
||||
|
||||
bool? dialogResult = feedForm.Display(_database, feed, this);
|
||||
var dialogResult = feedForm.Display(_database, feed, this);
|
||||
|
||||
// Display the new feed form
|
||||
if (dialogResult.HasValue && dialogResult.Value)
|
||||
{
|
||||
// Add the feed to the feed table
|
||||
_database.Feeds.AddObject(feed);
|
||||
_database.Feeds.Add(feed);
|
||||
|
||||
// Save the changes
|
||||
_database.SaveChanges();
|
||||
@@ -828,7 +824,7 @@ namespace FeedCenter
|
||||
private void ResetDatabase()
|
||||
{
|
||||
// Get the ID of the current feed
|
||||
Guid currentId = _currentFeed.ID;
|
||||
var currentId = _currentFeed.ID;
|
||||
|
||||
// Create a new database object
|
||||
_database = new FeedCenterEntities();
|
||||
@@ -872,7 +868,7 @@ namespace FeedCenter
|
||||
return;
|
||||
|
||||
// Get the data as a string
|
||||
string data = (string) e.Data.GetData(DataFormats.Text);
|
||||
var data = (string) e.Data.GetData(DataFormats.Text);
|
||||
|
||||
// If the data doesn't look like a URI then it is not allowed
|
||||
if (!Uri.IsWellFormedUriString(data, UriKind.Absolute))
|
||||
@@ -885,7 +881,7 @@ namespace FeedCenter
|
||||
private void HandleDragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
// Get the data as a string
|
||||
string data = (string) e.Data.GetData(DataFormats.Text);
|
||||
var data = (string) e.Data.GetData(DataFormats.Text);
|
||||
|
||||
// Handle the new feed but allow the drag/drop to complete
|
||||
Dispatcher.BeginInvoke(new NewFeedDelegate(HandleNewFeed), data);
|
||||
@@ -918,7 +914,7 @@ namespace FeedCenter
|
||||
return;
|
||||
|
||||
// Get the feed item
|
||||
FeedItem feedItem = (FeedItem) ((ListBoxItem) sender).DataContext;
|
||||
var feedItem = (FeedItem) ((ListBoxItem) sender).DataContext;
|
||||
|
||||
// The feed item has been read and is no longer new
|
||||
feedItem.BeenRead = true;
|
||||
@@ -935,7 +931,7 @@ namespace FeedCenter
|
||||
private void HandleLinkTextListListItemMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// Get the feed item
|
||||
FeedItem feedItem = (FeedItem) ((ListBoxItem) sender).DataContext;
|
||||
var feedItem = (FeedItem) ((ListBoxItem) sender).DataContext;
|
||||
|
||||
// Open the item link
|
||||
if (BrowserCommon.OpenLink(feedItem.Link))
|
||||
@@ -959,16 +955,16 @@ namespace FeedCenter
|
||||
private void HandleFeedButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Create a new context menu
|
||||
ContextMenu contextMenu = new ContextMenu();
|
||||
var contextMenu = new ContextMenu();
|
||||
|
||||
// Loop over each feed
|
||||
foreach (Feed feed in _database.Feeds.OrderBy(feed => feed.Name))
|
||||
foreach (var feed in _database.Feeds.OrderBy(feed => feed.Name))
|
||||
{
|
||||
// Build a string to display the feed name and the unread count
|
||||
string display = string.Format("{0} ({1:d})", feed.Name, feed.Items.Count(item => !item.BeenRead));
|
||||
var display = string.Format("{0} ({1:d})", feed.Name, feed.Items.Count(item => !item.BeenRead));
|
||||
|
||||
// Create a menu item
|
||||
MenuItem menuItem = new MenuItem
|
||||
var menuItem = new MenuItem
|
||||
{
|
||||
Header = display,
|
||||
Tag = feed,
|
||||
@@ -995,14 +991,14 @@ namespace FeedCenter
|
||||
private void HandleFeedMenuItemClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Get the menu item clicked
|
||||
MenuItem menuItem = (MenuItem) sender;
|
||||
var menuItem = (MenuItem) sender;
|
||||
|
||||
// Get the feed from the menu item tab
|
||||
Feed feed = (Feed) menuItem.Tag;
|
||||
var feed = (Feed) menuItem.Tag;
|
||||
|
||||
// Loop over all feeds and look for the index of the new one
|
||||
int feedIndex = 0;
|
||||
foreach (Feed loopFeed in _database.Feeds.OrderBy(loopFeed => loopFeed.Name))
|
||||
var feedIndex = 0;
|
||||
foreach (var loopFeed in _database.Feeds.OrderBy(loopFeed => loopFeed.Name))
|
||||
{
|
||||
if (loopFeed == feed)
|
||||
{
|
||||
@@ -1029,11 +1025,11 @@ namespace FeedCenter
|
||||
|
||||
private void UpdateBorder()
|
||||
{
|
||||
WindowInteropHelper windowInteropHelper = new WindowInteropHelper(this);
|
||||
var windowInteropHelper = new WindowInteropHelper(this);
|
||||
|
||||
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
|
||||
var screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
|
||||
|
||||
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle
|
||||
var rectangle = new System.Drawing.Rectangle
|
||||
{
|
||||
X = (int) Left,
|
||||
Y = (int) Top,
|
||||
@@ -1041,7 +1037,7 @@ namespace FeedCenter
|
||||
Height = (int) Height
|
||||
};
|
||||
|
||||
Thickness borderThickness = new Thickness();
|
||||
var borderThickness = new Thickness();
|
||||
|
||||
if (rectangle.Right != screen.WorkingArea.Right)
|
||||
borderThickness.Right = 1;
|
||||
@@ -1116,16 +1112,16 @@ namespace FeedCenter
|
||||
var feedItems = (from FeedItem feedItem in linkTextList.Items select feedItem).ToList();
|
||||
|
||||
// Get the browser
|
||||
Browser browser = BrowserCommon.FindBrowser(Settings.Default.Browser);
|
||||
var browser = BrowserCommon.FindBrowser(Settings.Default.Browser);
|
||||
|
||||
// Cache the settings object
|
||||
var settings = Settings.Default;
|
||||
|
||||
// Start with a longer sleep interval to give time for the browser to come up
|
||||
int sleepInterval = settings.OpenAllSleepIntervalFirst;
|
||||
var sleepInterval = settings.OpenAllSleepIntervalFirst;
|
||||
|
||||
// Loop over all items
|
||||
foreach (FeedItem feedItem in feedItems)
|
||||
foreach (var feedItem in feedItems)
|
||||
{
|
||||
// Try to open the link
|
||||
if (BrowserCommon.OpenLink(browser, feedItem.Link))
|
||||
@@ -1151,10 +1147,10 @@ namespace FeedCenter
|
||||
private void HandleOptionsToolbarButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Create the options form
|
||||
OptionsWindow optionsWindow = new OptionsWindow { Owner = this };
|
||||
var optionsWindow = new OptionsWindow { Owner = this };
|
||||
|
||||
// Show the options form and get the result
|
||||
bool? result = optionsWindow.ShowDialog();
|
||||
var result = optionsWindow.ShowDialog();
|
||||
|
||||
// If okay was selected
|
||||
if (result.HasValue && result.Value)
|
||||
@@ -1175,10 +1171,10 @@ namespace FeedCenter
|
||||
private void HandleShowErrorsButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Create the feed error window
|
||||
FeedErrorWindow feedErrorWindow = new FeedErrorWindow();
|
||||
var feedErrorWindow = new FeedErrorWindow();
|
||||
|
||||
// Display the window
|
||||
bool? result = feedErrorWindow.Display(this);
|
||||
var result = feedErrorWindow.Display(this);
|
||||
|
||||
// If okay was selected
|
||||
if (result.GetValueOrDefault())
|
||||
@@ -1195,11 +1191,11 @@ namespace FeedCenter
|
||||
|
||||
private void HandleRefreshMenuItemClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MenuItem menuItem = (MenuItem) e.Source;
|
||||
var menuItem = (MenuItem) e.Source;
|
||||
|
||||
if (menuItem == menuRefresh)
|
||||
if (Equals(menuItem, menuRefresh))
|
||||
ReadCurrentFeed(true);
|
||||
else if (menuItem == menuRefreshAll)
|
||||
else if (Equals(menuItem, menuRefreshAll))
|
||||
ReadFeeds(true);
|
||||
}
|
||||
|
||||
@@ -1210,11 +1206,11 @@ namespace FeedCenter
|
||||
|
||||
private void HandleOpenAllMenuItemClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MenuItem menuItem = (MenuItem) e.Source;
|
||||
var menuItem = (MenuItem) e.Source;
|
||||
|
||||
if (menuItem == menuOpenAllSinglePage)
|
||||
if (Equals(menuItem, menuOpenAllSinglePage))
|
||||
OpenAllFeedItemsOnSinglePage();
|
||||
else if (menuItem == menuOpenAllMultiplePages)
|
||||
else if (Equals(menuItem, menuOpenAllMultiplePages))
|
||||
OpenAllFeedItemsIndividually();
|
||||
}
|
||||
|
||||
@@ -1236,10 +1232,10 @@ namespace FeedCenter
|
||||
private void HandleEditCurrentFeedMenuItemClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Create a new feed window
|
||||
FeedWindow feedWindow = new FeedWindow();
|
||||
var feedWindow = new FeedWindow();
|
||||
|
||||
// Display the feed window and get the result
|
||||
bool? result = feedWindow.Display(_database, _currentFeed, this);
|
||||
var result = feedWindow.Display(_database, _currentFeed, this);
|
||||
|
||||
// If OK was clicked...
|
||||
if (result.HasValue && result.Value)
|
||||
@@ -1259,17 +1255,17 @@ namespace FeedCenter
|
||||
return;
|
||||
|
||||
// Get the current feed
|
||||
Feed feedToDelete = _currentFeed;
|
||||
var feedToDelete = _currentFeed;
|
||||
|
||||
// Move to the next feed
|
||||
NextFeed();
|
||||
|
||||
// Delete all items
|
||||
foreach (var item in feedToDelete.Items.ToList())
|
||||
_database.FeedItems.DeleteObject(item);
|
||||
_database.FeedItems.Remove(item);
|
||||
|
||||
// Delete the feed
|
||||
_database.Feeds.DeleteObject(feedToDelete);
|
||||
_database.Feeds.Remove(feedToDelete);
|
||||
|
||||
// Save
|
||||
_database.SaveChanges();
|
||||
@@ -1281,10 +1277,10 @@ namespace FeedCenter
|
||||
|
||||
private void OpenAllFeedItemsOnSinglePage()
|
||||
{
|
||||
string fileName = Path.GetTempFileName() + ".html";
|
||||
var fileName = Path.GetTempFileName() + ".html";
|
||||
TextWriter textWriter = new StreamWriter(fileName);
|
||||
|
||||
using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(textWriter))
|
||||
using (var htmlTextWriter = new HtmlTextWriter(textWriter))
|
||||
{
|
||||
htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Html);
|
||||
|
||||
@@ -1305,7 +1301,7 @@ namespace FeedCenter
|
||||
|
||||
var sortedItems = from item in _currentFeed.Items where !item.BeenRead orderby item.Sequence ascending select item;
|
||||
|
||||
bool firstItem = true;
|
||||
var firstItem = true;
|
||||
|
||||
foreach (var item in sortedItems)
|
||||
{
|
||||
@@ -1351,28 +1347,5 @@ namespace FeedCenter
|
||||
// Display update information
|
||||
VersionCheck.DisplayUpdateInformation(true);
|
||||
}
|
||||
|
||||
#region Hover selection events
|
||||
|
||||
private void HandleListItemMouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
// Get the list box item
|
||||
ListBoxItem listBoxItem = (ListBoxItem) sender;
|
||||
|
||||
// Select the data context
|
||||
linkTextList.SelectedItem = listBoxItem.DataContext;
|
||||
|
||||
// Set the cursor
|
||||
listBoxItem.Cursor = Cursors.Hand;
|
||||
}
|
||||
|
||||
private void HandleListItemMouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
// Clear selection
|
||||
linkTextList.SelectedItem = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
34
Model.Context.cs
Normal file
34
Model.Context.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated from a template.
|
||||
//
|
||||
// Manual changes to this file may cause unexpected behavior in your application.
|
||||
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
|
||||
public partial class FeedCenterEntities : DbContext
|
||||
{
|
||||
public FeedCenterEntities()
|
||||
: base("name=FeedCenterEntities")
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||
{
|
||||
throw new UnintentionalCodeFirstException();
|
||||
}
|
||||
|
||||
public virtual DbSet<Category> Categories { get; set; }
|
||||
public virtual DbSet<Feed> Feeds { get; set; }
|
||||
public virtual DbSet<FeedAction> FeedActions { get; set; }
|
||||
public virtual DbSet<FeedItem> FeedItems { get; set; }
|
||||
public virtual DbSet<Setting> Settings { get; set; }
|
||||
}
|
||||
}
|
||||
636
Model.Context.tt
Normal file
636
Model.Context.tt
Normal file
@@ -0,0 +1,636 @@
|
||||
<#@ template language="C#" debug="false" hostspecific="true"#>
|
||||
<#@ include file="EF6.Utility.CS.ttinclude"#><#@
|
||||
output extension=".cs"#><#
|
||||
|
||||
const string inputFile = @"Model.edmx";
|
||||
var textTransform = DynamicTextTransformation.Create(this);
|
||||
var code = new CodeGenerationTools(this);
|
||||
var ef = new MetadataTools(this);
|
||||
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
|
||||
var loader = new EdmMetadataLoader(textTransform.Host, textTransform.Errors);
|
||||
var itemCollection = loader.CreateEdmItemCollection(inputFile);
|
||||
var modelNamespace = loader.GetModelNamespace(inputFile);
|
||||
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef);
|
||||
|
||||
var container = itemCollection.OfType<EntityContainer>().FirstOrDefault();
|
||||
if (container == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
#>
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine1")#>
|
||||
//
|
||||
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine2")#>
|
||||
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine3")#>
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
<#
|
||||
|
||||
var codeNamespace = code.VsNamespaceSuggestion();
|
||||
if (!String.IsNullOrEmpty(codeNamespace))
|
||||
{
|
||||
#>
|
||||
namespace <#=code.EscapeNamespace(codeNamespace)#>
|
||||
{
|
||||
<#
|
||||
PushIndent(" ");
|
||||
}
|
||||
|
||||
#>
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
<#
|
||||
if (container.FunctionImports.Any())
|
||||
{
|
||||
#>
|
||||
using System.Data.Entity.Core.Objects;
|
||||
using System.Linq;
|
||||
<#
|
||||
}
|
||||
#>
|
||||
|
||||
<#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : DbContext
|
||||
{
|
||||
public <#=code.Escape(container)#>()
|
||||
: base("name=<#=container.Name#>")
|
||||
{
|
||||
<#
|
||||
if (!loader.IsLazyLoadingEnabled(container))
|
||||
{
|
||||
#>
|
||||
this.Configuration.LazyLoadingEnabled = false;
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var entitySet in container.BaseEntitySets.OfType<EntitySet>())
|
||||
{
|
||||
// Note: the DbSet members are defined below such that the getter and
|
||||
// setter always have the same accessibility as the DbSet definition
|
||||
if (Accessibility.ForReadOnlyProperty(entitySet) != "public")
|
||||
{
|
||||
#>
|
||||
<#=codeStringGenerator.DbSetInitializer(entitySet)#>
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||
{
|
||||
throw new UnintentionalCodeFirstException();
|
||||
}
|
||||
|
||||
<#
|
||||
foreach (var entitySet in container.BaseEntitySets.OfType<EntitySet>())
|
||||
{
|
||||
#>
|
||||
<#=codeStringGenerator.DbSet(entitySet)#>
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var edmFunction in container.FunctionImports)
|
||||
{
|
||||
WriteFunctionImport(typeMapper, codeStringGenerator, edmFunction, modelNamespace, includeMergeOption: false);
|
||||
}
|
||||
#>
|
||||
}
|
||||
<#
|
||||
|
||||
if (!String.IsNullOrEmpty(codeNamespace))
|
||||
{
|
||||
PopIndent();
|
||||
#>
|
||||
}
|
||||
<#
|
||||
}
|
||||
#>
|
||||
<#+
|
||||
|
||||
private void WriteFunctionImport(TypeMapper typeMapper, CodeStringGenerator codeStringGenerator, EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||
{
|
||||
if (typeMapper.IsComposable(edmFunction))
|
||||
{
|
||||
#>
|
||||
|
||||
[DbFunction("<#=edmFunction.NamespaceName#>", "<#=edmFunction.Name#>")]
|
||||
<#=codeStringGenerator.ComposableFunctionMethod(edmFunction, modelNamespace)#>
|
||||
{
|
||||
<#+
|
||||
codeStringGenerator.WriteFunctionParameters(edmFunction, WriteFunctionParameter);
|
||||
#>
|
||||
<#=codeStringGenerator.ComposableCreateQuery(edmFunction, modelNamespace)#>
|
||||
}
|
||||
<#+
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
|
||||
<#=codeStringGenerator.FunctionMethod(edmFunction, modelNamespace, includeMergeOption)#>
|
||||
{
|
||||
<#+
|
||||
codeStringGenerator.WriteFunctionParameters(edmFunction, WriteFunctionParameter);
|
||||
#>
|
||||
<#=codeStringGenerator.ExecuteFunction(edmFunction, modelNamespace, includeMergeOption)#>
|
||||
}
|
||||
<#+
|
||||
if (typeMapper.GenerateMergeOptionFunction(edmFunction, includeMergeOption))
|
||||
{
|
||||
WriteFunctionImport(typeMapper, codeStringGenerator, edmFunction, modelNamespace, includeMergeOption: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteFunctionParameter(string name, string isNotNull, string notNullInit, string nullInit)
|
||||
{
|
||||
#>
|
||||
var <#=name#> = <#=isNotNull#> ?
|
||||
<#=notNullInit#> :
|
||||
<#=nullInit#>;
|
||||
|
||||
<#+
|
||||
}
|
||||
|
||||
public const string TemplateId = "CSharp_DbContext_Context_EF6";
|
||||
|
||||
public class CodeStringGenerator
|
||||
{
|
||||
private readonly CodeGenerationTools _code;
|
||||
private readonly TypeMapper _typeMapper;
|
||||
private readonly MetadataTools _ef;
|
||||
|
||||
public CodeStringGenerator(CodeGenerationTools code, TypeMapper typeMapper, MetadataTools ef)
|
||||
{
|
||||
ArgumentNotNull(code, "code");
|
||||
ArgumentNotNull(typeMapper, "typeMapper");
|
||||
ArgumentNotNull(ef, "ef");
|
||||
|
||||
_code = code;
|
||||
_typeMapper = typeMapper;
|
||||
_ef = ef;
|
||||
}
|
||||
|
||||
public string Property(EdmProperty edmProperty)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} {1} {2} {{ {3}get; {4}set; }}",
|
||||
Accessibility.ForProperty(edmProperty),
|
||||
_typeMapper.GetTypeName(edmProperty.TypeUsage),
|
||||
_code.Escape(edmProperty),
|
||||
_code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
|
||||
_code.SpaceAfter(Accessibility.ForSetter(edmProperty)));
|
||||
}
|
||||
|
||||
public string NavigationProperty(NavigationProperty navProp)
|
||||
{
|
||||
var endType = _typeMapper.GetTypeName(navProp.ToEndMember.GetEntityType());
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} {1} {2} {{ {3}get; {4}set; }}",
|
||||
AccessibilityAndVirtual(Accessibility.ForNavigationProperty(navProp)),
|
||||
navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,
|
||||
_code.Escape(navProp),
|
||||
_code.SpaceAfter(Accessibility.ForGetter(navProp)),
|
||||
_code.SpaceAfter(Accessibility.ForSetter(navProp)));
|
||||
}
|
||||
|
||||
public string AccessibilityAndVirtual(string accessibility)
|
||||
{
|
||||
return accessibility + (accessibility != "private" ? " virtual" : "");
|
||||
}
|
||||
|
||||
public string EntityClassOpening(EntityType entity)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} {1}partial class {2}{3}",
|
||||
Accessibility.ForType(entity),
|
||||
_code.SpaceAfter(_code.AbstractOption(entity)),
|
||||
_code.Escape(entity),
|
||||
_code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType)));
|
||||
}
|
||||
|
||||
public string EnumOpening(SimpleType enumType)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} enum {1} : {2}",
|
||||
Accessibility.ForType(enumType),
|
||||
_code.Escape(enumType),
|
||||
_code.Escape(_typeMapper.UnderlyingClrType(enumType)));
|
||||
}
|
||||
|
||||
public void WriteFunctionParameters(EdmFunction edmFunction, Action<string, string, string, string> writeParameter)
|
||||
{
|
||||
var parameters = FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef);
|
||||
foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable))
|
||||
{
|
||||
var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null";
|
||||
var notNullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")";
|
||||
var nullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + TypeMapper.FixNamespaces(parameter.RawClrTypeName) + "))";
|
||||
writeParameter(parameter.LocalVariableName, isNotNull, notNullInit, nullInit);
|
||||
}
|
||||
}
|
||||
|
||||
public string ComposableFunctionMethod(EdmFunction edmFunction, string modelNamespace)
|
||||
{
|
||||
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} IQueryable<{1}> {2}({3})",
|
||||
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)),
|
||||
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace),
|
||||
_code.Escape(edmFunction),
|
||||
string.Join(", ", parameters.Select(p => TypeMapper.FixNamespaces(p.FunctionParameterType) + " " + p.FunctionParameterName).ToArray()));
|
||||
}
|
||||
|
||||
public string ComposableCreateQuery(EdmFunction edmFunction, string modelNamespace)
|
||||
{
|
||||
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<{0}>(\"[{1}].[{2}]({3})\"{4});",
|
||||
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace),
|
||||
edmFunction.NamespaceName,
|
||||
edmFunction.Name,
|
||||
string.Join(", ", parameters.Select(p => "@" + p.EsqlParameterName).ToArray()),
|
||||
_code.StringBefore(", ", string.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray())));
|
||||
}
|
||||
|
||||
public string FunctionMethod(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||
{
|
||||
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||
var returnType = _typeMapper.GetReturnType(edmFunction);
|
||||
|
||||
var paramList = String.Join(", ", parameters.Select(p => TypeMapper.FixNamespaces(p.FunctionParameterType) + " " + p.FunctionParameterName).ToArray());
|
||||
if (includeMergeOption)
|
||||
{
|
||||
paramList = _code.StringAfter(paramList, ", ") + "MergeOption mergeOption";
|
||||
}
|
||||
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} {1} {2}({3})",
|
||||
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)),
|
||||
returnType == null ? "int" : "ObjectResult<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
|
||||
_code.Escape(edmFunction),
|
||||
paramList);
|
||||
}
|
||||
|
||||
public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||
{
|
||||
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||
var returnType = _typeMapper.GetReturnType(edmFunction);
|
||||
|
||||
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
|
||||
if (includeMergeOption)
|
||||
{
|
||||
callParams = ", mergeOption" + callParams;
|
||||
}
|
||||
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});",
|
||||
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
|
||||
edmFunction.Name,
|
||||
callParams);
|
||||
}
|
||||
|
||||
public string DbSet(EntitySet entitySet)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} virtual DbSet<{1}> {2} {{ get; set; }}",
|
||||
Accessibility.ForReadOnlyProperty(entitySet),
|
||||
_typeMapper.GetTypeName(entitySet.ElementType),
|
||||
_code.Escape(entitySet));
|
||||
}
|
||||
|
||||
public string DbSetInitializer(EntitySet entitySet)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} = Set<{1}>();",
|
||||
_code.Escape(entitySet),
|
||||
_typeMapper.GetTypeName(entitySet.ElementType));
|
||||
}
|
||||
|
||||
public string UsingDirectives(bool inHeader, bool includeCollections = true)
|
||||
{
|
||||
return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion())
|
||||
? string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0}using System;{1}" +
|
||||
"{2}",
|
||||
inHeader ? Environment.NewLine : "",
|
||||
includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "",
|
||||
inHeader ? "" : Environment.NewLine)
|
||||
: "";
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeMapper
|
||||
{
|
||||
private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName";
|
||||
|
||||
private readonly System.Collections.IList _errors;
|
||||
private readonly CodeGenerationTools _code;
|
||||
private readonly MetadataTools _ef;
|
||||
|
||||
public static string FixNamespaces(string typeName)
|
||||
{
|
||||
return typeName.Replace("System.Data.Spatial.", "System.Data.Entity.Spatial.");
|
||||
}
|
||||
|
||||
public TypeMapper(CodeGenerationTools code, MetadataTools ef, System.Collections.IList errors)
|
||||
{
|
||||
ArgumentNotNull(code, "code");
|
||||
ArgumentNotNull(ef, "ef");
|
||||
ArgumentNotNull(errors, "errors");
|
||||
|
||||
_code = code;
|
||||
_ef = ef;
|
||||
_errors = errors;
|
||||
}
|
||||
|
||||
public string GetTypeName(TypeUsage typeUsage)
|
||||
{
|
||||
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace: null);
|
||||
}
|
||||
|
||||
public string GetTypeName(EdmType edmType)
|
||||
{
|
||||
return GetTypeName(edmType, isNullable: null, modelNamespace: null);
|
||||
}
|
||||
|
||||
public string GetTypeName(TypeUsage typeUsage, string modelNamespace)
|
||||
{
|
||||
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace);
|
||||
}
|
||||
|
||||
public string GetTypeName(EdmType edmType, string modelNamespace)
|
||||
{
|
||||
return GetTypeName(edmType, isNullable: null, modelNamespace: modelNamespace);
|
||||
}
|
||||
|
||||
public string GetTypeName(EdmType edmType, bool? isNullable, string modelNamespace)
|
||||
{
|
||||
if (edmType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var collectionType = edmType as CollectionType;
|
||||
if (collectionType != null)
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", GetTypeName(collectionType.TypeUsage, modelNamespace));
|
||||
}
|
||||
|
||||
var typeName = _code.Escape(edmType.MetadataProperties
|
||||
.Where(p => p.Name == ExternalTypeNameAttributeName)
|
||||
.Select(p => (string)p.Value)
|
||||
.FirstOrDefault())
|
||||
?? (modelNamespace != null && edmType.NamespaceName != modelNamespace ?
|
||||
_code.CreateFullName(_code.EscapeNamespace(edmType.NamespaceName), _code.Escape(edmType)) :
|
||||
_code.Escape(edmType));
|
||||
|
||||
if (edmType is StructuralType)
|
||||
{
|
||||
return typeName;
|
||||
}
|
||||
|
||||
if (edmType is SimpleType)
|
||||
{
|
||||
var clrType = UnderlyingClrType(edmType);
|
||||
if (!IsEnumType(edmType))
|
||||
{
|
||||
typeName = _code.Escape(clrType);
|
||||
}
|
||||
|
||||
typeName = FixNamespaces(typeName);
|
||||
|
||||
return clrType.IsValueType && isNullable == true ?
|
||||
String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName) :
|
||||
typeName;
|
||||
}
|
||||
|
||||
throw new ArgumentException("edmType");
|
||||
}
|
||||
|
||||
public Type UnderlyingClrType(EdmType edmType)
|
||||
{
|
||||
ArgumentNotNull(edmType, "edmType");
|
||||
|
||||
var primitiveType = edmType as PrimitiveType;
|
||||
if (primitiveType != null)
|
||||
{
|
||||
return primitiveType.ClrEquivalentType;
|
||||
}
|
||||
|
||||
if (IsEnumType(edmType))
|
||||
{
|
||||
return GetEnumUnderlyingType(edmType).ClrEquivalentType;
|
||||
}
|
||||
|
||||
return typeof(object);
|
||||
}
|
||||
|
||||
public object GetEnumMemberValue(MetadataItem enumMember)
|
||||
{
|
||||
ArgumentNotNull(enumMember, "enumMember");
|
||||
|
||||
var valueProperty = enumMember.GetType().GetProperty("Value");
|
||||
return valueProperty == null ? null : valueProperty.GetValue(enumMember, null);
|
||||
}
|
||||
|
||||
public string GetEnumMemberName(MetadataItem enumMember)
|
||||
{
|
||||
ArgumentNotNull(enumMember, "enumMember");
|
||||
|
||||
var nameProperty = enumMember.GetType().GetProperty("Name");
|
||||
return nameProperty == null ? null : (string)nameProperty.GetValue(enumMember, null);
|
||||
}
|
||||
|
||||
public System.Collections.IEnumerable GetEnumMembers(EdmType enumType)
|
||||
{
|
||||
ArgumentNotNull(enumType, "enumType");
|
||||
|
||||
var membersProperty = enumType.GetType().GetProperty("Members");
|
||||
return membersProperty != null
|
||||
? (System.Collections.IEnumerable)membersProperty.GetValue(enumType, null)
|
||||
: Enumerable.Empty<MetadataItem>();
|
||||
}
|
||||
|
||||
public bool EnumIsFlags(EdmType enumType)
|
||||
{
|
||||
ArgumentNotNull(enumType, "enumType");
|
||||
|
||||
var isFlagsProperty = enumType.GetType().GetProperty("IsFlags");
|
||||
return isFlagsProperty != null && (bool)isFlagsProperty.GetValue(enumType, null);
|
||||
}
|
||||
|
||||
public bool IsEnumType(GlobalItem edmType)
|
||||
{
|
||||
ArgumentNotNull(edmType, "edmType");
|
||||
|
||||
return edmType.GetType().Name == "EnumType";
|
||||
}
|
||||
|
||||
public PrimitiveType GetEnumUnderlyingType(EdmType enumType)
|
||||
{
|
||||
ArgumentNotNull(enumType, "enumType");
|
||||
|
||||
return (PrimitiveType)enumType.GetType().GetProperty("UnderlyingType").GetValue(enumType, null);
|
||||
}
|
||||
|
||||
public string CreateLiteral(object value)
|
||||
{
|
||||
if (value == null || value.GetType() != typeof(TimeSpan))
|
||||
{
|
||||
return _code.CreateLiteral(value);
|
||||
}
|
||||
|
||||
return string.Format(CultureInfo.InvariantCulture, "new TimeSpan({0})", ((TimeSpan)value).Ticks);
|
||||
}
|
||||
|
||||
public bool VerifyCaseInsensitiveTypeUniqueness(IEnumerable<string> types, string sourceFile)
|
||||
{
|
||||
ArgumentNotNull(types, "types");
|
||||
ArgumentNotNull(sourceFile, "sourceFile");
|
||||
|
||||
var hash = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
|
||||
if (types.Any(item => !hash.Add(item)))
|
||||
{
|
||||
_errors.Add(
|
||||
new CompilerError(sourceFile, -1, -1, "6023",
|
||||
String.Format(CultureInfo.CurrentCulture, CodeGenerationTools.GetResourceString("Template_CaseInsensitiveTypeConflict"))));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<SimpleType> GetEnumItemsToGenerate(IEnumerable<GlobalItem> itemCollection)
|
||||
{
|
||||
return GetItemsToGenerate<SimpleType>(itemCollection)
|
||||
.Where(e => IsEnumType(e));
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetItemsToGenerate<T>(IEnumerable<GlobalItem> itemCollection) where T: EdmType
|
||||
{
|
||||
return itemCollection
|
||||
.OfType<T>()
|
||||
.Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName))
|
||||
.OrderBy(i => i.Name);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllGlobalItems(IEnumerable<GlobalItem> itemCollection)
|
||||
{
|
||||
return itemCollection
|
||||
.Where(i => i is EntityType || i is ComplexType || i is EntityContainer || IsEnumType(i))
|
||||
.Select(g => GetGlobalItemName(g));
|
||||
}
|
||||
|
||||
public string GetGlobalItemName(GlobalItem item)
|
||||
{
|
||||
if (item is EdmType)
|
||||
{
|
||||
return ((EdmType)item).Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((EntityContainer)item).Name;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetSimpleProperties(EntityType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetSimpleProperties(ComplexType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetComplexProperties(EntityType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetComplexProperties(ComplexType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(EntityType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(ComplexType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null);
|
||||
}
|
||||
|
||||
public IEnumerable<NavigationProperty> GetNavigationProperties(EntityType type)
|
||||
{
|
||||
return type.NavigationProperties.Where(np => np.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<NavigationProperty> GetCollectionNavigationProperties(EntityType type)
|
||||
{
|
||||
return type.NavigationProperties.Where(np => np.DeclaringType == type && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many);
|
||||
}
|
||||
|
||||
public FunctionParameter GetReturnParameter(EdmFunction edmFunction)
|
||||
{
|
||||
ArgumentNotNull(edmFunction, "edmFunction");
|
||||
|
||||
var returnParamsProperty = edmFunction.GetType().GetProperty("ReturnParameters");
|
||||
return returnParamsProperty == null
|
||||
? edmFunction.ReturnParameter
|
||||
: ((IEnumerable<FunctionParameter>)returnParamsProperty.GetValue(edmFunction, null)).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool IsComposable(EdmFunction edmFunction)
|
||||
{
|
||||
ArgumentNotNull(edmFunction, "edmFunction");
|
||||
|
||||
var isComposableProperty = edmFunction.GetType().GetProperty("IsComposableAttribute");
|
||||
return isComposableProperty != null && (bool)isComposableProperty.GetValue(edmFunction, null);
|
||||
}
|
||||
|
||||
public IEnumerable<FunctionImportParameter> GetParameters(EdmFunction edmFunction)
|
||||
{
|
||||
return FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef);
|
||||
}
|
||||
|
||||
public TypeUsage GetReturnType(EdmFunction edmFunction)
|
||||
{
|
||||
var returnParam = GetReturnParameter(edmFunction);
|
||||
return returnParam == null ? null : _ef.GetElementType(returnParam.TypeUsage);
|
||||
}
|
||||
|
||||
public bool GenerateMergeOptionFunction(EdmFunction edmFunction, bool includeMergeOption)
|
||||
{
|
||||
var returnType = GetReturnType(edmFunction);
|
||||
return !includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ArgumentNotNull<T>(T arg, string name) where T : class
|
||||
{
|
||||
if (arg == null)
|
||||
{
|
||||
throw new ArgumentNullException(name);
|
||||
}
|
||||
}
|
||||
#>
|
||||
1543
Model.Designer.cs
generated
1543
Model.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
9
Model.cs
Normal file
9
Model.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated from a template.
|
||||
//
|
||||
// Manual changes to this file may cause unexpected behavior in your application.
|
||||
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
101
Model.edmx
101
Model.edmx
@@ -4,55 +4,36 @@
|
||||
<edmx:Runtime>
|
||||
<!-- SSDL content -->
|
||||
<edmx:StorageModels>
|
||||
<Schema Namespace="FeedCenterModel.Store" Alias="Self" Provider="System.Data.SqlServerCe.4.0" ProviderManifestToken="4.0" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
|
||||
<EntityContainer Name="FeedCenterModelStoreContainer">
|
||||
<EntitySet Name="Category" EntityType="FeedCenterModel.Store.Category" store:Type="Tables" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" />
|
||||
<EntitySet Name="Feed" EntityType="FeedCenterModel.Store.Feed" store:Type="Tables" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" />
|
||||
<EntitySet Name="FeedAction" EntityType="FeedCenterModel.Store.FeedAction" store:Type="Tables" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" />
|
||||
<EntitySet Name="FeedItem" EntityType="FeedCenterModel.Store.FeedItem" store:Type="Tables" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" />
|
||||
<EntitySet Name="Setting" EntityType="FeedCenterModel.Store.Setting" store:Type="Tables" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" />
|
||||
<AssociationSet Name="FK_Feed_Category" Association="FeedCenterModel.Store.FK_Feed_Category">
|
||||
<End Role="Category" EntitySet="Category" />
|
||||
<End Role="Feed" EntitySet="Feed" />
|
||||
</AssociationSet>
|
||||
<AssociationSet Name="FK_FeedAction_Feed" Association="FeedCenterModel.Store.FK_FeedAction_Feed">
|
||||
<End Role="Feed" EntitySet="Feed" />
|
||||
<End Role="FeedAction" EntitySet="FeedAction" />
|
||||
</AssociationSet>
|
||||
<AssociationSet Name="FK_FeedItem_Feed" Association="FeedCenterModel.Store.FK_FeedItem_Feed">
|
||||
<End Role="Feed" EntitySet="Feed" />
|
||||
<End Role="FeedItem" EntitySet="FeedItem" />
|
||||
</AssociationSet>
|
||||
</EntityContainer>
|
||||
<Schema Namespace="FeedCenterModel.Store" Provider="System.Data.SqlServerCe.4.0" ProviderManifestToken="4.0" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
|
||||
<EntityType Name="Category">
|
||||
<Key>
|
||||
<PropertyRef Name="ID" />
|
||||
</Key>
|
||||
<Property Name="ID" Type="uniqueidentifier" Nullable="false" />
|
||||
<Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Name" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
</EntityType>
|
||||
<EntityType Name="Feed">
|
||||
<Key>
|
||||
<PropertyRef Name="ID" />
|
||||
</Key>
|
||||
<Property Name="ID" Type="uniqueidentifier" Nullable="false" />
|
||||
<Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Title" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Source" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Link" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Name" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Title" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Source" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Link" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Description" Type="ntext" Nullable="false" />
|
||||
<Property Name="LastChecked" Type="datetime" Nullable="false" />
|
||||
<Property Name="CheckInterval" Type="int" Nullable="false" />
|
||||
<Property Name="Enabled" Type="bit" Nullable="false" />
|
||||
<Property Name="Authenticate" Type="bit" Nullable="false" />
|
||||
<Property Name="Username" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Password" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Domain" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Username" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Password" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Domain" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="LastReadResult" Type="int" Nullable="false" />
|
||||
<Property Name="LastUpdated" Type="datetime" Nullable="false" />
|
||||
<Property Name="ItemComparison" Type="tinyint" Nullable="false" />
|
||||
<Property Name="CategoryID" Type="uniqueidentifier" Nullable="false" />
|
||||
<Property Name="MultipleOpenAction" Type="int" Nullable="false" />
|
||||
<Property Name="MultipleOpenAction" Type="int" Nullable="false" />
|
||||
</EntityType>
|
||||
<EntityType Name="FeedAction">
|
||||
<Key>
|
||||
@@ -61,8 +42,8 @@
|
||||
<Property Name="ID" Type="uniqueidentifier" Nullable="false" />
|
||||
<Property Name="FeedID" Type="uniqueidentifier" Nullable="false" />
|
||||
<Property Name="Field" Type="int" Nullable="false" />
|
||||
<Property Name="Search" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Replace" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Search" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Replace" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Sequence" Type="int" Nullable="false" />
|
||||
</EntityType>
|
||||
<EntityType Name="FeedItem">
|
||||
@@ -72,26 +53,26 @@
|
||||
<Property Name="ID" Type="uniqueidentifier" Nullable="false" />
|
||||
<Property Name="FeedID" Type="uniqueidentifier" Nullable="false" />
|
||||
<Property Name="Title" Type="ntext" Nullable="false" />
|
||||
<Property Name="Link" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Link" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
<Property Name="Description" Type="ntext" Nullable="false" />
|
||||
<Property Name="BeenRead" Type="bit" Nullable="false" />
|
||||
<Property Name="LastFound" Type="datetime" Nullable="false" />
|
||||
<Property Name="New" Type="bit" Nullable="false" />
|
||||
<Property Name="Sequence" Type="int" Nullable="false" />
|
||||
<Property Name="Guid" Type="nvarchar" Nullable="false" MaxLength="1000" />
|
||||
<Property Name="Guid" Type="nvarchar" MaxLength="1000" Nullable="false" />
|
||||
</EntityType>
|
||||
<EntityType Name="Setting">
|
||||
<Key>
|
||||
<PropertyRef Name="Name" />
|
||||
<PropertyRef Name="Version" />
|
||||
</Key>
|
||||
<Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="500" />
|
||||
<Property Name="Value" Type="nvarchar" Nullable="false" MaxLength="3500" />
|
||||
<Property Name="Version" Type="nvarchar" Nullable="false" MaxLength="50" />
|
||||
<Property Name="Name" Type="nvarchar" MaxLength="500" Nullable="false" />
|
||||
<Property Name="Value" Type="nvarchar" MaxLength="3500" Nullable="false" />
|
||||
<Property Name="Version" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||
</EntityType>
|
||||
<Association Name="FK_Feed_Category">
|
||||
<End Role="Category" Type="FeedCenterModel.Store.Category" Multiplicity="1" />
|
||||
<End Role="Feed" Type="FeedCenterModel.Store.Feed" Multiplicity="*" />
|
||||
<End Role="Category" Type="Self.Category" Multiplicity="1" />
|
||||
<End Role="Feed" Type="Self.Feed" Multiplicity="*" />
|
||||
<ReferentialConstraint>
|
||||
<Principal Role="Category">
|
||||
<PropertyRef Name="ID" />
|
||||
@@ -102,10 +83,10 @@
|
||||
</ReferentialConstraint>
|
||||
</Association>
|
||||
<Association Name="FK_FeedAction_Feed">
|
||||
<End Role="Feed" Type="FeedCenterModel.Store.Feed" Multiplicity="1">
|
||||
<End Role="Feed" Type="Self.Feed" Multiplicity="1">
|
||||
<OnDelete Action="Cascade" />
|
||||
</End>
|
||||
<End Role="FeedAction" Type="FeedCenterModel.Store.FeedAction" Multiplicity="*" />
|
||||
<End Role="FeedAction" Type="Self.FeedAction" Multiplicity="*" />
|
||||
<ReferentialConstraint>
|
||||
<Principal Role="Feed">
|
||||
<PropertyRef Name="ID" />
|
||||
@@ -116,10 +97,10 @@
|
||||
</ReferentialConstraint>
|
||||
</Association>
|
||||
<Association Name="FK_FeedItem_Feed">
|
||||
<End Role="Feed" Type="FeedCenterModel.Store.Feed" Multiplicity="1">
|
||||
<End Role="Feed" Type="Self.Feed" Multiplicity="1">
|
||||
<OnDelete Action="Cascade" />
|
||||
</End>
|
||||
<End Role="FeedItem" Type="FeedCenterModel.Store.FeedItem" Multiplicity="*" />
|
||||
<End Role="FeedItem" Type="Self.FeedItem" Multiplicity="*" />
|
||||
<ReferentialConstraint>
|
||||
<Principal Role="Feed">
|
||||
<PropertyRef Name="ID" />
|
||||
@@ -129,6 +110,25 @@
|
||||
</Dependent>
|
||||
</ReferentialConstraint>
|
||||
</Association>
|
||||
<EntityContainer Name="FeedCenterModelStoreContainer">
|
||||
<EntitySet Name="Category" EntityType="Self.Category" store:Type="Tables" />
|
||||
<EntitySet Name="Feed" EntityType="Self.Feed" store:Type="Tables" />
|
||||
<EntitySet Name="FeedAction" EntityType="Self.FeedAction" store:Type="Tables" />
|
||||
<EntitySet Name="FeedItem" EntityType="Self.FeedItem" store:Type="Tables" />
|
||||
<EntitySet Name="Setting" EntityType="Self.Setting" store:Type="Tables" />
|
||||
<AssociationSet Name="FK_Feed_Category" Association="Self.FK_Feed_Category">
|
||||
<End Role="Category" EntitySet="Category" />
|
||||
<End Role="Feed" EntitySet="Feed" />
|
||||
</AssociationSet>
|
||||
<AssociationSet Name="FK_FeedAction_Feed" Association="Self.FK_FeedAction_Feed">
|
||||
<End Role="Feed" EntitySet="Feed" />
|
||||
<End Role="FeedAction" EntitySet="FeedAction" />
|
||||
</AssociationSet>
|
||||
<AssociationSet Name="FK_FeedItem_Feed" Association="Self.FK_FeedItem_Feed">
|
||||
<End Role="Feed" EntitySet="Feed" />
|
||||
<End Role="FeedItem" EntitySet="FeedItem" />
|
||||
</AssociationSet>
|
||||
</EntityContainer>
|
||||
</Schema></edmx:StorageModels>
|
||||
<!-- CSDL content -->
|
||||
<edmx:ConceptualModels>
|
||||
@@ -170,21 +170,21 @@
|
||||
<Property Type="String" Name="Source" Nullable="false" MaxLength="1000" FixedLength="false" Unicode="true" DefaultValue="" />
|
||||
<Property Type="String" Name="Link" Nullable="false" MaxLength="1000" FixedLength="false" Unicode="true" DefaultValue="" />
|
||||
<Property Type="String" Name="Description" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" DefaultValue="" />
|
||||
<Property Type="DateTime" Name="LastChecked" Nullable="false" DefaultValue="1900-01-01 00:00:00.000Z" />
|
||||
<Property Type="DateTime" Name="LastChecked" Nullable="false" DefaultValue="1900-01-01 00:00:00.000Z" Precision="3" />
|
||||
<Property Type="Int32" Name="CheckInterval" Nullable="false" DefaultValue="60" />
|
||||
<Property Type="Boolean" Name="Enabled" Nullable="false" DefaultValue="True" />
|
||||
<Property Type="Boolean" Name="Authenticate" Nullable="false" DefaultValue="False" />
|
||||
<Property Type="String" Name="Username" Nullable="false" MaxLength="1000" FixedLength="false" Unicode="true" DefaultValue="" />
|
||||
<Property Type="String" Name="Password" Nullable="false" MaxLength="1000" FixedLength="false" Unicode="true" DefaultValue="" />
|
||||
<Property Type="String" Name="Domain" Nullable="false" MaxLength="1000" FixedLength="false" Unicode="true" DefaultValue="" />
|
||||
<Property Type="Int32" Name="LastReadResult" Nullable="false" />
|
||||
<Property Type="DateTime" Name="LastUpdated" Nullable="false" DefaultValue="1900-01-01 00:00:00.000Z" />
|
||||
<Property Type="Byte" Name="ItemComparison" Nullable="false" DefaultValue="0" />
|
||||
<Property Type="FeedCenterModel.FeedReadResult" Name="LastReadResult" Nullable="false" />
|
||||
<Property Type="DateTime" Name="LastUpdated" Nullable="false" DefaultValue="1900-01-01 00:00:00.000Z" Precision="3" />
|
||||
<Property Type="FeedCenterModel.FeedItemComparison" Name="ItemComparison" Nullable="false" />
|
||||
<Property Type="Guid" Name="CategoryID" Nullable="false" />
|
||||
<NavigationProperty Name="Category" Relationship="FeedCenterModel.FK_Feed_Category" FromRole="Feed" ToRole="Category" />
|
||||
<NavigationProperty Name="Actions" Relationship="FeedCenterModel.FK_FeedAction_Feed" FromRole="Feed" ToRole="FeedAction" />
|
||||
<NavigationProperty Name="Items" Relationship="FeedCenterModel.FK_FeedItem_Feed" FromRole="Feed" ToRole="FeedItem" />
|
||||
<Property Type="Int32" Name="MultipleOpenAction" Nullable="false" DefaultValue="0" />
|
||||
<Property Type="FeedCenterModel.MultipleOpenAction" Name="MultipleOpenAction" Nullable="false" />
|
||||
</EntityType>
|
||||
<EntityType Name="FeedAction">
|
||||
<Key>
|
||||
@@ -208,7 +208,7 @@
|
||||
<Property Type="String" Name="Link" Nullable="false" MaxLength="1000" FixedLength="false" Unicode="true" DefaultValue="" />
|
||||
<Property Type="String" Name="Description" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" DefaultValue="" />
|
||||
<Property Type="Boolean" Name="BeenRead" Nullable="false" />
|
||||
<Property Type="DateTime" Name="LastFound" Nullable="false" DefaultValue="1900-01-01 00:00:00.000Z" />
|
||||
<Property Type="DateTime" Name="LastFound" Nullable="false" DefaultValue="1900-01-01 00:00:00.000Z" Precision="3" />
|
||||
<Property Type="Boolean" Name="New" Nullable="false" />
|
||||
<NavigationProperty Name="Feed" Relationship="FeedCenterModel.FK_FeedItem_Feed" FromRole="FeedItem" ToRole="Feed" />
|
||||
<Property Type="String" Name="Guid" Nullable="false" MaxLength="1000" FixedLength="false" Unicode="true" />
|
||||
@@ -259,6 +259,9 @@
|
||||
</Dependent>
|
||||
</ReferentialConstraint>
|
||||
</Association>
|
||||
<EnumType Name="FeedReadResult" a:ExternalTypeName="FeedCenter.FeedReadResult" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" />
|
||||
<EnumType Name="FeedItemComparison" UnderlyingType="Byte" a:ExternalTypeName="FeedCenter.FeedItemComparison" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" />
|
||||
<EnumType Name="MultipleOpenAction" a:ExternalTypeName="FeedCenter.MultipleOpenAction" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" />
|
||||
</Schema>
|
||||
</edmx:ConceptualModels>
|
||||
<!-- C-S mapping content -->
|
||||
@@ -350,6 +353,8 @@
|
||||
<DesignerProperty Name="ValidateOnBuild" Value="true" />
|
||||
<DesignerProperty Name="EnablePluralization" Value="True" />
|
||||
<DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
|
||||
<DesignerProperty Name="CodeGenerationStrategy" Value="None" />
|
||||
<DesignerProperty Name="UseLegacyProvider" Value="False" />
|
||||
</DesignerInfoPropertySet>
|
||||
</Options>
|
||||
<!-- Diagram content (shape and connector positions) -->
|
||||
|
||||
726
Model.tt
Normal file
726
Model.tt
Normal file
@@ -0,0 +1,726 @@
|
||||
<#@ template language="C#" debug="false" hostspecific="true"#>
|
||||
<#@ include file="EF6.Utility.CS.ttinclude"#><#@
|
||||
output extension=".cs"#><#
|
||||
|
||||
const string inputFile = @"Model.edmx";
|
||||
var textTransform = DynamicTextTransformation.Create(this);
|
||||
var code = new CodeGenerationTools(this);
|
||||
var ef = new MetadataTools(this);
|
||||
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
|
||||
var fileManager = EntityFrameworkTemplateFileManager.Create(this);
|
||||
var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile);
|
||||
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef);
|
||||
|
||||
if (!typeMapper.VerifyCaseInsensitiveTypeUniqueness(typeMapper.GetAllGlobalItems(itemCollection), inputFile))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
WriteHeader(codeStringGenerator, fileManager);
|
||||
|
||||
foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection))
|
||||
{
|
||||
fileManager.StartNewFile(entity.Name + ".cs");
|
||||
BeginNamespace(code);
|
||||
#>
|
||||
<#=codeStringGenerator.UsingDirectives(inHeader: false)#>
|
||||
<#=codeStringGenerator.EntityClassOpening(entity)#>
|
||||
{
|
||||
<#
|
||||
var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(entity);
|
||||
var collectionNavigationProperties = typeMapper.GetCollectionNavigationProperties(entity);
|
||||
var complexProperties = typeMapper.GetComplexProperties(entity);
|
||||
|
||||
if (propertiesWithDefaultValues.Any() || collectionNavigationProperties.Any() || complexProperties.Any())
|
||||
{
|
||||
#>
|
||||
public <#=code.Escape(entity)#>()
|
||||
{
|
||||
<#
|
||||
foreach (var edmProperty in propertiesWithDefaultValues)
|
||||
{
|
||||
#>
|
||||
this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>;
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var navigationProperty in collectionNavigationProperties)
|
||||
{
|
||||
#>
|
||||
this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>();
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var complexProperty in complexProperties)
|
||||
{
|
||||
#>
|
||||
this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>();
|
||||
<#
|
||||
}
|
||||
#>
|
||||
}
|
||||
|
||||
<#
|
||||
}
|
||||
|
||||
var simpleProperties = typeMapper.GetSimpleProperties(entity);
|
||||
if (simpleProperties.Any())
|
||||
{
|
||||
foreach (var edmProperty in simpleProperties)
|
||||
{
|
||||
#>
|
||||
<#=codeStringGenerator.Property(edmProperty)#>
|
||||
<#
|
||||
}
|
||||
}
|
||||
|
||||
if (complexProperties.Any())
|
||||
{
|
||||
#>
|
||||
|
||||
<#
|
||||
foreach(var complexProperty in complexProperties)
|
||||
{
|
||||
#>
|
||||
<#=codeStringGenerator.Property(complexProperty)#>
|
||||
<#
|
||||
}
|
||||
}
|
||||
|
||||
var navigationProperties = typeMapper.GetNavigationProperties(entity);
|
||||
if (navigationProperties.Any())
|
||||
{
|
||||
#>
|
||||
|
||||
<#
|
||||
foreach (var navigationProperty in navigationProperties)
|
||||
{
|
||||
#>
|
||||
<#=codeStringGenerator.NavigationProperty(navigationProperty)#>
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
}
|
||||
<#
|
||||
EndNamespace(code);
|
||||
}
|
||||
|
||||
foreach (var complex in typeMapper.GetItemsToGenerate<ComplexType>(itemCollection))
|
||||
{
|
||||
fileManager.StartNewFile(complex.Name + ".cs");
|
||||
BeginNamespace(code);
|
||||
#>
|
||||
<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#>
|
||||
<#=Accessibility.ForType(complex)#> partial class <#=code.Escape(complex)#>
|
||||
{
|
||||
<#
|
||||
var complexProperties = typeMapper.GetComplexProperties(complex);
|
||||
var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(complex);
|
||||
|
||||
if (propertiesWithDefaultValues.Any() || complexProperties.Any())
|
||||
{
|
||||
#>
|
||||
public <#=code.Escape(complex)#>()
|
||||
{
|
||||
<#
|
||||
foreach (var edmProperty in propertiesWithDefaultValues)
|
||||
{
|
||||
#>
|
||||
this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>;
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var complexProperty in complexProperties)
|
||||
{
|
||||
#>
|
||||
this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>();
|
||||
<#
|
||||
}
|
||||
#>
|
||||
}
|
||||
|
||||
<#
|
||||
}
|
||||
|
||||
var simpleProperties = typeMapper.GetSimpleProperties(complex);
|
||||
if (simpleProperties.Any())
|
||||
{
|
||||
foreach(var edmProperty in simpleProperties)
|
||||
{
|
||||
#>
|
||||
<#=codeStringGenerator.Property(edmProperty)#>
|
||||
<#
|
||||
}
|
||||
}
|
||||
|
||||
if (complexProperties.Any())
|
||||
{
|
||||
#>
|
||||
|
||||
<#
|
||||
foreach(var edmProperty in complexProperties)
|
||||
{
|
||||
#>
|
||||
<#=codeStringGenerator.Property(edmProperty)#>
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
}
|
||||
<#
|
||||
EndNamespace(code);
|
||||
}
|
||||
|
||||
foreach (var enumType in typeMapper.GetEnumItemsToGenerate(itemCollection))
|
||||
{
|
||||
fileManager.StartNewFile(enumType.Name + ".cs");
|
||||
BeginNamespace(code);
|
||||
#>
|
||||
<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#>
|
||||
<#
|
||||
if (typeMapper.EnumIsFlags(enumType))
|
||||
{
|
||||
#>
|
||||
[Flags]
|
||||
<#
|
||||
}
|
||||
#>
|
||||
<#=codeStringGenerator.EnumOpening(enumType)#>
|
||||
{
|
||||
<#
|
||||
var foundOne = false;
|
||||
|
||||
foreach (MetadataItem member in typeMapper.GetEnumMembers(enumType))
|
||||
{
|
||||
foundOne = true;
|
||||
#>
|
||||
<#=code.Escape(typeMapper.GetEnumMemberName(member))#> = <#=typeMapper.GetEnumMemberValue(member)#>,
|
||||
<#
|
||||
}
|
||||
|
||||
if (foundOne)
|
||||
{
|
||||
this.GenerationEnvironment.Remove(this.GenerationEnvironment.Length - 3, 1);
|
||||
}
|
||||
#>
|
||||
}
|
||||
<#
|
||||
EndNamespace(code);
|
||||
}
|
||||
|
||||
fileManager.Process();
|
||||
|
||||
#>
|
||||
<#+
|
||||
|
||||
public void WriteHeader(CodeStringGenerator codeStringGenerator, EntityFrameworkTemplateFileManager fileManager)
|
||||
{
|
||||
fileManager.StartHeader();
|
||||
#>
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine1")#>
|
||||
//
|
||||
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine2")#>
|
||||
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine3")#>
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
<#=codeStringGenerator.UsingDirectives(inHeader: true)#>
|
||||
<#+
|
||||
fileManager.EndBlock();
|
||||
}
|
||||
|
||||
public void BeginNamespace(CodeGenerationTools code)
|
||||
{
|
||||
var codeNamespace = code.VsNamespaceSuggestion();
|
||||
if (!String.IsNullOrEmpty(codeNamespace))
|
||||
{
|
||||
#>
|
||||
namespace <#=code.EscapeNamespace(codeNamespace)#>
|
||||
{
|
||||
<#+
|
||||
PushIndent(" ");
|
||||
}
|
||||
}
|
||||
|
||||
public void EndNamespace(CodeGenerationTools code)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(code.VsNamespaceSuggestion()))
|
||||
{
|
||||
PopIndent();
|
||||
#>
|
||||
}
|
||||
<#+
|
||||
}
|
||||
}
|
||||
|
||||
public const string TemplateId = "CSharp_DbContext_Types_EF6";
|
||||
|
||||
public class CodeStringGenerator
|
||||
{
|
||||
private readonly CodeGenerationTools _code;
|
||||
private readonly TypeMapper _typeMapper;
|
||||
private readonly MetadataTools _ef;
|
||||
|
||||
public CodeStringGenerator(CodeGenerationTools code, TypeMapper typeMapper, MetadataTools ef)
|
||||
{
|
||||
ArgumentNotNull(code, "code");
|
||||
ArgumentNotNull(typeMapper, "typeMapper");
|
||||
ArgumentNotNull(ef, "ef");
|
||||
|
||||
_code = code;
|
||||
_typeMapper = typeMapper;
|
||||
_ef = ef;
|
||||
}
|
||||
|
||||
public string Property(EdmProperty edmProperty)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} {1} {2} {{ {3}get; {4}set; }}",
|
||||
Accessibility.ForProperty(edmProperty),
|
||||
_typeMapper.GetTypeName(edmProperty.TypeUsage),
|
||||
_code.Escape(edmProperty),
|
||||
_code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
|
||||
_code.SpaceAfter(Accessibility.ForSetter(edmProperty)));
|
||||
}
|
||||
|
||||
public string NavigationProperty(NavigationProperty navProp)
|
||||
{
|
||||
var endType = _typeMapper.GetTypeName(navProp.ToEndMember.GetEntityType());
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} {1} {2} {{ {3}get; {4}set; }}",
|
||||
AccessibilityAndVirtual(Accessibility.ForNavigationProperty(navProp)),
|
||||
navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,
|
||||
_code.Escape(navProp),
|
||||
_code.SpaceAfter(Accessibility.ForGetter(navProp)),
|
||||
_code.SpaceAfter(Accessibility.ForSetter(navProp)));
|
||||
}
|
||||
|
||||
public string AccessibilityAndVirtual(string accessibility)
|
||||
{
|
||||
return accessibility + (accessibility != "private" ? " virtual" : "");
|
||||
}
|
||||
|
||||
public string EntityClassOpening(EntityType entity)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} {1}partial class {2}{3}",
|
||||
Accessibility.ForType(entity),
|
||||
_code.SpaceAfter(_code.AbstractOption(entity)),
|
||||
_code.Escape(entity),
|
||||
_code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType)));
|
||||
}
|
||||
|
||||
public string EnumOpening(SimpleType enumType)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} enum {1} : {2}",
|
||||
Accessibility.ForType(enumType),
|
||||
_code.Escape(enumType),
|
||||
_code.Escape(_typeMapper.UnderlyingClrType(enumType)));
|
||||
}
|
||||
|
||||
public void WriteFunctionParameters(EdmFunction edmFunction, Action<string, string, string, string> writeParameter)
|
||||
{
|
||||
var parameters = FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef);
|
||||
foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable))
|
||||
{
|
||||
var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null";
|
||||
var notNullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")";
|
||||
var nullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + TypeMapper.FixNamespaces(parameter.RawClrTypeName) + "))";
|
||||
writeParameter(parameter.LocalVariableName, isNotNull, notNullInit, nullInit);
|
||||
}
|
||||
}
|
||||
|
||||
public string ComposableFunctionMethod(EdmFunction edmFunction, string modelNamespace)
|
||||
{
|
||||
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} IQueryable<{1}> {2}({3})",
|
||||
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)),
|
||||
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace),
|
||||
_code.Escape(edmFunction),
|
||||
string.Join(", ", parameters.Select(p => TypeMapper.FixNamespaces(p.FunctionParameterType) + " " + p.FunctionParameterName).ToArray()));
|
||||
}
|
||||
|
||||
public string ComposableCreateQuery(EdmFunction edmFunction, string modelNamespace)
|
||||
{
|
||||
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<{0}>(\"[{1}].[{2}]({3})\"{4});",
|
||||
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace),
|
||||
edmFunction.NamespaceName,
|
||||
edmFunction.Name,
|
||||
string.Join(", ", parameters.Select(p => "@" + p.EsqlParameterName).ToArray()),
|
||||
_code.StringBefore(", ", string.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray())));
|
||||
}
|
||||
|
||||
public string FunctionMethod(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||
{
|
||||
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||
var returnType = _typeMapper.GetReturnType(edmFunction);
|
||||
|
||||
var paramList = String.Join(", ", parameters.Select(p => TypeMapper.FixNamespaces(p.FunctionParameterType) + " " + p.FunctionParameterName).ToArray());
|
||||
if (includeMergeOption)
|
||||
{
|
||||
paramList = _code.StringAfter(paramList, ", ") + "MergeOption mergeOption";
|
||||
}
|
||||
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} {1} {2}({3})",
|
||||
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)),
|
||||
returnType == null ? "int" : "ObjectResult<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
|
||||
_code.Escape(edmFunction),
|
||||
paramList);
|
||||
}
|
||||
|
||||
public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
|
||||
{
|
||||
var parameters = _typeMapper.GetParameters(edmFunction);
|
||||
var returnType = _typeMapper.GetReturnType(edmFunction);
|
||||
|
||||
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
|
||||
if (includeMergeOption)
|
||||
{
|
||||
callParams = ", mergeOption" + callParams;
|
||||
}
|
||||
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});",
|
||||
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
|
||||
edmFunction.Name,
|
||||
callParams);
|
||||
}
|
||||
|
||||
public string DbSet(EntitySet entitySet)
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0} virtual DbSet<{1}> {2} {{ get; set; }}",
|
||||
Accessibility.ForReadOnlyProperty(entitySet),
|
||||
_typeMapper.GetTypeName(entitySet.ElementType),
|
||||
_code.Escape(entitySet));
|
||||
}
|
||||
|
||||
public string UsingDirectives(bool inHeader, bool includeCollections = true)
|
||||
{
|
||||
return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion())
|
||||
? string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0}using System;{1}" +
|
||||
"{2}",
|
||||
inHeader ? Environment.NewLine : "",
|
||||
includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "",
|
||||
inHeader ? "" : Environment.NewLine)
|
||||
: "";
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeMapper
|
||||
{
|
||||
private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName";
|
||||
|
||||
private readonly System.Collections.IList _errors;
|
||||
private readonly CodeGenerationTools _code;
|
||||
private readonly MetadataTools _ef;
|
||||
|
||||
public TypeMapper(CodeGenerationTools code, MetadataTools ef, System.Collections.IList errors)
|
||||
{
|
||||
ArgumentNotNull(code, "code");
|
||||
ArgumentNotNull(ef, "ef");
|
||||
ArgumentNotNull(errors, "errors");
|
||||
|
||||
_code = code;
|
||||
_ef = ef;
|
||||
_errors = errors;
|
||||
}
|
||||
|
||||
public static string FixNamespaces(string typeName)
|
||||
{
|
||||
return typeName.Replace("System.Data.Spatial.", "System.Data.Entity.Spatial.");
|
||||
}
|
||||
|
||||
public string GetTypeName(TypeUsage typeUsage)
|
||||
{
|
||||
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace: null);
|
||||
}
|
||||
|
||||
public string GetTypeName(EdmType edmType)
|
||||
{
|
||||
return GetTypeName(edmType, isNullable: null, modelNamespace: null);
|
||||
}
|
||||
|
||||
public string GetTypeName(TypeUsage typeUsage, string modelNamespace)
|
||||
{
|
||||
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace);
|
||||
}
|
||||
|
||||
public string GetTypeName(EdmType edmType, string modelNamespace)
|
||||
{
|
||||
return GetTypeName(edmType, isNullable: null, modelNamespace: modelNamespace);
|
||||
}
|
||||
|
||||
public string GetTypeName(EdmType edmType, bool? isNullable, string modelNamespace)
|
||||
{
|
||||
if (edmType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var collectionType = edmType as CollectionType;
|
||||
if (collectionType != null)
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", GetTypeName(collectionType.TypeUsage, modelNamespace));
|
||||
}
|
||||
|
||||
var typeName = _code.Escape(edmType.MetadataProperties
|
||||
.Where(p => p.Name == ExternalTypeNameAttributeName)
|
||||
.Select(p => (string)p.Value)
|
||||
.FirstOrDefault())
|
||||
?? (modelNamespace != null && edmType.NamespaceName != modelNamespace ?
|
||||
_code.CreateFullName(_code.EscapeNamespace(edmType.NamespaceName), _code.Escape(edmType)) :
|
||||
_code.Escape(edmType));
|
||||
|
||||
if (edmType is StructuralType)
|
||||
{
|
||||
return typeName;
|
||||
}
|
||||
|
||||
if (edmType is SimpleType)
|
||||
{
|
||||
var clrType = UnderlyingClrType(edmType);
|
||||
if (!IsEnumType(edmType))
|
||||
{
|
||||
typeName = _code.Escape(clrType);
|
||||
}
|
||||
|
||||
typeName = FixNamespaces(typeName);
|
||||
|
||||
return clrType.IsValueType && isNullable == true ?
|
||||
String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName) :
|
||||
typeName;
|
||||
}
|
||||
|
||||
throw new ArgumentException("edmType");
|
||||
}
|
||||
|
||||
public Type UnderlyingClrType(EdmType edmType)
|
||||
{
|
||||
ArgumentNotNull(edmType, "edmType");
|
||||
|
||||
var primitiveType = edmType as PrimitiveType;
|
||||
if (primitiveType != null)
|
||||
{
|
||||
return primitiveType.ClrEquivalentType;
|
||||
}
|
||||
|
||||
if (IsEnumType(edmType))
|
||||
{
|
||||
return GetEnumUnderlyingType(edmType).ClrEquivalentType;
|
||||
}
|
||||
|
||||
return typeof(object);
|
||||
}
|
||||
|
||||
public object GetEnumMemberValue(MetadataItem enumMember)
|
||||
{
|
||||
ArgumentNotNull(enumMember, "enumMember");
|
||||
|
||||
var valueProperty = enumMember.GetType().GetProperty("Value");
|
||||
return valueProperty == null ? null : valueProperty.GetValue(enumMember, null);
|
||||
}
|
||||
|
||||
public string GetEnumMemberName(MetadataItem enumMember)
|
||||
{
|
||||
ArgumentNotNull(enumMember, "enumMember");
|
||||
|
||||
var nameProperty = enumMember.GetType().GetProperty("Name");
|
||||
return nameProperty == null ? null : (string)nameProperty.GetValue(enumMember, null);
|
||||
}
|
||||
|
||||
public System.Collections.IEnumerable GetEnumMembers(EdmType enumType)
|
||||
{
|
||||
ArgumentNotNull(enumType, "enumType");
|
||||
|
||||
var membersProperty = enumType.GetType().GetProperty("Members");
|
||||
return membersProperty != null
|
||||
? (System.Collections.IEnumerable)membersProperty.GetValue(enumType, null)
|
||||
: Enumerable.Empty<MetadataItem>();
|
||||
}
|
||||
|
||||
public bool EnumIsFlags(EdmType enumType)
|
||||
{
|
||||
ArgumentNotNull(enumType, "enumType");
|
||||
|
||||
var isFlagsProperty = enumType.GetType().GetProperty("IsFlags");
|
||||
return isFlagsProperty != null && (bool)isFlagsProperty.GetValue(enumType, null);
|
||||
}
|
||||
|
||||
public bool IsEnumType(GlobalItem edmType)
|
||||
{
|
||||
ArgumentNotNull(edmType, "edmType");
|
||||
|
||||
return edmType.GetType().Name == "EnumType";
|
||||
}
|
||||
|
||||
public PrimitiveType GetEnumUnderlyingType(EdmType enumType)
|
||||
{
|
||||
ArgumentNotNull(enumType, "enumType");
|
||||
|
||||
return (PrimitiveType)enumType.GetType().GetProperty("UnderlyingType").GetValue(enumType, null);
|
||||
}
|
||||
|
||||
public string CreateLiteral(object value)
|
||||
{
|
||||
if (value == null || value.GetType() != typeof(TimeSpan))
|
||||
{
|
||||
return _code.CreateLiteral(value);
|
||||
}
|
||||
|
||||
return string.Format(CultureInfo.InvariantCulture, "new TimeSpan({0})", ((TimeSpan)value).Ticks);
|
||||
}
|
||||
|
||||
public bool VerifyCaseInsensitiveTypeUniqueness(IEnumerable<string> types, string sourceFile)
|
||||
{
|
||||
ArgumentNotNull(types, "types");
|
||||
ArgumentNotNull(sourceFile, "sourceFile");
|
||||
|
||||
var hash = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
|
||||
if (types.Any(item => !hash.Add(item)))
|
||||
{
|
||||
_errors.Add(
|
||||
new CompilerError(sourceFile, -1, -1, "6023",
|
||||
String.Format(CultureInfo.CurrentCulture, CodeGenerationTools.GetResourceString("Template_CaseInsensitiveTypeConflict"))));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<SimpleType> GetEnumItemsToGenerate(IEnumerable<GlobalItem> itemCollection)
|
||||
{
|
||||
return GetItemsToGenerate<SimpleType>(itemCollection)
|
||||
.Where(e => IsEnumType(e));
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetItemsToGenerate<T>(IEnumerable<GlobalItem> itemCollection) where T: EdmType
|
||||
{
|
||||
return itemCollection
|
||||
.OfType<T>()
|
||||
.Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName))
|
||||
.OrderBy(i => i.Name);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllGlobalItems(IEnumerable<GlobalItem> itemCollection)
|
||||
{
|
||||
return itemCollection
|
||||
.Where(i => i is EntityType || i is ComplexType || i is EntityContainer || IsEnumType(i))
|
||||
.Select(g => GetGlobalItemName(g));
|
||||
}
|
||||
|
||||
public string GetGlobalItemName(GlobalItem item)
|
||||
{
|
||||
if (item is EdmType)
|
||||
{
|
||||
return ((EdmType)item).Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((EntityContainer)item).Name;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetSimpleProperties(EntityType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetSimpleProperties(ComplexType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetComplexProperties(EntityType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetComplexProperties(ComplexType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(EntityType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null);
|
||||
}
|
||||
|
||||
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(ComplexType type)
|
||||
{
|
||||
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null);
|
||||
}
|
||||
|
||||
public IEnumerable<NavigationProperty> GetNavigationProperties(EntityType type)
|
||||
{
|
||||
return type.NavigationProperties.Where(np => np.DeclaringType == type);
|
||||
}
|
||||
|
||||
public IEnumerable<NavigationProperty> GetCollectionNavigationProperties(EntityType type)
|
||||
{
|
||||
return type.NavigationProperties.Where(np => np.DeclaringType == type && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many);
|
||||
}
|
||||
|
||||
public FunctionParameter GetReturnParameter(EdmFunction edmFunction)
|
||||
{
|
||||
ArgumentNotNull(edmFunction, "edmFunction");
|
||||
|
||||
var returnParamsProperty = edmFunction.GetType().GetProperty("ReturnParameters");
|
||||
return returnParamsProperty == null
|
||||
? edmFunction.ReturnParameter
|
||||
: ((IEnumerable<FunctionParameter>)returnParamsProperty.GetValue(edmFunction, null)).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool IsComposable(EdmFunction edmFunction)
|
||||
{
|
||||
ArgumentNotNull(edmFunction, "edmFunction");
|
||||
|
||||
var isComposableProperty = edmFunction.GetType().GetProperty("IsComposableAttribute");
|
||||
return isComposableProperty != null && (bool)isComposableProperty.GetValue(edmFunction, null);
|
||||
}
|
||||
|
||||
public IEnumerable<FunctionImportParameter> GetParameters(EdmFunction edmFunction)
|
||||
{
|
||||
return FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef);
|
||||
}
|
||||
|
||||
public TypeUsage GetReturnType(EdmFunction edmFunction)
|
||||
{
|
||||
var returnParam = GetReturnParameter(edmFunction);
|
||||
return returnParam == null ? null : _ef.GetElementType(returnParam.TypeUsage);
|
||||
}
|
||||
|
||||
public bool GenerateMergeOptionFunction(EdmFunction edmFunction, bool includeMergeOption)
|
||||
{
|
||||
var returnType = GetReturnType(edmFunction);
|
||||
return !includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ArgumentNotNull<T>(T arg, string name) where T : class
|
||||
{
|
||||
if (arg == null)
|
||||
{
|
||||
throw new ArgumentNullException(name);
|
||||
}
|
||||
}
|
||||
#>
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
using FeedCenter.Properties;
|
||||
using FeedCenter.Properties;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
@@ -19,9 +18,9 @@ namespace FeedCenter
|
||||
_notificationIcon.DoubleClick += HandleNotificationIconDoubleClick;
|
||||
|
||||
// Setup the menu
|
||||
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
|
||||
var contextMenuStrip = new ContextMenuStrip();
|
||||
|
||||
ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem(Resources.NotificationIconContextMenuLocked, null, HandleLockWindowClicked)
|
||||
var toolStripMenuItem = new ToolStripMenuItem(Resources.NotificationIconContextMenuLocked, null, HandleLockWindowClicked)
|
||||
{
|
||||
Checked = Settings.Default.WindowLocked
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Reflection;
|
||||
|
||||
namespace FeedCenter.Options
|
||||
{
|
||||
public partial class AboutOptionsPanel
|
||||
public partial class AboutOptionsPanel
|
||||
{
|
||||
public AboutOptionsPanel()
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
xmlns:my="clr-namespace:FeedCenter.Properties"
|
||||
xmlns:Options="clr-namespace:FeedCenter.Options"
|
||||
xmlns:LinkControl="clr-namespace:Common.Wpf.LinkControl;assembly=Common.Wpf"
|
||||
xmlns:feedCenter="clr-namespace:FeedCenter"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
Icon="/FeedCenter;component/Resources/Application.ico"
|
||||
FocusManager.FocusedElement="{Binding ElementName=feedLinkFilterText}">
|
||||
@@ -97,9 +98,9 @@
|
||||
ToolTip="{x:Static my:Resources.DisableHint}"
|
||||
IsEnabled="False">
|
||||
<ComboBoxItem Content="{x:Static my:Resources.openAllMultipleToolbarButton}"
|
||||
Tag="{x:Static Options:MultipleOpenAction.IndividualPages}" />
|
||||
Tag="{x:Static feedCenter:MultipleOpenAction.IndividualPages}" />
|
||||
<ComboBoxItem Content="{x:Static my:Resources.openAllSingleToolbarButton}"
|
||||
Tag="{x:Static Options:MultipleOpenAction.SinglePage}" />
|
||||
Tag="{x:Static feedCenter:MultipleOpenAction.SinglePage}" />
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
<Button Content="{x:Static my:Resources.OkayButton}"
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using Common.Wpf;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
using Common.Wpf;
|
||||
|
||||
namespace FeedCenter.Options
|
||||
{
|
||||
public partial class BulkFeedWindow
|
||||
@@ -39,9 +38,9 @@ namespace FeedCenter.Options
|
||||
|
||||
void HandleCollectionViewSourceFilter(object sender, FilterEventArgs e)
|
||||
{
|
||||
CheckedListItem<Feed> checkedListBoxItem = (CheckedListItem<Feed>) e.Item;
|
||||
var checkedListBoxItem = (CheckedListItem<Feed>) e.Item;
|
||||
|
||||
Feed feed = checkedListBoxItem.Item;
|
||||
var feed = checkedListBoxItem.Item;
|
||||
|
||||
e.Accepted = feed.Link.Contains(feedLinkFilterText.Text);
|
||||
}
|
||||
@@ -56,7 +55,7 @@ namespace FeedCenter.Options
|
||||
foreach (var item in _checkedListBoxItems.Where(i => i.IsChecked))
|
||||
{
|
||||
if (openComboBox.IsEnabled)
|
||||
item.Item.MultipleOpenAction = (int) ((ComboBoxItem) openComboBox.SelectedItem).Tag;
|
||||
item.Item.MultipleOpenAction = (MultipleOpenAction) ((ComboBoxItem) openComboBox.SelectedItem).Tag;
|
||||
}
|
||||
|
||||
DialogResult = true;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System.Linq;
|
||||
using FeedCenter.Properties;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
|
||||
using FeedCenter.Properties;
|
||||
|
||||
namespace FeedCenter.Options
|
||||
{
|
||||
public partial class DisplayOptionsPanel
|
||||
@@ -35,13 +34,11 @@ namespace FeedCenter.Options
|
||||
if (displayEmptyFeedsCheckBox.IsChecked.HasValue && Settings.Default.DisplayEmptyFeeds != displayEmptyFeedsCheckBox.IsChecked.Value)
|
||||
Settings.Default.DisplayEmptyFeeds = displayEmptyFeedsCheckBox.IsChecked.Value;
|
||||
|
||||
Dock dock = (Dock) ((ComboBoxItem) toolbarLocationComboBox.SelectedItem).Tag;
|
||||
if (Settings.Default.ToolbarLocation != dock)
|
||||
Settings.Default.ToolbarLocation = dock;
|
||||
var dock = (Dock) ((ComboBoxItem) toolbarLocationComboBox.SelectedItem).Tag;
|
||||
Settings.Default.ToolbarLocation = dock;
|
||||
|
||||
MultipleLineDisplay multipleLineDisplay = (MultipleLineDisplay) ((ComboBoxItem) multipleLineDisplayComboBox.SelectedItem).Tag;
|
||||
if (Settings.Default.MultipleLineDisplay != multipleLineDisplay)
|
||||
Settings.Default.MultipleLineDisplay = multipleLineDisplay;
|
||||
var multipleLineDisplay = (MultipleLineDisplay) ((ComboBoxItem) multipleLineDisplayComboBox.SelectedItem).Tag;
|
||||
Settings.Default.MultipleLineDisplay = multipleLineDisplay;
|
||||
}
|
||||
|
||||
public override string CategoryName
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:Properties="clr-namespace:FeedCenter.Properties"
|
||||
xmlns:Options="clr-namespace:FeedCenter.Options"
|
||||
xmlns:feedCenter="clr-namespace:FeedCenter"
|
||||
Title="FeedWindow"
|
||||
Height="300"
|
||||
Width="450"
|
||||
@@ -10,7 +10,7 @@
|
||||
Icon="/FeedCenter;component/Resources/Application.ico"
|
||||
FocusManager.FocusedElement="{Binding ElementName=urlTextBox}">
|
||||
<Window.Resources>
|
||||
<Options:MultipleOpenActionConverter x:Key="multipleOpenActionConverter" />
|
||||
<feedCenter:MultipleOpenActionConverter x:Key="multipleOpenActionConverter" />
|
||||
</Window.Resources>
|
||||
<Grid Name="mainGrid">
|
||||
<TabControl Name="optionsTabControl"
|
||||
@@ -116,9 +116,9 @@
|
||||
Margin="6">
|
||||
|
||||
<ComboBoxItem Content="{x:Static Properties:Resources.openAllSingleToolbarButton}"
|
||||
Tag="{x:Static Options:MultipleOpenAction.SinglePage}" />
|
||||
Tag="{x:Static feedCenter:MultipleOpenAction.SinglePage}" />
|
||||
<ComboBoxItem Content="{x:Static Properties:Resources.openAllMultipleToolbarButton}"
|
||||
Tag="{x:Static Options:MultipleOpenAction.IndividualPages}" />
|
||||
Tag="{x:Static feedCenter:MultipleOpenAction.IndividualPages}" />
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Win32;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
@@ -6,7 +7,6 @@ using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Xml;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace FeedCenter.Options
|
||||
{
|
||||
@@ -27,7 +27,7 @@ namespace FeedCenter.Options
|
||||
{
|
||||
base.LoadPanel(database);
|
||||
|
||||
CollectionViewSource collectionViewSource = new CollectionViewSource { Source = Database.AllCategories };
|
||||
var collectionViewSource = new CollectionViewSource { Source = Database.AllCategories };
|
||||
collectionViewSource.SortDescriptions.Add(new SortDescription("SortKey", ListSortDirection.Ascending));
|
||||
collectionViewSource.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
|
||||
|
||||
@@ -61,15 +61,15 @@ namespace FeedCenter.Options
|
||||
|
||||
private void AddFeed()
|
||||
{
|
||||
Feed feed = new Feed();
|
||||
var feed = Feed.Create();
|
||||
|
||||
FeedWindow feedWindow = new FeedWindow();
|
||||
var feedWindow = new FeedWindow();
|
||||
|
||||
bool? result = feedWindow.Display(Database, feed, Window.GetWindow(this));
|
||||
var result = feedWindow.Display(Database, feed, Window.GetWindow(this));
|
||||
|
||||
if (result.HasValue && result.Value)
|
||||
{
|
||||
Database.Feeds.AddObject(feed);
|
||||
Database.Feeds.Add(feed);
|
||||
|
||||
feedListBox.SelectedItem = feed;
|
||||
|
||||
@@ -82,18 +82,18 @@ namespace FeedCenter.Options
|
||||
if (feedListBox.SelectedItem == null)
|
||||
return;
|
||||
|
||||
Feed feed = (Feed) feedListBox.SelectedItem;
|
||||
var feed = (Feed) feedListBox.SelectedItem;
|
||||
|
||||
FeedWindow feedWindow = new FeedWindow();
|
||||
var feedWindow = new FeedWindow();
|
||||
|
||||
feedWindow.Display(Database, feed, Window.GetWindow(this));
|
||||
}
|
||||
|
||||
private void DeleteSelectedFeed()
|
||||
{
|
||||
Feed feed = (Feed) feedListBox.SelectedItem;
|
||||
var feed = (Feed) feedListBox.SelectedItem;
|
||||
|
||||
Database.Feeds.DeleteObject(feed);
|
||||
Database.Feeds.Remove(feed);
|
||||
|
||||
SetFeedButtonStates();
|
||||
}
|
||||
@@ -134,20 +134,20 @@ namespace FeedCenter.Options
|
||||
private void ExportFeeds()
|
||||
{
|
||||
// Setup the save file dialog
|
||||
SaveFileDialog saveFileDialog = new SaveFileDialog
|
||||
var saveFileDialog = new SaveFileDialog
|
||||
{
|
||||
Filter = Properties.Resources.ImportExportFilter,
|
||||
FilterIndex = 0,
|
||||
OverwritePrompt = true
|
||||
};
|
||||
|
||||
bool? result = saveFileDialog.ShowDialog();
|
||||
var result = saveFileDialog.ShowDialog();
|
||||
|
||||
if (!result.Value)
|
||||
if (!result.GetValueOrDefault(false))
|
||||
return;
|
||||
|
||||
// Setup the writer settings
|
||||
XmlWriterSettings writerSettings = new XmlWriterSettings
|
||||
var writerSettings = new XmlWriterSettings
|
||||
{
|
||||
Indent = true,
|
||||
CheckCharacters = true,
|
||||
@@ -155,7 +155,7 @@ namespace FeedCenter.Options
|
||||
};
|
||||
|
||||
// Create an XML writer for the file chosen
|
||||
XmlWriter xmlWriter = XmlWriter.Create(saveFileDialog.FileName, writerSettings);
|
||||
var xmlWriter = XmlWriter.Create(saveFileDialog.FileName, writerSettings);
|
||||
|
||||
// Start the opml element
|
||||
xmlWriter.WriteStartElement("opml");
|
||||
@@ -164,7 +164,7 @@ namespace FeedCenter.Options
|
||||
xmlWriter.WriteStartElement("body");
|
||||
|
||||
// Loop over each feed
|
||||
foreach (Feed feed in Database.Feeds.OrderBy(feed => feed.Name))
|
||||
foreach (var feed in Database.Feeds.OrderBy(feed => feed.Name))
|
||||
{
|
||||
// Start the outline element
|
||||
xmlWriter.WriteStartElement("outline");
|
||||
@@ -196,22 +196,22 @@ namespace FeedCenter.Options
|
||||
private void ImportFeeds()
|
||||
{
|
||||
// Setup the open file dialog
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog
|
||||
var openFileDialog = new OpenFileDialog
|
||||
{
|
||||
Filter = Properties.Resources.ImportExportFilter,
|
||||
FilterIndex = 0
|
||||
};
|
||||
|
||||
bool? result = openFileDialog.ShowDialog();
|
||||
var result = openFileDialog.ShowDialog();
|
||||
|
||||
if (!result.Value)
|
||||
if (!result.GetValueOrDefault(false))
|
||||
return;
|
||||
|
||||
// Setup the reader settings
|
||||
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings { IgnoreWhitespace = true };
|
||||
var xmlReaderSettings = new XmlReaderSettings { IgnoreWhitespace = true };
|
||||
|
||||
// Create an XML reader for the file chosen
|
||||
XmlReader xmlReader = XmlReader.Create(openFileDialog.FileName, xmlReaderSettings);
|
||||
var xmlReader = XmlReader.Create(openFileDialog.FileName, xmlReaderSettings);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -228,7 +228,8 @@ namespace FeedCenter.Options
|
||||
while (xmlReader.NodeType != XmlNodeType.EndElement)
|
||||
{
|
||||
// Create a new feed
|
||||
Feed feed = new Feed { Category = Database.Categories.ToList().First(c => c.IsDefault) };
|
||||
var feed = Feed.Create();
|
||||
feed.Category = Database.Categories.ToList().First(c => c.IsDefault);
|
||||
|
||||
// Loop over all attributes
|
||||
while (xmlReader.MoveToNextAttribute())
|
||||
@@ -259,7 +260,7 @@ namespace FeedCenter.Options
|
||||
feed.Name = feed.Title;
|
||||
|
||||
// Add the feed to the main list
|
||||
Database.Feeds.AddObject(feed);
|
||||
Database.Feeds.Add(feed);
|
||||
|
||||
// Move back to the element node
|
||||
xmlReader.MoveToElement();
|
||||
@@ -293,15 +294,15 @@ namespace FeedCenter.Options
|
||||
|
||||
private void AddCategory()
|
||||
{
|
||||
Category category = new Category();
|
||||
var category = Category.Create();
|
||||
|
||||
CategoryWindow categoryWindow = new CategoryWindow();
|
||||
var categoryWindow = new CategoryWindow();
|
||||
|
||||
bool? result = categoryWindow.Display(category, Window.GetWindow(this));
|
||||
var result = categoryWindow.Display(category, Window.GetWindow(this));
|
||||
|
||||
if (result.HasValue && result.Value)
|
||||
{
|
||||
Database.Categories.AddObject(category);
|
||||
Database.Categories.Add(category);
|
||||
|
||||
categoryListBox.SelectedItem = category;
|
||||
|
||||
@@ -314,18 +315,18 @@ namespace FeedCenter.Options
|
||||
if (categoryListBox.SelectedItem == null)
|
||||
return;
|
||||
|
||||
Category category = (Category) categoryListBox.SelectedItem;
|
||||
var category = (Category) categoryListBox.SelectedItem;
|
||||
|
||||
CategoryWindow categoryWindow = new CategoryWindow();
|
||||
var categoryWindow = new CategoryWindow();
|
||||
|
||||
categoryWindow.Display(category, Window.GetWindow(this));
|
||||
}
|
||||
|
||||
private void DeleteSelectedCategory()
|
||||
{
|
||||
Category category = (Category) categoryListBox.SelectedItem;
|
||||
var category = (Category) categoryListBox.SelectedItem;
|
||||
|
||||
Database.Categories.DeleteObject(category);
|
||||
Database.Categories.Remove(category);
|
||||
|
||||
SetCategoryButtonStates();
|
||||
}
|
||||
@@ -357,14 +358,14 @@ namespace FeedCenter.Options
|
||||
{
|
||||
if (_collectionViewSource == null)
|
||||
{
|
||||
_collectionViewSource = new CollectionViewSource {Source = Database.AllFeeds};
|
||||
_collectionViewSource = new CollectionViewSource { Source = Database.AllFeeds };
|
||||
_collectionViewSource.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
|
||||
_collectionViewSource.Filter += HandleCollectionViewSourceFilter;
|
||||
|
||||
feedListBox.ItemsSource = _collectionViewSource.View;
|
||||
}
|
||||
|
||||
_collectionViewSource.View.Refresh();
|
||||
_collectionViewSource.View.Refresh();
|
||||
|
||||
if (feedListBox.Items.Count > 0)
|
||||
feedListBox.SelectedIndex = 0;
|
||||
@@ -374,20 +375,20 @@ namespace FeedCenter.Options
|
||||
|
||||
private void HandleCollectionViewSourceFilter(object sender, FilterEventArgs e)
|
||||
{
|
||||
Category selectedCategory = (Category) categoryListBox.SelectedItem;
|
||||
var selectedCategory = (Category) categoryListBox.SelectedItem;
|
||||
|
||||
Feed feed = (Feed) e.Item;
|
||||
var feed = (Feed) e.Item;
|
||||
|
||||
e.Accepted = (feed.Category == selectedCategory);
|
||||
}
|
||||
|
||||
private void HandleTextBlockDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
List<Feed> feedList = (List<Feed>) e.Data.GetData(typeof(List<Feed>));
|
||||
var feedList = (List<Feed>) e.Data.GetData(typeof(List<Feed>));
|
||||
|
||||
Category category = (Category) ((DataGridRow) sender).Item;
|
||||
var category = (Category) ((DataGridRow) sender).Item;
|
||||
|
||||
foreach (Feed feed in feedList)
|
||||
foreach (var feed in feedList)
|
||||
feed.Category = category;
|
||||
|
||||
_collectionViewSource.View.Refresh();
|
||||
@@ -399,7 +400,7 @@ namespace FeedCenter.Options
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
List<Feed> selectedItems = feedListBox.SelectedItems.Cast<Feed>().ToList();
|
||||
var selectedItems = feedListBox.SelectedItems.Cast<Feed>().ToList();
|
||||
|
||||
DragDrop.DoDragDrop(feedListBox, selectedItems, DragDropEffects.Move);
|
||||
}
|
||||
@@ -407,14 +408,14 @@ namespace FeedCenter.Options
|
||||
|
||||
private void HandleTextBlockDragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
DataGridRow dataGridRow = (DataGridRow) sender;
|
||||
var dataGridRow = (DataGridRow) sender;
|
||||
|
||||
dataGridRow.FontWeight = FontWeights.Bold;
|
||||
}
|
||||
|
||||
private void HandleTextBlockDragLeave(object sender, DragEventArgs e)
|
||||
{
|
||||
DataGridRow dataGridRow = (DataGridRow) sender;
|
||||
var dataGridRow = (DataGridRow) sender;
|
||||
|
||||
dataGridRow.FontWeight = FontWeights.Normal;
|
||||
}
|
||||
@@ -426,7 +427,7 @@ namespace FeedCenter.Options
|
||||
|
||||
private void HandleMultipleEditClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BulkFeedWindow bulkFeedWindow = new BulkFeedWindow();
|
||||
var bulkFeedWindow = new BulkFeedWindow();
|
||||
bulkFeedWindow.Display(Window.GetWindow(this), Database);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace FeedCenter.Options
|
||||
namespace FeedCenter.Options
|
||||
{
|
||||
public enum MultipleLineDisplay
|
||||
{
|
||||
@@ -10,24 +6,4 @@ namespace FeedCenter.Options
|
||||
SingleLine,
|
||||
FirstLine
|
||||
}
|
||||
|
||||
public enum MultipleOpenAction
|
||||
{
|
||||
IndividualPages,
|
||||
SinglePage
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(int), typeof(MultipleOpenAction))]
|
||||
public class MultipleOpenActionConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (MultipleOpenAction) value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (int) value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FeedCenter.Options
|
||||
{
|
||||
public partial class UpdateOptionsPanel
|
||||
public partial class UpdateOptionsPanel
|
||||
{
|
||||
public UpdateOptionsPanel()
|
||||
{
|
||||
|
||||
21
Setting.cs
Normal file
21
Setting.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated from a template.
|
||||
//
|
||||
// Manual changes to this file may cause unexpected behavior in your application.
|
||||
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class Setting
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,14 @@ namespace FeedCenter
|
||||
{
|
||||
public static object OpenDataStore()
|
||||
{
|
||||
FeedCenterEntities entities = new FeedCenterEntities();
|
||||
var entities = new FeedCenterEntities();
|
||||
|
||||
return entities.DatabaseExists() ? entities : null;
|
||||
return entities.Database.Exists() ? entities : null;
|
||||
}
|
||||
|
||||
public static void CloseDataStore(object dataStore)
|
||||
{
|
||||
FeedCenterEntities entities = (FeedCenterEntities) dataStore;
|
||||
var entities = (FeedCenterEntities) dataStore;
|
||||
|
||||
if (entities == null)
|
||||
return;
|
||||
@@ -26,25 +26,25 @@ namespace FeedCenter
|
||||
|
||||
public static string GetSettingValue(object dataStore, string name, string version)
|
||||
{
|
||||
FeedCenterEntities entities = (FeedCenterEntities) dataStore;
|
||||
var entities = (FeedCenterEntities) dataStore;
|
||||
|
||||
if (entities == null)
|
||||
return null;
|
||||
|
||||
Setting setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == version);
|
||||
var setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == version);
|
||||
|
||||
return setting == null ? null : setting.Value;
|
||||
}
|
||||
|
||||
public static void SetSettingValue(object dataStore, string name, string version, string value)
|
||||
{
|
||||
FeedCenterEntities entities = (FeedCenterEntities) dataStore;
|
||||
var entities = (FeedCenterEntities) dataStore;
|
||||
|
||||
if (entities == null)
|
||||
return;
|
||||
|
||||
// Try to get the setting from the database that matches the name and version
|
||||
Setting setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == version);
|
||||
var setting = entities.Settings.FirstOrDefault(s => s.Name == name && s.Version == version);
|
||||
|
||||
// If there was no setting we need to create it
|
||||
if (setting == null)
|
||||
@@ -53,7 +53,7 @@ namespace FeedCenter
|
||||
setting = new Setting { Name = name, Version = version };
|
||||
|
||||
// Add the setting to the database
|
||||
entities.Settings.AddObject(setting);
|
||||
entities.Settings.Add(setting);
|
||||
}
|
||||
|
||||
// Set the value into the setting
|
||||
@@ -62,7 +62,7 @@ namespace FeedCenter
|
||||
|
||||
public static List<string> GetVersionList(object dataStore)
|
||||
{
|
||||
FeedCenterEntities entities = (FeedCenterEntities) dataStore;
|
||||
var entities = (FeedCenterEntities) dataStore;
|
||||
|
||||
if (entities == null)
|
||||
return null;
|
||||
@@ -73,7 +73,7 @@ namespace FeedCenter
|
||||
|
||||
public static void DeleteSettingsForVersion(object dataStore, string version)
|
||||
{
|
||||
FeedCenterEntities entities = (FeedCenterEntities) dataStore;
|
||||
var entities = (FeedCenterEntities) dataStore;
|
||||
|
||||
if (entities == null)
|
||||
return;
|
||||
@@ -82,8 +82,8 @@ namespace FeedCenter
|
||||
var settings = entities.Settings.Where(setting => setting.Version == version);
|
||||
|
||||
// Delete each setting
|
||||
foreach (Setting setting in settings)
|
||||
entities.Settings.DeleteObject(setting);
|
||||
foreach (var setting in settings)
|
||||
entities.Settings.Remove(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using Common.Debug;
|
||||
using FeedCenter.Data;
|
||||
using FeedCenter.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Deployment.Application;
|
||||
@@ -6,10 +9,6 @@ using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
using Common.Debug;
|
||||
using FeedCenter.Data;
|
||||
using FeedCenter.Properties;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
public partial class SplashWindow
|
||||
@@ -103,7 +102,7 @@ namespace FeedCenter
|
||||
progressBar.Value += e.ProgressPercentage;
|
||||
|
||||
// Get the message
|
||||
string message = (string) e.UserState;
|
||||
var message = (string) e.UserState;
|
||||
|
||||
// Update the status label if one was supplied
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using Common.Debug;
|
||||
using FeedCenter.Properties;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Deployment.Application;
|
||||
using System.Windows;
|
||||
|
||||
using Common.Debug;
|
||||
|
||||
using FeedCenter.Properties;
|
||||
using Application = System.Windows.Forms.Application;
|
||||
|
||||
namespace FeedCenter
|
||||
|
||||
36
app.config
36
app.config
@@ -1,12 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<section name="FeedCenter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
|
||||
<section name="FeedCenter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<section name="FeedCenter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
|
||||
<section name="FeedCenter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
</configSections>
|
||||
<userSettings>
|
||||
<FeedCenter.Properties.Settings>
|
||||
@@ -32,7 +35,7 @@
|
||||
<value>True</value>
|
||||
</setting>
|
||||
<setting name="LastVersionCheck" serializeAs="String">
|
||||
<value/>
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="StartWithWindows" serializeAs="String">
|
||||
<value>False</value>
|
||||
@@ -50,7 +53,7 @@
|
||||
<value>False</value>
|
||||
</setting>
|
||||
<setting name="Browser" serializeAs="String">
|
||||
<value/>
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="OpenAllSleepIntervalFirst" serializeAs="String">
|
||||
<value>1500</value>
|
||||
@@ -80,7 +83,7 @@
|
||||
</FeedCenter.Properties.Settings>
|
||||
</applicationSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
|
||||
</startup>
|
||||
<!--<system.data>
|
||||
<DbProviderFactories>
|
||||
@@ -89,6 +92,23 @@
|
||||
</DbProviderFactories>
|
||||
</system.data>-->
|
||||
<connectionStrings>
|
||||
<add name="FeedCenterEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\FeedCenter.sdf"" providerName="System.Data.EntityClient"/>
|
||||
<add name="FeedCenterEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\FeedCenter.sdf"" providerName="System.Data.EntityClient" />
|
||||
</connectionStrings>
|
||||
</configuration>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
<parameter value="System.Data.SqlServerCe.4.0" />
|
||||
</parameters>
|
||||
</defaultConnectionFactory>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
|
||||
</providers>
|
||||
</entityFramework>
|
||||
<system.data>
|
||||
<DbProviderFactories>
|
||||
<remove invariant="System.Data.SqlServerCe.4.0" />
|
||||
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
|
||||
</DbProviderFactories>
|
||||
</system.data>
|
||||
</configuration>
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl" version="1.1.8" targetFramework="net45" />
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
|
||||
<package id="EntityFramework" version="6.1.1" targetFramework="net451" />
|
||||
<package id="EntityFramework.SqlServerCompact" version="6.1.1" targetFramework="net451" />
|
||||
<package id="Microsoft.SqlServer.Compact" version="4.0.8854.1" targetFramework="net451" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user