Ejemplo n.º 1
0
        /// <summary>
        /// Method for all points one year
        /// </summary>
        /// <param name="namechart">Specific name chart</param>
        /// <returns>Result is list points</returns>
        public static async Task <List <DataPointChart> > GetPointsData(string namechart)
        {
            Tuple <int, ArgChart.Date> timespan       = new Tuple <int, ArgChart.Date>(1, ArgChart.Date.year);
            Tuple <int, ArgChart.Date> rollingAverage = new Tuple <int, ArgChart.Date>(8, ArgChart.Date.hours);
            Uri newUri = UriEngine.GetUriforChart(BaseApi.Type.charts, namechart, timespan, rollingAverage, ArgChart.Formater.json);

            HttpClient client = new HttpClient();

            Debug.WriteLine(newUri.AbsoluteUri);
            string jsonData = string.Empty;

            try
            {
                jsonData = await client.GetStringAsync(newUri);
            }
            catch
            {
                //throw new Exception("Error in client.GetStringAsynch, maybe bad url address or params!");
                //Logging.Debug("Start app.", Logging.Level.DATABASE); // TODO vyresit kruhovou referenci na Logging

                Debug.WriteLine("Error in client.GetStringAsynch, maybe bad url address or params!");
                return(new List <DataPointChart>()); // empty data
            }

            List <DataPointChart> selectedList = new List <DataPointChart>();

            selectedList = DateSelector(RatersChart.GetRates(jsonData));
            return(selectedList);
            //return RatersChart.GetRates(jsonData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates if subscription state change can occur.
        /// </summary>
        /// <param name="subscriptionId">The subscription Id.</param>
        /// <param name="providerNamespace">The provider namespace.</param>
        /// <param name="resourceType">The resource type.</param>
        /// <param name="tenantId">The tenant ID of the subscription.</param>
        private async Task ValidateSubscriptionLifeCycleNotification(string subscriptionId, string providerNamespace, string resourceType, string tenantId)
        {
            // Call into ARM to get all resources of this resource type which are in successful provisioning state.
            var resourceRequestUri = UriEngine.GetResourceTypeResourceRequestUri(
                endpoint: this.ArmEndpoint,
                subscriptionId: subscriptionId,
                resourceProviderNamespace: providerNamespace,
                resourceType: resourceType,
                apiVersion: this.ApiVersion,
                filter: "ProvisioningState eq 1 AND Properties.group eq 'Avengers'");

            var getResponseFromARM = await this.CallRPSaaSForMetadata(resourceRequestUri, tenantId, HttpMethod.Get).ConfigureAwait(false);

            Logger.LogMessage($"Response status from ARM for GET resources '{resourceRequestUri}': '{getResponseFromARM.StatusCode}'");

            if (getResponseFromARM.StatusCode == HttpStatusCode.OK)
            {
                // Do any validations.
                var reader              = new StreamReader(await getResponseFromARM.Content.ReadAsStreamAsync().ConfigureAwait(false));
                var responseContent     = reader.ReadToEnd();
                var resourcesCollection = JsonConvert.DeserializeObject <ResponseWithContinuation <Resource[]> >(responseContent);

                Logger.LogMessage($"Retrived '{resourcesCollection?.Value?.Length}' resources from ARM for GET resources '{resourceRequestUri}'.");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method for Get Transaction max. 50 items
        /// </summary>
        /// <returns>Result is list transaction</returns>
        public static async Task<DataTransaction> GetTransactionData()
        {
            HttpClient client = new HttpClient();
            Uri BaseUrl = UriEngine.GetUriforTransaction(BaseApi.Type.address, BitcoinAddres, Arg.Formater.json);
            if (BaseUrl == null)
            {
                return new DataTransaction();
            }

            Debug.WriteLine(BaseUrl.AbsoluteUri);
            string jsonData = string.Empty;
            try
            {
                jsonData = await client.GetStringAsync(BaseUrl);
            }
            catch
            {
                //throw new Exception("Error in client.GetStringAsynch, maybe bad url address or params!");
                //Logging.Debug("Start app.", Logging.Level.DATABASE); // TODO vyresit kruhovou referenci na Logging

                Debug.WriteLine("Error in client.GetStringAsynch, maybe bad url address or params!");
                return new DataTransaction(); // empty data transaction
            }

            return RatersTransacion.GetRates(jsonData);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Completes the resource creation.
        /// </summary>
        /// <param name="subscriptionId">The subscription Id.</param>
        /// <param name="resourceGroup">The resource group.</param>
        /// <param name="providerNamespace">The provider namespace.</param>
        /// <param name="resourceType">The resource type.</param>
        /// <param name="resourceName">The resource name.</param>
        /// <param name="tenantId">The tenant Id.</param>
        private async Task CompleteResourceCreation(string subscriptionId, string resourceGroup, string providerNamespace, string resourceType, string resourceName, string tenantId)
        {
            // Call into ARM to get all resources of this resource type within the resource group.
            var resourceRequestUri = UriEngine.GetResourceGroupResourceRequestUri(
                endpoint: this.ArmEndpoint,
                subscriptionId: subscriptionId,
                resourceGroupName: resourceGroup,
                resourceProviderNamespace: providerNamespace,
                resourceType: resourceType,
                resourceName: resourceName,
                apiVersion: this.ApiVersion);

            var getResponseFromARM = await this.CallRPSaaSForMetadata(resourceRequestUri, tenantId, HttpMethod.Get).ConfigureAwait(false);

            Logger.LogMessage($"Response status from ARM for GET resource '{resourceRequestUri}': '{getResponseFromARM.StatusCode}'");

            if (getResponseFromARM.StatusCode == HttpStatusCode.OK)
            {
                var reader     = new StreamReader(await getResponseFromARM.Content.ReadAsStreamAsync().ConfigureAwait(false));
                var getContent = reader.ReadToEnd();
                var resource   = JsonConvert.DeserializeObject <Resource>(getContent);

                if (resource != null)
                {
                    // Add some tags on this resource.
                    // In order to do a PUT, ensure that all the properties specified in the swagger
                    // for PUT are present in the payload.
                    var updatedResource = new Resource
                    {
                        Tags = resource.Tags,
                    };

                    if (updatedResource.Tags.ContainsKey("contosoPrivateTag"))
                    {
                        updatedResource.Tags["contosoPrivateTag"] = $"Updated in OnResourceCreationCompleted at '{DateTime.UtcNow}'";
                    }
                    else
                    {
                        updatedResource.Tags.TryAdd("contosoPrivateTag", $"Updated in OnResourceCreationCompleted at '{DateTime.UtcNow}'");
                    }

                    var putResponseFromARM = await this.CallRPSaaSForMetadata(resourceRequestUri, tenantId, HttpMethod.Patch, updatedResource).ConfigureAwait(false);

                    Logger.LogMessage($"Response code from ARM for PUT: '{putResponseFromARM.StatusCode}'");
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Validates if the number of resources in the resource group is under the limit.
        /// </summary>
        /// <param name="subscriptionId">The subscription Id.</param>
        /// <param name="resourceGroup">The resource group.</param>
        /// <param name="providerNamespace">The provider namespace.</param>
        /// <param name="resourceType">The resource type.</param>
        /// <param name="tenantId">The tenant Id.</param>
        private async Task <IActionResult> ValidateMaximumResourceCounts(string subscriptionId, string resourceGroup, string providerNamespace, string resourceType, string tenantId)
        {
            ErrorResponse errorRespone = null;

            // Call into ARM to get all resources of this resource type within the resource group.
            var resourceCollectionUri = UriEngine.GetResourceGroupResourceRequestUri(
                endpoint: this.ArmEndpoint,
                subscriptionId: subscriptionId,
                resourceGroupName: resourceGroup,
                resourceProviderNamespace: providerNamespace,
                resourceType: resourceType,
                resourceName: null,
                apiVersion: this.ApiVersion);

            var responseFromARM = await this.CallRPSaaSForMetadata(resourceCollectionUri, tenantId, HttpMethod.Get).ConfigureAwait(false);

            Logger.LogMessage($"Response status from ARM: '{responseFromARM.StatusCode}'");

            if (responseFromARM.StatusCode == HttpStatusCode.OK)
            {
                var reader              = new StreamReader(await responseFromARM.Content.ReadAsStreamAsync().ConfigureAwait(false));
                var responseContent     = reader.ReadToEnd();
                var resourcesCollection = JsonConvert.DeserializeObject <ResponseWithContinuation <Resource[]> >(responseContent);

                if (resourcesCollection.Value != null)
                {
                    // Return error if we have more than max count resources of this type in the resource group.
                    if (resourcesCollection.Value.Count() >= this.MaxCount)
                    {
                        errorRespone = new ErrorResponse
                        {
                            Error = new Error
                            {
                                Code    = "SampleValidationErrorCode",
                                Message = "SampleValidationErrorMessage - Maximum number of resources per resource group count hit.",
                            },
                            Status = "Failed",
                        };
                    }
                }
            }

            // Required response format in case of validation failure.
            return(ContosoController.CreateResponse(
                       statusCode: HttpStatusCode.OK,
                       value: errorRespone));
        }
Ejemplo n.º 6
0
        public static async Task <List <DataTricker> > GetMarketData()
        {
            Uri newUri = UriEngine.GetUriforChart(BaseApi.Type.ticker);

            HttpClient client = new HttpClient();

            Debug.WriteLine(newUri.AbsoluteUri);
            string jsonData = string.Empty;

            try
            {
                jsonData = await client.GetStringAsync(newUri);
            }
            catch
            {
                //throw new Exception("Error in client.GetStringAsynch, maybe bad url address or params!");
                //Logging.Debug("Start app.", Logging.Level.DATABASE); // TODO vyresit kruhovou referenci na Logging

                Debug.WriteLine("Error in client.GetStringAsynch, maybe bad url address or params!");
                return(new List <DataTricker>()); // empty data
            }

            return(RatesTicker.GetRates(jsonData));
        }