Exemplo n.º 1
0
        public void AddRepository(FooTree tree, Guid ID)
        {
            if (tree == null)
                throw new ArgumentNullException("tree");
            if (ID == null)
                throw new ArgumentException("ID");

            Dirty = true;
            Modified = DateTime.Now;

            RepositoryState repository = new RepositoryState();
            repository.ID = ID;

            foreach (var file in tree.Files)
            {
                string filename = file.Key;

                repository.MTimes.Add(filename, file.Value.MTime);

                if (ID == RepositoryID)
                {
                    Origin.Add(filename, RepositoryID);
                }
            }

            Repositories.Add(ID, repository);
        }
Exemplo n.º 2
0
        void Run(string hostname, int port, string repo)
        {
            var foo = new FooSyncEngine();

            var client = new TcpClient(hostname, port);
            var stream = client.GetStream();
            var writer = new BinaryWriter(stream);
            var reader = new BinaryReader(stream);

            var passwd = new System.Security.SecureString();
            foreach (char c in "qwerty")
                passwd.AppendChar(c);

            RetCode ret;
            int count = 0;

            writer.Write(OpCode.Hello);
            ret = reader.ReadRetCode();

            Console.WriteLine("hello returned {0}", ret);

            Version protocolVersion = new Version(reader.ReadInt32(), reader.ReadInt32());
            String serverName = reader.ReadString();
            String serverDesc = reader.ReadString();
            Version serverVersion = new Version(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
            String helloString = reader.ReadString();

            Console.WriteLine("Protocol {0}\nName: {1}\nDescription: {2}\nServer {3}\n{4}", protocolVersion, serverName, serverDesc, serverVersion, helloString);

            writer.Write(OpCode.Auth);
            writer.Write("test");
            writer.Write(passwd);
            ret = reader.ReadRetCode();

            Console.WriteLine("auth returned {0}", ret);

            writer.Write(OpCode.ListRepos);
            ret = reader.ReadRetCode();
            count = reader.ReadInt32();

            Console.WriteLine("listrepos returned {0}", ret);
            Console.WriteLine("{0} repositories", count);

            for (int x = 0; x < count; x++)
            {
                var repoName = reader.ReadString();
                Console.WriteLine("> {0}", repoName);
            }

            writer.Write(OpCode.Hello);
            ret = reader.ReadRetCode();
            var s = reader.ReadString();

            Console.WriteLine("hello replied {0}", s);

            writer.Write(OpCode.Tree);
            writer.Write("test");
            ret = reader.ReadRetCode();

            Console.WriteLine("tree returned {0}", ret);

            var tree = new FooTree(foo, string.Format("fs://{0}:{1}/{2}", hostname, port, repo), stream,
                (item, total, path) =>
                    {
                        Console.WriteLine("{0}: {1}", item, path);
                    }
                );

            Console.WriteLine("{0} items in tree", tree.Files.Count);

            writer.Write(OpCode.GetFile);
            writer.Write("test");
            writer.Write(tree.Files.Keys.First());
            ret = reader.ReadRetCode();

            Console.WriteLine("getfile returned {0}", ret);

            var len = reader.ReadInt64();
            var bytes = reader.ReadBytes((int)len);

            stream.Close();
        }
Exemplo n.º 3
0
        private Dictionary<SyncGroupConfigMember, FooTree> GetTrees(SyncGroupConfig syncGroup)
        {
            Dictionary<SyncGroupConfigMember, FooTree> trees = new Dictionary<SyncGroupConfigMember, FooTree>();
            ICollection<string> exceptions = FooSyncEngine.PrepareExceptions(syncGroup.IgnorePatterns);
            Progress enumCallback = new Progress((current, total, name) =>
            {
                Console.Write("\r{0} items...", current);
            });

            foreach (SyncGroupConfigMember member in syncGroup.Members)
            {
                Console.Write("Enumerating files in ");

                FooTree tree = null;
                if (member.Url.IsLocal)
                {
                    Console.WriteLine(member.Url.LocalPath);

                    try
                    {
                        tree = new FooTree(Foo, member.Url.LocalPath, exceptions, enumCallback);
                        Console.WriteLine("\r{0} items.  ", tree.Files.Count);
                    }
                    catch (DirectoryNotFoundException)
                    {
                        Console.WriteLine("Directory {1} not found.", member.Url.LocalPath);
                        continue;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("{0} reading directory {1}: {2}",
                            ex.GetType().Name,
                            member.Url.LocalPath,
                            ex.Message);
                        continue;
                    }
                }
                else
                {
                    Console.WriteLine(member.UrlString);

                    NetClient nc = new NetClient(
                        Foo,
                        member.Url.Host,
                        member.Url.Port,
                        member.Auth == null ? string.Empty : member.Auth.User,
                        member.Auth == null ? string.Empty : member.Auth.Password,
                        member.Url.AbsolutePath.Substring(1)
                        );

                    tree = nc.GetTree(enumCallback);
                    Console.WriteLine("\r{0} items.  ", tree.Files.Count);
                }

                trees.Add(member, tree);
            }

            return trees;
        }
Exemplo n.º 4
0
        public static void UpdateRepoState(RepositoryStateCollection state, FooChangeSet changeset, FooTree repo, FooTree source)
        {
            if (state == null)
                throw new ArgumentNullException("state");
            if (changeset == null)
                throw new ArgumentNullException("changeset");
            if (repo == null)
                throw new ArgumentNullException("repo");
            if (source == null)
                throw new ArgumentNullException("source");

            /*
            foreach (var filename in changeset.Where(e => e.FileOperation != FileOperation.NoOp))
            {
                ChangeStatus cstatus = changeset[filename].ChangeStatus;
                FileOperation operation = changeset[filename].FileOperation;

                if (cstatus == ChangeStatus.SourceDeleted
                        && operation != FileOperation.UseRepo)
                {
                    state.Source.MTimes.Remove(filename);
                }

                if (cstatus == ChangeStatus.RepoDeleted
                        && operation != FileOperation.UseSource)
                {
                    state.Repository.MTimes.Remove(filename);
                }

                if (operation == FileOperation.UseSource)
                {
                    state.Repository.MTimes[filename] = source.Files[filename].MTime;
                    state.Source.MTimes[filename] = source.Files[filename].MTime;
                    state.Origin[filename] = state.Source.ID;
                }
                else if (operation == FileOperation.UseRepo)
                {
                    state.Repository.MTimes[filename] = repo.Files[filename].MTime;
                    state.Source.MTimes[filename] = repo.Files[filename].MTime;
                }
                else if (operation == FileOperation.DeleteSource)
                {
                    state.Source.MTimes.Remove(filename);
                }
                else if (operation == FileOperation.DeleteRepo)
                {
                    state.Repository.MTimes.Remove(filename);
                }
            }
            */
        }
Exemplo n.º 5
0
        private FooTree GetFooTree(string path, ICollection<string> exceptions, string type)
        {
            FooTree ret = null;
            try
            {
                ret = new FooTree(Foo, path, exceptions);
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("{0} directory {1} not found.",
                    type,
                    path);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} reading {1} directory {2}: {3}",
                    ex.GetType().Name,
                    type,
                    path,
                    ex.Message);
            }

            return ret;
        }