Exemplo n.º 1
0
        public BaseFile(BaseFolder Parentdir, string Name)
        {
            if (Parentdir == null) throw new ArgumentNullException();
            ParentFolder = Parentdir;
            this.Name = Name;

            RelativePath = Path.Combine(Parentdir.RelativePath, Name);

            MetaPath = Path.Combine(Parentdir.MetaPath, Name);
            RealPath = Path.Combine(Parentdir.RealPath, Name);
        }
Exemplo n.º 2
0
        public BaseFolder(BaseFolder ParentFolder, string Name)
        {
            this.ParentFolder = ParentFolder;
            this.FS = ParentFolder.FS;
            this.RelativePath = RelativePath;
            this.Name = Name;

            RelativePath = Path.Combine(ParentFolder.RelativePath, Name);
            MetaPath = Path.Combine(ParentFolder.MetaPath, Name);
            RealPath = Path.Combine(ParentFolder.RealPath, Name);

            init();
        }
Exemplo n.º 3
0
        public BaseFile(BaseFolder ParentFolder, FileMetaInfo MetaFile)
        {
            this.ParentFolder = ParentFolder;
            this.Name = MetaFile.Name;

            RelativePath = Path.Combine(ParentFolder.RelativePath, Name);
            MetaPath = Path.Combine(ParentFolder.MetaPath, Name);
            RealPath = Path.Combine(ParentFolder.RealPath, Name);

            _meta = MetaFile;
            _meta.ParenFile = this;

            MetaFile.Save();
        }
Exemplo n.º 4
0
 public NewFolderMessage(BaseFolder srcFolder)
 {
     // TODO: Complete member initialization
     this.srcFolder = srcFolder;
 }
Exemplo n.º 5
0
        private void TvFS_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (selected == "..")
            {
                v_curdir = v_curdir.ParentFolder as BaseFolder;
                return;
            }

            var pfold = v_curdir.Folders.FirstOrDefault(x => x.Name == selected);
            if (pfold != null)
            {
                v_curdir = pfold;
                return;
            }

            var file = v_curdir.Files.FirstOrDefault(x => x.Name == selected);
            if (file == null) return;

            var opres = file.Open();
            if (!opres)
            {
                MessageBox.Show("Файл открыт на другом узле");
                return;
            }
            var p = new Process();
            p.EnableRaisingEvents = true;
            p.StartInfo = new ProcessStartInfo(file.RealPath);
            p.Exited += (s, q) =>
            {
                file.Close();
            };
            p.Start();
        }
Exemplo n.º 6
0
 void synchfolders(BaseFolder srcFolder, FSObjectEvents eventtype)
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         v_curdir = v_curdir;
     }), null);
 }
Exemplo n.º 7
0
 void copydir(string from, BaseFolder to)
 {
     var newf = to.FS.CreateFolder(to, new DirectoryInfo(from).Name, FSObjectEvents.local_created);
     foreach (var f in Directory.GetFiles(from))
         c.FileSystem.AddFile(newf, f);
     foreach (var f in Directory.GetDirectories(from))
         copydir(f, newf);
 }
Exemplo n.º 8
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (c.State != ClientStates.Offline)
            {
                c.ShutDown();
            }
            else
            {
                c.Up();

                c.FileSystem.OnFileEvent += synchfiles;
                c.FileSystem.OnFolderEvent += synchfolders;

                RemoteClients.Clear();
                foreach (var it in c.RemoteClients) RemoteClients.Add(it);
                c.RemoteClients.CollectionChanged += RemoteClients_CollectionChanged;

                v_curdir = c.FileSystem.RootDir;

                N("Items");
            }
        }
Exemplo n.º 9
0
 void FileSystem_OnFolderEvent(BaseFolder srcFolder, FSObjectEvents eventtype)
 {
     if (eventtype == FSObjectEvents.local_created)
     {
         Log(LogLevel.Info, "Шлем команду \"создать папку {0}\"", srcFolder.Name);
         Environment.SendToAll(new NewFolderMessage(srcFolder));
     }
     if (eventtype == FSObjectEvents.local_delete)
     {
         Log(LogLevel.Info, "Шлем команду \"удалить папку {0}\"", srcFolder.Name);
         Environment.SendToAll(new DeleteFSObjMessage(srcFolder));
     }
 }
Exemplo n.º 10
0
        private void LoadFS(BaseFolder RootDir)
        {
            lock (RootDir.FS)
            {
                foreach (var f in Directory.GetDirectories(RootDir.MetaPath))
                {
                    var d = new BaseFolder(RootDir, new DirectoryInfo(f).Name);
                    RootDir.Folders.Add(d);
                }

                foreach (var f in Directory.GetFiles(RootDir.MetaPath))
                {
                    var newf = new BaseFile(RootDir, new FileInfo(f).Name);
                    RootDir.Files.Add(newf);
                    newf.OnFileEvent += OnFileEventHandled;
                }

                foreach (var f in RootDir.Folders)
                    LoadFS(f);
            }
        }
Exemplo n.º 11
0
        private IFSObject FindFSObjByRelativePath(string RelPath, BaseFolder folder)
        {
            lock (this)
            {
                foreach (var it in folder.Files)
                    if (it.RelativePath == RelPath) return it;
                foreach (var it in folder.Folders)
                    if (it.RelativePath == RelPath) return it;

                foreach (var it in folder.Folders)
                {
                    var res = FindFSObjByRelativePath(RelPath, it as BaseFolder);
                    if (res != null) return res;
                }
                return null;
            }
        }
Exemplo n.º 12
0
 public virtual void OnFolderEventHandled(BaseFolder srcFolder, FSObjectEvents eventtype)
 {
     ///передача агрегированных событий
     if (OnFolderEvent != null)
         OnFolderEvent(srcFolder, eventtype);
 }
Exemplo n.º 13
0
 public List<BaseFile> GetFileList(BaseFolder rootdir = null)
 {
     if (rootdir == null) rootdir = RootDir;
     var ret = new List<BaseFile>();
     foreach (var it in rootdir.Files)
         ret.Add(it);
     foreach (var it in rootdir.Folders)
         ret.AddRange(GetFileList(it));
     return ret;
 }
Exemplo n.º 14
0
        /// <summary>
        /// CreateFolder folders without subfolders
        /// </summary>
        /// <param name="ParentFolder">parent folder</param>
        /// <param name="FolderName">folder name only (or '\\' for root)</param>
        /// <param name="CreationType">type of folder creatinon (by local or by remote)</param>
        /// <returns></returns>
        public BaseFolder CreateFolder(BaseFolder ParentFolder, string FolderName, FSObjectEvents CreationType)
        {
            //   if (ReadOnly) return null;

            if (!string.IsNullOrEmpty(FolderName) && FolderName.Length > 0 && FolderName != "\\" && FolderName[0] == '\\')
                FolderName = FolderName.Substring(1);
            if (FolderName.Contains("\\") || FolderName.Contains("/"))
            {
                var g = FolderName.Split('\\').ToList();
                while (g.Count > 0)
                {
                    var pfold = Path.Combine(ParentFolder.RelativePath, g[0]);
                    var tmpfold = FindFSObjByRelativePath(pfold, ParentFolder) as BaseFolder;
                    if (tmpfold == null)
                        ParentFolder = CreateFolder(ParentFolder, g[0], CreationType);
                    else ParentFolder = tmpfold;
                    g.RemoveAt(0);
                }
            }

            var realdir = Path.Combine(ParentFolder.RealPath, FolderName);
            if (Directory.Exists(realdir))
            {
                //Delete(dirtodel, FSObjectEvents.local_delete);
                throw new Exception(string.Format("Folder {0} exists!", FolderName));
                return Find(FolderName) as BaseFolder;
            }
            //create real
            //create meta
            try
            {
                lock (ParentFolder.FS)
                {
                    var f = ParentFolder.CreateFolder(FolderName);

                    ParentFolder.Folders.Add(f);

                    if (_OnFolderEvent != null)
                        _OnFolderEvent(f, CreationType);

                    return f;
                }
            }
            catch (Exception)
            {
                //ParentClient.Log(NLog.LogLevel.Error, ex.Message);
                return null;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Add file by metafileinfo
        /// </summary>
        /// <param name="ParentFolder">Direactory to move new file</param>
        /// <param name="MetaFile">new file meta information</param>
        /// <returns></returns>
        public BaseFile AddFile(BaseFolder ParentFolder, FileMetaInfo MetaFile, FSObjectEvents FileEventType)
        {
            //   if (ReadOnly) return null;

            lock (ParentFolder.FS)
            {
                var metapath = Path.Combine(ParentFolder.MetaPath, MetaFile.Name);

                if (File.Exists(metapath))
                    throw new Exception(string.Format("Файл \"{0}\" уже существует!", metapath));// return null;

                var f = new BaseFile(ParentFolder, MetaFile);
                ParentFolder.Files.Add(f);

                //add to files
                if (_OnFileEvent != null)
                    _OnFileEvent(f, FileEventType);

                return f;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// CreateFolder file+meta sourcelist existing file in local file system
        /// it meant that file where local_created
        /// </summary>
        /// <param name="ParentFolder">Direactory to move new file</param>
        /// <param name="pathToExistingfile">existing file</param>
        /// <returns></returns>
        public BaseFile AddFile(BaseFolder ParentFolder, string pathToExistingfile)
        {
            //        if (ReadOnly) return null;
            try
            {
                var f = ParentFolder.CreateFile(pathToExistingfile);
                lock (ParentFolder.FS)
                {
                    ParentFolder.Files.Add(f);
                }

                if (_OnFileEvent != null)
                    _OnFileEvent(f, FSObjectEvents.local_created);
                return f;

            }
            catch (Exception)
            {
                //ParentClient.Log(NLog.LogLevel.Error, rc.Message);
                return null;
            }
        }