diff --git a/SendsafelyAPI/ClientAPI.cs b/SendsafelyAPI/ClientAPI.cs index 7afe7c6..40d4362 100644 --- a/SendsafelyAPI/ClientAPI.cs +++ b/SendsafelyAPI/ClientAPI.cs @@ -713,12 +713,40 @@ public String FinalizePackage(String packageId, String keycode) /// /// A link to access the package. This link can be sent to the recipients. /// + [Obsolete("This version of FinalizePackage is deprecated. Instead please use FinalizePackage which supports both allowReplyAll and notifyRecipients features.")] public String FinalizePackage(String packageId, String keycode, bool allowReplyAll) { EnforceInitialized(); PackageUtility pu = new PackageUtility(connection); - return pu.FinalizePackage(packageId, keycode, allowReplyAll); + return pu.FinalizePackage(packageId, keycode, false, allowReplyAll); + } + + /// + /// Finalizes the package so it can be delivered to the recipients. + /// createPackage(). Additionally, the package must contain at least one file. + /// + /// The unique package id of the package to be finalized. + /// The keycode belonging to the package. + /// Determines whether package recipients are automatically notified. + /// Determines whether package recipients permitted to reply to all recipients or just sender. + /// Thrown when the API has not been initialized. + /// Thrown when the API credentials are incorrect. + /// Thrown when the API failed to connect to the server. + /// Thrown when a non-existent or invalid package ID is used. + /// Thrown when the package limits has been exceeded. + /// Thrown when the package couldn't be finalized. The message will contain detailed information + /// Thrown when the keycode is null, empty or to short. + /// Will be thrown if the server returns an error message + /// + /// A link to access the package. This link can be sent to the recipients. + /// + public String FinalizePackage(String packageId, String keycode, bool notifyRecipients, bool allowReplyAll) + { + EnforceInitialized(); + + PackageUtility pu = new PackageUtility(connection); + return pu.FinalizePackage(packageId, keycode, notifyRecipients, allowReplyAll); } /// @@ -820,7 +848,7 @@ public PrivateKey GenerateKeyPair(String description) } /// - /// Get all active packages for the current user. + /// Get active packages for the current user. A maximum of 100 records is returned by this method. /// /// Thrown when the API has not been initialized. /// Thrown when the API credentials are incorrect. @@ -828,8 +856,9 @@ public PrivateKey GenerateKeyPair(String description) /// Thrown when the API failed to connect to the server. /// Will be thrown if the server returns an error message /// - /// A List containing package metadata for all active packages. + /// A List containing package metadata for active packages. /// + [Obsolete("GetActivePackages() is deprecated, please use GetActivePackages(rowIndex, pageSize) instead", false)] public List GetActivePackages() { EnforceInitialized(); @@ -838,6 +867,27 @@ public List GetActivePackages() return pu.GetActivePackages(); } + /// + /// Get a paginated set of active packages for the current user. A maximum pagesize of 100 records per method call is supported. + /// + /// The starting row index of the results to be returned. + /// The size of results to be returned. + /// Thrown when the API has not been initialized. + /// Thrown when the API credentials are incorrect. + /// Thrown when the limits for the user has been exceeded. + /// Thrown when the API failed to connect to the server. + /// Will be thrown if the server returns an error message + /// + /// A PaginatedList containing package metadata for active packages. + /// + public PaginatedList GetActivePackages(int rowIndex, int pageSize) + { + EnforceInitialized(); + + PackageUtility pu = new PackageUtility(connection); + return pu.GetActivePackages(rowIndex, pageSize); + } + /// /// Retrieves activity log records for a Workspace package. The method supports returning up to 10 records at a time. The caller must be the owner of the Workspace, assigned to the manager role within the Workspace, or an enterprise administrator. /// @@ -853,15 +903,17 @@ public List GetActivityLog(String packageId, int rowIndex) } /// - /// Get all archived packages for the current user. + /// Gets archived packages for the current user. A maximum of 100 records is returned by this method. /// + /// The starting row index of the results to be returned. + /// The size of the results to be returned. /// Thrown when the API has not been initialized. /// Thrown when the API credentials are incorrect. /// Thrown when the limits for the user has been exceeded. /// Thrown when the API failed to connect to the server. /// Will be thrown if the server returns an error message /// - /// A List containing package metadata for all archived packages. + /// A List containing package metadata for archived packages. /// public List GetArchivedPackages() { @@ -871,6 +923,28 @@ public List GetArchivedPackages() return pu.GetArchivedPackages(); } + /// + /// Gets a paginated set of archived packages for the current user. A maximum pagesize of 100 records per method call is supported. + /// + /// The starting row index of the results to be returned. + /// The size of the results to be returned. + /// Thrown when the API has not been initialized. + /// Thrown when the API credentials are incorrect. + /// Thrown when the limits for the user has been exceeded. + /// Thrown when the API failed to connect to the server. + /// Will be thrown if the server returns an error message + /// + /// A PaginatedList containing package metadata for archived packages. + /// + public PaginatedList GetArchivedPackages(int rowIndex, int pageSize) + { + EnforceInitialized(); + + PackageUtility pu = new PackageUtility(connection); + + return pu.GetArchivedPackages(rowIndex, pageSize); + } + /// /// Retrieve the list of available Contact Groups for the current user profile, including all email addresses associated with each Contact Group. /// @@ -901,6 +975,7 @@ public List getContactGroups() /// The unique package id of the package for the target directory. /// The unique directory id of the target directory. /// A Directory object containing information about the directory. + [Obsolete("GetDirectory(packageId, directoryId) is deprecated, please use GetDirectory(packageId, directoryId, directoryIndex, fileIndex) or GetDirectory(packageId, directoryId, directoryIndex, fileIndex, sortField, sortOrder) instead", false)] public Directory GetDirectory(String packageId, String directoryId) { EnforceInitialized(); @@ -909,6 +984,38 @@ public Directory GetDirectory(String packageId, String directoryId) } + /// + /// Retrieves meta data about a directory in a Workspace package. + /// + /// The unique package id of the package for the target directory. + /// The unique directory id of the target directory. + /// The index for paging subdirectories within the current directory. + /// The index for paging files within the current directory. + /// A Directory object containing information about the directory. + public Directory GetDirectory(String packageId, String directoryId, int directoryIndex, int fileIndex) + { + return this.GetDirectory(packageId, directoryId, directoryIndex, fileIndex, null, null); + + } + + /// + /// Retrieves meta data about a directory in a Workspace package. + /// + /// The unique package id of the package for the target directory. + /// The unique directory id of the target directory. + /// The index for paging files within the current directory. + /// The index for paging subdirectories within the current directory. + /// Field for sorting returned files and directories. Supported values are "name" to sort files and directories by name or "date" which sorts on fileUploaded for files and created for directories. The endpoint defaults to the "name" field. + /// Order of the sorted field. Suppported values are "asc" or "desc" order. The endpoint defaults to the "asc" value. + /// A Directory object containing information about the directory. + public Directory GetDirectory(String packageId, String directoryId, int directoryIndex, int fileIndex, String sortField, String sortOrder) + { + EnforceInitialized(); + PackageUtility pu = new PackageUtility(connection); + return pu.GetDirectory(packageId, directoryId, directoryIndex, fileIndex, sortField, sortOrder); + + } + /// /// Gets all recipients assigned to the current user's Dropzone. /// @@ -1024,7 +1131,7 @@ public String GetMessage(String secureLink) } /// - /// Returns packages in the current user's organization based on provided search criteria. The search defaults to returning all packages up to the current date and time, if a specific value is not passed for each search criteria. A maximum of 100 records will be returned per method call. The calling user must be a SendSafely Enterprise Administrator. + /// Returns packages in the current user's organization based on provided search criteria. The search defaults to returning all packages up to the current date and time, if a specific value is not passed for each search criteria. A maximum of 100 records is returned by this method. The calling user must be a SendSafely Enterprise Administrator. /// /// Date and time to search for packages with a package timestamp that is greater than or equal to the specified value. /// Date and time to search for packages with a package timestamp that is less than or equal to the specified value. @@ -1033,6 +1140,7 @@ public String GetMessage(String secureLink) /// Email address to search for packages with a matching recipient email address. A valid email address must be provided. /// Name of a file to search for packages with a matching file name. /// A PackageSearchResults object + [Obsolete("GetOrganizationPackages is deprecated, please use GetOrganizationPackagesSearch instead", false)] public PackageSearchResults GetOrganizationPackages(DateTime? fromDate, DateTime? toDate, String sender, PackageStatus? status, String recipient, String fileName) { EnforceInitialized(); @@ -1041,6 +1149,26 @@ public PackageSearchResults GetOrganizationPackages(DateTime? fromDate, DateTime return pu.GetOrganizationPackages(fromDate, toDate, sender, status, recipient, fileName); } + /// + /// Returns packages in the current user's organization based on provided search criteria. The search defaults to returning a paginated set of packages up to the current date and time, if a specific value is not passed for each search criteria. A maximum pagesize of 100 records per method call is supported. The calling user must be a SendSafely Enterprise Administrator. + /// + /// Date and time to search for packages with a package timestamp that is greater than or equal to the specified value. + /// Date and time to search for packages with a package timestamp that is less than or equal to the specified value. + /// Email address to search for packages with a matching package sender email address. A valid email address must be provided. + /// PackageStatus enum value to search for packages with a matching package status. + /// Email address to search for packages with a matching recipient email address. A valid email address must be provided. + /// Name of a file to search for packages with a matching file name. + /// Index of row to start retreiving for pagination. + /// The size of the results to be returned. + /// A PaginatedList object containing PackageInformation items + public PaginatedList GetOrganizationPackagesSearch(DateTime? fromDate, DateTime? toDate, String sender, PackageStatus? status, String recipient, String fileName, int rowIndex, int pageSize) + { + EnforceInitialized(); + + PackageUtility pu = new PackageUtility(connection); + return pu.GetOrganizationPackagesSearch(fromDate, toDate, sender, status, recipient, fileName, rowIndex, pageSize); + } + /// /// Fetch the latest package meta data about a specific package given the unique package id. /// @@ -1151,7 +1279,7 @@ public String GetPackageLink(String packageId, String keyCode) } /// - /// Retrieves a list of all active packages received for the given API User. + /// Retrieves a list of active packages received for the given API User. A maximum of 100 records is returned by this method. /// /// Thrown when the API has not been initialized. /// Thrown when the API credentials are incorrect. @@ -1159,8 +1287,9 @@ public String GetPackageLink(String packageId, String keyCode) /// Thrown when the API failed to connect to the server. /// Will be thrown if the server returns an error message /// - /// A List containing package metadata for all received packages. + /// A List containing package metadata for received packages. /// + [Obsolete("GetReceivedPackages() is deprecated, please use GetReceivedPackages(rowIndex, pageSize) instead", false)] public List GetReceivedPackages() { EnforceInitialized(); @@ -1169,6 +1298,27 @@ public List GetReceivedPackages() return pu.GetReceivedPackages(); } + /// + /// Retrieves a paginated set of active packages received for the given API User. A maximum pagesize of 100 records per method call is supported. + /// + /// The starting row index of the results to be returned. + /// The size of the results to be returned. + /// Thrown when the API has not been initialized. + /// Thrown when the API credentials are incorrect. + /// Thrown when the limits for the user has been exceeded. + /// Thrown when the API failed to connect to the server. + /// Will be thrown if the server returns an error message + /// + /// A PaginatedList containing package metadata for received packages. + /// + public PaginatedList GetReceivedPackages(int rowIndex, int pageSize) + { + EnforceInitialized(); + + PackageUtility pu = new PackageUtility(connection); + return pu.GetReceivedPackages(rowIndex, pageSize); + } + /// /// Retrieves a recipient from a given package. /// diff --git a/SendsafelyAPI/Objects/Connection.cs b/SendsafelyAPI/Objects/Connection.cs index b55e3cd..121ef45 100644 --- a/SendsafelyAPI/Objects/Connection.cs +++ b/SendsafelyAPI/Objects/Connection.cs @@ -253,7 +253,7 @@ private String generateUserAgent() private String CreateSignature(String privateKey, String apiKey, String uri, String dateStr, String requestData) { - String content = apiKey + uri + dateStr + requestData; + String content = apiKey + uri.Split('?')[0] + dateStr + requestData; Logger.Log("-" + content + "-"); CryptUtility cu = new CryptUtility(); return cu.createSignature(privateKey, content); diff --git a/SendsafelyAPI/Objects/ConnectionStrings.cs b/SendsafelyAPI/Objects/ConnectionStrings.cs index 118dbaa..cedbe9a 100644 --- a/SendsafelyAPI/Objects/ConnectionStrings.cs +++ b/SendsafelyAPI/Objects/ConnectionStrings.cs @@ -15,6 +15,7 @@ internal class ConnectionStrings {"receivedPackages", new Endpoint("/api/v2.0/package/received/", HTTPMethod.GET, "application/json")}, {"archivedPackages", new Endpoint("/api/v2.0/package/archived/", HTTPMethod.GET, "application/json")}, {"organizationPackages", new Endpoint("/api/v2.0/package/organization/", HTTPMethod.POST, "application/json")}, + {"organizationPackagesSearch", new Endpoint("/api/v2.0/package/organization/search", HTTPMethod.POST, "application/json") }, {"addRecipient", new Endpoint("/api/v2.0/package/{packageId}/recipient/", HTTPMethod.PUT, "application/json")}, {"addRecipientPhonenumber", new Endpoint("/api/v2.0/package/{packageId}/recipient/{recipientId}/", HTTPMethod.POST, "application/json")}, {"createFileId", new Endpoint("/api/v2.0/package/{packageId}/file/", HTTPMethod.PUT, "application/json")}, @@ -73,6 +74,7 @@ internal class ConnectionStrings {"addContactGroupsToPackage", new Endpoint("/api/v2.0/package/{packageId}/group/{groupId}/", HTTPMethod.PUT, "application/json")}, {"removeContactGroupsToPackage", new Endpoint("/api/v2.0/package/{packageId}/group/{groupId}/", HTTPMethod.DELETE, "application/json")}, {"removeRecipient", new Endpoint("/api/v2.0/package/{packageId}/recipient/{recipientId}/", HTTPMethod.DELETE, "application/json")}, + {"notifyRecipients", new Endpoint("/api/v2.0/package/{packageId}/notify", HTTPMethod.POST, "application/json") }, }; } } diff --git a/SendsafelyAPI/Objects/DirectoryResponse.cs b/SendsafelyAPI/Objects/DirectoryResponse.cs index fe088f8..5c49ea7 100644 --- a/SendsafelyAPI/Objects/DirectoryResponse.cs +++ b/SendsafelyAPI/Objects/DirectoryResponse.cs @@ -15,25 +15,25 @@ public class DirectoryResponse private ICollection subDirectories = new Collection(); [JsonProperty(PropertyName = "directoryId")] - internal String DirectoryId + public String DirectoryId { get { return directoryId; } set { directoryId = value; } } [JsonProperty(PropertyName = "name")] - internal String Name + public String Name { get { return name; } set { name = value; } } [JsonProperty(PropertyName = "created")] - internal DateTime Created + public DateTime Created { get { return created; } set { created = value; } } [JsonProperty(PropertyName = "subDirectories")] - internal ICollection SubDirectories + public ICollection SubDirectories { get { return subDirectories; } set { subDirectories = value; } diff --git a/SendsafelyAPI/Objects/GetOrganizationPakagesResponse.cs b/SendsafelyAPI/Objects/GetOrganizationPakagesResponse.cs index 40bdfde..26218b4 100644 --- a/SendsafelyAPI/Objects/GetOrganizationPakagesResponse.cs +++ b/SendsafelyAPI/Objects/GetOrganizationPakagesResponse.cs @@ -5,7 +5,7 @@ namespace SendSafely.Objects { - class GetOrganizationPakagesResponse : StandardResponse + class GetOrganizationPakagesResponse : PaginationResponse { List packages; @@ -18,13 +18,12 @@ public List Packages set { packages = value; } } + [Obsolete("capped is deprecated, please use Pagination property instead)",false)] [JsonProperty(PropertyName = "capped")] public bool Capped { get { return capped; } set { capped = value; } } - - } } diff --git a/SendsafelyAPI/Objects/GetPackagesResponse.cs b/SendsafelyAPI/Objects/GetPackagesResponse.cs index a972472..422a7f6 100644 --- a/SendsafelyAPI/Objects/GetPackagesResponse.cs +++ b/SendsafelyAPI/Objects/GetPackagesResponse.cs @@ -6,18 +6,11 @@ namespace SendSafely.Objects { [JsonObject(MemberSerialization.OptIn)] - class GetPackagesResponse + class GetPackagesResponse : PaginationResponse { - private APIResponse _response; + private List _packages; - [JsonProperty(PropertyName = "response")] - internal APIResponse Response - { - get { return _response; } - set { _response = value; } - } - [JsonProperty(PropertyName = "packages")] public List Packages { diff --git a/SendsafelyAPI/Objects/Keypair.cs b/SendsafelyAPI/Objects/Keypair.cs index 0abe9bc..a67f105 100644 --- a/SendsafelyAPI/Objects/Keypair.cs +++ b/SendsafelyAPI/Objects/Keypair.cs @@ -4,7 +4,7 @@ namespace SendSafely.Objects { - class Keypair + public class Keypair { public String PrivateKey { get; set; } public String PublicKey { get; set; } diff --git a/SendsafelyAPI/Objects/NotifyPackageRecipientsRequest.cs b/SendsafelyAPI/Objects/NotifyPackageRecipientsRequest.cs new file mode 100644 index 0000000..2cfe62d --- /dev/null +++ b/SendsafelyAPI/Objects/NotifyPackageRecipientsRequest.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace SendSafely.Objects +{ + [JsonObject(MemberSerialization.OptIn)] + class NotifyPackageRecipientsRequest + { + private String _keycode; + + [JsonProperty(PropertyName = "keycode")] + public String Keycode { get; set; } + } +} diff --git a/SendsafelyAPI/Objects/PaginationResponse.cs b/SendsafelyAPI/Objects/PaginationResponse.cs new file mode 100644 index 0000000..33d4425 --- /dev/null +++ b/SendsafelyAPI/Objects/PaginationResponse.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace SendSafely.Objects +{ + class PaginationResponse : StandardResponse + { + + private Dictionary _pagination; + + [JsonProperty(PropertyName = "pagination")] + internal Dictionary Pagination + { + get { return _pagination; } + set { _pagination = value; } + } + } +} diff --git a/SendsafelyAPI/Objects/ProgressStream.cs b/SendsafelyAPI/Objects/ProgressStream.cs index 1b6e7e2..acf89c5 100644 --- a/SendsafelyAPI/Objects/ProgressStream.cs +++ b/SendsafelyAPI/Objects/ProgressStream.cs @@ -25,7 +25,7 @@ public ProgressStream(Stream inner, ISendSafelyProgress progress, String prefix, this._inner = inner; this._progress = progress; this._prefix = prefix; - this._fileSize = size; + this._fileSize = size < 1024 ? size * 1024 : size; // multiple file size by 1024 if fileSize is less than 1024 bytes. this._readSoFar = 0; this._offset = offset; _lastProgressCallback = DateTime.Now.Ticks - UPDATE_FREQUENCY; // Make sure we trigger it the first time. diff --git a/SendsafelyAPI/PaginatedList.cs b/SendsafelyAPI/PaginatedList.cs new file mode 100644 index 0000000..0af9551 --- /dev/null +++ b/SendsafelyAPI/PaginatedList.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace SendSafely +{ + [JsonObject(MemberSerialization.OptIn)] + public class PaginatedList : List + { + private int _rowIndex = 0; + private int _rowsReturned; + private int _nextRowIndex; + private bool _rowsCapped; + + [JsonProperty(PropertyName = "rowIndex")] + public int RowIndex + { + get { return _rowIndex; } + set { _rowIndex = value; } + } + + [JsonProperty(PropertyName = "rowsReturned")] + public int RowsReturned + { + get { return _rowsReturned; } + set { _rowsReturned = value; } + } + + [JsonProperty(PropertyName = "nextRowIndex")] + public int NextRowIndex + { + get { return _nextRowIndex; } + set { _nextRowIndex = value; } + } + + [JsonProperty(PropertyName = "rowsCapped")] + public bool RowsCapped + { + get { return _rowsCapped; } + set { _rowsCapped = value; } + } + } + + +} diff --git a/SendsafelyAPI/Properties/AssemblyInfo.cs b/SendsafelyAPI/Properties/AssemblyInfo.cs index f50b333..dcc3069 100644 --- a/SendsafelyAPI/Properties/AssemblyInfo.cs +++ b/SendsafelyAPI/Properties/AssemblyInfo.cs @@ -32,7 +32,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.6")] -[assembly: AssemblyFileVersion("3.0.6")] +[assembly: AssemblyVersion("3.0.7")] +[assembly: AssemblyFileVersion("3.0.7")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("APITests")] \ No newline at end of file diff --git a/SendsafelyAPI/SendsafelyAPI.csproj b/SendsafelyAPI/SendsafelyAPI.csproj index cc5f208..ce03578 100644 --- a/SendsafelyAPI/SendsafelyAPI.csproj +++ b/SendsafelyAPI/SendsafelyAPI.csproj @@ -1,187 +1,191 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {9BDEB9EC-7B8C-44DD-A3A1-9EF4F2B2499E} - Library - Properties - SendSafely - SendsafelyAPI - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\SendsafelyAPI.XML - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\SendsafelyAPI.XML - false - - - - ThirdParty\BouncyCastle.Crypto.dll - - - ThirdParty\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {9BDEB9EC-7B8C-44DD-A3A1-9EF4F2B2499E} + Library + Properties + SendSafely + SendsafelyAPI + v4.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\SendsafelyAPI.XML + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + bin\Release\SendsafelyAPI.XML + false + + + + ThirdParty\BouncyCastle.Crypto.dll + + + + ThirdParty\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SendsafelyAPI/Utilities/CryptUtility.cs b/SendsafelyAPI/Utilities/CryptUtility.cs index 7143ec5..08b05a1 100644 --- a/SendsafelyAPI/Utilities/CryptUtility.cs +++ b/SendsafelyAPI/Utilities/CryptUtility.cs @@ -22,7 +22,7 @@ namespace SendSafely.Utilities { - class CryptUtility + public class CryptUtility { public String GenerateToken() { diff --git a/SendsafelyAPI/Utilities/PackageUtility.cs b/SendsafelyAPI/Utilities/PackageUtility.cs index 54e0c3a..90f3984 100644 --- a/SendsafelyAPI/Utilities/PackageUtility.cs +++ b/SendsafelyAPI/Utilities/PackageUtility.cs @@ -5,6 +5,7 @@ using SendSafely.Exceptions; using SendSafely.Utilities; using System.IO; +using System.Collections.Specialized; namespace SendSafely { @@ -30,7 +31,7 @@ public PackageInformation CreatePackage() public PackageInformation CreatePackage(Boolean isWorkspace) { - return CreatePackage(true, String.Empty); + return CreatePackage(isWorkspace, String.Empty); } @@ -115,12 +116,28 @@ public void DeleteDirectory(String packageId, String directoryId) } } - public List GetActivePackages() + public List GetActivePackages() + { + return GetActivePackages(-1, -1); + } + + public PaginatedList GetActivePackages(int rowIndex, int pageSize) { Endpoint p = ConnectionStrings.Endpoints["activePackages"].Clone(); - GetPackagesResponse response = connection.Send(p); + NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); + if (rowIndex >= 0) + { + queryString.Add("rowIndex", rowIndex.ToString()); + } + + if(pageSize >= 0) + { + queryString.Add("pageSize", pageSize.ToString()); + } - return Convert(response.Packages); + p.Path = p.Path + "?" + queryString.ToString(); + GetPackagesResponse response = connection.Send(p); + return ProcessPagination(Convert(response.Packages), response); } public List GetRecipientHistory(String recipientEmail) @@ -145,19 +162,51 @@ public List GetRecipientHistory(String recipientEmail) } public List GetReceivedPackages() + { + return GetReceivedPackages(-1, -1); + } + + public PaginatedList GetReceivedPackages(int rowIndex, int pageSize) { Endpoint p = ConnectionStrings.Endpoints["receivedPackages"].Clone(); + NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); + if (rowIndex >= 0) + { + queryString.Add("rowIndex", rowIndex.ToString()); + } + + if(pageSize >= 0) + { + queryString.Add("pageSize", pageSize.ToString()); + } + p.Path = p.Path + "?" + queryString.ToString(); GetPackagesResponse response = connection.Send(p); - return Convert(response.Packages); + return ProcessPagination(Convert(response.Packages), response); } public List GetArchivedPackages() + { + return GetArchivedPackages(-1, -1); + } + + public PaginatedList GetArchivedPackages(int rowIndex, int pageSize) { Endpoint p = ConnectionStrings.Endpoints["archivedPackages"].Clone(); - GetPackagesResponse response = connection.Send(p); + NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); + if (rowIndex >= 0) + { + queryString.Add("rowIndex", rowIndex.ToString()); + } + + if(pageSize >= 0) + { + queryString.Add("pageSize", pageSize.ToString()); + } - return Convert(response.Packages); + p.Path = p.Path + "?" + queryString.ToString(); + GetPackagesResponse response = connection.Send(p); + return ProcessPagination(Convert(response.Packages), response); } public PackageInformation GetPackageInformation(String packageId) @@ -576,7 +625,7 @@ public String FinalizePackage(String packageId, String keycode) return FinalizePackage(packageInfo); } - public String FinalizePackage(String packageId, String keycode, bool allowReplyAll) + public String FinalizePackage(String packageId, String keycode, bool notifyRecipients, bool allowReplyAll) { if (packageId == null) { @@ -590,7 +639,7 @@ public String FinalizePackage(String packageId, String keycode, bool allowReplyA // Get the updated package information. PackageInformation packageInfo = GetPackageInformation(packageId); - return FinalizePackage(packageInfo, request); + return FinalizePackage(packageInfo, request, notifyRecipients); } public String FinalizePackage(PackageInformation packageInfo) @@ -599,6 +648,35 @@ public String FinalizePackage(PackageInformation packageInfo) return FinalizePackage(packageInfo, request); } + public String FinalizePackage(PackageInformation packageInfo, FinalizePackageRequest request, Boolean notify) + { + try + { + String link = FinalizePackage(packageInfo, request); + + if (notify) + { + try + { + notifyPackageRecipients(packageInfo.PackageId, packageInfo.KeyCode); + return link; + } + catch (ActionFailedException e) + { + String message = "Unable to notify package recipients. Server Error: " + e.Message + ", Finalized Package Link: " + link; + throw new ActionFailedException(e.Reason, message); + } + } else + { + return link; + } + + } catch (PackageNeedsApprovalException pnae) + { + throw pnae; + } + } + public String FinalizePackage(PackageInformation packageInfo, FinalizePackageRequest request) { if (packageInfo == null) @@ -724,6 +802,19 @@ public String FinalizeUndisclosedPackage(PackageInformation packageInfo, Finaliz return response.Message + "#keyCode=" + packageInfo.KeyCode; } + public void notifyPackageRecipients(String packageId, String keycode) + { + NotifyPackageRecipientsRequest request = new NotifyPackageRecipientsRequest(); + request.Keycode = keycode; + Endpoint p = ConnectionStrings.Endpoints["notifyRecipients"].Clone(); + p.Path = p.Path.Replace("{packageId}", packageId); + StandardResponse response = connection.Send(p, request); + + if(response.Response != APIResponse.SUCCESS) + { + throw new ActionFailedException(response.Response.ToString(),response.Message); + } + } public void DeleteTempPackage(String packageId) { @@ -808,6 +899,11 @@ public void MoveFile(String packageId, String fileId, String destinationDirector } public Directory GetDirectory(String packageId, String directoryId) + { + return GetDirectory(packageId, directoryId, 0, 0, null, null); + } + + public Directory GetDirectory(String packageId, String directoryId, int directoryIndex, int fileIndex, String sortField, String sortOrder) { if (packageId == null) { @@ -818,9 +914,16 @@ public Directory GetDirectory(String packageId, String directoryId) throw new InvalidPackageException("Directory ID can not be null"); } + NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); + Endpoint p = ConnectionStrings.Endpoints["directoryInformation"].Clone(); p.Path = p.Path.Replace("{packageId}", packageId); p.Path = p.Path.Replace("{directoryId}", directoryId); + queryString.Add("directoryIndex", directoryIndex.ToString()); + queryString.Add("fileIndex", fileIndex.ToString()); + queryString.Add("sortField", sortField); + queryString.Add("sortOrder", sortOrder); + p.Path = p.Path + "/?" + queryString.ToString(); GetDirectoryResponse response = connection.Send(p); if (response.Response != APIResponse.SUCCESS) @@ -1141,6 +1244,18 @@ private List EncryptKeycodes(List publicKeys, St } internal PackageSearchResults GetOrganizationPackages(DateTime? fromDate, DateTime? toDate, string sender, PackageStatus? status, string recipient, string fileName) + { + GetOrganizationPakagesResponse response = GetOrganizationPackagesSend(fromDate, toDate, sender, status, recipient, fileName, -1, -1); + return Convert(response); + } + + internal PaginatedList GetOrganizationPackagesSearch(DateTime? fromDate, DateTime? toDate, string sender, PackageStatus? status, string recipient, string fileName, int rowIndex, int pageSize) + { + GetOrganizationPakagesResponse response = GetOrganizationPackagesSend(fromDate, toDate, sender, status, recipient, fileName, rowIndex, pageSize); + return ProcessPagination(Convert(response).Packages, response); + } + + internal GetOrganizationPakagesResponse GetOrganizationPackagesSend(DateTime? fromDate, DateTime? toDate, string sender, PackageStatus? status, string recipient, string fileName, int rowIndex, int pageSize) { GetOrganizationPackagesRequest request = new GetOrganizationPackagesRequest(); @@ -1159,16 +1274,55 @@ internal PackageSearchResults GetOrganizationPackages(DateTime? fromDate, DateTi request.Sender = sender; request.Recipient = recipient; request.Filename = fileName; + Endpoint p = ConnectionStrings.Endpoints["organizationPackagesSearch"].Clone(); + NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); - Endpoint p = ConnectionStrings.Endpoints["organizationPackages"].Clone(); - GetOrganizationPakagesResponse response = connection.Send(p, request); + if (rowIndex == -1 && pageSize == -1) + { + p = ConnectionStrings.Endpoints["organizationPackages"].Clone(); + } + else + { + queryString.Add("rowIndex", rowIndex.ToString()); + queryString.Add("pageSize", pageSize.ToString()); + p.Path = p.Path + "?" + queryString.ToString(); + } + GetOrganizationPakagesResponse response = connection.Send(p, request); if (response.Response != APIResponse.SUCCESS) { throw new ActionFailedException(response.Response.ToString(), response.Message); } - - return Convert(response); + + return response; + } + + private PaginatedList ProcessPagination(List packages, PaginationResponse response) + { + PaginatedList paginatedList = new PaginatedList(); + paginatedList.AddRange(packages); + + int rowIndex = 0, rowsReturned = 0, nextRowIndex = 0; + bool rowsCapped = false; + + int.TryParse(response.Pagination["rowIndex"], out rowIndex); + paginatedList.RowIndex = rowIndex; + int.TryParse(response.Pagination["rowsReturned"], out rowsReturned); + paginatedList.RowsReturned = rowsReturned; + if (response.Pagination.ContainsKey("nextRowIndex")) + { + int.TryParse(response.Pagination["nextRowIndex"], out nextRowIndex); + paginatedList.NextRowIndex = nextRowIndex; + } + + if (response.Pagination.ContainsKey("rowsCapped")) + { + bool.TryParse(response.Pagination["rowsCapped"], out rowsCapped); + paginatedList.RowsCapped = rowsCapped; + } + + return paginatedList; + } private PackageSearchResults Convert(GetOrganizationPakagesResponse response) @@ -1300,10 +1454,8 @@ private List Convert(List rawPackages) { returnList.Add(Convert(raw)); } - return returnList; - } - + } private Directory Convert(GetDirectoryResponse response) { @@ -1345,7 +1497,15 @@ private PackageInformation Convert(PackageDTO raw) packageInfo.PackageParentId = raw.PackageParentId; packageInfo.PackageOwner = raw.PackageUserName; - + int stateValue; + if (!Int32.TryParse(raw.PackageState, out stateValue)) + { + stateValue = 0; + } + packageInfo.Status = ConvertStateToStatus(stateValue); + + packageInfo.State = stateValue.ToString() ; + packageInfo.Files = new List(); foreach (String fileName in raw.Filenames) { diff --git a/SendsafelyAPI/Utilities/ParseLinksUtility.cs b/SendsafelyAPI/Utilities/ParseLinksUtility.cs index e6e8012..d0e6cea 100644 --- a/SendsafelyAPI/Utilities/ParseLinksUtility.cs +++ b/SendsafelyAPI/Utilities/ParseLinksUtility.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions;