Beispiel #1
0
        private void RefreshInternal()
        {
            // update ignore files
            UpdateIgnores();

            // load last filemap
            var filemapData = File.ReadAllText(RootDir + ".mysync\\last_filemap.json");

            _lastFilemap = Filemap.FromJson(filemapData);

            // build current filemap
            _currentFilemap = Filemap.Build(RootDir, Ignores);
        }
Beispiel #2
0
        /// <summary>
        /// Create new project.
        /// </summary>
        /// <param name="directory">The directory for the project, eg.: 'D:\\SomeProject'</param>
        /// <param name="name">The project name.</param>
        /// <returns>The created project, or null when can't create project in this directory.</returns>
        public static Project Create(string directory, string name)
        {
            if (!directory.EndsWith("\\"))
            {
                directory += "\\";
            }

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var dir = Directory.GetFiles(directory, "*.*");

            // check if this directory is empty
            if (dir.Length == 0)
            {
                var project = new Project
                {
                    RootDir = directory
                };

                var mysyncDataDir = directory + ".mysync";
                var msDir         = Directory.CreateDirectory(mysyncDataDir);

                // hide the directory
                msDir.Attributes = FileAttributes.Directory | FileAttributes.Hidden;

                // build empty for 'last commit'.
                var emptyFilemap = Filemap.BuildEmpty();
                project._lastFilemap = emptyFilemap;

                // save
                File.WriteAllText(mysyncDataDir + "\\last_filemap.json", emptyFilemap.ToJson());

                // refresh the changes
                project.Refresh();

                // return created project
                return(project);
            }

            return(null); // nope!
        }
Beispiel #3
0
        /// <summary>
        /// Open remote project.
        /// </summary>
        /// <param name="address">The server address.</param>
        /// <param name="name">The project name.</param>
        /// <param name="username">Username that will be used to download the project.</param>
        /// <param name="accesstoken">Password that will be used to download the project.</param>
        /// <param name="directory">The directory when the project will be downloaded.</param>
        /// <returns>The project, null when something failed.</returns>
        public static Project OpenProject(string address, string name, string username, string accesstoken, string directory)
        {
            var authority = new ProjectAuthority
            {
                ProjectName = name,
                Username    = username,
                AccessToken = accesstoken
            };

            // send project authority request
            var    response = Request.Send(address + "authorize", authority.ToJson());
            string responseBody;

            using (var sr = new BinaryReader(response))
            {
                responseBody = sr.ReadString();
            }

            var authResult = JObject.Parse(responseBody);
            var authorized = authResult["auth"].ToObject <bool>();

            if (!authorized)
            {
                return(null);
            }

            // setup directory
            if (!directory.EndsWith("\\"))
            {
                directory += "\\";
            }

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var dir = Directory.GetFiles(directory, "*.*");

            if (dir.Length > 0) // directory is not empty!
            {
                return(null);
            }

            // create local project
            var project = new Project
            {
                RootDir       = directory,
                ServerAddress = address,
                Authority     = authority
            };

            var mysyncDataDir = directory + ".mysync";
            var msDir         = Directory.CreateDirectory(mysyncDataDir);

            // hide the directory
            msDir.Attributes = FileAttributes.Directory | FileAttributes.Hidden;

            // build empty for 'last commit'.
            var emptyFilemap = Filemap.BuildEmpty();

            project._lastFilemap = emptyFilemap;

            // save
            File.WriteAllText(mysyncDataDir + "\\last_filemap.json", emptyFilemap.ToJson());

            // refresh the changes
            project.Refresh();

            // download all files
            project.Pull(x => { }); // TODO: progress

            return(project);
        }