protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _encoder?.Dispose();
         _replayGainFilterLifetime?.Dispose();
         _oggStream?.Dispose();
     }
 }
Beispiel #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            _encoder?.Dispose();
            _replayGainFilterLifetime?.Dispose();
        }
        public bool DisposeOnDemand()
        {
            if (lifeTime == null)
            {
                return(false);
            }

            lifeTime.Dispose();
            return(Instance == null);
        }
Beispiel #4
0
 /// <summary>
 /// Закрыть главное окно
 /// </summary>
 private void CloseMainViewModel()
 {
     if (_mainViewModel != null)
     {
         _mainViewModel.Dispose();
         _mainViewModel.Close();
         _mainViewModelExport.Dispose();
         _mainViewModel       = null;
         _mainViewModelExport = null;
     }
 }
            protected override async Task DisposeCoreUnderLockAsync(bool initialized)
            {
                if (initialized)
                {
                    _subscriptions?.Dispose();
                    _applyChangesToWorkspaceContext?.Dispose();

                    if (_context != null)
                    {
                        await _workspaceProjectContextProvider.ReleaseProjectContextAsync(_context);
                    }
                }
            }
            protected override async Task DisposeCoreUnderLockAsync(bool initialized)
            {
                if (initialized)
                {
                    _subscriptions?.Dispose();
                    _applyChangesToWorkspaceContext?.Dispose();

                    if (_contextAccessor != null)
                    {
                        _activeWorkspaceProjectContextTracker.UnregisterContext(_contextAccessor.ContextId);

                        await _workspaceProjectContextProvider.ReleaseProjectContextAsync(_contextAccessor);
                    }
                }
            }
        void Run()
        {
            var catalog   = new DirectoryCatalog(".");
            var container = new CompositionContainer(catalog);

            container.ComposeParts(this);

            ExportLifetimeContext <ICarContract> carA = carFactory.CreateExport();
            ExportLifetimeContext <ICarContract> carB = carFactory.CreateExport();

            carA.Value.DoSomething("carA");
            carB.Value.DoSomething("carB");

            carA.Dispose();
            carB.Dispose();
        }
 static void StopUI(ExportLifetimeContext <IUIController> disposable)
 {
     try {
         if (disposable != null && disposable.Value != null)
         {
             if (!disposable.Value.IsStopped)
             {
                 disposable.Value.Stop();
             }
             disposable.Dispose();
         }
     }
     catch (Exception ex)
     {
         log.Error("Failed to dispose UI. {0}", ex);
     }
 }
Beispiel #9
0
 void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (disposed)
         {
             return;
         }
         if (!handlers.IsDisposed)
         {
             handlers.Dispose();
         }
         view?.Dispose();
         viewModel?.Dispose();
         disposed = true;
     }
 }
Beispiel #10
0
        private Lifetime<ICommand> CreateCommand(string id, out bool cache)
        {
            ExportFactory<ICommand, ICommandMetadata> factory =  _commands.Where(c => c.Metadata.Id == id)
                                                                          .SingleOrDefault();
            cache = false;
            if (factory == null)
                return null;

            ExportLifetimeContext<ICommand> context = factory.CreateExport();
            if (factory.Metadata.IsReusable)
            {
                cache = true;
                return new Lifetime<ICommand>(() => context.Value, (Action)null);
            }

            // Don't catch non-reusable commands, they are created for every request to FindCommand
            return new Lifetime<ICommand>(() => context.Value, () => context.Dispose());
        }
Beispiel #11
0
        void Run()
        {
            // var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            // var container = new CompositionContainer(catalog);

            var managerCatalog = new TypeCatalog(typeof(CarManager));
            var partCatalog    = new TypeCatalog(typeof(CarHost), typeof(CarMercedes), typeof(CarBMW), typeof(CarGarage));

            var scope = new CompositionScopeDefinition(
                managerCatalog,
                new[] { new CompositionScopeDefinition(partCatalog, null) });

            var container = new CompositionContainer(scope);

            var carManager = container.GetExportedValue <CarManager>();

            ExportLifetimeContext <CarHost> carHostContextA = carManager.CreateCarHost();

            Console.WriteLine("");

            ExportLifetimeContext <CarHost> carHostContextB = carManager.CreateCarHost();

            Console.WriteLine("");

            foreach (ICarContract carParts in carHostContextA.Value.CarParts)
            {
                Console.WriteLine(carParts.DoSomething());
            }
            carHostContextA.Dispose();
            Console.WriteLine("");

            foreach (ICarContract carParts in carHostContextB.Value.CarParts)
            {
                Console.WriteLine(carParts.DoSomething());
            }
            carHostContextB.Dispose();
            Console.WriteLine("");

            Console.ReadLine();
        }
Beispiel #12
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _exportLifetimeContext.Dispose();
 }
        public ExportableAudioFile Export(string encoder, CancellationToken cancelToken, SettingsDictionary settings = null, DirectoryInfo outputDirectory = null, string outputFileName = null, bool replaceExisting = false)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(encoder));
            Contract.Ensures(Contract.Result <ExportableAudioFile>() != null);

            if (settings == null)
            {
                settings = new SettingsDictionary();
            }

            ExportFactory <ISampleEncoder> encoderFactory =
                ExtensionProvider.GetFactories <ISampleEncoder>("Name", encoder).SingleOrDefault();

            if (encoderFactory == null)
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.CurrentCulture, Resources.ExportableAudioFileFactoryError, encoder),
                          nameof(encoder));
            }

            ExportLifetimeContext <ISampleEncoder> encoderLifetime = null;
            FileInfo   outputFileInfo = null;
            FileInfo   finalOutputFileInfo;
            FileStream outputStream = null;

            try
            {
                try
                {
                    encoderLifetime = encoderFactory.CreateExport();

                    ValidateSettings(settings, encoderLifetime.Value);

                    outputFileInfo = finalOutputFileInfo = GetOutputFileInfo(FileInfo, outputDirectory, outputFileName, encoderLifetime.Value);

                    // If the output file already exists, write to a temporary file first:
                    if (outputFileInfo.Exists)
                    {
                        outputFileInfo = new FileInfo(Path.Combine(outputFileInfo.DirectoryName ?? string.Empty, Path.GetRandomFileName()));

                        if (!replaceExisting)
                        {
                            throw new IOException(string.Format(CultureInfo.CurrentCulture,
                                                                Resources.ExportableAudioFileFileExistsError, finalOutputFileInfo.FullName));
                        }
                    }

                    outputStream = new FileStream(outputFileInfo.FullName, replaceExisting ? FileMode.Create : FileMode.CreateNew, FileAccess.ReadWrite);

                    DoExport(encoderLifetime.Value, outputStream, settings, cancelToken);
                }
                finally
                {
                    // Dispose the encoder before closing the output stream:
                    encoderLifetime?.Dispose();
                    outputStream?.Dispose();
                }
            }
            catch (Exception)
            {
                outputFileInfo?.Delete();
                throw;
            }

            // If using a temporary file, replace the original:
            if (outputFileInfo != finalOutputFileInfo)
            {
                finalOutputFileInfo.Delete();
                outputFileInfo.MoveTo(finalOutputFileInfo.FullName);
            }

            outputFileInfo.Refresh();
            return(new ExportableAudioFile(outputFileInfo));
        }
 public PresenterLifetime(ExportLifetimeContext <IPresenter> presenter, IPresenterMetadata metadata)
     : base(() => (T)presenter.Value, () => presenter.Dispose())
 {
     _metadata = metadata;
 }