Exemplo n.º 1
0
        public Directory RefreshPath(Share share)
        {
            try
            {
                model.GetAntiShutdownLock();
                lock (share)
                {
                    RootShare rs = shares.Where(s => s.ID == share.ID).FirstOrDefault();
                    if (null == rs)
                    {
                        rs = new RootShare();
                        rs.ID = share.ID;
                        rs.Data = new Directory();
                        shares.Add(rs);
                    }
                    rs.Data.Name = share.Name;
                    rs.Data.Size = 0;
                    rs.Data.ItemCount = 0;

                    RefreshFileInfo(new DirectoryInfo(share.Path), rs.Data);
                    try
                    {
                        rs.Data.Save(share.ID);
                    }
                    catch (Exception e)
                    {
                        LogManager.GetLogger("faplog").Warn("Failed save share info for " + share.Name, e);
                    }
                    return rs.Data;
                }
            }
            finally
            {
                model.ReleaseAntiShutdownLock();
            }
        }
Exemplo n.º 2
0
        private void AddCommand()
        {
            string folder = string.Empty;
            if (browser.SelectFolder(out folder))
            {
                if (model.Shares.Where(os => os.Path == folder).Count() > 0)
                {
                    logger.Debug("A share with this path already exists");
                }

                try
                {
                    //Check folder is accessible.
                    Directory.GetFiles(folder);

                    if (model.Shares.Where(sh => sh.Path == folder).Count() > 0)
                    {
                        MessageBox.Show("You have already shared this folder!");
                        return;
                    }

                    var s = new Share();
                    string name = folder;
                    if (name.Contains(Path.DirectorySeparatorChar))
                    {
                        name = name.Substring(name.LastIndexOf(Path.DirectorySeparatorChar) + 1,
                                              (name.Length - name.LastIndexOf(Path.DirectorySeparatorChar)) - 1);
                    }
                    //Check name is valid and ok
                    var messagebox = container.Resolve<MessageBoxViewModel>();
                    messagebox.Response = name;
                    messagebox.Message = "What do you want to name the share?";
                    if (messagebox.ShowDialog())
                        name = messagebox.Response;
                    else
                        return;

                    if (name.Length > 0)
                    {
                        s.Name = name;
                        s.Path = folder;
                        model.Shares.Add(s);
                        ThreadPool.QueueUserWorkItem(AsyncRefresh, s);
                    }
                }
                catch (Exception e)
                {
                    logger.Error("Add share error", e);
                    container.Resolve<IMessageService>().ShowError("Failed to add share: " + e.Message);
                }
            }
        }