Exemplo n.º 1
0
        protected void InitializeServiceApi(Type interfaceType)
        {
            ConcurrentDictionary <string, ActionWrapper> wrapper;

            if (cache.TryGetValue(interfaceType, out wrapper))
            {
                return;
            }
            var newWrapper = new ConcurrentDictionary <string, ActionWrapper>();

            foreach (var methodInfo in interfaceType.GetMethods())
            {
                var template   = ExtensionsFactory.GetServiceTemplate(methodInfo);
                var actionName = GetActionName(methodInfo);
                var action     = new ActionWrapper {
                    Name = actionName, ReturnType = methodInfo.ReturnType, RouteTemplate = template, Parameters = new List <ParameterWrapper>()
                };
                var actions  = methodInfo.GetCustomAttributes(true).OfType <IActionHttpMethodProvider>();
                var methods  = ExtensionsFactory.GetHttpMethods(actions.ToList(), methodInfo);
                var handlers = ExtensionsFactory.GetHeaderInspectors(methodInfo);
                action.CustomHandlers = handlers;
                action.Actions        = methods;
                BuildParameterInfo(methodInfo, action);
                newWrapper.TryAdd(action.Name, action);
            }
            if (cache.TryGetValue(interfaceType, out wrapper))
            {
                return;
            }
            cache.TryAdd(interfaceType, newWrapper);
        }
Exemplo n.º 2
0
        internal IEnumerable <string> RetrieveUsedExtensions()
        {
            // retrieve ALL the property based objects of the whole model.
            var allObjects = GetLogicalChildrenFlattened();

            // check all the extensions used by each object
            var used = new HashSet <string>();

            // search for known extensions
            foreach (var c in allObjects)
            {
                var ids = c.Extensions
                          .Select(item => ExtensionsFactory.Identify(c.GetType(), item.GetType()))
                          .Where(item => !string.IsNullOrWhiteSpace(item));

                used.UnionWith(ids);
            }

            // search for unknown extensions
            foreach (var unk in allObjects.SelectMany(item => item.Extensions).OfType <UnknownNode>())
            {
                used.Add(unk.Name);
            }

            return(used);
        }
Exemplo n.º 3
0
        public static GridViewExtension GridViewReport <TModel>(this ExtensionsFactory extensionsFactory, ECOM.Models.GridViewConfig gridConfig, Action <GridViewSettings <TModel> > action, bool IsExportData = true)
        {
            var gridViewSettings = GetGridViewReportSetting <TModel>(gridConfig, IsExportData);

            action(gridViewSettings);

            return(new GridViewExtension(gridViewSettings));
        }
Exemplo n.º 4
0
        public static GridViewExtension GridViewCustom <TModel>(this ExtensionsFactory extensionsFactory, ECOM.Models.GridViewConfig gridConfig, Action <GridViewSettings <TModel> > action, bool IsGenerateColumn = true)
        {
            var gridViewSettings = GetGridViewSetting <TModel>(gridConfig, IsGenerateColumn);

            action(gridViewSettings);

            return(new GridViewExtension(gridViewSettings));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generate  extension GridView from specify class config
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="extensionsFactory"></param>
        /// <param name="gridConfig"></param>
        /// <param name="viewContext"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static GridViewExtension GridViewCustom <TModel>(this ExtensionsFactory extensionsFactory, ECOM.Models.GridViewConfig gridConfig, ViewContext viewContext, Action <GridViewSettings <TModel> > action)
        {
            var gridViewSettings = GetGridViewSetting <TModel>(gridConfig);

            action(gridViewSettings);

            return(new GridViewExtension(gridViewSettings, viewContext));
        }
Exemplo n.º 6
0
        private PositionViewModel GetTarget()
        {
            PositionViewModel target = new PositionViewModel();

            target.OknaDocument = _oknaDoc;
            ExtensionsFactory.Nacist(target);
            return(target);
        }
Exemplo n.º 7
0
 public static MvcHtmlString GetScriptsEx(this ExtensionsFactory factory, params Script[] scriptItems)
 {
     try
     {
         return(factory.GetScripts(scriptItems));
     }
     finally
     {
         MvcUtils.RenderScriptsCalled = false;
     }
 }
Exemplo n.º 8
0
        internal void UsingExtension(Type parentType, Type extensionType)
        {
            var id = ExtensionsFactory.Identify(parentType, extensionType);

            if (string.IsNullOrWhiteSpace(id))
            {
                return;
            }

            if (this._extensionsUsed.Contains(id))
            {
                return;
            }

            this._extensionsUsed.Add(id);
        }
        protected static IWorkflowService GetWfService(IUnityContainer container, Activity outerActivity,
                                                       WorkflowIdentity innerIdentity, Activity innerActivity)
        {
            var mockWfStorage = new Mock <IWorkflowStorage>();

            mockWfStorage.Setup(i => i.Load(OuterWfidentity)).Returns(outerActivity);
            mockWfStorage.Setup(i => i.Load(innerIdentity)).Returns(innerActivity);

            var wfAppFactory = new WorkflowApplicationFactory(null as InstanceStore, mockWfStorage.Object);

            container.RegisterInstance <IWorkflowApplicationFactory>(wfAppFactory);
            container.RegisterType <IWorkflowChildContainerConfigurator, StubWorkflowChildContainerConfigurator>();
            var extensionsFactory = new ExtensionsFactory(container);

            return(new WorkflowService(wfAppFactory, extensionsFactory));
        }
Exemplo n.º 10
0
        private void CopyFromDocument(bool copyColors, bool copyComponents, bool copyComponentFlagsOnly = false)
        {
            var docData = GetDocumentData();

            if (docData == null)
            {
                return;
            }

            DocumentViewModel docVM = new DocumentViewModel();

            ExtensionsFactory.Nacist(docVM);
            docVM.SetModel(docData);

            CopyFromDocumentCore(copyColors, copyComponents, copyComponentFlagsOnly, docVM);
        }
Exemplo n.º 11
0
        public static RoundPanelExtension RoundPanelCustom(this ExtensionsFactory extensionsFactory, string name, string headerText, Action <RoundPanelSettings> action)
        {
            RoundPanelSettings settings = new RoundPanelSettings();

            settings.View       = DevExpress.Web.View.GroupBox;
            settings.Name       = name;
            settings.HeaderText = headerText;
            settings.Width      = System.Web.UI.WebControls.Unit.Percentage(100);
            settings.ShowHeader = true;

            settings.CornerRadius = System.Web.UI.WebControls.Unit.Pixel(0);

            //Collapsing Options
            //settings.View = View.Standard;
            settings.AllowCollapsingByHeaderClick = true;
            settings.ShowCollapseButton           = true;


            settings.EnableAnimation = true;


            action(settings);
            return(new RoundPanelExtension(settings));
        }
Exemplo n.º 12
0
 public static void RegisterWcfAdapters()
 {
     ExtensionsFactory.SetServiceLocator(new WcfRouteResolver());
 }
Exemplo n.º 13
0
        private static MethodBuilder DefineMethod(TypeBuilder type, MethodInfo implementationMethod, out List <ParameterWrapper> methodParams, out Type[] pTypes, IServiceLocator serviceLocator)
        {
            // Declaring method builder
            // Method attributes
            const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.HideBySig | MethodAttributes.NewSlot;
            var method = type.DefineMethod(implementationMethod.Name, methodAttributes);
            // Preparing Reflection instances


            var route      = typeof(RouteAttribute).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(String) }, null);
            var httpGet    = httpMethodAttribute(implementationMethod, serviceLocator);
            var uriAttrib  = typeof(FromRouteAttribute).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { }, null);
            var queryAttib = typeof(FromQueryAttribute).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { }, null);
            var bodyAttrib = typeof(FromBodyAttribute).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { }, null);

            method.SetReturnType(typeof(Task).IsAssignableFrom(implementationMethod.ReturnType) ? typeof(Task <IActionResult>) : typeof(IActionResult));
            // Adding parameters
            methodParams = GetMethodParams(implementationMethod, serviceLocator);
            pTypes       = methodParams.Where(p => p.In != InclutionTypes.Header).Select(p => p.Type).ToArray();
            method.SetParameters(pTypes.ToArray());
            var obsolete = implementationMethod.GetCustomAttribute <ObsoleteAttribute>();

            if (obsolete != null)
            {
                method.SetCustomAttribute(new CustomAttributeBuilder(obsolete.GetType().GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(string), typeof(bool) }, null), new object[] { obsolete.Message, obsolete.IsError }));
            }
            // Parameter id
            var template = implementationMethod.GetCustomAttribute <RouteAttribute>()?.Template ?? implementationMethod.GetCustomAttribute <VerbAttribute>()?.Route;

            if (template == null)
            {
                template = ExtensionsFactory.GetServiceTemplate(implementationMethod, serviceLocator);
            }
            if (template == null)
            {
                template = "";
            }
            int pid = 1;

            foreach (var parameterWrapper in methodParams.Where(p => p.In != InclutionTypes.Header))
            {
                try
                {
                    var p = method.DefineParameter(pid, ParameterAttributes.None, parameterWrapper.Name);
                    if (parameterWrapper.In == InclutionTypes.Path && template.Contains("{" + parameterWrapper.Name + "}"))
                    {
                        p.SetCustomAttribute(new CustomAttributeBuilder(uriAttrib, new Type[] { }));
                    }
                    else if (parameterWrapper.In == InclutionTypes.Path)
                    {
                        p.SetCustomAttribute(new CustomAttributeBuilder(queryAttib, new Type[] { }));
                    }
                    else if (parameterWrapper.In == InclutionTypes.Body)
                    {
                        p.SetCustomAttribute(new CustomAttributeBuilder(bodyAttrib, new Type[] { }));
                    }
                    pid++;
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            DefineAuthorizeAttributes(implementationMethod, method);
            if (_apiControllerAttributeType != null)
            {
                var ctor = _apiControllerAttributeType.GetConstructor(
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { }, null);
                method.SetCustomAttribute(new CustomAttributeBuilder(ctor, new object[0]));
            }
            // Adding custom attributes to method
            // [RouteAttribute]
            //method.SetCustomAttribute(new CustomAttributeBuilder(typeof(ApiControllerAttribute),new object[0]));
            method.SetCustomAttribute(new CustomAttributeBuilder(route, new[] { template }));
            // [HttpGetAttribute]
            method.SetCustomAttribute(new CustomAttributeBuilder(httpGet, new Type[] { }));
            var defaultResponse = implementationMethod.GetCustomAttribute <SuccessStatusCodeAttribute>();

            if (defaultResponse != null)
            {
                var returnType = implementationMethod.ReturnType;
                if (returnType.IsGenericType && typeof(Task).IsAssignableFrom(returnType))
                {
                    returnType = returnType.GetGenericArguments().First();
                }
                else if (returnType == typeof(Task))
                {
                    method.SetCustomAttribute(defaultResponse.CreateAttribute());
                }
                else if (returnType != typeof(void))
                {
                    method.SetCustomAttribute(defaultResponse.CreateAttribute(returnType));
                }
                else
                {
                    method.SetCustomAttribute(defaultResponse.CreateAttribute());
                }
            }
            else
            {
                ConstructorInfo ctor5 = typeof(ProducesResponseTypeAttribute).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(Type), typeof(int) }, null);
                method.SetCustomAttribute(new CustomAttributeBuilder(ctor5, new object[] { GetReturnType(implementationMethod), 200 }));
                try
                {
                    var attributeCreators = implementationMethod.GetCustomAttributes().OfType <ICreateImplementationAttribute>();
                    foreach (var createImplementationAttribute in attributeCreators)
                    {
                        method.SetCustomAttribute(createImplementationAttribute.CreateAttribute());
                    }
                }
                catch (Exception ex)
                {
                    Logging.Exception(ex);
                }
            }
            BuildServiceDescriptionAttribute(implementationMethod, method);

            return(method);
        }
Exemplo n.º 14
0
        public void InitializeClient(Type interfaceType)
        {
            ConcurrentDictionary <string, ActionWrapper> concurrentDictionary1;

            if (RestWrapper.cache.TryGetValue(interfaceType, out concurrentDictionary1))
            {
                return;
            }
            ConcurrentDictionary <string, ActionWrapper> concurrentDictionary2 = new ConcurrentDictionary <string, ActionWrapper>();
            IRoutePrefix routePrefix = RestWrapper.GetRoutePrefix(interfaceType);

            this._errorInterceptor = interfaceType.GetCustomAttribute <ErrorHandlerAttribute>();
            this._serviceLocator.GetService <ILogger>()?.Message("Initializing client " + interfaceType.Name);
            RetryAttribute customAttribute = interfaceType.GetCustomAttribute <RetryAttribute>();

            if (interfaceType.GetCustomAttribute <CircuitBreakerAttribute>() != null)
            {
                CircuitBreakerContainer.Register(interfaceType, (ICircuitBreaker) new Stardust.Interstellar.Rest.Client.CircuitBreaker.CircuitBreaker(interfaceType.GetCustomAttribute <CircuitBreakerAttribute>(), this._serviceLocator)
                {
                    ServiceName = interfaceType.FullName
                });
            }
            else
            {
                CircuitBreakerContainer.Register(interfaceType, (ICircuitBreaker) new NullBreaker());
            }
            foreach (MethodInfo methodInfo in interfaceType.GetMethods().Length == 0 ? ((IEnumerable <Type>)interfaceType.GetInterfaces()).First <Type>().GetMethods() : interfaceType.GetMethods())
            {
                try
                {
                    RetryAttribute retryAttribute = methodInfo.GetCustomAttribute <RetryAttribute>() ?? customAttribute;
                    this._serviceLocator.GetService <ILogger>()?.Message("Initializing client action " + interfaceType.Name + "." + methodInfo.Name);
                    IRoute template             = (IRoute)methodInfo.GetCustomAttribute <IRouteAttribute>() ?? (IRoute)methodInfo.GetCustomAttribute <VerbAttribute>();
                    string actionName           = this.GetActionName(methodInfo);
                    List <VerbAttribute> list   = methodInfo.GetCustomAttributes(true).OfType <VerbAttribute>().ToList <VerbAttribute>();
                    ActionWrapper        action = new ActionWrapper()
                    {
                        Name          = actionName,
                        ReturnType    = methodInfo.ReturnType,
                        RouteTemplate = ExtensionsFactory.GetRouteTemplate(routePrefix, template, methodInfo, this._serviceLocator),
                        Parameters    = new List <ParameterWrapper>()
                    };
                    MethodInfo              method           = methodInfo;
                    IServiceProvider        serviceLocator   = this._serviceLocator;
                    List <HttpMethod>       httpMethods      = ExtensionsFactory.GetHttpMethods(list, method, serviceLocator);
                    List <IHeaderInspector> headerInspectors = ExtensionsFactory.GetHeaderInspectors(methodInfo, this._serviceLocator);
                    action.UseXml         = methodInfo.GetCustomAttributes().OfType <UseXmlAttribute>().Any <UseXmlAttribute>();
                    action.CustomHandlers = headerInspectors.Where <IHeaderInspector>((Func <IHeaderInspector, bool>)(h => this.headerHandlers.All <IHeaderHandler>((Func <IHeaderHandler, bool>)(parent => parent.GetType() != h.GetType())))).ToList <IHeaderInspector>();
                    action.ErrorHandler   = this._errorInterceptor;
                    action.Actions        = httpMethods;
                    if (retryAttribute != null)
                    {
                        action.Retry            = true;
                        action.Interval         = retryAttribute.RetryInterval;
                        action.NumberOfRetries  = retryAttribute.NumberOfRetries;
                        action.IncrementalRetry = retryAttribute.IncremetalWait;
                        if (retryAttribute.ErrorCategorizer != (Type)null)
                        {
                            action.ErrorCategorizer = (IErrorCategorizer)Activator.CreateInstance(retryAttribute.ErrorCategorizer, (object)this._serviceLocator);
                        }
                    }
                    ExtensionsFactory.BuildParameterInfo(methodInfo, action, this._serviceLocator);
                    concurrentDictionary2.TryAdd(action.Name, action);
                }
                catch (Exception ex)
                {
                    this._logger?.Error(ex);
                    throw;
                }
            }
            if (RestWrapper.cache.TryGetValue(interfaceType, out concurrentDictionary1))
            {
                return;
            }
            RestWrapper.cache.TryAdd(interfaceType, concurrentDictionary2);
        }