示例#1
0
        /// <summary>Initializes a new instance of the <see cref="ResponseModelBase" /> class.</summary>
        /// <param name="operationModel">The operation model.</param>
        /// <param name="statusCode">The status code.</param>
        /// <param name="response">The response.</param>
        /// <param name="isPrimarySuccessResponse">Specifies whether this is the success response.</param>
        /// <param name="exceptionSchema">The exception schema.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="generator">The client generator.</param>
        protected ResponseModelBase(IOperationModel operationModel,
                                    string statusCode, SwaggerResponse response, bool isPrimarySuccessResponse,
                                    JsonSchema4 exceptionSchema, CodeGeneratorSettingsBase settings, IClientGenerator generator)
        {
            _response        = response;
            _exceptionSchema = exceptionSchema;
            _generator       = generator;
            _settings        = settings;
            _operationModel  = operationModel;

            IsPrimarySuccessResponse = isPrimarySuccessResponse;
            StatusCode = statusCode;
        }
示例#2
0
        public async Task SaveOperation(IOperationModel newOperation, CancellationToken token)
        {
            if (newOperation == null)
            {
                return;
            }

            await newOperation.Save(token);

            //Adding an new operation in begin of list
            Operations.Insert(0, newOperation);
            OnPropertyChanged(nameof(Operations));
        }
示例#3
0
        /// <summary>Gets a value indicating whether this is success response.</summary>
        public bool IsSuccess(IOperationModel operationModel)
        {
            if (_isPrimarySuccessResponse)
            {
                return(true);
            }

            var primarySuccessResponse = operationModel.Responses.FirstOrDefault(r => r.IsPrimarySuccessResponse);

            return(HttpUtilities.IsSuccessStatusCode(StatusCode) && (
                       primarySuccessResponse == null ||
                       primarySuccessResponse.Type == Type
                       ));
        }
示例#4
0
        //private static string GetMethodCallParameters(IOperationModel operation)
        //{
        //    return operation.Parameters
        //        .Select(x => $"{LowerFirst(x.Name)}: {LowerFirst(x.Name)}")
        //        .Aggregate((x, y) => $"{x}, {y}");
        //}

        private static string GetReturnType(IOperationModel o)
        {
            if (o.ReturnType.TypeReference.Name.StartsWith("PagedResult"))
            {
                return($"Contracts.PagedResultDTO<{ConvertType(o.ReturnType.TypeReference.Name)}>");
            }

            if (o.ReturnType.TypeReference.IsCollection)
            {
                return($"{ConvertType(o.ReturnType.TypeReference.Name)}[]");
            }

            return($"{ConvertType(o.ReturnType.TypeReference.Name)}");
        }
示例#5
0
        private HttpVerb GetHttpVerb(IOperationModel operation)
        {
            var verb = operation.GetStereotypeProperty("Http", "Verb", "AUTO").ToUpper();

            if (verb != "AUTO")
            {
                return(Enum.TryParse(verb, out HttpVerb verbEnum) ? verbEnum : HttpVerb.POST);
            }
            if (operation.ReturnType == null || operation.Parameters.Any(x => x.TypeReference.Type == ReferenceType.ClassType))
            {
                return(HttpVerb.POST);
            }
            return(HttpVerb.GET);
        }
        public override void RemoveJob(IOperationModel operationModel)
        {
            if (ActiveJobs.ContainsKey(operationModel))
            {
                foreach (var executionId in ActiveJobs[operationModel].Keys)
                {
                    ActiveJobs[operationModel][executionId].Stop();
                    ActiveJobs[operationModel][executionId].JobUpdate    -= job_JobUpdate;
                    ActiveJobs[operationModel][executionId].JobCompleted -= job_JobCompleted;
                }

                ActiveJobs.Remove(operationModel);
            }
        }
示例#7
0
        private static HttpVerb GetHttpVerb(IOperationModel operation)
        {
            var verb = operation.GetStereotypeProperty("Http", "Verb", "AUTO").ToUpper();

            if (verb != "AUTO")
            {
                return(Enum.TryParse(verb, out HttpVerb verbEnum) ? verbEnum : HttpVerb.POST);
            }

            if (operation.ReturnType == null || operation.Parameters.Any(IsFromBody))
            {
                return(HttpVerb.POST);
            }

            return(HttpVerb.GET);
        }
示例#8
0
        public static bool RequiresPayloadObject(this IOperationModel operation)
        {
            if (!operation.Parameters.Any())
            {
                return(false);
            }

            var verb = GetHttpVerb(operation);

            if (verb != HttpVerb.POST && verb != HttpVerb.PUT)
            {
                return(false);
            }

            return(operation.Parameters.Count(IsFromBody) > 1);
        }
示例#9
0
        public static bool UsesBodyContent(this IOperationModel operation)
        {
            if (!operation.Parameters.Any())
            {
                return(false);
            }

            var verb = GetHttpVerb(operation);

            if (verb != HttpVerb.POST && verb != HttpVerb.PUT)
            {
                return(false);
            }

            return(operation.Parameters.Any(IsFromBody));
        }
        public override string AfterTransaction(IServiceModel service, IOperationModel operation)
        {
            var returnString = @"
";

            if (operation.ReturnType != null)
            {
                returnString += $@"
                Logger.Trace(""{FormatOperationName(operation.Name)}Returning: {{0}}"", SanitizingJsonSerializer.Serialize(result));";
            }

            returnString += $@"
                Logger.Info(""{FormatOperationName(operation.Name)}Duration (ms): {{0:#,0}}"", stopWatch.ElapsedMilliseconds);";

            return(returnString);
        }
示例#11
0
        /// <summary>Initializes a new instance of the <see cref="ResponseModelBase" /> class.</summary>
        /// <param name="operationModel">The operation model.</param>
        /// <param name="operation">The operation.</param>
        /// <param name="statusCode">The status code.</param>
        /// <param name="response">The response.</param>
        /// <param name="isPrimarySuccessResponse">Specifies whether this is the success response.</param>
        /// <param name="exceptionSchema">The exception schema.</param>
        /// <param name="resolver">The resolver.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="generator">The client generator.</param>
        protected ResponseModelBase(IOperationModel operationModel,
                                    SwaggerOperation operation,
                                    string statusCode, SwaggerResponse response, bool isPrimarySuccessResponse,
                                    JsonSchema4 exceptionSchema, TypeResolverBase resolver, CodeGeneratorSettingsBase settings, IClientGenerator generator)
        {
            _response        = response;
            _exceptionSchema = exceptionSchema;
            _generator       = generator;
            _settings        = settings;
            _resolver        = resolver;
            _operationModel  = operationModel;

            StatusCode = statusCode;
            IsPrimarySuccessResponse = isPrimarySuccessResponse;
            ActualResponseSchema     = response.GetActualResponseSchema(operation);
        }
示例#12
0
        /// <summary>
        /// конвертировать курс
        /// </summary>
        public void Convert(IConvertParam _param)
        {
            if (_param == null)
            {
                throw new ArgumentNullException("Не переданы параметры конвертации");
            }

            if (IsConvert == false)
            {
                throw new Exception("Не выбран элемент для конвертации");
            }

            convParams = (XSLTConvertParams)_param;
            if (convParams == null)
            {
                throw new Exception("Неидентифицированные пареметры конвертации: " + _param.GetType());
            }

            convParams.SetFlashParam(flashParam);

            if (!convParams.IsParamsValid)
            {
                throw new Exception("Ошибка параметров конвертации. " + convParams.ErrorMessage + "\n Исправьте ошибку и перезапустите программу.");
            }

            IOperationModel conv = ConvertorFactory.Create(this, convParams);

            conv.StepChange += conv_StepChange;
            try
            {
                conv.Prepare();
                conv.Do();
                conv.PostStep();
            }
            catch (Exception ex)
            {
                if (conv.Undo())
                {
                    throw new Exception(ex.Message);
                }
                else
                {
                    throw new Exception("Произошла ошибка при конвертации: " + ex.Message + ". Действия конвертации не могут быть отменены: " + conv.LastError);
                }
            }
        }
 private void recursiveCheckForCircularBrushing(IOperationModel current, HashSet <IOperationModel> chain)
 {
     if (!chain.Contains(current))
     {
         var links = ((IFilterConsumerOperationModel)current).LinkModels;
         foreach (var link in links)
         {
             chain.Add(link.ToOperationModel);
             recursiveCheckForCircularBrushing(link.ToOperationModel, chain);
         }
         var brushes = ((IBrushableOperationModel)current).BrushOperationModels;
         foreach (var brush in brushes)
         {
             chain.Add(brush);
             recursiveCheckForCircularBrushing(brush, chain);
         }
     }
 }
示例#14
0
        private string GetOperationParameters(IOperationModel operation)
        {
            if (!operation.Parameters.Any())
            {
                return(string.Empty);
            }
            var verb = GetHttpVerb(operation);

            switch (verb)
            {
            case HttpVerb.POST:
            case HttpVerb.PUT:
                return(RequiresPayloadObject(operation)
                        ? operation.Parameters
                       .Where(x => !IsFromBody(x))
                       .Select(x => $"{GetParameterBindingAttribute(x)}{GetTypeName(x.TypeReference)} {x.Name}")
                       .Concat(new [] { $"{GetPayloadObjectTypeName(operation)} bodyPayload" })
                       .Aggregate((x, y) => $"{x}, {y}")
                        : operation.Parameters
                       .Select(x => $"{GetParameterBindingAttribute(x)}{GetTypeName(x.TypeReference)} {x.Name}")
                       .Aggregate((x, y) => $"{x}, {y}"));

            case HttpVerb.GET:
            case HttpVerb.DELETE:
                if (operation.Parameters.Any(x => GetParameterBindingAttribute(x) == "[FromBody]"))
                {
                    throw new Exception($"Intent.AspNet.WebApi: [{Model.Name}.{operation.Name}] HTTP {verb} does not support parameters with a [FromBody] attribute.");
                }

                if (operation.Parameters.Any(x => x.TypeReference.Type == ReferenceType.ClassType))
                {
                    Logging.Log.Warning($@"Intent.AspNet.WebApi: [{Model.Name}.{operation.Name}] Passing complex types into HTTP {verb} operations is not well supported by this module.
    We recommend using a POST or PUT verb.");
                    // Log warning
                }

                return(operation.Parameters
                       .Select(x => $"{GetTypeName(x.TypeReference)} {x.Name}")
                       .Aggregate((x, y) => x + ", " + y));

            default:
                throw new NotSupportedException($"{verb} not supported");
            }
        }
        private string GetReadAs(IOperationModel operation)
        {
            return($"ReadAsAsync<{GetOperationReturnType(operation)}>()");


            // UsesRawSignature not supported (yet?) in this new template, WebApi controllers aren't supporting it in the new template either
            //if (!operation.UsesRawSignature)
            //{
            //    return $"ReadAsAsync<{operation.ReturnType.FullName}>()";
            //}

            //if (operation.ReturnType.FullName.Equals(typeof(byte[]).Name, StringComparison.InvariantCultureIgnoreCase) ||
            //    operation.ReturnType.FullName.Equals(typeof(byte[]).FullName, StringComparison.InvariantCultureIgnoreCase))
            //{
            //    return "ReadAsByteArrayAsync()";
            //}

            //return $"ReadAsAsync<{operation.ReturnType.FullName}>()";
        }
        private HttpVerb GetHttpVerb(IOperationModel operation)
        {
            var verb = operation.GetStereotypeProperty("Http", "Verb", "AUTO").ToUpper();

            if (verb != "AUTO")
            {
                return(Enum.TryParse(verb, out HttpVerb verbEnum) ? verbEnum : HttpVerb.POST);
            }
            if (operation.ReturnType == null || operation.Parameters.Any(x => x.TypeReference.Type == ReferenceType.ClassType))
            {
                var hasIdParam = operation.Parameters.Any(x => x.Name.ToLower().EndsWith("id") && x.TypeReference.Type != ReferenceType.ClassType);
                if (hasIdParam && new[] { "delete", "remove" }.Any(x => operation.Name.ToLower().Contains(x)))
                {
                    return(HttpVerb.DELETE);
                }
                return(hasIdParam ? HttpVerb.PUT : HttpVerb.POST);
            }
            return(HttpVerb.GET);
        }
        private string GetOperationCallParameters(IOperationModel operation)
        {
            if (!operation.Parameters.Any())
            {
                return(string.Empty);
            }

            var verb = GetHttpVerb(operation);

            switch (verb)
            {
            case HttpVerb.POST:
            case HttpVerb.PUT:
            case HttpVerb.GET:
            case HttpVerb.DELETE:
                return(operation.Parameters.Select(x => x.Name).Aggregate((x, y) => $"{x}, {y}"));

            default:
                throw new NotSupportedException($"{verb} not supported");
            }
        }
示例#18
0
        private static bool RequiresPayloadObject(IOperationModel operation)
        {
            if (!operation.Parameters.Any())
            {
                return(false);
            }

            if (operation.GetStereotypeProperty("Http", "Payload", "AUTO") == "Payload Object")
            {
                return(true);
            }

            var verb = GetHttpVerb(operation);

            if (verb != HttpVerb.POST && verb != HttpVerb.PUT)
            {
                return(false);
            }

            return(operation.Parameters.Count(IsFromBody) > 1);
        }
示例#19
0
 private IServiceModel GetServiceModel()
 {
     // Fabricate a ServiceModel for use by decorators.
     return(_serviceModel ?? (_serviceModel = new ServiceModel(
                                  id: Guid.Empty.ToString(),
                                  name: ClassName,
                                  application: new Application(
                                      id: Project.Application.Id,
                                      name: Project.Application.ApplicationName),
                                  parentFolder: null,
                                  operations: new[]
     {
         _operationModel = new OperationModel(
             id: Guid.Empty.ToString(),
             name: "ConsumeMessage",
             parameters: new List <IOperationParameterModel>
         {
             new OperationParameterModel(
                 id: Guid.Empty.ToString(),
                 name: "content",
                 typeReference: new ClassTypeReference(
                     id: Guid.Empty.ToString(),
                     name: "string",
                     isNullable: false,
                     isCollection: false,
                     folder: null,
                     stereotypes: new IStereotype[0],
                     comment: null),
                 stereotypes: new IStereotype[0],
                 comment: null)
         },
             returnType: null,
             stereotypes: new IStereotype[0],
             comment: null),
     },
                                  stereotypes: new IStereotype[0],
                                  comment: null)));
 }
示例#20
0
        public OperationDialogViewModel(IOperationModel model, OperationViewType viewType, IToastService toastService, ILocalizationService localizationService)
        {
            _toastService        = toastService;
            _localizationService = localizationService;
            Model = model;
            IsNew = model.IsNew;
            switch (viewType)
            {
            case OperationViewType.Income:
                IsIncome = true;
                break;

            case OperationViewType.Expense:
                IsExpense = true;
                break;

            case OperationViewType.Transfer:
                IsTransfer = true;
                break;
            }

            Accounts   = new List <Account>();
            Categories = new List <Category>();
        }
 public string GetImplementation(IMetaDataManager metaDataManager, SoftwareFactory.Engine.IApplication application, IClass domainModel, IOperationModel operationModel)
 {
     return($@"var existing{domainModel.Name} ={ (operationModel.IsAsync() ? " await" : "") } {domainModel.Name.ToPrivateMember()}Repository.FindById{ (operationModel.IsAsync() ? "Async" : "") }(id);
         {domainModel.Name.ToPrivateMember()}Repository.Remove(existing{domainModel.Name});");
 }
示例#22
0
 /// <summary>Initializes a new instance of the <see cref="CSharpResponseModel"/> class.</summary>
 /// <param name="operationModel">The operation model.</param>
 /// <param name="operation">The operation.</param>
 /// <param name="statusCode">The status code.</param>
 /// <param name="response">The response.</param>
 /// <param name="isPrimarySuccessResponse">Specifies whether this is the success response.</param>
 /// <param name="exceptionSchema">The exception schema.</param>
 /// <param name="generator">The client generator.</param>
 /// <param name="resolver">The resolver.</param>
 /// <param name="settings">The settings.</param>
 public CSharpResponseModel(IOperationModel operationModel, SwaggerOperation operation, string statusCode, SwaggerResponse response,
                            bool isPrimarySuccessResponse, JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, CodeGeneratorSettingsBase settings)
     : base(operationModel, operation, statusCode, response, isPrimarySuccessResponse, exceptionSchema, resolver, settings, generator)
 {
 }
        public bool Match(IMetaDataManager metaDataManager, SoftwareFactory.Engine.IApplication application, IClass domainModel, IOperationModel operationModel)
        {
            if (operationModel.Parameters.Count() != 1)
            {
                return(false);
            }

            if (!operationModel.Parameters.Any(p => string.Equals(p.Name, "id", StringComparison.OrdinalIgnoreCase)))
            {
                return(false);
            }

            if (operationModel.ReturnType != null)
            {
                return(false);
            }

            var lowerDomainName    = domainModel.Name.ToLower();
            var lowerOperationName = operationModel.Name.ToLower();

            return(new[]
            {
                "delete",
                $"delete{lowerDomainName}"
            }
                   .Contains(lowerOperationName));
        }
示例#24
0
 public virtual void ResumeJob(IOperationModel operationModel)
 {
 }
示例#25
0
 public abstract void ExecuteOperationModel(IOperationModel operationModel, bool stopPreviousExecutions);
示例#26
0
 public virtual void HaltJob(IOperationModel operationModel)
 {
 }
 public BrushableOperationModelImpl(IOperationModel host)
 {
     _host = host;
     _brushOperationModels.CollectionChanged += BrushOperationModelsCollectionChanged;
 }
示例#28
0
        public string GetImplementation(IMetaDataManager metaDataManager, SoftwareFactory.Engine.IApplication application, IClass domainModel, IOperationModel operationModel)
        {
            var idParam  = operationModel.Parameters.First(p => string.Equals(p.Name, "id", StringComparison.OrdinalIgnoreCase));
            var dtoParam = operationModel.Parameters.First(p => !string.Equals(p.Name, "id", StringComparison.OrdinalIgnoreCase));

            return($@"var existing{domainModel.Name} ={ (operationModel.IsAsync() ? " await" : "") } {domainModel.Name.ToPrivateMember()}Repository.FindById{ (operationModel.IsAsync() ? "Async" : "") }({idParam.Name});
                {EmitPropertyAssignments(metaDataManager, application, domainModel, "existing"+ domainModel.Name, dtoParam)}");
        }
示例#29
0
 public override string BeginOperation(IServiceModel service, IOperationModel operation) => @"
     var userContext = _userContextProvider.GetUserContext();
     ServiceCallContext.Instance.Set<IUserContextData>(userContext);";
 public string GetImplementation(IMetaDataManager metaDataManager, SoftwareFactory.Engine.IApplication application, IClass domainModel, IOperationModel operationModel)
 {
     return($@"var elements ={ (operationModel.IsAsync() ? "await" : "") } {domainModel.Name.ToPrivateMember()}Repository.FindAll{ (operationModel.IsAsync() ? "Async" : "") }();
     return elements.MapTo{domainModel.Name.ToPascalCase()}DTOs();");
 }