Пример #1
0
        //TODO: add detection & resolution of duplicate names
        public static TypeMember WebApiController(TypeMember middlewareType, WebApiMetadata api) =>
        PUBLIC.CLASS(ID(api.InterfaceType.Name.TrimPrefixFragment("I"), "Controller"), () => {
            EXTENDS <Controller>();
            ATTRIBUTE <RouteAttribute>("api/[controller]");

            PRIVATE.READONLY.FIELD(api.InterfaceType, "_service", out var @serviceField);

            PUBLIC.CONSTRUCTOR(() => {
                PARAMETER(api.InterfaceType, "service", out var @service);
                @serviceField.ASSIGN(@service);
            });

            api.ApiMethods.ForEach(apiMethod => {
                var requestClass = DataTransferObjectGenerator.MethodInvocation(apiMethod);

                PUBLIC.ASYNC.FUNCTION <Task <IActionResult> >(apiMethod.Name, () => {
                    ATTRIBUTE(middlewareType);
                    ATTRIBUTE <HttpPostAttribute>(apiMethod.Name.ToString(CasingStyle.Camel));
                    PARAMETER(requestClass, "requestData", out MethodParameter @requestData, () => {
                        ATTRIBUTE <FromBodyAttribute>();
                    });

                    LOCAL(apiMethod.ReturnType.GenericArguments[0], "resultValue", out LocalVariable resultValueLocal);

                    resultValueLocal.ASSIGN(
                        AWAIT(THIS.DOT(@serviceField).DOT(apiMethod).INVOKE(() => {
                        apiMethod.Signature.Parameters.ForEach(p => ARGUMENT(@requestData.DOT(p.Name.ToString(CasingStyle.Pascal))));
                    }))
                        );

                    DO.RETURN(THIS.DOT("Json").INVOKE(resultValueLocal));
                });
            });
Пример #2
0
        public static TypeMember Controller(WebApiMetadata api) => 
            PUBLIC.CLASS($"{api.Interface.Name.TrimPrefix("I")}Controller", () => {
                EXTENDS<Controller>();
                ATTRIBUTE<RouteAttribute>("api/[controller]");

                PUBLIC.FUNCTION<string>("Index", () => {
                    ATTRIBUTE<HttpGetAttribute>();
                    DO.RETURN("Hello World!");
                });
            });
Пример #3
0
        public static TypeMember InvalidModelAutoResponderAttribute() =>
        PUBLIC.CLASS("InvalidModelAutoResponderAttribute", () => {
            EXTENDS <ActionFilterAttribute>();

            PUBLIC.OVERRIDE.VOID("OnActionExecuting", () => {
                PARAMETER <ActionExecutingContext>("context", out MethodParameter @context);

                DO.IF(NOT(context.DOT("ModelState").DOT("Valid"))).THEN(() => {
                    @context.DOT("Result").ASSIGN(NEW <BadRequestObjectResult>(@context.DOT("ModelState")));
                });
            });
        });
Пример #4
0
        public static void Test()
        {
            PUBLIC PublicKey = new PUBLIC();

            PublicKey.E = 3;
            PublicKey.N = 11;

            PublicKey.ghj();

            string text = "Hello world!";

            char[] chars = text.ToCharArray();

            byte[] btxt = ASCIIEncoding.ASCII.GetBytes(text);

            //byte[] btxt = new byte[] { 1, 2, 3, 4, 5, 6, 7, 1, 2 };

            byte[] bctext = new byte[btxt.Length];

            for (int i = 0; i < btxt.Length; i++)
            {
                double potega = Math.Pow(btxt[i],PublicKey.E);

                bctext[i] = (byte)(potega % PublicKey.N);
            }

            //string ctext = ASCIIEncoding.ASCII.GetString(bctext);

            //byte[] bdtext = ASCIIEncoding.ASCII.GetBytes(ctext);

            byte[] dtxt = new byte[bctext.Length];

            PUBLIC PrivateKey = new PUBLIC();

            PrivateKey.N = 11;
            PrivateKey.E = 7;

            for (int i = 0; i < bctext.Length; i++)
            {
                double potega = Math.Pow(bctext[i], PrivateKey.E);

                dtxt[i] = (byte)(potega % PrivateKey.N);
            }

            //string dtext = ASCIIEncoding.ASCII.GetString(dtxt);
        }
Пример #5
0
 public static TypeMember MethodInvocation(MethodMember method) =>
 PUBLIC.CLASS($"{method.Name}Invocation", () => {
     method.Signature.Parameters.ForEach(p => {
         PUBLIC.PROPERTY(p.Type, p.Name.ToString(CasingStyle.Pascal));
     });
 });