public StaticSchemaNode(Repository r) : base(r)
 {
     base.Nodes.Add("(Populating)").NodeFont = SchemaTree.BaseFont;
     this.SetToolTip();
     base.ImageKey = base.SelectedImageKey = this.NormalImageKey;
     this.CreateFileWatcher();
 }
        public RepositoryNode(LINQPad.Repository r) : base(r.GetFriendlyName())
        {
            EventHandler handler = null;

            this._locker = new object();
            Timer timer = new Timer {
                Interval = 0xea60
            };

            this._resourcesTimer = timer;
            this.Repository      = r;
            base.NodeFont        = SchemaTree.BaseFont;
            base.ImageKey        = base.SelectedImageKey = this.NormalImageKey;
            this.BaseText        = base.Text;
            handler = delegate(object sender, EventArgs e) {
                if (base.IsExpanded || this.Populating)
                {
                    this._resourcesTimer.Stop();
                }
                else
                {
                    this.OnIdle();
                }
            };
            this._resourcesTimer.Tick += handler;
        }
 public void AddCx()
 {
     Repository repository2 = new Repository {
         Persist = true
     };
     if (RepositoryDialogManager.Show(repository2, true))
     {
         repository2.SaveToDisk();
         this.AddCx(repository2, true, true);
     }
 }
 public static bool AreEquivalent(Repository r1, Repository r2)
 {
     if ((r1 == null) && (r2 == null))
     {
         return true;
     }
     if ((r1 == null) || (r2 == null))
     {
         return false;
     }
     return ((r1 == r2) || r1.IsEquivalent(r2));
 }
 public void AddCx(Repository repos, Repository child, bool selectNode, bool expandNode, bool delaySchemaPopulation, bool updateAllNodeText)
 {
     if (repos.DriverLoader.IsValid)
     {
         RepositoryNode node;
         base.HideSelection = false;
         bool flag = false;
         if (!repos.DynamicSchema)
         {
             node = new StaticSchemaNode(repos);
         }
         else if (repos.IsQueryable)
         {
             node = new DynamicSchemaNode(repos);
         }
         else
         {
             node = new ServerNode(repos);
         }
         try
         {
             base.BeginUpdate();
             base.Nodes.Add(node);
             flag = (!repos.IsQueryable || expandNode) || !delaySchemaPopulation;
             node.ExpandOnUpdate = expandNode;
             DynamicSchemaNode node2 = null;
             if (child != null)
             {
                 DynamicSchemaNode node3 = new DynamicSchemaNode(child) {
                     ExpandOnUpdate = expandNode
                 };
                 node.Nodes.Add(node2 = node3);
             }
             if (flag)
             {
                 node.Init();
             }
             if (selectNode)
             {
                 base.SelectedNode = (node2 != null) ? node2 : node;
             }
             if (updateAllNodeText)
             {
                 this.UpdateAllNodeText();
             }
         }
         finally
         {
             base.EndUpdate();
         }
     }
 }
 public IEnumerable<ExplorerItem> GetSchemaAndBuildAssembly(string repositoryData, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName, bool allowOneToOne, out IDictionary<string, object> sessionData)
 {
     IEnumerable<ExplorerItem> enumerable2;
     Program.AddLINQPadAssemblyResolver();
     Program.AllowOneToOne = allowOneToOne;
     try
     {
         IEnumerable<ExplorerItem> enumerable;
         Repository r = new Repository(XElement.Parse(repositoryData));
         DynamicDataContextDriver driver = (DynamicDataContextDriver) r.DriverLoader.Driver;
         if (driver is LinqToSqlDynamicDriver)
         {
             enumerable = ((LinqToSqlDynamicDriver) driver).GetSchemaAndBuildAssembly(r, assemblyToBuild, nameSpace, typeName);
         }
         else
         {
             enumerable = driver.GetSchemaAndBuildAssembly(r, assemblyToBuild, ref nameSpace, ref typeName);
         }
         sessionData = null;
         if (r.SessionData.Count > 0)
         {
             sessionData = r.SessionData;
         }
         enumerable2 = enumerable;
     }
     catch (Exception exception)
     {
         if (exception.GetType().FullName == "System.Data.SqlServerCe.SqlCeException")
         {
             throw new DisplayToUserException("SqlCeException: " + exception.Message);
         }
         if (!this.IsForeignException(exception))
         {
             throw;
         }
         Log.Write(exception, "Custom Data Context Driver");
         string msg = exception.GetType().Name + " - " + exception.Message;
         if (exception.InnerException != null)
         {
             msg = msg + " (" + exception.InnerException.Message + ")";
         }
         throw new DisplayToUserException(msg);
     }
     return enumerable2;
 }
 public RepositoryNode(LINQPad.Repository r) : base(r.GetFriendlyName())
 {
     EventHandler handler = null;
     this._locker = new object();
     Timer timer = new Timer {
         Interval = 0xea60
     };
     this._resourcesTimer = timer;
     this.Repository = r;
     base.NodeFont = SchemaTree.BaseFont;
     base.ImageKey = base.SelectedImageKey = this.NormalImageKey;
     this.BaseText = base.Text;
     handler = delegate (object sender, EventArgs e) {
         if (base.IsExpanded || this.Populating)
         {
             this._resourcesTimer.Stop();
         }
         else
         {
             this.OnIdle();
         }
     };
     this._resourcesTimer.Tick += handler;
 }
 public void AddCx(Repository r, bool selectNode, bool expandNode)
 {
     this.AddCx(r, null, selectNode, expandNode, false, true);
 }
Exemple #9
0
 public Database GetDatabase(LINQPad.Repository r)
 {
     return(this.GetDatabase(r, null, false, null));
 }
Exemple #10
0
        public Database GetDatabase(LINQPad.Repository r, LinkedDatabase serverLinkedDb, bool sameServerLink, string systemSchema)
        {
            Func <LINQPad.Repository, Database> selector = null;
            Func <LinkedDatabase, Database>     func2    = null;
            Database database;

            if (systemSchema != null)
            {
                sameServerLink = true;
            }
            this._repository   = r;
            this._serverPrefix = (serverLinkedDb == null) ? "" : (serverLinkedDb.QualifiedPrefix + ".");
            this._excludeFuncs = serverLinkedDb != null;
            this._systemSchema = systemSchema;
            using (this._cx = (SqlConnection)this._repository.Open())
            {
                this.PopulateVersionAndTypes();
                using (SqlDataReader reader = this.GetMainSchemaReader())
                {
                    HashSet <string> keys = new HashSet <string>(this.ReadPKeys(reader));
                    reader.NextResult();
                    List <Column> columns = this.ReadColumns(reader, keys).ToList <Column>();
                    reader.NextResult();
                    List <ColumnAssociation> associations = this.ReadAssociations(columns, reader).ToList <ColumnAssociation>();
                    reader.NextResult();
                    List <Parameter> routineParameters = this.ReadParameters(reader).ToList <Parameter>();
                    if (serverLinkedDb != null)
                    {
                        return(new Database(serverLinkedDb.Server, serverLinkedDb.Database, systemSchema, r.DynamicSchemaOptions, columns, associations, routineParameters, null));
                    }
                    if (sameServerLink || (systemSchema != null))
                    {
                        return(new Database(null, r.Database, systemSchema, r.DynamicSchemaOptions, columns, associations, routineParameters, null));
                    }
                    List <Database> list4 = new List <Database>();
                    if (this.AllowOtherDatabases)
                    {
                        if ((r.IncludeSystemObjects && (r.Database != "master")) && (string.IsNullOrEmpty(this._sqlVersion) || (this._sqlVersion[0] != '8')))
                        {
                            LINQPad.Repository repository = r.Clone();
                            repository.LinkedDatabases      = null;
                            repository.IncludeSystemObjects = false;
                            if (this.ThunkToMasterForSystemSchemas)
                            {
                                repository.Database = "master";
                            }
                            repository.AttachFile     = false;
                            repository.AttachFileName = "";
                            list4.Add(this.CreateNew().GetDatabase(repository, null, true, "sys"));
                            list4.Add(this.CreateNew().GetDatabase(repository, null, true, "INFORMATION_SCHEMA"));
                        }
                        if (selector == null)
                        {
                            selector = lr => this.CreateNew().GetDatabase(lr, null, true, null);
                        }
                        list4.AddRange(r.GetSameServerLinkedRepositories().Select <LINQPad.Repository, Database>(selector));
                        if (func2 == null)
                        {
                            func2 = ld => this.CreateNew().GetDatabase(r, ld, false, null);
                        }
                        list4.AddRange(r.GetOtherServerLinkedDatabases().Select <LinkedDatabase, Database>(func2));
                    }
                    database = new Database(null, null, null, r.DynamicSchemaOptions, columns, associations, routineParameters, list4.ToArray());
                }
            }
            return(database);
        }
 public List<ExplorerItem> GetSchema(Repository r)
 {
     StaticDataContextDriver driver = (StaticDataContextDriver) r.DriverLoader.Driver;
     return driver.GetSchema(r);
 }
 public bool IsEquivalent(Repository other)
 {
     if (other == null)
     {
         return false;
     }
     if (!(this.DriverLoader.IsValid && other.DriverLoader.IsValid))
     {
         return (this.GetStore().ToString() == other.GetStore().ToString());
     }
     if (!this.DriverLoader.Equals(other.DriverLoader))
     {
         return false;
     }
     return this.DriverLoader.Driver.AreRepositoriesEquivalent(this, other);
 }
 public ServerNode(Repository r) : base(r)
 {
 }
Exemple #14
0
 public void ExecuteSqlQuery(QueryLanguage language, LINQPad.Repository repository, string query, string[] refs, Client client, LINQPad.UI.PluginWindowManager pluginWinManager)
 {
     QueryRunner runner;
     this.IsClrQuery = false;
     Util.Progress = null;
     this._repository = repository;
     this._sqlQuery = query;
     this._client = client;
     this._additionalRefs = refs;
     CurrentQueryAdditionalRefs = this._additionalRefs;
     this.PluginWindowManager = pluginWinManager;
     if (language == QueryLanguage.ESQL)
     {
         runner = new ESqlQueryRunner(this, query);
     }
     else
     {
         runner = new SqlQueryRunner(this, query);
     }
     Thread thread = new Thread(() => this.StartQuery(runner)) {
         Name = ((language == QueryLanguage.ESQL) ? "E" : "") + "SQL Query Runner",
         IsBackground = true
     };
     this._worker = thread;
     this._worker.SetApartmentState(ApartmentState.STA);
     this._worker.Start();
 }
 public ExplorerItemNode(Repository r, LINQPad.Extensibility.DataContext.ExplorerItem m) : base(GetItemText(m, UseSqlMode(r)))
 {
     this._repository = r;
     this._explorerItem = m;
     this._sqlMode = UseSqlMode(r);
     base.ImageKey = base.SelectedImageKey = m.Icon.ToString();
     base.ToolTipText = m.ToolTipText;
     if (m.HyperlinkTarget != null)
     {
         base.NodeFont = SchemaTree.UnderlineFont;
     }
     else if (m.Kind == ExplorerItemKind.Parameter)
     {
         base.NodeFont = SchemaTree.ItalicFont;
     }
     else if (m.Kind != ExplorerItemKind.QueryableObject)
     {
         base.NodeFont = SchemaTree.BaseFont;
     }
     if (m.Kind == ExplorerItemKind.Category)
     {
         base.ForeColor = (SystemColors.Window.GetBrightness() < 0.5f) ? Color.FromArgb(120, 0xff, 0xff) : Color.FromArgb(0, 120, 120);
     }
     else if (m.Kind == ExplorerItemKind.CollectionLink)
     {
         base.ForeColor = (SystemColors.Window.GetBrightness() < 0.5f) ? Color.LightGreen : Color.Green;
     }
     else if (m.Kind == ExplorerItemKind.Parameter)
     {
         base.ForeColor = (SystemColors.Window.GetBrightness() < 0.5f) ? Color.FromArgb(110, 140, 0xff) : Color.FromArgb(60, 80, 150);
     }
     else if (m.Kind == ExplorerItemKind.Property)
     {
         if (SystemColors.Window.GetBrightness() > 0.8f)
         {
             base.ForeColor = Color.FromArgb(40, 40, 40);
         }
     }
     else if (m.Kind == ExplorerItemKind.ReferenceLink)
     {
         base.ForeColor = (SystemColors.Window.GetBrightness() < 0.5f) ? Color.RoyalBlue : Color.Blue;
     }
     else if (m.Kind == ExplorerItemKind.Schema)
     {
         base.ForeColor = (SystemColors.Window.GetBrightness() < 0.5f) ? Color.Orchid : Color.Purple;
     }
     if (m.Icon == ExplorerIcon.Inherited)
     {
         base.ForeColor = Color.FromArgb(base.ForeColor.R + ((0xff - base.ForeColor.R) / 3), base.ForeColor.G + ((0xff - base.ForeColor.G) / 3), base.ForeColor.B + ((0xff - base.ForeColor.B) / 3));
     }
     bool flag = m.Kind == ExplorerItemKind.QueryableObject;
     if (m.Children != null)
     {
         foreach (LINQPad.Extensibility.DataContext.ExplorerItem item in m.Children)
         {
             if (flag)
             {
                 this._dormantChildren = true;
             }
             else
             {
                 base.Nodes.Add(new ExplorerItemNode(this._repository, item));
             }
         }
     }
     if (this._dormantChildren)
     {
         base.Nodes.Add(" ");
     }
 }
 private AppDomain CreateAppDomain(Repository repository, string name)
 {
     AppDomain domain;
     this._loadedAssemblyCount = 0;
     this._cumulativeFootprint = 0L;
     this._cachedDomainPolluted = false;
     _lastRemotelyLoadedAssemblies = this._remotelyLoadedAssemblies;
     this._remotelyLoadedAssemblies = new List<TempFileRef>();
     string data = this.AllowShadow() ? this._shadowFolder : null;
     if (repository != null)
     {
         domain = repository.CreateSchemaAndRunnerDomain("LINQPad Query Server [" + name + "]", data != null, true);
     }
     else
     {
         domain = AppDomainUtil.CreateDomain("LINQPad Query Server [" + name + "]");
     }
     if (data != null)
     {
         domain.SetData("LINQPad.ShadowPath", data);
     }
     return domain;
 }
 protected override void OnItemDrag(ItemDragEventArgs e)
 {
     RepositoryNode item = e.Item as RepositoryNode;
     if (((item != null) && (item.Repository != null)) && item.Repository.IsQueryable)
     {
         base.SelectedNode = item;
         base.DoDragDrop(new RepositoryDragData(item.Repository), DragDropEffects.Link | DragDropEffects.Copy);
     }
     else
     {
         BaseNode node = e.Item as BaseNode;
         if ((node != null) && !string.IsNullOrEmpty(node.DragText))
         {
             base.SelectedNode = node;
             RepositoryNode queryableRespositoryParent = this.GetQueryableRespositoryParent(node);
             if (queryableRespositoryParent != null)
             {
                 DragRepository = queryableRespositoryParent.Repository;
             }
             try
             {
                 base.DoDragDrop(node.DragText, DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll);
             }
             finally
             {
                 DragRepository = null;
             }
         }
     }
     base.OnItemDrag(e);
 }
 internal string ShowConnectionDialog(string repositoryData, bool isNewRepository)
 {
     Repository cxInfo = new Repository(XElement.Parse(repositoryData));
     if (this.ShowConnectionDialog(cxInfo, isNewRepository))
     {
         return cxInfo.GetStore().ToString();
     }
     return null;
 }
 public void AddCxFromTemplate(Repository template)
 {
     Repository repository = template.Clone();
     repository.ID = Guid.NewGuid();
     if (RepositoryDialogManager.Show(repository, false))
     {
         repository.SaveToDisk();
         this.AddCx(repository, true, true);
     }
 }
 public void Test(Repository repos, string arg)
 {
     Type customType = this.GetCustomType(repos.CustomAssemblyPath, repos.CustomTypeName);
     Type[] paramTypes = string.IsNullOrEmpty(arg) ? new Type[0] : new Type[] { typeof(string) };
     if (this.GetConstructor(customType, paramTypes) == null)
     {
         throw new Exception("Could not find constructor on type '" + repos.CustomTypeName + "'.");
     }
     object[] args = string.IsNullOrEmpty(arg) ? null : new object[] { arg };
     dynamic obj2 = Activator.CreateInstance(customType, args);
     obj2.Database.Connection.Open();
     obj2.Database.Connection.Close();
     ((EntityFrameworkDbContextDriver) repos.DriverLoader.Driver).Test(repos);
 }
 protected ParameterDescriptor[] GetContextConstructorParams(DataContextDriver driver, Repository r)
 {
     ParameterDescriptor[] descriptorArray2;
     try
     {
         descriptorArray2 = driver.GetContextConstructorParameters(r) ?? new ParameterDescriptor[0];
     }
     catch (Exception exception)
     {
         if (driver.IsBuiltIn)
         {
             throw;
         }
         Log.Write(exception, "GetContextConstructorParameters");
         throw new DisplayToUserException(exception.Message);
     }
     return descriptorArray2;
 }
Exemple #22
0
 internal void ClearAllConnections(Repository repository)
 {
     foreach (QueryControl control in this.GetQueryControls())
     {
         if (control.Query.Repository == repository)
         {
             control.Cancel(true);
         }
     }
     if (repository.DriverLoader.IsValid)
     {
         repository.DriverLoader.Driver.ClearConnectionPools(repository);
         if (repository.DriverLoader.InternalID != null)
         {
             try
             {
                 repository.DriverLoader.ClearDriverDomain();
             }
             catch
             {
             }
         }
     }
 }
Exemple #23
0
 private void StaticSchemaRepositoryChanged(Repository r)
 {
     foreach (QueryControl control in this.GetQueryControls())
     {
         if (control.Query.Repository == r)
         {
             control.CheckAutocompletionCache();
         }
     }
 }
 private static bool UseSqlMode(Repository r)
 {
     if (UserOptions.Instance.DefaultQueryLanguage.HasValue && (((QueryLanguage) UserOptions.Instance.DefaultQueryLanguage.Value) == QueryLanguage.SQL))
     {
         return ((((MainForm.Instance == null) || (MainForm.Instance.CurrentQuery == null)) || (MainForm.Instance.CurrentQuery.Repository != r)) || (MainForm.Instance.CurrentQuery.QueryKind == QueryLanguage.SQL));
     }
     return ((((MainForm.Instance != null) && (MainForm.Instance.CurrentQuery != null)) && (MainForm.Instance.CurrentQuery.Repository == r)) && (MainForm.Instance.CurrentQuery.QueryKind == QueryLanguage.SQL));
 }
 public IEnumerable<ExplorerItem> GetSchemaAndBuildAssembly(Repository r, AssemblyName target, string nameSpace, string typeName)
 {
     Database mainSchema = r.IsSqlCE ? new SqlCeSchemaReader().GetDatabase(r) : (r.IsAzure ? new AzureSchemaReader().GetDatabase(r) : new SqlServerSchemaReader().GetDatabase(r));
     EmissionsGenerator.Generate(mainSchema, target, r.GetCxString(), nameSpace, typeName);
     return mainSchema.GetExplorerSchema(true, null, false);
 }
 public bool CheckForRepositoryChange()
 {
     if (this._query.QueryKind >= QueryLanguage.SQL)
     {
         return false;
     }
     if (this._lastRepository == this._query.Repository)
     {
         return false;
     }
     this._lastRepository = this._query.Repository;
     if (this._dcManager != null)
     {
         this._dcManager.Dispose();
     }
     this._dcManager = null;
     this.ResetDCAssembly();
     if (!((this._query.Repository != null) && this._query.Repository.DynamicSchema))
     {
         this.ConfigureLanguage();
         this.ConfigureResolver();
         this._typeResolver.set_CurrentDCNamespace(this._query.QueryBaseClassNamespace);
         this._typeResolver.set_CurrentDCTypeName(this._query.QueryBaseClassName);
         this._typeResolver.set_DataContextBuilding(false);
         this._typeResolver.set_CurrentDCError(null);
         return true;
     }
     this._typeResolver.set_DataContextBuilding(true);
     this._typeResolver.set_CurrentDCError(null);
     this._dcManager = DataContextManager.SubscribeToDataContextChanges(this._query.Repository, new DataContextCallback(this.DataContextInfoUpdated));
     this._dcManager.GetDataContextInfo(SchemaChangeTestMode.None);
     return true;
 }
 private void btnTest_Click(object sender, EventArgs e)
 {
     if (this._testCxThread != null)
     {
         this._testCxThread = null;
     }
     else
     {
         Repository r = new Repository();
         this.UpdateRepository(r);
         Thread thread = new Thread(() => this.TestCx(r)) {
             Name = "Cx Tester",
             IsBackground = true
         };
         this._testCxThread = thread;
         this._testCxThread.Start();
     }
     this.EnableControls();
 }
Exemple #28
0
 public void ExecuteClrQuery(Client client, LINQPad.Repository r, string assemblyPath, int lineOffset, string[] additionalRefs, bool mta, bool compilationHadWarnings, string queryPath, string queryName, LINQPad.UI.PluginWindowManager pluginWinManager, bool executionTrackingEnabled)
 {
     this.IsClrQuery = true;
     this._client = client;
     _currentServer = null;
     this._repository = r;
     this._assemblyPath = assemblyPath;
     this._lineOffset = lineOffset;
     this._additionalRefs = additionalRefs;
     this._compilationHadWarnings = compilationHadWarnings;
     this._lastLambdaLength = 0;
     this._lastSqlLogLength = 0;
     this._lastResultsLength = 0;
     this._cacheVersionAtStart = UserCache.CacheVersion;
     this.PluginWindowManager = pluginWinManager;
     CurrentQueryAdditionalRefs = this._additionalRefs;
     Util.Progress = null;
     Util.CurrentQueryPath = (queryPath == "") ? null : queryPath;
     Util.CurrentQueryName = queryName;
     PluginServer.CustomCount = 1;
     UserCache.ClearSession();
     Thread thread = new Thread(() => this.StartQuery(new ClrQueryRunner(this, executionTrackingEnabled))) {
         IsBackground = true,
         Name = System.AppDomain.CurrentDomain.FriendlyName
     };
     this._worker = thread;
     if (!mta)
     {
         this._worker.SetApartmentState(ApartmentState.STA);
     }
     this._worker.Start();
 }
 public DynamicSchemaNode(Repository r) : base(r)
 {
     base.Nodes.Add("(Populating)").NodeFont = SchemaTree.BaseFont;
     base.ImageKey = base.SelectedImageKey = this._baseImageKey = r.DriverLoader.IsValid ? r.DriverLoader.Driver.GetImageKey(r) : "CustomError";
     base.Name = base.Text;
 }
Exemple #30
0
 public static IDbConnection OpenCachedCx(LINQPad.Repository r)
 {
     lock (_cachedCxLock)
     {
         if (_cachedCx != null)
         {
             bool flag2 = (_cachedRepos == null) || !_cachedRepos.IsEquivalent(r);
             if (!((_cachedCx.State != ConnectionState.Open) || flag2))
             {
                 return _cachedCx;
             }
             if ((_cachedCx.State != ConnectionState.Closed) || flag2)
             {
                 try
                 {
                     _cachedCx.Dispose();
                 }
                 catch
                 {
                 }
                 _cachedCx = null;
             }
         }
         if (_cachedCx == null)
         {
             _cachedCx = r.Open(true);
             _cachedRepos = r;
         }
         else
         {
             _cachedCx.Open();
         }
         return _cachedCx;
     }
 }
 internal virtual bool IsQueryable(Repository r)
 {
     return true;
 }
 internal override bool IsQueryable(Repository r)
 {
     return (((r.Database.Length > 0) || (r.AttachFile && (r.AttachFileName.Length > 0))) || !r.IsSqlServer);
 }
 private static string TestDallas(Repository r)
 {
     try
     {
         return AstoriaHelper.TestConnection(r);
     }
     catch (Exception exception)
     {
         Log.Write(exception);
         return exception.Message;
     }
 }