private async Task <ContainerProperties> ReadCollectionAsync( string collectionLink, IDocumentClientRetryPolicy retryPolicyInstance, ITrace trace, IClientSideRequestStatistics clientSideRequestStatistics, CancellationToken cancellationToken) { using (ITrace childTrace = trace.StartChild("Read Collection", TraceComponent.Transport, TraceLevel.Info)) { cancellationToken.ThrowIfCancellationRequested(); RequestNameValueCollection headers = new RequestNameValueCollection(); using (DocumentServiceRequest request = DocumentServiceRequest.Create( OperationType.Read, ResourceType.Collection, collectionLink, AuthorizationTokenType.PrimaryMasterKey, headers)) { headers.XDate = Rfc1123DateTimeCache.UtcNow(); request.RequestContext.ClientRequestStatistics = clientSideRequestStatistics ?? new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, trace.Summary); if (clientSideRequestStatistics == null) { childTrace.AddDatum( "Client Side Request Stats", request.RequestContext.ClientRequestStatistics); } string authorizationToken = await this.tokenProvider.GetUserAuthorizationTokenAsync( request.ResourceAddress, PathsHelper.GetResourcePath(request.ResourceType), HttpConstants.HttpMethods.Get, request.Headers, AuthorizationTokenType.PrimaryMasterKey, childTrace); headers.Authorization = authorizationToken; using (new ActivityScope(Guid.NewGuid())) { retryPolicyInstance?.OnBeforeSendRequest(request); try { using (DocumentServiceResponse response = await this.storeModel.ProcessMessageAsync(request)) { return(CosmosResource.FromStream <ContainerProperties>(response)); } } catch (DocumentClientException ex) { childTrace.AddDatum("Exception Message", ex.Message); throw; } } } } }
/// <summary> /// /// </summary> /// <returns></returns> public SPMState reloadState() { log.Debug(" -- reloadState"); this.updateManagerState(); if (this.activeProfile != null) { log.Debug("Active profiles => name:" + this.activeProfile.name + ", color:" + this.activeProfile.color); } log.Debug("Desactivated profiles [Count:" + this.listDesactivated.Count + "]"); foreach (var item in this.listDesactivated) { log.Debug(" name:" + item.name + ", color:" + item.color + ", creationDate:" + item.creationDate); } string textConfig = ""; string configPath = PathsHelper.getConfigFileName(); if (File.Exists(configPath)) { textConfig = File.ReadAllText(configPath); log.Debug(textConfig); } else { log.Debug("** ERROR!! CONFIGURATION FILE NOT FOUND!!"); } log.Info("# APPLICATION STATE:" + this.applicationState.ToString()); return(this.applicationState); }
private async Task RefreshAsync(DocumentServiceRequest request, CancellationToken cancellationToken) { System.Diagnostics.Debug.Assert(request.IsNameBased); string resourceFullName = PathsHelper.GetCollectionPath(request.ResourceAddress); if (request.RequestContext.ResolvedCollectionRid != null) { // Here we will issue backend call only if cache wasn't already refreshed (if whatever is there corresponds to presiously resolved collection rid). await this.collectionInfoByNameCache.GetAsync( resourceFullName, CosmosContainerSettings.CreateWithResourceId(request.RequestContext.ResolvedCollectionRid), async() => { CosmosContainerSettings collection = await this.GetByNameAsync(resourceFullName, cancellationToken); if (collection != null) { this.collectionInfoByIdCache.Set(collection.ResourceId, collection); } return(collection); }, cancellationToken); } else { // In case of ForceRefresh directive coming from client, there will be no ResolvedCollectionRid, so we // need to refresh unconditionally. this.Refresh(request.ResourceAddress); } request.RequestContext.ResolvedCollectionRid = null; }
/// <summary> /// /// </summary> /// <returns></returns> public SPMState showState() { this.updateManagerState(); Console.WriteLine("###############################################################################"); Console.WriteLine("# STEAM PROFILE APP_CORE"); Console.WriteLine("###############################################################################"); Console.WriteLine("# Active profiles"); if (this.activeProfile != null) { Console.WriteLine(" name:" + this.activeProfile.name + ", color:" + this.activeProfile.color); } Console.WriteLine("# Desactivated profiles [Count:" + this.listDesactivated.Count + "]"); foreach (var item in this.listDesactivated) { Console.WriteLine(" name:" + item.name + ", color:" + item.color + ", creationDate:" + item.creationDate); } Console.WriteLine("# configuration file"); string textConfig = ""; string configPath = PathsHelper.getConfigFileName(); if (File.Exists(configPath)) { textConfig = File.ReadAllText(configPath); Console.WriteLine(textConfig); } else { Console.WriteLine("** ERROR!! CONFIGURATION FILE NOT FOUND!!"); } Console.WriteLine("# APPLICATION STATE:" + this.applicationState.ToString()); return(this.applicationState); }
private static ConcurrentDictionary <string, ISessionToken> GetPartitionKeyRangeIdToTokenMap(SessionContainerState self, DocumentServiceRequest request) { ulong?maybeRID = null; if (request.IsNameBased) { string collectionName = PathsHelper.GetCollectionPath(request.ResourceAddress); if (self.collectionNameByResourceId.TryGetValue(collectionName, out ulong rid)) { maybeRID = rid; } } else { if (!string.IsNullOrEmpty(request.ResourceId)) { ResourceId resourceId = ResourceId.Parse(request.ResourceId); if (resourceId.DocumentCollection != 0) { maybeRID = resourceId.UniqueDocumentCollectionId; } } } ConcurrentDictionary <string, ISessionToken> partitionKeyRangeIdToTokenMap = null; if (maybeRID.HasValue) { self.sessionTokensRIDBased.TryGetValue(maybeRID.Value, out partitionKeyRangeIdToTokenMap); } return(partitionKeyRangeIdToTokenMap); }
public void ClearToken(DocumentServiceRequest request, INameValueCollection responseHeaders) { string ownerFullName = responseHeaders[HttpConstants.HttpHeaders.OwnerFullName]; string collectionName = PathsHelper.GetCollectionPath(ownerFullName); string resourceIdString; if (!request.IsNameBased) { resourceIdString = request.ResourceId; } else { resourceIdString = responseHeaders[HttpConstants.HttpHeaders.OwnerId]; } if (!string.IsNullOrEmpty(resourceIdString)) { ResourceId resourceId = ResourceId.Parse(resourceIdString); if (resourceId.DocumentCollection != 0 && collectionName != null) { ConcurrentDictionary <string, ISessionToken> ignored; this.sessionTokens.TryRemove(resourceId.UniqueDocumentCollectionId, out ignored); this.sessionTokensNameBased.TryRemove(collectionName, out ignored); } } }
public string GetSessionToken(string collectionLink) { bool isNameBased; bool isFeed; string resourceTypeString; string resourceIdOrFullName; ConcurrentDictionary <string, ISessionToken> partitionKeyRangeIdToTokenMap = null; if (PathsHelper.TryParsePathSegments(collectionLink, out isFeed, out resourceTypeString, out resourceIdOrFullName, out isNameBased)) { if (isNameBased) { string collectionName = PathsHelper.GetCollectionPath(resourceIdOrFullName); this.sessionTokensNameBased.TryGetValue(collectionName, out partitionKeyRangeIdToTokenMap); } else { ResourceId resourceId = ResourceId.Parse(resourceIdOrFullName); if (resourceId.DocumentCollection != 0) { this.sessionTokens.TryGetValue(resourceId.UniqueDocumentCollectionId, out partitionKeyRangeIdToTokenMap); } } } if (partitionKeyRangeIdToTokenMap == null) { return(string.Empty); } return(SessionContainer.GetSessionTokenString(partitionKeyRangeIdToTokenMap)); }
private async Task <CosmosContainerSettings> ResolveByNameAsync( string apiVersion, string resourceAddress, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); string resourceFullName = PathsHelper.GetCollectionPath(resourceAddress); InternalCache cache = this.GetCache(apiVersion); return(await cache.collectionInfoByName.GetAsync( resourceFullName, null, async() => { DateTime currentTime = DateTime.UtcNow; CosmosContainerSettings collection = await this.GetByNameAsync(apiVersion, resourceFullName, cancellationToken); cache.collectionInfoById.Set(collection.ResourceId, collection); cache.collectionInfoByNameLastRefreshTime.AddOrUpdate(resourceFullName, currentTime, (string currentKey, DateTime currentValue) => currentTime); cache.collectionInfoByIdLastRefreshTime.AddOrUpdate(collection.ResourceId, currentTime, (string currentKey, DateTime currentValue) => currentTime); return collection; }, cancellationToken)); }
public async Task <PartitionKeyRange> GetTargetPartitionKeyRangeByIdAsync(string collectionResourceId, string partitionKeyRangeId) { IRoutingMapProvider routingMapProvider = await this.Client.GetRoutingMapProviderAsync(); PartitionKeyRange range = await routingMapProvider.TryGetPartitionKeyRangeByIdAsync(collectionResourceId, partitionKeyRangeId); if (range == null && PathsHelper.IsNameBased(this.ResourceLink)) { // Refresh the cache and don't try to reresolve collection as it is not clear what already // happened based on previously resolved collection rid. // Return NotFoundException this time. Next query will succeed. // This can only happen if collection is deleted/created with same name and client was not restarted // inbetween. CollectionCache collectionCache = await this.Client.GetCollectionCacheAsync(); collectionCache.Refresh(this.ResourceLink); } if (range == null) { throw new NotFoundException($"{DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture)}: GetTargetPartitionKeyRangeById(collectionResourceId:{collectionResourceId}, partitionKeyRangeId: {partitionKeyRangeId}) failed due to stale cache"); } return(range); }
internal static void GetResourceTypeAndIdOrFullName(Uri uri, out bool isNameBased, out string resourceType, out string resourceId, string clientVersion = "") { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } resourceType = string.Empty; resourceId = string.Empty; int uriSegmentsCount = uri.Segments.Length; if (uriSegmentsCount < 1) { throw new ArgumentException(RMResources.InvalidUrl); } // Authorization code is fine with Uri not having resource id and path. // We will just return empty in that case bool isFeed = false; if (!PathsHelper.TryParsePathSegments(uri.PathAndQuery, out isFeed, out resourceType, out resourceId, out isNameBased, clientVersion)) { resourceType = string.Empty; resourceId = string.Empty; } }
public static void GetFullNameOfClassThatInheritsFromApplication(string pathOfAssemblyThatContainsEntryPoint, out string applicationClassFullName, out string assemblyName, out string assemblyFullName) { //----------------- // Thanks to: http://www.c-sharpcorner.com/UploadFile/girish.nehte/how-to-unload-an-assembly-loaded-dynamically-using-reflection/ //----------------- // Load the assembly in a new AppDomain mainly so that we are able to unload it, which is necessary when we want to delete all temporary files including this assembly. AppDomainSetup setupInformation = AppDomain.CurrentDomain.SetupInformation; AppDomain newAppDomain = AppDomain.CreateDomain("newAppDomain", AppDomain.CurrentDomain.Evidence, setupInformation); //Create an instance of the inspector class in the new domain: //System.Runtime.Remoting.ObjectHandle obj = newAppDomain.CreateInstance(typeof(AssemblyInspectorOnOtherDomain).Assembly.FullName, typeof(AssemblyInspectorOnOtherDomain).FullName); string pathOfThisVeryAssembly = PathsHelper.GetPathOfThisVeryAssembly(); System.Runtime.Remoting.ObjectHandle obj = newAppDomain.CreateInstanceFrom(pathOfThisVeryAssembly, typeof(AssemblyInspectorOnOtherDomain).FullName); IAssemblyInspectorOnOtherDomain inspector = (IAssemblyInspectorOnOtherDomain)obj.Unwrap(); // As the object we are creating is from another appdomain hence we will get that object in wrapped format and hence in next step we have unwrappped it // Call LoadAssembly method so that the assembly will be loaded into the new appdomain amd the object will also remain in new appdomain only: inspector.LoadAssembly(pathOfAssemblyThatContainsEntryPoint); // Call the method that finds the type that inherits from Application: applicationClassFullName = inspector.FindApplicationClassFullName(); // Get the assembly name and full name too: assemblyName = inspector.GetAssemblyName(); assemblyFullName = inspector.GetAssemblyFullName(); // Unload the assembly (so that we can later delete it if necessary): AppDomain.Unload(newAppDomain); GC.Collect(); // Collects all unused memory GC.WaitForPendingFinalizers(); // Waits until GC has finished its work GC.Collect(); }
internal async Task <List <PartitionKeyRange> > GetTargetPartitionKeyRangesAsync(string collectionResourceId, List <Range <string> > providedRanges) { if (string.IsNullOrEmpty(nameof(collectionResourceId))) { throw new ArgumentNullException(); } if (providedRanges == null || !providedRanges.Any()) { throw new ArgumentNullException(nameof(providedRanges)); } IRoutingMapProvider routingMapProvider = await this.Client.GetRoutingMapProviderAsync(); List <PartitionKeyRange> ranges = await routingMapProvider.TryGetOverlappingRangesAsync(collectionResourceId, providedRanges); if (ranges == null && PathsHelper.IsNameBased(this.ResourceLink)) { // Refresh the cache and don't try to re-resolve collection as it is not clear what already // happened based on previously resolved collection rid. // Return NotFoundException this time. Next query will succeed. // This can only happen if collection is deleted/created with same name and client was not restarted // in between. CollectionCache collectionCache = await this.Client.GetCollectionCacheAsync(); collectionCache.Refresh(this.ResourceLink); } if (ranges == null) { throw new NotFoundException($"{DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture)}: GetTargetPartitionKeyRanges(collectionResourceId:{collectionResourceId}, providedRanges: {string.Join(",", providedRanges)} failed due to stale cache"); } return(ranges); }
internal Task <DocumentServiceResponse> ProcessMessageAsync( CosmosRequestMessage request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } DocumentServiceRequest serviceRequest = request.ToDocumentServiceRequest(); //TODO: extrace auth into a separate handler string authorization = ((IAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationToken( serviceRequest.ResourceAddress, PathsHelper.GetResourcePath(request.ResourceType), request.Method.ToString(), serviceRequest.Headers, AuthorizationTokenType.PrimaryMasterKey); serviceRequest.Headers[HttpConstants.HttpHeaders.Authorization] = authorization; IStoreModel storeProxy = this.client.DocumentClient.GetStoreProxy(serviceRequest); if (request.OperationType == OperationType.Upsert) { return(this.ProcessUpsertAsync(storeProxy, serviceRequest, cancellationToken)); } else { return(storeProxy.ProcessMessageAsync(serviceRequest, cancellationToken)); } }
/// <summary> /// Заполняет аргументы запуска необходимыми либами /// </summary> private void FillLibrariesPaths() { // нашли папку с либами var dirs = Directory.GetDirectories(_minecraftPath, "libraries", SearchOption.AllDirectories); var dir = PathsHelper.GetTopPath(dirs); // проерили CheckFolderAndThrow(dir); // вытащили все jar var allJars = Directory.GetFiles(dir, "*.jar", SearchOption.AllDirectories).ToList(); var selected = new List <string>(); // ищем те, которые нужны foreach (var libName in LibraryNameRegexes) { var libs = allJars.Where(x => Regex.IsMatch(x, libName)).ToList(); if (libs.IsNullOrEmpty()) { continue; } var shortest = PathsHelper.GetShortestName(libs); selected.Add(shortest); allJars.Remove(shortest); } _libPaths = string.Join(";", selected); }
private async Task RefreshAsync(DocumentServiceRequest request, CancellationToken cancellationToken) { System.Diagnostics.Debug.Assert(request.IsNameBased); InternalCache cache = this.GetCache(request.Headers[HttpConstants.HttpHeaders.Version]); string resourceFullName = PathsHelper.GetCollectionPath(request.ResourceAddress); if (request.RequestContext.ResolvedCollectionRid != null) { // Here we will issue backend call only if cache wasn't already refreshed (if whatever is there corresponds to presiously resolved collection rid). await cache.collectionInfoByName.GetAsync( resourceFullName, CosmosContainerSettings.CreateWithResourceId(request.RequestContext.ResolvedCollectionRid), async() => { DateTime currentTime = DateTime.UtcNow; CosmosContainerSettings collection = await this.GetByNameAsync(request.Headers[HttpConstants.HttpHeaders.Version], resourceFullName, cancellationToken); cache.collectionInfoById.Set(collection.ResourceId, collection); cache.collectionInfoByNameLastRefreshTime.AddOrUpdate(resourceFullName, currentTime, (string currentKey, DateTime currentValue) => currentTime); cache.collectionInfoByIdLastRefreshTime.AddOrUpdate(collection.ResourceId, currentTime, (string currentKey, DateTime currentValue) => currentTime); return(collection); }, cancellationToken); } else { // In case of ForceRefresh directive coming from client, there will be no ResolvedCollectionRid, so we // need to refresh unconditionally. this.Refresh(request.ResourceAddress, request.Headers[HttpConstants.HttpHeaders.Version]); } request.RequestContext.ResolvedCollectionRid = null; }
/// <inheritdoc /> public new void BindProperties(T element, ICommandProvider commandProvider = null, IList <StyleModel> styleModels = null) { if (element is null) { throw new UIException(nameof(element)); } element.Balance = Balance; element.Clock = Clock; element.IsMuted = IsMuted; element.LoadedBehavior = LoadedBehavior; bool isParsed = TimeSpan.TryParse(Position, out TimeSpan positionTimeSpan); element.Position = isParsed ? positionTimeSpan : default; element.ScrubbingEnabled = ScrubbingEnabled; if (!string.IsNullOrWhiteSpace(Source)) { element.Source = PathsHelper.GetUriFromRelativePath(Source); } element.SpeedRatio = SpeedRatio; element.Stretch = Stretch; element.StretchDirection = StretchDirection; element.UnloadedBehavior = UnloadedBehavior; element.Volume = Volume; }
public void ClearTokenByCollectionFullname(string collectionFullname) { if (!string.IsNullOrEmpty(collectionFullname)) { string collectionName = PathsHelper.GetCollectionPath(collectionFullname); this.rwlock.EnterWriteLock(); try { if (collectionNameByResourceId.ContainsKey(collectionName)) { string ignoreString; ulong ignoreUlong; ulong rid = this.collectionNameByResourceId[collectionName]; ConcurrentDictionary <string, ISessionToken> ignored; this.sessionTokensRIDBased.TryRemove(rid, out ignored); this.collectionResourceIdByName.TryRemove(rid, out ignoreString); this.collectionNameByResourceId.TryRemove(collectionName, out ignoreUlong); } } finally { this.rwlock.ExitWriteLock(); } } }
internal virtual async Task <ContainerProperties> ResolveByNameAsync( string apiVersion, string resourceAddress, bool forceRefesh, ITrace trace, IClientSideRequestStatistics clientSideRequestStatistics, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); string resourceFullName = PathsHelper.GetCollectionPath(resourceAddress); InternalCache cache = this.GetCache(apiVersion); if (forceRefesh) { cache.collectionInfoByName.TryRemoveIfCompleted(resourceFullName); } return(await cache.collectionInfoByName.GetAsync( resourceFullName, null, async() => { DateTime currentTime = DateTime.UtcNow; ContainerProperties collection = await this.GetByNameAsync(apiVersion, resourceFullName, trace, clientSideRequestStatistics, cancellationToken); cache.collectionInfoById.Set(collection.ResourceId, collection); cache.collectionInfoByNameLastRefreshTime.AddOrUpdate(resourceFullName, currentTime, (string currentKey, DateTime currentValue) => currentTime); cache.collectionInfoByIdLastRefreshTime.AddOrUpdate(collection.ResourceId, currentTime, (string currentKey, DateTime currentValue) => currentTime); return collection; }, cancellationToken)); }
private static async Task <DocumentClientException> CreateDocumentClientException(HttpResponseMessage responseMessage) { Stream readStream = await responseMessage.Content.ReadAsStreamAsync(); Error error = CosmosResource.LoadFrom <Error>(readStream); // ensure there is no local ActivityId, since in Gateway mode ActivityId // should always come from message headers Trace.CorrelationManager.ActivityId = Guid.Empty; bool isNameBased = false; bool isFeed = false; string resourceTypeString; string resourceIdOrFullName; string resourceLink = responseMessage.RequestMessage.RequestUri.LocalPath; if (!PathsHelper.TryParsePathSegments(resourceLink, out isFeed, out resourceTypeString, out resourceIdOrFullName, out isNameBased)) { // if resourceLink is invalid - we will not set resourceAddress in exception. } return(new DocumentClientException(error, responseMessage.Headers, responseMessage.StatusCode) { StatusDescription = responseMessage.ReasonPhrase, ResourceAddress = resourceIdOrFullName }); }
private async Task <DocumentServiceResponse> ExecutePartitionKeyRangeReadChangeFeedAsync(string collectionRid, INameValueCollection headers, ITrace trace) { using (ITrace childTrace = trace.StartChild("Read PartitionKeyRange Change Feed", TraceComponent.Transport, Tracing.TraceLevel.Info)) { using (DocumentServiceRequest request = DocumentServiceRequest.Create( OperationType.ReadFeed, collectionRid, ResourceType.PartitionKeyRange, AuthorizationTokenType.PrimaryMasterKey, headers)) { string authorizationToken = null; try { authorizationToken = (await this.authorizationTokenProvider.GetUserAuthorizationAsync( request.ResourceAddress, PathsHelper.GetResourcePath(request.ResourceType), HttpConstants.HttpMethods.Get, request.Headers, AuthorizationTokenType.PrimaryMasterKey)).token; } catch (UnauthorizedException) { } if (authorizationToken == null) { // User doesn't have rid based resource token. Maybe he has name based. throw new NotSupportedException("Resource tokens are not supported"); ////CosmosContainerSettings collection = await this.collectionCache.ResolveCollectionAsync(request, CancellationToken.None); ////authorizationToken = //// this.authorizationTokenProvider.GetUserAuthorizationTokenAsync( //// collection.AltLink, //// PathsHelper.GetResourcePath(request.ResourceType), //// HttpConstants.HttpMethods.Get, //// request.Headers, //// AuthorizationTokenType.PrimaryMasterKey); } request.Headers[HttpConstants.HttpHeaders.Authorization] = authorizationToken; using (new ActivityScope(Guid.NewGuid())) { try { return(await this.storeModel.ProcessMessageAsync(request)); } catch (DocumentClientException ex) { childTrace.AddDatum("Exception Message", ex.Message); throw; } } } } }
internal override async Task <IDocumentClientRetryPolicy> GetRetryPolicy(CosmosRequestMessage request) { return(new PartitionKeyRangeGoneRetryPolicy( await client.DocumentClient.GetCollectionCacheAsync(), await client.DocumentClient.GetPartitionKeyRangeCacheAsync(), PathsHelper.GetCollectionPath(request.RequestUri.ToString()), null)); }
/// <summary> /// Ищет папку assets Майнкрафта /// </summary> private void FindMinecraftAssets() { var dirs = Directory.GetDirectories(_minecraftPath, "assets", SearchOption.AllDirectories); _minecraftAssetsPath = PathsHelper.GetTopPath(dirs); CheckFolderAndThrow(_minecraftAssetsPath); }
/// <summary> /// Находит папку нативных библиотек Форджа /// </summary> private void FindForgeNatives() { var dirs = Directory.GetDirectories(_minecraftPath, "natives", SearchOption.AllDirectories); _forgeNativesPath = PathsHelper.GetTopPath(dirs); CheckFolderAndThrow(_forgeNativesPath); }
private async Task <FeedResource <Address> > GetMasterAddressesViaGatewayAsync( DocumentServiceRequest request, ResourceType resourceType, string resourceAddress, string entryUrl, bool forceRefresh, bool useMasterCollectionResolver) { INameValueCollection addressQuery = new DictionaryNameValueCollection(StringComparer.Ordinal); addressQuery.Add(HttpConstants.QueryStrings.Url, HttpUtility.UrlEncode(entryUrl)); INameValueCollection headers = new DictionaryNameValueCollection(StringComparer.Ordinal); if (forceRefresh) { headers.Set(HttpConstants.HttpHeaders.ForceRefresh, bool.TrueString); } if (useMasterCollectionResolver) { headers.Set(HttpConstants.HttpHeaders.UseMasterCollectionResolver, bool.TrueString); } if (request.ForceCollectionRoutingMapRefresh) { headers.Set(HttpConstants.HttpHeaders.ForceCollectionRoutingMapRefresh, bool.TrueString); } addressQuery.Add(HttpConstants.QueryStrings.Filter, this.protocolFilter); string resourceTypeToSign = PathsHelper.GetResourcePath(resourceType); headers.Set(HttpConstants.HttpHeaders.XDate, DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture)); string token = this.tokenProvider.GetUserAuthorizationToken( resourceAddress, resourceTypeToSign, HttpConstants.HttpMethods.Get, headers, AuthorizationTokenType.PrimaryMasterKey, payload: out _); headers.Set(HttpConstants.HttpHeaders.Authorization, token); Uri targetEndpoint = UrlUtility.SetQuery(this.addressEndpoint, UrlUtility.CreateQuery(addressQuery)); string identifier = GatewayAddressCache.LogAddressResolutionStart(request, targetEndpoint); using (HttpResponseMessage httpResponseMessage = await this.httpClient.GetAsync(targetEndpoint, headers)) { using (DocumentServiceResponse documentServiceResponse = await ClientExtensions.ParseResponseAsync(httpResponseMessage)) { GatewayAddressCache.LogAddressResolutionEnd(request, identifier); return(documentServiceResponse.GetResource <FeedResource <Address> >()); } } }
public bool Execute() { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Uploading files (press ESC to cancel)..."); Console.ResetColor(); Console.WriteLine(); var cts = new CancellationTokenSource(); var completed = false; if (string.IsNullOrEmpty(ArgSettings.DestinationConnection)) { ArgSettings.DestinationConnection = "UseDevelopmentStorage=true"; } var task = Task.Factory.StartNew(() => { uploader.UploadFiles(PathsHelper.GetDirectory(ArgSettings.Source), PathsHelper.ListFiles(ArgSettings.Source), ArgSettings.DestinationConnection, ArgSettings.Destination, cts.Token, (f) => { Console.WriteLine(f); }, (f, e) => { Console.Error.WriteLine("Failed to upload {0}: {1}", f, e.ToString()); }, () => { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); Console.WriteLine("Finished uploading files."); Console.ResetColor(); completed = true; }); }, cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); while (!completed) { if (ArgumentsHelper.IsKeyAvailable()) { if (Console.ReadKey(true).Key == ConsoleKey.Escape) { cts.Cancel(); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Cancelled!"); Console.ResetColor(); return(false); } } } return(true); }
public IList <string> ListBlobs(string directoryUri, string pattern, string storageConnectionString, bool flatten) { var storageAccount = CloudStorageAccount.Parse(storageConnectionString); var blobClient = storageAccount.CreateCloudBlobClient(); List <IListBlobItem> blobs; if (string.IsNullOrEmpty(directoryUri)) { blobs = blobClient.ListBlobsWithPrefix(string.Empty, new BlobRequestOptions() { BlobListingDetails = BlobListingDetails.Metadata, UseFlatBlobListing = flatten }).ToList(); } else { var container = blobClient.GetContainerReference(directoryUri); try { container.FetchAttributes(); blobs = container.ListBlobs(new BlobRequestOptions() { UseFlatBlobListing = flatten }).ToList(); } catch (StorageClientException) { try { var directory = blobClient.GetBlobDirectoryReference(directoryUri); blobs = directory.ListBlobs(new BlobRequestOptions() { UseFlatBlobListing = flatten }).ToList(); } catch { blobs = blobClient.ListBlobsWithPrefix(string.Empty, new BlobRequestOptions() { BlobListingDetails = BlobListingDetails.Metadata, UseFlatBlobListing = flatten }).ToList(); } } } var result = new List <string>(); foreach (var blob in blobs) { if (string.IsNullOrEmpty(pattern) || PathsHelper.MatchPattern(pattern, blob.Uri.ToString())) { result.Add(blob.Uri.ToString()); } } return(result); }
private async Task <DocumentServiceResponse> GetMasterAddressesViaGatewayAsync( DocumentServiceRequest request, ResourceType resourceType, string resourceAddress, string entryUrl, bool forceRefresh, bool useMasterCollectionResolver) { INameValueCollection addressQuery = new RequestNameValueCollection { { HttpConstants.QueryStrings.Url, HttpUtility.UrlEncode(entryUrl) } }; INameValueCollection headers = new RequestNameValueCollection(); if (forceRefresh) { headers.Set(HttpConstants.HttpHeaders.ForceRefresh, bool.TrueString); } if (useMasterCollectionResolver) { headers.Set(HttpConstants.HttpHeaders.UseMasterCollectionResolver, bool.TrueString); } if (request.ForceCollectionRoutingMapRefresh) { headers.Set(HttpConstants.HttpHeaders.ForceCollectionRoutingMapRefresh, bool.TrueString); } addressQuery.Add(HttpConstants.QueryStrings.Filter, this.protocolFilter); string resourceTypeToSign = PathsHelper.GetResourcePath(resourceType); headers.Set(HttpConstants.HttpHeaders.XDate, Rfc1123DateTimeCache.UtcNow()); using (ITrace trace = Trace.GetRootTrace(nameof(GetMasterAddressesViaGatewayAsync), TraceComponent.Authorization, TraceLevel.Info)) { string token = await this.tokenProvider.GetUserAuthorizationTokenAsync( resourceAddress, resourceTypeToSign, HttpConstants.HttpMethods.Get, headers, AuthorizationTokenType.PrimaryMasterKey, trace); headers.Set(HttpConstants.HttpHeaders.Authorization, token); Uri targetEndpoint = UrlUtility.SetQuery(this.addressEndpoint, UrlUtility.CreateQuery(addressQuery)); string identifier = GatewayAddressCache.LogAddressResolutionStart(request, targetEndpoint); using (HttpResponseMessage httpResponseMessage = await this.httpClient.GetAsync( uri: targetEndpoint, additionalHeaders: headers, resourceType: resourceType, timeoutPolicy: HttpTimeoutPolicyControlPlaneRetriableHotPath.Instance, clientSideRequestStatistics: request.RequestContext?.ClientRequestStatistics, cancellationToken: default))
static void CreateAndSaveIndexHtml( string outputPathAbsolute, string startupCode, string codeForReferencingAdditionalLibraries, string outputRootPath, string outputAppFilesPath, string outputLibrariesPath, string outputResourcesPath, string assemblyNameWithoutExtension ) { // Read the "index.html" template: string indexHtmlFileTemplate = WrapperHelpers.ReadTextFileFromEmbeddedResource("index.html"); // Replace the placeholders: string indexHtmlFile = indexHtmlFileTemplate.Replace("[BOOT_JAVASCRIPT_CODE_GOES_HERE]", startupCode); indexHtmlFile = indexHtmlFile.Replace("[ADDITIONAL_LIBRARIES_GO_HERE]", codeForReferencingAdditionalLibraries); indexHtmlFile = indexHtmlFile.Replace("[LIBRARIES_PATH_GOES_HERE]", PathsHelper.EnsureNoBackslashAndEnsureItEndsWithAForwardSlash(outputLibrariesPath)); indexHtmlFile = indexHtmlFile.Replace("[APPFILES_PATH_GOES_HERE]", PathsHelper.EnsureNoBackslashAndEnsureItEndsWithAForwardSlash(outputAppFilesPath)); // Prevent browser caching of the JSIL and CSHTML5 libraries: indexHtmlFile = WrapperHelpers.AppendDateToLibraryFileName("JSIL.js", indexHtmlFile); indexHtmlFile = WrapperHelpers.AppendDateToLibraryFileName("cshtml5.js", indexHtmlFile); indexHtmlFile = WrapperHelpers.AppendDateToLibraryFileName("cshtml5.css", indexHtmlFile); // Read the "App.Config" file for future use by the ClientBase. string relativePathToAppConfigFolder = PathsHelper.CombinePathsWhileEnsuringEndingBackslashAndMore(outputResourcesPath, assemblyNameWithoutExtension); string relativePathToAppConfig = Path.Combine(relativePathToAppConfigFolder, "app.config.g.js"); if (File.Exists(Path.Combine(outputPathAbsolute, relativePathToAppConfig))) { string scriptToReadAppConfig = "<script type=\"application/javascript\" src=\"" + relativePathToAppConfig + "\"></script>"; indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_APPCONFIG_GOES_HERE]", scriptToReadAppConfig); } else { indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_APPCONFIG_GOES_HERE]", string.Empty); } // Read the "ServiceReferences.ClientConfig" file for future use by the ClientBase. string relativePathToServiceReferencesClientConfig = Path.Combine(relativePathToAppConfigFolder, "servicereferences.clientconfig.g.js"); if (File.Exists(Path.Combine(outputPathAbsolute, relativePathToServiceReferencesClientConfig))) { string scriptToReadServiceReferencesClientConfig = "<script src=\"" + relativePathToServiceReferencesClientConfig.Replace('\\', '/') + "\"></script>"; indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_SERVICEREFERENCESCLIENTCONFIG_GOES_HERE]", scriptToReadServiceReferencesClientConfig); } else { indexHtmlFile = indexHtmlFile.Replace("[SCRIPT_TO_READ_SERVICEREFERENCESCLIENTCONFIG_GOES_HERE]", string.Empty); } // Save the "index.html" to the final folder: File.WriteAllText(Path.Combine(outputPathAbsolute, "index.html"), indexHtmlFile); }
protected override Task <ContainerProperties> GetByRidAsync(string apiVersion, string collectionRid, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); IDocumentClientRetryPolicy retryPolicyInstance = new ClearingSessionContainerClientRetryPolicy(this.sessionContainer, this.retryPolicy.GetRequestPolicy()); return(TaskHelper.InlineIfPossible( () => this.ReadCollectionAsync(PathsHelper.GeneratePath(ResourceType.Collection, collectionRid, false), cancellationToken, retryPolicyInstance), retryPolicyInstance, cancellationToken)); }
protected override Task <CosmosContainerSettings> GetByRidAsync(string collectionRid, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); IDocumentClientRetryPolicy retryPolicyInstance = this.retryPolicy.GetRequestPolicy(); return(TaskHelper.InlineIfPossible( () => this.ReadCollectionAsync(PathsHelper.GeneratePath(ResourceType.Collection, collectionRid, false), cancellationToken, retryPolicyInstance), retryPolicyInstance, cancellationToken)); }