Exemplo n.º 1
0
        /// <summary>
        ///     Exports and saves declare model into file as json
        /// </summary>
        /// <param name="model">Declare model</param>
        /// <param name="path">Path to the folder where to export</param>
        /// <param name="fileName">Name of the saved file</param>
        /// <returns></returns>
        /// <exception cref="Exception">File already exists in the folder</exception>
        public async Task ExportSaveModelAsync(DeclareModel model, string path, string fileName)
        {
            fileName ??= model.Name;
            if (File.Exists(Path.Combine(path + ".json", fileName)) || !Directory.Exists(path))
            {
                throw new Exception("Path does not exist or file with given name already exists");
            }

            var json = JsonConvert.SerializeObject(model, new ParametrizedTemplateConverter());
            await File.WriteAllTextAsync(Path.Combine(path, fileName + ".json"), json);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Evaluates trace on a declare model
        /// </summary>
        /// <param name="model">Declare model towards which trace is to be checked</param>
        /// <param name="trace">Trace to be checked</param>
        /// <returns>Evaluation of trace for a model and each template and constraint in it.</returns>
        public TraceEvaluation EvaluateTrace(DeclareModel model, List <Event> trace)
        {
            var             templateEvaluations = new List <TemplateEvaluation>();
            TraceEvaluation evaluation          = new(trace, templateEvaluations);

            foreach (var template in model.Constraints)
            {
                if (template.TemplateDescription.TemplateParametersType != TemplateTypes.BiTemplate)
                {
                    continue;
                }

                var templateEvaluation = EvaluateTrace(template, trace);
                templateEvaluations.Add(templateEvaluation);
            }

            evaluation.UpdateHealthiness();
            return(evaluation);
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Exports Declare model into json string
 /// </summary>
 /// <param name="model">Declare model</param>
 /// <returns>json string</returns>
 public async Task <string> ExportModelAsync(DeclareModel model)
 {
     return(await Task.Run(() =>
                           JsonConvert.SerializeObject(model, new ParametrizedTemplateConverter())));
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Exports Declare model into json string
 /// </summary>
 /// <param name="model">Declare model</param>
 /// <returns>json string</returns>
 public string ExportModel(DeclareModel model)
 {
     return(JsonConvert.SerializeObject(model, new ParametrizedTemplateConverter()));
 }