//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Tango.MachineStudio.UsersAndRoles.Properties {
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private staticpre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */using EFCache;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
using System.Data.SqlClient;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.Core;
using Tango.Settings;
namespace Tango.BL
{
//[DbConfigurationType(typeof(ObservablesContextConfiguration))]
public partial class ObservablesContext
{
private List<ObservableModifiedEventArgs> _pending_notifications = new List<ObservableModifiedEventArgs>();
private ObservablesContextAdapter _adapter;
private static DataSource _override_datasource;
private DataSource _dataSource;
private static List<ObservablesContext> _open_contexts;
/// <summary>
/// Gets a value indicating whether this instance is disposed.
/// </summary>
public bool IsDisposed { get; private set; }
/// <summary>
/// Initializes the <see cref="ObservablesContext"/> class.
/// </summary>
static ObservablesContext()
{
_open_contexts = new List<ObservablesContext>();
}
/// <summary>
/// Initializes a new instance of the <see cref="ObservablesContext"/> class.
/// </summary>
public ObservablesContext()
{
_open_contexts.Add(this);
}
/// <summary>
/// Initializes a new instance of the <see cref="ObservablesContext" /> class.
/// </summary>
/// <param name="path">The server file path.</param>
/// <param name="isFile">if set to <c>true</c> will try to connect to an .mdf file.</param>
public ObservablesContext(DataSource dataSource) : base(dataSource.ToConnection(), true)
{
_open_contexts.Add(this);
_dataSource = dataSource;
Database.SetInitializer<ObservablesContext>(null);
Configuration.LazyLoadingEnabled = false;
_adapter = new ObservablesContextAdapter(this);
}
/// <summary>
/// Creates a default remote database context by the address specified in <see cref="SettingsManager.Default.DataBase.SQLServerAddress" />.
/// </summary>
/// <returns></returns>
public static ObservablesContext CreateDefault()
{
return new ObservablesContext(_override_datasource != null ? _override_datasource : SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource);
}
/// <summary>
/// Creates a default remote database context.
/// </summary>
/// <returns></returns>
public static ObservablesContext CreateDefault(DataSource dataSource)
{
return new ObservablesContext(dataSource);
}
/// <summary>
/// Creates a default remote database context.
/// </summary>
/// <returns></returns>
public static ObservablesContext CreateDefault(String address, String catalog, DataSourceType type)
{
return new ObservablesContext(new DataSource()
{
Address = address,
Catalog = catalog,
IntegratedSecurity = true,
Type = type
});
}
/// <summary>
/// Creates a default remote database context.
/// </summary>
/// <returns></returns>
public static ObservablesContext CreateDefault(String address, DataSourceType type)
{
return CreateDefault(address, "Tango", type);
}
/// <summary>
/// Creates a default remote database context.
/// </summary>
/// <returns></returns>
public static ObservablesContext CreateDefault(String address)
{
return CreateDefault(address, "Tango", DataSourceType.SQLServer);
}
/// <summary>
/// Gets the inner object context.
/// </summary>
/// <returns></returns>
private ObjectContext GetObjectContext()
{
return ((IObjectContextAdapter)this).ObjectContext;
}
/// <summary>
/// Saves all changes made in this context to the underlying database.
/// </summary>
/// <returns>
/// The number of objects written to the underlying database.
/// </returns>
public override int SaveChanges()
{
foreach (var entity in ChangeTracker.Entries().Where(x => x.State == EntityState.Added || x.State == EntityState.Modified).ToList())
{
if (entity is IObservableEntity && entity != null)
{
(entity as IObservableEntity).OnBeforeSave();
}
}
var result = base.SaveChanges();
RaisePendingNotifications();
return result;
}
/// <summary>
/// Asynchronously saves all changes made in this context to the underlying database.
/// </summary>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>
/// A task that represents the asynchronous save operation.
/// The task result contains the number of objects written to the underlying database.
/// </returns>
/// <remarks>
/// Multiple active operations on the same context instance are not supported. Use 'await' to ensure
/// that any asynchronous operations have completed before calling another method on this context.
/// </remarks>
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken)
{
foreach (var entity in ChangeTracker.Entries().Where(x => x.State == EntityState.Added || x.State == EntityState.Modified).ToList().Select(x => x.Entity).ToList())
{
if (entity is IObservableEntity && entity != null)
{
(entity as IObservableEntity).OnBeforeSave();
}
}
var result = base.SaveChangesAsync(cancellationToken);
RaisePendingNotifications();
return result;
}
/// <summary>
/// Raises the pending notifications.
/// </summary>
private void RaisePendingNotifications()
{
Task.Factory.StartNew(() =>
{
foreach (var e in _pending_notifications.DistinctBy(x => x.NotifiedEntity))
{
try
{
e.NotifiedEntity.RaiseModified(e.Context, e.ModifiedEntity, e.NotifiedEntity);
}
catch { }
}
_pending_notifications.Clear();
});
}
/// <summary>
/// Extension point allowing the user to override the default behavior of validating only
/// added and modified entities.
/// </summary>
/// <param name="entityEntry">DbEntityEntry instance that is supposed to be validated.</param>
/// <returns>
/// true to proceed with validation; false otherwise.
/// </returns>
protected override bool ShouldValidateEntity(DbEntityEntry entityEntry)
{
if (entityEntry.State == EntityState.Modified && entityEntry.Entity is IObservableEntity)
{
IObservableEntity modified = entityEntry.Entity as IObservableEntity;
foreach (var toNotify in ObservableEntitiesContainer.RegisteredEntities.ToList().Where(x => x.Guid == modified.Guid).ToList())
{
_pending_notifications.Add(new ObservableModifiedEventArgs(this, modified, toNotify));
}
}
return base.ShouldValidateEntity(entityEntry);
}
/// <summary>
/// Gets an instance of <see cref="ObservablesContextAdapter"/> which wraps this instance.
/// </summary>
public ObservablesContextAdapter Adapter
{
get { return _adapter; }
}
/// <summary>
/// Overrides the default data source that is read from the core settings.
/// </summary>
/// <param name="dataSource">The data source.</param>
public static void OverrideSettingsDataSource(DataSource dataSource)
{
_override_datasource = dataSource;
}
/// <summary>
/// Gets the current data source.
/// </summary>
/// <returns></returns>
public DataSource GetDataSource()
{
return _dataSource;
}
/// <summary>
/// Gets the actual data source (settings or overridden).
/// </summary>
/// <returns></returns>
public static DataSource GetActualDataSource()
{
return _override_datasource != null ? _override_datasource : SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource;
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
/// <inheritdoc />
public override string ToString()
{
return GetDataSource().ToString();
}
/// <summary>
/// Clears the model store on the file system.
/// </summary>
public static void ClearModelStore()
{
//ObservablesContextConfiguration.ClearModelStore();
}
/// <summary>
/// Enables the in memory cache.
/// </summary>
/// <param name="cacheTime">Maximum cache time to preserve a single entity cache.</param>
public static void EnableInMemoryCache(TimeSpan cacheTime, ObservablesContextInMemoryCachingMode mode)
{
if (mode != ObservablesContextInMemoryCachingMode.None)
{
var cache = new ObservablesContextInMemoryCache() { Expiration = cacheTime };
if (mode == ObservablesContextInMemoryCachingMode.Relative)
{
cache.ResetAccessTimeOnAccess = true;
}
EntityFrameworkCache.Initialize(cache);
}
}
/// <summary>
/// Disposes the context. The underlying <see cref="T:System.Data.Entity.Core.Objects.ObjectContext" /> is also disposed if it was created
/// is by this context or ownership was passed to this context when this context was created.
/// The connection to the database (<see cref="T:System.Data.Common.DbConnection" /> object) is also disposed if it was created
/// is by this context or ownership was passed to this context when this context was created.
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected override void Dispose(bool disposing)
{
_open_contexts.Remove(this);
base.Dispose(disposing);
IsDisposed = true;
}
public static void UpdateAccessToken(String accessToken, DateTime expiration)
{
if (_override_datasource != null)
{
_override_datasource.AccessToken = accessToken;
_override_datasource.AccessTokenExpiration = expiration;
foreach (var context in _open_contexts.Where(x => x._dataSource.Type == DataSourceType.AccessToken))
{
context._dataSource = _override_datasource;
var connection = context.Database.Connection as SqlConnection;
if (connection != null)
{
connection.AccessToken = context._dataSource.AccessToken;
}
}
}
}
}
}