azure-storage-files-shares
share_rest_client.hpp
1 
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 
5 #pragma once
6 
8 #include "azure/storage/files/shares/share_file_attributes.hpp"
9 
10 #include <functional>
11 #include <iostream>
12 #include <map>
13 #include <memory>
14 #include <stdexcept>
15 #include <string>
16 #include <vector>
17 
18 #include <azure/core/datetime.hpp>
19 #include <azure/core/etag.hpp>
20 #include <azure/core/http/http.hpp>
21 #include <azure/core/internal/http/pipeline.hpp>
22 #include <azure/core/internal/json/json.hpp>
23 #include <azure/core/nullable.hpp>
24 #include <azure/core/response.hpp>
25 #include <azure/storage/common/crypt.hpp>
26 #include <azure/storage/common/internal/xml_wrapper.hpp>
27 #include <azure/storage/common/storage_common.hpp>
28 #include <azure/storage/common/storage_exception.hpp>
29 
30 namespace Azure { namespace Storage { namespace Files { namespace Shares {
31 
32  namespace Models {
33 
37  struct FileHttpHeaders final
38  {
39 
43  std::string CacheControl;
44 
48  std::string ContentDisposition;
49 
53  std::string ContentEncoding;
54 
58  std::string ContentLanguage;
59 
63  std::string ContentType;
64 
68  Storage::ContentHash ContentHash;
69  };
70 
74  struct FileSmbProperties final
75  {
79  Azure::Nullable<std::string> PermissionKey;
80 
87 
91  Azure::Nullable<DateTime> CreatedOn;
92 
96  Azure::Nullable<DateTime> LastWrittenOn;
97 
101  Azure::Nullable<DateTime> ChangedOn;
102 
106  std::string FileId;
107 
111  std::string ParentFileId;
112  };
113 
117  class AccessTier final {
118  public:
119  AccessTier() = default;
120  explicit AccessTier(std::string value) : m_value(std::move(value)) {}
121  bool operator==(const AccessTier& other) const { return m_value == other.m_value; }
122  bool operator!=(const AccessTier& other) const { return !(*this == other); }
123  const std::string& ToString() const { return m_value; }
124 
125  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static AccessTier TransactionOptimized;
128  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static AccessTier Premium;
129 
130  private:
131  std::string m_value;
132  }; // extensible enum AccessTier
133 
139  class PermissionCopyMode final {
140  public:
141  PermissionCopyMode() = default;
142  explicit PermissionCopyMode(std::string value) : m_value(std::move(value)) {}
143  bool operator==(const PermissionCopyMode& other) const { return m_value == other.m_value; }
144  bool operator!=(const PermissionCopyMode& other) const { return !(*this == other); }
145  const std::string& ToString() const { return m_value; }
146 
149 
150  private:
151  std::string m_value;
152  }; // extensible enum PermissionCopyMode
153 
157  class DeleteSnapshotsOption final {
158  public:
159  DeleteSnapshotsOption() = default;
160  explicit DeleteSnapshotsOption(std::string value) : m_value(std::move(value)) {}
161  bool operator==(const DeleteSnapshotsOption& other) const { return m_value == other.m_value; }
162  bool operator!=(const DeleteSnapshotsOption& other) const { return !(*this == other); }
163  const std::string& ToString() const { return m_value; }
164 
166 
167  private:
168  std::string m_value;
169  }; // extensible enum DeleteSnapshotsOption
170 
174  struct AccessPolicy final
175  {
179  DateTime StartsOn;
180 
184  DateTime ExpiresOn;
185 
189  std::string Permission;
190  };
191 
198  struct CorsRule final
199  {
207  std::string AllowedOrigins;
208 
213  std::string AllowedMethods;
214 
218  std::string AllowedHeaders;
219 
224  std::string ExposedHeaders;
225 
229  int32_t MaxAgeInSeconds = int32_t();
230  };
231 
235  struct DirectoryItem final
236  {
240  std::string Name;
241  };
242 
246  struct FileItemDetails final
247  {
254  int64_t FileSize = int64_t();
255  };
256 
260  struct FileItem final
261  {
265  std::string Name;
266 
271  };
272 
276  struct HandleItem final
277  {
281  std::string HandleId;
282 
286  std::string Path;
287 
291  std::string FileId;
292 
296  std::string ParentId;
297 
301  std::string SessionId;
302 
306  std::string ClientIp;
307 
311  DateTime OpenedOn;
312 
317  };
318 
323  class LeaseDuration final {
324  public:
325  LeaseDuration() = default;
326  explicit LeaseDuration(std::string value) : m_value(std::move(value)) {}
327  bool operator==(const LeaseDuration& other) const { return m_value == other.m_value; }
328  bool operator!=(const LeaseDuration& other) const { return !(*this == other); }
329  const std::string& ToString() const { return m_value; }
330 
331  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseDuration Infinite;
333 
334  private:
335  std::string m_value;
336  }; // extensible enum LeaseDuration
337 
341  class LeaseState final {
342  public:
343  LeaseState() = default;
344  explicit LeaseState(std::string value) : m_value(std::move(value)) {}
345  bool operator==(const LeaseState& other) const { return m_value == other.m_value; }
346  bool operator!=(const LeaseState& other) const { return !(*this == other); }
347  const std::string& ToString() const { return m_value; }
348 
349  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseState Available;
350  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseState Leased;
351  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseState Expired;
352  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseState Breaking;
353  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseState Broken;
354 
355  private:
356  std::string m_value;
357  }; // extensible enum LeaseState
358 
362  class LeaseStatus final {
363  public:
364  LeaseStatus() = default;
365  explicit LeaseStatus(std::string value) : m_value(std::move(value)) {}
366  bool operator==(const LeaseStatus& other) const { return m_value == other.m_value; }
367  bool operator!=(const LeaseStatus& other) const { return !(*this == other); }
368  const std::string& ToString() const { return m_value; }
369 
371  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseStatus Unlocked;
372 
373  private:
374  std::string m_value;
375  }; // extensible enum LeaseStatus
376 
380  struct ShareItemDetails final
381  {
387  DateTime LastModified;
388 
392  Azure::ETag Etag;
393 
397  int64_t Quota = int64_t();
398 
402  Azure::Nullable<int32_t> ProvisionedIops;
403 
407  Azure::Nullable<int32_t> ProvisionedIngressMBps;
408 
412  Azure::Nullable<int32_t> ProvisionedEgressMBps;
413 
417  Azure::Nullable<DateTime> NextAllowedQuotaDowngradeTime;
418 
422  Azure::Nullable<DateTime> DeletedOn;
423 
427  int32_t RemainingRetentionDays = int32_t();
428 
432  Azure::Nullable<Models::AccessTier> AccessTier;
433 
437  Azure::Nullable<DateTime> AccessTierChangedOn;
438 
442  Azure::Nullable<std::string> AccessTierTransitionState;
443 
448 
453 
459  };
460 
464  struct ShareItem final
465  {
469  std::string Name;
470 
474  std::string Snapshot;
475 
479  bool Deleted = bool();
480 
484  std::string Version;
485 
490 
494  Storage::Metadata Metadata;
495  };
496 
500  struct RetentionPolicy final
501  {
506  bool Enabled = bool();
507 
513  Azure::Nullable<int32_t> Days;
514  };
515 
519  struct Metrics final
520  {
524  std::string Version;
525 
529  bool Enabled = bool();
530 
534  Azure::Nullable<bool> IncludeApis;
535 
540  };
541 
545  struct SmbMultichannel final
546  {
550  bool Enabled = bool();
551  };
552 
556  struct SmbSettings final
557  {
562  };
563 
567  struct ProtocolSettings final
568  {
573  };
574 
578  struct SignedIdentifier final
579  {
583  std::string Id;
584 
589  };
590 
595  {
600 
605 
609  std::vector<CorsRule> Cors;
610 
614  Azure::Nullable<ProtocolSettings> Protocol;
615  };
616 
620  class CopyStatus final {
621  public:
622  CopyStatus() = default;
623  explicit CopyStatus(std::string value) : m_value(std::move(value)) {}
624  bool operator==(const CopyStatus& other) const { return m_value == other.m_value; }
625  bool operator!=(const CopyStatus& other) const { return !(*this == other); }
626  const std::string& ToString() const { return m_value; }
627 
628  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static CopyStatus Pending;
629  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static CopyStatus Success;
630  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static CopyStatus Aborted;
631  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static CopyStatus Failed;
632 
633  private:
634  std::string m_value;
635  }; // extensible enum CopyStatus
636 
641  {
642  };
643 
647  struct CreateShareResult final
648  {
649 
653  Azure::ETag ETag;
654 
660  DateTime LastModified;
661 
665  bool Created = true;
666  };
667 
671  struct ShareProperties final
672  {
673 
677  Storage::Metadata Metadata;
678 
682  Azure::ETag ETag;
683 
689  DateTime LastModified;
690 
694  int64_t Quota = int64_t();
695 
699  Azure::Nullable<int32_t> ProvisionedIops;
700 
704  Azure::Nullable<int32_t> ProvisionedIngressMBps;
705 
709  Azure::Nullable<int32_t> ProvisionedEgressMBps;
710 
714  Azure::Nullable<DateTime> NextAllowedQuotaDowngradeTime;
715 
720  Azure::Nullable<Models::LeaseDuration> LeaseDuration;
721 
725  Azure::Nullable<Models::LeaseState> LeaseState;
726 
730  Azure::Nullable<Models::LeaseStatus> LeaseStatus;
731 
735  Azure::Nullable<Models::AccessTier> AccessTier;
736 
740  Azure::Nullable<DateTime> AccessTierChangedOn;
741 
745  Azure::Nullable<std::string> AccessTierTransitionState;
746  };
747 
751  struct DeleteShareResult final
752  {
753 
757  bool Deleted = true;
758  };
759 
763  struct AcquireLeaseResult final
764  {
765 
769  Azure::ETag ETag;
770 
776  DateTime LastModified;
777 
781  std::string LeaseId;
782  };
783 
787  struct ReleaseLeaseResult final
788  {
789 
793  Azure::ETag ETag;
794 
800  DateTime LastModified;
801  };
802 
806  struct ChangeLeaseResult final
807  {
808 
812  Azure::ETag ETag;
813 
819  DateTime LastModified;
820 
824  std::string LeaseId;
825  };
826 
830  struct RenewLeaseResult final
831  {
832 
836  Azure::ETag ETag;
837 
843  DateTime LastModified;
844 
848  std::string LeaseId;
849  };
850 
854  struct BreakLeaseResult final
855  {
856 
860  Azure::ETag ETag;
861 
867  DateTime LastModified;
868  };
869 
874  {
875 
881  std::string Snapshot;
882 
891  Azure::ETag ETag;
892 
901  DateTime LastModified;
902  };
903 
908  {
909 
913  std::string FilePermissionKey;
914  };
915 
920  {
921 
925  Azure::ETag ETag;
926 
932  DateTime LastModified;
933  };
934 
939  {
940 
944  Azure::ETag ETag;
945 
951  DateTime LastModified;
952  };
953 
957  struct ShareAccessPolicy final
958  {
959  std::vector<SignedIdentifier> SignedIdentifiers;
960  };
961 
966  {
967 
971  Azure::ETag ETag;
972 
978  DateTime LastModified;
979  };
980 
984  struct ShareStatistics final
985  {
990  int64_t ShareUsageInBytes = int64_t();
991 
995  Azure::ETag ETag;
996 
1002  DateTime LastModified;
1003  };
1004 
1009  {
1010 
1014  Azure::ETag ETag;
1015 
1021  DateTime LastModified;
1022 
1026  bool IsServerEncrypted = bool();
1027 
1032 
1036  bool Created = true;
1037  };
1038 
1042  struct DirectoryProperties final
1043  {
1044 
1048  Storage::Metadata Metadata;
1049 
1053  Azure::ETag ETag;
1054 
1059  DateTime LastModified;
1060 
1065  bool IsServerEncrypted = bool();
1066 
1071  };
1072 
1077  {
1078 
1082  bool Deleted = true;
1083  };
1084 
1089  {
1090 
1094  Azure::ETag ETag;
1095 
1101  DateTime LastModified;
1102 
1106  bool IsServerEncrypted = bool();
1107 
1112  };
1113 
1118  {
1119 
1123  Azure::ETag ETag;
1124 
1128  bool IsServerEncrypted = bool();
1129  };
1130 
1134  struct CreateFileResult final
1135  {
1136 
1140  Azure::ETag ETag;
1141 
1147  DateTime LastModified;
1148 
1152  bool IsServerEncrypted = bool();
1153 
1158 
1162  bool Created = true;
1163  };
1164 
1168  struct FileProperties final
1169  {
1170 
1175  DateTime LastModified;
1176 
1180  Storage::Metadata Metadata;
1181 
1186  int64_t FileSize = int64_t();
1187 
1192 
1196  Azure::ETag ETag;
1197 
1203  Azure::Nullable<DateTime> CopyCompletedOn;
1204 
1209  Azure::Nullable<std::string> CopyStatusDescription;
1210 
1215  Azure::Nullable<std::string> CopyId;
1216 
1222  Azure::Nullable<std::string> CopyProgress;
1223 
1228  Azure::Nullable<std::string> CopySource;
1229 
1233  Azure::Nullable<Models::CopyStatus> CopyStatus;
1234 
1241  bool IsServerEncrypted = bool();
1242 
1247 
1252  Azure::Nullable<Models::LeaseDuration> LeaseDuration;
1253 
1257  Azure::Nullable<Models::LeaseState> LeaseState;
1258 
1262  Azure::Nullable<Models::LeaseStatus> LeaseStatus;
1263  };
1264 
1268  struct DeleteFileResult final
1269  {
1270 
1274  bool Deleted = true;
1275  };
1276 
1281  {
1282 
1286  Azure::ETag ETag;
1287 
1293  DateTime LastModified;
1294 
1298  bool IsServerEncrypted = bool();
1299 
1304  };
1305 
1310  {
1311 
1315  Azure::ETag ETag;
1316 
1320  bool IsServerEncrypted = bool();
1321  };
1322 
1327  {
1328 
1332  Azure::ETag ETag;
1333 
1339  DateTime LastModified;
1340 
1346  Storage::ContentHash TransactionalContentHash;
1347 
1351  bool IsServerEncrypted = bool();
1352  };
1353 
1358  {
1359 
1363  Azure::ETag ETag;
1364 
1370  DateTime LastModified;
1371 
1377  Storage::ContentHash TransactionalContentHash;
1378 
1382  bool IsServerEncrypted = bool();
1383  };
1384 
1389  {
1393  std::vector<Core::Http::HttpRange> Ranges;
1394 
1398  std::vector<Core::Http::HttpRange> ClearRanges;
1399 
1405  DateTime LastModified;
1406 
1410  Azure::ETag ETag;
1411 
1415  int64_t FileSize = int64_t();
1416  };
1417 
1421  struct AbortFileCopyResult final
1422  {
1423  };
1424 
1428  enum class ListSharesIncludeFlags
1429  {
1430  None = 0,
1431  Snapshots = 1,
1432  Metadata = 2,
1433  Deleted = 4,
1434  };
1435 
1436  inline ListSharesIncludeFlags operator|(ListSharesIncludeFlags lhs, ListSharesIncludeFlags rhs)
1437  {
1438  using type = std::underlying_type_t<ListSharesIncludeFlags>;
1439  return static_cast<ListSharesIncludeFlags>(static_cast<type>(lhs) | static_cast<type>(rhs));
1440  }
1441 
1442  inline ListSharesIncludeFlags& operator|=(
1443  ListSharesIncludeFlags& lhs,
1444  ListSharesIncludeFlags rhs)
1445  {
1446  lhs = lhs | rhs;
1447  return lhs;
1448  }
1449 
1450  inline ListSharesIncludeFlags operator&(ListSharesIncludeFlags lhs, ListSharesIncludeFlags rhs)
1451  {
1452  using type = std::underlying_type_t<ListSharesIncludeFlags>;
1453  return static_cast<ListSharesIncludeFlags>(static_cast<type>(lhs) & static_cast<type>(rhs));
1454  }
1455 
1456  inline ListSharesIncludeFlags& operator&=(
1457  ListSharesIncludeFlags& lhs,
1458  ListSharesIncludeFlags rhs)
1459  {
1460  lhs = lhs & rhs;
1461  return lhs;
1462  }
1463  inline std::string ListSharesIncludeFlagsToString(const ListSharesIncludeFlags& val)
1464  {
1465  ListSharesIncludeFlags value_list[] = {
1466  ListSharesIncludeFlags::Snapshots,
1467  ListSharesIncludeFlags::Metadata,
1468  ListSharesIncludeFlags::Deleted,
1469  };
1470  const char* string_list[] = {
1471  "snapshots",
1472  "metadata",
1473  "deleted",
1474  };
1475  std::string result;
1476  for (size_t i = 0; i < sizeof(value_list) / sizeof(ListSharesIncludeFlags); ++i)
1477  {
1478  if ((val & value_list[i]) == value_list[i])
1479  {
1480  if (!result.empty())
1481  {
1482  result += ",";
1483  }
1484  result += string_list[i];
1485  }
1486  }
1487  return result;
1488  }
1489 
1490  } // namespace Models
1491  namespace _detail {
1492  using namespace Models;
1493  constexpr static const char* DefaultServiceApiVersion = "2020-02-10";
1494  constexpr static const char* QueryCopyId = "copyid";
1495  constexpr static const char* QueryIncludeFlags = "include";
1496  constexpr static const char* QueryContinuationToken = "marker";
1497  constexpr static const char* QueryPageSizeHint = "maxresults";
1498  constexpr static const char* QueryPrefix = "prefix";
1499  constexpr static const char* QueryPrevShareSnapshot = "prevsharesnapshot";
1500  constexpr static const char* QueryShareSnapshot = "sharesnapshot";
1501  constexpr static const char* QueryTimeout = "timeout";
1502  constexpr static const char* QueryRestype = "restype";
1503  constexpr static const char* QueryComp = "comp";
1504  constexpr static const char* HeaderVersion = "x-ms-version";
1505  constexpr static const char* HeaderAccessTier = "x-ms-access-tier";
1506  constexpr static const char* HeaderContentLength = "content-length";
1507  constexpr static const char* HeaderContentHashMd5 = "content-md5";
1508  constexpr static const char* HeaderCopyActionAbortConstant = "x-ms-copy-action";
1509  constexpr static const char* HeaderCopySource = "x-ms-copy-source";
1510  constexpr static const char* HeaderFilePermissionCopyMode = "x-ms-file-permission-copy-mode";
1511  constexpr static const char* HeaderIgnoreReadOnly = "x-ms-file-copy-ignore-read-only";
1512  constexpr static const char* HeaderFileAttributes = "x-ms-file-attributes";
1513  constexpr static const char* HeaderFileCreatedOn = "x-ms-file-creation-time";
1514  constexpr static const char* HeaderFileLastWrittenOn = "x-ms-file-last-write-time";
1515  constexpr static const char* HeaderSetArchiveAttribute = "x-ms-file-copy-set-archive";
1516  constexpr static const char* HeaderDeletedShareName = "x-ms-deleted-share-name";
1517  constexpr static const char* HeaderDeletedShareVersion = "x-ms-deleted-share-version";
1518  constexpr static const char* HeaderDeleteSnapshots = "x-ms-delete-snapshots";
1519  constexpr static const char* HeaderFileCacheControl = "x-ms-cache-control";
1520  constexpr static const char* HeaderFileContentDisposition = "x-ms-content-disposition";
1521  constexpr static const char* HeaderFileContentEncoding = "x-ms-content-encoding";
1522  constexpr static const char* HeaderFileContentLanguage = "x-ms-content-language";
1523  constexpr static const char* HeaderFileContentType = "x-ms-content-type";
1524  constexpr static const char* HeaderFilePermission = "x-ms-file-permission";
1525  constexpr static const char* HeaderFilePermissionKey = "x-ms-file-permission-key";
1526  constexpr static const char* HeaderFileRangeWriteFromUrl = "x-ms-write";
1527  constexpr static const char* HeaderFileRangeWriteFromUrlDefault = "update";
1528  constexpr static const char* HeaderFileTypeConstant = "x-ms-type";
1529  constexpr static const char* HeaderRangeGetContentMd5 = "x-ms-range-get-content-md5";
1530  constexpr static const char* HeaderHandleId = "x-ms-handle-id";
1531  constexpr static const char* HeaderBreakPeriod = "x-ms-lease-break-period";
1532  constexpr static const char* HeaderDuration = "x-ms-lease-duration";
1533  constexpr static const char* HeaderLeaseId = "x-ms-lease-id";
1534  constexpr static const char* HeaderMetadata = "x-ms-meta";
1535  constexpr static const char* HeaderProposedLeaseId = "x-ms-proposed-lease-id";
1536  constexpr static const char* HeaderRange = "x-ms-range";
1537  constexpr static const char* HeaderRecursive = "x-ms-recursive";
1538  constexpr static const char* HeaderQuota = "x-ms-share-quota";
1539  constexpr static const char* HeaderSourceContentHashCrc64 = "x-ms-source-content-crc64";
1540  constexpr static const char* HeaderSourceIfMatchHashCrc64 = "x-ms-source-if-match-crc64";
1541  constexpr static const char* HeaderSourceIfNoneMatchHashCrc64
1542  = "x-ms-source-if-none-match-crc64";
1543  constexpr static const char* HeaderSourceRange = "x-ms-source-range";
1544  constexpr static const char* HeaderRequestId = "x-ms-request-id";
1545  constexpr static const char* HeaderErrorCode = "x-ms-error-code";
1546  constexpr static const char* HeaderETag = "etag";
1547  constexpr static const char* HeaderLastModified = "last-modified";
1548  constexpr static const char* HeaderDate = "date";
1549  constexpr static const char* HeaderProvisionedIops = "x-ms-share-provisioned-iops";
1550  constexpr static const char* HeaderProvisionedIngressMBps
1551  = "x-ms-share-provisioned-ingress-mbps";
1552  constexpr static const char* HeaderProvisionedEgressMBps = "x-ms-share-provisioned-egress-mbps";
1553  constexpr static const char* HeaderNextAllowedQuotaDowngradeTime
1554  = "x-ms-share-next-allowed-quota-downgrade-time";
1555  constexpr static const char* HeaderLeaseDuration = "x-ms-lease-duration";
1556  constexpr static const char* HeaderLeaseState = "x-ms-lease-state";
1557  constexpr static const char* HeaderLeaseStatus = "x-ms-lease-status";
1558  constexpr static const char* HeaderAccessTierChangedOn = "x-ms-access-tier-change-time";
1559  constexpr static const char* HeaderAccessTierTransitionState
1560  = "x-ms-access-tier-transition-state";
1561  constexpr static const char* HeaderClientRequestId = "x-ms-client-request-id";
1562  constexpr static const char* HeaderAction = "x-ms-lease-action";
1563  constexpr static const char* HeaderSnapshot = "x-ms-snapshot";
1564  constexpr static const char* HeaderRequestIsServerEncrypted = "x-ms-request-server-encrypted";
1565  constexpr static const char* HeaderAttributes = "x-ms-file-attributes";
1566  constexpr static const char* HeaderCreatedOn = "x-ms-file-creation-time";
1567  constexpr static const char* HeaderLastWrittenOn = "x-ms-file-last-write-time";
1568  constexpr static const char* HeaderChangedOn = "x-ms-file-change-time";
1569  constexpr static const char* HeaderFileId = "x-ms-file-id";
1570  constexpr static const char* HeaderParentFileId = "x-ms-file-parent-id";
1571  constexpr static const char* HeaderIsServerEncrypted = "x-ms-server-encrypted";
1572  constexpr static const char* HeaderContentType = "content-type";
1573  constexpr static const char* HeaderContinuationToken = "x-ms-marker";
1574  constexpr static const char* HeaderNumberOfHandlesClosed = "x-ms-number-of-handles-closed";
1575  constexpr static const char* HeaderNumberOfHandlesFailedToClose
1576  = "x-ms-number-of-handles-failed";
1577  constexpr static const char* HeaderXMsContentLength = "x-ms-content-length";
1578  constexpr static const char* HeaderContentRange = "content-range";
1579  constexpr static const char* HeaderTransactionalContentHashMd5 = "content-md5";
1580  constexpr static const char* HeaderContentEncoding = "content-encoding";
1581  constexpr static const char* HeaderCacheControl = "cache-control";
1582  constexpr static const char* HeaderContentDisposition = "content-disposition";
1583  constexpr static const char* HeaderContentLanguage = "content-language";
1584  constexpr static const char* HeaderAcceptRanges = "accept-ranges";
1585  constexpr static const char* HeaderCopyCompletedOn = "x-ms-copy-completion-time";
1586  constexpr static const char* HeaderCopyStatusDescription = "x-ms-copy-status-description";
1587  constexpr static const char* HeaderCopyId = "x-ms-copy-id";
1588  constexpr static const char* HeaderCopyProgress = "x-ms-copy-progress";
1589  constexpr static const char* HeaderCopyStatus = "x-ms-copy-status";
1590  constexpr static const char* HeaderXMsRange = "x-ms-range";
1591  constexpr static const char* HeaderFileRangeWrite = "x-ms-write";
1592  constexpr static const char* HeaderFileRangeWriteDefault = "update";
1593  constexpr static const char* HeaderTransactionalContentHashCrc64 = "x-ms-content-crc64";
1594 
1599  class FileRangeWriteFromUrl final {
1600  public:
1601  FileRangeWriteFromUrl() = default;
1602  explicit FileRangeWriteFromUrl(std::string value) : m_value(std::move(value)) {}
1603  bool operator==(const FileRangeWriteFromUrl& other) const { return m_value == other.m_value; }
1604  bool operator!=(const FileRangeWriteFromUrl& other) const { return !(*this == other); }
1605  const std::string& ToString() const { return m_value; }
1606 
1607  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static FileRangeWriteFromUrl Update;
1608 
1609  private:
1610  std::string m_value;
1611  }; // extensible enum FileRangeWriteFromUrl
1612 
1616  struct FilesAndDirectoriesListSinglePage final
1617  {
1621  std::vector<DirectoryItem> DirectoryItems;
1622 
1626  std::vector<FileItem> FileItems;
1627  };
1628 
1632  struct ListFilesAndDirectoriesSinglePageResponse final
1633  {
1637  std::string ServiceEndpoint;
1638 
1642  std::string ShareName;
1643 
1647  std::string ShareSnapshot;
1648 
1652  std::string DirectoryPath;
1653 
1657  std::string Prefix;
1658 
1662  int32_t PageSizeHint = int32_t();
1663 
1667  FilesAndDirectoriesListSinglePage SinglePage;
1668 
1672  Azure::Nullable<std::string> ContinuationToken;
1673  };
1674 
1678  struct ListHandlesResponse final
1679  {
1683  std::vector<HandleItem> HandleList;
1684 
1688  Azure::Nullable<std::string> ContinuationToken;
1689  };
1690 
1694  struct ListSharesResponse final
1695  {
1699  std::string ServiceEndpoint;
1700 
1704  std::string Prefix;
1705 
1709  int32_t PageSizeHint = int32_t();
1710 
1714  std::vector<ShareItem> Items;
1715 
1719  Azure::Nullable<std::string> ContinuationToken;
1720  };
1721 
1725  struct FileRange final
1726  {
1730  int64_t Start = int64_t();
1731 
1735  int64_t End = int64_t();
1736  };
1737 
1741  struct ClearRange final
1742  {
1746  int64_t Start = int64_t();
1747 
1751  int64_t End = int64_t();
1752  };
1753 
1757  struct RangeList final
1758  {
1762  std::vector<Core::Http::HttpRange> Ranges;
1763 
1767  std::vector<Core::Http::HttpRange> ClearRanges;
1768  };
1769 
1773  struct ShareStats final
1774  {
1779  int64_t ShareUsageInBytes = int64_t();
1780  };
1781 
1785  struct SharePermission final
1786  {
1790  std::string FilePermission;
1791  };
1792 
1796  class LeaseAction final {
1797  public:
1798  LeaseAction() = default;
1799  explicit LeaseAction(std::string value) : m_value(std::move(value)) {}
1800  bool operator==(const LeaseAction& other) const { return m_value == other.m_value; }
1801  bool operator!=(const LeaseAction& other) const { return !(*this == other); }
1802  const std::string& ToString() const { return m_value; }
1803 
1804  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseAction Acquire;
1805  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseAction Release;
1806  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseAction Change;
1807  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseAction Renew;
1808  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static LeaseAction Break;
1809 
1810  private:
1811  std::string m_value;
1812  }; // extensible enum LeaseAction
1813 
1821  class FileRangeWrite final {
1822  public:
1823  FileRangeWrite() = default;
1824  explicit FileRangeWrite(std::string value) : m_value(std::move(value)) {}
1825  bool operator==(const FileRangeWrite& other) const { return m_value == other.m_value; }
1826  bool operator!=(const FileRangeWrite& other) const { return !(*this == other); }
1827  const std::string& ToString() const { return m_value; }
1828 
1829  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static FileRangeWrite Update;
1830  AZ_STORAGE_FILES_SHARES_DLLEXPORT const static FileRangeWrite Clear;
1831 
1832  private:
1833  std::string m_value;
1834  }; // extensible enum FileRangeWrite
1835 
1836  struct ServiceGetPropertiesResult final
1837  {
1841  Metrics HourMetrics;
1842 
1846  Metrics MinuteMetrics;
1847 
1851  std::vector<CorsRule> Cors;
1852 
1856  Azure::Nullable<ProtocolSettings> Protocol;
1857  };
1858 
1859  struct ServiceListSharesSinglePageResult final
1860  {
1864  std::string ServiceEndpoint;
1865 
1869  std::string Prefix;
1870 
1874  int32_t PageSizeHint = int32_t();
1875 
1879  std::vector<ShareItem> Items;
1880 
1884  Azure::Nullable<std::string> ContinuationToken;
1885  };
1886 
1887  struct ShareGetPermissionResult final
1888  {
1892  std::string FilePermission;
1893  };
1894 
1895  struct ShareRestoreResult final
1896  {
1897 
1901  Azure::ETag ETag;
1902 
1908  DateTime LastModified;
1909  };
1910 
1911  struct DirectoryListFilesAndDirectoriesSinglePageResult final
1912  {
1916  std::string ServiceEndpoint;
1917 
1921  std::string ShareName;
1922 
1926  std::string ShareSnapshot;
1927 
1931  std::string DirectoryPath;
1932 
1936  std::string Prefix;
1937 
1941  int32_t PageSizeHint = int32_t();
1942 
1946  FilesAndDirectoriesListSinglePage SinglePage;
1947 
1951  Azure::Nullable<std::string> ContinuationToken;
1952 
1956  FileHttpHeaders HttpHeaders;
1957  };
1958 
1959  struct DirectoryListHandlesResult final
1960  {
1964  std::vector<HandleItem> HandleList;
1965 
1969  Azure::Nullable<std::string> ContinuationToken;
1970 
1974  FileHttpHeaders HttpHeaders;
1975  };
1976 
1977  struct DirectoryForceCloseHandlesResult final
1978  {
1979 
1984  Azure::Nullable<std::string> ContinuationToken;
1985 
1989  int32_t NumberOfHandlesClosed = int32_t();
1990 
1994  int32_t NumberOfHandlesFailedToClose = int32_t();
1995  };
1996 
1997  struct FileDownloadResult final
1998  {
1999  std::unique_ptr<Azure::Core::IO::BodyStream> BodyStream;
2000 
2005  DateTime LastModified;
2006 
2010  Storage::Metadata Metadata;
2011 
2015  FileHttpHeaders HttpHeaders;
2016 
2020  Azure::Core::Http::HttpRange ContentRange;
2021 
2025  int64_t FileSize = int64_t();
2026 
2030  Azure::ETag ETag;
2031 
2040  Azure::Nullable<Storage::ContentHash> TransactionalContentHash;
2041 
2045  std::string AcceptRanges;
2046 
2052  Azure::Nullable<DateTime> CopyCompletedOn;
2053 
2058  Azure::Nullable<std::string> CopyStatusDescription;
2059 
2064  Azure::Nullable<std::string> CopyId;
2065 
2071  Azure::Nullable<std::string> CopyProgress;
2072 
2077  Azure::Nullable<std::string> CopySource;
2078 
2082  Azure::Nullable<Models::CopyStatus> CopyStatus;
2083 
2090  bool IsServerEncrypted = bool();
2091 
2095  FileSmbProperties SmbProperties;
2096 
2101  Azure::Nullable<Models::LeaseDuration> LeaseDuration;
2102 
2106  Azure::Nullable<Models::LeaseState> LeaseState;
2107 
2111  Azure::Nullable<Models::LeaseStatus> LeaseStatus;
2112  };
2113 
2114  struct FileAcquireLeaseResult final
2115  {
2116 
2121  Azure::ETag ETag;
2122 
2128  DateTime LastModified;
2129 
2133  std::string LeaseId;
2134  };
2135 
2136  struct FileReleaseLeaseResult final
2137  {
2138 
2143  Azure::ETag ETag;
2144 
2150  DateTime LastModified;
2151  };
2152 
2153  struct FileChangeLeaseResult final
2154  {
2155 
2160  Azure::ETag ETag;
2161 
2167  DateTime LastModified;
2168 
2172  std::string LeaseId;
2173  };
2174 
2175  struct FileBreakLeaseResult final
2176  {
2177 
2182  Azure::ETag ETag;
2183 
2189  DateTime LastModified;
2190 
2194  Azure::Nullable<std::string> LeaseId;
2195  };
2196 
2197  struct FileStartCopyResult final
2198  {
2199 
2204  Azure::ETag ETag;
2205 
2209  DateTime LastModified;
2210 
2216  std::string CopyId;
2217 
2221  Models::CopyStatus CopyStatus;
2222  };
2223 
2224  struct FileListHandlesResult final
2225  {
2229  std::vector<HandleItem> HandleList;
2230 
2234  Azure::Nullable<std::string> ContinuationToken;
2235 
2239  FileHttpHeaders HttpHeaders;
2240  };
2241 
2242  struct FileForceCloseHandlesResult final
2243  {
2244 
2249  Azure::Nullable<std::string> ContinuationToken;
2250 
2254  int32_t NumberOfHandlesClosed = int32_t();
2255 
2259  int32_t NumberOfHandlesFailedToClose = int32_t();
2260  };
2261 
2262  class ShareRestClient final {
2263  private:
2264  static Azure::Core::Http::HttpRange HttpRangeFromXml(_internal::XmlReader& reader)
2265  {
2266  int depth = 0;
2267  bool is_start = false;
2268  bool is_end = false;
2269  int64_t start = 0;
2270  int64_t end = 0;
2271  while (true)
2272  {
2273  auto node = reader.Read();
2274  if (node.Type == _internal::XmlNodeType::End)
2275  {
2276  break;
2277  }
2278  else if (node.Type == _internal::XmlNodeType::StartTag && strcmp(node.Name, "Start") == 0)
2279  {
2280  ++depth;
2281  is_start = true;
2282  }
2283  else if (node.Type == _internal::XmlNodeType::StartTag && strcmp(node.Name, "End") == 0)
2284  {
2285  ++depth;
2286  is_end = true;
2287  }
2288  else if (node.Type == _internal::XmlNodeType::EndTag)
2289  {
2290  is_start = false;
2291  is_end = false;
2292  if (depth-- == 0)
2293  {
2294  break;
2295  }
2296  }
2297  if (depth == 1 && node.Type == _internal::XmlNodeType::Text)
2298  {
2299  if (is_start)
2300  {
2301  start = std::stoll(node.Value);
2302  }
2303  else if (is_end)
2304  {
2305  end = std::stoll(node.Value);
2306  }
2307  }
2308  }
2309  Azure::Core::Http::HttpRange ret;
2310  ret.Offset = start;
2311  ret.Length = end - start + 1;
2312  return ret;
2313  }
2314 
2315  public:
2316  class Service final {
2317  public:
2318  struct SetPropertiesOptions final
2319  {
2320  ShareServiceProperties ServiceProperties;
2321  Azure::Nullable<int32_t> Timeout;
2322  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
2323  };
2324 
2325  static Azure::Response<Models::SetServicePropertiesResult> SetProperties(
2326  const Azure::Core::Url& url,
2327  Azure::Core::Http::_internal::HttpPipeline& pipeline,
2328  Azure::Core::Context context,
2329  const SetPropertiesOptions& setPropertiesOptions)
2330  {
2331 
2332  std::string xml_body;
2333  {
2334  _internal::XmlWriter writer;
2335  ShareServicePropertiesToXml(writer, setPropertiesOptions.ServiceProperties);
2336  writer.Write(_internal::XmlNode{_internal::XmlNodeType::End});
2337  xml_body = writer.GetDocument();
2338  }
2339  auto body = Azure::Core::IO::MemoryBodyStream(
2340  reinterpret_cast<const uint8_t*>(xml_body.data()), xml_body.length());
2341  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url, &body);
2342  request.SetHeader("Content-Length", std::to_string(body.Length()));
2343  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "service");
2344  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "properties");
2345  if (setPropertiesOptions.Timeout.HasValue())
2346  {
2347  request.GetUrl().AppendQueryParameter(
2348  _detail::QueryTimeout,
2349  _internal::UrlEncodeQueryParameter(
2350  std::to_string(setPropertiesOptions.Timeout.Value())));
2351  }
2352  request.SetHeader(_detail::HeaderVersion, setPropertiesOptions.ApiVersionParameter);
2353  return SetPropertiesParseResult(context, pipeline.Send(request, context));
2354  }
2355 
2356  struct GetPropertiesOptions final
2357  {
2358  Azure::Nullable<int32_t> Timeout;
2359  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
2360  };
2361 
2362  static Azure::Response<ServiceGetPropertiesResult> GetProperties(
2363  const Azure::Core::Url& url,
2364  Azure::Core::Http::_internal::HttpPipeline& pipeline,
2365  Azure::Core::Context context,
2366  const GetPropertiesOptions& getPropertiesOptions)
2367  {
2368  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
2369  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "service");
2370  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "properties");
2371  if (getPropertiesOptions.Timeout.HasValue())
2372  {
2373  request.GetUrl().AppendQueryParameter(
2374  _detail::QueryTimeout,
2375  _internal::UrlEncodeQueryParameter(
2376  std::to_string(getPropertiesOptions.Timeout.Value())));
2377  }
2378  request.SetHeader(_detail::HeaderVersion, getPropertiesOptions.ApiVersionParameter);
2379  return GetPropertiesParseResult(context, pipeline.Send(request, context));
2380  }
2381 
2382  struct ListSharesSinglePageOptions final
2383  {
2384  Azure::Nullable<std::string> Prefix;
2385  Azure::Nullable<std::string> ContinuationToken;
2386  Azure::Nullable<int32_t> MaxResults;
2387  Azure::Nullable<ListSharesIncludeFlags> IncludeFlags;
2388  Azure::Nullable<int32_t> Timeout;
2389  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
2390  };
2391 
2392  static Azure::Response<ServiceListSharesSinglePageResult> ListSharesSinglePage(
2393  const Azure::Core::Url& url,
2394  Azure::Core::Http::_internal::HttpPipeline& pipeline,
2395  Azure::Core::Context context,
2396  const ListSharesSinglePageOptions& listSharesSinglePageOptions)
2397  {
2398  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
2399  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "list");
2400  if (listSharesSinglePageOptions.Prefix.HasValue())
2401  {
2402  request.GetUrl().AppendQueryParameter(
2403  _detail::QueryPrefix,
2404  _internal::UrlEncodeQueryParameter(listSharesSinglePageOptions.Prefix.Value()));
2405  }
2406  if (listSharesSinglePageOptions.ContinuationToken.HasValue())
2407  {
2408  request.GetUrl().AppendQueryParameter(
2409  _detail::QueryContinuationToken,
2410  _internal::UrlEncodeQueryParameter(
2411  listSharesSinglePageOptions.ContinuationToken.Value()));
2412  }
2413  if (listSharesSinglePageOptions.MaxResults.HasValue())
2414  {
2415  request.GetUrl().AppendQueryParameter(
2416  _detail::QueryPageSizeHint,
2417  _internal::UrlEncodeQueryParameter(
2418  std::to_string(listSharesSinglePageOptions.MaxResults.Value())));
2419  }
2420  if (listSharesSinglePageOptions.IncludeFlags.HasValue())
2421  {
2422  request.GetUrl().AppendQueryParameter(
2423  _detail::QueryIncludeFlags,
2424  _internal::UrlEncodeQueryParameter(ListSharesIncludeFlagsToString(
2425  listSharesSinglePageOptions.IncludeFlags.Value())));
2426  }
2427  if (listSharesSinglePageOptions.Timeout.HasValue())
2428  {
2429  request.GetUrl().AppendQueryParameter(
2430  _detail::QueryTimeout,
2431  _internal::UrlEncodeQueryParameter(
2432  std::to_string(listSharesSinglePageOptions.Timeout.Value())));
2433  }
2434  request.SetHeader(
2435  _detail::HeaderVersion, listSharesSinglePageOptions.ApiVersionParameter);
2436  return ListSharesSinglePageParseResult(context, pipeline.Send(request, context));
2437  }
2438 
2439  private:
2440  static Azure::Response<Models::SetServicePropertiesResult> SetPropertiesParseResult(
2441  Azure::Core::Context context,
2442  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
2443  {
2444  auto& response = *responsePtr;
2445  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Accepted)
2446  {
2447  // Success (Accepted)
2448  Models::SetServicePropertiesResult result;
2449  return Azure::Response<Models::SetServicePropertiesResult>(
2450  std::move(result), std::move(responsePtr));
2451  }
2452  else
2453  {
2454  (void)context;
2455  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
2456  }
2457  }
2458 
2459  static void RetentionPolicyToXml(
2460  _internal::XmlWriter& writer,
2461  const RetentionPolicy& object)
2462  {
2463  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Enabled"});
2464  writer.Write(_internal::XmlNode{
2465  _internal::XmlNodeType::Text, nullptr, object.Enabled ? "true" : "false"});
2466  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2467  if (object.Days.HasValue())
2468  {
2469  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Days"});
2470  writer.Write(_internal::XmlNode{
2471  _internal::XmlNodeType::Text, nullptr, std::to_string(object.Days.Value()).data()});
2472  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2473  }
2474  }
2475 
2476  static void MetricsToXml(_internal::XmlWriter& writer, const Metrics& object)
2477  {
2478  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Version"});
2479  writer.Write(
2480  _internal::XmlNode{_internal::XmlNodeType::Text, nullptr, object.Version.data()});
2481  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2482  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Enabled"});
2483  writer.Write(_internal::XmlNode{
2484  _internal::XmlNodeType::Text, nullptr, object.Enabled ? "true" : "false"});
2485  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2486  if (object.IncludeApis.HasValue())
2487  {
2488  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "IncludeAPIs"});
2489  writer.Write(_internal::XmlNode{
2490  _internal::XmlNodeType::Text,
2491  nullptr,
2492  object.IncludeApis.Value() ? "true" : "false"});
2493  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2494  }
2495  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "RetentionPolicy"});
2496  RetentionPolicyToXml(writer, object.RetentionPolicy);
2497  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2498  }
2499 
2500  static void CorsRuleToXml(_internal::XmlWriter& writer, const CorsRule& object)
2501  {
2502  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "CorsRule"});
2503  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AllowedOrigins"});
2504  writer.Write(_internal::XmlNode{
2505  _internal::XmlNodeType::Text, nullptr, object.AllowedOrigins.data()});
2506  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2507  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AllowedMethods"});
2508  writer.Write(_internal::XmlNode{
2509  _internal::XmlNodeType::Text, nullptr, object.AllowedMethods.data()});
2510  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2511  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AllowedHeaders"});
2512  writer.Write(_internal::XmlNode{
2513  _internal::XmlNodeType::Text, nullptr, object.AllowedHeaders.data()});
2514  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2515  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "ExposedHeaders"});
2516  writer.Write(_internal::XmlNode{
2517  _internal::XmlNodeType::Text, nullptr, object.ExposedHeaders.data()});
2518  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2519  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "MaxAgeInSeconds"});
2520  writer.Write(_internal::XmlNode{
2521  _internal::XmlNodeType::Text,
2522  nullptr,
2523  std::to_string(object.MaxAgeInSeconds).data()});
2524  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2525  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2526  }
2527 
2528  static void SmbMultichannelToXml(
2529  _internal::XmlWriter& writer,
2530  const SmbMultichannel& object)
2531  {
2532  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Multichannel"});
2533  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Enabled"});
2534  writer.Write(_internal::XmlNode{
2535  _internal::XmlNodeType::Text, nullptr, object.Enabled ? "true" : "false"});
2536  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2537  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2538  }
2539 
2540  static void SmbSettingsToXml(_internal::XmlWriter& writer, const SmbSettings& object)
2541  {
2542  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "SMB"});
2543  SmbMultichannelToXml(writer, object.Multichannel);
2544  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2545  }
2546 
2547  static void ProtocolSettingsToXml(
2548  _internal::XmlWriter& writer,
2549  const ProtocolSettings& object)
2550  {
2551  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "ProtocolSettings"});
2552  SmbSettingsToXml(writer, object.Settings);
2553  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2554  }
2555 
2556  static void ShareServicePropertiesToXml(
2557  _internal::XmlWriter& writer,
2558  const ShareServiceProperties& object)
2559  {
2560  writer.Write(
2561  _internal::XmlNode{_internal::XmlNodeType::StartTag, "StorageServiceProperties"});
2562  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "HourMetrics"});
2563  MetricsToXml(writer, object.HourMetrics);
2564  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2565  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "MinuteMetrics"});
2566  MetricsToXml(writer, object.MinuteMetrics);
2567  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2568  if (object.Cors.size() > 0)
2569  {
2570  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Cors"});
2571  for (const auto& item : object.Cors)
2572  {
2573  CorsRuleToXml(writer, item);
2574  }
2575  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2576  }
2577  if (object.Protocol.HasValue())
2578  {
2579  ProtocolSettingsToXml(writer, object.Protocol.Value());
2580  }
2581  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
2582  }
2583  static Azure::Response<ServiceGetPropertiesResult> GetPropertiesParseResult(
2584  Azure::Core::Context context,
2585  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
2586  {
2587  auto& response = *responsePtr;
2588  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
2589  {
2590  // Success.
2591  const auto& bodyBuffer = response.GetBody();
2592  auto reader = _internal::XmlReader(
2593  reinterpret_cast<const char*>(bodyBuffer.data()), bodyBuffer.size());
2594  ServiceGetPropertiesResult result = bodyBuffer.empty()
2595  ? ServiceGetPropertiesResult()
2596  : ServiceGetPropertiesResultFromShareServiceProperties(
2597  ShareServicePropertiesFromXml(reader));
2598  return Azure::Response<ServiceGetPropertiesResult>(
2599  std::move(result), std::move(responsePtr));
2600  }
2601  else
2602  {
2603  (void)context;
2604  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
2605  }
2606  }
2607 
2608  static RetentionPolicy RetentionPolicyFromXml(_internal::XmlReader& reader)
2609  {
2610  auto result = RetentionPolicy();
2611  enum class XmlTagName
2612  {
2613  Days,
2614  Enabled,
2615  Unknown,
2616  };
2617  std::vector<XmlTagName> path;
2618 
2619  while (true)
2620  {
2621  auto node = reader.Read();
2622  if (node.Type == _internal::XmlNodeType::End)
2623  {
2624  break;
2625  }
2626  else if (node.Type == _internal::XmlNodeType::EndTag)
2627  {
2628  if (path.size() > 0)
2629  {
2630  path.pop_back();
2631  }
2632  else
2633  {
2634  break;
2635  }
2636  }
2637  else if (node.Type == _internal::XmlNodeType::StartTag)
2638  {
2639 
2640  if (std::strcmp(node.Name, "Days") == 0)
2641  {
2642  path.emplace_back(XmlTagName::Days);
2643  }
2644  else if (std::strcmp(node.Name, "Enabled") == 0)
2645  {
2646  path.emplace_back(XmlTagName::Enabled);
2647  }
2648  else
2649  {
2650  path.emplace_back(XmlTagName::Unknown);
2651  }
2652  }
2653  else if (node.Type == _internal::XmlNodeType::Text)
2654  {
2655  if (path.size() == 1 && path[0] == XmlTagName::Days)
2656  {
2657  result.Days = std::stoi(node.Value);
2658  }
2659  else if (path.size() == 1 && path[0] == XmlTagName::Enabled)
2660  {
2661  result.Enabled = (std::strcmp(node.Value, "true") == 0);
2662  }
2663  }
2664  }
2665  return result;
2666  }
2667 
2668  static Metrics MetricsFromXml(_internal::XmlReader& reader)
2669  {
2670  auto result = Metrics();
2671  enum class XmlTagName
2672  {
2673  Enabled,
2674  IncludeAPIs,
2675  RetentionPolicy,
2676  Unknown,
2677  Version,
2678  };
2679  std::vector<XmlTagName> path;
2680 
2681  while (true)
2682  {
2683  auto node = reader.Read();
2684  if (node.Type == _internal::XmlNodeType::End)
2685  {
2686  break;
2687  }
2688  else if (node.Type == _internal::XmlNodeType::EndTag)
2689  {
2690  if (path.size() > 0)
2691  {
2692  path.pop_back();
2693  }
2694  else
2695  {
2696  break;
2697  }
2698  }
2699  else if (node.Type == _internal::XmlNodeType::StartTag)
2700  {
2701 
2702  if (std::strcmp(node.Name, "Enabled") == 0)
2703  {
2704  path.emplace_back(XmlTagName::Enabled);
2705  }
2706  else if (std::strcmp(node.Name, "IncludeAPIs") == 0)
2707  {
2708  path.emplace_back(XmlTagName::IncludeAPIs);
2709  }
2710  else if (std::strcmp(node.Name, "RetentionPolicy") == 0)
2711  {
2712  path.emplace_back(XmlTagName::RetentionPolicy);
2713  }
2714  else if (std::strcmp(node.Name, "Version") == 0)
2715  {
2716  path.emplace_back(XmlTagName::Version);
2717  }
2718  else
2719  {
2720  path.emplace_back(XmlTagName::Unknown);
2721  }
2722 
2723  if (path.size() == 1 && path[0] == XmlTagName::RetentionPolicy)
2724  {
2725  result.RetentionPolicy = RetentionPolicyFromXml(reader);
2726  path.pop_back();
2727  }
2728  }
2729  else if (node.Type == _internal::XmlNodeType::Text)
2730  {
2731  if (path.size() == 1 && path[0] == XmlTagName::Enabled)
2732  {
2733  result.Enabled = (std::strcmp(node.Value, "true") == 0);
2734  }
2735  else if (path.size() == 1 && path[0] == XmlTagName::IncludeAPIs)
2736  {
2737  result.IncludeApis = (std::strcmp(node.Value, "true") == 0);
2738  }
2739  else if (path.size() == 1 && path[0] == XmlTagName::Version)
2740  {
2741  result.Version = node.Value;
2742  }
2743  }
2744  }
2745  return result;
2746  }
2747 
2748  static CorsRule CorsRuleFromXml(_internal::XmlReader& reader)
2749  {
2750  auto result = CorsRule();
2751  enum class XmlTagName
2752  {
2753  AllowedHeaders,
2754  AllowedMethods,
2755  AllowedOrigins,
2756  ExposedHeaders,
2757  MaxAgeInSeconds,
2758  Unknown,
2759  };
2760  std::vector<XmlTagName> path;
2761 
2762  while (true)
2763  {
2764  auto node = reader.Read();
2765  if (node.Type == _internal::XmlNodeType::End)
2766  {
2767  break;
2768  }
2769  else if (node.Type == _internal::XmlNodeType::EndTag)
2770  {
2771  if (path.size() > 0)
2772  {
2773  path.pop_back();
2774  }
2775  else
2776  {
2777  break;
2778  }
2779  }
2780  else if (node.Type == _internal::XmlNodeType::StartTag)
2781  {
2782 
2783  if (std::strcmp(node.Name, "AllowedHeaders") == 0)
2784  {
2785  path.emplace_back(XmlTagName::AllowedHeaders);
2786  }
2787  else if (std::strcmp(node.Name, "AllowedMethods") == 0)
2788  {
2789  path.emplace_back(XmlTagName::AllowedMethods);
2790  }
2791  else if (std::strcmp(node.Name, "AllowedOrigins") == 0)
2792  {
2793  path.emplace_back(XmlTagName::AllowedOrigins);
2794  }
2795  else if (std::strcmp(node.Name, "ExposedHeaders") == 0)
2796  {
2797  path.emplace_back(XmlTagName::ExposedHeaders);
2798  }
2799  else if (std::strcmp(node.Name, "MaxAgeInSeconds") == 0)
2800  {
2801  path.emplace_back(XmlTagName::MaxAgeInSeconds);
2802  }
2803  else
2804  {
2805  path.emplace_back(XmlTagName::Unknown);
2806  }
2807  }
2808  else if (node.Type == _internal::XmlNodeType::Text)
2809  {
2810  if (path.size() == 1 && path[0] == XmlTagName::AllowedHeaders)
2811  {
2812  result.AllowedHeaders = node.Value;
2813  }
2814  else if (path.size() == 1 && path[0] == XmlTagName::AllowedMethods)
2815  {
2816  result.AllowedMethods = node.Value;
2817  }
2818  else if (path.size() == 1 && path[0] == XmlTagName::AllowedOrigins)
2819  {
2820  result.AllowedOrigins = node.Value;
2821  }
2822  else if (path.size() == 1 && path[0] == XmlTagName::ExposedHeaders)
2823  {
2824  result.ExposedHeaders = node.Value;
2825  }
2826  else if (path.size() == 1 && path[0] == XmlTagName::MaxAgeInSeconds)
2827  {
2828  result.MaxAgeInSeconds = std::stoi(node.Value);
2829  }
2830  }
2831  }
2832  return result;
2833  }
2834 
2835  static SmbMultichannel SmbMultichannelFromXml(_internal::XmlReader& reader)
2836  {
2837  auto result = SmbMultichannel();
2838  enum class XmlTagName
2839  {
2840  Enabled,
2841  Unknown,
2842  };
2843  std::vector<XmlTagName> path;
2844 
2845  while (true)
2846  {
2847  auto node = reader.Read();
2848  if (node.Type == _internal::XmlNodeType::End)
2849  {
2850  break;
2851  }
2852  else if (node.Type == _internal::XmlNodeType::EndTag)
2853  {
2854  if (path.size() > 0)
2855  {
2856  path.pop_back();
2857  }
2858  else
2859  {
2860  break;
2861  }
2862  }
2863  else if (node.Type == _internal::XmlNodeType::StartTag)
2864  {
2865 
2866  if (std::strcmp(node.Name, "Enabled") == 0)
2867  {
2868  path.emplace_back(XmlTagName::Enabled);
2869  }
2870  else
2871  {
2872  path.emplace_back(XmlTagName::Unknown);
2873  }
2874  }
2875  else if (node.Type == _internal::XmlNodeType::Text)
2876  {
2877  if (path.size() == 1 && path[0] == XmlTagName::Enabled)
2878  {
2879  result.Enabled = (std::strcmp(node.Value, "true") == 0);
2880  }
2881  }
2882  }
2883  return result;
2884  }
2885 
2886  static SmbSettings SmbSettingsFromXml(_internal::XmlReader& reader)
2887  {
2888  auto result = SmbSettings();
2889  enum class XmlTagName
2890  {
2891  Multichannel,
2892  Unknown,
2893  };
2894  std::vector<XmlTagName> path;
2895 
2896  while (true)
2897  {
2898  auto node = reader.Read();
2899  if (node.Type == _internal::XmlNodeType::End)
2900  {
2901  break;
2902  }
2903  else if (node.Type == _internal::XmlNodeType::EndTag)
2904  {
2905  if (path.size() > 0)
2906  {
2907  path.pop_back();
2908  }
2909  else
2910  {
2911  break;
2912  }
2913  }
2914  else if (node.Type == _internal::XmlNodeType::StartTag)
2915  {
2916 
2917  if (std::strcmp(node.Name, "Multichannel") == 0)
2918  {
2919  path.emplace_back(XmlTagName::Multichannel);
2920  }
2921  else
2922  {
2923  path.emplace_back(XmlTagName::Unknown);
2924  }
2925 
2926  if (path.size() == 1 && path[0] == XmlTagName::Multichannel)
2927  {
2928  result.Multichannel = SmbMultichannelFromXml(reader);
2929  path.pop_back();
2930  }
2931  }
2932  else if (node.Type == _internal::XmlNodeType::Text)
2933  {
2934  }
2935  }
2936  return result;
2937  }
2938 
2939  static ProtocolSettings ProtocolSettingsFromXml(_internal::XmlReader& reader)
2940  {
2941  auto result = ProtocolSettings();
2942  enum class XmlTagName
2943  {
2944  SMB,
2945  Unknown,
2946  };
2947  std::vector<XmlTagName> path;
2948 
2949  while (true)
2950  {
2951  auto node = reader.Read();
2952  if (node.Type == _internal::XmlNodeType::End)
2953  {
2954  break;
2955  }
2956  else if (node.Type == _internal::XmlNodeType::EndTag)
2957  {
2958  if (path.size() > 0)
2959  {
2960  path.pop_back();
2961  }
2962  else
2963  {
2964  break;
2965  }
2966  }
2967  else if (node.Type == _internal::XmlNodeType::StartTag)
2968  {
2969 
2970  if (std::strcmp(node.Name, "SMB") == 0)
2971  {
2972  path.emplace_back(XmlTagName::SMB);
2973  }
2974  else
2975  {
2976  path.emplace_back(XmlTagName::Unknown);
2977  }
2978 
2979  if (path.size() == 1 && path[0] == XmlTagName::SMB)
2980  {
2981  result.Settings = SmbSettingsFromXml(reader);
2982  path.pop_back();
2983  }
2984  }
2985  else if (node.Type == _internal::XmlNodeType::Text)
2986  {
2987  }
2988  }
2989  return result;
2990  }
2991 
2992  static ShareServiceProperties ShareServicePropertiesFromXml(_internal::XmlReader& reader)
2993  {
2994  auto result = ShareServiceProperties();
2995  enum class XmlTagName
2996  {
2997  Cors,
2998  CorsRule,
2999  HourMetrics,
3000  MinuteMetrics,
3001  ProtocolSettings,
3002  StorageServiceProperties,
3003  Unknown,
3004  };
3005  std::vector<XmlTagName> path;
3006 
3007  while (true)
3008  {
3009  auto node = reader.Read();
3010  if (node.Type == _internal::XmlNodeType::End)
3011  {
3012  break;
3013  }
3014  else if (node.Type == _internal::XmlNodeType::EndTag)
3015  {
3016  if (path.size() > 0)
3017  {
3018  path.pop_back();
3019  }
3020  else
3021  {
3022  break;
3023  }
3024  }
3025  else if (node.Type == _internal::XmlNodeType::StartTag)
3026  {
3027 
3028  if (std::strcmp(node.Name, "Cors") == 0)
3029  {
3030  path.emplace_back(XmlTagName::Cors);
3031  }
3032  else if (std::strcmp(node.Name, "CorsRule") == 0)
3033  {
3034  path.emplace_back(XmlTagName::CorsRule);
3035  }
3036  else if (std::strcmp(node.Name, "HourMetrics") == 0)
3037  {
3038  path.emplace_back(XmlTagName::HourMetrics);
3039  }
3040  else if (std::strcmp(node.Name, "MinuteMetrics") == 0)
3041  {
3042  path.emplace_back(XmlTagName::MinuteMetrics);
3043  }
3044  else if (std::strcmp(node.Name, "ProtocolSettings") == 0)
3045  {
3046  path.emplace_back(XmlTagName::ProtocolSettings);
3047  }
3048  else if (std::strcmp(node.Name, "StorageServiceProperties") == 0)
3049  {
3050  path.emplace_back(XmlTagName::StorageServiceProperties);
3051  }
3052  else
3053  {
3054  path.emplace_back(XmlTagName::Unknown);
3055  }
3056 
3057  if (path.size() == 2 && path[0] == XmlTagName::StorageServiceProperties
3058  && path[1] == XmlTagName::HourMetrics)
3059  {
3060  result.HourMetrics = MetricsFromXml(reader);
3061  path.pop_back();
3062  }
3063  else if (
3064  path.size() == 2 && path[0] == XmlTagName::StorageServiceProperties
3065  && path[1] == XmlTagName::MinuteMetrics)
3066  {
3067  result.MinuteMetrics = MetricsFromXml(reader);
3068  path.pop_back();
3069  }
3070  else if (
3071  path.size() == 2 && path[0] == XmlTagName::StorageServiceProperties
3072  && path[1] == XmlTagName::ProtocolSettings)
3073  {
3074  result.Protocol = ProtocolSettingsFromXml(reader);
3075  path.pop_back();
3076  }
3077  else if (
3078  path.size() == 3 && path[0] == XmlTagName::StorageServiceProperties
3079  && path[1] == XmlTagName::Cors && path[2] == XmlTagName::CorsRule)
3080  {
3081  result.Cors.emplace_back(CorsRuleFromXml(reader));
3082  path.pop_back();
3083  }
3084  }
3085  else if (node.Type == _internal::XmlNodeType::Text)
3086  {
3087  }
3088  }
3089  return result;
3090  }
3091 
3092  static ServiceGetPropertiesResult ServiceGetPropertiesResultFromShareServiceProperties(
3093  ShareServiceProperties object)
3094  {
3095  ServiceGetPropertiesResult result;
3096  result.HourMetrics = std::move(object.HourMetrics);
3097  result.MinuteMetrics = std::move(object.MinuteMetrics);
3098  result.Cors = std::move(object.Cors);
3099  result.Protocol = std::move(object.Protocol);
3100 
3101  return result;
3102  }
3103  static Azure::Response<ServiceListSharesSinglePageResult> ListSharesSinglePageParseResult(
3104  Azure::Core::Context context,
3105  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
3106  {
3107  auto& response = *responsePtr;
3108  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
3109  {
3110  // Success.
3111  const auto& bodyBuffer = response.GetBody();
3112  auto reader = _internal::XmlReader(
3113  reinterpret_cast<const char*>(bodyBuffer.data()), bodyBuffer.size());
3114  ServiceListSharesSinglePageResult result = bodyBuffer.empty()
3115  ? ServiceListSharesSinglePageResult()
3116  : ServiceListSharesSinglePageResultFromListSharesResponse(
3117  ListSharesResponseFromXml(reader));
3118  return Azure::Response<ServiceListSharesSinglePageResult>(
3119  std::move(result), std::move(responsePtr));
3120  }
3121  else
3122  {
3123  (void)context;
3124  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
3125  }
3126  }
3127 
3128  static LeaseStatus LeaseStatusFromXml(_internal::XmlReader& reader)
3129  {
3130  LeaseStatus result;
3131  enum class XmlTagName
3132  {
3133  LeaseStatus,
3134  Unknown,
3135  };
3136  std::vector<XmlTagName> path;
3137 
3138  while (true)
3139  {
3140  auto node = reader.Read();
3141  if (node.Type == _internal::XmlNodeType::End)
3142  {
3143  break;
3144  }
3145  else if (node.Type == _internal::XmlNodeType::EndTag)
3146  {
3147  if (path.size() > 0)
3148  {
3149  path.pop_back();
3150  }
3151  else
3152  {
3153  break;
3154  }
3155  }
3156  else if (node.Type == _internal::XmlNodeType::StartTag)
3157  {
3158 
3159  if (std::strcmp(node.Name, "LeaseStatus") == 0)
3160  {
3161  path.emplace_back(XmlTagName::LeaseStatus);
3162  }
3163  else
3164  {
3165  path.emplace_back(XmlTagName::Unknown);
3166  }
3167  }
3168  else if (node.Type == _internal::XmlNodeType::Text)
3169  {
3170  if (path.size() == 1 && path[0] == XmlTagName::LeaseStatus)
3171  {
3172  result = LeaseStatus(node.Value);
3173  }
3174  }
3175  }
3176  return result;
3177  }
3178 
3179  static LeaseState LeaseStateFromXml(_internal::XmlReader& reader)
3180  {
3181  LeaseState result;
3182  enum class XmlTagName
3183  {
3184  LeaseState,
3185  Unknown,
3186  };
3187  std::vector<XmlTagName> path;
3188 
3189  while (true)
3190  {
3191  auto node = reader.Read();
3192  if (node.Type == _internal::XmlNodeType::End)
3193  {
3194  break;
3195  }
3196  else if (node.Type == _internal::XmlNodeType::EndTag)
3197  {
3198  if (path.size() > 0)
3199  {
3200  path.pop_back();
3201  }
3202  else
3203  {
3204  break;
3205  }
3206  }
3207  else if (node.Type == _internal::XmlNodeType::StartTag)
3208  {
3209 
3210  if (std::strcmp(node.Name, "LeaseState") == 0)
3211  {
3212  path.emplace_back(XmlTagName::LeaseState);
3213  }
3214  else
3215  {
3216  path.emplace_back(XmlTagName::Unknown);
3217  }
3218  }
3219  else if (node.Type == _internal::XmlNodeType::Text)
3220  {
3221  if (path.size() == 1 && path[0] == XmlTagName::LeaseState)
3222  {
3223  result = LeaseState(node.Value);
3224  }
3225  }
3226  }
3227  return result;
3228  }
3229 
3230  static LeaseDuration LeaseDurationFromXml(_internal::XmlReader& reader)
3231  {
3232  LeaseDuration result;
3233  enum class XmlTagName
3234  {
3235  LeaseDuration,
3236  Unknown,
3237  };
3238  std::vector<XmlTagName> path;
3239 
3240  while (true)
3241  {
3242  auto node = reader.Read();
3243  if (node.Type == _internal::XmlNodeType::End)
3244  {
3245  break;
3246  }
3247  else if (node.Type == _internal::XmlNodeType::EndTag)
3248  {
3249  if (path.size() > 0)
3250  {
3251  path.pop_back();
3252  }
3253  else
3254  {
3255  break;
3256  }
3257  }
3258  else if (node.Type == _internal::XmlNodeType::StartTag)
3259  {
3260 
3261  if (std::strcmp(node.Name, "LeaseDuration") == 0)
3262  {
3263  path.emplace_back(XmlTagName::LeaseDuration);
3264  }
3265  else
3266  {
3267  path.emplace_back(XmlTagName::Unknown);
3268  }
3269  }
3270  else if (node.Type == _internal::XmlNodeType::Text)
3271  {
3272  if (path.size() == 1 && path[0] == XmlTagName::LeaseDuration)
3273  {
3274  result = LeaseDuration(node.Value);
3275  }
3276  }
3277  }
3278  return result;
3279  }
3280 
3281  static ShareItemDetails ShareItemDetailsFromXml(_internal::XmlReader& reader)
3282  {
3283  auto result = ShareItemDetails();
3284  enum class XmlTagName
3285  {
3286  AccessTier,
3287  AccessTierChangeTime,
3288  AccessTierTransitionState,
3289  DeletedTime,
3290  Etag,
3291  LastModified,
3292  LeaseDuration,
3293  LeaseState,
3294  LeaseStatus,
3295  NextAllowedQuotaDowngradeTime,
3296  ProvisionedEgressMBps,
3297  ProvisionedIngressMBps,
3298  ProvisionedIops,
3299  Quota,
3300  RemainingRetentionDays,
3301  Unknown,
3302  };
3303  std::vector<XmlTagName> path;
3304 
3305  while (true)
3306  {
3307  auto node = reader.Read();
3308  if (node.Type == _internal::XmlNodeType::End)
3309  {
3310  break;
3311  }
3312  else if (node.Type == _internal::XmlNodeType::EndTag)
3313  {
3314  if (path.size() > 0)
3315  {
3316  path.pop_back();
3317  }
3318  else
3319  {
3320  break;
3321  }
3322  }
3323  else if (node.Type == _internal::XmlNodeType::StartTag)
3324  {
3325 
3326  if (std::strcmp(node.Name, "AccessTier") == 0)
3327  {
3328  path.emplace_back(XmlTagName::AccessTier);
3329  }
3330  else if (std::strcmp(node.Name, "AccessTierChangeTime") == 0)
3331  {
3332  path.emplace_back(XmlTagName::AccessTierChangeTime);
3333  }
3334  else if (std::strcmp(node.Name, "AccessTierTransitionState") == 0)
3335  {
3336  path.emplace_back(XmlTagName::AccessTierTransitionState);
3337  }
3338  else if (std::strcmp(node.Name, "DeletedTime") == 0)
3339  {
3340  path.emplace_back(XmlTagName::DeletedTime);
3341  }
3342  else if (std::strcmp(node.Name, "Etag") == 0)
3343  {
3344  path.emplace_back(XmlTagName::Etag);
3345  }
3346  else if (std::strcmp(node.Name, "Last-Modified") == 0)
3347  {
3348  path.emplace_back(XmlTagName::LastModified);
3349  }
3350  else if (std::strcmp(node.Name, "LeaseDuration") == 0)
3351  {
3352  path.emplace_back(XmlTagName::LeaseDuration);
3353  }
3354  else if (std::strcmp(node.Name, "LeaseState") == 0)
3355  {
3356  path.emplace_back(XmlTagName::LeaseState);
3357  }
3358  else if (std::strcmp(node.Name, "LeaseStatus") == 0)
3359  {
3360  path.emplace_back(XmlTagName::LeaseStatus);
3361  }
3362  else if (std::strcmp(node.Name, "NextAllowedQuotaDowngradeTime") == 0)
3363  {
3364  path.emplace_back(XmlTagName::NextAllowedQuotaDowngradeTime);
3365  }
3366  else if (std::strcmp(node.Name, "ProvisionedEgressMBps") == 0)
3367  {
3368  path.emplace_back(XmlTagName::ProvisionedEgressMBps);
3369  }
3370  else if (std::strcmp(node.Name, "ProvisionedIngressMBps") == 0)
3371  {
3372  path.emplace_back(XmlTagName::ProvisionedIngressMBps);
3373  }
3374  else if (std::strcmp(node.Name, "ProvisionedIops") == 0)
3375  {
3376  path.emplace_back(XmlTagName::ProvisionedIops);
3377  }
3378  else if (std::strcmp(node.Name, "Quota") == 0)
3379  {
3380  path.emplace_back(XmlTagName::Quota);
3381  }
3382  else if (std::strcmp(node.Name, "RemainingRetentionDays") == 0)
3383  {
3384  path.emplace_back(XmlTagName::RemainingRetentionDays);
3385  }
3386  else
3387  {
3388  path.emplace_back(XmlTagName::Unknown);
3389  }
3390 
3391  if (path.size() == 1 && path[0] == XmlTagName::LeaseStatus)
3392  {
3393  result.LeaseStatus = LeaseStatusFromXml(reader);
3394  path.pop_back();
3395  }
3396  else if (path.size() == 1 && path[0] == XmlTagName::LeaseState)
3397  {
3398  result.LeaseState = LeaseStateFromXml(reader);
3399  path.pop_back();
3400  }
3401  else if (path.size() == 1 && path[0] == XmlTagName::LeaseDuration)
3402  {
3403  result.LeaseDuration = LeaseDurationFromXml(reader);
3404  path.pop_back();
3405  }
3406  }
3407  else if (node.Type == _internal::XmlNodeType::Text)
3408  {
3409  if (path.size() == 1 && path[0] == XmlTagName::AccessTier)
3410  {
3411  result.AccessTier = AccessTier(node.Value);
3412  }
3413  else if (path.size() == 1 && path[0] == XmlTagName::AccessTierChangeTime)
3414  {
3415  result.AccessTierChangedOn
3416  = DateTime::Parse(node.Value, DateTime::DateFormat::Rfc1123);
3417  }
3418  else if (path.size() == 1 && path[0] == XmlTagName::AccessTierTransitionState)
3419  {
3420  result.AccessTierTransitionState = node.Value;
3421  }
3422  else if (path.size() == 1 && path[0] == XmlTagName::DeletedTime)
3423  {
3424  result.DeletedOn = DateTime::Parse(node.Value, DateTime::DateFormat::Rfc1123);
3425  }
3426  else if (path.size() == 1 && path[0] == XmlTagName::Etag)
3427  {
3428  result.Etag = Azure::ETag(node.Value);
3429  }
3430  else if (path.size() == 1 && path[0] == XmlTagName::LastModified)
3431  {
3432  result.LastModified = DateTime::Parse(node.Value, DateTime::DateFormat::Rfc1123);
3433  }
3434  else if (path.size() == 1 && path[0] == XmlTagName::NextAllowedQuotaDowngradeTime)
3435  {
3436  result.NextAllowedQuotaDowngradeTime
3437  = DateTime::Parse(node.Value, DateTime::DateFormat::Rfc1123);
3438  }
3439  else if (path.size() == 1 && path[0] == XmlTagName::ProvisionedEgressMBps)
3440  {
3441  result.ProvisionedEgressMBps = std::stoi(node.Value);
3442  }
3443  else if (path.size() == 1 && path[0] == XmlTagName::ProvisionedIngressMBps)
3444  {
3445  result.ProvisionedIngressMBps = std::stoi(node.Value);
3446  }
3447  else if (path.size() == 1 && path[0] == XmlTagName::ProvisionedIops)
3448  {
3449  result.ProvisionedIops = std::stoi(node.Value);
3450  }
3451  else if (path.size() == 1 && path[0] == XmlTagName::Quota)
3452  {
3453  result.Quota = std::stoll(node.Value);
3454  }
3455  else if (path.size() == 1 && path[0] == XmlTagName::RemainingRetentionDays)
3456  {
3457  result.RemainingRetentionDays = std::stoi(node.Value);
3458  }
3459  }
3460  }
3461  return result;
3462  }
3463 
3464  static Metadata MetadataFromXml(_internal::XmlReader& reader)
3465  {
3466  Metadata result;
3467  int depth = 0;
3468  std::string key;
3469  while (true)
3470  {
3471  auto node = reader.Read();
3472  if (node.Type == _internal::XmlNodeType::End)
3473  {
3474  break;
3475  }
3476  else if (node.Type == _internal::XmlNodeType::StartTag)
3477  {
3478  if (depth++ == 0)
3479  {
3480  key = node.Name;
3481  }
3482  }
3483  else if (node.Type == _internal::XmlNodeType::EndTag)
3484  {
3485  if (depth-- == 0)
3486  {
3487  break;
3488  }
3489  }
3490  else if (depth == 1 && node.Type == _internal::XmlNodeType::Text)
3491  {
3492  result.emplace(std::move(key), std::string(node.Value));
3493  }
3494  }
3495  return result;
3496  }
3497 
3498  static ShareItem ShareItemFromXml(_internal::XmlReader& reader)
3499  {
3500  auto result = ShareItem();
3501  enum class XmlTagName
3502  {
3503  Deleted,
3504  Metadata,
3505  Name,
3506  Properties,
3507  Snapshot,
3508  Unknown,
3509  Version,
3510  };
3511  std::vector<XmlTagName> path;
3512 
3513  while (true)
3514  {
3515  auto node = reader.Read();
3516  if (node.Type == _internal::XmlNodeType::End)
3517  {
3518  break;
3519  }
3520  else if (node.Type == _internal::XmlNodeType::EndTag)
3521  {
3522  if (path.size() > 0)
3523  {
3524  path.pop_back();
3525  }
3526  else
3527  {
3528  break;
3529  }
3530  }
3531  else if (node.Type == _internal::XmlNodeType::StartTag)
3532  {
3533 
3534  if (std::strcmp(node.Name, "Deleted") == 0)
3535  {
3536  path.emplace_back(XmlTagName::Deleted);
3537  }
3538  else if (std::strcmp(node.Name, "Metadata") == 0)
3539  {
3540  path.emplace_back(XmlTagName::Metadata);
3541  }
3542  else if (std::strcmp(node.Name, "Name") == 0)
3543  {
3544  path.emplace_back(XmlTagName::Name);
3545  }
3546  else if (std::strcmp(node.Name, "Properties") == 0)
3547  {
3548  path.emplace_back(XmlTagName::Properties);
3549  }
3550  else if (std::strcmp(node.Name, "Snapshot") == 0)
3551  {
3552  path.emplace_back(XmlTagName::Snapshot);
3553  }
3554  else if (std::strcmp(node.Name, "Version") == 0)
3555  {
3556  path.emplace_back(XmlTagName::Version);
3557  }
3558  else
3559  {
3560  path.emplace_back(XmlTagName::Unknown);
3561  }
3562 
3563  if (path.size() == 1 && path[0] == XmlTagName::Properties)
3564  {
3565  result.Details = ShareItemDetailsFromXml(reader);
3566  path.pop_back();
3567  }
3568  else if (path.size() == 1 && path[0] == XmlTagName::Metadata)
3569  {
3570  result.Metadata = MetadataFromXml(reader);
3571  path.pop_back();
3572  }
3573  }
3574  else if (node.Type == _internal::XmlNodeType::Text)
3575  {
3576  if (path.size() == 1 && path[0] == XmlTagName::Deleted)
3577  {
3578  result.Deleted = (std::strcmp(node.Value, "true") == 0);
3579  }
3580  else if (path.size() == 1 && path[0] == XmlTagName::Name)
3581  {
3582  result.Name = node.Value;
3583  }
3584  else if (path.size() == 1 && path[0] == XmlTagName::Snapshot)
3585  {
3586  result.Snapshot = node.Value;
3587  }
3588  else if (path.size() == 1 && path[0] == XmlTagName::Version)
3589  {
3590  result.Version = node.Value;
3591  }
3592  }
3593  }
3594  return result;
3595  }
3596 
3597  static ListSharesResponse ListSharesResponseFromXml(_internal::XmlReader& reader)
3598  {
3599  auto result = ListSharesResponse();
3600  enum class XmlTagName
3601  {
3602  EnumerationResults,
3603  MaxResults,
3604  NextMarker,
3605  Prefix,
3606  Share,
3607  Shares,
3608  Unknown,
3609  };
3610  std::vector<XmlTagName> path;
3611 
3612  while (true)
3613  {
3614  auto node = reader.Read();
3615  if (node.Type == _internal::XmlNodeType::End)
3616  {
3617  break;
3618  }
3619  else if (node.Type == _internal::XmlNodeType::EndTag)
3620  {
3621  if (path.size() > 0)
3622  {
3623  path.pop_back();
3624  }
3625  else
3626  {
3627  break;
3628  }
3629  }
3630  else if (node.Type == _internal::XmlNodeType::StartTag)
3631  {
3632 
3633  if (std::strcmp(node.Name, "EnumerationResults") == 0)
3634  {
3635  path.emplace_back(XmlTagName::EnumerationResults);
3636  }
3637  else if (std::strcmp(node.Name, "MaxResults") == 0)
3638  {
3639  path.emplace_back(XmlTagName::MaxResults);
3640  }
3641  else if (std::strcmp(node.Name, "NextMarker") == 0)
3642  {
3643  path.emplace_back(XmlTagName::NextMarker);
3644  }
3645  else if (std::strcmp(node.Name, "Prefix") == 0)
3646  {
3647  path.emplace_back(XmlTagName::Prefix);
3648  }
3649  else if (std::strcmp(node.Name, "Share") == 0)
3650  {
3651  path.emplace_back(XmlTagName::Share);
3652  }
3653  else if (std::strcmp(node.Name, "Shares") == 0)
3654  {
3655  path.emplace_back(XmlTagName::Shares);
3656  }
3657  else
3658  {
3659  path.emplace_back(XmlTagName::Unknown);
3660  }
3661  if (path.size() == 3 && path[0] == XmlTagName::EnumerationResults
3662  && path[1] == XmlTagName::Shares && path[2] == XmlTagName::Share)
3663  {
3664  result.Items.emplace_back(ShareItemFromXml(reader));
3665  path.pop_back();
3666  }
3667  }
3668  else if (node.Type == _internal::XmlNodeType::Text)
3669  {
3670  if (path.size() == 2 && path[0] == XmlTagName::EnumerationResults
3671  && path[1] == XmlTagName::NextMarker)
3672  {
3673  result.ContinuationToken = node.Value;
3674  }
3675  else if (
3676  path.size() == 2 && path[0] == XmlTagName::EnumerationResults
3677  && path[1] == XmlTagName::MaxResults)
3678  {
3679  result.PageSizeHint = std::stoi(node.Value);
3680  }
3681  else if (
3682  path.size() == 2 && path[0] == XmlTagName::EnumerationResults
3683  && path[1] == XmlTagName::Prefix)
3684  {
3685  result.Prefix = node.Value;
3686  }
3687  }
3688  else if (node.Type == _internal::XmlNodeType::Attribute)
3689  {
3690  if (path.size() == 1 && path[0] == XmlTagName::EnumerationResults
3691  && (std::strcmp(node.Name, "ServiceEndpoint") == 0))
3692  {
3693  result.ServiceEndpoint = node.Value;
3694  }
3695  }
3696  }
3697  return result;
3698  }
3699 
3700  static ServiceListSharesSinglePageResult
3701  ServiceListSharesSinglePageResultFromListSharesResponse(ListSharesResponse object)
3702  {
3703  ServiceListSharesSinglePageResult result;
3704  result.ServiceEndpoint = std::move(object.ServiceEndpoint);
3705  result.Prefix = std::move(object.Prefix);
3706  result.PageSizeHint = object.PageSizeHint;
3707  result.Items = std::move(object.Items);
3708  result.ContinuationToken = std::move(object.ContinuationToken);
3709 
3710  return result;
3711  }
3712  };
3713 
3714  class Share final {
3715  public:
3716  struct CreateOptions final
3717  {
3718  Azure::Nullable<int32_t> Timeout;
3719  Storage::Metadata Metadata;
3720  Azure::Nullable<int64_t> ShareQuota;
3721  Azure::Nullable<AccessTier> XMsAccessTier;
3722  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
3723  };
3724 
3725  static Azure::Response<Models::CreateShareResult> Create(
3726  const Azure::Core::Url& url,
3727  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3728  Azure::Core::Context context,
3729  const CreateOptions& createOptions)
3730  {
3731  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
3732  request.SetHeader(_detail::HeaderContentLength, "0");
3733  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
3734  if (createOptions.Timeout.HasValue())
3735  {
3736  request.GetUrl().AppendQueryParameter(
3737  _detail::QueryTimeout,
3738  _internal::UrlEncodeQueryParameter(std::to_string(createOptions.Timeout.Value())));
3739  }
3740  for (const auto& pair : createOptions.Metadata)
3741  {
3742  request.SetHeader(_detail::HeaderMetadata + ("-" + pair.first), pair.second);
3743  }
3744  if (createOptions.ShareQuota.HasValue())
3745  {
3746  request.SetHeader(
3747  _detail::HeaderQuota, std::to_string(createOptions.ShareQuota.Value()));
3748  }
3749  if (createOptions.XMsAccessTier.HasValue())
3750  {
3751  request.SetHeader(
3752  _detail::HeaderAccessTier, createOptions.XMsAccessTier.Value().ToString());
3753  }
3754  request.SetHeader(_detail::HeaderVersion, createOptions.ApiVersionParameter);
3755  return CreateParseResult(context, pipeline.Send(request, context));
3756  }
3757 
3758  struct GetPropertiesOptions final
3759  {
3760  Azure::Nullable<std::string> ShareSnapshot;
3761  Azure::Nullable<int32_t> Timeout;
3762  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
3763  Azure::Nullable<std::string> LeaseIdOptional;
3764  };
3765 
3766  static Azure::Response<Models::ShareProperties> GetProperties(
3767  const Azure::Core::Url& url,
3768  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3769  Azure::Core::Context context,
3770  const GetPropertiesOptions& getPropertiesOptions)
3771  {
3772  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
3773  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
3774  if (getPropertiesOptions.ShareSnapshot.HasValue())
3775  {
3776  request.GetUrl().AppendQueryParameter(
3777  _detail::QueryShareSnapshot,
3778  _internal::UrlEncodeQueryParameter(getPropertiesOptions.ShareSnapshot.Value()));
3779  }
3780  if (getPropertiesOptions.Timeout.HasValue())
3781  {
3782  request.GetUrl().AppendQueryParameter(
3783  _detail::QueryTimeout,
3784  _internal::UrlEncodeQueryParameter(
3785  std::to_string(getPropertiesOptions.Timeout.Value())));
3786  }
3787  request.SetHeader(_detail::HeaderVersion, getPropertiesOptions.ApiVersionParameter);
3788  if (getPropertiesOptions.LeaseIdOptional.HasValue())
3789  {
3790  request.SetHeader(_detail::HeaderLeaseId, getPropertiesOptions.LeaseIdOptional.Value());
3791  }
3792  return GetPropertiesParseResult(context, pipeline.Send(request, context));
3793  }
3794 
3795  struct DeleteOptions final
3796  {
3797  Azure::Nullable<std::string> ShareSnapshot;
3798  Azure::Nullable<int32_t> Timeout;
3799  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
3800  Azure::Nullable<DeleteSnapshotsOption> XMsDeleteSnapshots;
3801  Azure::Nullable<std::string> LeaseIdOptional;
3802  };
3803 
3804  static Azure::Response<Models::DeleteShareResult> Delete(
3805  const Azure::Core::Url& url,
3806  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3807  Azure::Core::Context context,
3808  const DeleteOptions& deleteOptions)
3809  {
3810  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Delete, url);
3811  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
3812  if (deleteOptions.ShareSnapshot.HasValue())
3813  {
3814  request.GetUrl().AppendQueryParameter(
3815  _detail::QueryShareSnapshot,
3816  _internal::UrlEncodeQueryParameter(deleteOptions.ShareSnapshot.Value()));
3817  }
3818  if (deleteOptions.Timeout.HasValue())
3819  {
3820  request.GetUrl().AppendQueryParameter(
3821  _detail::QueryTimeout,
3822  _internal::UrlEncodeQueryParameter(std::to_string(deleteOptions.Timeout.Value())));
3823  }
3824  request.SetHeader(_detail::HeaderVersion, deleteOptions.ApiVersionParameter);
3825  if (deleteOptions.XMsDeleteSnapshots.HasValue())
3826  {
3827  request.SetHeader(
3828  _detail::HeaderDeleteSnapshots,
3829  deleteOptions.XMsDeleteSnapshots.Value().ToString());
3830  }
3831  if (deleteOptions.LeaseIdOptional.HasValue())
3832  {
3833  request.SetHeader(_detail::HeaderLeaseId, deleteOptions.LeaseIdOptional.Value());
3834  }
3835  return DeleteParseResult(context, pipeline.Send(request, context));
3836  }
3837 
3838  struct AcquireLeaseOptions final
3839  {
3840  Azure::Nullable<int32_t> Timeout;
3841  int32_t LeaseDuration = int32_t();
3842  Azure::Nullable<std::string> ProposedLeaseIdOptional;
3843  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
3844  Azure::Nullable<std::string> ShareSnapshot;
3845  };
3846 
3847  static Azure::Response<Models::AcquireLeaseResult> AcquireLease(
3848  const Azure::Core::Url& url,
3849  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3850  Azure::Core::Context context,
3851  const AcquireLeaseOptions& acquireLeaseOptions)
3852  {
3853  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
3854  request.SetHeader(_detail::HeaderContentLength, "0");
3855  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
3856  request.SetHeader(_detail::HeaderAction, "acquire");
3857  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
3858  if (acquireLeaseOptions.Timeout.HasValue())
3859  {
3860  request.GetUrl().AppendQueryParameter(
3861  _detail::QueryTimeout,
3862  _internal::UrlEncodeQueryParameter(
3863  std::to_string(acquireLeaseOptions.Timeout.Value())));
3864  }
3865  request.SetHeader(
3866  _detail::HeaderDuration, std::to_string(acquireLeaseOptions.LeaseDuration));
3867  if (acquireLeaseOptions.ProposedLeaseIdOptional.HasValue())
3868  {
3869  request.SetHeader(
3870  _detail::HeaderProposedLeaseId,
3871  acquireLeaseOptions.ProposedLeaseIdOptional.Value());
3872  }
3873  request.SetHeader(_detail::HeaderVersion, acquireLeaseOptions.ApiVersionParameter);
3874  if (acquireLeaseOptions.ShareSnapshot.HasValue())
3875  {
3876  request.GetUrl().AppendQueryParameter(
3877  _detail::QueryShareSnapshot,
3878  _internal::UrlEncodeQueryParameter(acquireLeaseOptions.ShareSnapshot.Value()));
3879  }
3880  return AcquireLeaseParseResult(context, pipeline.Send(request, context));
3881  }
3882 
3883  struct ReleaseLeaseOptions final
3884  {
3885  Azure::Nullable<int32_t> Timeout;
3886  std::string LeaseIdRequired;
3887  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
3888  Azure::Nullable<std::string> ShareSnapshot;
3889  };
3890 
3891  static Azure::Response<Models::ReleaseLeaseResult> ReleaseLease(
3892  const Azure::Core::Url& url,
3893  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3894  Azure::Core::Context context,
3895  const ReleaseLeaseOptions& releaseLeaseOptions)
3896  {
3897  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
3898  request.SetHeader(_detail::HeaderContentLength, "0");
3899  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
3900  request.SetHeader(_detail::HeaderAction, "release");
3901  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
3902  if (releaseLeaseOptions.Timeout.HasValue())
3903  {
3904  request.GetUrl().AppendQueryParameter(
3905  _detail::QueryTimeout,
3906  _internal::UrlEncodeQueryParameter(
3907  std::to_string(releaseLeaseOptions.Timeout.Value())));
3908  }
3909  request.SetHeader(_detail::HeaderLeaseId, releaseLeaseOptions.LeaseIdRequired);
3910  request.SetHeader(_detail::HeaderVersion, releaseLeaseOptions.ApiVersionParameter);
3911  if (releaseLeaseOptions.ShareSnapshot.HasValue())
3912  {
3913  request.GetUrl().AppendQueryParameter(
3914  _detail::QueryShareSnapshot,
3915  _internal::UrlEncodeQueryParameter(releaseLeaseOptions.ShareSnapshot.Value()));
3916  }
3917  return ReleaseLeaseParseResult(context, pipeline.Send(request, context));
3918  }
3919 
3920  struct ChangeLeaseOptions final
3921  {
3922  Azure::Nullable<int32_t> Timeout;
3923  std::string LeaseIdRequired;
3924  Azure::Nullable<std::string> ProposedLeaseIdOptional;
3925  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
3926  Azure::Nullable<std::string> ShareSnapshot;
3927  };
3928 
3929  static Azure::Response<Models::ChangeLeaseResult> ChangeLease(
3930  const Azure::Core::Url& url,
3931  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3932  Azure::Core::Context context,
3933  const ChangeLeaseOptions& changeLeaseOptions)
3934  {
3935  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
3936  request.SetHeader(_detail::HeaderContentLength, "0");
3937  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
3938  request.SetHeader(_detail::HeaderAction, "change");
3939  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
3940  if (changeLeaseOptions.Timeout.HasValue())
3941  {
3942  request.GetUrl().AppendQueryParameter(
3943  _detail::QueryTimeout,
3944  _internal::UrlEncodeQueryParameter(
3945  std::to_string(changeLeaseOptions.Timeout.Value())));
3946  }
3947  request.SetHeader(_detail::HeaderLeaseId, changeLeaseOptions.LeaseIdRequired);
3948  if (changeLeaseOptions.ProposedLeaseIdOptional.HasValue())
3949  {
3950  request.SetHeader(
3951  _detail::HeaderProposedLeaseId, changeLeaseOptions.ProposedLeaseIdOptional.Value());
3952  }
3953  request.SetHeader(_detail::HeaderVersion, changeLeaseOptions.ApiVersionParameter);
3954  if (changeLeaseOptions.ShareSnapshot.HasValue())
3955  {
3956  request.GetUrl().AppendQueryParameter(
3957  _detail::QueryShareSnapshot,
3958  _internal::UrlEncodeQueryParameter(changeLeaseOptions.ShareSnapshot.Value()));
3959  }
3960  return ChangeLeaseParseResult(context, pipeline.Send(request, context));
3961  }
3962 
3963  struct RenewLeaseOptions final
3964  {
3965  Azure::Nullable<int32_t> Timeout;
3966  std::string LeaseIdRequired;
3967  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
3968  Azure::Nullable<std::string> ShareSnapshot;
3969  };
3970 
3971  static Azure::Response<Models::RenewLeaseResult> RenewLease(
3972  const Azure::Core::Url& url,
3973  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3974  Azure::Core::Context context,
3975  const RenewLeaseOptions& renewLeaseOptions)
3976  {
3977  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
3978  request.SetHeader(_detail::HeaderContentLength, "0");
3979  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
3980  request.SetHeader(_detail::HeaderAction, "renew");
3981  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
3982  if (renewLeaseOptions.Timeout.HasValue())
3983  {
3984  request.GetUrl().AppendQueryParameter(
3985  _detail::QueryTimeout,
3986  _internal::UrlEncodeQueryParameter(
3987  std::to_string(renewLeaseOptions.Timeout.Value())));
3988  }
3989  request.SetHeader(_detail::HeaderLeaseId, renewLeaseOptions.LeaseIdRequired);
3990  request.SetHeader(_detail::HeaderVersion, renewLeaseOptions.ApiVersionParameter);
3991  if (renewLeaseOptions.ShareSnapshot.HasValue())
3992  {
3993  request.GetUrl().AppendQueryParameter(
3994  _detail::QueryShareSnapshot,
3995  _internal::UrlEncodeQueryParameter(renewLeaseOptions.ShareSnapshot.Value()));
3996  }
3997  return RenewLeaseParseResult(context, pipeline.Send(request, context));
3998  }
3999 
4000  struct BreakLeaseOptions final
4001  {
4002  Azure::Nullable<int32_t> Timeout;
4003  Azure::Nullable<int32_t> LeaseBreakPeriod;
4004  Azure::Nullable<std::string> LeaseIdOptional;
4005  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4006  Azure::Nullable<std::string> ShareSnapshot;
4007  };
4008 
4009  static Azure::Response<Models::BreakLeaseResult> BreakLease(
4010  const Azure::Core::Url& url,
4011  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4012  Azure::Core::Context context,
4013  const BreakLeaseOptions& breakLeaseOptions)
4014  {
4015  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
4016  request.SetHeader(_detail::HeaderContentLength, "0");
4017  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
4018  request.SetHeader(_detail::HeaderAction, "break");
4019  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4020  if (breakLeaseOptions.Timeout.HasValue())
4021  {
4022  request.GetUrl().AppendQueryParameter(
4023  _detail::QueryTimeout,
4024  _internal::UrlEncodeQueryParameter(
4025  std::to_string(breakLeaseOptions.Timeout.Value())));
4026  }
4027  if (breakLeaseOptions.LeaseBreakPeriod.HasValue())
4028  {
4029  request.SetHeader(
4030  _detail::HeaderBreakPeriod,
4031  std::to_string(breakLeaseOptions.LeaseBreakPeriod.Value()));
4032  }
4033  if (breakLeaseOptions.LeaseIdOptional.HasValue())
4034  {
4035  request.SetHeader(_detail::HeaderLeaseId, breakLeaseOptions.LeaseIdOptional.Value());
4036  }
4037  request.SetHeader(_detail::HeaderVersion, breakLeaseOptions.ApiVersionParameter);
4038  if (breakLeaseOptions.ShareSnapshot.HasValue())
4039  {
4040  request.GetUrl().AppendQueryParameter(
4041  _detail::QueryShareSnapshot,
4042  _internal::UrlEncodeQueryParameter(breakLeaseOptions.ShareSnapshot.Value()));
4043  }
4044  return BreakLeaseParseResult(context, pipeline.Send(request, context));
4045  }
4046 
4047  struct CreateSnapshotOptions final
4048  {
4049  Azure::Nullable<int32_t> Timeout;
4050  Storage::Metadata Metadata;
4051  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4052  };
4053 
4054  static Azure::Response<Models::CreateShareSnapshotResult> CreateSnapshot(
4055  const Azure::Core::Url& url,
4056  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4057  Azure::Core::Context context,
4058  const CreateSnapshotOptions& createSnapshotOptions)
4059  {
4060  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
4061  request.SetHeader(_detail::HeaderContentLength, "0");
4062  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4063  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "snapshot");
4064  if (createSnapshotOptions.Timeout.HasValue())
4065  {
4066  request.GetUrl().AppendQueryParameter(
4067  _detail::QueryTimeout,
4068  _internal::UrlEncodeQueryParameter(
4069  std::to_string(createSnapshotOptions.Timeout.Value())));
4070  }
4071  for (const auto& pair : createSnapshotOptions.Metadata)
4072  {
4073  request.SetHeader(_detail::HeaderMetadata + ("-" + pair.first), pair.second);
4074  }
4075  request.SetHeader(_detail::HeaderVersion, createSnapshotOptions.ApiVersionParameter);
4076  return CreateSnapshotParseResult(context, pipeline.Send(request, context));
4077  }
4078 
4079  struct CreatePermissionOptions final
4080  {
4081  Azure::Nullable<int32_t> Timeout;
4082  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4083  SharePermission Permission;
4084  };
4085 
4086  static Azure::Response<Models::CreateSharePermissionResult> CreatePermission(
4087  const Azure::Core::Url& url,
4088  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4089  Azure::Core::Context context,
4090  const CreatePermissionOptions& createPermissionOptions)
4091  {
4092 
4093  std::string json_body;
4094  {
4095  Azure::Core::Json::_internal::json json;
4096  SharePermissionToJson(json, createPermissionOptions.Permission);
4097  json_body = json.dump();
4098  }
4099  auto body = Azure::Core::IO::MemoryBodyStream(
4100  reinterpret_cast<const uint8_t*>(json_body.data()), json_body.length());
4101  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url, &body);
4102  request.SetHeader("Content-Length", std::to_string(body.Length()));
4103  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4104  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "filepermission");
4105  if (createPermissionOptions.Timeout.HasValue())
4106  {
4107  request.GetUrl().AppendQueryParameter(
4108  _detail::QueryTimeout,
4109  _internal::UrlEncodeQueryParameter(
4110  std::to_string(createPermissionOptions.Timeout.Value())));
4111  }
4112  request.SetHeader(_detail::HeaderVersion, createPermissionOptions.ApiVersionParameter);
4113  return CreatePermissionParseResult(context, pipeline.Send(request, context));
4114  }
4115 
4116  struct GetPermissionOptions final
4117  {
4118  std::string FilePermissionKeyRequired;
4119  Azure::Nullable<int32_t> Timeout;
4120  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4121  };
4122 
4123  static Azure::Response<ShareGetPermissionResult> GetPermission(
4124  const Azure::Core::Url& url,
4125  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4126  Azure::Core::Context context,
4127  const GetPermissionOptions& getPermissionOptions)
4128  {
4129  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
4130  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4131  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "filepermission");
4132  request.SetHeader(
4133  _detail::HeaderFilePermissionKey, getPermissionOptions.FilePermissionKeyRequired);
4134  if (getPermissionOptions.Timeout.HasValue())
4135  {
4136  request.GetUrl().AppendQueryParameter(
4137  _detail::QueryTimeout,
4138  _internal::UrlEncodeQueryParameter(
4139  std::to_string(getPermissionOptions.Timeout.Value())));
4140  }
4141  request.SetHeader(_detail::HeaderVersion, getPermissionOptions.ApiVersionParameter);
4142  return GetPermissionParseResult(context, pipeline.Send(request, context));
4143  }
4144 
4145  struct SetPropertiesOptions final
4146  {
4147  Azure::Nullable<int32_t> Timeout;
4148  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4149  Azure::Nullable<int64_t> ShareQuota;
4150  Azure::Nullable<AccessTier> XMsAccessTier;
4151  Azure::Nullable<std::string> LeaseIdOptional;
4152  };
4153 
4154  static Azure::Response<Models::SetSharePropertiesResult> SetProperties(
4155  const Azure::Core::Url& url,
4156  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4157  Azure::Core::Context context,
4158  const SetPropertiesOptions& setPropertiesOptions)
4159  {
4160  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
4161  request.SetHeader(_detail::HeaderContentLength, "0");
4162  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4163  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "properties");
4164  if (setPropertiesOptions.Timeout.HasValue())
4165  {
4166  request.GetUrl().AppendQueryParameter(
4167  _detail::QueryTimeout,
4168  _internal::UrlEncodeQueryParameter(
4169  std::to_string(setPropertiesOptions.Timeout.Value())));
4170  }
4171  request.SetHeader(_detail::HeaderVersion, setPropertiesOptions.ApiVersionParameter);
4172  if (setPropertiesOptions.ShareQuota.HasValue())
4173  {
4174  request.SetHeader(
4175  _detail::HeaderQuota, std::to_string(setPropertiesOptions.ShareQuota.Value()));
4176  }
4177  if (setPropertiesOptions.XMsAccessTier.HasValue())
4178  {
4179  request.SetHeader(
4180  _detail::HeaderAccessTier, setPropertiesOptions.XMsAccessTier.Value().ToString());
4181  }
4182  if (setPropertiesOptions.LeaseIdOptional.HasValue())
4183  {
4184  request.SetHeader(_detail::HeaderLeaseId, setPropertiesOptions.LeaseIdOptional.Value());
4185  }
4186  return SetPropertiesParseResult(context, pipeline.Send(request, context));
4187  }
4188 
4189  struct SetMetadataOptions final
4190  {
4191  Azure::Nullable<int32_t> Timeout;
4192  Storage::Metadata Metadata;
4193  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4194  Azure::Nullable<std::string> LeaseIdOptional;
4195  };
4196 
4197  static Azure::Response<Models::SetShareMetadataResult> SetMetadata(
4198  const Azure::Core::Url& url,
4199  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4200  Azure::Core::Context context,
4201  const SetMetadataOptions& setMetadataOptions)
4202  {
4203  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
4204  request.SetHeader(_detail::HeaderContentLength, "0");
4205  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4206  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "metadata");
4207  if (setMetadataOptions.Timeout.HasValue())
4208  {
4209  request.GetUrl().AppendQueryParameter(
4210  _detail::QueryTimeout,
4211  _internal::UrlEncodeQueryParameter(
4212  std::to_string(setMetadataOptions.Timeout.Value())));
4213  }
4214  for (const auto& pair : setMetadataOptions.Metadata)
4215  {
4216  request.SetHeader(_detail::HeaderMetadata + ("-" + pair.first), pair.second);
4217  }
4218  request.SetHeader(_detail::HeaderVersion, setMetadataOptions.ApiVersionParameter);
4219  if (setMetadataOptions.LeaseIdOptional.HasValue())
4220  {
4221  request.SetHeader(_detail::HeaderLeaseId, setMetadataOptions.LeaseIdOptional.Value());
4222  }
4223  return SetMetadataParseResult(context, pipeline.Send(request, context));
4224  }
4225 
4226  struct GetAccessPolicyOptions final
4227  {
4228  Azure::Nullable<int32_t> Timeout;
4229  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4230  Azure::Nullable<std::string> LeaseIdOptional;
4231  };
4232 
4233  static Azure::Response<Models::ShareAccessPolicy> GetAccessPolicy(
4234  const Azure::Core::Url& url,
4235  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4236  Azure::Core::Context context,
4237  const GetAccessPolicyOptions& getAccessPolicyOptions)
4238  {
4239  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
4240  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4241  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "acl");
4242  if (getAccessPolicyOptions.Timeout.HasValue())
4243  {
4244  request.GetUrl().AppendQueryParameter(
4245  _detail::QueryTimeout,
4246  _internal::UrlEncodeQueryParameter(
4247  std::to_string(getAccessPolicyOptions.Timeout.Value())));
4248  }
4249  request.SetHeader(_detail::HeaderVersion, getAccessPolicyOptions.ApiVersionParameter);
4250  if (getAccessPolicyOptions.LeaseIdOptional.HasValue())
4251  {
4252  request.SetHeader(
4253  _detail::HeaderLeaseId, getAccessPolicyOptions.LeaseIdOptional.Value());
4254  }
4255  return GetAccessPolicyParseResult(context, pipeline.Send(request, context));
4256  }
4257 
4258  struct SetAccessPolicyOptions final
4259  {
4260  std::vector<SignedIdentifier> ShareAcl;
4261  Azure::Nullable<int32_t> Timeout;
4262  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4263  Azure::Nullable<std::string> LeaseIdOptional;
4264  };
4265 
4266  static Azure::Response<Models::SetShareAccessPolicyResult> SetAccessPolicy(
4267  const Azure::Core::Url& url,
4268  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4269  Azure::Core::Context context,
4270  const SetAccessPolicyOptions& setAccessPolicyOptions)
4271  {
4272 
4273  std::string xml_body;
4274  {
4275  _internal::XmlWriter writer;
4276  SignedIdentifiersToXml(writer, setAccessPolicyOptions.ShareAcl);
4277  writer.Write(_internal::XmlNode{_internal::XmlNodeType::End});
4278  xml_body = writer.GetDocument();
4279  }
4280  auto body = Azure::Core::IO::MemoryBodyStream(
4281  reinterpret_cast<const uint8_t*>(xml_body.data()), xml_body.length());
4282  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url, &body);
4283  request.SetHeader("Content-Length", std::to_string(body.Length()));
4284  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4285  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "acl");
4286  if (setAccessPolicyOptions.Timeout.HasValue())
4287  {
4288  request.GetUrl().AppendQueryParameter(
4289  _detail::QueryTimeout,
4290  _internal::UrlEncodeQueryParameter(
4291  std::to_string(setAccessPolicyOptions.Timeout.Value())));
4292  }
4293  request.SetHeader(_detail::HeaderVersion, setAccessPolicyOptions.ApiVersionParameter);
4294  if (setAccessPolicyOptions.LeaseIdOptional.HasValue())
4295  {
4296  request.SetHeader(
4297  _detail::HeaderLeaseId, setAccessPolicyOptions.LeaseIdOptional.Value());
4298  }
4299  return SetAccessPolicyParseResult(context, pipeline.Send(request, context));
4300  }
4301 
4302  struct GetStatisticsOptions final
4303  {
4304  Azure::Nullable<int32_t> Timeout;
4305  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4306  Azure::Nullable<std::string> LeaseIdOptional;
4307  };
4308 
4309  static Azure::Response<Models::ShareStatistics> GetStatistics(
4310  const Azure::Core::Url& url,
4311  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4312  Azure::Core::Context context,
4313  const GetStatisticsOptions& getStatisticsOptions)
4314  {
4315  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
4316  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4317  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "stats");
4318  if (getStatisticsOptions.Timeout.HasValue())
4319  {
4320  request.GetUrl().AppendQueryParameter(
4321  _detail::QueryTimeout,
4322  _internal::UrlEncodeQueryParameter(
4323  std::to_string(getStatisticsOptions.Timeout.Value())));
4324  }
4325  request.SetHeader(_detail::HeaderVersion, getStatisticsOptions.ApiVersionParameter);
4326  if (getStatisticsOptions.LeaseIdOptional.HasValue())
4327  {
4328  request.SetHeader(_detail::HeaderLeaseId, getStatisticsOptions.LeaseIdOptional.Value());
4329  }
4330  return GetStatisticsParseResult(context, pipeline.Send(request, context));
4331  }
4332 
4333  struct RestoreOptions final
4334  {
4335  Azure::Nullable<int32_t> Timeout;
4336  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
4337  Azure::Nullable<std::string> DeletedShareName;
4338  Azure::Nullable<std::string> DeletedShareVersion;
4339  };
4340 
4341  static Azure::Response<ShareRestoreResult> Restore(
4342  const Azure::Core::Url& url,
4343  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4344  Azure::Core::Context context,
4345  const RestoreOptions& restoreOptions)
4346  {
4347  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
4348  request.SetHeader(_detail::HeaderContentLength, "0");
4349  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "share");
4350  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "undelete");
4351  if (restoreOptions.Timeout.HasValue())
4352  {
4353  request.GetUrl().AppendQueryParameter(
4354  _detail::QueryTimeout,
4355  _internal::UrlEncodeQueryParameter(std::to_string(restoreOptions.Timeout.Value())));
4356  }
4357  request.SetHeader(_detail::HeaderVersion, restoreOptions.ApiVersionParameter);
4358  if (restoreOptions.DeletedShareName.HasValue())
4359  {
4360  request.SetHeader(
4361  _detail::HeaderDeletedShareName, restoreOptions.DeletedShareName.Value());
4362  }
4363  if (restoreOptions.DeletedShareVersion.HasValue())
4364  {
4365  request.SetHeader(
4366  _detail::HeaderDeletedShareVersion, restoreOptions.DeletedShareVersion.Value());
4367  }
4368  return RestoreParseResult(context, pipeline.Send(request, context));
4369  }
4370 
4371  private:
4372  static Azure::Response<Models::CreateShareResult> CreateParseResult(
4373  Azure::Core::Context context,
4374  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4375  {
4376  auto& response = *responsePtr;
4377  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
4378  {
4379  // Success, Share created.
4380  Models::CreateShareResult result;
4381  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4382  result.LastModified = DateTime::Parse(
4383  response.GetHeaders().at(_detail::HeaderLastModified),
4384  DateTime::DateFormat::Rfc1123);
4385  return Azure::Response<Models::CreateShareResult>(
4386  std::move(result), std::move(responsePtr));
4387  }
4388  else
4389  {
4390  (void)context;
4391  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4392  }
4393  }
4394 
4395  static Azure::Response<Models::ShareProperties> GetPropertiesParseResult(
4396  Azure::Core::Context context,
4397  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4398  {
4399  auto& response = *responsePtr;
4400  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4401  {
4402  // Success
4403  Models::ShareProperties result;
4404 
4405  for (auto i = response.GetHeaders().lower_bound(_detail::HeaderMetadata);
4406  i != response.GetHeaders().end()
4407  && i->first.substr(0, 9) == _detail::HeaderMetadata;
4408  ++i)
4409  {
4410  result.Metadata.emplace(i->first.substr(10), i->second);
4411  }
4412  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4413  result.LastModified = DateTime::Parse(
4414  response.GetHeaders().at(_detail::HeaderLastModified),
4415  DateTime::DateFormat::Rfc1123);
4416  result.Quota = std::stoll(response.GetHeaders().at(_detail::HeaderQuota));
4417  if (response.GetHeaders().find(_detail::HeaderProvisionedIops)
4418  != response.GetHeaders().end())
4419  {
4420  result.ProvisionedIops
4421  = std::stoi(response.GetHeaders().at(_detail::HeaderProvisionedIops));
4422  }
4423  if (response.GetHeaders().find(_detail::HeaderProvisionedIngressMBps)
4424  != response.GetHeaders().end())
4425  {
4426  result.ProvisionedIngressMBps
4427  = std::stoi(response.GetHeaders().at(_detail::HeaderProvisionedIngressMBps));
4428  }
4429  if (response.GetHeaders().find(_detail::HeaderProvisionedEgressMBps)
4430  != response.GetHeaders().end())
4431  {
4432  result.ProvisionedEgressMBps
4433  = std::stoi(response.GetHeaders().at(_detail::HeaderProvisionedEgressMBps));
4434  }
4435  if (response.GetHeaders().find(_detail::HeaderNextAllowedQuotaDowngradeTime)
4436  != response.GetHeaders().end())
4437  {
4438  result.NextAllowedQuotaDowngradeTime = DateTime::Parse(
4439  response.GetHeaders().at(_detail::HeaderNextAllowedQuotaDowngradeTime),
4440  DateTime::DateFormat::Rfc1123);
4441  }
4442  if (response.GetHeaders().find(_detail::HeaderLeaseDuration)
4443  != response.GetHeaders().end())
4444  {
4445  result.LeaseDuration
4446  = LeaseDuration(response.GetHeaders().at(_detail::HeaderLeaseDuration));
4447  }
4448  if (response.GetHeaders().find(_detail::HeaderLeaseState)
4449  != response.GetHeaders().end())
4450  {
4451  result.LeaseState = LeaseState(response.GetHeaders().at(_detail::HeaderLeaseState));
4452  }
4453  if (response.GetHeaders().find(_detail::HeaderLeaseStatus)
4454  != response.GetHeaders().end())
4455  {
4456  result.LeaseStatus
4457  = LeaseStatus(response.GetHeaders().at(_detail::HeaderLeaseStatus));
4458  }
4459  if (response.GetHeaders().find("x-ms-access-tier") != response.GetHeaders().end())
4460  {
4461  result.AccessTier = AccessTier(response.GetHeaders().at("x-ms-access-tier"));
4462  }
4463  if (response.GetHeaders().find(_detail::HeaderAccessTierChangedOn)
4464  != response.GetHeaders().end())
4465  {
4466  result.AccessTierChangedOn = DateTime::Parse(
4467  response.GetHeaders().at(_detail::HeaderAccessTierChangedOn),
4468  DateTime::DateFormat::Rfc1123);
4469  }
4470  if (response.GetHeaders().find(_detail::HeaderAccessTierTransitionState)
4471  != response.GetHeaders().end())
4472  {
4473  result.AccessTierTransitionState
4474  = response.GetHeaders().at(_detail::HeaderAccessTierTransitionState);
4475  }
4476  return Azure::Response<Models::ShareProperties>(
4477  std::move(result), std::move(responsePtr));
4478  }
4479  else
4480  {
4481  (void)context;
4482  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4483  }
4484  }
4485 
4486  static Azure::Response<Models::DeleteShareResult> DeleteParseResult(
4487  Azure::Core::Context context,
4488  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4489  {
4490  auto& response = *responsePtr;
4491  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Accepted)
4492  {
4493  // Accepted
4494  Models::DeleteShareResult result;
4495  return Azure::Response<Models::DeleteShareResult>(
4496  std::move(result), std::move(responsePtr));
4497  }
4498  else
4499  {
4500  (void)context;
4501  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4502  }
4503  }
4504 
4505  static Azure::Response<Models::AcquireLeaseResult> AcquireLeaseParseResult(
4506  Azure::Core::Context context,
4507  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4508  {
4509  auto& response = *responsePtr;
4510  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
4511  {
4512  // The Acquire operation completed successfully.
4513  Models::AcquireLeaseResult result;
4514  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4515  result.LastModified = DateTime::Parse(
4516  response.GetHeaders().at(_detail::HeaderLastModified),
4517  DateTime::DateFormat::Rfc1123);
4518  result.LeaseId = response.GetHeaders().at(_detail::HeaderLeaseId);
4519  return Azure::Response<Models::AcquireLeaseResult>(
4520  std::move(result), std::move(responsePtr));
4521  }
4522  else
4523  {
4524  (void)context;
4525  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4526  }
4527  }
4528 
4529  static Azure::Response<Models::ReleaseLeaseResult> ReleaseLeaseParseResult(
4530  Azure::Core::Context context,
4531  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4532  {
4533  auto& response = *responsePtr;
4534  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4535  {
4536  // The Release operation completed successfully.
4537  Models::ReleaseLeaseResult result;
4538  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4539  result.LastModified = DateTime::Parse(
4540  response.GetHeaders().at(_detail::HeaderLastModified),
4541  DateTime::DateFormat::Rfc1123);
4542  return Azure::Response<Models::ReleaseLeaseResult>(
4543  std::move(result), std::move(responsePtr));
4544  }
4545  else
4546  {
4547  (void)context;
4548  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4549  }
4550  }
4551 
4552  static Azure::Response<Models::ChangeLeaseResult> ChangeLeaseParseResult(
4553  Azure::Core::Context context,
4554  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4555  {
4556  auto& response = *responsePtr;
4557  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4558  {
4559  // The Change operation completed successfully.
4560  Models::ChangeLeaseResult result;
4561  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4562  result.LastModified = DateTime::Parse(
4563  response.GetHeaders().at(_detail::HeaderLastModified),
4564  DateTime::DateFormat::Rfc1123);
4565  result.LeaseId = response.GetHeaders().at(_detail::HeaderLeaseId);
4566  return Azure::Response<Models::ChangeLeaseResult>(
4567  std::move(result), std::move(responsePtr));
4568  }
4569  else
4570  {
4571  (void)context;
4572  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4573  }
4574  }
4575 
4576  static Azure::Response<Models::RenewLeaseResult> RenewLeaseParseResult(
4577  Azure::Core::Context context,
4578  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4579  {
4580  auto& response = *responsePtr;
4581  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4582  {
4583  // The Renew operation completed successfully.
4584  Models::RenewLeaseResult result;
4585  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4586  result.LastModified = DateTime::Parse(
4587  response.GetHeaders().at(_detail::HeaderLastModified),
4588  DateTime::DateFormat::Rfc1123);
4589  result.LeaseId = response.GetHeaders().at(_detail::HeaderLeaseId);
4590  return Azure::Response<Models::RenewLeaseResult>(
4591  std::move(result), std::move(responsePtr));
4592  }
4593  else
4594  {
4595  (void)context;
4596  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4597  }
4598  }
4599 
4600  static Azure::Response<Models::BreakLeaseResult> BreakLeaseParseResult(
4601  Azure::Core::Context context,
4602  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4603  {
4604  auto& response = *responsePtr;
4605  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Accepted)
4606  {
4607  // The Break operation completed successfully.
4608  Models::BreakLeaseResult result;
4609  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4610  result.LastModified = DateTime::Parse(
4611  response.GetHeaders().at(_detail::HeaderLastModified),
4612  DateTime::DateFormat::Rfc1123);
4613  return Azure::Response<Models::BreakLeaseResult>(
4614  std::move(result), std::move(responsePtr));
4615  }
4616  else
4617  {
4618  (void)context;
4619  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4620  }
4621  }
4622 
4623  static Azure::Response<Models::CreateShareSnapshotResult> CreateSnapshotParseResult(
4624  Azure::Core::Context context,
4625  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4626  {
4627  auto& response = *responsePtr;
4628  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
4629  {
4630  // Success, Share snapshot created.
4631  Models::CreateShareSnapshotResult result;
4632  result.Snapshot = response.GetHeaders().at(_detail::HeaderSnapshot);
4633  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4634  result.LastModified = DateTime::Parse(
4635  response.GetHeaders().at(_detail::HeaderLastModified),
4636  DateTime::DateFormat::Rfc1123);
4637  return Azure::Response<Models::CreateShareSnapshotResult>(
4638  std::move(result), std::move(responsePtr));
4639  }
4640  else
4641  {
4642  (void)context;
4643  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4644  }
4645  }
4646 
4647  static Azure::Response<Models::CreateSharePermissionResult> CreatePermissionParseResult(
4648  Azure::Core::Context context,
4649  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4650  {
4651  auto& response = *responsePtr;
4652  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
4653  {
4654  // Success, Share level permission created.
4655  Models::CreateSharePermissionResult result;
4656  result.FilePermissionKey = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
4657  return Azure::Response<Models::CreateSharePermissionResult>(
4658  std::move(result), std::move(responsePtr));
4659  }
4660  else
4661  {
4662  (void)context;
4663  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4664  }
4665  }
4666 
4667  static void SharePermissionToJson(
4668  Azure::Core::Json::_internal::json& node,
4669  const SharePermission& object)
4670  {
4671  node["permission"] = object.FilePermission;
4672  }
4673 
4674  static Azure::Response<ShareGetPermissionResult> GetPermissionParseResult(
4675  Azure::Core::Context context,
4676  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4677  {
4678  auto& response = *responsePtr;
4679  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4680  {
4681  // Success
4682  const auto& bodyBuffer = response.GetBody();
4683  ShareGetPermissionResult result = bodyBuffer.empty()
4684  ? ShareGetPermissionResult()
4685  : ShareGetPermissionResultFromSharePermission(
4686  SharePermissionFromJson(Azure::Core::Json::_internal::json::parse(bodyBuffer)));
4687  return Azure::Response<ShareGetPermissionResult>(
4688  std::move(result), std::move(responsePtr));
4689  }
4690  else
4691  {
4692  (void)context;
4693  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4694  }
4695  }
4696 
4697  static SharePermission SharePermissionFromJson(
4698  const Azure::Core::Json::_internal::json& node)
4699  {
4700  SharePermission result;
4701  result.FilePermission = node["permission"].get<std::string>();
4702  return result;
4703  }
4704 
4705  static ShareGetPermissionResult ShareGetPermissionResultFromSharePermission(
4706  SharePermission object)
4707  {
4708  ShareGetPermissionResult result;
4709  result.FilePermission = std::move(object.FilePermission);
4710 
4711  return result;
4712  }
4713  static Azure::Response<Models::SetSharePropertiesResult> SetPropertiesParseResult(
4714  Azure::Core::Context context,
4715  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4716  {
4717  auto& response = *responsePtr;
4718  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4719  {
4720  // Success
4721  Models::SetSharePropertiesResult result;
4722  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4723  result.LastModified = DateTime::Parse(
4724  response.GetHeaders().at(_detail::HeaderLastModified),
4725  DateTime::DateFormat::Rfc1123);
4726  return Azure::Response<Models::SetSharePropertiesResult>(
4727  std::move(result), std::move(responsePtr));
4728  }
4729  else
4730  {
4731  (void)context;
4732  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4733  }
4734  }
4735 
4736  static Azure::Response<Models::SetShareMetadataResult> SetMetadataParseResult(
4737  Azure::Core::Context context,
4738  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4739  {
4740  auto& response = *responsePtr;
4741  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4742  {
4743  // Success
4744  Models::SetShareMetadataResult result;
4745  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4746  result.LastModified = DateTime::Parse(
4747  response.GetHeaders().at(_detail::HeaderLastModified),
4748  DateTime::DateFormat::Rfc1123);
4749  return Azure::Response<Models::SetShareMetadataResult>(
4750  std::move(result), std::move(responsePtr));
4751  }
4752  else
4753  {
4754  (void)context;
4755  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4756  }
4757  }
4758 
4759  static Azure::Response<Models::ShareAccessPolicy> GetAccessPolicyParseResult(
4760  Azure::Core::Context context,
4761  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4762  {
4763  auto& response = *responsePtr;
4764  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4765  {
4766  // Success
4767  const auto& bodyBuffer = response.GetBody();
4768  auto reader = _internal::XmlReader(
4769  reinterpret_cast<const char*>(bodyBuffer.data()), bodyBuffer.size());
4770  Models::ShareAccessPolicy result = bodyBuffer.empty()
4771  ? Models::ShareAccessPolicy()
4772  : ShareAccessPolicyFromSignedIdentifiers(SignedIdentifiersFromXml(reader));
4773  return Azure::Response<Models::ShareAccessPolicy>(
4774  std::move(result), std::move(responsePtr));
4775  }
4776  else
4777  {
4778  (void)context;
4779  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
4780  }
4781  }
4782 
4783  static AccessPolicy AccessPolicyFromXml(_internal::XmlReader& reader)
4784  {
4785  auto result = AccessPolicy();
4786  enum class XmlTagName
4787  {
4788  Expiry,
4789  Permission,
4790  Start,
4791  Unknown,
4792  };
4793  std::vector<XmlTagName> path;
4794 
4795  while (true)
4796  {
4797  auto node = reader.Read();
4798  if (node.Type == _internal::XmlNodeType::End)
4799  {
4800  break;
4801  }
4802  else if (node.Type == _internal::XmlNodeType::EndTag)
4803  {
4804  if (path.size() > 0)
4805  {
4806  path.pop_back();
4807  }
4808  else
4809  {
4810  break;
4811  }
4812  }
4813  else if (node.Type == _internal::XmlNodeType::StartTag)
4814  {
4815 
4816  if (std::strcmp(node.Name, "Expiry") == 0)
4817  {
4818  path.emplace_back(XmlTagName::Expiry);
4819  }
4820  else if (std::strcmp(node.Name, "Permission") == 0)
4821  {
4822  path.emplace_back(XmlTagName::Permission);
4823  }
4824  else if (std::strcmp(node.Name, "Start") == 0)
4825  {
4826  path.emplace_back(XmlTagName::Start);
4827  }
4828  else
4829  {
4830  path.emplace_back(XmlTagName::Unknown);
4831  }
4832  }
4833  else if (node.Type == _internal::XmlNodeType::Text)
4834  {
4835  if (path.size() == 1 && path[0] == XmlTagName::Expiry)
4836  {
4837  result.ExpiresOn = DateTime::Parse(node.Value, DateTime::DateFormat::Rfc3339);
4838  }
4839  else if (path.size() == 1 && path[0] == XmlTagName::Permission)
4840  {
4841  result.Permission = node.Value;
4842  }
4843  else if (path.size() == 1 && path[0] == XmlTagName::Start)
4844  {
4845  result.StartsOn = DateTime::Parse(node.Value, DateTime::DateFormat::Rfc3339);
4846  }
4847  }
4848  }
4849  return result;
4850  }
4851 
4852  static SignedIdentifier SignedIdentifierFromXml(_internal::XmlReader& reader)
4853  {
4854  auto result = SignedIdentifier();
4855  enum class XmlTagName
4856  {
4857  AccessPolicy,
4858  Id,
4859  Unknown,
4860  };
4861  std::vector<XmlTagName> path;
4862 
4863  while (true)
4864  {
4865  auto node = reader.Read();
4866  if (node.Type == _internal::XmlNodeType::End)
4867  {
4868  break;
4869  }
4870  else if (node.Type == _internal::XmlNodeType::EndTag)
4871  {
4872  if (path.size() > 0)
4873  {
4874  path.pop_back();
4875  }
4876  else
4877  {
4878  break;
4879  }
4880  }
4881  else if (node.Type == _internal::XmlNodeType::StartTag)
4882  {
4883 
4884  if (std::strcmp(node.Name, "AccessPolicy") == 0)
4885  {
4886  path.emplace_back(XmlTagName::AccessPolicy);
4887  }
4888  else if (std::strcmp(node.Name, "Id") == 0)
4889  {
4890  path.emplace_back(XmlTagName::Id);
4891  }
4892  else
4893  {
4894  path.emplace_back(XmlTagName::Unknown);
4895  }
4896 
4897  if (path.size() == 1 && path[0] == XmlTagName::AccessPolicy)
4898  {
4899  result.Policy = AccessPolicyFromXml(reader);
4900  path.pop_back();
4901  }
4902  }
4903  else if (node.Type == _internal::XmlNodeType::Text)
4904  {
4905  if (path.size() == 1 && path[0] == XmlTagName::Id)
4906  {
4907  result.Id = node.Value;
4908  }
4909  }
4910  }
4911  return result;
4912  }
4913 
4914  static std::vector<SignedIdentifier> SignedIdentifiersFromXml(_internal::XmlReader& reader)
4915  {
4916  auto result = std::vector<SignedIdentifier>();
4917  enum class XmlTagName
4918  {
4919  SignedIdentifier,
4920  SignedIdentifiers,
4921  Unknown,
4922  };
4923  std::vector<XmlTagName> path;
4924 
4925  while (true)
4926  {
4927  auto node = reader.Read();
4928  if (node.Type == _internal::XmlNodeType::End)
4929  {
4930  break;
4931  }
4932  else if (node.Type == _internal::XmlNodeType::EndTag)
4933  {
4934  if (path.size() > 0)
4935  {
4936  path.pop_back();
4937  }
4938  else
4939  {
4940  break;
4941  }
4942  }
4943  else if (node.Type == _internal::XmlNodeType::StartTag)
4944  {
4945 
4946  if (std::strcmp(node.Name, "SignedIdentifier") == 0)
4947  {
4948  path.emplace_back(XmlTagName::SignedIdentifier);
4949  }
4950  else if (std::strcmp(node.Name, "SignedIdentifiers") == 0)
4951  {
4952  path.emplace_back(XmlTagName::SignedIdentifiers);
4953  }
4954  else
4955  {
4956  path.emplace_back(XmlTagName::Unknown);
4957  }
4958 
4959  if (path.size() == 2 && path[0] == XmlTagName::SignedIdentifiers
4960  && path[1] == XmlTagName::SignedIdentifier)
4961  {
4962  result.emplace_back(SignedIdentifierFromXml(reader));
4963  path.pop_back();
4964  }
4965  }
4966  else if (node.Type == _internal::XmlNodeType::Text)
4967  {
4968  }
4969  }
4970  return result;
4971  }
4972 
4973  static Models::ShareAccessPolicy ShareAccessPolicyFromSignedIdentifiers(
4974  std::vector<SignedIdentifier> object)
4975  {
4976  Models::ShareAccessPolicy result;
4977  result.SignedIdentifiers = std::move(object);
4978 
4979  return result;
4980  }
4981  static Azure::Response<Models::SetShareAccessPolicyResult> SetAccessPolicyParseResult(
4982  Azure::Core::Context context,
4983  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
4984  {
4985  auto& response = *responsePtr;
4986  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
4987  {
4988  // Success.
4989  Models::SetShareAccessPolicyResult result;
4990  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
4991  result.LastModified = DateTime::Parse(
4992  response.GetHeaders().at(_detail::HeaderLastModified),
4993  DateTime::DateFormat::Rfc1123);
4994  return Azure::Response<Models::SetShareAccessPolicyResult>(
4995  std::move(result), std::move(responsePtr));
4996  }
4997  else
4998  {
4999  (void)context;
5000  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5001  }
5002  }
5003 
5004  static void AccessPolicyToXml(_internal::XmlWriter& writer, const AccessPolicy& object)
5005  {
5006  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AccessPolicy"});
5007  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Start"});
5008  writer.Write(_internal::XmlNode{
5009  _internal::XmlNodeType::Text,
5010  nullptr,
5011  object.StartsOn
5012  .ToString(
5013  Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits)
5014  .data()});
5015  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
5016  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Expiry"});
5017  writer.Write(_internal::XmlNode{
5018  _internal::XmlNodeType::Text,
5019  nullptr,
5020  object.ExpiresOn
5021  .ToString(
5022  Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits)
5023  .data()});
5024  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
5025  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Permission"});
5026  writer.Write(
5027  _internal::XmlNode{_internal::XmlNodeType::Text, nullptr, object.Permission.data()});
5028  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
5029  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
5030  }
5031 
5032  static void SignedIdentifierToXml(
5033  _internal::XmlWriter& writer,
5034  const SignedIdentifier& object)
5035  {
5036  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "SignedIdentifier"});
5037  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Id"});
5038  writer.Write(_internal::XmlNode{_internal::XmlNodeType::Text, nullptr, object.Id.data()});
5039  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
5040  AccessPolicyToXml(writer, object.Policy);
5041  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
5042  }
5043 
5044  static void SignedIdentifiersToXml(
5045  _internal::XmlWriter& writer,
5046  const std::vector<SignedIdentifier>& object)
5047  {
5048  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "SignedIdentifiers"});
5049  for (const auto& item : object)
5050  {
5051  SignedIdentifierToXml(writer, item);
5052  }
5053  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
5054  }
5055  static Azure::Response<Models::ShareStatistics> GetStatisticsParseResult(
5056  Azure::Core::Context context,
5057  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
5058  {
5059  auto& response = *responsePtr;
5060  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
5061  {
5062  // Success
5063  const auto& bodyBuffer = response.GetBody();
5064  auto reader = _internal::XmlReader(
5065  reinterpret_cast<const char*>(bodyBuffer.data()), bodyBuffer.size());
5066  Models::ShareStatistics result = bodyBuffer.empty()
5067  ? Models::ShareStatistics()
5068  : ShareStatisticsFromShareStats(ShareStatsFromXml(reader));
5069  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
5070  result.LastModified = DateTime::Parse(
5071  response.GetHeaders().at(_detail::HeaderLastModified),
5072  DateTime::DateFormat::Rfc1123);
5073  return Azure::Response<Models::ShareStatistics>(
5074  std::move(result), std::move(responsePtr));
5075  }
5076  else
5077  {
5078  (void)context;
5079  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5080  }
5081  }
5082 
5083  static ShareStats ShareStatsFromXml(_internal::XmlReader& reader)
5084  {
5085  auto result = ShareStats();
5086  enum class XmlTagName
5087  {
5088  ShareStats,
5089  ShareUsageBytes,
5090  Unknown,
5091  };
5092  std::vector<XmlTagName> path;
5093 
5094  while (true)
5095  {
5096  auto node = reader.Read();
5097  if (node.Type == _internal::XmlNodeType::End)
5098  {
5099  break;
5100  }
5101  else if (node.Type == _internal::XmlNodeType::EndTag)
5102  {
5103  if (path.size() > 0)
5104  {
5105  path.pop_back();
5106  }
5107  else
5108  {
5109  break;
5110  }
5111  }
5112  else if (node.Type == _internal::XmlNodeType::StartTag)
5113  {
5114 
5115  if (std::strcmp(node.Name, "ShareStats") == 0)
5116  {
5117  path.emplace_back(XmlTagName::ShareStats);
5118  }
5119  else if (std::strcmp(node.Name, "ShareUsageBytes") == 0)
5120  {
5121  path.emplace_back(XmlTagName::ShareUsageBytes);
5122  }
5123  else
5124  {
5125  path.emplace_back(XmlTagName::Unknown);
5126  }
5127  }
5128  else if (node.Type == _internal::XmlNodeType::Text)
5129  {
5130  if (path.size() == 2 && path[0] == XmlTagName::ShareStats
5131  && path[1] == XmlTagName::ShareUsageBytes)
5132  {
5133  result.ShareUsageInBytes = std::stoll(node.Value);
5134  }
5135  }
5136  }
5137  return result;
5138  }
5139 
5140  static Models::ShareStatistics ShareStatisticsFromShareStats(ShareStats object)
5141  {
5142  Models::ShareStatistics result;
5143  result.ShareUsageInBytes = object.ShareUsageInBytes;
5144 
5145  return result;
5146  }
5147  static Azure::Response<ShareRestoreResult> RestoreParseResult(
5148  Azure::Core::Context context,
5149  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
5150  {
5151  auto& response = *responsePtr;
5152  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
5153  {
5154  // Created
5155  ShareRestoreResult result;
5156  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
5157  result.LastModified = DateTime::Parse(
5158  response.GetHeaders().at(_detail::HeaderLastModified),
5159  DateTime::DateFormat::Rfc1123);
5160  return Azure::Response<ShareRestoreResult>(std::move(result), std::move(responsePtr));
5161  }
5162  else
5163  {
5164  (void)context;
5165  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5166  }
5167  }
5168  };
5169 
5170  class Directory final {
5171  public:
5172  struct CreateOptions final
5173  {
5174  Azure::Nullable<int32_t> Timeout;
5175  Storage::Metadata Metadata;
5176  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
5177  Azure::Nullable<std::string> FilePermission;
5178  Azure::Nullable<std::string> FilePermissionKey;
5179  std::string FileAttributes;
5180  std::string FileCreationTime;
5181  std::string FileLastWriteTime;
5182  };
5183 
5184  static Azure::Response<Models::CreateDirectoryResult> Create(
5185  const Azure::Core::Url& url,
5186  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5187  Azure::Core::Context context,
5188  const CreateOptions& createOptions)
5189  {
5190  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
5191  request.SetHeader(_detail::HeaderContentLength, "0");
5192  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "directory");
5193  if (createOptions.Timeout.HasValue())
5194  {
5195  request.GetUrl().AppendQueryParameter(
5196  _detail::QueryTimeout,
5197  _internal::UrlEncodeQueryParameter(std::to_string(createOptions.Timeout.Value())));
5198  }
5199  for (const auto& pair : createOptions.Metadata)
5200  {
5201  request.SetHeader(_detail::HeaderMetadata + ("-" + pair.first), pair.second);
5202  }
5203  request.SetHeader(_detail::HeaderVersion, createOptions.ApiVersionParameter);
5204  if (createOptions.FilePermission.HasValue())
5205  {
5206  request.SetHeader(_detail::HeaderFilePermission, createOptions.FilePermission.Value());
5207  }
5208  if (createOptions.FilePermissionKey.HasValue())
5209  {
5210  request.SetHeader(
5211  _detail::HeaderFilePermissionKey, createOptions.FilePermissionKey.Value());
5212  }
5213  request.SetHeader(_detail::HeaderFileAttributes, createOptions.FileAttributes);
5214  request.SetHeader(_detail::HeaderFileCreatedOn, createOptions.FileCreationTime);
5215  request.SetHeader(_detail::HeaderFileLastWrittenOn, createOptions.FileLastWriteTime);
5216  return CreateParseResult(context, pipeline.Send(request, context));
5217  }
5218 
5219  struct GetPropertiesOptions final
5220  {
5221  Azure::Nullable<std::string> ShareSnapshot;
5222  Azure::Nullable<int32_t> Timeout;
5223  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
5224  };
5225 
5226  static Azure::Response<Models::DirectoryProperties> GetProperties(
5227  const Azure::Core::Url& url,
5228  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5229  Azure::Core::Context context,
5230  const GetPropertiesOptions& getPropertiesOptions)
5231  {
5232  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
5233  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "directory");
5234  if (getPropertiesOptions.ShareSnapshot.HasValue())
5235  {
5236  request.GetUrl().AppendQueryParameter(
5237  _detail::QueryShareSnapshot,
5238  _internal::UrlEncodeQueryParameter(getPropertiesOptions.ShareSnapshot.Value()));
5239  }
5240  if (getPropertiesOptions.Timeout.HasValue())
5241  {
5242  request.GetUrl().AppendQueryParameter(
5243  _detail::QueryTimeout,
5244  _internal::UrlEncodeQueryParameter(
5245  std::to_string(getPropertiesOptions.Timeout.Value())));
5246  }
5247  request.SetHeader(_detail::HeaderVersion, getPropertiesOptions.ApiVersionParameter);
5248  return GetPropertiesParseResult(context, pipeline.Send(request, context));
5249  }
5250 
5251  struct DeleteOptions final
5252  {
5253  Azure::Nullable<int32_t> Timeout;
5254  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
5255  };
5256 
5257  static Azure::Response<Models::DeleteDirectoryResult> Delete(
5258  const Azure::Core::Url& url,
5259  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5260  Azure::Core::Context context,
5261  const DeleteOptions& deleteOptions)
5262  {
5263  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Delete, url);
5264  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "directory");
5265  if (deleteOptions.Timeout.HasValue())
5266  {
5267  request.GetUrl().AppendQueryParameter(
5268  _detail::QueryTimeout,
5269  _internal::UrlEncodeQueryParameter(std::to_string(deleteOptions.Timeout.Value())));
5270  }
5271  request.SetHeader(_detail::HeaderVersion, deleteOptions.ApiVersionParameter);
5272  return DeleteParseResult(context, pipeline.Send(request, context));
5273  }
5274 
5275  struct SetPropertiesOptions final
5276  {
5277  Azure::Nullable<int32_t> Timeout;
5278  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
5279  Azure::Nullable<std::string> FilePermission;
5280  Azure::Nullable<std::string> FilePermissionKey;
5281  std::string FileAttributes;
5282  std::string FileCreationTime;
5283  std::string FileLastWriteTime;
5284  };
5285 
5286  static Azure::Response<Models::SetDirectoryPropertiesResult> SetProperties(
5287  const Azure::Core::Url& url,
5288  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5289  Azure::Core::Context context,
5290  const SetPropertiesOptions& setPropertiesOptions)
5291  {
5292  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
5293  request.SetHeader(_detail::HeaderContentLength, "0");
5294  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "directory");
5295  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "properties");
5296  if (setPropertiesOptions.Timeout.HasValue())
5297  {
5298  request.GetUrl().AppendQueryParameter(
5299  _detail::QueryTimeout,
5300  _internal::UrlEncodeQueryParameter(
5301  std::to_string(setPropertiesOptions.Timeout.Value())));
5302  }
5303  request.SetHeader(_detail::HeaderVersion, setPropertiesOptions.ApiVersionParameter);
5304  if (setPropertiesOptions.FilePermission.HasValue())
5305  {
5306  request.SetHeader(
5307  _detail::HeaderFilePermission, setPropertiesOptions.FilePermission.Value());
5308  }
5309  if (setPropertiesOptions.FilePermissionKey.HasValue())
5310  {
5311  request.SetHeader(
5312  _detail::HeaderFilePermissionKey, setPropertiesOptions.FilePermissionKey.Value());
5313  }
5314  request.SetHeader(_detail::HeaderFileAttributes, setPropertiesOptions.FileAttributes);
5315  request.SetHeader(_detail::HeaderFileCreatedOn, setPropertiesOptions.FileCreationTime);
5316  request.SetHeader(
5317  _detail::HeaderFileLastWrittenOn, setPropertiesOptions.FileLastWriteTime);
5318  return SetPropertiesParseResult(context, pipeline.Send(request, context));
5319  }
5320 
5321  struct SetMetadataOptions final
5322  {
5323  Azure::Nullable<int32_t> Timeout;
5324  Storage::Metadata Metadata;
5325  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
5326  };
5327 
5328  static Azure::Response<Models::SetDirectoryMetadataResult> SetMetadata(
5329  const Azure::Core::Url& url,
5330  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5331  Azure::Core::Context context,
5332  const SetMetadataOptions& setMetadataOptions)
5333  {
5334  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
5335  request.SetHeader(_detail::HeaderContentLength, "0");
5336  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "directory");
5337  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "metadata");
5338  if (setMetadataOptions.Timeout.HasValue())
5339  {
5340  request.GetUrl().AppendQueryParameter(
5341  _detail::QueryTimeout,
5342  _internal::UrlEncodeQueryParameter(
5343  std::to_string(setMetadataOptions.Timeout.Value())));
5344  }
5345  for (const auto& pair : setMetadataOptions.Metadata)
5346  {
5347  request.SetHeader(_detail::HeaderMetadata + ("-" + pair.first), pair.second);
5348  }
5349  request.SetHeader(_detail::HeaderVersion, setMetadataOptions.ApiVersionParameter);
5350  return SetMetadataParseResult(context, pipeline.Send(request, context));
5351  }
5352 
5353  struct ListFilesAndDirectoriesSinglePageOptions final
5354  {
5355  Azure::Nullable<std::string> Prefix;
5356  Azure::Nullable<std::string> ShareSnapshot;
5357  Azure::Nullable<std::string> ContinuationToken;
5358  Azure::Nullable<int32_t> MaxResults;
5359  Azure::Nullable<int32_t> Timeout;
5360  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
5361  };
5362 
5363  static Azure::Response<DirectoryListFilesAndDirectoriesSinglePageResult>
5364  ListFilesAndDirectoriesSinglePage(
5365  const Azure::Core::Url& url,
5366  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5367  Azure::Core::Context context,
5368  const ListFilesAndDirectoriesSinglePageOptions&
5369  listFilesAndDirectoriesSinglePageOptions)
5370  {
5371  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
5372  request.GetUrl().AppendQueryParameter(_detail::QueryRestype, "directory");
5373  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "list");
5374  if (listFilesAndDirectoriesSinglePageOptions.Prefix.HasValue())
5375  {
5376  request.GetUrl().AppendQueryParameter(
5377  _detail::QueryPrefix,
5378  _internal::UrlEncodeQueryParameter(
5379  listFilesAndDirectoriesSinglePageOptions.Prefix.Value()));
5380  }
5381  if (listFilesAndDirectoriesSinglePageOptions.ShareSnapshot.HasValue())
5382  {
5383  request.GetUrl().AppendQueryParameter(
5384  _detail::QueryShareSnapshot,
5385  _internal::UrlEncodeQueryParameter(
5386  listFilesAndDirectoriesSinglePageOptions.ShareSnapshot.Value()));
5387  }
5388  if (listFilesAndDirectoriesSinglePageOptions.ContinuationToken.HasValue())
5389  {
5390  request.GetUrl().AppendQueryParameter(
5391  _detail::QueryContinuationToken,
5392  _internal::UrlEncodeQueryParameter(
5393  listFilesAndDirectoriesSinglePageOptions.ContinuationToken.Value()));
5394  }
5395  if (listFilesAndDirectoriesSinglePageOptions.MaxResults.HasValue())
5396  {
5397  request.GetUrl().AppendQueryParameter(
5398  _detail::QueryPageSizeHint,
5399  _internal::UrlEncodeQueryParameter(
5400  std::to_string(listFilesAndDirectoriesSinglePageOptions.MaxResults.Value())));
5401  }
5402  if (listFilesAndDirectoriesSinglePageOptions.Timeout.HasValue())
5403  {
5404  request.GetUrl().AppendQueryParameter(
5405  _detail::QueryTimeout,
5406  _internal::UrlEncodeQueryParameter(
5407  std::to_string(listFilesAndDirectoriesSinglePageOptions.Timeout.Value())));
5408  }
5409  request.SetHeader(
5410  _detail::HeaderVersion, listFilesAndDirectoriesSinglePageOptions.ApiVersionParameter);
5411  return ListFilesAndDirectoriesSinglePageParseResult(
5412  context, pipeline.Send(request, context));
5413  }
5414 
5415  struct ListHandlesOptions final
5416  {
5417  Azure::Nullable<std::string> ContinuationToken;
5418  Azure::Nullable<int32_t> MaxResults;
5419  Azure::Nullable<int32_t> Timeout;
5420  Azure::Nullable<std::string> ShareSnapshot;
5421  Azure::Nullable<bool> Recursive;
5422  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
5423  };
5424 
5425  static Azure::Response<DirectoryListHandlesResult> ListHandles(
5426  const Azure::Core::Url& url,
5427  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5428  Azure::Core::Context context,
5429  const ListHandlesOptions& listHandlesOptions)
5430  {
5431  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
5432  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "listhandles");
5433  if (listHandlesOptions.ContinuationToken.HasValue())
5434  {
5435  request.GetUrl().AppendQueryParameter(
5436  _detail::QueryContinuationToken,
5437  _internal::UrlEncodeQueryParameter(listHandlesOptions.ContinuationToken.Value()));
5438  }
5439  if (listHandlesOptions.MaxResults.HasValue())
5440  {
5441  request.GetUrl().AppendQueryParameter(
5442  _detail::QueryPageSizeHint,
5443  _internal::UrlEncodeQueryParameter(
5444  std::to_string(listHandlesOptions.MaxResults.Value())));
5445  }
5446  if (listHandlesOptions.Timeout.HasValue())
5447  {
5448  request.GetUrl().AppendQueryParameter(
5449  _detail::QueryTimeout,
5450  _internal::UrlEncodeQueryParameter(
5451  std::to_string(listHandlesOptions.Timeout.Value())));
5452  }
5453  if (listHandlesOptions.ShareSnapshot.HasValue())
5454  {
5455  request.GetUrl().AppendQueryParameter(
5456  _detail::QueryShareSnapshot,
5457  _internal::UrlEncodeQueryParameter(listHandlesOptions.ShareSnapshot.Value()));
5458  }
5459  if (listHandlesOptions.Recursive.HasValue())
5460  {
5461  request.SetHeader(
5462  _detail::HeaderRecursive,
5463  (listHandlesOptions.Recursive.Value() ? "true" : "false"));
5464  }
5465  request.SetHeader(_detail::HeaderVersion, listHandlesOptions.ApiVersionParameter);
5466  return ListHandlesParseResult(context, pipeline.Send(request, context));
5467  }
5468 
5469  struct ForceCloseHandlesOptions final
5470  {
5471  Azure::Nullable<int32_t> Timeout;
5472  Azure::Nullable<std::string> ContinuationToken;
5473  Azure::Nullable<std::string> ShareSnapshot;
5474  std::string HandleId;
5475  Azure::Nullable<bool> Recursive;
5476  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
5477  };
5478 
5479  static Azure::Response<DirectoryForceCloseHandlesResult> ForceCloseHandles(
5480  const Azure::Core::Url& url,
5481  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5482  Azure::Core::Context context,
5483  const ForceCloseHandlesOptions& forceCloseHandlesOptions)
5484  {
5485  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
5486  request.SetHeader(_detail::HeaderContentLength, "0");
5487  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "forceclosehandles");
5488  if (forceCloseHandlesOptions.Timeout.HasValue())
5489  {
5490  request.GetUrl().AppendQueryParameter(
5491  _detail::QueryTimeout,
5492  _internal::UrlEncodeQueryParameter(
5493  std::to_string(forceCloseHandlesOptions.Timeout.Value())));
5494  }
5495  if (forceCloseHandlesOptions.ContinuationToken.HasValue())
5496  {
5497  request.GetUrl().AppendQueryParameter(
5498  _detail::QueryContinuationToken,
5499  _internal::UrlEncodeQueryParameter(
5500  forceCloseHandlesOptions.ContinuationToken.Value()));
5501  }
5502  if (forceCloseHandlesOptions.ShareSnapshot.HasValue())
5503  {
5504  request.GetUrl().AppendQueryParameter(
5505  _detail::QueryShareSnapshot,
5506  _internal::UrlEncodeQueryParameter(forceCloseHandlesOptions.ShareSnapshot.Value()));
5507  }
5508  request.SetHeader(_detail::HeaderHandleId, forceCloseHandlesOptions.HandleId);
5509  if (forceCloseHandlesOptions.Recursive.HasValue())
5510  {
5511  request.SetHeader(
5512  _detail::HeaderRecursive,
5513  (forceCloseHandlesOptions.Recursive.Value() ? "true" : "false"));
5514  }
5515  request.SetHeader(_detail::HeaderVersion, forceCloseHandlesOptions.ApiVersionParameter);
5516  return ForceCloseHandlesParseResult(context, pipeline.Send(request, context));
5517  }
5518 
5519  private:
5520  static Azure::Response<Models::CreateDirectoryResult> CreateParseResult(
5521  Azure::Core::Context context,
5522  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
5523  {
5524  auto& response = *responsePtr;
5525  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
5526  {
5527  // Success, Directory created.
5528  Models::CreateDirectoryResult result;
5529  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
5530  result.LastModified = DateTime::Parse(
5531  response.GetHeaders().at(_detail::HeaderLastModified),
5532  DateTime::DateFormat::Rfc1123);
5533  result.IsServerEncrypted
5534  = response.GetHeaders().at(_detail::HeaderRequestIsServerEncrypted) == "true";
5535  result.SmbProperties.PermissionKey
5536  = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
5537  result.SmbProperties.Attributes
5538  = FileAttributes(response.GetHeaders().at(_detail::HeaderAttributes));
5539  result.SmbProperties.CreatedOn = DateTime::Parse(
5540  response.GetHeaders().at(_detail::HeaderCreatedOn), DateTime::DateFormat::Rfc3339);
5541  result.SmbProperties.LastWrittenOn = DateTime::Parse(
5542  response.GetHeaders().at(_detail::HeaderLastWrittenOn),
5543  DateTime::DateFormat::Rfc3339);
5544  result.SmbProperties.ChangedOn = DateTime::Parse(
5545  response.GetHeaders().at(_detail::HeaderChangedOn), DateTime::DateFormat::Rfc3339);
5546  result.SmbProperties.FileId = response.GetHeaders().at(_detail::HeaderFileId);
5547  result.SmbProperties.ParentFileId
5548  = response.GetHeaders().at(_detail::HeaderParentFileId);
5549  return Azure::Response<Models::CreateDirectoryResult>(
5550  std::move(result), std::move(responsePtr));
5551  }
5552  else
5553  {
5554  (void)context;
5555  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5556  }
5557  }
5558 
5559  static Azure::Response<Models::DirectoryProperties> GetPropertiesParseResult(
5560  Azure::Core::Context context,
5561  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
5562  {
5563  auto& response = *responsePtr;
5564  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
5565  {
5566  // Success.
5567  Models::DirectoryProperties result;
5568 
5569  for (auto i = response.GetHeaders().lower_bound(_detail::HeaderMetadata);
5570  i != response.GetHeaders().end()
5571  && i->first.substr(0, 9) == _detail::HeaderMetadata;
5572  ++i)
5573  {
5574  result.Metadata.emplace(i->first.substr(10), i->second);
5575  }
5576  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
5577  result.LastModified = DateTime::Parse(
5578  response.GetHeaders().at(_detail::HeaderLastModified),
5579  DateTime::DateFormat::Rfc1123);
5580  result.IsServerEncrypted
5581  = response.GetHeaders().at(_detail::HeaderIsServerEncrypted) == "true";
5582  result.SmbProperties.Attributes
5583  = FileAttributes(response.GetHeaders().at(_detail::HeaderAttributes));
5584  result.SmbProperties.CreatedOn = DateTime::Parse(
5585  response.GetHeaders().at(_detail::HeaderCreatedOn), DateTime::DateFormat::Rfc3339);
5586  result.SmbProperties.LastWrittenOn = DateTime::Parse(
5587  response.GetHeaders().at(_detail::HeaderLastWrittenOn),
5588  DateTime::DateFormat::Rfc3339);
5589  result.SmbProperties.ChangedOn = DateTime::Parse(
5590  response.GetHeaders().at(_detail::HeaderChangedOn), DateTime::DateFormat::Rfc3339);
5591  result.SmbProperties.PermissionKey
5592  = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
5593  result.SmbProperties.FileId = response.GetHeaders().at(_detail::HeaderFileId);
5594  result.SmbProperties.ParentFileId
5595  = response.GetHeaders().at(_detail::HeaderParentFileId);
5596  return Azure::Response<Models::DirectoryProperties>(
5597  std::move(result), std::move(responsePtr));
5598  }
5599  else
5600  {
5601  (void)context;
5602  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5603  }
5604  }
5605 
5606  static Azure::Response<Models::DeleteDirectoryResult> DeleteParseResult(
5607  Azure::Core::Context context,
5608  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
5609  {
5610  auto& response = *responsePtr;
5611  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Accepted)
5612  {
5613  // Success (Accepted).
5614  Models::DeleteDirectoryResult result;
5615  return Azure::Response<Models::DeleteDirectoryResult>(
5616  std::move(result), std::move(responsePtr));
5617  }
5618  else
5619  {
5620  (void)context;
5621  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5622  }
5623  }
5624 
5625  static Azure::Response<Models::SetDirectoryPropertiesResult> SetPropertiesParseResult(
5626  Azure::Core::Context context,
5627  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
5628  {
5629  auto& response = *responsePtr;
5630  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
5631  {
5632  // Success
5633  Models::SetDirectoryPropertiesResult result;
5634  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
5635  result.LastModified = DateTime::Parse(
5636  response.GetHeaders().at(_detail::HeaderLastModified),
5637  DateTime::DateFormat::Rfc1123);
5638  result.IsServerEncrypted
5639  = response.GetHeaders().at(_detail::HeaderRequestIsServerEncrypted) == "true";
5640  result.SmbProperties.PermissionKey
5641  = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
5642  result.SmbProperties.Attributes
5643  = FileAttributes(response.GetHeaders().at(_detail::HeaderAttributes));
5644  result.SmbProperties.CreatedOn = DateTime::Parse(
5645  response.GetHeaders().at(_detail::HeaderCreatedOn), DateTime::DateFormat::Rfc3339);
5646  result.SmbProperties.LastWrittenOn = DateTime::Parse(
5647  response.GetHeaders().at(_detail::HeaderLastWrittenOn),
5648  DateTime::DateFormat::Rfc3339);
5649  result.SmbProperties.ChangedOn = DateTime::Parse(
5650  response.GetHeaders().at(_detail::HeaderChangedOn), DateTime::DateFormat::Rfc3339);
5651  result.SmbProperties.FileId = response.GetHeaders().at(_detail::HeaderFileId);
5652  result.SmbProperties.ParentFileId
5653  = response.GetHeaders().at(_detail::HeaderParentFileId);
5654  return Azure::Response<Models::SetDirectoryPropertiesResult>(
5655  std::move(result), std::move(responsePtr));
5656  }
5657  else
5658  {
5659  (void)context;
5660  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5661  }
5662  }
5663 
5664  static Azure::Response<Models::SetDirectoryMetadataResult> SetMetadataParseResult(
5665  Azure::Core::Context context,
5666  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
5667  {
5668  auto& response = *responsePtr;
5669  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
5670  {
5671  // Success (OK).
5672  Models::SetDirectoryMetadataResult result;
5673  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
5674  result.IsServerEncrypted
5675  = response.GetHeaders().at(_detail::HeaderRequestIsServerEncrypted) == "true";
5676  return Azure::Response<Models::SetDirectoryMetadataResult>(
5677  std::move(result), std::move(responsePtr));
5678  }
5679  else
5680  {
5681  (void)context;
5682  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5683  }
5684  }
5685 
5686  static Azure::Response<DirectoryListFilesAndDirectoriesSinglePageResult>
5687  ListFilesAndDirectoriesSinglePageParseResult(
5688  Azure::Core::Context context,
5689  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
5690  {
5691  auto& response = *responsePtr;
5692  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
5693  {
5694  // Success.
5695  const auto& bodyBuffer = response.GetBody();
5696  auto reader = _internal::XmlReader(
5697  reinterpret_cast<const char*>(bodyBuffer.data()), bodyBuffer.size());
5698  DirectoryListFilesAndDirectoriesSinglePageResult result = bodyBuffer.empty()
5699  ? DirectoryListFilesAndDirectoriesSinglePageResult()
5700  : DirectoryListFilesAndDirectoriesSinglePageResultFromListFilesAndDirectoriesSinglePageResponse(
5701  ListFilesAndDirectoriesSinglePageResponseFromXml(reader));
5702  result.HttpHeaders.ContentType = response.GetHeaders().at(_detail::HeaderContentType);
5703  return Azure::Response<DirectoryListFilesAndDirectoriesSinglePageResult>(
5704  std::move(result), std::move(responsePtr));
5705  }
5706  else
5707  {
5708  (void)context;
5709  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
5710  }
5711  }
5712 
5713  static DirectoryItem DirectoryItemFromXml(_internal::XmlReader& reader)
5714  {
5715  auto result = DirectoryItem();
5716  enum class XmlTagName
5717  {
5718  Name,
5719  Unknown,
5720  };
5721  std::vector<XmlTagName> path;
5722 
5723  while (true)
5724  {
5725  auto node = reader.Read();
5726  if (node.Type == _internal::XmlNodeType::End)
5727  {
5728  break;
5729  }
5730  else if (node.Type == _internal::XmlNodeType::EndTag)
5731  {
5732  if (path.size() > 0)
5733  {
5734  path.pop_back();
5735  }
5736  else
5737  {
5738  break;
5739  }
5740  }
5741  else if (node.Type == _internal::XmlNodeType::StartTag)
5742  {
5743 
5744  if (std::strcmp(node.Name, "Name") == 0)
5745  {
5746  path.emplace_back(XmlTagName::Name);
5747  }
5748  else
5749  {
5750  path.emplace_back(XmlTagName::Unknown);
5751  }
5752  }
5753  else if (node.Type == _internal::XmlNodeType::Text)
5754  {
5755  if (path.size() == 1 && path[0] == XmlTagName::Name)
5756  {
5757  result.Name = node.Value;
5758  }
5759  }
5760  }
5761  return result;
5762  }
5763 
5764  static FileItemDetails FileItemDetailsFromXml(_internal::XmlReader& reader)
5765  {
5766  auto result = FileItemDetails();
5767  enum class XmlTagName
5768  {
5769  ContentLength,
5770  Unknown,
5771  };
5772  std::vector<XmlTagName> path;
5773 
5774  while (true)
5775  {
5776  auto node = reader.Read();
5777  if (node.Type == _internal::XmlNodeType::End)
5778  {
5779  break;
5780  }
5781  else if (node.Type == _internal::XmlNodeType::EndTag)
5782  {
5783  if (path.size() > 0)
5784  {
5785  path.pop_back();
5786  }
5787  else
5788  {
5789  break;
5790  }
5791  }
5792  else if (node.Type == _internal::XmlNodeType::StartTag)
5793  {
5794 
5795  if (std::strcmp(node.Name, "Content-Length") == 0)
5796  {
5797  path.emplace_back(XmlTagName::ContentLength);
5798  }
5799  else
5800  {
5801  path.emplace_back(XmlTagName::Unknown);
5802  }
5803  }
5804  else if (node.Type == _internal::XmlNodeType::Text)
5805  {
5806  if (path.size() == 1 && path[0] == XmlTagName::ContentLength)
5807  {
5808  result.FileSize = std::stoll(node.Value);
5809  }
5810  }
5811  }
5812  return result;
5813  }
5814 
5815  static FileItem FileItemFromXml(_internal::XmlReader& reader)
5816  {
5817  auto result = FileItem();
5818  enum class XmlTagName
5819  {
5820  Name,
5821  Properties,
5822  Unknown,
5823  };
5824  std::vector<XmlTagName> path;
5825 
5826  while (true)
5827  {
5828  auto node = reader.Read();
5829  if (node.Type == _internal::XmlNodeType::End)
5830  {
5831  break;
5832  }
5833  else if (node.Type == _internal::XmlNodeType::EndTag)
5834  {
5835  if (path.size() > 0)
5836  {
5837  path.pop_back();
5838  }
5839  else
5840  {
5841  break;
5842  }
5843  }
5844  else if (node.Type == _internal::XmlNodeType::StartTag)
5845  {
5846 
5847  if (std::strcmp(node.Name, "Name") == 0)
5848  {
5849  path.emplace_back(XmlTagName::Name);
5850  }
5851  else if (std::strcmp(node.Name, "Properties") == 0)
5852  {
5853  path.emplace_back(XmlTagName::Properties);
5854  }
5855  else
5856  {
5857  path.emplace_back(XmlTagName::Unknown);
5858  }
5859 
5860  if (path.size() == 1 && path[0] == XmlTagName::Properties)
5861  {
5862  result.Details = FileItemDetailsFromXml(reader);
5863  path.pop_back();
5864  }
5865  }
5866  else if (node.Type == _internal::XmlNodeType::Text)
5867  {
5868  if (path.size() == 1 && path[0] == XmlTagName::Name)
5869  {
5870  result.Name = node.Value;
5871  }
5872  }
5873  }
5874  return result;
5875  }
5876 
5877  static FilesAndDirectoriesListSinglePage FilesAndDirectoriesListSinglePageFromXml(
5878  _internal::XmlReader& reader)
5879  {
5880  auto result = FilesAndDirectoriesListSinglePage();
5881  enum class XmlTagName
5882  {
5883  Directory,
5884  File,
5885  Unknown,
5886  };
5887  std::vector<XmlTagName> path;
5888 
5889  while (true)
5890  {
5891  auto node = reader.Read();
5892  if (node.Type == _internal::XmlNodeType::End)
5893  {
5894  break;
5895  }
5896  else if (node.Type == _internal::XmlNodeType::EndTag)
5897  {
5898  if (path.size() > 0)
5899  {
5900  path.pop_back();
5901  }
5902  else
5903  {
5904  break;
5905  }
5906  }
5907  else if (node.Type == _internal::XmlNodeType::StartTag)
5908  {
5909 
5910  if (std::strcmp(node.Name, "Directory") == 0)
5911  {
5912  path.emplace_back(XmlTagName::Directory);
5913  }
5914  else if (std::strcmp(node.Name, "File") == 0)
5915  {
5916  path.emplace_back(XmlTagName::File);
5917  }
5918  else
5919  {
5920  path.emplace_back(XmlTagName::Unknown);
5921  }
5922  if (path.size() == 1 && path[0] == XmlTagName::Directory)
5923  {
5924  result.DirectoryItems.emplace_back(DirectoryItemFromXml(reader));
5925  path.pop_back();
5926  }
5927  else if (path.size() == 1 && path[0] == XmlTagName::File)
5928  {
5929  result.FileItems.emplace_back(FileItemFromXml(reader));
5930  path.pop_back();
5931  }
5932  }
5933  else if (node.Type == _internal::XmlNodeType::Text)
5934  {
5935  }
5936  }
5937  return result;
5938  }
5939 
5940  static ListFilesAndDirectoriesSinglePageResponse
5941  ListFilesAndDirectoriesSinglePageResponseFromXml(_internal::XmlReader& reader)
5942  {
5943  auto result = ListFilesAndDirectoriesSinglePageResponse();
5944  enum class XmlTagName
5945  {
5946  Entries,
5947  EnumerationResults,
5948  MaxResults,
5949  NextMarker,
5950  Prefix,
5951  Unknown,
5952  };
5953  std::vector<XmlTagName> path;
5954 
5955  while (true)
5956  {
5957  auto node = reader.Read();
5958  if (node.Type == _internal::XmlNodeType::End)
5959  {
5960  break;
5961  }
5962  else if (node.Type == _internal::XmlNodeType::EndTag)
5963  {
5964  if (path.size() > 0)
5965  {
5966  path.pop_back();
5967  }
5968  else
5969  {
5970  break;
5971  }
5972  }
5973  else if (node.Type == _internal::XmlNodeType::StartTag)
5974  {
5975 
5976  if (std::strcmp(node.Name, "Entries") == 0)
5977  {
5978  path.emplace_back(XmlTagName::Entries);
5979  }
5980  else if (std::strcmp(node.Name, "EnumerationResults") == 0)
5981  {
5982  path.emplace_back(XmlTagName::EnumerationResults);
5983  }
5984  else if (std::strcmp(node.Name, "MaxResults") == 0)
5985  {
5986  path.emplace_back(XmlTagName::MaxResults);
5987  }
5988  else if (std::strcmp(node.Name, "NextMarker") == 0)
5989  {
5990  path.emplace_back(XmlTagName::NextMarker);
5991  }
5992  else if (std::strcmp(node.Name, "Prefix") == 0)
5993  {
5994  path.emplace_back(XmlTagName::Prefix);
5995  }
5996  else
5997  {
5998  path.emplace_back(XmlTagName::Unknown);
5999  }
6000 
6001  if (path.size() == 2 && path[0] == XmlTagName::EnumerationResults
6002  && path[1] == XmlTagName::Entries)
6003  {
6004  result.SinglePage = FilesAndDirectoriesListSinglePageFromXml(reader);
6005  path.pop_back();
6006  }
6007  }
6008  else if (node.Type == _internal::XmlNodeType::Text)
6009  {
6010  if (path.size() == 2 && path[0] == XmlTagName::EnumerationResults
6011  && path[1] == XmlTagName::NextMarker)
6012  {
6013  result.ContinuationToken = node.Value;
6014  }
6015  else if (
6016  path.size() == 2 && path[0] == XmlTagName::EnumerationResults
6017  && path[1] == XmlTagName::MaxResults)
6018  {
6019  result.PageSizeHint = std::stoi(node.Value);
6020  }
6021  else if (
6022  path.size() == 2 && path[0] == XmlTagName::EnumerationResults
6023  && path[1] == XmlTagName::Prefix)
6024  {
6025  result.Prefix = node.Value;
6026  }
6027  }
6028  else if (node.Type == _internal::XmlNodeType::Attribute)
6029  {
6030  if (path.size() == 1 && path[0] == XmlTagName::EnumerationResults
6031  && (std::strcmp(node.Name, "DirectoryPath") == 0))
6032  {
6033  result.DirectoryPath = node.Value;
6034  }
6035  else if (
6036  path.size() == 1 && path[0] == XmlTagName::EnumerationResults
6037  && (std::strcmp(node.Name, "ServiceEndpoint") == 0))
6038  {
6039  result.ServiceEndpoint = node.Value;
6040  }
6041  else if (
6042  path.size() == 1 && path[0] == XmlTagName::EnumerationResults
6043  && (std::strcmp(node.Name, "ShareName") == 0))
6044  {
6045  result.ShareName = node.Value;
6046  }
6047  else if (
6048  path.size() == 1 && path[0] == XmlTagName::EnumerationResults
6049  && (std::strcmp(node.Name, "ShareSnapshot") == 0))
6050  {
6051  result.ShareSnapshot = node.Value;
6052  }
6053  }
6054  }
6055  return result;
6056  }
6057 
6058  static DirectoryListFilesAndDirectoriesSinglePageResult
6059  DirectoryListFilesAndDirectoriesSinglePageResultFromListFilesAndDirectoriesSinglePageResponse(
6060  ListFilesAndDirectoriesSinglePageResponse object)
6061  {
6062  DirectoryListFilesAndDirectoriesSinglePageResult result;
6063  result.ServiceEndpoint = std::move(object.ServiceEndpoint);
6064  result.ShareName = std::move(object.ShareName);
6065  result.ShareSnapshot = std::move(object.ShareSnapshot);
6066  result.DirectoryPath = std::move(object.DirectoryPath);
6067  result.Prefix = std::move(object.Prefix);
6068  result.PageSizeHint = object.PageSizeHint;
6069  result.SinglePage = std::move(object.SinglePage);
6070  result.ContinuationToken = std::move(object.ContinuationToken);
6071 
6072  return result;
6073  }
6074  static Azure::Response<DirectoryListHandlesResult> ListHandlesParseResult(
6075  Azure::Core::Context context,
6076  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
6077  {
6078  auto& response = *responsePtr;
6079  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
6080  {
6081  // Success.
6082  const auto& bodyBuffer = response.GetBody();
6083  auto reader = _internal::XmlReader(
6084  reinterpret_cast<const char*>(bodyBuffer.data()), bodyBuffer.size());
6085  DirectoryListHandlesResult result = bodyBuffer.empty()
6086  ? DirectoryListHandlesResult()
6087  : DirectoryListHandlesResultFromListHandlesResponse(
6088  ListHandlesResponseFromXml(reader));
6089  result.HttpHeaders.ContentType = response.GetHeaders().at(_detail::HeaderContentType);
6090  return Azure::Response<DirectoryListHandlesResult>(
6091  std::move(result), std::move(responsePtr));
6092  }
6093  else
6094  {
6095  (void)context;
6096  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
6097  }
6098  }
6099 
6100  static HandleItem HandleItemFromXml(_internal::XmlReader& reader)
6101  {
6102  auto result = HandleItem();
6103  enum class XmlTagName
6104  {
6105  ClientIp,
6106  FileId,
6107  HandleId,
6108  LastReconnectTime,
6109  OpenTime,
6110  ParentId,
6111  Path,
6112  SessionId,
6113  Unknown,
6114  };
6115  std::vector<XmlTagName> path;
6116 
6117  while (true)
6118  {
6119  auto node = reader.Read();
6120  if (node.Type == _internal::XmlNodeType::End)
6121  {
6122  break;
6123  }
6124  else if (node.Type == _internal::XmlNodeType::EndTag)
6125  {
6126  if (path.size() > 0)
6127  {
6128  path.pop_back();
6129  }
6130  else
6131  {
6132  break;
6133  }
6134  }
6135  else if (node.Type == _internal::XmlNodeType::StartTag)
6136  {
6137 
6138  if (std::strcmp(node.Name, "ClientIp") == 0)
6139  {
6140  path.emplace_back(XmlTagName::ClientIp);
6141  }
6142  else if (std::strcmp(node.Name, "FileId") == 0)
6143  {
6144  path.emplace_back(XmlTagName::FileId);
6145  }
6146  else if (std::strcmp(node.Name, "HandleId") == 0)
6147  {
6148  path.emplace_back(XmlTagName::HandleId);
6149  }
6150  else if (std::strcmp(node.Name, "LastReconnectTime") == 0)
6151  {
6152  path.emplace_back(XmlTagName::LastReconnectTime);
6153  }
6154  else if (std::strcmp(node.Name, "OpenTime") == 0)
6155  {
6156  path.emplace_back(XmlTagName::OpenTime);
6157  }
6158  else if (std::strcmp(node.Name, "ParentId") == 0)
6159  {
6160  path.emplace_back(XmlTagName::ParentId);
6161  }
6162  else if (std::strcmp(node.Name, "Path") == 0)
6163  {
6164  path.emplace_back(XmlTagName::Path);
6165  }
6166  else if (std::strcmp(node.Name, "SessionId") == 0)
6167  {
6168  path.emplace_back(XmlTagName::SessionId);
6169  }
6170  else
6171  {
6172  path.emplace_back(XmlTagName::Unknown);
6173  }
6174  }
6175  else if (node.Type == _internal::XmlNodeType::Text)
6176  {
6177  if (path.size() == 1 && path[0] == XmlTagName::ClientIp)
6178  {
6179  result.ClientIp = node.Value;
6180  }
6181  else if (path.size() == 1 && path[0] == XmlTagName::FileId)
6182  {
6183  result.FileId = node.Value;
6184  }
6185  else if (path.size() == 1 && path[0] == XmlTagName::HandleId)
6186  {
6187  result.HandleId = node.Value;
6188  }
6189  else if (path.size() == 1 && path[0] == XmlTagName::LastReconnectTime)
6190  {
6191  result.LastReconnectedOn
6192  = DateTime::Parse(node.Value, DateTime::DateFormat::Rfc1123);
6193  }
6194  else if (path.size() == 1 && path[0] == XmlTagName::OpenTime)
6195  {
6196  result.OpenedOn = DateTime::Parse(node.Value, DateTime::DateFormat::Rfc1123);
6197  }
6198  else if (path.size() == 1 && path[0] == XmlTagName::ParentId)
6199  {
6200  result.ParentId = node.Value;
6201  }
6202  else if (path.size() == 1 && path[0] == XmlTagName::Path)
6203  {
6204  result.Path = node.Value;
6205  }
6206  else if (path.size() == 1 && path[0] == XmlTagName::SessionId)
6207  {
6208  result.SessionId = node.Value;
6209  }
6210  }
6211  }
6212  return result;
6213  }
6214 
6215  static ListHandlesResponse ListHandlesResponseFromXml(_internal::XmlReader& reader)
6216  {
6217  auto result = ListHandlesResponse();
6218  enum class XmlTagName
6219  {
6220  Entries,
6221  EnumerationResults,
6222  Handle,
6223  NextMarker,
6224  Unknown,
6225  };
6226  std::vector<XmlTagName> path;
6227 
6228  while (true)
6229  {
6230  auto node = reader.Read();
6231  if (node.Type == _internal::XmlNodeType::End)
6232  {
6233  break;
6234  }
6235  else if (node.Type == _internal::XmlNodeType::EndTag)
6236  {
6237  if (path.size() > 0)
6238  {
6239  path.pop_back();
6240  }
6241  else
6242  {
6243  break;
6244  }
6245  }
6246  else if (node.Type == _internal::XmlNodeType::StartTag)
6247  {
6248 
6249  if (std::strcmp(node.Name, "Entries") == 0)
6250  {
6251  path.emplace_back(XmlTagName::Entries);
6252  }
6253  else if (std::strcmp(node.Name, "EnumerationResults") == 0)
6254  {
6255  path.emplace_back(XmlTagName::EnumerationResults);
6256  }
6257  else if (std::strcmp(node.Name, "Handle") == 0)
6258  {
6259  path.emplace_back(XmlTagName::Handle);
6260  }
6261  else if (std::strcmp(node.Name, "NextMarker") == 0)
6262  {
6263  path.emplace_back(XmlTagName::NextMarker);
6264  }
6265  else
6266  {
6267  path.emplace_back(XmlTagName::Unknown);
6268  }
6269  if (path.size() == 3 && path[0] == XmlTagName::EnumerationResults
6270  && path[1] == XmlTagName::Entries && path[2] == XmlTagName::Handle)
6271  {
6272  result.HandleList.emplace_back(HandleItemFromXml(reader));
6273  path.pop_back();
6274  }
6275  }
6276  else if (node.Type == _internal::XmlNodeType::Text)
6277  {
6278  if (path.size() == 2 && path[0] == XmlTagName::EnumerationResults
6279  && path[1] == XmlTagName::NextMarker)
6280  {
6281  result.ContinuationToken = node.Value;
6282  }
6283  }
6284  }
6285  return result;
6286  }
6287 
6288  static DirectoryListHandlesResult DirectoryListHandlesResultFromListHandlesResponse(
6289  ListHandlesResponse object)
6290  {
6291  DirectoryListHandlesResult result;
6292  result.HandleList = std::move(object.HandleList);
6293  result.ContinuationToken = std::move(object.ContinuationToken);
6294 
6295  return result;
6296  }
6297  static Azure::Response<DirectoryForceCloseHandlesResult> ForceCloseHandlesParseResult(
6298  Azure::Core::Context context,
6299  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
6300  {
6301  auto& response = *responsePtr;
6302  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
6303  {
6304  // Success.
6305  DirectoryForceCloseHandlesResult result;
6306  if (response.GetHeaders().find(_detail::HeaderContinuationToken)
6307  != response.GetHeaders().end())
6308  {
6309  result.ContinuationToken = response.GetHeaders().at(_detail::HeaderContinuationToken);
6310  }
6311  result.NumberOfHandlesClosed
6312  = std::stoi(response.GetHeaders().at(_detail::HeaderNumberOfHandlesClosed));
6313  result.NumberOfHandlesFailedToClose
6314  = std::stoi(response.GetHeaders().at(_detail::HeaderNumberOfHandlesFailedToClose));
6315  return Azure::Response<DirectoryForceCloseHandlesResult>(
6316  std::move(result), std::move(responsePtr));
6317  }
6318  else
6319  {
6320  (void)context;
6321  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
6322  }
6323  }
6324  };
6325 
6326  class File final {
6327  public:
6328  struct CreateOptions final
6329  {
6330  Azure::Nullable<int32_t> Timeout;
6331  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6332  int64_t XMsContentLength = int64_t();
6333  Azure::Nullable<std::string> FileContentType;
6334  Azure::Nullable<std::string> FileContentEncoding;
6335  Azure::Nullable<std::string> FileContentLanguage;
6336  Azure::Nullable<std::string> FileCacheControl;
6337  Azure::Nullable<Storage::ContentHash> ContentMd5;
6338  Azure::Nullable<std::string> FileContentDisposition;
6339  Storage::Metadata Metadata;
6340  Azure::Nullable<std::string> FilePermission;
6341  Azure::Nullable<std::string> FilePermissionKey;
6342  std::string FileAttributes;
6343  std::string FileCreationTime;
6344  std::string FileLastWriteTime;
6345  Azure::Nullable<std::string> LeaseIdOptional;
6346  };
6347 
6348  static Azure::Response<Models::CreateFileResult> Create(
6349  const Azure::Core::Url& url,
6350  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6351  Azure::Core::Context context,
6352  const CreateOptions& createOptions)
6353  {
6354  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6355  request.SetHeader(_detail::HeaderContentLength, "0");
6356  if (createOptions.Timeout.HasValue())
6357  {
6358  request.GetUrl().AppendQueryParameter(
6359  _detail::QueryTimeout,
6360  _internal::UrlEncodeQueryParameter(std::to_string(createOptions.Timeout.Value())));
6361  }
6362  request.SetHeader(_detail::HeaderVersion, createOptions.ApiVersionParameter);
6363  request.SetHeader(
6364  _detail::HeaderXMsContentLength, std::to_string(createOptions.XMsContentLength));
6365  request.SetHeader(_detail::HeaderFileTypeConstant, "file");
6366  if (createOptions.FileContentType.HasValue())
6367  {
6368  request.SetHeader(
6369  _detail::HeaderFileContentType, createOptions.FileContentType.Value());
6370  }
6371  if (createOptions.FileContentEncoding.HasValue())
6372  {
6373  request.SetHeader(
6374  _detail::HeaderFileContentEncoding, createOptions.FileContentEncoding.Value());
6375  }
6376  if (createOptions.FileContentLanguage.HasValue())
6377  {
6378  request.SetHeader(
6379  _detail::HeaderFileContentLanguage, createOptions.FileContentLanguage.Value());
6380  }
6381  if (createOptions.FileCacheControl.HasValue())
6382  {
6383  request.SetHeader(
6384  _detail::HeaderFileCacheControl, createOptions.FileCacheControl.Value());
6385  }
6386  if (createOptions.ContentMd5.HasValue())
6387  {
6388  request.SetHeader(
6389  _detail::HeaderContentHashMd5,
6390  _internal::ToBase64String(createOptions.ContentMd5.Value()));
6391  }
6392  if (createOptions.FileContentDisposition.HasValue())
6393  {
6394  request.SetHeader(
6395  _detail::HeaderFileContentDisposition,
6396  createOptions.FileContentDisposition.Value());
6397  }
6398  for (const auto& pair : createOptions.Metadata)
6399  {
6400  request.SetHeader(_detail::HeaderMetadata + ("-" + pair.first), pair.second);
6401  }
6402  if (createOptions.FilePermission.HasValue())
6403  {
6404  request.SetHeader(_detail::HeaderFilePermission, createOptions.FilePermission.Value());
6405  }
6406  if (createOptions.FilePermissionKey.HasValue())
6407  {
6408  request.SetHeader(
6409  _detail::HeaderFilePermissionKey, createOptions.FilePermissionKey.Value());
6410  }
6411  request.SetHeader(_detail::HeaderFileAttributes, createOptions.FileAttributes);
6412  request.SetHeader(_detail::HeaderFileCreatedOn, createOptions.FileCreationTime);
6413  request.SetHeader(_detail::HeaderFileLastWrittenOn, createOptions.FileLastWriteTime);
6414  if (createOptions.LeaseIdOptional.HasValue())
6415  {
6416  request.SetHeader(_detail::HeaderLeaseId, createOptions.LeaseIdOptional.Value());
6417  }
6418  return CreateParseResult(context, pipeline.Send(request, context));
6419  }
6420 
6421  struct DownloadOptions final
6422  {
6423  Azure::Nullable<int32_t> Timeout;
6424  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6425  Azure::Nullable<std::string> Range;
6426  Azure::Nullable<bool> GetRangeContentMd5;
6427  Azure::Nullable<std::string> LeaseIdOptional;
6428  };
6429 
6430  static Azure::Response<FileDownloadResult> Download(
6431  const Azure::Core::Url& url,
6432  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6433  Azure::Core::Context context,
6434  const DownloadOptions& downloadOptions)
6435  {
6436  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url, false);
6437  if (downloadOptions.Timeout.HasValue())
6438  {
6439  request.GetUrl().AppendQueryParameter(
6440  _detail::QueryTimeout,
6441  _internal::UrlEncodeQueryParameter(
6442  std::to_string(downloadOptions.Timeout.Value())));
6443  }
6444  request.SetHeader(_detail::HeaderVersion, downloadOptions.ApiVersionParameter);
6445  if (downloadOptions.Range.HasValue())
6446  {
6447  request.SetHeader(_detail::HeaderRange, downloadOptions.Range.Value());
6448  }
6449  if (downloadOptions.GetRangeContentMd5.HasValue())
6450  {
6451  request.SetHeader(
6452  _detail::HeaderRangeGetContentMd5,
6453  (downloadOptions.GetRangeContentMd5.Value() ? "true" : "false"));
6454  }
6455  if (downloadOptions.LeaseIdOptional.HasValue())
6456  {
6457  request.SetHeader(_detail::HeaderLeaseId, downloadOptions.LeaseIdOptional.Value());
6458  }
6459  return DownloadParseResult(context, pipeline.Send(request, context));
6460  }
6461 
6462  struct GetPropertiesOptions final
6463  {
6464  Azure::Nullable<std::string> ShareSnapshot;
6465  Azure::Nullable<int32_t> Timeout;
6466  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6467  Azure::Nullable<std::string> LeaseIdOptional;
6468  };
6469 
6470  static Azure::Response<Models::FileProperties> GetProperties(
6471  const Azure::Core::Url& url,
6472  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6473  Azure::Core::Context context,
6474  const GetPropertiesOptions& getPropertiesOptions)
6475  {
6476  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Head, url);
6477  if (getPropertiesOptions.ShareSnapshot.HasValue())
6478  {
6479  request.GetUrl().AppendQueryParameter(
6480  _detail::QueryShareSnapshot,
6481  _internal::UrlEncodeQueryParameter(getPropertiesOptions.ShareSnapshot.Value()));
6482  }
6483  if (getPropertiesOptions.Timeout.HasValue())
6484  {
6485  request.GetUrl().AppendQueryParameter(
6486  _detail::QueryTimeout,
6487  _internal::UrlEncodeQueryParameter(
6488  std::to_string(getPropertiesOptions.Timeout.Value())));
6489  }
6490  request.SetHeader(_detail::HeaderVersion, getPropertiesOptions.ApiVersionParameter);
6491  if (getPropertiesOptions.LeaseIdOptional.HasValue())
6492  {
6493  request.SetHeader(_detail::HeaderLeaseId, getPropertiesOptions.LeaseIdOptional.Value());
6494  }
6495  return GetPropertiesParseResult(context, pipeline.Send(request, context));
6496  }
6497 
6498  struct DeleteOptions final
6499  {
6500  Azure::Nullable<int32_t> Timeout;
6501  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6502  Azure::Nullable<std::string> LeaseIdOptional;
6503  };
6504 
6505  static Azure::Response<Models::DeleteFileResult> Delete(
6506  const Azure::Core::Url& url,
6507  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6508  Azure::Core::Context context,
6509  const DeleteOptions& deleteOptions)
6510  {
6511  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Delete, url);
6512  if (deleteOptions.Timeout.HasValue())
6513  {
6514  request.GetUrl().AppendQueryParameter(
6515  _detail::QueryTimeout,
6516  _internal::UrlEncodeQueryParameter(std::to_string(deleteOptions.Timeout.Value())));
6517  }
6518  request.SetHeader(_detail::HeaderVersion, deleteOptions.ApiVersionParameter);
6519  if (deleteOptions.LeaseIdOptional.HasValue())
6520  {
6521  request.SetHeader(_detail::HeaderLeaseId, deleteOptions.LeaseIdOptional.Value());
6522  }
6523  return DeleteParseResult(context, pipeline.Send(request, context));
6524  }
6525 
6526  struct SetHttpHeadersOptions final
6527  {
6528  Azure::Nullable<int32_t> Timeout;
6529  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6530  Azure::Nullable<int64_t> XMsContentLength;
6531  Azure::Nullable<std::string> FileContentType;
6532  Azure::Nullable<std::string> FileContentEncoding;
6533  Azure::Nullable<std::string> FileContentLanguage;
6534  Azure::Nullable<std::string> FileCacheControl;
6535  Azure::Nullable<Storage::ContentHash> ContentMd5;
6536  Azure::Nullable<std::string> FileContentDisposition;
6537  Azure::Nullable<std::string> FilePermission;
6538  Azure::Nullable<std::string> FilePermissionKey;
6539  std::string FileAttributes;
6540  std::string FileCreationTime;
6541  std::string FileLastWriteTime;
6542  Azure::Nullable<std::string> LeaseIdOptional;
6543  };
6544 
6545  static Azure::Response<Models::SetFilePropertiesResult> SetHttpHeaders(
6546  const Azure::Core::Url& url,
6547  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6548  Azure::Core::Context context,
6549  const SetHttpHeadersOptions& setHttpHeadersOptions)
6550  {
6551  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6552  request.SetHeader(_detail::HeaderContentLength, "0");
6553  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "properties");
6554  if (setHttpHeadersOptions.Timeout.HasValue())
6555  {
6556  request.GetUrl().AppendQueryParameter(
6557  _detail::QueryTimeout,
6558  _internal::UrlEncodeQueryParameter(
6559  std::to_string(setHttpHeadersOptions.Timeout.Value())));
6560  }
6561  request.SetHeader(_detail::HeaderVersion, setHttpHeadersOptions.ApiVersionParameter);
6562  if (setHttpHeadersOptions.XMsContentLength.HasValue())
6563  {
6564  request.SetHeader(
6565  _detail::HeaderXMsContentLength,
6566  std::to_string(setHttpHeadersOptions.XMsContentLength.Value()));
6567  }
6568  if (setHttpHeadersOptions.FileContentType.HasValue())
6569  {
6570  request.SetHeader(
6571  _detail::HeaderFileContentType, setHttpHeadersOptions.FileContentType.Value());
6572  }
6573  if (setHttpHeadersOptions.FileContentEncoding.HasValue())
6574  {
6575  request.SetHeader(
6576  _detail::HeaderFileContentEncoding,
6577  setHttpHeadersOptions.FileContentEncoding.Value());
6578  }
6579  if (setHttpHeadersOptions.FileContentLanguage.HasValue())
6580  {
6581  request.SetHeader(
6582  _detail::HeaderFileContentLanguage,
6583  setHttpHeadersOptions.FileContentLanguage.Value());
6584  }
6585  if (setHttpHeadersOptions.FileCacheControl.HasValue())
6586  {
6587  request.SetHeader(
6588  _detail::HeaderFileCacheControl, setHttpHeadersOptions.FileCacheControl.Value());
6589  }
6590  if (setHttpHeadersOptions.ContentMd5.HasValue())
6591  {
6592  request.SetHeader(
6593  _detail::HeaderContentHashMd5,
6594  _internal::ToBase64String(setHttpHeadersOptions.ContentMd5.Value()));
6595  }
6596  if (setHttpHeadersOptions.FileContentDisposition.HasValue())
6597  {
6598  request.SetHeader(
6599  _detail::HeaderFileContentDisposition,
6600  setHttpHeadersOptions.FileContentDisposition.Value());
6601  }
6602  if (setHttpHeadersOptions.FilePermission.HasValue())
6603  {
6604  request.SetHeader(
6605  _detail::HeaderFilePermission, setHttpHeadersOptions.FilePermission.Value());
6606  }
6607  if (setHttpHeadersOptions.FilePermissionKey.HasValue())
6608  {
6609  request.SetHeader(
6610  _detail::HeaderFilePermissionKey, setHttpHeadersOptions.FilePermissionKey.Value());
6611  }
6612  request.SetHeader(_detail::HeaderFileAttributes, setHttpHeadersOptions.FileAttributes);
6613  request.SetHeader(_detail::HeaderFileCreatedOn, setHttpHeadersOptions.FileCreationTime);
6614  request.SetHeader(
6615  _detail::HeaderFileLastWrittenOn, setHttpHeadersOptions.FileLastWriteTime);
6616  if (setHttpHeadersOptions.LeaseIdOptional.HasValue())
6617  {
6618  request.SetHeader(
6619  _detail::HeaderLeaseId, setHttpHeadersOptions.LeaseIdOptional.Value());
6620  }
6621  return SetHttpHeadersParseResult(context, pipeline.Send(request, context));
6622  }
6623 
6624  struct SetMetadataOptions final
6625  {
6626  Azure::Nullable<int32_t> Timeout;
6627  Storage::Metadata Metadata;
6628  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6629  Azure::Nullable<std::string> LeaseIdOptional;
6630  };
6631 
6632  static Azure::Response<Models::SetFileMetadataResult> SetMetadata(
6633  const Azure::Core::Url& url,
6634  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6635  Azure::Core::Context context,
6636  const SetMetadataOptions& setMetadataOptions)
6637  {
6638  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6639  request.SetHeader(_detail::HeaderContentLength, "0");
6640  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "metadata");
6641  if (setMetadataOptions.Timeout.HasValue())
6642  {
6643  request.GetUrl().AppendQueryParameter(
6644  _detail::QueryTimeout,
6645  _internal::UrlEncodeQueryParameter(
6646  std::to_string(setMetadataOptions.Timeout.Value())));
6647  }
6648  for (const auto& pair : setMetadataOptions.Metadata)
6649  {
6650  request.SetHeader(_detail::HeaderMetadata + ("-" + pair.first), pair.second);
6651  }
6652  request.SetHeader(_detail::HeaderVersion, setMetadataOptions.ApiVersionParameter);
6653  if (setMetadataOptions.LeaseIdOptional.HasValue())
6654  {
6655  request.SetHeader(_detail::HeaderLeaseId, setMetadataOptions.LeaseIdOptional.Value());
6656  }
6657  return SetMetadataParseResult(context, pipeline.Send(request, context));
6658  }
6659 
6660  struct AcquireLeaseOptions final
6661  {
6662  Azure::Nullable<int32_t> Timeout;
6663  int32_t LeaseDuration = int32_t();
6664  Azure::Nullable<std::string> ProposedLeaseIdOptional;
6665  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6666  };
6667 
6668  static Azure::Response<FileAcquireLeaseResult> AcquireLease(
6669  const Azure::Core::Url& url,
6670  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6671  Azure::Core::Context context,
6672  const AcquireLeaseOptions& acquireLeaseOptions)
6673  {
6674  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6675  request.SetHeader(_detail::HeaderContentLength, "0");
6676  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
6677  request.SetHeader(_detail::HeaderAction, "acquire");
6678  if (acquireLeaseOptions.Timeout.HasValue())
6679  {
6680  request.GetUrl().AppendQueryParameter(
6681  _detail::QueryTimeout,
6682  _internal::UrlEncodeQueryParameter(
6683  std::to_string(acquireLeaseOptions.Timeout.Value())));
6684  }
6685  request.SetHeader(
6686  _detail::HeaderDuration, std::to_string(acquireLeaseOptions.LeaseDuration));
6687  if (acquireLeaseOptions.ProposedLeaseIdOptional.HasValue())
6688  {
6689  request.SetHeader(
6690  _detail::HeaderProposedLeaseId,
6691  acquireLeaseOptions.ProposedLeaseIdOptional.Value());
6692  }
6693  request.SetHeader(_detail::HeaderVersion, acquireLeaseOptions.ApiVersionParameter);
6694  return AcquireLeaseParseResult(context, pipeline.Send(request, context));
6695  }
6696 
6697  struct ReleaseLeaseOptions final
6698  {
6699  Azure::Nullable<int32_t> Timeout;
6700  std::string LeaseIdRequired;
6701  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6702  };
6703 
6704  static Azure::Response<FileReleaseLeaseResult> ReleaseLease(
6705  const Azure::Core::Url& url,
6706  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6707  Azure::Core::Context context,
6708  const ReleaseLeaseOptions& releaseLeaseOptions)
6709  {
6710  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6711  request.SetHeader(_detail::HeaderContentLength, "0");
6712  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
6713  request.SetHeader(_detail::HeaderAction, "release");
6714  if (releaseLeaseOptions.Timeout.HasValue())
6715  {
6716  request.GetUrl().AppendQueryParameter(
6717  _detail::QueryTimeout,
6718  _internal::UrlEncodeQueryParameter(
6719  std::to_string(releaseLeaseOptions.Timeout.Value())));
6720  }
6721  request.SetHeader(_detail::HeaderLeaseId, releaseLeaseOptions.LeaseIdRequired);
6722  request.SetHeader(_detail::HeaderVersion, releaseLeaseOptions.ApiVersionParameter);
6723  return ReleaseLeaseParseResult(context, pipeline.Send(request, context));
6724  }
6725 
6726  struct ChangeLeaseOptions final
6727  {
6728  Azure::Nullable<int32_t> Timeout;
6729  std::string LeaseIdRequired;
6730  Azure::Nullable<std::string> ProposedLeaseIdOptional;
6731  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6732  };
6733 
6734  static Azure::Response<FileChangeLeaseResult> ChangeLease(
6735  const Azure::Core::Url& url,
6736  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6737  Azure::Core::Context context,
6738  const ChangeLeaseOptions& changeLeaseOptions)
6739  {
6740  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6741  request.SetHeader(_detail::HeaderContentLength, "0");
6742  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
6743  request.SetHeader(_detail::HeaderAction, "change");
6744  if (changeLeaseOptions.Timeout.HasValue())
6745  {
6746  request.GetUrl().AppendQueryParameter(
6747  _detail::QueryTimeout,
6748  _internal::UrlEncodeQueryParameter(
6749  std::to_string(changeLeaseOptions.Timeout.Value())));
6750  }
6751  request.SetHeader(_detail::HeaderLeaseId, changeLeaseOptions.LeaseIdRequired);
6752  if (changeLeaseOptions.ProposedLeaseIdOptional.HasValue())
6753  {
6754  request.SetHeader(
6755  _detail::HeaderProposedLeaseId, changeLeaseOptions.ProposedLeaseIdOptional.Value());
6756  }
6757  request.SetHeader(_detail::HeaderVersion, changeLeaseOptions.ApiVersionParameter);
6758  return ChangeLeaseParseResult(context, pipeline.Send(request, context));
6759  }
6760 
6761  struct BreakLeaseOptions final
6762  {
6763  Azure::Nullable<int32_t> Timeout;
6764  Azure::Nullable<std::string> LeaseIdOptional;
6765  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6766  };
6767 
6768  static Azure::Response<FileBreakLeaseResult> BreakLease(
6769  const Azure::Core::Url& url,
6770  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6771  Azure::Core::Context context,
6772  const BreakLeaseOptions& breakLeaseOptions)
6773  {
6774  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6775  request.SetHeader(_detail::HeaderContentLength, "0");
6776  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "lease");
6777  request.SetHeader(_detail::HeaderAction, "break");
6778  if (breakLeaseOptions.Timeout.HasValue())
6779  {
6780  request.GetUrl().AppendQueryParameter(
6781  _detail::QueryTimeout,
6782  _internal::UrlEncodeQueryParameter(
6783  std::to_string(breakLeaseOptions.Timeout.Value())));
6784  }
6785  if (breakLeaseOptions.LeaseIdOptional.HasValue())
6786  {
6787  request.SetHeader(_detail::HeaderLeaseId, breakLeaseOptions.LeaseIdOptional.Value());
6788  }
6789  request.SetHeader(_detail::HeaderVersion, breakLeaseOptions.ApiVersionParameter);
6790  return BreakLeaseParseResult(context, pipeline.Send(request, context));
6791  }
6792 
6793  struct UploadRangeOptions final
6794  {
6795  Azure::Nullable<int32_t> Timeout;
6796  std::string XMsRange;
6797  FileRangeWrite XMsWrite;
6798  int64_t ContentLength = int64_t();
6799  Azure::Nullable<Storage::ContentHash> ContentMd5;
6800  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6801  Azure::Nullable<std::string> LeaseIdOptional;
6802  };
6803 
6804  static Azure::Response<Models::UploadFileRangeResult> UploadRange(
6805  const Azure::Core::Url& url,
6806  Azure::Core::IO::BodyStream& bodyStream,
6807  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6808  Azure::Core::Context context,
6809  const UploadRangeOptions& uploadRangeOptions)
6810  {
6811  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url, &bodyStream);
6812  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "range");
6813  if (uploadRangeOptions.Timeout.HasValue())
6814  {
6815  request.GetUrl().AppendQueryParameter(
6816  _detail::QueryTimeout,
6817  _internal::UrlEncodeQueryParameter(
6818  std::to_string(uploadRangeOptions.Timeout.Value())));
6819  }
6820  request.SetHeader(_detail::HeaderXMsRange, uploadRangeOptions.XMsRange);
6821  request.SetHeader(_detail::HeaderFileRangeWrite, uploadRangeOptions.XMsWrite.ToString());
6822  request.SetHeader(
6823  _detail::HeaderContentLength, std::to_string(uploadRangeOptions.ContentLength));
6824  if (uploadRangeOptions.ContentMd5.HasValue())
6825  {
6826  request.SetHeader(
6827  _detail::HeaderContentHashMd5,
6828  _internal::ToBase64String(uploadRangeOptions.ContentMd5.Value()));
6829  }
6830  request.SetHeader(_detail::HeaderVersion, uploadRangeOptions.ApiVersionParameter);
6831  if (uploadRangeOptions.LeaseIdOptional.HasValue())
6832  {
6833  request.SetHeader(_detail::HeaderLeaseId, uploadRangeOptions.LeaseIdOptional.Value());
6834  }
6835  return UploadRangeParseResult(context, pipeline.Send(request, context));
6836  }
6837 
6838  struct UploadRangeFromUrlOptions final
6839  {
6840  Azure::Nullable<int32_t> Timeout;
6841  std::string TargetRange;
6842  std::string CopySource;
6843  Azure::Nullable<std::string> SourceRange;
6844  FileRangeWriteFromUrl XMsWrite;
6845  int64_t ContentLength = int64_t();
6846  Azure::Nullable<Storage::ContentHash> SourceContentCrc64;
6847  Azure::Nullable<Storage::ContentHash> SourceIfMatchCrc64;
6848  Azure::Nullable<Storage::ContentHash> SourceIfNoneMatchCrc64;
6849  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6850  Azure::Nullable<std::string> LeaseIdOptional;
6851  };
6852 
6853  static Azure::Response<Models::UploadFileRangeFromUriResult> UploadRangeFromUrl(
6854  const Azure::Core::Url& url,
6855  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6856  Azure::Core::Context context,
6857  const UploadRangeFromUrlOptions& uploadRangeFromUrlOptions)
6858  {
6859  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6860  request.SetHeader(_detail::HeaderContentLength, "0");
6861  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "range");
6862  if (uploadRangeFromUrlOptions.Timeout.HasValue())
6863  {
6864  request.GetUrl().AppendQueryParameter(
6865  _detail::QueryTimeout,
6866  _internal::UrlEncodeQueryParameter(
6867  std::to_string(uploadRangeFromUrlOptions.Timeout.Value())));
6868  }
6869  request.SetHeader(_detail::HeaderRange, uploadRangeFromUrlOptions.TargetRange);
6870  request.SetHeader(_detail::HeaderCopySource, uploadRangeFromUrlOptions.CopySource);
6871  if (uploadRangeFromUrlOptions.SourceRange.HasValue())
6872  {
6873  request.SetHeader(
6874  _detail::HeaderSourceRange, uploadRangeFromUrlOptions.SourceRange.Value());
6875  }
6876  request.SetHeader(
6877  _detail::HeaderFileRangeWriteFromUrl, uploadRangeFromUrlOptions.XMsWrite.ToString());
6878  request.SetHeader(
6879  _detail::HeaderContentLength,
6880  std::to_string(uploadRangeFromUrlOptions.ContentLength));
6881  if (uploadRangeFromUrlOptions.SourceContentCrc64.HasValue())
6882  {
6883  request.SetHeader(
6884  _detail::HeaderSourceContentHashCrc64,
6885  _internal::ToBase64String(uploadRangeFromUrlOptions.SourceContentCrc64.Value()));
6886  }
6887  if (uploadRangeFromUrlOptions.SourceIfMatchCrc64.HasValue())
6888  {
6889  request.SetHeader(
6890  _detail::HeaderSourceIfMatchHashCrc64,
6891  _internal::ToBase64String(uploadRangeFromUrlOptions.SourceIfMatchCrc64.Value()));
6892  }
6893  if (uploadRangeFromUrlOptions.SourceIfNoneMatchCrc64.HasValue())
6894  {
6895  request.SetHeader(
6896  _detail::HeaderSourceIfNoneMatchHashCrc64,
6897  _internal::ToBase64String(
6898  uploadRangeFromUrlOptions.SourceIfNoneMatchCrc64.Value()));
6899  }
6900  request.SetHeader(_detail::HeaderVersion, uploadRangeFromUrlOptions.ApiVersionParameter);
6901  if (uploadRangeFromUrlOptions.LeaseIdOptional.HasValue())
6902  {
6903  request.SetHeader(
6904  _detail::HeaderLeaseId, uploadRangeFromUrlOptions.LeaseIdOptional.Value());
6905  }
6906  return UploadRangeFromUrlParseResult(context, pipeline.Send(request, context));
6907  }
6908 
6909  struct GetRangeListOptions final
6910  {
6911  Azure::Nullable<std::string> ShareSnapshot;
6912  Azure::Nullable<std::string> PrevShareSnapshot;
6913  Azure::Nullable<int32_t> Timeout;
6914  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6915  Azure::Nullable<std::string> XMsRange;
6916  Azure::Nullable<std::string> LeaseIdOptional;
6917  };
6918 
6919  static Azure::Response<Models::GetFileRangeListResult> GetRangeList(
6920  const Azure::Core::Url& url,
6921  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6922  Azure::Core::Context context,
6923  const GetRangeListOptions& getRangeListOptions)
6924  {
6925  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
6926  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "rangelist");
6927  if (getRangeListOptions.ShareSnapshot.HasValue())
6928  {
6929  request.GetUrl().AppendQueryParameter(
6930  _detail::QueryShareSnapshot,
6931  _internal::UrlEncodeQueryParameter(getRangeListOptions.ShareSnapshot.Value()));
6932  }
6933  if (getRangeListOptions.PrevShareSnapshot.HasValue())
6934  {
6935  request.GetUrl().AppendQueryParameter(
6936  _detail::QueryPrevShareSnapshot,
6937  _internal::UrlEncodeQueryParameter(getRangeListOptions.PrevShareSnapshot.Value()));
6938  }
6939  if (getRangeListOptions.Timeout.HasValue())
6940  {
6941  request.GetUrl().AppendQueryParameter(
6942  _detail::QueryTimeout,
6943  _internal::UrlEncodeQueryParameter(
6944  std::to_string(getRangeListOptions.Timeout.Value())));
6945  }
6946  request.SetHeader(_detail::HeaderVersion, getRangeListOptions.ApiVersionParameter);
6947  if (getRangeListOptions.XMsRange.HasValue())
6948  {
6949  request.SetHeader(_detail::HeaderXMsRange, getRangeListOptions.XMsRange.Value());
6950  }
6951  if (getRangeListOptions.LeaseIdOptional.HasValue())
6952  {
6953  request.SetHeader(_detail::HeaderLeaseId, getRangeListOptions.LeaseIdOptional.Value());
6954  }
6955  return GetRangeListParseResult(context, pipeline.Send(request, context));
6956  }
6957 
6958  struct StartCopyOptions final
6959  {
6960  Azure::Nullable<int32_t> Timeout;
6961  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
6962  Storage::Metadata Metadata;
6963  std::string CopySource;
6964  Azure::Nullable<std::string> FilePermission;
6965  Azure::Nullable<std::string> FilePermissionKey;
6966  Azure::Nullable<PermissionCopyMode> XMsFilePermissionCopyMode;
6967  Azure::Nullable<bool> FileCopyIgnoreReadOnly;
6968  Azure::Nullable<std::string> FileCopyFileAttributes;
6969  Azure::Nullable<std::string> FileCopyFileCreationTime;
6970  Azure::Nullable<std::string> FileCopyFileLastWriteTime;
6971  Azure::Nullable<bool> FileCopySetArchiveAttribute;
6972  Azure::Nullable<std::string> LeaseIdOptional;
6973  };
6974 
6975  static Azure::Response<FileStartCopyResult> StartCopy(
6976  const Azure::Core::Url& url,
6977  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6978  Azure::Core::Context context,
6979  const StartCopyOptions& startCopyOptions)
6980  {
6981  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
6982  request.SetHeader(_detail::HeaderContentLength, "0");
6983  if (startCopyOptions.Timeout.HasValue())
6984  {
6985  request.GetUrl().AppendQueryParameter(
6986  _detail::QueryTimeout,
6987  _internal::UrlEncodeQueryParameter(
6988  std::to_string(startCopyOptions.Timeout.Value())));
6989  }
6990  request.SetHeader(_detail::HeaderVersion, startCopyOptions.ApiVersionParameter);
6991  for (const auto& pair : startCopyOptions.Metadata)
6992  {
6993  request.SetHeader(_detail::HeaderMetadata + ("-" + pair.first), pair.second);
6994  }
6995  request.SetHeader(_detail::HeaderCopySource, startCopyOptions.CopySource);
6996  if (startCopyOptions.FilePermission.HasValue())
6997  {
6998  request.SetHeader(
6999  _detail::HeaderFilePermission, startCopyOptions.FilePermission.Value());
7000  }
7001  if (startCopyOptions.FilePermissionKey.HasValue())
7002  {
7003  request.SetHeader(
7004  _detail::HeaderFilePermissionKey, startCopyOptions.FilePermissionKey.Value());
7005  }
7006  if (startCopyOptions.XMsFilePermissionCopyMode.HasValue())
7007  {
7008  request.SetHeader(
7009  _detail::HeaderFilePermissionCopyMode,
7010  startCopyOptions.XMsFilePermissionCopyMode.Value().ToString());
7011  }
7012  if (startCopyOptions.FileCopyIgnoreReadOnly.HasValue())
7013  {
7014  request.SetHeader(
7015  _detail::HeaderIgnoreReadOnly,
7016  (startCopyOptions.FileCopyIgnoreReadOnly.Value() ? "true" : "false"));
7017  }
7018  if (startCopyOptions.FileCopyFileAttributes.HasValue())
7019  {
7020  request.SetHeader(
7021  _detail::HeaderFileAttributes, startCopyOptions.FileCopyFileAttributes.Value());
7022  }
7023  if (startCopyOptions.FileCopyFileCreationTime.HasValue())
7024  {
7025  request.SetHeader(
7026  _detail::HeaderFileCreatedOn, startCopyOptions.FileCopyFileCreationTime.Value());
7027  }
7028  if (startCopyOptions.FileCopyFileLastWriteTime.HasValue())
7029  {
7030  request.SetHeader(
7031  _detail::HeaderFileLastWrittenOn,
7032  startCopyOptions.FileCopyFileLastWriteTime.Value());
7033  }
7034  if (startCopyOptions.FileCopySetArchiveAttribute.HasValue())
7035  {
7036  request.SetHeader(
7037  _detail::HeaderSetArchiveAttribute,
7038  (startCopyOptions.FileCopySetArchiveAttribute.Value() ? "true" : "false"));
7039  }
7040  if (startCopyOptions.LeaseIdOptional.HasValue())
7041  {
7042  request.SetHeader(_detail::HeaderLeaseId, startCopyOptions.LeaseIdOptional.Value());
7043  }
7044  return StartCopyParseResult(context, pipeline.Send(request, context));
7045  }
7046 
7047  struct AbortCopyOptions final
7048  {
7049  std::string CopyId;
7050  Azure::Nullable<int32_t> Timeout;
7051  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
7052  Azure::Nullable<std::string> LeaseIdOptional;
7053  };
7054 
7055  static Azure::Response<Models::AbortFileCopyResult> AbortCopy(
7056  const Azure::Core::Url& url,
7057  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7058  Azure::Core::Context context,
7059  const AbortCopyOptions& abortCopyOptions)
7060  {
7061  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
7062  request.SetHeader(_detail::HeaderContentLength, "0");
7063  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "copy");
7064  request.GetUrl().AppendQueryParameter(
7065  _detail::QueryCopyId, _internal::UrlEncodeQueryParameter(abortCopyOptions.CopyId));
7066  if (abortCopyOptions.Timeout.HasValue())
7067  {
7068  request.GetUrl().AppendQueryParameter(
7069  _detail::QueryTimeout,
7070  _internal::UrlEncodeQueryParameter(
7071  std::to_string(abortCopyOptions.Timeout.Value())));
7072  }
7073  request.SetHeader(_detail::HeaderCopyActionAbortConstant, "abort");
7074  request.SetHeader(_detail::HeaderVersion, abortCopyOptions.ApiVersionParameter);
7075  if (abortCopyOptions.LeaseIdOptional.HasValue())
7076  {
7077  request.SetHeader(_detail::HeaderLeaseId, abortCopyOptions.LeaseIdOptional.Value());
7078  }
7079  return AbortCopyParseResult(context, pipeline.Send(request, context));
7080  }
7081 
7082  struct ListHandlesOptions final
7083  {
7084  Azure::Nullable<std::string> ContinuationToken;
7085  Azure::Nullable<int32_t> MaxResults;
7086  Azure::Nullable<int32_t> Timeout;
7087  Azure::Nullable<std::string> ShareSnapshot;
7088  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
7089  };
7090 
7091  static Azure::Response<FileListHandlesResult> ListHandles(
7092  const Azure::Core::Url& url,
7093  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7094  Azure::Core::Context context,
7095  const ListHandlesOptions& listHandlesOptions)
7096  {
7097  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
7098  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "listhandles");
7099  if (listHandlesOptions.ContinuationToken.HasValue())
7100  {
7101  request.GetUrl().AppendQueryParameter(
7102  _detail::QueryContinuationToken,
7103  _internal::UrlEncodeQueryParameter(listHandlesOptions.ContinuationToken.Value()));
7104  }
7105  if (listHandlesOptions.MaxResults.HasValue())
7106  {
7107  request.GetUrl().AppendQueryParameter(
7108  _detail::QueryPageSizeHint,
7109  _internal::UrlEncodeQueryParameter(
7110  std::to_string(listHandlesOptions.MaxResults.Value())));
7111  }
7112  if (listHandlesOptions.Timeout.HasValue())
7113  {
7114  request.GetUrl().AppendQueryParameter(
7115  _detail::QueryTimeout,
7116  _internal::UrlEncodeQueryParameter(
7117  std::to_string(listHandlesOptions.Timeout.Value())));
7118  }
7119  if (listHandlesOptions.ShareSnapshot.HasValue())
7120  {
7121  request.GetUrl().AppendQueryParameter(
7122  _detail::QueryShareSnapshot,
7123  _internal::UrlEncodeQueryParameter(listHandlesOptions.ShareSnapshot.Value()));
7124  }
7125  request.SetHeader(_detail::HeaderVersion, listHandlesOptions.ApiVersionParameter);
7126  return ListHandlesParseResult(context, pipeline.Send(request, context));
7127  }
7128 
7129  struct ForceCloseHandlesOptions final
7130  {
7131  Azure::Nullable<int32_t> Timeout;
7132  Azure::Nullable<std::string> ContinuationToken;
7133  Azure::Nullable<std::string> ShareSnapshot;
7134  std::string HandleId;
7135  std::string ApiVersionParameter = _detail::DefaultServiceApiVersion;
7136  };
7137 
7138  static Azure::Response<FileForceCloseHandlesResult> ForceCloseHandles(
7139  const Azure::Core::Url& url,
7140  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7141  Azure::Core::Context context,
7142  const ForceCloseHandlesOptions& forceCloseHandlesOptions)
7143  {
7144  Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Put, url);
7145  request.SetHeader(_detail::HeaderContentLength, "0");
7146  request.GetUrl().AppendQueryParameter(_detail::QueryComp, "forceclosehandles");
7147  if (forceCloseHandlesOptions.Timeout.HasValue())
7148  {
7149  request.GetUrl().AppendQueryParameter(
7150  _detail::QueryTimeout,
7151  _internal::UrlEncodeQueryParameter(
7152  std::to_string(forceCloseHandlesOptions.Timeout.Value())));
7153  }
7154  if (forceCloseHandlesOptions.ContinuationToken.HasValue())
7155  {
7156  request.GetUrl().AppendQueryParameter(
7157  _detail::QueryContinuationToken,
7158  _internal::UrlEncodeQueryParameter(
7159  forceCloseHandlesOptions.ContinuationToken.Value()));
7160  }
7161  if (forceCloseHandlesOptions.ShareSnapshot.HasValue())
7162  {
7163  request.GetUrl().AppendQueryParameter(
7164  _detail::QueryShareSnapshot,
7165  _internal::UrlEncodeQueryParameter(forceCloseHandlesOptions.ShareSnapshot.Value()));
7166  }
7167  request.SetHeader(_detail::HeaderHandleId, forceCloseHandlesOptions.HandleId);
7168  request.SetHeader(_detail::HeaderVersion, forceCloseHandlesOptions.ApiVersionParameter);
7169  return ForceCloseHandlesParseResult(context, pipeline.Send(request, context));
7170  }
7171 
7172  private:
7173  static Azure::Response<Models::CreateFileResult> CreateParseResult(
7174  Azure::Core::Context context,
7175  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7176  {
7177  auto& response = *responsePtr;
7178  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
7179  {
7180  // Success, File created.
7181  Models::CreateFileResult result;
7182  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7183  result.LastModified = DateTime::Parse(
7184  response.GetHeaders().at(_detail::HeaderLastModified),
7185  DateTime::DateFormat::Rfc1123);
7186  result.IsServerEncrypted
7187  = response.GetHeaders().at(_detail::HeaderRequestIsServerEncrypted) == "true";
7188  result.SmbProperties.PermissionKey
7189  = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
7190  result.SmbProperties.Attributes
7191  = FileAttributes(response.GetHeaders().at(_detail::HeaderAttributes));
7192  result.SmbProperties.CreatedOn = DateTime::Parse(
7193  response.GetHeaders().at(_detail::HeaderCreatedOn), DateTime::DateFormat::Rfc3339);
7194  result.SmbProperties.LastWrittenOn = DateTime::Parse(
7195  response.GetHeaders().at(_detail::HeaderLastWrittenOn),
7196  DateTime::DateFormat::Rfc3339);
7197  result.SmbProperties.ChangedOn = DateTime::Parse(
7198  response.GetHeaders().at(_detail::HeaderChangedOn), DateTime::DateFormat::Rfc3339);
7199  result.SmbProperties.FileId = response.GetHeaders().at(_detail::HeaderFileId);
7200  result.SmbProperties.ParentFileId
7201  = response.GetHeaders().at(_detail::HeaderParentFileId);
7202  return Azure::Response<Models::CreateFileResult>(
7203  std::move(result), std::move(responsePtr));
7204  }
7205  else
7206  {
7207  (void)context;
7208  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7209  }
7210  }
7211 
7212  static Azure::Response<FileDownloadResult> DownloadParseResult(
7213  Azure::Core::Context context,
7214  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7215  {
7216  auto& response = *responsePtr;
7217  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
7218  {
7219  // Succeeded to read the entire file.
7220  FileDownloadResult result;
7221  result.BodyStream = response.ExtractBodyStream();
7222  result.LastModified = DateTime::Parse(
7223  response.GetHeaders().at(_detail::HeaderLastModified),
7224  DateTime::DateFormat::Rfc1123);
7225 
7226  for (auto i = response.GetHeaders().lower_bound(_detail::HeaderMetadata);
7227  i != response.GetHeaders().end()
7228  && i->first.substr(0, 9) == _detail::HeaderMetadata;
7229  ++i)
7230  {
7231  result.Metadata.emplace(i->first.substr(10), i->second);
7232  }
7233  result.HttpHeaders.ContentType = response.GetHeaders().at(_detail::HeaderContentType);
7234 
7235  auto content_range_iterator = response.GetHeaders().find(_detail::HeaderContentRange);
7236  if (content_range_iterator != response.GetHeaders().end())
7237  {
7238  const std::string& content_range = content_range_iterator->second;
7239  auto bytes_pos = content_range.find("bytes ");
7240  auto dash_pos = content_range.find("-", bytes_pos + 6);
7241  auto slash_pos = content_range.find("/", dash_pos + 1);
7242  int64_t range_start_offset = std::stoll(std::string(
7243  content_range.begin() + bytes_pos + 6, content_range.begin() + dash_pos));
7244  int64_t range_end_offset = std::stoll(std::string(
7245  content_range.begin() + dash_pos + 1, content_range.begin() + slash_pos));
7246  result.ContentRange = Azure::Core::Http::HttpRange{
7247  range_start_offset, range_end_offset - range_start_offset + 1};
7248  }
7249  else
7250  {
7251  result.ContentRange = Azure::Core::Http::HttpRange{
7252  0, std::stoll(response.GetHeaders().at(_detail::HeaderContentLength))};
7253  }
7254  if (content_range_iterator != response.GetHeaders().end())
7255  {
7256  const std::string& content_range = content_range_iterator->second;
7257  auto slash_pos = content_range.find("/");
7258  result.FileSize = std::stoll(content_range.substr(slash_pos + 1));
7259  }
7260  else
7261  {
7262  result.FileSize = std::stoll(response.GetHeaders().at(_detail::HeaderContentLength));
7263  }
7264  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7265  if (response.GetHeaders().find(_detail::HeaderTransactionalContentHashMd5)
7266  != response.GetHeaders().end())
7267  {
7268  result.TransactionalContentHash = _internal::FromBase64String(
7269  response.GetHeaders().at(_detail::HeaderTransactionalContentHashMd5),
7270  HashAlgorithm::Md5);
7271  }
7272  if (response.GetHeaders().find(_detail::HeaderContentEncoding)
7273  != response.GetHeaders().end())
7274  {
7275  result.HttpHeaders.ContentEncoding
7276  = response.GetHeaders().at(_detail::HeaderContentEncoding);
7277  }
7278  if (response.GetHeaders().find(_detail::HeaderCacheControl)
7279  != response.GetHeaders().end())
7280  {
7281  result.HttpHeaders.CacheControl
7282  = response.GetHeaders().at(_detail::HeaderCacheControl);
7283  }
7284  if (response.GetHeaders().find(_detail::HeaderContentDisposition)
7285  != response.GetHeaders().end())
7286  {
7287  result.HttpHeaders.ContentDisposition
7288  = response.GetHeaders().at(_detail::HeaderContentDisposition);
7289  }
7290  if (response.GetHeaders().find(_detail::HeaderContentLanguage)
7291  != response.GetHeaders().end())
7292  {
7293  result.HttpHeaders.ContentLanguage
7294  = response.GetHeaders().at(_detail::HeaderContentLanguage);
7295  }
7296  result.AcceptRanges = response.GetHeaders().at(_detail::HeaderAcceptRanges);
7297  if (response.GetHeaders().find(_detail::HeaderCopyCompletedOn)
7298  != response.GetHeaders().end())
7299  {
7300  result.CopyCompletedOn = DateTime::Parse(
7301  response.GetHeaders().at(_detail::HeaderCopyCompletedOn),
7302  DateTime::DateFormat::Rfc1123);
7303  }
7304  if (response.GetHeaders().find(_detail::HeaderCopyStatusDescription)
7305  != response.GetHeaders().end())
7306  {
7307  result.CopyStatusDescription
7308  = response.GetHeaders().at(_detail::HeaderCopyStatusDescription);
7309  }
7310  if (response.GetHeaders().find(_detail::HeaderCopyId) != response.GetHeaders().end())
7311  {
7312  result.CopyId = response.GetHeaders().at(_detail::HeaderCopyId);
7313  }
7314  if (response.GetHeaders().find(_detail::HeaderCopyProgress)
7315  != response.GetHeaders().end())
7316  {
7317  result.CopyProgress = response.GetHeaders().at(_detail::HeaderCopyProgress);
7318  }
7319  if (response.GetHeaders().find(_detail::HeaderCopySource)
7320  != response.GetHeaders().end())
7321  {
7322  result.CopySource = response.GetHeaders().at(_detail::HeaderCopySource);
7323  }
7324  if (response.GetHeaders().find(_detail::HeaderCopyStatus)
7325  != response.GetHeaders().end())
7326  {
7327  result.CopyStatus = CopyStatus(response.GetHeaders().at(_detail::HeaderCopyStatus));
7328  }
7329  if (response.GetHeaders().find(_detail::HeaderContentHashMd5)
7330  != response.GetHeaders().end())
7331  {
7332  result.HttpHeaders.ContentHash = _internal::FromBase64String(
7333  response.GetHeaders().at(_detail::HeaderContentHashMd5), HashAlgorithm::Md5);
7334  }
7335  if (response.GetHeaders().find(_detail::HeaderIsServerEncrypted)
7336  != response.GetHeaders().end())
7337  {
7338  result.IsServerEncrypted
7339  = response.GetHeaders().at(_detail::HeaderIsServerEncrypted) == "true";
7340  }
7341  result.SmbProperties.Attributes
7342  = FileAttributes(response.GetHeaders().at(_detail::HeaderAttributes));
7343  result.SmbProperties.CreatedOn = DateTime::Parse(
7344  response.GetHeaders().at(_detail::HeaderCreatedOn), DateTime::DateFormat::Rfc3339);
7345  result.SmbProperties.LastWrittenOn = DateTime::Parse(
7346  response.GetHeaders().at(_detail::HeaderLastWrittenOn),
7347  DateTime::DateFormat::Rfc3339);
7348  result.SmbProperties.ChangedOn = DateTime::Parse(
7349  response.GetHeaders().at(_detail::HeaderChangedOn), DateTime::DateFormat::Rfc3339);
7350  result.SmbProperties.PermissionKey
7351  = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
7352  result.SmbProperties.FileId = response.GetHeaders().at(_detail::HeaderFileId);
7353  result.SmbProperties.ParentFileId
7354  = response.GetHeaders().at(_detail::HeaderParentFileId);
7355  if (response.GetHeaders().find(_detail::HeaderLeaseDuration)
7356  != response.GetHeaders().end())
7357  {
7358  result.LeaseDuration
7359  = LeaseDuration(response.GetHeaders().at(_detail::HeaderLeaseDuration));
7360  }
7361  if (response.GetHeaders().find(_detail::HeaderLeaseState)
7362  != response.GetHeaders().end())
7363  {
7364  result.LeaseState = LeaseState(response.GetHeaders().at(_detail::HeaderLeaseState));
7365  }
7366  if (response.GetHeaders().find(_detail::HeaderLeaseStatus)
7367  != response.GetHeaders().end())
7368  {
7369  result.LeaseStatus
7370  = LeaseStatus(response.GetHeaders().at(_detail::HeaderLeaseStatus));
7371  }
7372  return Azure::Response<FileDownloadResult>(std::move(result), std::move(responsePtr));
7373  }
7374  else if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::PartialContent)
7375  {
7376  // Succeeded to read a specified range of the file.
7377  FileDownloadResult result;
7378  result.BodyStream = response.ExtractBodyStream();
7379  result.LastModified = DateTime::Parse(
7380  response.GetHeaders().at(_detail::HeaderLastModified),
7381  DateTime::DateFormat::Rfc1123);
7382 
7383  for (auto i = response.GetHeaders().lower_bound(_detail::HeaderMetadata);
7384  i != response.GetHeaders().end()
7385  && i->first.substr(0, 9) == _detail::HeaderMetadata;
7386  ++i)
7387  {
7388  result.Metadata.emplace(i->first.substr(10), i->second);
7389  }
7390  result.HttpHeaders.ContentType = response.GetHeaders().at(_detail::HeaderContentType);
7391 
7392  auto content_range_iterator = response.GetHeaders().find(_detail::HeaderContentRange);
7393  if (content_range_iterator != response.GetHeaders().end())
7394  {
7395  const std::string& content_range = content_range_iterator->second;
7396  auto bytes_pos = content_range.find("bytes ");
7397  auto dash_pos = content_range.find("-", bytes_pos + 6);
7398  auto slash_pos = content_range.find("/", dash_pos + 1);
7399  int64_t range_start_offset = std::stoll(std::string(
7400  content_range.begin() + bytes_pos + 6, content_range.begin() + dash_pos));
7401  int64_t range_end_offset = std::stoll(std::string(
7402  content_range.begin() + dash_pos + 1, content_range.begin() + slash_pos));
7403  result.ContentRange = Azure::Core::Http::HttpRange{
7404  range_start_offset, range_end_offset - range_start_offset + 1};
7405  }
7406  else
7407  {
7408  result.ContentRange = Azure::Core::Http::HttpRange{
7409  0, std::stoll(response.GetHeaders().at(_detail::HeaderContentLength))};
7410  }
7411  if (content_range_iterator != response.GetHeaders().end())
7412  {
7413  const std::string& content_range = content_range_iterator->second;
7414  auto slash_pos = content_range.find("/");
7415  result.FileSize = std::stoll(content_range.substr(slash_pos + 1));
7416  }
7417  else
7418  {
7419  result.FileSize = std::stoll(response.GetHeaders().at(_detail::HeaderContentLength));
7420  }
7421  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7422  if (response.GetHeaders().find(_detail::HeaderTransactionalContentHashMd5)
7423  != response.GetHeaders().end())
7424  {
7425  result.TransactionalContentHash = _internal::FromBase64String(
7426  response.GetHeaders().at(_detail::HeaderTransactionalContentHashMd5),
7427  HashAlgorithm::Md5);
7428  }
7429  if (response.GetHeaders().find(_detail::HeaderContentEncoding)
7430  != response.GetHeaders().end())
7431  {
7432  result.HttpHeaders.ContentEncoding
7433  = response.GetHeaders().at(_detail::HeaderContentEncoding);
7434  }
7435  if (response.GetHeaders().find(_detail::HeaderCacheControl)
7436  != response.GetHeaders().end())
7437  {
7438  result.HttpHeaders.CacheControl
7439  = response.GetHeaders().at(_detail::HeaderCacheControl);
7440  }
7441  if (response.GetHeaders().find(_detail::HeaderContentDisposition)
7442  != response.GetHeaders().end())
7443  {
7444  result.HttpHeaders.ContentDisposition
7445  = response.GetHeaders().at(_detail::HeaderContentDisposition);
7446  }
7447  if (response.GetHeaders().find(_detail::HeaderContentLanguage)
7448  != response.GetHeaders().end())
7449  {
7450  result.HttpHeaders.ContentLanguage
7451  = response.GetHeaders().at(_detail::HeaderContentLanguage);
7452  }
7453  result.AcceptRanges = response.GetHeaders().at(_detail::HeaderAcceptRanges);
7454  if (response.GetHeaders().find(_detail::HeaderCopyCompletedOn)
7455  != response.GetHeaders().end())
7456  {
7457  result.CopyCompletedOn = DateTime::Parse(
7458  response.GetHeaders().at(_detail::HeaderCopyCompletedOn),
7459  DateTime::DateFormat::Rfc1123);
7460  }
7461  if (response.GetHeaders().find(_detail::HeaderCopyStatusDescription)
7462  != response.GetHeaders().end())
7463  {
7464  result.CopyStatusDescription
7465  = response.GetHeaders().at(_detail::HeaderCopyStatusDescription);
7466  }
7467  if (response.GetHeaders().find(_detail::HeaderCopyId) != response.GetHeaders().end())
7468  {
7469  result.CopyId = response.GetHeaders().at(_detail::HeaderCopyId);
7470  }
7471  if (response.GetHeaders().find(_detail::HeaderCopyProgress)
7472  != response.GetHeaders().end())
7473  {
7474  result.CopyProgress = response.GetHeaders().at(_detail::HeaderCopyProgress);
7475  }
7476  if (response.GetHeaders().find(_detail::HeaderCopySource)
7477  != response.GetHeaders().end())
7478  {
7479  result.CopySource = response.GetHeaders().at(_detail::HeaderCopySource);
7480  }
7481  if (response.GetHeaders().find(_detail::HeaderCopyStatus)
7482  != response.GetHeaders().end())
7483  {
7484  result.CopyStatus = CopyStatus(response.GetHeaders().at(_detail::HeaderCopyStatus));
7485  }
7486  if (response.GetHeaders().find(_detail::HeaderContentHashMd5)
7487  != response.GetHeaders().end())
7488  {
7489  result.HttpHeaders.ContentHash = _internal::FromBase64String(
7490  response.GetHeaders().at(_detail::HeaderContentHashMd5), HashAlgorithm::Md5);
7491  }
7492  if (response.GetHeaders().find(_detail::HeaderIsServerEncrypted)
7493  != response.GetHeaders().end())
7494  {
7495  result.IsServerEncrypted
7496  = response.GetHeaders().at(_detail::HeaderIsServerEncrypted) == "true";
7497  }
7498  result.SmbProperties.Attributes
7499  = FileAttributes(response.GetHeaders().at(_detail::HeaderAttributes));
7500  result.SmbProperties.CreatedOn = DateTime::Parse(
7501  response.GetHeaders().at(_detail::HeaderCreatedOn), DateTime::DateFormat::Rfc3339);
7502  result.SmbProperties.LastWrittenOn = DateTime::Parse(
7503  response.GetHeaders().at(_detail::HeaderLastWrittenOn),
7504  DateTime::DateFormat::Rfc3339);
7505  result.SmbProperties.ChangedOn = DateTime::Parse(
7506  response.GetHeaders().at(_detail::HeaderChangedOn), DateTime::DateFormat::Rfc3339);
7507  result.SmbProperties.PermissionKey
7508  = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
7509  result.SmbProperties.FileId = response.GetHeaders().at(_detail::HeaderFileId);
7510  result.SmbProperties.ParentFileId
7511  = response.GetHeaders().at(_detail::HeaderParentFileId);
7512  if (response.GetHeaders().find(_detail::HeaderLeaseDuration)
7513  != response.GetHeaders().end())
7514  {
7515  result.LeaseDuration
7516  = LeaseDuration(response.GetHeaders().at(_detail::HeaderLeaseDuration));
7517  }
7518  if (response.GetHeaders().find(_detail::HeaderLeaseState)
7519  != response.GetHeaders().end())
7520  {
7521  result.LeaseState = LeaseState(response.GetHeaders().at(_detail::HeaderLeaseState));
7522  }
7523  if (response.GetHeaders().find(_detail::HeaderLeaseStatus)
7524  != response.GetHeaders().end())
7525  {
7526  result.LeaseStatus
7527  = LeaseStatus(response.GetHeaders().at(_detail::HeaderLeaseStatus));
7528  }
7529  return Azure::Response<FileDownloadResult>(std::move(result), std::move(responsePtr));
7530  }
7531  else
7532  {
7533  (void)context;
7534  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7535  }
7536  }
7537 
7538  static Azure::Response<Models::FileProperties> GetPropertiesParseResult(
7539  Azure::Core::Context context,
7540  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7541  {
7542  auto& response = *responsePtr;
7543  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
7544  {
7545  // Success.
7546  Models::FileProperties result;
7547  result.LastModified = DateTime::Parse(
7548  response.GetHeaders().at(_detail::HeaderLastModified),
7549  DateTime::DateFormat::Rfc1123);
7550 
7551  for (auto i = response.GetHeaders().lower_bound(_detail::HeaderMetadata);
7552  i != response.GetHeaders().end()
7553  && i->first.substr(0, 9) == _detail::HeaderMetadata;
7554  ++i)
7555  {
7556  result.Metadata.emplace(i->first.substr(10), i->second);
7557  }
7558  result.FileSize = std::stoll(response.GetHeaders().at(_detail::HeaderContentLength));
7559  if (response.GetHeaders().find(_detail::HeaderContentType)
7560  != response.GetHeaders().end())
7561  {
7562  result.HttpHeaders.ContentType = response.GetHeaders().at(_detail::HeaderContentType);
7563  }
7564  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7565  if (response.GetHeaders().find(_detail::HeaderTransactionalContentHashMd5)
7566  != response.GetHeaders().end())
7567  {
7568  result.HttpHeaders.ContentHash = _internal::FromBase64String(
7569  response.GetHeaders().at(_detail::HeaderTransactionalContentHashMd5),
7570  HashAlgorithm::Md5);
7571  }
7572  if (response.GetHeaders().find(_detail::HeaderContentEncoding)
7573  != response.GetHeaders().end())
7574  {
7575  result.HttpHeaders.ContentEncoding
7576  = response.GetHeaders().at(_detail::HeaderContentEncoding);
7577  }
7578  if (response.GetHeaders().find(_detail::HeaderCacheControl)
7579  != response.GetHeaders().end())
7580  {
7581  result.HttpHeaders.CacheControl
7582  = response.GetHeaders().at(_detail::HeaderCacheControl);
7583  }
7584  if (response.GetHeaders().find(_detail::HeaderContentDisposition)
7585  != response.GetHeaders().end())
7586  {
7587  result.HttpHeaders.ContentDisposition
7588  = response.GetHeaders().at(_detail::HeaderContentDisposition);
7589  }
7590  if (response.GetHeaders().find(_detail::HeaderContentLanguage)
7591  != response.GetHeaders().end())
7592  {
7593  result.HttpHeaders.ContentLanguage
7594  = response.GetHeaders().at(_detail::HeaderContentLanguage);
7595  }
7596  if (response.GetHeaders().find(_detail::HeaderCopyCompletedOn)
7597  != response.GetHeaders().end())
7598  {
7599  result.CopyCompletedOn = DateTime::Parse(
7600  response.GetHeaders().at(_detail::HeaderCopyCompletedOn),
7601  DateTime::DateFormat::Rfc1123);
7602  }
7603  if (response.GetHeaders().find(_detail::HeaderCopyStatusDescription)
7604  != response.GetHeaders().end())
7605  {
7606  result.CopyStatusDescription
7607  = response.GetHeaders().at(_detail::HeaderCopyStatusDescription);
7608  }
7609  if (response.GetHeaders().find(_detail::HeaderCopyId) != response.GetHeaders().end())
7610  {
7611  result.CopyId = response.GetHeaders().at(_detail::HeaderCopyId);
7612  }
7613  if (response.GetHeaders().find(_detail::HeaderCopyProgress)
7614  != response.GetHeaders().end())
7615  {
7616  result.CopyProgress = response.GetHeaders().at(_detail::HeaderCopyProgress);
7617  }
7618  if (response.GetHeaders().find(_detail::HeaderCopySource)
7619  != response.GetHeaders().end())
7620  {
7621  result.CopySource = response.GetHeaders().at(_detail::HeaderCopySource);
7622  }
7623  if (response.GetHeaders().find(_detail::HeaderCopyStatus)
7624  != response.GetHeaders().end())
7625  {
7626  result.CopyStatus = CopyStatus(response.GetHeaders().at(_detail::HeaderCopyStatus));
7627  }
7628  if (response.GetHeaders().find(_detail::HeaderIsServerEncrypted)
7629  != response.GetHeaders().end())
7630  {
7631  result.IsServerEncrypted
7632  = response.GetHeaders().at(_detail::HeaderIsServerEncrypted) == "true";
7633  }
7634  result.SmbProperties.Attributes
7635  = FileAttributes(response.GetHeaders().at(_detail::HeaderAttributes));
7636  result.SmbProperties.CreatedOn = DateTime::Parse(
7637  response.GetHeaders().at(_detail::HeaderCreatedOn), DateTime::DateFormat::Rfc3339);
7638  result.SmbProperties.LastWrittenOn = DateTime::Parse(
7639  response.GetHeaders().at(_detail::HeaderLastWrittenOn),
7640  DateTime::DateFormat::Rfc3339);
7641  result.SmbProperties.ChangedOn = DateTime::Parse(
7642  response.GetHeaders().at(_detail::HeaderChangedOn), DateTime::DateFormat::Rfc3339);
7643  result.SmbProperties.PermissionKey
7644  = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
7645  result.SmbProperties.FileId = response.GetHeaders().at(_detail::HeaderFileId);
7646  result.SmbProperties.ParentFileId
7647  = response.GetHeaders().at(_detail::HeaderParentFileId);
7648  if (response.GetHeaders().find(_detail::HeaderLeaseDuration)
7649  != response.GetHeaders().end())
7650  {
7651  result.LeaseDuration
7652  = LeaseDuration(response.GetHeaders().at(_detail::HeaderLeaseDuration));
7653  }
7654  if (response.GetHeaders().find(_detail::HeaderLeaseState)
7655  != response.GetHeaders().end())
7656  {
7657  result.LeaseState = LeaseState(response.GetHeaders().at(_detail::HeaderLeaseState));
7658  }
7659  if (response.GetHeaders().find(_detail::HeaderLeaseStatus)
7660  != response.GetHeaders().end())
7661  {
7662  result.LeaseStatus
7663  = LeaseStatus(response.GetHeaders().at(_detail::HeaderLeaseStatus));
7664  }
7665  return Azure::Response<Models::FileProperties>(
7666  std::move(result), std::move(responsePtr));
7667  }
7668  else
7669  {
7670  (void)context;
7671  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7672  }
7673  }
7674 
7675  static Azure::Response<Models::DeleteFileResult> DeleteParseResult(
7676  Azure::Core::Context context,
7677  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7678  {
7679  auto& response = *responsePtr;
7680  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Accepted)
7681  {
7682  // Success (Accepted).
7683  Models::DeleteFileResult result;
7684  return Azure::Response<Models::DeleteFileResult>(
7685  std::move(result), std::move(responsePtr));
7686  }
7687  else
7688  {
7689  (void)context;
7690  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7691  }
7692  }
7693 
7694  static Azure::Response<Models::SetFilePropertiesResult> SetHttpHeadersParseResult(
7695  Azure::Core::Context context,
7696  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7697  {
7698  auto& response = *responsePtr;
7699  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
7700  {
7701  // Success
7702  Models::SetFilePropertiesResult result;
7703  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7704  result.LastModified = DateTime::Parse(
7705  response.GetHeaders().at(_detail::HeaderLastModified),
7706  DateTime::DateFormat::Rfc1123);
7707  result.IsServerEncrypted
7708  = response.GetHeaders().at(_detail::HeaderRequestIsServerEncrypted) == "true";
7709  result.SmbProperties.PermissionKey
7710  = response.GetHeaders().at(_detail::HeaderFilePermissionKey);
7711  result.SmbProperties.Attributes
7712  = FileAttributes(response.GetHeaders().at(_detail::HeaderAttributes));
7713  result.SmbProperties.CreatedOn = DateTime::Parse(
7714  response.GetHeaders().at(_detail::HeaderCreatedOn), DateTime::DateFormat::Rfc3339);
7715  result.SmbProperties.LastWrittenOn = DateTime::Parse(
7716  response.GetHeaders().at(_detail::HeaderLastWrittenOn),
7717  DateTime::DateFormat::Rfc3339);
7718  result.SmbProperties.ChangedOn = DateTime::Parse(
7719  response.GetHeaders().at(_detail::HeaderChangedOn), DateTime::DateFormat::Rfc3339);
7720  result.SmbProperties.FileId = response.GetHeaders().at(_detail::HeaderFileId);
7721  result.SmbProperties.ParentFileId
7722  = response.GetHeaders().at(_detail::HeaderParentFileId);
7723  return Azure::Response<Models::SetFilePropertiesResult>(
7724  std::move(result), std::move(responsePtr));
7725  }
7726  else
7727  {
7728  (void)context;
7729  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7730  }
7731  }
7732 
7733  static Azure::Response<Models::SetFileMetadataResult> SetMetadataParseResult(
7734  Azure::Core::Context context,
7735  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7736  {
7737  auto& response = *responsePtr;
7738  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
7739  {
7740  // Success (OK).
7741  Models::SetFileMetadataResult result;
7742  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7743  result.IsServerEncrypted
7744  = response.GetHeaders().at(_detail::HeaderRequestIsServerEncrypted) == "true";
7745  return Azure::Response<Models::SetFileMetadataResult>(
7746  std::move(result), std::move(responsePtr));
7747  }
7748  else
7749  {
7750  (void)context;
7751  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7752  }
7753  }
7754 
7755  static Azure::Response<FileAcquireLeaseResult> AcquireLeaseParseResult(
7756  Azure::Core::Context context,
7757  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7758  {
7759  auto& response = *responsePtr;
7760  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
7761  {
7762  // The Acquire operation completed successfully.
7763  FileAcquireLeaseResult result;
7764  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7765  result.LastModified = DateTime::Parse(
7766  response.GetHeaders().at(_detail::HeaderLastModified),
7767  DateTime::DateFormat::Rfc1123);
7768  result.LeaseId = response.GetHeaders().at(_detail::HeaderLeaseId);
7769  return Azure::Response<FileAcquireLeaseResult>(
7770  std::move(result), std::move(responsePtr));
7771  }
7772  else
7773  {
7774  (void)context;
7775  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7776  }
7777  }
7778 
7779  static Azure::Response<FileReleaseLeaseResult> ReleaseLeaseParseResult(
7780  Azure::Core::Context context,
7781  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7782  {
7783  auto& response = *responsePtr;
7784  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
7785  {
7786  // The Release operation completed successfully.
7787  FileReleaseLeaseResult result;
7788  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7789  result.LastModified = DateTime::Parse(
7790  response.GetHeaders().at(_detail::HeaderLastModified),
7791  DateTime::DateFormat::Rfc1123);
7792  return Azure::Response<FileReleaseLeaseResult>(
7793  std::move(result), std::move(responsePtr));
7794  }
7795  else
7796  {
7797  (void)context;
7798  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7799  }
7800  }
7801 
7802  static Azure::Response<FileChangeLeaseResult> ChangeLeaseParseResult(
7803  Azure::Core::Context context,
7804  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7805  {
7806  auto& response = *responsePtr;
7807  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
7808  {
7809  // The Change operation completed successfully.
7810  FileChangeLeaseResult result;
7811  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7812  result.LastModified = DateTime::Parse(
7813  response.GetHeaders().at(_detail::HeaderLastModified),
7814  DateTime::DateFormat::Rfc1123);
7815  result.LeaseId = response.GetHeaders().at(_detail::HeaderLeaseId);
7816  return Azure::Response<FileChangeLeaseResult>(
7817  std::move(result), std::move(responsePtr));
7818  }
7819  else
7820  {
7821  (void)context;
7822  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7823  }
7824  }
7825 
7826  static Azure::Response<FileBreakLeaseResult> BreakLeaseParseResult(
7827  Azure::Core::Context context,
7828  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7829  {
7830  auto& response = *responsePtr;
7831  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Accepted)
7832  {
7833  // The Break operation completed successfully.
7834  FileBreakLeaseResult result;
7835  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7836  result.LastModified = DateTime::Parse(
7837  response.GetHeaders().at(_detail::HeaderLastModified),
7838  DateTime::DateFormat::Rfc1123);
7839  if (response.GetHeaders().find(_detail::HeaderLeaseId) != response.GetHeaders().end())
7840  {
7841  result.LeaseId = response.GetHeaders().at(_detail::HeaderLeaseId);
7842  }
7843  return Azure::Response<FileBreakLeaseResult>(std::move(result), std::move(responsePtr));
7844  }
7845  else
7846  {
7847  (void)context;
7848  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7849  }
7850  }
7851 
7852  static Azure::Response<Models::UploadFileRangeResult> UploadRangeParseResult(
7853  Azure::Core::Context context,
7854  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7855  {
7856  auto& response = *responsePtr;
7857  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
7858  {
7859  // Success (Created).
7860  Models::UploadFileRangeResult result;
7861  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7862  result.LastModified = DateTime::Parse(
7863  response.GetHeaders().at(_detail::HeaderLastModified),
7864  DateTime::DateFormat::Rfc1123);
7865  if (response.GetHeaders().find(_detail::HeaderTransactionalContentHashMd5)
7866  != response.GetHeaders().end())
7867  {
7868  result.TransactionalContentHash = _internal::FromBase64String(
7869  response.GetHeaders().at(_detail::HeaderTransactionalContentHashMd5),
7870  HashAlgorithm::Md5);
7871  }
7872  if (response.GetHeaders().find(_detail::HeaderRequestIsServerEncrypted)
7873  != response.GetHeaders().end())
7874  {
7875  result.IsServerEncrypted
7876  = response.GetHeaders().at(_detail::HeaderRequestIsServerEncrypted) == "true";
7877  }
7878  return Azure::Response<Models::UploadFileRangeResult>(
7879  std::move(result), std::move(responsePtr));
7880  }
7881  else
7882  {
7883  (void)context;
7884  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7885  }
7886  }
7887 
7888  static Azure::Response<Models::UploadFileRangeFromUriResult> UploadRangeFromUrlParseResult(
7889  Azure::Core::Context context,
7890  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7891  {
7892  auto& response = *responsePtr;
7893  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Created)
7894  {
7895  // Success (Created).
7896  Models::UploadFileRangeFromUriResult result;
7897  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7898  result.LastModified = DateTime::Parse(
7899  response.GetHeaders().at(_detail::HeaderLastModified),
7900  DateTime::DateFormat::Rfc1123);
7901  result.TransactionalContentHash = _internal::FromBase64String(
7902  response.GetHeaders().at(_detail::HeaderTransactionalContentHashCrc64),
7903  HashAlgorithm::Crc64);
7904  result.IsServerEncrypted
7905  = response.GetHeaders().at(_detail::HeaderRequestIsServerEncrypted) == "true";
7906  return Azure::Response<Models::UploadFileRangeFromUriResult>(
7907  std::move(result), std::move(responsePtr));
7908  }
7909  else
7910  {
7911  (void)context;
7912  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7913  }
7914  }
7915 
7916  static Azure::Response<Models::GetFileRangeListResult> GetRangeListParseResult(
7917  Azure::Core::Context context,
7918  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
7919  {
7920  auto& response = *responsePtr;
7921  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
7922  {
7923  // Success.
7924  const auto& bodyBuffer = response.GetBody();
7925  auto reader = _internal::XmlReader(
7926  reinterpret_cast<const char*>(bodyBuffer.data()), bodyBuffer.size());
7927  Models::GetFileRangeListResult result = bodyBuffer.empty()
7928  ? Models::GetFileRangeListResult()
7929  : GetFileRangeListResultFromRangeList(RangeListFromXml(reader));
7930  result.LastModified = DateTime::Parse(
7931  response.GetHeaders().at(_detail::HeaderLastModified),
7932  DateTime::DateFormat::Rfc1123);
7933  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
7934  result.FileSize = std::stoll(response.GetHeaders().at(_detail::HeaderXMsContentLength));
7935  return Azure::Response<Models::GetFileRangeListResult>(
7936  std::move(result), std::move(responsePtr));
7937  }
7938  else
7939  {
7940  (void)context;
7941  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
7942  }
7943  }
7944 
7945  static RangeList RangeListFromXml(_internal::XmlReader& reader)
7946  {
7947  auto result = RangeList();
7948  enum class XmlTagName
7949  {
7950  ClearRange,
7951  Range,
7952  Ranges,
7953  Unknown,
7954  };
7955  std::vector<XmlTagName> path;
7956 
7957  while (true)
7958  {
7959  auto node = reader.Read();
7960  if (node.Type == _internal::XmlNodeType::End)
7961  {
7962  break;
7963  }
7964  else if (node.Type == _internal::XmlNodeType::EndTag)
7965  {
7966  if (path.size() > 0)
7967  {
7968  path.pop_back();
7969  }
7970  else
7971  {
7972  break;
7973  }
7974  }
7975  else if (node.Type == _internal::XmlNodeType::StartTag)
7976  {
7977 
7978  if (std::strcmp(node.Name, "ClearRange") == 0)
7979  {
7980  path.emplace_back(XmlTagName::ClearRange);
7981  }
7982  else if (std::strcmp(node.Name, "Range") == 0)
7983  {
7984  path.emplace_back(XmlTagName::Range);
7985  }
7986  else if (std::strcmp(node.Name, "Ranges") == 0)
7987  {
7988  path.emplace_back(XmlTagName::Ranges);
7989  }
7990  else
7991  {
7992  path.emplace_back(XmlTagName::Unknown);
7993  }
7994  if (path.size() == 2 && path[0] == XmlTagName::Ranges && path[1] == XmlTagName::Range)
7995  {
7996  result.Ranges.emplace_back(HttpRangeFromXml(reader));
7997  path.pop_back();
7998  }
7999  else if (
8000  path.size() == 2 && path[0] == XmlTagName::Ranges
8001  && path[1] == XmlTagName::ClearRange)
8002  {
8003  result.ClearRanges.emplace_back(HttpRangeFromXml(reader));
8004  path.pop_back();
8005  }
8006  }
8007  else if (node.Type == _internal::XmlNodeType::Text)
8008  {
8009  }
8010  }
8011  return result;
8012  }
8013 
8014  static Models::GetFileRangeListResult GetFileRangeListResultFromRangeList(RangeList object)
8015  {
8016  Models::GetFileRangeListResult result;
8017  result.Ranges = std::move(object.Ranges);
8018  result.ClearRanges = std::move(object.ClearRanges);
8019 
8020  return result;
8021  }
8022  static Azure::Response<FileStartCopyResult> StartCopyParseResult(
8023  Azure::Core::Context context,
8024  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
8025  {
8026  auto& response = *responsePtr;
8027  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Accepted)
8028  {
8029  // The copy file has been accepted with the specified copy status.
8030  FileStartCopyResult result;
8031  result.ETag = Azure::ETag(response.GetHeaders().at(_detail::HeaderETag));
8032  result.LastModified = DateTime::Parse(
8033  response.GetHeaders().at(_detail::HeaderLastModified),
8034  DateTime::DateFormat::Rfc1123);
8035  if (response.GetHeaders().find(_detail::HeaderCopyId) != response.GetHeaders().end())
8036  {
8037  result.CopyId = response.GetHeaders().at(_detail::HeaderCopyId);
8038  }
8039  if (response.GetHeaders().find(_detail::HeaderCopyStatus)
8040  != response.GetHeaders().end())
8041  {
8042  result.CopyStatus = CopyStatus(response.GetHeaders().at(_detail::HeaderCopyStatus));
8043  }
8044  return Azure::Response<FileStartCopyResult>(std::move(result), std::move(responsePtr));
8045  }
8046  else
8047  {
8048  (void)context;
8049  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
8050  }
8051  }
8052 
8053  static Azure::Response<Models::AbortFileCopyResult> AbortCopyParseResult(
8054  Azure::Core::Context context,
8055  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
8056  {
8057  auto& response = *responsePtr;
8058  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::NoContent)
8059  {
8060  // The delete request was accepted and the file will be deleted.
8061  Models::AbortFileCopyResult result;
8062  return Azure::Response<Models::AbortFileCopyResult>(
8063  std::move(result), std::move(responsePtr));
8064  }
8065  else
8066  {
8067  (void)context;
8068  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
8069  }
8070  }
8071 
8072  static Azure::Response<FileListHandlesResult> ListHandlesParseResult(
8073  Azure::Core::Context context,
8074  std::unique_ptr<Azure::Core::Http::RawResponse> responsePtr)
8075  {
8076  auto& response = *responsePtr;
8077  if (response.GetStatusCode() == Azure::Core::Http::HttpStatusCode::Ok)
8078  {
8079  // Success.
8080  const auto& bodyBuffer = response.GetBody();
8081  auto reader = _internal::XmlReader(
8082  reinterpret_cast<const char*>(bodyBuffer.data()), bodyBuffer.size());
8083  FileListHandlesResult result = bodyBuffer.empty()
8084  ? FileListHandlesResult()
8085  : FileListHandlesResultFromListHandlesResponse(ListHandlesResponseFromXml(reader));
8086  result.HttpHeaders.ContentType = response.GetHeaders().at(_detail::HeaderContentType);
8087  return Azure::Response<FileListHandlesResult>(
8088  std::move(result), std::move(responsePtr));
8089  }
8090  else
8091  {
8092  (void)context;
8093  throw Storage::StorageException::CreateFromResponse(std::move(responsePtr));
8094  }
8095  }
8096 
8097  static HandleItem HandleItemFromXml(_internal::XmlReader& reader)
8098  {
8099  auto result = HandleItem();
8100  enum class XmlTagName
8101  {
8102  ClientIp,
8103  FileId,
8104  HandleId,
8105  LastReconnectTime,
8106  OpenTime,
8107  ParentId,
8108  Path,
8109  SessionId,
8110  Unknown,
8111  };
8112  std::vector<XmlTagName> path;
8113 
8114  while (true)
8115  {
8116  auto node = reader.Read();
8117  if (node.Type == _internal::XmlNodeType::End)
8118  {
8119  break;
8120  }
8121  else if (node.Type == _internal::XmlNodeType::EndTag)
8122  {