public DownloadManagerViewModel() { _downloadsSemaphore = new FifoSemaphore(Properties.Settings.Default.MaxParallelDownloads); var olderDownloads = new List <DownloadViewModel>(); ServiceLocator.Instance.GetService <ILibraryManager>().UpdateScrapersList(ScraperLoader.Instance.AllScrapers); foreach (DownloadedChapterInfo chapterInfo in ServiceLocator.Instance.GetService <ILibraryManager>().GetDownloads()) { var downloadViewModel = new DownloadViewModel(chapterInfo, _downloadsSemaphore); downloadViewModel.RemoveFromCollection += DownloadViewModel_RemoveFromCollection; downloadViewModel.DownloadStarted += DownloadViewModel_DownloadStarted; olderDownloads.Add(downloadViewModel); } Downloads = new AsyncObservableCollection <DownloadViewModel>(olderDownloads); _downloadsCollectionView = (ListCollectionView)CollectionViewSource.GetDefaultView(Downloads); _downloadsCollectionView.CustomSort = new DownloadAgeComparer(); // init filter SelectedTabIndex = Properties.Settings.Default.SelectedDownloadsTab; }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { if ((this._parent.Entry == null)) { ISemaphore entryCasted = item.As <ISemaphore>(); if ((entryCasted != null)) { this._parent.Entry = entryCasted; return; } } ISwitchPosition followsCasted = item.As <ISwitchPosition>(); if ((followsCasted != null)) { this._parent.Follows.Add(followsCasted); } if ((this._parent.Exit == null)) { ISemaphore exitCasted = item.As <ISemaphore>(); if ((exitCasted != null)) { this._parent.Exit = exitCasted; return; } } ISensor definedByCasted = item.As <ISensor>(); if ((definedByCasted != null)) { this._parent.DefinedBy.Add(definedByCasted); } }
/// <summary> /// Removes the given item from the collection /// </summary> /// <returns>True, if the item was removed, otherwise False</returns> /// <param name="item">The item that should be removed</param> public override bool Remove(IModelElement item) { IRailwayElement railwayElementItem = item.As <IRailwayElement>(); if (((railwayElementItem != null) && this._parent.Invalids.Remove(railwayElementItem))) { return(true); } ISemaphore semaphoreItem = item.As <ISemaphore>(); if (((semaphoreItem != null) && this._parent.Semaphores.Remove(semaphoreItem))) { return(true); } IRoute routeItem = item.As <IRoute>(); if (((routeItem != null) && this._parent.Routes.Remove(routeItem))) { return(true); } return(false); }
static void Main(string[] args) { try { semaphore = new MyMonitorSemaphore(3); ThreePlaceSemaphore = new MyMonitorSemaphore(3); TwoPlaceSemaphore = new MyMonitorSemaphore(2); TryAcquireTest(); AutoAcquireTestThread(); semaphore = new MySemaphore(2); semaphore.Release(-1); int x = 0; Test(); TryAcquireTest(); } catch (Exception ex) { Console.WriteLine("Type of exception {0}", ex.GetType().ToString()); Console.WriteLine(ex.ToString()); } int y = 0; }
public virtual void DownloadChapterAsync(ISemaphore semaphore, IChapterRecord chapter, string outputFolder, IDownloadFormatProvider formatProvider) { if (_backgroundWorker.IsBusy) { throw new InvalidOperationException("Download is currently in progress."); } if (semaphore == null) { throw new ArgumentNullException("semaphore"); } if (chapter == null) { throw new ArgumentNullException("chapter"); } if (String.IsNullOrEmpty(outputFolder)) { throw new ArgumentException("Output folder must not be null or empty.", "outputFolder"); } if (formatProvider == null) { throw new ArgumentNullException("formatProvider"); } var workerParams = new WorkerParams() { Chapter = chapter, Semaphore = semaphore, OutputFolder = outputFolder, FormatProvider = formatProvider }; _backgroundWorker.RunWorkerAsync(workerParams); }
public DownloadManagerViewModel() { _downloadsSemaphore = new FifoSemaphore(Properties.Settings.Default.MaxParallelDownloads); var olderDownloads = new List<DownloadViewModel>(); ServiceLocator.Instance.GetService<ILibraryManager>().UpdateScrapersList(ScraperLoader.Instance.AllScrapers); foreach (DownloadedChapterInfo chapterInfo in ServiceLocator.Instance.GetService<ILibraryManager>().GetDownloads()) { var downloadViewModel = new DownloadViewModel(chapterInfo, _downloadsSemaphore); downloadViewModel.RemoveFromCollection += DownloadViewModel_RemoveFromCollection; downloadViewModel.DownloadStarted += DownloadViewModel_DownloadStarted; olderDownloads.Add(downloadViewModel); } Downloads = new AsyncObservableCollection<DownloadViewModel>(olderDownloads); _downloadsCollectionView = (ListCollectionView) CollectionViewSource.GetDefaultView(Downloads); _downloadsCollectionView.CustomSort = new DownloadAgeComparer(); // init filter SelectedTabIndex = Properties.Settings.Default.SelectedDownloadsTab; }
public DownloadViewModel(DownloadedChapterInfo downloadInfo, ISemaphore downloadSemaphore) { if (downloadInfo == null) throw new ArgumentNullException("downloadInfo"); if (downloadSemaphore == null) throw new ArgumentNullException("downloadSemaphore"); if (downloadInfo.ChapterRecord == null) throw new ArgumentException("Chapter record is invalid.", "downloadInfo"); if (String.IsNullOrEmpty(downloadInfo.ChapterRecord.ChapterId)) throw new ArgumentException("Chapter record id is invalid.", "downloadInfo"); if (downloadInfo.ChapterRecord.MangaRecord == null) throw new ArgumentException("Manga record is invalid.", "downloadInfo"); if (String.IsNullOrEmpty(downloadInfo.ChapterRecord.MangaRecord.MangaId)) throw new ArgumentException("Manga record id is invalid.", "downloadInfo"); _downloadInfo = downloadInfo; _downloadSemaphore = downloadSemaphore; _scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == downloadInfo.ChapterRecord.Scraper); if (_scraper != null) { _downloader = _scraper.GetDownloader(); // register downloader events _downloader.DownloadProgress += _downloader_DownloadProgress; _downloader.DownloadCompleted += _downloader_DownloadCompleted; } if (!String.IsNullOrEmpty(_downloadInfo.Path)) { // file was already downloaded State = DownloadState.Unknown; Completed = true; } else { // we will be downloading the file now State = DownloadState.Ok; Completed = false; } CurrentActionText = String.Empty; _cancelDownloadCommand = new RelayCommand(Cancel, x => !Completed); _removeDownloadCommand = new RelayCommand(Remove); _openDownloadCommand = new RelayCommand(Open, x => DownloadExists); _retryDownloadCommand = new RelayCommand(RetryDownload, x => _downloader != null && Completed && !DownloadExists && !String.IsNullOrEmpty(_downloadInfo.DownloadFolder)); CancelText = ButtonCancelText; }
public void Init() { s = Client.GetSemaphore(TestSupport.RandomString()); s.ReducePermits(100); s.Release(9); s.Release(); }
public DownloadGroup() { queue = new EmiliaQueue(downloadSizeCallback, downloadStatusCallback, downloadRetryCallback, downloadErrorCallback); remain_contents = 0; index_count = 0; jobs = new List <Tuple <int, object, SemaphoreCallBack, DownloadQueue.DownloadSizeCallBack, DownloadQueue.DownloadStatusCallBack, DownloadQueue.RetryCallBack> >(); download_file_count = new List <int>(); file_count = new List <int>(); }
public EmiliaDispatcher() { queue = new EmiliaQueue(downloadSizeCallback, downloadStatusCallback, downloadRetryCallback, downloadErrorCallback); series_dictionary = new Dictionary <int, EmiliaSeriesSegment>(); dispatcher_dictionary = new Dictionary <int, DispatchInformation>(); check_dictionary = new Dictionary <int, List <bool[]> >(); downloaded_count_dictionary = new Dictionary <int, int[]>(); downloaded_articles_count_dictionary = new Dictionary <int, int>(); series_count = -1; }
private void DisposeInternal() { NotifyFinishedInternal(); if (_concurrencyControlSemaphore != null) { _concurrencyControlSemaphore.Dispose(); _concurrencyControlSemaphore = null; } if (_singleThread != null) { _singleThread.Dispose(); _singleThread = null; } }
/// <summary /// Instantiates a worker group with specified maximum concurrency and external progress reporting. Progress /// will be reported on the thread instantiating the ProgressContext used. /// </summary> /// <param name="maxConcurrent">The maximum number of worker threads active at any one time</param> /// <param name="progress">The ProgressContext that receives progress notifications</param> public WorkerGroup(int maxConcurrent, IProgressContext progress) { if (progress == null) { throw new ArgumentNullException("progress"); } _concurrencyControlSemaphore = Resolve.Portable.Semaphore(maxConcurrent, maxConcurrent); _maxConcurrencyCount = maxConcurrent; _singleThread = Resolve.Portable.SingleThread(); FirstError = new FileOperationContext(String.Empty, ErrorStatus.Success); progress.NotifyLevelStart(); Progress = new WorkerGroupProgressContext(progress, _singleThread); }
public MainWindowViewModel(Window owner) { if (owner == null) throw new ArgumentNullException("owner"); Owner = owner; _searchCommand = new SearchCommand(this); _browseCommand = new BrowseCommand(this); _saveCommand = new SaveCommand(this); _settingsCommand = new SettingsCommand(this); // load all enabled scrapers _scrapers = ScraperLoader.Instance.EnabledScrapers; if (!string.IsNullOrEmpty(Properties.Settings.Default.SelectedScraper)) CurrentScraper = _scrapers.FirstOrDefault(s => s.Name == Properties.Settings.Default.SelectedScraper); if (CurrentScraper == null) CurrentScraper = _scrapers.First(); // load output path from user settings _outputPath = Properties.Settings.Default.OutputPath; Mangas = new AsyncObservableCollection<MangaRecord>(); Chapters = new AsyncObservableCollection<ChapterRecord>(); Downloads = new AsyncObservableCollection<DownloadViewModel>(); SelectedChapters = new AsyncObservableCollection<ChapterRecord>(); ZipFile = true; ProgressValue = 0; _requestQueue = new AsyncRequestQueue(System.Threading.SynchronizationContext.Current); _requestQueue.TasksCompleted += _requestQueue_TasksCompleted; _requestQueue.Initialize(); _downloadsSemaphore = new FifoSemaphore(Properties.Settings.Default.MaxParallelDownloads); if (Properties.Settings.Default.EnablePreload) { PreloadMangas(); } }
private static void Test() { semaphore = new MyMonitorSemaphore(2); //semaphore.Release(1); System.Threading.Thread t = new Thread(new ThreadStart(Do)); System.Threading.Thread t2 = new Thread(new ThreadStart(Do)); System.Threading.Thread t3 = new Thread(new ThreadStart(Do)); t.Start(); t2.Start(); t3.Start(); t.Join(timeWait); t2.Join(timeWait); t3.Join(timeWait); Console.WriteLine("Result: {0}", result); semaphore.Release(1); t3.Join(timeWait); Console.WriteLine("Result: {0}", result); int p = 0; }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { IRailwayElement invalidsCasted = item.As <IRailwayElement>(); if ((invalidsCasted != null)) { this._parent.Invalids.Add(invalidsCasted); } ISemaphore semaphoresCasted = item.As <ISemaphore>(); if ((semaphoresCasted != null)) { this._parent.Semaphores.Add(semaphoresCasted); } IRoute routesCasted = item.As <IRoute>(); if ((routesCasted != null)) { this._parent.Routes.Add(routesCasted); } }
public static void TryAcquireTest2() { semaphore = new MyMonitorSemaphore(2); System.Threading.Thread t = new Thread(new ThreadStart(Do)); System.Threading.Thread t2 = new Thread(new ThreadStart(Do)); System.Threading.Thread t3 = new Thread(new ThreadStart(Do)); bool isGood = true; isGood &= semaphore.TryAcquire(); semaphore.Release(1); t.Start(); t.Join(timeWait); isGood &= semaphore.TryAcquire(); semaphore.Release(1); t2.Start(); t2.Join(timeWait); isGood &= !semaphore.TryAcquire(); t3.Start(); t3.Join(timeWait); isGood &= !semaphore.TryAcquire(); semaphore.Release(1); t3.Join(timeWait); isGood &= !semaphore.TryAcquire(); semaphore.Release(1); isGood &= semaphore.TryAcquire(); semaphore.Release(1); semaphore.Release(1); }
public static bool IsGo(ISemaphore semaphore) { return(semaphore != null && semaphore.Signal == Signal.GO); }
public void DownloadChapter(string outputPath, bool isZipped, ISemaphore semaphore) { if (string.IsNullOrEmpty(outputPath)) throw new ArgumentException("Invalid output path", "outputPath"); _isZipped = isZipped; if (isZipped) { var fileInfo = new FileInfo(Path.Combine(outputPath, GetNameForSave(Chapter) + ".zip")); _outputFullPath = fileInfo.FullName; Downloader.DownloadChapterAsync(semaphore, Chapter, fileInfo); } else { var directoryInfo = new DirectoryInfo(Path.Combine(outputPath, GetNameForSave(Chapter))); _outputFullPath = directoryInfo.FullName; Downloader.DownloadChapterAsync(semaphore, Chapter, directoryInfo); } }
public DeploymentJournal(ICalamariFileSystem fileSystem, ISemaphore semaphore, VariableDictionary variables) { this.fileSystem = fileSystem; this.semaphore = semaphore; this.variables = variables; }
public DownloadViewModel(DownloadedChapterInfo downloadInfo, ISemaphore downloadSemaphore) { if (downloadInfo == null) { throw new ArgumentNullException("downloadInfo"); } if (downloadSemaphore == null) { throw new ArgumentNullException("downloadSemaphore"); } if (downloadInfo.ChapterRecord == null) { throw new ArgumentException("Chapter record is invalid.", "downloadInfo"); } if (String.IsNullOrEmpty(downloadInfo.ChapterRecord.ChapterId)) { throw new ArgumentException("Chapter record id is invalid.", "downloadInfo"); } if (downloadInfo.ChapterRecord.MangaRecord == null) { throw new ArgumentException("Manga record is invalid.", "downloadInfo"); } if (String.IsNullOrEmpty(downloadInfo.ChapterRecord.MangaRecord.MangaId)) { throw new ArgumentException("Manga record id is invalid.", "downloadInfo"); } _downloadInfo = downloadInfo; _downloadSemaphore = downloadSemaphore; _scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == downloadInfo.ChapterRecord.Scraper); if (_scraper != null) { _downloader = _scraper.GetDownloader(); // register downloader events _downloader.DownloadProgress += _downloader_DownloadProgress; _downloader.DownloadCompleted += _downloader_DownloadCompleted; } if (!String.IsNullOrEmpty(_downloadInfo.Path)) { // file was already downloaded State = DownloadState.Unknown; Completed = true; } else { // we will be downloading the file now State = DownloadState.Ok; Completed = false; } CurrentActionText = String.Empty; _cancelDownloadCommand = new RelayCommand(Cancel, x => !Completed); _removeDownloadCommand = new RelayCommand(Remove); _openDownloadCommand = new RelayCommand(Open, x => DownloadExists); _retryDownloadCommand = new RelayCommand(RetryDownload, x => _downloader != null && Completed && !DownloadExists && !String.IsNullOrEmpty(_downloadInfo.DownloadFolder)); CancelText = ButtonCancelText; }
public void Init() { semaphore = Client.GetSemaphore(TestSupport.RandomString()); }
public virtual void DownloadChapterAsync(ISemaphore semaphore, ChapterRecord chapter, DirectoryInfo directory, bool createDir = true) { if (_backgroundWorker.IsBusy) throw new InvalidOperationException("Download is currently in progress."); if (semaphore == null) throw new ArgumentNullException("semaphore"); if (chapter == null) throw new ArgumentNullException("chapter"); if (directory == null) throw new ArgumentNullException("directory"); if (!createDir && !directory.Exists) throw new ArgumentException("Specified directory does not exists.", "directory"); var workerParams = new WorkerParams() { Chapter = chapter, IsFile = false, Directory = directory, CreateDirectory = createDir, Semaphore = semaphore }; _backgroundWorker.RunWorkerAsync(workerParams); }
public ExtractPackageToApplicationDirectoryConvention(IPackageExtractor extractor, ICalamariFileSystem fileSystem, ISemaphore semaphore) { this.extractor = extractor; this.fileSystem = fileSystem; this.semaphore = semaphore; }
public LockFileBasedSemaphoreReleaser(ISemaphore semaphore) { this.semaphore = semaphore; }
public ExtractPackageToApplicationDirectoryConvention(IPackageExtractor extractor, ICalamariFileSystem fileSystem, ISemaphore semaphore) : base(extractor, fileSystem) { this.semaphore = semaphore; }
public SettingsManager(ILog log, ISemaphore semaphore, ISettingsRepository settingsRepository) { _log = log; _available = semaphore; _settingsRepository = settingsRepository; }
// Use this for initialization void Start() { semaphore = GetComponentInParent<ISemaphore>(); }
public virtual void DownloadChapterAsync(ISemaphore semaphore, ChapterRecord chapter, FileInfo file) { if (_backgroundWorker.IsBusy) throw new InvalidOperationException("Download is currently in progress."); if (semaphore == null) throw new ArgumentNullException("semaphore"); if (chapter == null) throw new ArgumentNullException("chapter"); if (file == null) throw new ArgumentNullException("file"); var workerParams = new WorkerParams() { Chapter = chapter, IsFile = true, File = file, Semaphore = semaphore }; _backgroundWorker.RunWorkerAsync(workerParams); }
public static bool WrongParameters(ISemaphore semaphore) { return(true); }
public static bool WrongMember(ISemaphore semaphore) { return(semaphore.Id == 42); }
public virtual void DownloadChapterAsync(ISemaphore semaphore, IChapterRecord chapter, string outputFolder, IDownloadFormatProvider formatProvider) { if (_backgroundWorker.IsBusy) throw new InvalidOperationException("Download is currently in progress."); if (semaphore == null) throw new ArgumentNullException("semaphore"); if (chapter == null) throw new ArgumentNullException("chapter"); if (String.IsNullOrEmpty(outputFolder)) throw new ArgumentException("Output folder must not be null or empty.", "outputFolder"); if (formatProvider == null) throw new ArgumentNullException("formatProvider"); var workerParams = new WorkerParams() { Chapter = chapter, Semaphore = semaphore, OutputFolder = outputFolder, FormatProvider = formatProvider }; _backgroundWorker.RunWorkerAsync(workerParams); }