private void DataContextInfoUpdated(DataContextInfo m) { if (this._dcManager != null) { this.UpdateNode(m); } }
public static int Delete <T>([NotNull] this IDataContext dataContext, T obj) { if (dataContext == null) { throw new ArgumentNullException("dataContext"); } return(Query <T> .Delete(DataContextInfo.Create(dataContext), obj)); }
public static void DropTable <T>([NotNull] this IDataContext dataContext, string tableName = null, string databaseName = null, string schemaName = null) { if (dataContext == null) { throw new ArgumentNullException("dataContext"); } Query <T> .DropTable(DataContextInfo.Create(dataContext), tableName, databaseName, schemaName); }
private void DataContextGenerationError(DataContextInfo dcInfo) { base.BeginInvoke(delegate { RepositoryNode node = this.GetAllRepositoryNodes(true).FirstOrDefault <RepositoryNode>(db => db.Repository == dcInfo.Repository); if (node != null) { node.ShowErrorIfUninitialized(dcInfo.Error); } }); }
protected bool IsMasterControl(SceneNode sceneNode, IProperty selectedItemProperty, DataSourceInfo targetDataSource, DataContextEvaluator evaluator) { if (!selectedItemProperty.DeclaringType.IsAssignableFrom((ITypeId)sceneNode.Type)) { return(false); } DataContextInfo dataContextInfo = evaluator.Evaluate(sceneNode, (IPropertyId)selectedItemProperty, false); return(targetDataSource.CompareSources(dataContextInfo.DataSource) == DataSourceMatchCriteria.Exact); }
public static DataContextInfo FindDataContextPlacement(SceneNode sceneNode, IProperty targetProperty, DataSourceInfo dataSourceInfo) { DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(sceneNode, (IPropertyId)targetProperty, true); if (!dataContextInfo.IsValid) { return((DataContextInfo)null); } if (dataContextInfo.Owner != null) { dataContextInfo.DataSourceMatch = dataContextInfo.DataSource.CompareSources(dataSourceInfo); if (dataContextInfo.DataSourceMatch == DataSourceMatchCriteria.Ignore) { using (sceneNode.ViewModel.CreateEditTransaction("", true)) { if (targetProperty != null) { sceneNode.ClearLocalValue((IPropertyId)targetProperty); } if (DataContextPlacementEvaluator.IsAnySourcelessBindings(sceneNode)) { return((DataContextInfo)null); } SceneNode sourcelessBindings = DataContextPlacementEvaluator.FindHighestDataContextLocationWithoutSourcelessBindings(dataContextInfo.GetOwnerSceneNode(sceneNode.ViewModel), sceneNode); if (sourcelessBindings == null) { dataContextInfo.Owner = (DocumentCompositeNode)null; dataContextInfo.Property = (IProperty)null; dataContextInfo.DataSourceMatch = DataSourceMatchCriteria.Ignore; } else { dataContextInfo.Owner = (DocumentCompositeNode)sourcelessBindings.DocumentNode; dataContextInfo.Property = DataContextHelper.GetDataContextProperty(dataContextInfo.Owner.Type); dataContextInfo.DataSourceMatch = DataSourceMatchCriteria.Any; } } } } else { SceneNode highestDataContextHost = DataContextPlacementEvaluator.GetHighestDataContextHost(sceneNode); if (highestDataContextHost == null) { return((DataContextInfo)null); } dataContextInfo = new DataContextInfo(); dataContextInfo.Owner = (DocumentCompositeNode)highestDataContextHost.DocumentNode; dataContextInfo.DataSourceMatch = DataSourceMatchCriteria.Any; } return(dataContextInfo); }
private void GotDataContext(DataContextInfo dcInfo) { lock (this._locker) { if (this._cancelRequest) { return; } } new Thread(() => this.CompileAndRun(dcInfo)) { Name = "DataContext Query Compiler", IsBackground = true }.Start(); }
public static ITable <T> CreateTable <T>([NotNull] this IDataContext dataContext, string tableName = null, string databaseName = null, string ownerName = null, string statementHeader = null, string statementFooter = null, DefaulNullable defaulNullable = DefaulNullable.None) { if (dataContext == null) { throw new ArgumentNullException("dataContext"); } return(Query <T> .CreateTable(DataContextInfo.Create(dataContext), tableName, databaseName, ownerName, statementHeader, statementFooter, defaulNullable)); }
private void UpdateNode(DataContextInfo m) { TreeNode[] nodes; this._error = false; if (m.Busy) { if (((base.TreeView != null) && !base.TreeView.IsDisposed) && base.TreeView.IsHandleCreated) { base.SetStatusInvoke(m.Status); } } else { this._error = m.Error != null; if (this._error) { if (!((base.TreeView == null) || base.TreeView.IsDisposed)) { base.WaitForTreeView(); base.TreeView.Invoke(new Action <string>(this.SetError), new object[] { m.Error }); } } else { if (((base.TreeView != null) && !base.TreeView.IsDisposed) && base.TreeView.IsHandleCreated) { base.SetStatusInvoke(""); } if ((m.Schema != null) && (m.Schema.GetHashCode() != this._lastSchemaHash)) { this._lastSchemaHash = m.Schema.GetHashCode(); this._dormantNodes = null; nodes = base.ToExplorerItemNodes(m.Schema); if ((base.TreeView != null) && !base.TreeView.IsDisposed) { base.WaitForTreeView(); base.TreeView.Invoke(() => this.AddNodes(nodes)); base.TreeView.Invoke(new Action(this.SetDone)); } } } } }
public static object InsertWithIdentity <T>(this IDataContext dataContext, T obj, bool ignoreNullInsert = false) { return(Query <T> .InsertWithIdentity(DataContextInfo.Create(dataContext), obj, ignoreNullInsert)); }
public static int Update <T>(this IDataContext dataContext, T obj) { return(Query <T> .Update(DataContextInfo.Create(dataContext), obj)); }
public static object InsertWithIdentity <T>(this IDataContext dataContext, T obj) { return(Query <T> .InsertWithIdentity(DataContextInfo.Create(dataContext), obj)); }
public static int InsertOrReplace <T>(this IDataContext dataContext, T obj) { return(Query <T> .InsertOrReplace(DataContextInfo.Create(dataContext), obj)); }
/// <summary> /// 不能插入list 或 ienumer /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dataContext"></param> /// <param name="obj"></param> /// <param name="tableName"></param> /// <param name="databaseName"></param> /// <param name="schemaName"></param> /// <returns></returns> public static int Insert <T>(this IDataContext dataContext, T obj, string tableName = null, string databaseName = null, string schemaName = null) { return(Query <T> .Insert(DataContextInfo.Create(dataContext), obj, tableName, databaseName, schemaName)); }
public static int Update <T>(this IDataContext dataContext, T obj, bool ignoreNullUpdate = false) { return(Query <T> .Update(DataContextInfo.Create(dataContext), obj, ignoreNullUpdate)); }
public static F InsertWithIdentity <T, F>(this IDataContext dataContext, T obj, bool ignoreNullInsert = false) { var result = Query <T> .InsertWithIdentity(DataContextInfo.Create(dataContext), obj, ignoreNullInsert); return((F)Convert.ChangeType(result, typeof(F))); }
private void CompileAndRun(DataContextInfo dcInfo) { try { object obj2; QueryCore core; lock ((obj2 = this._locker)) { core = this._query; if ((core == null) || this._cancelRequest) { return; } } if ((dcInfo != null) && (dcInfo.Error != null)) { this.OnQueryCompleted("Connection error", dcInfo.Error); } else { DataContextDriver driver = core.GetDriver(true); if ((driver != null) && (driver.AssembliesToAddError != null)) { this.OnQueryCompleted("Error loading custom driver assemblies", driver.AssembliesToAddError.Message); } else { QueryCompiler c = null; if (((this._lastCompilation != null) && (this._lastCompilation.AssemblyDLL != null)) && File.Exists(this._lastCompilation.AssemblyDLL.FullPath)) { c = this._lastCompilation.Compiler; if (!((((dcInfo != null) || (this._lastCompilation.DataContextDLL == null)) && ((dcInfo == null) || (this._lastCompilation.DataContextDLL != null))) ? (((dcInfo == null) || (this._lastCompilation.DataContextDLL == null)) || (dcInfo.AssemblyPath == this._lastCompilation.DataContextDLL)) : false)) { c = null; } } bool flag2 = false; if (c == null) { this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Compiling; c = QueryCompiler.Create(core, true); lock ((obj2 = this._locker)) { if (this._cancelRequest) { return; } } c.Compile(this._source, core, (dcInfo == null) ? null : dcInfo.AssemblyPath); lock ((obj2 = this._locker)) { if (this._cancelRequest) { return; } if (c.Errors.HasErrors) { this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished; this.QueryCompleted = null; this.PluginsReady = null; this.CustomClickComplete = null; } } this.OnQueryCompiled(new QueryCompilationEventArgs(c, (dcInfo == null) ? null : dcInfo.AssemblyPath, this._partialSource)); flag2 = true; } lock ((obj2 = this._locker)) { if ((this._cancelRequest || c.Errors.HasErrors) || this._compileOnly) { this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished; return; } } Server server = this._serverGenerator(this); if (server != null) { lock ((obj2 = this._locker)) { if (this._cancelRequest) { return; } if (this._server != server) { this.ClearServer(); } this._server = server; this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Executing; } bool flag7 = c.References.Any <string>(r => r.EndsWith(".winmd", StringComparison.InvariantCultureIgnoreCase)); server.WriteResultsToGrids = core.ToDataGrids; server.ExecuteClrQuery(this, core.Repository, c.OutputFile.FullPath, c.LineOffset, c.References.ToArray <string>(), Program.MTAMode || flag7, flag2 && c.Errors.HasWarnings, core.FilePath, core.Name, this._pluginWinManager, !UserOptionsLive.Instance.ExecutionTrackingDisabled); } } } } catch (Exception exception) { try { this.OnQueryCompleted("Unable to execute query", ""); } catch { } Program.ProcessException(exception); } }
private bool SetSourceAsDataContext(SceneNode target, IPropertyId targetPropertyId, ref DataSchemaNodePath bindingPath, bool testOnly) { if (target == null || targetPropertyId == null) { return(false); } IProperty property = target.ProjectContext.ResolveProperty(targetPropertyId); if (property == null) { return(false); } SceneNode sceneNode = target; IProperty targetProperty = property; if (DataContextHelper.IsDataContextProperty(target.DocumentNode, (IPropertyId)property)) { sceneNode = sceneNode.Parent; targetProperty = (IProperty)null; if (sceneNode == null || sceneNode.Parent == null) { return(false); } } DataSourceInfo dataSourceInfo = new DataSourceInfo(bindingPath); DataContextInfo contextPlacement = DataContextPlacementEvaluator.FindDataContextPlacement(sceneNode, targetProperty, dataSourceInfo); if (contextPlacement == null || contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Ignore) { return(false); } if (contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Exact || contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Compatible) { if (contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Exact) { bindingPath = bindingPath.GetRelativeNodePath(bindingPath); } else if (!string.IsNullOrEmpty(contextPlacement.DataSource.Path)) { DataSchemaNodePath nodePathFromPath = bindingPath.Schema.GetNodePathFromPath(contextPlacement.DataSource.Path); bindingPath = nodePathFromPath.GetRelativeNodePath(bindingPath); } return(true); } if (contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Any && contextPlacement.Owner != null && (contextPlacement.Owner != target.DocumentNode || contextPlacement.Property == null || !contextPlacement.Property.Equals((object)property))) { IProperty dataContextProperty = DataContextHelper.GetDataContextProperty(contextPlacement.Owner.Type); if (dataContextProperty != null) { SceneNode ownerSceneNode = contextPlacement.GetOwnerSceneNode(target.ViewModel); SceneNode dataSource = this.CreateDataSource(ownerSceneNode, bindingPath, true); if (dataSource != null) { if (!testOnly) { BindingEditor.SetBindingOrData(ownerSceneNode, (IPropertyId)dataContextProperty, dataSource, bindingPath); } return(true); } } } return(false); }
public static int Delete <T>([NotNull] this IDataContext dataContext, T obj) { return(Query <T> .Delete(DataContextInfo.Create(dataContext), obj)); }