Пример #1
0
        public Task <InstanceEvent> InsertInstanceEvent(InstanceEvent instanceEvent)
        {
            lock (TestDataUtil.dataLock)
            {
                string instanceId = instanceEvent.InstanceId;

                if (instanceId.Contains("/"))
                {
                    instanceId = instanceEvent.InstanceId.Split("/")[1];
                }

                if (!Directory.Exists(GetInstanceEventsPath(instanceId, instanceEvent.InstanceOwnerPartyId)))
                {
                    Directory.CreateDirectory(GetInstanceEventsPath(instanceId, instanceEvent.InstanceOwnerPartyId));
                }

                instanceEvent.Id = Guid.NewGuid();


                string instancePath = GetInstanceEventPath(instanceId, instanceEvent.InstanceOwnerPartyId, instanceEvent.Id.Value);
                File.WriteAllText(instancePath, instanceEvent.ToString());

                return(Task.FromResult(instanceEvent));
            }
        }
Пример #2
0
        public Task<InstanceEvent> InsertInstanceEvent(InstanceEvent instanceEvent)
        {
            instanceEvent.Id = Guid.NewGuid();

            string path = GetInstanceEventPath(instanceEvent.InstanceId, instanceEvent.Id.Value);
            Directory.CreateDirectory(GetInstanceEventFolder());
            File.WriteAllText(path, instanceEvent.ToString());

            return Task.FromResult(instanceEvent);
        }
Пример #3
0
        /// <inheritdoc/>
        public Task <string> SaveInstanceEvent(object dataToSerialize, string applicationOwnerId, string applicationId)
        {
            InstanceEvent instanceEvent = (InstanceEvent)dataToSerialize;

            instanceEvent.Id = Guid.NewGuid();
            instanceEvent.CreatedDateTime = DateTime.UtcNow;

            string developer        = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
            string testDataForParty = _settings.GetTestdataForPartyPath(applicationOwnerId, applicationId, developer);
            string folderForEvents  = $"{testDataForParty}{instanceEvent.InstanceOwnerId}/{instanceEvent.InstanceId}/events";

            Directory.CreateDirectory(folderForEvents);
            string eventFilePath = $"{folderForEvents}/{instanceEvent.Id}.json";

            File.WriteAllText(eventFilePath, instanceEvent.ToString(), Encoding.UTF8);

            return(Task.FromResult(instanceEvent.Id.ToString()));
        }
Пример #4
0
        /// <inheritdoc/>
        public async Task <string> SaveInstanceEvent(object dataToSerialize, string applicationOwnerId, string applicationId)
        {
            InstanceEvent instanceEvent = (InstanceEvent)dataToSerialize;

            instanceEvent.CreatedDateTime = DateTime.UtcNow;
            string apiUrl = $"{_platformSettings.GetApiStorageEndpoint}instances/{instanceEvent.InstanceId}/events";

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(apiUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                try
                {
                    HttpResponseMessage response = await client.PostAsync(apiUrl, new StringContent(instanceEvent.ToString(), Encoding.UTF8, "application/json"));

                    string eventData = await response.Content.ReadAsStringAsync();

                    InstanceEvent result = JsonConvert.DeserializeObject <InstanceEvent>(eventData);
                    return(result.Id.ToString());
                }
                catch
                {
                    throw new Exception("Unable to store instance event");
                }
            }
        }
Пример #5
0
        /// <inheritdoc/>
        public async Task <string> SaveInstanceEvent(object dataToSerialize, string org, string app)
        {
            InstanceEvent instanceEvent = (InstanceEvent)dataToSerialize;

            instanceEvent.Created = DateTime.UtcNow;
            string apiUrl = $"instances/{instanceEvent.InstanceId}/events";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);


            HttpResponseMessage response = await _client.PostAsync(token, apiUrl, new StringContent(instanceEvent.ToString(), Encoding.UTF8, "application/json"));

            if (response.IsSuccessStatusCode)
            {
                string eventData = await response.Content.ReadAsStringAsync();

                InstanceEvent result = JsonConvert.DeserializeObject <InstanceEvent>(eventData);
                return(result.Id.ToString());
            }

            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #6
0
        /// <summary>
        /// Inserts new instance event into the instanceEvent collection.
        /// </summary>
        /// <param name="instanceEvent">Instance event to be stored. </param>
        /// <returns>The stored instance event.</returns>
        public async Task <string> PostInstanceEvent(InstanceEvent instanceEvent)
        {
            string requestUri            = $"{versionPrefix}/instances/{instanceEvent.InstanceId}/events";
            HttpResponseMessage response = await client.PostAsync(hostName + requestUri, new StringContent(instanceEvent.ToString(), Encoding.UTF8, "application/json"));

            if (response.IsSuccessStatusCode)
            {
                string newId = await response.Content.ReadAsStringAsync();

                return(newId);
            }

            throw new StorageClientException($"POST error: {response.ReasonPhrase}");
        }
Пример #7
0
        /// <inheritdoc/>
        public async Task <string> SaveInstanceEvent(object dataToSerialize, string org, string appName)
        {
            InstanceEvent instanceEvent = (InstanceEvent)dataToSerialize;

            instanceEvent.CreatedDateTime = DateTime.UtcNow;
            string apiUrl = $"instances/{instanceEvent.InstanceId}/events";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _cookieOptions.Cookie.Name);

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);

            try
            {
                HttpResponseMessage response = await _client.PostAsync(apiUrl, new StringContent(instanceEvent.ToString(), Encoding.UTF8, "application/json"));

                string eventData = await response.Content.ReadAsStringAsync();

                InstanceEvent result = JsonConvert.DeserializeObject <InstanceEvent>(eventData);
                return(result.Id.ToString());
            }
            catch
            {
                _logger.LogError($"Unable to store instance event");
                return(null);
            }
        }
Пример #8
0
        /// <summary>
        /// Inserts new instance event into the instanceEvent collection.
        /// </summary>
        /// <param name="instanceEvent">Instance event to be stored. </param>
        /// <returns>The stored instance event.</returns>
        public async Task <string> PostInstanceEvent(InstanceEvent instanceEvent)
        {
            string requestUri            = $"{versionPrefix}/instances/{instanceEvent.InstanceId}/events";
            HttpResponseMessage response = await client.PostAsync(hostName + requestUri, new StringContent(instanceEvent.ToString(), Encoding.UTF8, "application/json"));

            string newId = await response.Content.ReadAsStringAsync();

            return(newId);
        }