public static FileRipperResult TryOpenFile(string path, ContainerHandler handler = null) { if (!File.Exists(path)) { return(new FileRipperResult(RipResultCode.FileExist)); } if (handler == null) { handler = DefaultHandler; } try { using var fs = new FileStream(path, FileMode.Open, FileAccess.Read); using var br = new BinaryReader(fs); if (br.BaseStream.Length < 4) { return(new FileRipperResult(RipResultCode.BadSize)); } var header = br.ReadUInt32(); var result = TryLoadFile(br, header, path, handler); if (result.Code == RipResultCode.Success) { return(result); } } catch (Exception e) { Debug.WriteLine(e.Message); return(new FileRipperResult(RipResultCode.ReadError)); } return(new FileRipperResult(RipResultCode.UnknownFormat)); }
Expression BlobContainer(ContainerHandler handler) { Debug.Assert(schemaType.IsBondBlob()); var arraySegment = Expression.Variable(typeof(ArraySegment <byte>), "arraySegment"); var count = Expression.Variable(typeof(int), "count"); var index = Expression.Variable(typeof(int), "index"); var end = Expression.Variable(typeof(int), "end"); var blob = typeAlias.Convert(value, schemaType); var item = Expression.ArrayIndex(Expression.Property(arraySegment, "Array"), Expression.PostIncrementAssign(index)); var loop = handler( new ObjectParser(this, item, typeof(sbyte)), Expression.Constant(BondDataType.BT_INT8), Expression.LessThan(index, end), count); return(Expression.Block( new[] { arraySegment, count, index, end }, Expression.Assign(arraySegment, blob), Expression.Assign(index, Expression.Property(arraySegment, "Offset")), Expression.Assign(count, Expression.Property(arraySegment, "Count")), Expression.Assign(end, Expression.Add(index, count)), loop)); }
public override Expression Container(BondDataType?expectedType, ContainerHandler handler) { var parser = new SimpleJsonParser <R>(this, Schema.GetElementSchema()); var elementType = Expression.Constant(Schema.TypeDef.element.id); // if the json contains null instead of an array, simulate an empty list to deserialize a null value // into a nullable var readJsonNullAsEmptyList = Expression.Block( Reader.Read(), handler(parser, elementType, Expression.Constant(false), Expression.Constant(0), null)); // if the json contains an array, read the array into the list var readJsonArrayAsList = Expression.Block( Reader.Read(), handler(parser, elementType, JsonTokenNotEquals(JsonToken.EndArray), Expression.Constant(0), null), Reader.Read()); return(Expression.IfThenElse( JsonTokenEquals(JsonToken.Null), readJsonNullAsEmptyList, Expression.IfThenElse( JsonTokenEquals(JsonToken.StartArray), readJsonArrayAsList, ThrowUnexpectedInput("Expected JSON array or null.")))); }
private static RipResult NSODump(BinaryReader br, uint header, string path, ContainerHandler handler) { if (header != NSOHeader.ExpectedMagic) { return(new RipResult(RipResultCode.UnknownFormat)); } br.BaseStream.Position = 0; var nso = new NSO(br); var dir = Path.GetDirectoryName(path); var folder = Path.GetFileNameWithoutExtension(path); var resultPath = Path.Combine(dir, folder); if (resultPath == path) { resultPath += "_nso"; } Directory.CreateDirectory(resultPath); File.WriteAllBytes(Path.Combine(resultPath, "text.bin"), nso.DecompressedText); File.WriteAllBytes(Path.Combine(resultPath, "data.bin"), nso.DecompressedData); File.WriteAllBytes(Path.Combine(resultPath, "ro.bin"), nso.DecompressedRO); return(new RipResult(RipResultCode.Success) { ResultPath = resultPath }); }
public override Expression Container(BondDataType?expectedType, ContainerHandler handler) { return(Items(nextItem => handler( new SimpleXmlParser <R>(this, Schema.GetElementSchema()), Expression.Constant(Schema.TypeDef.element.id), nextItem, Expression.Constant(0)))); }
public sw.FrameworkElement SetupCell(sw.FrameworkElement defaultContent) { if (ContainerHandler != null) { return(ContainerHandler.SetupCell(this, defaultContent)); } else { return(defaultContent); } }
public Expression Container(BondDataType?expectedType, ContainerHandler handler) { var count = Expression.Variable(typeof(int), "count"); var elementType = Expression.Variable(typeof(BondDataType), "elementType"); var next = Expression.GreaterThan(Expression.PostDecrementAssign(count), Expression.Constant(0)); var loops = MatchOrCompatible( elementType, expectedType, type => handler(this, type, next, count)); return(Expression.Block( new[] { count, elementType }, reader.ReadContainerBegin(count, elementType), loops, reader.ReadContainerEnd())); }
public Expression Container(BondDataType?expectedType, ContainerHandler handler) { Debug.Assert(schema.IsContainer); var count = Expression.Variable(typeof(int), "count"); var loop = handler( new UntaggedParser <R>(this, schema.GetElementSchema()), Expression.Constant(schema.TypeDef.element.id), Expression.GreaterThan(Expression.PostDecrementAssign(count), Expression.Constant(0)), count); return(Expression.Block( new[] { count }, Expression.Assign(count, reader.ReadContainerBegin()), loop, reader.ReadContainerEnd())); }
Expression Nullable(ContainerHandler handler) { Debug.Assert(schemaType.IsBondNullable()); var valueType = schemaType.GetValueType(); var count = Expression.Variable(typeof(int), "count"); ParameterExpression convertedBlob = null; var nullableValue = value; var valueParser = new ObjectParser(this, value, valueType); if (valueType.IsBondBlob()) { convertedBlob = Expression.Variable(typeof(ArraySegment <byte>), "convertedBlob"); nullableValue = Expression.Property(convertedBlob, "Array"); valueParser = new ObjectParser(this, convertedBlob, convertedBlob.Type); } var notNull = Expression.NotEqual(nullableValue, Expression.Constant(null)); var loop = handler( valueParser, Expression.Constant(valueType.GetBondDataType()), Expression.NotEqual(Expression.PostDecrementAssign(count), Expression.Constant(0)), count, null); if (convertedBlob != null) { return(Expression.Block( new[] { convertedBlob, count }, Expression.Assign(convertedBlob, typeAlias.Convert(value, valueType)), Expression.Assign(count, Expression.Condition(notNull, Expression.Constant(1), Expression.Constant(0))), loop)); } else { return(Expression.Block( new[] { count }, Expression.Assign(count, Expression.Condition(notNull, Expression.Constant(1), Expression.Constant(0))), loop)); } }
private async Task <HttpResponseMessage> SetContainerAcl(CloudBlobContainer container) { var formatter = GlobalConfiguration.Configuration.Formatters.XmlFormatter; var stream = await Request.Content.ReadAsStreamAsync(); SharedAccessBlobPolicies policies = (SharedAccessBlobPolicies)await formatter.ReadFromStreamAsync(typeof(SharedAccessBlobPolicies), stream, null, null); string accessLevel = Request.Headers.GetValues("x-ms-blob-public-access").FirstOrDefault(); BlobContainerPublicAccessType access = BlobContainerPublicAccessType.Off; if (!String.IsNullOrWhiteSpace(accessLevel)) { if (accessLevel.ToLower() == "blob") { access = BlobContainerPublicAccessType.Blob; } else if (accessLevel.ToLower() == "container") { access = BlobContainerPublicAccessType.Container; } } BlobContainerPermissions perms = new BlobContainerPermissions() { PublicAccess = access }; foreach (var policy in policies) { perms.SharedAccessPolicies.Add(policy); } var status = await ContainerHandler.DoForAllContainersAsync(container.Name, HttpStatusCode.OK, async containerObj => await containerObj.SetPermissionsAsync(perms), true); HttpResponseMessage response = new HttpResponseMessage(status.StatusCode); await AddBasicContainerHeaders(response, container); return(response); }
public Expression Container(BondDataType?expectedType, ContainerHandler handler) { if (schemaType.IsBondNullable()) { return(Nullable(handler)); } if (schemaType.IsBondBlob()) { return(BlobContainer(handler)); } var itemType = schemaType.GetValueType(); ContainerItemHandler itemHandler = (item, next, count) => handler( new ObjectParser(this, item, itemType), Expression.Constant(itemType.GetBondDataType()), next, count, null); if (value.Type.IsArray) { return(ArrayContainer(itemHandler)); } if (value.Type.IsGenericType()) { if (typeof(IList <>).MakeGenericType(value.Type.GetTypeInfo().GenericTypeArguments[0]).IsAssignableFrom(value.Type)) { return(ListContainer(itemHandler)); } if (typeof(LinkedList <>) == value.Type.GetGenericTypeDefinition()) { return(LinkedListContainer(itemHandler)); } } return(EnumerableContainer(itemHandler)); }
Expression Nullable(ContainerHandler handler) { Debug.Assert(schemaType.IsBondNullable()); var valueType = schemaType.GetValueType(); var count = Expression.Variable(typeof(int), "count"); var nullableValue = valueType.IsBondBlob() ? Expression.Property(typeAlias.Convert(value, valueType), "Array") : value; var notNull = Expression.NotEqual(nullableValue, Expression.Constant(null)); var loop = handler( new ObjectParser(this, value, valueType), Expression.Constant(valueType.GetBondDataType()), Expression.NotEqual(Expression.PostDecrementAssign(count), Expression.Constant(0)), count); return(Expression.Block( new[] { count }, Expression.Assign(count, Expression.Condition(notNull, Expression.Constant(1), Expression.Constant(0))), loop)); }
public void FormatCell(sw.FrameworkElement element, swc.DataGridCell cell, object dataItem) { ContainerHandler.FormatCell(this, element, cell, dataItem); }
public abstract Expression Container(BondDataType?expectedType, ContainerHandler handler);
public ClientHandler(string basePath, ClientCreateArgs createArgs) { basePath = basePath ?? ""; BasePath = basePath; CreateArgs = createArgs; string flavorInfoProductCode = null; if (createArgs.UseContainer && !Directory.Exists(basePath)) { throw new FileNotFoundException("invalid archive directory"); } var dbPath = Path.Combine(basePath, createArgs.ProductDatabaseFilename); try { if (File.Exists(dbPath)) { using (var _ = new PerfCounter("AgentDatabase::ctor`string`bool")) foreach (var install in new AgentDatabase(dbPath).Data.ProductInstall) { if (string.IsNullOrEmpty(createArgs.Flavor) || install.Settings.GameSubfolder.Contains(createArgs.Flavor)) { AgentProduct = install; break; } } if (AgentProduct == null) { throw new InvalidDataException(); } Product = ProductHelpers.ProductFromUID(AgentProduct.ProductCode); } else { throw new InvalidDataException(); } } catch { try { if (File.Exists(Path.Combine(basePath, ".flavor.info"))) { // mixed installation, store the product code to be used below flavorInfoProductCode = File.ReadLines(Path.Combine(basePath, ".flavor.info")).Skip(1).First(); Product = ProductHelpers.ProductFromUID(flavorInfoProductCode); BasePath = basePath = Path.Combine(basePath, "../"); // lmao Logger.Info("Core", $".flavor.info detected. Found product \"{flavorInfoProductCode}\""); } else { throw new InvalidDataException(); } } catch { try { Product = ProductHelpers.ProductFromLocalInstall(basePath); } catch { if (createArgs.VersionSource == ClientCreateArgs.InstallMode.Local) // if we need an archive then we should be able to detect the product { throw; } Product = createArgs.OnlineProduct; } } AgentProduct = new ProductInstall { ProductCode = flavorInfoProductCode ?? createArgs.Product ?? ProductHelpers.UIDFromProduct(Product), Settings = new UserSettings { SelectedTextLanguage = createArgs.TextLanguage ?? "enUS", SelectedSpeechLanguage = createArgs.SpeechLanguage ?? "enUS", PlayRegion = "us" } }; if (AgentProduct.Settings.SelectedSpeechLanguage == AgentProduct.Settings.SelectedTextLanguage) { AgentProduct.Settings.Languages.Add(new LanguageSetting { Language = AgentProduct.Settings.SelectedTextLanguage, Option = LanguageOption.LangoptionTextAndSpeech }); } else { AgentProduct.Settings.Languages.Add(new LanguageSetting { Language = AgentProduct.Settings.SelectedTextLanguage, Option = LanguageOption.LangoptionText }); AgentProduct.Settings.Languages.Add(new LanguageSetting { Language = AgentProduct.Settings.SelectedSpeechLanguage, Option = LanguageOption.LangoptionSpeech }); } } if (string.IsNullOrWhiteSpace(createArgs.TextLanguage)) { createArgs.TextLanguage = AgentProduct.Settings.SelectedTextLanguage; } if (string.IsNullOrWhiteSpace(createArgs.SpeechLanguage)) { createArgs.SpeechLanguage = AgentProduct.Settings.SelectedSpeechLanguage; } if (createArgs.Online) { using var _ = new PerfCounter("INetworkHandler::ctor`ClientHandler"); if (createArgs.OnlineRootHost.StartsWith("ribbit:")) { NetHandle = new RibbitCDNClient(this); } else { NetHandle = new NGDPClient(this); } } if (createArgs.VersionSource == ClientCreateArgs.InstallMode.Local) { var installationInfoPath = Path.Combine(basePath, createArgs.InstallInfoFileName) + createArgs.ExtraFileEnding; if (!File.Exists(installationInfoPath)) { throw new FileNotFoundException(installationInfoPath); } using var _ = new PerfCounter("InstallationInfo::ctor`string"); InstallationInfo = new InstallationInfo(installationInfoPath, AgentProduct.ProductCode); } else { using var _ = new PerfCounter("InstallationInfo::ctor`INetworkHandler"); InstallationInfo = new InstallationInfo(NetHandle, createArgs.OnlineRegion); } Logger.Info("CASC", $"{Product} build {InstallationInfo.Values["Version"]}"); if (createArgs.UseContainer) { Logger.Info("CASC", "Initializing..."); using var _ = new PerfCounter("ContainerHandler::ctor`ClientHandler"); ContainerHandler = new ContainerHandler(this); } using (var _ = new PerfCounter("ConfigHandler::ctor`ClientHandler")) ConfigHandler = new ConfigHandler(this); using (var _ = new PerfCounter("EncodingHandler::ctor`ClientHandler")) EncodingHandler = new EncodingHandler(this); if (ConfigHandler.BuildConfig.VFSRoot != null) { using var _ = new PerfCounter("VFSFileTree::ctor`ClientHandler"); VFS = new VFSFileTree(this); } if (createArgs.Online) { m_cdnIdx = CDNIndexHandler.Initialize(this); } using (var _ = new PerfCounter("ProductHandlerFactory::GetHandler`TACTProduct`ClientHandler`Stream")) ProductHandler = ProductHandlerFactory.GetHandler(Product, this, OpenCKey(ConfigHandler.BuildConfig.Root.ContentKey)); Logger.Info("CASC", "Ready"); }
/// <summary> /// Packs the <see cref="LargeContainer"/> to the specified writing stream. /// </summary> /// <param name="bw">Stream Writer to write contents to.</param> /// <param name="handler">Manager for monitoring progress.</param> /// <param name="token">Cancellation object</param> /// <returns>Awaitable Task</returns> protected abstract Task Pack(BinaryWriter bw, ContainerHandler handler, CancellationToken token);
Expression BlobContainer(ContainerHandler handler) { Debug.Assert(schemaType.IsBondBlob()); var arraySegment = Expression.Variable(typeof(ArraySegment<byte>), "arraySegment"); var count = Expression.Variable(typeof(int), "count"); var index = Expression.Variable(typeof(int), "index"); var end = Expression.Variable(typeof(int), "end"); var blob = typeAlias.Convert(value, schemaType); var item = Expression.ArrayIndex(Expression.Property(arraySegment, "Array"), Expression.PostIncrementAssign(index)); var loop = handler( new ObjectParser(this, item, typeof(sbyte)), Expression.Constant(BondDataType.BT_INT8), Expression.LessThan(index, end), count); return Expression.Block( new[] { arraySegment, count, index, end }, Expression.Assign(arraySegment, blob), Expression.Assign(index, Expression.Property(arraySegment, "Offset")), Expression.Assign(count, Expression.Property(arraySegment, "Count")), Expression.Assign(end, Expression.Add(index, count)), loop); }
public sw.FrameworkElement SetupCell(sw.FrameworkElement defaultContent) { return(ContainerHandler != null?ContainerHandler.SetupCell(this, defaultContent) : defaultContent); }
public Expression Container(BondDataType?expectedType, ContainerHandler handler) { throw new System.NotImplementedException(); }
public async Task <HttpResponseMessage> DeleteContainer(string container) { return(new DelegatedResponse(await ContainerHandler.DeleteContainer(container)).CreateResponse()); }
private static RipResult TryLoadFile(BinaryReader br, uint header, string path, ContainerHandler handler) { foreach (var method in Loaders) { try { var result = method(br, header, path, handler); if (result.Code == RipResultCode.Success) { return(result); } } catch (Exception e) { Debug.WriteLine(e.Message); } } return(new RipResult(RipResultCode.UnknownFormat)); }
public Expression Container(BondDataType? expectedType, ContainerHandler handler) { if (schemaType.IsBondNullable()) return Nullable(handler); if (schemaType.IsBondBlob()) return BlobContainer(handler); var itemType = schemaType.GetValueType(); ContainerItemHandler itemHandler = (item, next, count) => handler( new ObjectParser(this, item, itemType), Expression.Constant(itemType.GetBondDataType()), next, count); if (value.Type.IsArray) return ArrayContainer(itemHandler); if (value.Type.IsGenericType()) { if (typeof(IList<>).MakeGenericType(value.Type.GetGenericArguments()[0]).IsAssignableFrom(value.Type)) return ListContainer(itemHandler); if (typeof(LinkedList<>) == value.Type.GetGenericTypeDefinition()) return LinkedListContainer(itemHandler); } return EnumerableContainer(itemHandler); }
// Gera o container de scripts (arquivo XML), recebe como parâmetro a localização dos scripts que é // o diretório raiz de uma estrutura de diretórios contendo scripts T-SQL private static void BuildScriptsXml(String scriptsLocation) // exemplo: "C:\Users\renato\Desktop\Scripts" { ContainerHandler containerHandler = new ContainerHandler(); containerHandler.BuildContainer("ScriptFiles.xml", scriptsLocation); }
public static async Task ImportAccountAsync(string accountName) { await OperationRunner.DoActionAsync(String.Format("Importing data account: {0}", accountName), async() => { // This method will only import the blobs into the namespace. A future task may be // to redistribute the blobs to balance the entire virtual account. var account = DashConfiguration.GetDataAccountByAccountName(accountName); if (account == null) { DashTrace.TraceWarning("Failure importing storage account: {0}. The storage account has not been configured as part of this virtual account", accountName); return; } // Check if we've already imported this account var accountClient = account.CreateCloudBlobClient(); var namespaceClient = DashConfiguration.NamespaceAccount.CreateCloudBlobClient(); var accountContainers = await ListContainersAsync(accountClient); var status = await AccountStatus.GetAccountStatus(accountName); await status.UpdateStatusInformation(AccountStatus.States.Healthy, "Importing storage account: {0} into virtual account", accountName); bool alreadyImported = false; await GetAccountBlobs(accountClient, async(blobItem) => { var blob = (ICloudBlob)blobItem; var namespaceBlob = await NamespaceBlob.FetchForBlobAsync( (CloudBlockBlob)NamespaceHandler.GetBlobByName(DashConfiguration.NamespaceAccount, blob.Container.Name, blob.Name, blob.IsSnapshot ? blob.SnapshotTime.ToString() : String.Empty)); alreadyImported = await namespaceBlob.ExistsAsync(true) && namespaceBlob.DataAccounts.Contains(accountName, StringComparer.OrdinalIgnoreCase); return(false); }); if (alreadyImported) { await status.UpdateStatusWarning("Importing storage account: {0} has already been imported. This account cannot be imported again.", accountName); return; } // Sync the container structure first - add containers in the imported account to the virtual account await status.UpdateStatusInformation("Importing storage account: {0}. Synchronizing container structure", accountName); int containersAddedCount = 0, containersWarningCount = 0; var namespaceContainers = await ListContainersAsync(namespaceClient); await ProcessContainerDifferencesAsync(accountContainers, namespaceContainers, async(newContainerName, accountContainer) => { var createContainerResult = await ContainerHandler.DoForAllContainersAsync(newContainerName, HttpStatusCode.Created, async newContainer => await CopyContainer(accountContainer, newContainer), true, new[] { account }); if (createContainerResult.StatusCode < HttpStatusCode.OK || createContainerResult.StatusCode >= HttpStatusCode.Ambiguous) { await status.UpdateStatusWarning("Importing storage account: {0}. Failed to create container: {1} in virtual account. Details: {2}, {3}", accountName, newContainerName, createContainerResult.StatusCode.ToString(), createContainerResult.ReasonPhrase); containersWarningCount++; } else { containersAddedCount++; } }, (newContainerName, ex) => { status.UpdateStatusWarning("Importing storage account: {0}. Error processing container {1}. Details: {2}", accountName, newContainerName, ex.ToString()).Wait(); containersWarningCount++; }); // Sync the other way await ProcessContainerDifferencesAsync(namespaceContainers, accountContainers, async(newContainerName, namespaceContainer) => { await CopyContainer(namespaceContainer, accountClient.GetContainerReference(newContainerName)); }, (newContainerName, ex) => { status.UpdateStatusWarning("Importing storage account: {0}. Error replicating container {1} to imported account. Details: {2}", accountName, newContainerName, ex.ToString()).Wait(); containersWarningCount++; }); DashTrace.TraceInformation("Importing storage account: {0}. Synchronized containers structure. {1} containers added to virtual account. {2} failures/warnings.", accountName, containersAddedCount, containersWarningCount); // Start importing namespace entries await status.UpdateStatusInformation("Importing storage account: {0}. Adding blob entries to namespace", accountName); int blobsAddedCount = 0, warningCount = 0, duplicateCount = 0; await GetAccountBlobs(accountClient, async(blobItem) => { var blob = (ICloudBlob)blobItem; try { var namespaceBlob = await NamespaceBlob.FetchForBlobAsync( (CloudBlockBlob)NamespaceHandler.GetBlobByName(DashConfiguration.NamespaceAccount, blob.Container.Name, blob.Name, blob.IsSnapshot ? blob.SnapshotTime.ToString() : String.Empty)); if (await namespaceBlob.ExistsAsync()) { if (!String.Equals(namespaceBlob.PrimaryAccountName, accountName, StringComparison.OrdinalIgnoreCase)) { await status.UpdateStatusWarning("Importing storage account: {0}. Adding blob: {1}/{2} would result in a duplicate blob entry. This blob will NOT be imported into the virtual account. Manually add the contents of this blob to the virtual account.", accountName, blob.Container.Name, blob.Name); duplicateCount++; } } else { namespaceBlob.PrimaryAccountName = accountName; namespaceBlob.Container = blob.Container.Name; namespaceBlob.BlobName = blob.Name; namespaceBlob.IsMarkedForDeletion = false; await namespaceBlob.SaveAsync(); blobsAddedCount++; } } catch (StorageException ex) { status.UpdateStatusWarning("Importing storage account: {0}. Error importing blob: {0}/{1} into virtual namespace. Details: {3}", accountName, blob.Container.Name, blob.Name, ex.ToString()).Wait(); warningCount++; } return(true); }); if (status.State < AccountStatus.States.Warning) { await status.UpdateStatus(String.Empty, AccountStatus.States.Unknown, TraceLevel.Off); } DashTrace.TraceInformation("Successfully imported the contents of storage account: '{0}' into the virtual namespace. Blobs added: {1}, duplicates detected: {2}, errors encountered: {3}", accountName, blobsAddedCount, duplicateCount, warningCount); }, ex => { var status = AccountStatus.GetAccountStatus(accountName).Result; status.UpdateStatusWarning("Error importing storage account: {0} into virtual account. Details: {1}", accountName, ex.ToString()).Wait(); }, false, true); }
private async Task <HttpResponseMessage> SetContainerLease(CloudBlobContainer container) { IEnumerable <string> action; string leaseId = null; string proposedLeaseId = null; HttpResponseMessage response = new HttpResponseMessage(); AccessCondition condition; string serverLeaseId; await AddBasicContainerHeaders(response, container); //If an action is not provided, it's not a valid call. if (!Request.Headers.TryGetValues("x-ms-lease-action", out action)) { response.StatusCode = HttpStatusCode.BadRequest; return(response); } if (Request.Headers.Contains("x-ms-lease-id")) { leaseId = Request.Headers.GetValues("x-ms-lease-id").FirstOrDefault(); } if (Request.Headers.Contains("x-ms-proposed-lease-id")) { proposedLeaseId = Request.Headers.GetValues("x-ms-proposed-lease-id").FirstOrDefault(); } switch (action.First().ToLower()) { case "acquire": int leaseDuration = Int32.Parse(Request.Headers.GetValues("x-ms-lease-duration").First()); TimeSpan?leaseDurationSpan; if (leaseDuration == -1) { leaseDurationSpan = null; } else if (leaseDuration >= 15 && leaseDuration <= 60) { leaseDurationSpan = new TimeSpan(0, 0, leaseDuration); } else { response.StatusCode = HttpStatusCode.BadRequest; return(response); } serverLeaseId = await container.AcquireLeaseAsync(leaseDurationSpan, proposedLeaseId); response = new DelegatedResponse(await ContainerHandler.DoForDataContainersAsync(container.Name, HttpStatusCode.Created, async containerObj => await containerObj.AcquireLeaseAsync(leaseDurationSpan, serverLeaseId), true)).CreateResponse(); await AddBasicContainerHeaders(response, container); response.Headers.Add("x-ms-lease-id", serverLeaseId); return(response); case "renew": condition = new AccessCondition() { LeaseId = leaseId }; response = new DelegatedResponse(await ContainerHandler.DoForAllContainersAsync(container.Name, HttpStatusCode.OK, async containerObj => await containerObj.RenewLeaseAsync(condition), true)).CreateResponse(); await AddBasicContainerHeaders(response, container); response.Headers.Add("x-ms-lease-id", leaseId); return(response); case "change": condition = new AccessCondition() { LeaseId = leaseId }; serverLeaseId = await container.ChangeLeaseAsync(proposedLeaseId, condition); response = new DelegatedResponse(await ContainerHandler.DoForDataContainersAsync(container.Name, HttpStatusCode.OK, async containerObj => await containerObj.ChangeLeaseAsync(proposedLeaseId, condition), true)).CreateResponse(); await AddBasicContainerHeaders(response, container); response.Headers.Add("x-ms-lease-id", container.ChangeLease(proposedLeaseId, condition)); return(response); case "release": condition = new AccessCondition() { LeaseId = leaseId }; response = new DelegatedResponse(await ContainerHandler.DoForAllContainersAsync(container.Name, HttpStatusCode.OK, async containerObj => await containerObj.ReleaseLeaseAsync(condition), true)).CreateResponse(); await AddBasicContainerHeaders(response, container); return(response); case "break": int breakDuration = 0; if (Request.Headers.Contains("x-ms-lease-break-period")) { breakDuration = Int32.Parse(Request.Headers.GetValues("x-ms-lease-break-period").FirstOrDefault()); } TimeSpan breakDurationSpan = new TimeSpan(0, 0, breakDuration); TimeSpan remainingTime = await container.BreakLeaseAsync(breakDurationSpan); response = new DelegatedResponse(await ContainerHandler.DoForDataContainersAsync(container.Name, HttpStatusCode.Accepted, async containerObj => await containerObj.BreakLeaseAsync(breakDurationSpan), true)).CreateResponse(); await AddBasicContainerHeaders(response, container); response.Headers.Add("x-ms-lease-time", remainingTime.Seconds.ToString()); return(response); default: //Not a recognized action response.StatusCode = HttpStatusCode.BadRequest; return(response); } }
Expression Nullable(ContainerHandler handler) { Debug.Assert(schemaType.IsBondNullable()); var valueType = schemaType.GetValueType(); var count = Expression.Variable(typeof(int), "count"); var nullableValue = valueType.IsBondBlob() ? Expression.Property(typeAlias.Convert(value, valueType), "Array") : value; var notNull = Expression.NotEqual(nullableValue, Expression.Constant(null)); var loop = handler( new ObjectParser(this, value, valueType), Expression.Constant(valueType.GetBondDataType()), Expression.NotEqual(Expression.PostDecrementAssign(count), Expression.Constant(0)), count); return Expression.Block( new[] { count }, Expression.Assign(count, Expression.Condition(notNull, Expression.Constant(1), Expression.Constant(0))), loop); }
private static RipResult GFPackDump(BinaryReader br, uint header, string path, ContainerHandler handler) { if (header != 0x584C_4647) { return(new RipResult(RipResultCode.UnknownFormat)); } br.BaseStream.Position = 0; var gfp = new GFPack(br); var dir = Path.GetDirectoryName(path); var folder = Path.GetFileNameWithoutExtension(path); var resultPath = Path.Combine(dir, folder); Directory.CreateDirectory(resultPath); gfp.Dump(resultPath, handler); return(new RipResult(RipResultCode.Success) { ResultPath = resultPath }); }
public Expression Container(BondDataType? expectedType, ContainerHandler handler) { throw new System.NotImplementedException(); }