private static string GetUrlFor(Site site, string folderPath, BinderSession session)
        {

            var url =
                site.Region.EndpointUrl.AppendPathSegment("SiteNavigator")
                    .AppendPathSegment(site.Subdomain)
                    .AppendPathSegment("Folder")
                    .SetQueryParam("path", folderPath)
                    .SetQueryParam("api_key", session.SessionToken);



            return url;

        }
        private void UploadFiles(string[] files, Site binderSite, StorageEngine storageEngine, string destination)
        {

            foreach (var file in files)
            {
                //string directoryName = Path.GetDirectoryName(file);
                string fileName = Path.GetFileName(file);

                Console.Write(fileName.PadRight(45) + " ");

                try
                {


                    using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
                    {
                        var storageResponse = storageEngine.StoreFile(fileStream);

                        var fileInfo = new FileInfo(file);
                        var options = new CreateSiteFileVersionOptions()
                        {
                            Length = fileInfo.Length,
                            FileModifiedTimeUtc = fileInfo.LastWriteTimeUtc,
                            HiggsFileId = storageResponse.HiggsFileID,
                            Name = fileName,
                            StorageZoneId = fixedStorageZoneId.ToString()
                        };


                        var url = binderSite.Region.EndpointUrl
                            .AppendPathSegment("SiteNavigator")
                            .AppendPathSegment(binderSite.Subdomain)
                            .AppendPathSegment("Folder")
                            .AppendPathSegment("Files")
                            .SetQueryParam("path", destination)
                            .SetQueryParam("api_key", AuthorisedSession.SessionToken);


                        var addFileResponseMessage = new PutOperation<CreateSiteFileVersionOptions>(url)
                            .WithRequest(options)
                            .ResponseMessage;

                        var siteFileModel = addFileResponseMessage.Content<SiteFileModel>();
                        if (siteFileModel.Length != fileInfo.Length)
                            throw new ApplicationException("Uploaded file length does not match");

                        Console.WriteLine(addFileResponseMessage.StatusCode.ToString());

                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR: " + ex.Message);
                }

            }
        }
        private void UploadDirectory(StorageEngine storageEngine, Site binderSite, string subDirectoryName, string directorySource, string directoryDestination)
        {

            try
            {


                Console.WriteLine("Uploading directory " + directorySource + "/" + subDirectoryName);

                var directoryDestinationModel =
                    new GetFolderOperation(binderSite, directoryDestination, AuthorisedSession).ResponseMessage
                        .Content<SiteFolderModel>();

                if (directoryDestinationModel.Folders.All(folder => folder.Name.ToLower() != subDirectoryName.ToLower()))
                {
                    Console.WriteLine("Creating folder " + subDirectoryName);
                    var createFolderOperation = new CreateFolderOperation(binderSite, directoryDestination,
                        AuthorisedSession, subDirectoryName);

                    if (!createFolderOperation.ResponseMessage.IsSuccessStatusCode)
                    {
                        throw new ApplicationException("Could not create folder " + subDirectoryName + " - " + createFolderOperation.ResponseMessage.StatusCode);
                    }

                }


                string newSource = Path.Combine(directorySource, subDirectoryName);
                string newDestination = directoryDestination.TrimEnd('/') + "/" + subDirectoryName;


                var files = Directory.GetFiles(newSource, "*.*");
                Console.WriteLine(files.Length + " files");

                UploadFiles(files, binderSite, storageEngine, newDestination);
                foreach (var newDirectory in Directory.GetDirectories(newSource))
                {
                    string newDirectoryName = new DirectoryInfo(newDirectory).Name;
                    UploadDirectory(storageEngine, binderSite, newDirectoryName, newSource, newDestination);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: Could not upload directory " + subDirectoryName + " - " + ex.Message);
            }


        }
 public GetFolderOperation(Site site, string folderPath, BinderSession session) : base(GetUrlFor(site,folderPath, session))
 {
 }