Ejemplo n.º 1
0
    /// <summary>
    /// Generates meta tags for the given content.
    /// </summary>
    /// <param name="app">The application service</param>
    /// <param name="content">The content</param>
    /// <param name="meta">If meta tags should be generated</param>
    /// <param name="opengraph">If open graph tags should be generated</param>
    /// <param name="generator">If generator tag should be generated</param>
    /// <returns>The meta tags</returns>
    public static HtmlString MetaTags(this IApplicationService app, IMeta content, bool meta = true, bool opengraph = true, bool generator = true)
    {
        var sb = new StringBuilder();

        if (meta)
        {
            // Generate meta tags
            if (!string.IsNullOrWhiteSpace(content.MetaKeywords))
            {
                sb.AppendLine($"<meta name=\"keywords\" value=\"{ content.MetaKeywords }\">");
            }
            if (!string.IsNullOrWhiteSpace(content.MetaDescription))
            {
                sb.AppendLine($"<meta name=\"description\" value=\"{ content.MetaDescription }\">");
            }
        }

        if (generator)
        {
            // Generate generator tag
            sb.AppendLine($"<meta name=\"generator\" value=\"Piranha CMS { Piranha.Utils.GetAssemblyVersion(typeof(Piranha.App).Assembly) }\">");
        }

        if (opengraph)
        {
            // Generate open graph tags
            sb.AppendLine($"<meta name=\"og:type\" value=\"article\">");
            sb.AppendLine($"<meta name=\"og:title\" value=\"{ content.Title }\">");
            if (!string.IsNullOrWhiteSpace(content.MetaDescription))
            {
                sb.AppendLine($"<meta name=\"og:description\" value=\"{ content.MetaDescription }\">");
            }
        }
        return(new HtmlString(sb.ToString()));
    }
Ejemplo n.º 2
0
        public IMeta[] Compile()
        {
            var index = 0;
            var list  = new IMeta[registerdTypes.Count];

            foreach (var item in registerdTypes)
            {
                var t = item.Key;

                var createMethod = new DynamicMethod("Create", t, Type.EmptyTypes, item.Value.OwnerType.GetTypeInfo().Module, true);
                var il           = createMethod.GetILGenerator();
                item.Value.EmitNewInstance(this, il, forceEmit: true);
                il.Emit(OpCodes.Ret);

                var factory = createMethod.CreateDelegate(typeof(Func <>).MakeGenericType(t));

                if (item.Value.Lifestyle == Lifestyle.Singleton)
                {
                    var lazyFactory = Activator.CreateInstance(typeof(Lazy <>).MakeGenericType(t), new object[] { factory });
                    var lazyValue   = Activator.CreateInstance(typeof(SingletonValue <>).MakeGenericType(t), lazyFactory);
                    factory = (Delegate)typeof(SingletonValue <>).MakeGenericType(t).GetRuntimeField("func").GetValue(lazyValue);
                }

                var setFactory = typeof(ObjectResolver).GetRuntimeMethods().First(x => x.Name == "SetFactory").MakeGenericMethod(item.Key);
                setFactory.Invoke(Resolver, new object[] { factory });

                item.Value.EmittedDelegate = factory;
                list[index++] = item.Value;
            }

            return(list);
        }
Ejemplo n.º 3
0
        public object Any(UserIdRequest request)
        {
            IMeta         response      = null;
            User          user          = null;
            QueryResponse queryResponse = null;

            user = _entityController.Single(request.Id, out queryResponse);

            if (queryResponse.success)
            {
                response = new UserResponse()
                {
                    Result = user
                };
            }
            else
            {
                response = new ResponseError()
                {
                    ErrorCode = queryResponse.errorCode,
                    Message   = queryResponse.errorMessage
                };
            }

            return(response);
        }
Ejemplo n.º 4
0
        public object Single(PostIdRequest request)
        {
            IMeta         response = null;
            QueryResponse queryResponse;

            var post = _postControllerCore.Single(request.Id, out queryResponse);

            if (queryResponse.success)
            {
                response = new PostResponse()
                {
                    Result = post
                };
            }
            else
            {
                response = new ResponseError()
                {
                    ErrorCode = queryResponse.errorCode,
                    Message   = queryResponse.errorMessage
                };
            }

            return(response);
        }
Ejemplo n.º 5
0
        public object Any(ReferencesPostIdRequest request)
        {
            IMeta         response      = null;
            QueryResponse queryResponse = null;

            var tree = _postControllerCore.PostsByAnchorId(request.Id, request.Index, request.MaxEntries, out queryResponse);

            if (queryResponse.success)
            {
                response = new TreeListResponse()
                {
                    Result = tree.ToList(),
                };
            }
            else
            {
                response = new ResponseError()
                {
                    ErrorCode = queryResponse.errorCode,
                    Message   = queryResponse.errorMessage
                };
            }

            return(response);
        }
Ejemplo n.º 6
0
 internal bool Start(int ticks, IOrderOperation OrderOperation, IAccount Account, IHistory History, IMeta Meta)
 {
     _maxTicks            = ticks;
     this._OrderOperation = OrderOperation;
     this._Account        = Account;
     this._History        = History;
     this._Meta           = Meta;
     return(onStart(ticks));
 }
Ejemplo n.º 7
0
        public static void AddMeta(this IMeta target, string key, object value)
        {
            if (target.Meta == null)
            {
                target.Meta = new MetaCollection();
            }

            target.Meta.Add(key, value);
        }
Ejemplo n.º 8
0
        public static void AddMeta(this IMeta target, MetaCollection meta)
        {
            if (meta == null)
            {
                return;
            }

            foreach (var item in meta)
            {
                target.AddMeta(item.Key, item.Value);
            }
        }
Ejemplo n.º 9
0
    /// <summary>
    /// Generates meta tags for the given content.
    /// </summary>
    /// <param name="app">The application service</param>
    /// <param name="content">The content</param>
    /// <param name="meta">If meta tags should be generated</param>
    /// <param name="opengraph">If open graph tags should be generated</param>
    /// <param name="generator">If generator tag should be generated</param>
    /// <returns>The meta tags</returns>
    public static HtmlString MetaTags(this IApplicationService app, IMeta content, bool meta = true, bool opengraph = true, bool generator = true)
    {
        var sb = new StringBuilder();

        if (meta)
        {
            // Generate meta tags
            sb.AppendLine($"<meta name=\"robots\" content=\"{ MetaRobots(content) }\">");

            if (!string.IsNullOrWhiteSpace(content.MetaKeywords))
            {
                sb.AppendLine($"<meta name=\"keywords\" content=\"{ content.MetaKeywords }\">");
            }
            if (!string.IsNullOrWhiteSpace(content.MetaDescription))
            {
                sb.AppendLine($"<meta name=\"description\" content=\"{ content.MetaDescription }\">");
            }
        }

        if (generator)
        {
            // Generate generator tag
            sb.AppendLine($"<meta name=\"generator\" content=\"Piranha CMS { Piranha.Utils.GetAssemblyVersion(typeof(Piranha.App).Assembly) }\">");
        }

        if (opengraph)
        {
            // Generate open graph tags
            if (content is PageBase page && page.IsStartPage)
            {
                sb.AppendLine($"<meta property=\"og:type\" content=\"website\">");
            }
            else
            {
                sb.AppendLine($"<meta property=\"og:type\" content=\"article\">");
            }
            sb.AppendLine($"<meta property=\"og:title\" content=\"{ OgTitle(content) }\">");
            if (content.OgImage != null && content.OgImage.HasValue)
            {
                sb.AppendLine($"<meta property=\"og:image\" content=\"{ app.AbsoluteContentUrl(content.OgImage) }\">");
            }
            else if (content is RoutedContentBase contentBase && contentBase.PrimaryImage != null && contentBase.PrimaryImage.HasValue)
            {
                // If there's no OG image specified but we have a primary image,
                // default to the primary image.
                sb.AppendLine($"<meta property=\"og:image\" content=\"{ app.AbsoluteContentUrl(contentBase.PrimaryImage) }\">");
            }
            if (!string.IsNullOrWhiteSpace(OgDescription(content)))
            {
                sb.AppendLine($"<meta property=\"og:description\" content=\"{ OgDescription(content) }\">");
            }
        }
Ejemplo n.º 10
0
 public HistorySimulator(BasicParam customParam, bool IsTestingMode, FxAdvisorCore.SimpleAdvisor advisor, StrategyParameter currentStrategyParam, string symbol, IMeta meta)
 {
     this.CustomParam  = customParam;
     this.IsSuccessful = false;
     if (IsTestingMode)
     {
         rootPath = System.Configuration.ConfigurationManager.AppSettings["QuotesFullPath"];
     }
     this.Advisor = advisor;
     this.CurrentStrategyParam = currentStrategyParam;
     this.Symbol = InputData.ConvertToStandardName(symbol);
     this.Meta   = meta;
 }
Ejemplo n.º 11
0
        private ITemplate FindTemplate(IMeta meta, Language language)
        {
            switch (meta)
            {
            case ClassMeta classMeta:
                return(FindClassTemplate(classMeta, language));

            case InterfaceMeta interfaceMeta:
                return(FindInterfaceTemplate(interfaceMeta, language));

            default:
                throw new ArgumentOutOfRangeException(meta.GetType().ToString(), meta.GetType(), null);
            }
        }
Ejemplo n.º 12
0
        public RowNode(int baseLineID, Line referenceLine, IMeta metaItem, Zone zone)
        {
            this.baseLineID    = baseLineID;
            this.referenceLine = referenceLine;
            this.metaItem      = metaItem;
            this.zone          = zone;
            name = "RowNode";
            next = null;
            prev = null;

            highLine   = zone.OffsetInZone(referenceLine, baseLineID, metaItem.GetClearHeight());
            lowLine    = referenceLine;
            middleLine = midLine(lowLine, highLine);
        }
Ejemplo n.º 13
0
        public static T Set <T>(this IMeta instance, T value)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            if (instance.Meta == null)
            {
                instance.Meta = new Dictionary <string, string>();
            }

            instance.Meta[typeof(T).GetOperationName()] = TypeSerializer.SerializeToString(value);
            return(value);
        }
Ejemplo n.º 14
0
 public static void SetTTL(this IMeta req, uint ttl)
 {
     if (req.Meta == null)
     {
         req.Meta = new RequestMetaHeader
         {
             Epoch = 0,
             TTL   = ttl,
         };
     }
     else
     {
         req.Meta.TTL = ttl;
     }
 }
Ejemplo n.º 15
0
        public static T Get <T>(this IMeta instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            if (instance.Meta == null)
            {
                return(default(T));
            }

            instance.Meta.TryGetValue(typeof(T).GetOperationName(), out string str);
            return(str == null ? default(T) : TypeSerializer.DeserializeFromString <T>(str));
        }
Ejemplo n.º 16
0
        public static bool TryGet <T>(this IMeta instance, out T value)
        {
            value = default(T);
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            if (!instance.Meta.TryGetValue(typeof(T).GetOperationName(), out string str))
            {
                return(false);
            }

            value = TypeSerializer.DeserializeFromString <T>(str);
            return(true);
        }
Ejemplo n.º 17
0
    private bool CheckCore()
    {
        string Base    = RuntimeEnvironment.GetRuntimeDirectory();
        string Build   = RuntimeEnvironment.GetSystemVersion();
        bool   HostCLR = Int32.Parse(Build[1].ToString()) >= 4;

        if (HostCLR)
        {
            Guid CID_META_HOST   = new Guid("9280188D-0E8E-4867-B30C-7FA83884E8DE");
            Guid CID_STRONG_NAME = new Guid("B79B0ACD-F5CD-409B-B5A5-A16244610B92");

            IMeta    Meta    = (IMeta)CreateInstance(CID_META_HOST, typeof(IMeta).GUID);
            IRuntime Runtime = (IRuntime)Meta.GetRuntime(Build, typeof(IRuntime).GUID);
            SN = (IStrongName)Runtime.GetInterface(CID_STRONG_NAME, typeof(IStrongName).GUID);
        }

        string File1 = Path.ChangeExtension(Path.Combine(Base, "mscorlib"), "dll");
        string File2 = Path.ChangeExtension(Path.Combine(Base, "system"), "dll");

        byte[] Token = new byte[] {
            183,
            122,
            92,
            86,
            25,
            52,
            224,
            137
        };
        if (!IsTrusted(File1, Token, HostCLR))
        {
            return(false);
        }
        if (!IsTrusted(File2, Token, HostCLR))
        {
            return(false);
        }

        return(true);
    }
		private static NavigationController CreateController(IMeta meta = null)
		{
			return new NavigationController(meta ?? new Mock<IMeta>().Object);
		}
Ejemplo n.º 19
0
 public ForexAPI(IMeta metaAPI, int magic)
 {
     this.MetaAPI     = metaAPI;
     this.MagicNumber = magic;
 }
		public NavigationController(IMeta meta)
		{
			_meta = meta;
		}
Ejemplo n.º 21
0
 private static string MetaTitle(IMeta content)
 {
     return(!string.IsNullOrWhiteSpace(content.MetaTitle) ? content.MetaTitle : content.Title);
 }
Ejemplo n.º 22
0
 public static string OgTitle(IMeta content)
 {
     return(!string.IsNullOrWhiteSpace(content.OgTitle) ? content.OgTitle : MetaTitle(content));
 }
Ejemplo n.º 23
0
 public static string OgDescription(IMeta content)
 {
     return(!string.IsNullOrWhiteSpace(content.OgDescription) ? content.OgDescription : content.MetaDescription);
 }
 public override bool Equals(IMeta other)
 {
     return(Object.ReferenceEquals(this, other));
 }
Ejemplo n.º 25
0
        /// <summary>
        /// 加载 DLL 插件。
        /// </summary>
        /// <param name="dllFiles">DLL 插件列表。</param>
        private void LoadDllPlugins(string[] dllFiles)
        {
            foreach (string file in dllFiles)
            {
                try
                {
                    _logger.LogDebug($"Loading plugin: {file}");

                    Assembly pluginAssembly = LoadPlugin(file);
                    Type[]   exportedTypes  = pluginAssembly.GetExportedTypes();

                    string pluginName = pluginAssembly.FullName;

                    _logger.LogDebug($"Parsing meta in plugin: {pluginName}");

                    Type[] metaTypes = exportedTypes.Where(type =>
                                                           Attribute.GetCustomAttribute(type, typeof(RmboxPluginAttribute)) is not null).ToArray();

                    if (metaTypes.Length != 1)
                    {
                        string err = $"插件 {pluginName} 具有的元信息的个数 {metaTypes.Length} 不符合 1 的要求。";
                        _logger.LogError(err);
                        throw new IndexOutOfRangeException(err);
                    }

                    // ReSharper disable once UseNegatedPatternMatching
                    IMeta pluginMeta = Activator.CreateInstance(metaTypes.Single()) as IMeta;
                    if (pluginMeta is null)
                    {
                        string err = $"在加载插件 {pluginName} 的元信息时发生错误。";
                        _logger.LogError(err);
                        throw new ArgumentNullException(nameof(pluginMeta));
                    }

                    _logger.LogDebug($"Meta parsed in: {pluginMeta.Name}");

                    MetaCollection.Add((pluginMeta, pluginAssembly));

                    _logger.LogDebug($"Parsing components in plugin: {pluginMeta.Name}");

                    List <Type> operationTypes = exportedTypes.Where(type =>
                                                                     Attribute.GetCustomAttribute(type, typeof(OperationAttribute)) is not null).ToList();

                    foreach (Type t in operationTypes.Where(type => !type.IsAssignableTo(typeof(IOperation)))
                             .ToArray())
                    {
                        _logger.LogWarning($"检测到错误导出的类型 {t.FullName},将会忽略加载。");
                        operationTypes.Remove(t);
                    }

                    foreach (Type operationType in operationTypes)
                    {
                        OperationAttribute operationAttribute =
                            Attribute.GetCustomAttribute(operationType, typeof(OperationAttribute))
                            as OperationAttribute;

                        OperationCollection.Add((operationAttribute, pluginMeta, operationType));

                        _logger.LogDebug($"Operation {operationAttribute.Name} loaded.");
                    }

                    List <Type> configSectionTypes = exportedTypes.Where(type =>
                                                                         Attribute.GetCustomAttribute(type, typeof(ConfigSectionAttribute)) is not null).ToList();

                    foreach (Type t in configSectionTypes.Where(type => !type.IsSubclassOf(typeof(ConfigSectionBase)))
                             .ToArray())
                    {
                        _logger.LogWarning($"检测到错误导出的类型 {t.FullName},将会忽略加载。");
                        configSectionTypes.Remove(t);
                    }

                    foreach (Type configSectionType in configSectionTypes)
                    {
                        var configSectionAttribute =
                            Attribute.GetCustomAttribute(configSectionType, typeof(ConfigSectionAttribute))
                            as ConfigSectionAttribute;

                        ConfigSectionCollection.Add((configSectionAttribute, configSectionType));

                        _logger.LogDebug($"Config section {configSectionAttribute.Id} loaded.");
                    }

                    List <Type> formatterTypes = exportedTypes.Where(type =>
                                                                     Attribute.GetCustomAttribute(type, typeof(FormatterAttribute)) is not null).ToList();

                    foreach (Type t in formatterTypes.Where(type => !type.IsAssignableTo(typeof(IFormatter)))
                             .ToArray())
                    {
                        _logger.LogWarning($"检测到错误导出的类型 {t.FullName},将会忽略加载。");
                        formatterTypes.Remove(t);
                    }

                    foreach (Type formatterType in formatterTypes)
                    {
                        FormatterAttribute formatterAttribute =
                            Attribute.GetCustomAttribute(formatterType, typeof(FormatterAttribute))
                            as FormatterAttribute;

                        FormatterCollection.Add((formatterAttribute, formatterType));

                        _logger.LogDebug($"Formatter {formatterType.FullName} loaded.");
                    }

                    _logger.LogDebug($"Plugin {pluginMeta.Name} loaded.");
                }
                catch (Exception e)
                {
                    _logger.LogWarning(e, $"在加载插件 {file} 时发生错误。将跳过该插件的加载。");
                }
            }
        }
Ejemplo n.º 26
0
        public string Create(IMeta classMeta, Language language)
        {
            var template = FindTemplate(classMeta, language);

            return(template.TransformText());
        }
Ejemplo n.º 27
0
 public bool TesterStart(int ticks, IOrderOperation OrderOperation, IAccount Account, IHistory History, IMeta Meta, IRegisterTickToHandle registerTickToHandle, string symbol)
 {
     _maxTicks                 = ticks;
     this.OrderOperation       = OrderOperation;
     this.Account              = Account;
     this.History              = History;
     this.Meta                 = Meta;
     this.Symbol               = symbol;
     this.RegisterTickToHandle = registerTickToHandle;
     return(onStart(ticks));
 }
Ejemplo n.º 28
0
 public MetaStrategyLogger(IMeta m)
 {
     this.meta = m;
 }