Example #1
0
        private void LoadToggleClicked(object sender, EventArgs args)
        {
            Dataphoria.Warnings.ClearErrors(Dataphoria);
            if (!Registered)
            {
                try
                {
                    DAE.IServerCursor cursor =
                        Dataphoria.OpenCursor
                        (
                            String.Format
                            (
                                @"
									select 
										RequiredLibraries('{0}') 
											group by {{ Library_Name }}
											add {{ Max(Level) Level }}
											where not exists (System.LoadedLibraries where Name = Library_Name) 
											order by {{ Level desc }};
								"                                ,
                                _libraryName
                            )
                        );
                    try
                    {
                        using (DAE.Runtime.Data.IRow row = cursor.Plan.RequestRow())
                        {
                            while (cursor.Next())
                            {
                                cursor.Select(row);
                                try
                                {
                                    Dataphoria.ExecuteScript(String.Format("RegisterLibrary('{0}', false);", (string)row["Library_Name"]));
                                }
                                catch (Exception exception)
                                {
                                    Dataphoria.Warnings.AppendError(Dataphoria, exception, false);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Dataphoria.CloseCursor(cursor);
                    }

                    try
                    {
                        Dataphoria.ExecuteScript(String.Format("RegisterLibrary('{0}', false);", _libraryName));
                    }
                    catch (Exception exception)
                    {
                        Dataphoria.Warnings.AppendError(Dataphoria, exception, false);
                    }
                }
                finally
                {
                    ((LibraryListNode)Parent).RefreshRegistered();
                }
                ((LibraryListNode)Parent).RefreshCurrent();
            }
            else
            {
                try
                {
                    using (Frontend.Client.Windows.IWindowsFormInterface form = (Frontend.Client.Windows.IWindowsFormInterface)Dataphoria.FrontendSession.CreateForm())
                    {
                        Dataphoria.FrontendSession.CreateHost().Load(".Frontend.Form('Frontend', 'UnloadLibrary')", form);
                        form.MainSource.Filter = GetFilter();
                        form.HostNode.Open();
                        if (form.ShowModal(Frontend.Client.FormMode.Query) != DialogResult.OK)
                        {
                            throw new AbortException();
                        }
                        DAE.Client.DataView view = ((Frontend.Client.ISource)form.FindNode("Dependencies")).DataView;
                        view.First();
                        foreach (DAE.Runtime.Data.Row row in view)
                        {
                            try
                            {
                                Dataphoria.ExecuteScript(String.Format("UnregisterLibrary('{0}', false);", (string)row["Library_Name"]));
                            }
                            catch (Exception exception)
                            {
                                Dataphoria.Warnings.AppendError(Dataphoria, exception, false);
                            }
                        }
                    }

                    try
                    {
                        Dataphoria.ExecuteScript(String.Format("UnregisterLibrary('{0}', false);", _libraryName));
                    }
                    catch (Exception exception)
                    {
                        Dataphoria.Warnings.AppendError(Dataphoria, exception, false);
                    }
                    _canLoad = true;
                }
                finally
                {
                    ((LibraryListNode)Parent).RefreshCurrent();
                    ((LibraryListNode)Parent).RefreshRegistered();
                }
            }
        }