Пример #1
0
        public async Task DisposeWorkplace(bool immediately = false)
        {
            if (!IsInitialized)
            {
                throw new InvalidOperationException();
            }

            // closing IDEs in reverse order
            while (IDEs.Count > 0)
            {
                await CloseIDE(IDEs.Last(), immediately);
            }

            bool locked;

            foreach (IInputDevice inputDevice in InputDevices)
            {
                if (inputDevice != null && inputDevice.IsInitialized)
                {
                    locked = false;
                    if (inputDevice.IsLockingRequiredForDispose())
                    {
                        IOmonitor.IdleForLock(inputDevice, out locked);
                    }
                    inputDevice.Dispose();
                    if (locked)
                    {
                        IOmonitor.Unlock(inputDevice);
                    }
                }
            }
            foreach (IOutputDevice outputDevice in OutputDevices)
            {
                if (outputDevice != null && outputDevice.IsInitialized)
                {
                    locked = false;
                    if (outputDevice.IsLockingRequiredForDispose())
                    {
                        IOmonitor.IdleForLock(outputDevice, out locked);
                    }
                    outputDevice.Dispose();
                    if (locked)
                    {
                        IOmonitor.Unlock(outputDevice);
                    }
                }
            }
            foreach (IExtraWorkplaceComponent extraComponent in ExtraComponents
                     .Where(e => e is IDisposable))
            {
                (extraComponent as IDisposable)?.Dispose();
            }

            IsInitialized = false;
            OnGotUpdated();
        }
Пример #2
0
        public async Task <bool> CloseWorkplaceByUser(bool immediately = false)
        {
            if (!IsInitialized)
            {
                return(true);
            }

            while (IDEs.Count > 0)
            {
                if (!(await CloseIDEbyUser(IDEs.Last(), true)))
                {
                    return(false);
                }
            }

            if (!ConfigFile.IsChangesSaved)
            {
                DialogResult answer =
                    OnAskingUser("Save changes in file "
                                 + ConfigFile.ShortFileName + " before closing the Workplace?", "Unsaved changes in " + Title, MessageBoxButtons.YesNoCancel);
                switch (answer)
                {
                case DialogResult.Yes:
                    if (!SaveWorkplaceByUser())
                    {
                        return(false);
                    }
                    break;

                case DialogResult.Cancel:
                    return(false);
                }
            }

            await DisposeWorkplace(true);

            return(true);
        }