Ejemplo n.º 1
0
        public IObservable <Unit> AddLibrary(string libraryId)
        {
            return(Observable.Return(libraryId)
                   .SelectMany(id =>
            {
                if (String.IsNullOrEmpty(id))
                {
                    return Observable.Throw <LibraryInfo>(new ArgumentException(FileLanguage.Error_LibraryIdEmpty));
                }

                if (LoggedUser.Libraries.Count(library => library.ServerId == libraryId) != 0)
                {
                    return Observable.Throw <LibraryInfo>(new ArgumentException(FileLanguage.LIBRARY_ALREADY_EXISTS));
                }

                return Transport.GetLibraryInfo(id);
            })
                   .ObserveOnDispatcher()
                   .Do(libInfo =>
            {
                Library library = new Library(libInfo.Id, libInfo.Title, libInfo.Version);
                StatisticsManager.LogAddLibrary(library);
                LoggedUser.Libraries.Add(library);
            })
                   .Select(_ => new Unit()));
        }