Exemplo n.º 1
0
        private void buttonAddDir_Click(object sender, RoutedEventArgs e)
        {
            var pickedFolder = new FolderPickerDialog();

            try {
                if (pickedFolder.ShowDialog() == true)
                {
                    string path = pickedFolder.SelectedPath;
                    if (path == null)
                    {
                        throw new ActionException("No folder was chosen.", ActionType.Directory);
                    }
                    //DirIdentity did = new DirIdentity(path.Substring(path.LastIndexOf('\\') + 1),
                    //	null, path);
                    DirectoryContents dcNew = new DirectoryContents(
                        path.Substring(path.LastIndexOf('\\') + 1), path, null, null, true);
                    foreach (DirectoryContents dc in Directories)
                    {
                        if (dc.Name.Equals(dcNew.Name) || dc.LocalPath.Equals(dcNew.LocalPath))
                        {
                            throw new ActionException("Folder already exists on this machine.",
                                                      ActionType.Directory);
                        }
                    }
                    Directories.Add(dcNew);
                    machine.Directories.Add(dcNew);
                }
            } catch (ActionException ex) {
                MessageBox.Show(ex.Message, ex.Title);
            }
        }
Exemplo n.º 2
0
        private void Populate(TreeNode parent, JungleDiskBucket bucket, string path)
        {
            TreeNode          node;
            DirectoryContents contents = null;

            try
            {
                contents = conn.GetDirectoryListing(bucket, path);
            }
            catch (Exception ex)
            {
                return;
            }

            foreach (DirectoryItem item in contents.SortedDirectories)
            {
                node            = parent.Nodes.Add(item.Name);
                node.ImageIndex = imgFolder;
                node.Tag        = item;
                node.Nodes.Add(".");
            }

            foreach (DirectoryItem item in contents.SortedFiles)
            {
                node            = parent.Nodes.Add(item.Name);
                node.ImageIndex = imgFile;
                node.Tag        = item;
            }
        }
Exemplo n.º 3
0
        private void optionDownloadDir_Click(object sender, RoutedEventArgs e)
        {
            try {
                if (SelectedDirectoryIndex < 0)
                {
                    throw new ActionException("No directory was selected to download.",
                                              ActionType.Directory);
                }

                DirectoryIdentity did = machine.Directories[SelectedDirectoryIndex];
                var dc = new DirectoryContents(credentials, machine, did, true, true);
                if (dc.SaveToDisk())
                {
                    new SystemMessage("FileSync", "File sync successful.",
                                      "Selected directory was downloaded and restored.", MemeType.FuckYea)
                    .ShowDialog();
                }

                //var files = DirActions.Download(credentials, machine.Identity, did);
                //foreach (FileContents f in files)
                //	f.SaveToDisk(did);

                RefreshDisplayedDirectories();

                //MessageBox.Show("Directory restored.", "FileSync",
                //    MessageBoxButton.OK, MessageBoxImage.Information);
            } catch (ActionException ex) {
                new SystemMessage(ex).ShowDialog();
                //MessageBox.Show(ex.Message, ex.Title);
            }
        }
Exemplo n.º 4
0
        public void AddFile(Credentials c, MachineContents m, DirectoryContents d,
                            FileContents f)
        {
            GetDirList(c, m);
            f.Dir = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
            if (!CheckFileExistence(c, m, d, f))
            {
                AddFileContent(f);
                //TypeManipulator.TypeToId(f);
                File f1 = File.CreateFile(1, f.Dir, 1, f.Content, f.Name, f.Size, f.Hash,
                                          f.Uploaded, f.Modified);
                using (filesyncEntities context = new filesyncEntities()) {
                    context.Files.AddObject(f1);
                    context.SaveChanges();
                }
            }
            else
            {
                GetFileId(c, m, d, f);
                GetFileContentId(c, m, d, f);
                UpdateFileContent(f);
                //TypeManipulator.TypeToId(f);

                using (filesyncEntities context = new filesyncEntities()) {
                    File f1 = (from o in context.Files where o.file_id == f.Id select o).Single();
                    f1.file_hash     = f.Hash;
                    f1.file_modified = f.Modified;
                    f1.file_size     = f.Size;
                    f1.file_uploaded = f.Uploaded;

                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 5
0
        public DirectoryContents GetDirectoryWithFiles(Credentials c, MachineContents m,
                                                       DirectoryIdentity did)
        {
            var cl = new Ref.FileSyncModelClient();

            try {
                DirectoryContents newD = new DirectoryContents(did);
                newD.Files = cl.GetFileList(c, m, newD);
                cl.Close();
                if (newD == null)
                {
                    throw new ActionException("Received a null object.", ActionType.User);
                }
                return(newD);

                //DirectoryContents d = null;
                //d = cl.GetDirectoryWithFiles(c, m, did);
                //cl.Close();
                //return d;
            } catch (ActionException ex) {
                cl.Abort();
                throw new ActionException("Unable to download directory contents.",
                                          ActionType.Directory, MemeType.Fuuuuu, ex);
            } catch (Exception ex) {
                cl.Abort();
                throw new ActionException("Error while downloading directory contents.",
                                          ActionType.Directory, MemeType.Fuuuuu, ex);
            }
        }
Exemplo n.º 6
0
        public MachineContents GetMachineWithDirs(Credentials c, MachineIdentity m)
        {
            MachineContents mc = new MachineContents(m);


            using (filesyncEntitiesNew context = new filesyncEntitiesNew())
            {
                int mach_id = MachineNameToId(context, m.Name);
                if (mach_id == -1)
                {
                    return(null);
                }
                mc.Id = mach_id;
                List <DirectoryContents> dirlist = new List <DirectoryContents>();

                foreach (var x in (from md in context.MachineDirs
                                   join d in context.Dirs on md.dir_id equals d.dir_id
                                   where md.machine_id == mach_id
                                   select new { md.dir_realpath, d }))
                {
                    var dir = new DirectoryContents(x.d.dir_name, x.d.dir_description, x.dir_realpath);
                    dir.Id    = x.d.dir_id;
                    dir.Owner = x.d.user_ownerid;
                    dirlist.Add(dir);
                }
                mc.Directories = dirlist;
                return(mc);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Removes the duplicate files inside this directory. It performes basing on
        /// the rule, which states that file names must not repeat.
        /// </summary>
        private void RemoveDuplicateFiles(DirectoryContents d)
        {
            // Possible second rule example (not introduced):
            // If hash of file.txt equals to hash of file.bmp, both are preserved.
            // If, on the other hand, hash of file.txt equals to hash of file2.txt the later file
            // is preserved.

            if (d.Files == null || d.Files.Count <= 1)
            {
                return;
            }

            List <FileContents> sortedFiles = new List <FileContents>(d.Files);

            sortedFiles.Sort(FileComparison);

            for (int i = 0; i < sortedFiles.Count - 1; i++)
            {
                if (sortedFiles[i].Name.Equals(sortedFiles[i + 1].Name))
                {
                    sortedFiles.RemoveAt(i);
                    i--;
                }
            }

            d.Files = sortedFiles;
        }
Exemplo n.º 8
0
        public DirectoryContents GetDirectoryWithFiles(Credentials c, MachineContents m, DirectoryIdentity d)
        {
            List <FileContents> filelist = new List <FileContents>();

            m.Directories = GetDirList(c, m);
            d.Id          = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
            var dc = new DirectoryContents(d);

            using (filesyncEntitiesNew context = new filesyncEntitiesNew())
            {
                foreach (var x in (from f in context.Files
                                   join t in context.Types on f.type_id equals t.type_id
                                   where f.dir_id == d.Id
                                   select new { f, t.type_name }))
                {
                    FileIdentity file = new FileIdentity(x.f.file_name, x.f.file_modified,
                                                         x.f.file_uploaded, FileType.PlainText, x.f.file_size, x.f.file_hash);
                    file.Content = x.f.content_id;
                    file.Id      = x.f.file_id;
                    filelist.Add(new FileContents(file));
                }
            }
            dc.Files = filelist;
            return(dc);
        }
Exemplo n.º 9
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            DirectoryContents contents = m_portalReader.GetRootDirectoryContents();

            ShowSubNodes(contents, treeView1.Nodes[0]);
        }
Exemplo n.º 10
0
        public static void Main(string[] args)
        {
            var startPath = "C:\\maven";
            var dirContents = new DirectoryContents(startPath);

            var file = "../../directory-content.xml";
            dirContents.AsXmlUsingXDocument(file);
        }
Exemplo n.º 11
0
        public static void Main(string[] args)
        {
            var startPath   = "C:\\maven";
            var dirContents = new DirectoryContents(startPath);

            var file = "../../directory-content.xml";

            dirContents.AsXmlUsingXDocument(file);
        }
Exemplo n.º 12
0
        private static void AddMachDir(MachineContents m, DirectoryContents d)
        {
            MachineDir md1 = MachineDir.CreateMachineDir(m.Id, d.Id, d.LocalPath);

            using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
                context.MachineDirs.AddObject(md1);
                context.SaveChanges();
            }
        }
Exemplo n.º 13
0
        public void ShowSubNodes(DirectoryContents contents, TreeNode node)
        {
            node.Tag = contents;

            foreach (uint rootDirPtr in contents.m_subDirLocations)
            {
                TreeNode subNode = new TreeNode(String.Format("0x{0:X8}", rootDirPtr));
                node.Nodes.Add(subNode);
            }
        }
Exemplo n.º 14
0
 public void GetFileContent(Credentials c, MachineContents m, DirectoryContents d,
                            FileContents f)
 {
     f.Id = GetFileContentId(c, m, d, f);
     using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
         Content c1 = (from o in context.Contents
                       where o.content_id == f.Content
                       select o).Single();
         f.Data = c1.content_data;
     }
 }
Exemplo n.º 15
0
        public static async Task Go()
        {
            var destination = new DirectoryInfo("GitHubPages");

            if (destination.Exists)
            {
                foreach (var file in destination.EnumerateFiles("*.*", SearchOption.AllDirectories))
                {
                    file.Delete();
                }
                foreach (var folder in destination.EnumerateDirectories("*.*", SearchOption.AllDirectories))
                {
                    folder.Delete(recursive: true);
                }
            }
            else
            {
                destination.Create();
            }

            var sourceSite = new Uri("http://*****:*****@"D:\github\Blog\Blog\App_Data\Posts");

            if (!postSourceFolder.Exists)
            {
                throw new ArgumentException("postSourceFolder does not exist");
            }
            var posts = await new SingleFolderPostRetriever(postSourceFolder).Get();

            FetchBlog(
                sourceSite,
                destination,
                additionalUrlsToRetrieve: posts.Select(post => new Uri("/Read/" + post.Id, UriKind.Relative))
                );

            // Copy all Posts into Archive/slug (there seem to be some links out in the wild that expect this.. not sure where they came from)
            foreach (var post in posts)
            {
                var primaryFile = new FileInfo(Path.Combine(destination.FullName, post.Slug + ".html"));
                if (!primaryFile.Exists)
                {
                    throw new Exception("Whhhhhaaaa?!");
                }
                primaryFile.CopyTo(Path.Combine(destination.FullName, "Archive", post.Slug + ".html"), overwrite: false); // Shouldn't already exist
            }
            var searchIndexFile = new FileInfo(
                @"D:\github\Blog\Blog\App_Data\SearchIndex.dat"
                );

            JsonSearchIndexDataRecorder.Write(searchIndexFile, destination);
            PlainTextContentRecorder.Write(posts, destination);
        }
Exemplo n.º 16
0
 private void GetFileId(Credentials c, MachineContents m, DirectoryContents d,
                        FileContents f)
 {
     GetDirList(c, m);
     d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
     using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
         int file_id = (from o in context.Files
                        where (o.file_name == f.Name) && (o.dir_id == d.Id)
                        select o.file_id).Single();
         f.Id = file_id;
     }
 }
Exemplo n.º 17
0
 private int GetFileContentId(Credentials c, MachineContents m, DirectoryContents d,
                              FileContents f)
 {
     m.Directories = GetDirList(c, m);
     d.Id          = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
     using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
         int content_id = (from o in context.Files
                           where (o.file_name == f.Name) && (o.dir_id == d.Id)
                           select o.content_id).Single();
         f.Content = content_id;
     }
     return(f.Content);
 }
Exemplo n.º 18
0
        public bool AddDirectory(Credentials c, MachineContents m, DirectoryContents d)
        {
            var cl = new Ref.FileSyncModelClient();

            try {
                bool result = false;
                result = cl.AddDirectory(c, m, d);
                cl.Close();
                return(result);
            } catch (Exception ex) {
                cl.Abort();
                throw new ActionException("Unable to create a new directory in the database.",
                                          ActionType.Directory, MemeType.Fuuuuu, ex);
            }
        }
Exemplo n.º 19
0
        public FileContents GetFileWithContent(Credentials c, MachineContents m, DirectoryContents d,
                                               FileIdentity f)
        {
            var fc = new FileContents(f);

            GetFileContentId(c, m, d, fc);
            using (filesyncEntitiesNew context = new filesyncEntitiesNew())
            {
                Content c1 = (from o in context.Contents
                              where o.content_id == f.Content
                              select o).Single();
                fc.Data = c1.content_data;
            }
            return(fc);
        }
Exemplo n.º 20
0
        private static void AddDir(DirectoryContents d)
        {
            int AddedDirId;
            Dir d1 = Dir.CreateDir(1, d.Name, d.Owner);

            d1.dir_description = d.Description;

            using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
                context.Dirs.AddObject(d1);
                context.SaveChanges();
                AddedDirId = (from z in context.Dirs select z).ToList().Last().dir_id;
            }

            d.Id = AddedDirId;
        }
Exemplo n.º 21
0
        public bool AddFile(Credentials c, MachineContents m, DirectoryContents d,
                            FileContents f)
        {
            var cl = new Ref.FileSyncModelClient();

            try {
                bool result = false;
                result = cl.AddFile(c, m, d, f);
                cl.Close();
                return(result);
            } catch (Exception ex) {
                cl.Abort();
                throw new ActionException("Error occurred while file was uploaded.",
                                          ActionType.File, MemeType.Fuuuuu, ex);
            }
        }
Exemplo n.º 22
0
 private bool CheckFileExistence(Credentials c, MachineContents m, DirectoryContents d,
                                 FileContents f)
 {
     GetDirList(c, m);
     d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
     try {
         using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
             (from o in context.Files
              where (o.file_name == f.Name) && (o.dir_id == d.Id)
              select o.file_id).Single();
         }
     } catch {
         return(false);
     }
     return(true);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Save the whole data set as a series of files in the given directory.
        /// </summary>
        public void SaveToDirectory(string directory)
        {
            DirectoryTable.SaveToFile(directory, s_directoryTableFileName);
            FileTable.SaveToFile(directory, s_fileTableFileName);
            PathTable.SaveToFile(directory, s_pathTableFileName);
            PipTable.SaveToFile(directory, s_pipTableFileName);
            PipExecutionTable.SaveToFile(directory, s_pipExecutionTableFileName);
            StringTable.SaveToFile(directory, s_stringTableFileName);
            WorkerTable.SaveToFile(directory, s_workerTableFileName);

            ConsumedFiles?.SaveToFile(directory, s_consumedFilesFileName);
            DeclaredInputDirectories?.SaveToFile(directory, s_declaredInputDirectoriesFileName);
            DeclaredInputFiles?.SaveToFile(directory, s_declaredInputFilesFileName);
            DirectoryContents?.SaveToFile(directory, s_directoryContentsFileName);
            PipDependencies?.SaveToFile(directory, s_pipDependenciesFileName);
        }
Exemplo n.º 24
0
        public void AddDirectory(Credentials c, MachineContents m, DirectoryContents d)
        {
            GetDirList(c, m);
            int NoSuchNameYet = (from o in m.Directories where o.Name == d.Name select o).Count();

            if (NoSuchNameYet != 0)
            {
                // throw new Exception("directory with given name already exists");
                //no action needed
            }
            else
            {
                d.Owner = LoginToId(c.Login);
                AddDir(d);
                m.Id = MachineNameToId(m.Name);
                AddMachDir(m, d);
            }
        }
Exemplo n.º 25
0
        public void GetDirList(Credentials c, MachineContents m)
        {
            int mach_id = MachineNameToId(m.Name);
            List <DirectoryContents> dirlist = new List <DirectoryContents>();

            using (filesyncEntities context = new filesyncEntities()) {
                foreach (var x in (from md in context.MachineDirs
                                   join d in context.Dirs on md.dir_id equals d.dir_id
                                   where md.machine_id == mach_id
                                   select new { md.dir_realpath, d }))
                {
                    var dir = new DirectoryContents(x.d.dir_name, x.d.dir_description, x.dir_realpath);
                    dir.Id    = x.d.dir_id;
                    dir.Owner = x.d.user_ownerid;
                    dirlist.Add(dir);
                }
                m.Directories = dirlist;
            }
        }
Exemplo n.º 26
0
        private void optionUploadDir_Click(object sender, RoutedEventArgs e)
        {
            try {
                if (SelectedDirectoryIndex < 0)
                {
                    throw new ActionException("No directory was selected to upload.",
                                              ActionType.Directory);
                }

                DirectoryContents dc = machine.Directories[SelectedDirectoryIndex];
                new SystemMessage(dc.Upload(credentials, machine)).ShowDialog();
                //DirActions.Upload(credentials, machine.Identity, did, new DirContents(did, true));

                //MessageBox.Show("Backup of the selected directory complete.", "FileSync",
                //	MessageBoxButton.OK, MessageBoxImage.Information);
            } catch (ActionException ex) {
                new SystemMessage(ex).ShowDialog();
                //MessageBox.Show(ex.Message, ex.Title);
            }
        }
Exemplo n.º 27
0
        public FileContents GetFileWithContent(Credentials c, MachineContents m,
                                               DirectoryContents d, FileIdentity fid)
        {
            var cl = new Ref.FileSyncModelClient();

            try {
                FileContents f = null;
                f = cl.GetFileWithContent(c, m, d, f);
                cl.Close();
                if (f == null)
                {
                    throw new ActionException("Received a null object.", ActionType.User);
                }
                return(f);
            } catch (Exception ex) {
                cl.Abort();
                throw new ActionException("Error while downloading file contents from database.",
                                          ActionType.File, MemeType.Fuuuuu, ex);
            }
        }
Exemplo n.º 28
0
        public bool AddDirectory(Credentials c, MachineContents m, DirectoryContents d)
        {
            m.Directories = GetDirList(c, m);
            int NoSuchNameYet = (from o in m.Directories where o.Name == d.Name select o).Count();

            if (NoSuchNameYet != 0)
            {
                // throw new Exception("directory with given name already exists");
                //no action needed
            }
            else
            {
                using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
                    d.Owner = LoginToId(context, c.Login);
                }
                AddDir(d);
                using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
                    m.Id = MachineNameToId(context, m.Name);
                }
                AddMachDir(m, d);
            }
            return(true);
        }
Exemplo n.º 29
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Tag == null)
            {
                uint fileId = uint.Parse(e.Node.Text.Substring(2), NumberStyles.HexNumber);
                DirectoryContents contents = m_portalReader.GetDirectoryContents(fileId);
                ShowSubNodes(contents, e.Node);
            }

            if (e.Node.Tag != null && e.Node.Tag is DirectoryContents)
            {
                StringBuilder     sb       = new StringBuilder();
                DirectoryContents contents = e.Node.Tag as DirectoryContents;
                foreach (uint fileId in contents.m_fileIds)
                {
                    sb.Append(String.Format("0x{0:X8}{1}", fileId, Environment.NewLine));
                }
                textBox1.Text = sb.ToString();
            }
            else
            {
                textBox1.Text = "";
            }
        }
Exemplo n.º 30
0
        public bool UploadDirectory(IFileSyncModel connection, Credentials c, MachineIdentity m,
                                    DirectoryContents d)
        {
            //add dir if it does not exist
            if (!connection.AddDirectory(c, new MachineContents(m), d))
            {
                return(false);
            }

            foreach (FileContents f in d.Files)
            {
                try {
                    FileContents fUp = null;
                    if (f.Size == 0)
                    {
                        fUp = ReadFileContents(f, d);
                    }
                    else
                    {
                        fUp = f;
                    }

                    if (!UploadFile(connection, c, m, d, f))
                    {
                        return(false);
                    }
                } catch (ActionException ex) {
                    throw new ActionException("Couldn't upload the directory contents.",
                                              ActionType.Directory, ex);
                } catch (Exception ex) {
                    throw new ActionException("Error while uploading a directory.",
                                              ActionType.Directory, ex);
                }
            }
            return(true);
        }
Exemplo n.º 31
0
        public DirectoryContents ReadDirectoryContents(DirectoryIdentity did,
                                                       bool addFilesContents = false)
        {
            if (did.LocalPath == null || did.LocalPath.Equals(EmptyLocalPath))
            {
                return(null);
            }

            string[] filePaths = Directory.GetFiles(did.LocalPath);

            DirectoryContents d = new DirectoryContents(did, new List <FileContents>());

            if (filePaths == null || filePaths.Length == 0)
            {
                return(null);
            }

            foreach (string path in filePaths)
            {
                FileContents fc = ReadFileContents(path);
                d.Files.Add(fc);
            }
            return(d);
        }