Пример #1
0
        private void openWithExploererTsmi_Click(object sender, System.EventArgs e)
        {
            NavigatePanelNode node = treeView.SelectedNode as NavigatePanelNode;

            if (node == null)
            {
                return;
            }

            if (node is FolderNode)
            {
                Data.Folder folder = (node as FolderNode).Folder;
                if (folder == null || folder.Project == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start("EXPLORER.EXE", folder.Project.GetAbsolutePath(folder.RelativePath));
            }
            else if (node is FileNode)
            {
                Data.File file = (node as FileNode).FileItem;
                if (file == null || file.Project == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start("EXPLORER.EXE", "/select,\"" + file.Project.GetAbsolutePath(file.RelativePath) + "\"");
            }
        }
Пример #2
0
        public UIFileDisplay(Data.File file)
        {
            File     = file;
            FileInfo = File.FileInfo;
            if (file.IsFolder)
            {
                Glyph = FolderGlyph;
            }
            else
            {
                string   ext  = System.IO.Path.GetExtension(file.Name).ToLower().TrimStart('.');
                FileType type = FileType.FileTypes.FirstOrDefault(p => p.Extensions.Contains(ext));
                if (type != null)
                {
                    Glyph = type.Glyph;
                }
            }

            if (DebugSwitch.OnDisplayPropertyChanged)
            {
                PropertyChanged += (p1, p2) =>
                {
                    System.Diagnostics.Debug.WriteLine("Display Prop Changed: " + p2.PropertyName);
                };
            }
        }
Пример #3
0
 public FileNode(Data.File file) : base(file)
 {
     if (FileNodeCreated != null)
     {
         FileNodeCreated(this);
     }
 }
Пример #4
0
 public void TestNameWithoutPathWithNullName()
 {
     Data.File file = new Data.File {
         Name = null
     };
     Assert.AreEqual(null, file.NameWithoutPath);
 }
Пример #5
0
 public void TestNameWithoutPathWithEmptyName()
 {
     Data.File file = new Data.File {
         Name = string.Empty
     };
     Assert.AreEqual(string.Empty, file.NameWithoutPath);
 }
Пример #6
0
        public void TestFileProgressWithSizeOfZero()
        {
            Data.File file = new Data.File {
                Downloaded = 345, Size = 0
            };
            int progress = file.Progress;

            Assert.AreEqual(0, progress);
        }
Пример #7
0
        public void TestNameWithoutPath()
        {
            Data.File file = new Data.File {
                Name = "/azerty/qwerty/file.txt"
            };
            const string expected = "file.txt";

            Assert.AreEqual(expected, file.NameWithoutPath);
        }
Пример #8
0
        public void TestFileProgress()
        {
            const long d = 354;
            const long s = 424;
            Data.File file = new Data.File {Downloaded = d, Size = s};
            int progress = file.Progress;

            const double x = d / (double)s;
            const int expected = (int)(x * 100);
            Assert.AreEqual(expected, progress);
        }
Пример #9
0
 private bool Callback(double per, Data.File file)
 {
     if (stopping)
     {
         Dispatcher.Invoke(() =>
         {
             working = false;
             Close();
         });
         return(false);
     }
     Percentage = per;
     Message    = $"正在处理({100 * per:N2}%):" + file.GetAbsolutePath();
     return(true);
 }
Пример #10
0
        public void TestFileProgress()
        {
            const long d = 354;
            const long s = 424;

            Data.File file = new Data.File {
                Downloaded = d, Size = s
            };
            int progress = file.Progress;

            const double x        = d / (double)s;
            const int    expected = (int)(x * 100);

            Assert.AreEqual(expected, progress);
        }
Пример #11
0
        public static ReturnObject Upload(HttpContext context, string parent_type, long parent_id)
        {
            var file = context.Request.Files["file"];
            string path = context.Server.MapPath("~/upload/" + parent_type + "/" + parent_id.ToString() + "/");

            if( !Directory.Exists(path) )
                Directory.CreateDirectory(path);

            string ext = Path.GetExtension(file.FileName);

            string fn = Guid.NewGuid().ToString()+ext;

            while( File.Exists(Path.Combine(path,fn)) )
                fn = Guid.NewGuid().ToString() + ext;

            fn = Path.Combine(path,fn);

            file.SaveAs( fn );

            var item = new Data.File();
            item.ParentType = parent_type;
            item.ParentID = parent_id;
            item.Path = fn;
            item.Name = file.FileName;
            item.ContentType = file.ContentType;
            item.Save();

            var ret = new ReturnObject() {
                Result = MapPathReverse(fn),
                Growl = new ReturnGrowlObject() {
                    Type = "default",
                    Vars = new ReturnGrowlVarsObject() {
                        text = "You have successfully uploaded a file.",
                        title = "File Uploaded"
                    }
                }
            };

            return ret;
        }
Пример #12
0
        private void fsTimer_Tick(object sender, System.EventArgs e)
        {
            lock (fileSystemEvents)
            {
                while (fileSystemEvents.Count != 0)
                {
                    System.IO.FileSystemEventArgs fs = fileSystemEvents.Values.FirstOrDefault();
                    fileSystemEvents.Remove(fs.FullPath);
                    {
                        Controller.AppendLog(fs.Name + " changed");
                        string    relativePath = GetRelativePath(fs.FullPath);
                        Data.File file         = GetItem(relativePath) as Data.File;
                        if (file == null)
                        {
                            return;
                        }
                        Data.ITextFile textFile = file as Data.ITextFile;
                        if (textFile == null)
                        {
                            return;
                        }
                        if (textFile.Dirty)
                        {
                            Controller.AppendLog(fs.FullPath + " conflict!");
                        }
                        else
                        {
                            DateTime lastWriteTime = System.IO.File.GetLastWriteTime(fs.FullPath);
                            if (textFile.LoadedFileLastWriteTime != lastWriteTime)
                            {
                                textFile.LoadFormFile();
                                textFile.Update();
                            }
                        }
                    }
                }
//                fsTimer.Enabled = false;
            }
        }
Пример #13
0
        /// <summary>
        /// Creates the <see cref="File"/> base on <see cref="FileInfo"/>.
        /// </summary>
        /// <param name="info">The file info.</param>
        /// <param name="parent">The parent</param>
        /// <returns>The result file.</returns>
        /// <remarks>
        /// It can't be merged with <see cref="DirectoryExtensions.ToDirectory"/>,
        /// because <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> have different hierarchy.
        /// </remarks>
        public static Data.File ToFile(this FileInfo info, Data.Directory parent)
        {
            var file = new Data.File
            {
                Name             = info.FullName,
                Parent           = parent,
                CreationDate     = info.CreationTime,
                LastAccessDate   = info.LastAccessTime,
                ModificationDate = info.LastWriteTime,
                Size             = info.Length
            };

            var access = info.GetAccessControl();

            try
            {
                file.Owner = access.GetOwner(typeof(System.Security.Principal.NTAccount)).Value;
            }
            catch (Exception)
            {
                file.Owner = "N/A";
            }

            file.Attributes = EnumUtil.GetNameValue <FileAttributes>().Where(o => (info.Attributes & o.Value) > 0).Select(o => o.Key).ToArray();
            file.UserRights = new[] { "N/A" };

            var currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

            foreach (FileSystemAccessRule rule in access.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
            {
                if (rule.IdentityReference.Value == currentUser)
                {
                    file.UserRights = EnumUtil.GetNameValue <FileSystemRights>().Where(o => (rule.FileSystemRights & o.Value) > 0).Select(o => o.Key).ToArray();
                    break;
                }
            }
            return(file);
        }
Пример #14
0
        protected void btnAddFile_Click(object sender, EventArgs evArgs)
        {
            Data.File f = new Data.File();
            f.name = fileName.Text;
            if (String.IsNullOrWhiteSpace(f.name))
                f.name = "New file";
            f.date_created = DateTime.Now;
            f.owner = Data.UserManager.GetUser().id;
            f.is_public = f.name.Length % 2;

            if (null != fileAdd.PostedFile)
            {
                try
                {
                    f.filename = fileAdd.PostedFile.FileName;

                    Data.FileManager.AddFile(f);
                }
                catch (Exception e)
                {

                }
            }
        }
Пример #15
0
 public void TestNameWithoutPathWithEmptyName()
 {
     Data.File file = new Data.File {Name = string.Empty};
     Assert.AreEqual(string.Empty, file.NameWithoutPath);
 }
Пример #16
0
 private void ShowProgressMessage(Data.File file)
 {
     Dispatcher.Invoke(() =>
                       MainWindow.Current.SetProcessRingMessage(
                           "正在导出" + Environment.NewLine + Path.Combine(file.Dir, file.Name)));
 }
Пример #17
0
 public void TestFileProgressWithSizeOfZero()
 {
     Data.File file = new Data.File {Downloaded = 345, Size = 0};
     int progress = file.Progress;
     Assert.AreEqual(0, progress);
 }
Пример #18
0
 public void TestNameWithoutPath()
 {
     Data.File file = new Data.File {Name = "/azerty/qwerty/file.txt"};
     const string expected = "file.txt";
     Assert.AreEqual(expected, file.NameWithoutPath);
 }
Пример #19
0
 public void TestNameWithoutPathWithNullName()
 {
     Data.File file = new Data.File {Name = null};
     Assert.AreEqual(null, file.NameWithoutPath);
 }