Beispiel #1
0
        public static DropboxEntryInfo ParseFrom(JArray json)
        {
            var deltaInfo = new DropboxEntryInfo
            {
                Path = (string)json[0]
            };

            JObject metadata = json[1] as JObject;
            if (metadata != null)
            {
                string correctlyCasedPath = metadata.Value<string>("path");
                if (!String.IsNullOrEmpty(correctlyCasedPath))
                {
                    // This preserves casing
                    deltaInfo.Path = correctlyCasedPath;
                }

                deltaInfo.IsDirectory = metadata.Value<bool>("is_dir");
                deltaInfo.IsDeleted = String.IsNullOrEmpty(correctlyCasedPath) || metadata.Value<bool>("is_deleted");

                if (!deltaInfo.IsDirectory && !deltaInfo.IsDeleted)
                {
                    deltaInfo.Modified = (string)metadata["modified"];
                }
            }
            else
            {
                deltaInfo.IsDeleted = true;
            }

            return deltaInfo;
        }
        private static string GetOAuthHeader(DropboxDeployInfo info, DropboxEntryInfo delta)
        {
            var parameters = new Dictionary <string, string>
            {
                { "oauth_consumer_key", info.ConsumerKey },
                { "oauth_signature_method", info.SignatureMethod },
                { "oauth_timestamp", info.TimeStamp },
                { "oauth_nonce", delta.Nonce },
                { "oauth_version", info.OAuthVersion },
                { "oauth_token", info.Token },
                { "oauth_signature", delta.Signature }
            };

            var sb = new StringBuilder();

            foreach (var item in parameters)
            {
                if (sb.Length != 0)
                {
                    sb.Append(',');
                }
                sb.AppendFormat("{0}=\"{1}\"", item.Key, item.Value);
            }
            return(sb.ToString());
        }
Beispiel #3
0
        public static DropboxEntryInfo ParseFrom(JArray json)
        {
            var deltaInfo = new DropboxEntryInfo
            {
                Path = (string)json[0]
            };

            JObject metadata = json[1] as JObject;

            if (metadata != null)
            {
                string correctlyCasedPath = metadata.Value <string>("path");
                if (!String.IsNullOrEmpty(correctlyCasedPath))
                {
                    // This preserves casing
                    deltaInfo.Path = correctlyCasedPath;
                }

                deltaInfo.IsDirectory = metadata.Value <bool>("is_dir");
                deltaInfo.IsDeleted   = String.IsNullOrEmpty(correctlyCasedPath) || metadata.Value <bool>("is_deleted");

                if (!deltaInfo.IsDirectory && !deltaInfo.IsDeleted)
                {
                    deltaInfo.Modified = (string)metadata["modified"];
                }
            }
            else
            {
                deltaInfo.IsDeleted = true;
            }

            return(deltaInfo);
        }
        public virtual HttpClient CreateDropboxHttpClient(DropboxDeployInfo info, DropboxEntryInfo entry)
        {
            var oauthToken = GetOAuthHeader(info, entry);
            var client     = new HttpClient {
                BaseAddress = new Uri(DropboxApiContentUri), Timeout = _timeout
            };

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", oauthToken);

            return(client);
        }
        /// <summary>
        /// An entry can be ignored if it doesn't belong to the path of the synced app or
        /// if it looks like a tool generated folder (e.g. .hg or .git)
        /// </summary>
        private static bool CanIgnoreEntry(string parent, DropboxEntryInfo entry)
        {
            if (!entry.Path.StartsWith(parent, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            // Ignore .git and .hg files and folders
            string pathWithSlash = entry.Path + "/";

            if (pathWithSlash.IndexOf("/.git/", StringComparison.OrdinalIgnoreCase) != -1 ||
                pathWithSlash.IndexOf("/.hg/", StringComparison.OrdinalIgnoreCase) != -1)
            {
                return(true);
            }

            return(false);
        }
        public static DropboxEntryInfo ParseFrom(JObject json)
        {
            // This preserves casing
            var correctlyCasedPath = json.Value <string>("path_display");
            var deltaInfo          = new DropboxEntryInfo
            {
                Path = correctlyCasedPath
            };

            var tag = json.Value <string>(".tag");

            if (tag == null || String.Equals(tag, "deleted", StringComparison.OrdinalIgnoreCase))
            {
                deltaInfo.IsDeleted = true;
            }
            else
            {
                deltaInfo.IsDirectory = String.Equals(tag, "folder", StringComparison.OrdinalIgnoreCase);
                deltaInfo.Modified    = json.Value <string>("server_modified");
            }

            return(deltaInfo);
        }
Beispiel #7
0
        /// <summary>
        /// An entry can be ignored if it doesn't belong to the path of the synced app or 
        /// if it looks like a tool generated folder (e.g. .hg or .git)
        /// </summary>
        private static bool CanIgnoreEntry(string parent, DropboxEntryInfo entry)
        {
            if (!entry.Path.StartsWith(parent, StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }

            // Ignore .git and .hg files and folders
            string pathWithSlash = entry.Path + "/";
            if (pathWithSlash.IndexOf("/.git/", StringComparison.OrdinalIgnoreCase) != -1 ||
                pathWithSlash.IndexOf("/.hg/", StringComparison.OrdinalIgnoreCase) != -1)
            {
                return true;
            }

            return false;
        }
Beispiel #8
0
        private static string GetOAuthHeader(DropboxDeployInfo info, DropboxEntryInfo delta)
        {
            var parameters = new Dictionary<string, string>
            {
                { "oauth_consumer_key", info.ConsumerKey },
                { "oauth_signature_method", info.SignatureMethod },
                { "oauth_timestamp", info.TimeStamp },
                { "oauth_nonce", delta.Nonce },
                { "oauth_version", info.OAuthVersion },
                { "oauth_token", info.Token },
                { "oauth_signature", delta.Signature }
            };

            var sb = new StringBuilder();
            foreach (var item in parameters)
            {
                if (sb.Length != 0)
                {
                    sb.Append(',');
                }
                sb.AppendFormat("{0}=\"{1}\"", item.Key, item.Value);
            }
            return sb.ToString();
        }
Beispiel #9
0
        public virtual HttpClient CreateDropboxHttpClient(DropboxDeployInfo info, DropboxEntryInfo entry)
        {
            var oauthToken = GetOAuthHeader(info, entry);
            var client = new HttpClient { BaseAddress = new Uri(DropboxApiContentUri), Timeout = _timeout };
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", oauthToken);

            return client;
        }
Beispiel #10
0
        internal DropboxDeployInfo GetDeployInfo(string path, OAuthInfo oauth, AccountInfo account, string cursor = null)
        {
            List<DropboxEntryInfo> deltas = new List<DropboxEntryInfo>();
            string timeStamp = GetUtcTimeStamp();
            string oldCursor = cursor;
            string newCursor = "";
            while (true)
            {
                DeltaInfo delta = GetDeltaInfo(oauth, cursor);
                newCursor = delta.cursor;
                if (newCursor == oldCursor)
                {
                    break;
                }

                foreach (EntryInfo info in delta.entries)
                {
                    DropboxEntryInfo item = new DropboxEntryInfo();

                    if (info.metadata != null && !info.metadata.path.StartsWith(path))
                    {
                        continue;
                    }

                    if (info.metadata == null || info.metadata.is_deleted || string.IsNullOrEmpty(info.metadata.path))
                    {
                        item.Path = info.path;
                        item.IsDeleted = true;
                    }
                    else
                    {
                        item.Path = info.metadata.path;
                        item.IsDirectory = info.metadata.is_dir;
                        if (!item.IsDirectory)
                        {
                            item.Modified = info.metadata.modified;
                            item.Nonce = GetNonce();
                            item.Signature = GetSignature(oauth, info.path, timeStamp, item.Nonce);
                        }
                    }

                    deltas.Add(item);
                }

                if (!delta.has_more)
                {
                    break;
                }

                cursor = newCursor;
            }

            if (deltas.Count == 0)
            {
                throw new InvalidOperationException("the repo is up-to-date.");
            }

            var deployInfo = new DropboxDeployInfo
            {
                TimeStamp = timeStamp,
                Token = oauth.Token,
                ConsumerKey = oauth.ConsumerKey,
                OAuthVersion = "1.0",
                SignatureMethod = "HMAC-SHA1",
                OldCursor = oldCursor,
                NewCursor = newCursor,
                Path = path,
                UserName = account.display_name,
                Email = account.email,
            };
            deployInfo.Deltas.AddRange(deltas);

            return deployInfo;
        }