/// <inheritdoc />
        /// <remarks>
        /// To avoid problems with writing to an existing file, the export is done to a temp file first.
        /// When the export was successful the file is moved to the given <see cref="filePath"/>.
        /// </remarks>
        public bool Export()
        {
            ValidateData();

            PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, generalInput, getNormativeAssessmentLevelFunc, filePath);

            string tempFilePath = $"{filePath}.temp";

            try
            {
                using (IPersister persister = persistenceFactory.CreateArchivePersister(tempFilePath, persistableDataModel))
                {
                    persister.Persist();
                }

                MoveTempFileToFinal(tempFilePath);
            }
            catch (Exception)
            {
                File.Delete(tempFilePath);

                log.ErrorFormat("{0} {1}", string.Format(CoreCommonUtilResources.Error_General_output_error_0, filePath), Resources.MacroStabilityInwardsCalculationExporter_Export_no_stability_project_exported);
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Instruments message <paramref name="message"/>.
        /// </summary>
        /// <param name="message"></param>
        private void InternalInstrument(IMessage message)
        {
            lock (syncRoot)
            {
                if (!IsInstrumentationEnabled)
                {
                    return;
                }

                //
                // Resolving persister names.
                string[] persisterNames;
                persisterNames = ResolvePersisterNames(message);

                if (persisterNames == null || persisterNames.GetLength(0) == 0)
                {
                    throw new InstrumentationException(string.Format(
                                                           Strings.InstrumentationManager_InternalInstrument_UnableToResolvePersistersForMessage,
                                                           message.GetType().FullName, message.Source, message.Severity));
                }

                //
                // Persisting message.
                foreach (string persisterName in persisterNames)
                {
                    if (!Persisters.ContainsKey(persisterName))
                    {
                        throw new InstrumentationException(string.Format(
                                                               Strings.InstrumentationManager_InternalInstrument_NoPersistersWithGivenNameRegistered,
                                                               persisterName));
                    }

                    IPersister persister = Persisters[persisterName];
                    persister.Persist(message);
                } // foreach
            }     // lock
        }
        public List <UpdatableElement> Update(string projectId, long from, List <UpdatableElement> toSynchronize)
        {
            lock (string.Intern(projectId))
            {
                var currentState = persister.Read(projectId);
                //first we update the current state
                foreach (var updatedTransaction in toSynchronize)
                {
                    var id = updatedTransaction.id;
                    //It is a new transaction, we just add it, else we might have to remove a previous version.
                    if (currentState.Count(o => o.id == id) != 0)
                    {
                        var existingTransaction = currentState.First(o => o.id == id);
                        if (existingTransaction.lastUpdated < updatedTransaction.lastUpdated)
                        {
                            //Then we update
                            currentState.Remove(existingTransaction);
                        }
                        else
                        {
                            //else the existing transaction is newer, so we keep the newest state.
                            //We ignore the out of date update
                            continue;
                        }
                    }
                    var newStateTransaction = updatedTransaction;
                    newStateTransaction.lastUpdated = DateTime.Now.JavascriptTicks();
                    currentState.Add(newStateTransaction);
                }

                if (currentState.Any())
                {
                    persister.Persist(projectId, currentState);
                }
                return(currentState.Where(o => o.lastUpdated >= from).ToList());
            }
        }
        public async Task <string> HandleUploadEvent(S3Event s3event, ILambdaContext context)
        {
            var logger   = context.Logger;
            var s3Record = s3event.Records[0].S3;

            logger.LogLine(String.Format("bucket {0}, key {1}", s3Record.Bucket.Name, s3Record.Object.Key));

            var request = new GetObjectRequest()
            {
                BucketName = s3Record.Bucket.Name,
                Key        = s3Record.Object.Key,
                ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.None
            };

            var response = await s3client.GetObjectAsync(request);

            var message = ParseResponse(response, logger);

            var document = persister.Persist(message, logger);

            NotifyAsync(message.Source);

            return(document.ToString());
        }