Exemplo n.º 1
0
        private void RemoveSource(object param)
        {
            if (SelectedSource != null)
            {
                var folderVM = SelectedSource as FolderVM;

                if (folderVM.Id.HasValue)
                {
                    try
                    {
                        ImoutoCollectionService.Use(imoutoService =>
                        {
                            imoutoService.DeleteFolder(this.Id, folderVM.Id.Value);
                        });
                        LoadFolders();
                    }
                    catch (Exception ex)
                    {
                        App.MainWindowVM?.SetStatusError("Can't remove folder", ex.Message);
                        Debug.WriteLine("Can't remove folder: " + ex.Message);
                    }
                }
                else
                {
                    LoadFolders();
                }
            }
        }
        public void ReloadCollections()
        {
            try
            {
                var sw = new Stopwatch();
                sw.Start();

                List <Collection> collections = ImoutoCollectionService.Use(imoutoService =>
                {
                    var res = imoutoService.GetCollections();
                    return(res);
                });

                sw.Stop();
                Debug.WriteLine($"Collections reloaded in {sw.ElapsedMilliseconds}ms.");

                Collections.Clear();
                collections.ForEach(x => Collections.Add(new CollectionVM(x.Id, x.Name)));

                Collections.ForEach(x => x.LoadFolders());

                SelectedCollection = Collections.FirstOrDefault();
            }
            catch (Exception ex)
            {
                App.MainWindowVM?.SetStatusError("Can't reload collections", ex.Message);
                Debug.WriteLine("Collections reload error: " + ex.Message);
            }
        }
Exemplo n.º 3
0
        private void FolderVM_SaveRequest(object sender, System.EventArgs e)
        {
            var folderVM = sender as FolderVM;

            try
            {
                if (folderVM.Id.HasValue)
                {
                    ImoutoCollectionService.Use(imoutoService =>
                    {
                        imoutoService.UpdateFolder(this.Id, WCFMapper.MapFolder(folderVM));
                    });
                    LoadFolders();
                }
                else
                {
                    ImoutoCollectionService.Use(imoutoService =>
                    {
                        imoutoService.CreateFolder(this.Id, WCFMapper.MapFolder(folderVM));
                    });
                    LoadFolders();
                }
            }
            catch (Exception ex)
            {
                App.MainWindowVM?.SetStatusError("Can't save folder", ex.Message);
                Debug.WriteLine("Can't save folder: " + ex.Message);
            }
        }
Exemplo n.º 4
0
        private void DestinationFolderVM_RemoveRequest(object sender, EventArgs e)
        {
            var folderVM = sender as FolderVM;

            if (folderVM.Id.HasValue)
            {
                try
                {
                    ImoutoCollectionService.Use(imoutoService =>
                    {
                        imoutoService.DeleteFolder(this.Id, folderVM.Id.Value);
                    });
                }
                catch (Exception ex)
                {
                    App.MainWindowVM?.SetStatusError("Can't remove folder", ex.Message);
                    Debug.WriteLine("Can't remove folder: " + ex.Message);
                }
                LoadFolders();
            }
            else
            {
                LoadFolders();
            }
        }
Exemplo n.º 5
0
        public void LoadFolders()
        {
            try
            {
                var folders = ImoutoCollectionService.Use(imoutoService =>
                {
                    return(imoutoService.GetFolders(this.Id));
                });

                this.Destination = null;
                this.Sources.Clear();

                foreach (var folder in folders)
                {
                    switch (folder.Type)
                    {
                    case FolderType.Destination:
                        var destinationFolderVM = new DestinationFolderVM(
                            folder.Id,
                            folder.Path,
                            folder.NeedDevideImagesByHash,
                            folder.NeedRename,
                            folder.IncorrectFormatSubpath,
                            folder.IncorrectHashSubpath,
                            folder.NonHashSubpath
                            );
                        destinationFolderVM.ResetRequest  += FolderVM_ResetRequest;
                        destinationFolderVM.SaveRequest   += FolderVM_SaveRequest;
                        destinationFolderVM.RemoveRequest += DestinationFolderVM_RemoveRequest;

                        this.Destination = destinationFolderVM;
                        break;

                    case FolderType.Source:
                        var sourceFolderVM = new SourceFolderVM(
                            folder.Id,
                            folder.Path,
                            folder.NeedCheckFormat,
                            folder.NeedCheckNameHash,
                            folder.Extensions,
                            folder.TagsFromSubfoder,
                            folder.AddTagFromFileName
                            );
                        sourceFolderVM.ResetRequest += FolderVM_ResetRequest;
                        sourceFolderVM.SaveRequest  += FolderVM_SaveRequest;

                        this.Sources.Add(sourceFolderVM);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                App.MainWindowVM?.SetStatusError("Folders reload error", ex.Message);
                Debug.WriteLine("Folders reload error: " + ex.Message);
            }
        }
Exemplo n.º 6
0
 public void Remove()
 {
     try
     {
         ImoutoCollectionService.Use(imoutoService =>
         {
             imoutoService.DeleteCollection(this.Id);
         });
     }
     catch (Exception ex)
     {
         App.MainWindowVM?.SetStatusError("Can't remove collection", ex.Message);
         Debug.WriteLine("Can't remove collection: " + ex.Message);
     }
 }
Exemplo n.º 7
0
        public void Rename(string newName)
        {
            try
            {
                ImoutoCollectionService.Use(imoutoService =>
                {
                    imoutoService.UpdateCollection(new Collection {
                        Id = this.Id, Name = newName
                    });
                });

                Name = newName;
            }
            catch (Exception ex)
            {
                App.MainWindowVM?.SetStatusError("Can't rename collection", ex.Message);
                Debug.WriteLine("Can't rename collection: " + ex.Message);
            }
        }
        public string CreateCollection(string name)
        {
            try
            {
                ImoutoCollectionService.Use(imoutoService =>
                {
                    imoutoService.CreateCollection(new Collection {
                        Name = name
                    });
                });

                ReloadCollections();
                return(null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Cannot create collection: " + ex.Message);
                return(ex.Message);
            }
        }