Exemplo n.º 1
0
        /// <summary>
        /// Inserts the right stream for key identifier asynchronous.
        /// </summary>
        /// <param name="keyIdentifier">The key identifier.</param>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        private async Task InsertRightStreamForKeyIdentifierAsync(int keyIdentifier, Stream stream)
        {
            string rightPartFilePath = GetFilePathForPart(DiffPartEnum.Right, keyIdentifier);

            #region Set Db part

            var diffPartsEnt = new DiffPartsEntity
            {
                KeyIdentifier       = keyIdentifier,
                RightPartFilePath   = rightPartFilePath,
                IsRightPartUpdating = true.ToString(),
                RightPartTimestamp  = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
            };

            _genericRepository.Insert(diffPartsEnt);

            await _genericRepository.DbContext.SaveChangesAsync();

            #endregion

            await SaveFile(stream, rightPartFilePath);

            #region Set Db part

            diffPartsEnt.IsRightPartUpdating = false.ToString();

            _genericRepository.UpdateFieldsInEntity(diffPartsEnt,
                                                    new List <string> {
                $"{nameof(diffPartsEnt.IsRightPartUpdating)}"
            });

            await _genericRepository.DbContext.SaveChangesAsync();

            #endregion
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the serialized calculated diffs for key identifier asynchronous.
        /// </summary>
        /// <param name="keyIdentifier">The key identifier.</param>
        /// <param name="calculatedDiffs">The calculated diffs.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">calculatedDiffs</exception>
        /// <exception cref="System.ApplicationException">keyIdentifier</exception>
        public async Task SaveSerializedCalculatedDiffsForKeyIdentifierAsync(int keyIdentifier, string calculatedDiffs)
        {
            if (calculatedDiffs == null)
            {
                throw new ArgumentNullException($"'{nameof(calculatedDiffs)}' parameter must not be null");
            }

            int?id = await GetIdForKeyIdentifier(keyIdentifier);

            if (id == null)
            {
                throw new ApplicationException(
                          $"Could not find the {nameof(keyIdentifier)} = {keyIdentifier} in database");
            }

            var diffPartsEntity = new DiffPartsEntity
            {
                Id = id.Value,
                CalculatedDiffsMetadata          = calculatedDiffs,
                CalculatedDiffsMetadataTimestamp = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
            };

            _genericRepository.UpdateFieldsInEntity(diffPartsEntity,
                                                    new List <string>
            {
                $"{nameof(diffPartsEntity.CalculatedDiffsMetadata)}",
                $"{nameof(diffPartsEntity.CalculatedDiffsMetadataTimestamp)}"
            });

            await _genericRepository.DbContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the right stream for key identifier asynchronous.
        /// </summary>
        /// <param name="keyIdentifier">The key identifier.</param>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        /// <exception cref="System.ApplicationException">keyIdentifier</exception>
        private async Task UpdateRightStreamForKeyIdentifierAsync(int keyIdentifier, Stream stream)
        {
            int?id = await GetIdForKeyIdentifier(keyIdentifier);

            if (id == null)
            {
                throw new ApplicationException(
                          $"Could not find the {nameof(keyIdentifier)} = {keyIdentifier} in database");
            }

            string rightPartFilePath = GetFilePathForPart(DiffPartEnum.Right, keyIdentifier);

            #region Set Db part

            var diffPartsEntity = new DiffPartsEntity
            {
                Id = id.Value,
                RightPartFilePath   = rightPartFilePath,
                IsRightPartUpdating = true.ToString(),
                RightPartTimestamp  = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
            };

            _genericRepository.UpdateFieldsInEntity(diffPartsEntity,
                                                    new List <string>
            {
                $"{nameof(diffPartsEntity.RightPartFilePath)}",
                $"{nameof(diffPartsEntity.IsRightPartUpdating)}",
                $"{nameof(diffPartsEntity.RightPartTimestamp)}"
            });

            await _genericRepository.DbContext.SaveChangesAsync();

            #endregion

            await SaveFile(stream, rightPartFilePath);

            #region Set Db part

            diffPartsEntity.IsRightPartUpdating = false.ToString();

            _genericRepository.UpdateFieldsInEntity(diffPartsEntity,
                                                    new List <string>
            {
                $"{nameof(diffPartsEntity.IsRightPartUpdating)}"
            });

            await _genericRepository.DbContext.SaveChangesAsync();

            #endregion
        }