public SchemaDrivenDocumentProcessor(
            DocumentSchema schema,
            ICompositionContainer container,
            MarkdigMarkdownService markdigMarkdownService,
            FolderRedirectionManager folderRedirectionManager)
        {
            if (string.IsNullOrWhiteSpace(schema.Title))
            {
                throw new ArgumentException("Title for schema must not be empty");
            }

            _schemaName               = schema.Title;
            _schema                   = schema;
            SchemaValidator           = schema.Validator;
            _allowOverwrite           = schema.AllowOverwrite;
            _serializerPool           = new ResourcePoolManager <JsonSerializer>(GetSerializer, 0x10);
            _markdigMarkdownService   = markdigMarkdownService ?? throw new ArgumentNullException(nameof(MarkdigMarkdownService));
            _folderRedirectionManager = folderRedirectionManager;
            if (container != null)
            {
                var commonSteps         = container.GetExports <IDocumentBuildStep>(nameof(SchemaDrivenDocumentProcessor));
                var schemaSpecificSteps = container.GetExports <IDocumentBuildStep>($"{nameof(SchemaDrivenDocumentProcessor)}.{_schemaName}");
                BuildSteps = commonSteps.Union(schemaSpecificSteps).ToList();
            }
        }
Beispiel #2
0
 public void Initialize()
 {
     shimsContext = ShimsContext.Create();
     SetupShims();
     resourcePoolManager = new ResourcePoolManager();
     privateObject       = new PrivateObject(resourcePoolManager);
 }
Beispiel #3
0
        private static ResourcePoolManager resourcePoolManager;        // = new ResourcePoolManager();

        internal static Graphics.Size MeasureText(IRenderer r, string text, string fontName, double fontSize, Drawing.Text.FontStyles style)
        {
            ResourcePoolManager resManager;
            Typeface            typeface = null;

            if (r == null)
            {
                if (resourcePoolManager == null)
                {
                    resourcePoolManager = new ResourcePoolManager();
                }

                resManager = resourcePoolManager;
            }
            else
            {
                resManager = r.ResourcePoolManager;
            }

            typeface = resManager.GetTypeface(fontName, FontWeights.Regular, ToWPFFontStyle(style), FontStretches.Normal);

            if (typeface == null)
            {
                return(Graphics.Size.Zero);
            }

            //var typeface = new System.Windows.Media.Typeface(
            //			new System.Windows.Media.FontFamily(fontName),
            //			PlatformUtility.ToWPFFontStyle(this.fontStyles),
            //			(this.fontStyles & FontStyles.Bold) == FontStyles.Bold ?
            //			System.Windows.FontWeights.Bold : System.Windows.FontWeights.Normal,
            //			System.Windows.FontStretches.Normal);

            System.Windows.Media.GlyphTypeface glyphTypeface;

            double totalWidth = 0;

            if (typeface.TryGetGlyphTypeface(out glyphTypeface))
            {
                //fontInfo.Ascent = typeface.FontFamily.Baseline;
                //fontInfo.LineHeight = typeface.CapsHeight;

                var size = fontSize * 1.33d;

                //this.GlyphIndexes.Capacity = text.Length;

                for (int n = 0; n < text.Length; n++)
                {
                    ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]];
                    //GlyphIndexes.Add(glyphIndex);

                    double width = glyphTypeface.AdvanceWidths[glyphIndex] * size;
                    //this.TextSizes.Add(width);

                    totalWidth += width;
                }
            }

            return(new Graphics.Size(totalWidth, typeface.CapsHeight));
        }
Beispiel #4
0
        public Template(string template, string templateName, string script, ResourceCollection resourceCollection)
        {
            if (string.IsNullOrEmpty(templateName))
            {
                throw new ArgumentNullException(nameof(templateName));
            }
            if (string.IsNullOrEmpty(template))
            {
                throw new ArgumentNullException(nameof(template));
            }
            Name = templateName;
            var typeAndExtension = GetTemplateTypeAndExtension(templateName);

            Extension = typeAndExtension.Item2;
            Type      = typeAndExtension.Item1;
            IsPrimary = typeAndExtension.Item3;
            _script   = script;
            if (script != null)
            {
                ScriptName  = templateName + ".js";
                _enginePool = ResourcePool.Create(() => CreateEngine(script), Constants.DefaultParallelism);
            }

            if (resourceCollection != null)
            {
                _rendererPool = ResourcePool.Create(() => CreateRenderer(resourceCollection, templateName, template), Constants.DefaultParallelism);
            }

            Resources = ExtractDependentResources();
        }
Beispiel #5
0
        internal static Graphics.Size MeasureText(DrawingContext dc, string text, string fontName, float fontSize, Drawing.Text.FontStyles style)
        {
            ResourcePoolManager resManager = dc.Renderer.ResourcePoolManager;

            var font = resManager.GetFont(fontName, fontSize, ToWFFontStyle(style));

            if (font == null)
            {
                return(Graphics.Size.Zero);
            }

            var g = ResourcePoolManager.CachedGDIGraphics;

            lock (g)
            {
                lock (sf)
                {
                    var size = ResourcePoolManager.CachedGDIGraphics.MeasureString(text, font, 99999999, sf);

                    size.Width  += 2;
                    size.Height += 2;

                    return(size);
                }
            }
        }
Beispiel #6
0
        public void Constructor_Should_CreatesInstance()
        {
            // Arrange, Act
            var instance = new ResourcePoolManager();

            // Assert
            instance.ShouldNotBeNull();
        }
Beispiel #7
0
 public static void UnInitGameResource()
 {
     if (AppEnv.IsUseAB)
     {
         BundleManager.UnInitGameBundle();
     }
     ResourcePoolManager.ClearPools();
 }
Beispiel #8
0
        internal static Graphics.Size MeasureText(DrawingContext dc, string text, string fontName, double fontSize, Drawing.Text.FontStyles style)
        {
            ResourcePoolManager resManager = dc.Renderer.ResourcePoolManager;

            FormattedText ft = new FormattedText(text, System.Threading.Thread.CurrentThread.CurrentCulture,
                                                 FlowDirection.LeftToRight, resManager.GetTypeface(fontName),
                                                 fontSize * PlatformUtility.GetDPI() / 72.0, null);

            return(new Graphics.Size(ft.Width, ft.Height));
        }
        public async Task UpdateComputedFields()
        {
            Security.LoginAs(1, "Administrator");

            using (var manager = new ResourcePoolManager())
            {
                var list = manager.GetResourcePoolSet(29).AsEnumerable();

                await manager.UpdateComputedFieldsAsync(list.First().Id);
            }
        }
        public async Task UpdateComputedFields2()
        {
            Security.LoginAs(3, "Regular");

            using (var manager = new ResourcePoolManager())
            {
                var list = manager.GetResourcePoolSet(17).AsEnumerable();

                await manager.UpdateComputedFieldsAsync(list.First().Id);
            }
        }
 /**
  * Ensure that only one instance of the ResourcePoolManager shall exist,
  * any further instances will be destoryed
  */
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(gameObject);            // Destory further instances of InputManager
     }
 }
        public RendererWithResourcePool(Func <ITemplateRenderer> creater, int maxParallelism)
        {
            _rendererPool = ResourcePool.Create(creater, maxParallelism);

            using var lease = _rendererPool.Rent();
            var inner = lease.Resource;

            Raw          = inner.Raw;
            Dependencies = inner.Dependencies;
            Path         = inner.Path;
            Name         = inner.Name;
        }
Beispiel #13
0
 /// <summary>
 /// This method is fake. All the parameters are required, even though not all of them are used
 /// </summary>
 private List <XElement> BuildXmlElements(
     ResourcePoolManager resourceManager,
     bool hidden,
     bool readOnly,
     IEnumerable <DataRow> rowCollection,
     List <SPField> fields,
     DataColumnCollection dataColumns,
     System.Data.DataTable resources,
     out Dictionary <string, object[]> valuesDict)
 {
     valuesDict = new Dictionary <string, object[]>();
     return(new List <XElement>());
 }
Beispiel #14
0
        private static void UnloadUnusedAssets(bool forceGc = false, bool clearPool = false)
        {
#if UNITY_EDITOR
            var  watch         = Stopwatch.StartNew();
            long totalTime     = 0;
            long clearPoolTime = 0;
            long unloadResTime = 0;
            long gcTime        = 0;
#endif
            ResourceManager._lastReleaseTime = Time.time;
            if (clearPool)
            {
                ResourcePoolManager.ClearPools();
            }

#if UNITY_EDITOR
            watch.Stop();
            totalTime    += watch.ElapsedMilliseconds;
            clearPoolTime = watch.ElapsedMilliseconds;
            watch.Reset();
            watch.Start();
#endif
            Resources.UnloadUnusedAssets();
#if UNITY_EDITOR
            watch.Stop();
            totalTime    += watch.ElapsedMilliseconds;
            unloadResTime = watch.ElapsedMilliseconds;
            watch.Reset();
            watch.Start();
#endif
            if (forceGc)
            {
                GC.Collect(0, GCCollectionMode.Forced);
            }

#if UNITY_EDITOR
            watch.Stop();
            totalTime += watch.ElapsedMilliseconds;
            gcTime     = watch.ElapsedMilliseconds;
            watch.Reset();
            watch.Start();

            watch.Stop();
            LogHelper.WARN(
                "ResManager", "UnloadUnusedAssets({0}, {1}) used {2}ms(CP{3},UL{4},GC{5})",
                forceGc ? "GC" : "--", clearPool ? "CP" : "--", totalTime, clearPoolTime, unloadResTime, gcTime);
#endif
        }
        public SchemaDrivenDocumentProcessor(DocumentSchema schema, ICompositionContainer container)
        {
            if (string.IsNullOrWhiteSpace(schema.Title))
            {
                throw new ArgumentException("Title for schema must not be empty");
            }

            _schemaName     = schema.Title;
            _schema         = schema;
            _serializerPool = new ResourcePoolManager <JsonSerializer>(GetSerializer, 0x10);
            if (container != null)
            {
                var commonSteps         = container.GetExports <IDocumentBuildStep>(nameof(SchemaDrivenDocumentProcessor));
                var schemaSpecificSteps = container.GetExports <IDocumentBuildStep>($"{nameof(SchemaDrivenDocumentProcessor)}.{_schemaName}");
                BuildSteps = commonSteps.Union(schemaSpecificSteps).ToList();
            }
        }
Beispiel #16
0
        public Template(string name, DocumentBuildContext context, TemplateRendererResource templateResource, TemplatePreprocessorResource scriptResource, ResourceCollection resourceCollection, int maxParallelism)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name = name;
            var templateInfo = GetTemplateInfo(Name);

            Extension    = templateInfo.Extension;
            Type         = templateInfo.DocumentType;
            TemplateType = templateInfo.TemplateType;
            _script      = scriptResource?.Content;
            if (!string.IsNullOrWhiteSpace(_script))
            {
                ScriptName        = Name + ".js";
                _preprocessorPool = ResourcePool.Create(() => CreatePreprocessor(resourceCollection, scriptResource, context), maxParallelism);
                try
                {
                    using (var preprocessor = _preprocessorPool.Rent())
                    {
                        ContainsGetOptions          = preprocessor.Resource.GetOptionsFunc != null;
                        ContainsModelTransformation = preprocessor.Resource.TransformModelFunc != null;
                    }
                }
                catch (Exception e)
                {
                    _preprocessorPool = null;
                    Logger.LogWarning($"{ScriptName} is not a valid template preprocessor, ignored: {e.Message}");
                }
            }

            if (!string.IsNullOrEmpty(templateResource?.Content) && resourceCollection != null)
            {
                _rendererPool            = ResourcePool.Create(() => CreateRenderer(resourceCollection, templateResource), maxParallelism);
                ContainsTemplateRenderer = true;
            }

            if (!ContainsGetOptions && !ContainsModelTransformation && !ContainsTemplateRenderer)
            {
                Logger.LogWarning($"Template {name} contains neither preprocessor to process model nor template to render model. Please check if the template is correctly defined. Allowed preprocessor functions are [exports.getOptions] and [exports.transform].");
            }

            Resources = ExtractDependentResources(Name);
        }
Beispiel #17
0
        public Template(string name, DocumentBuildContext context, TemplateRendererResource templateResource, TemplatePreprocessorResource scriptResource, ResourceCollection resourceCollection, int maxParallelism)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name = name;
            var templateInfo = GetTemplateInfo(Name);
            Extension = templateInfo.Extension;
            Type = templateInfo.DocumentType;
            TemplateType = templateInfo.TemplateType;
            _script = scriptResource?.Content;
            if (!string.IsNullOrWhiteSpace(_script))
            {
                ScriptName = Name + ".js";
                _preprocessorPool = ResourcePool.Create(() => CreatePreprocessor(resourceCollection, scriptResource, context), maxParallelism);
                try
                {
                    using (var preprocessor = _preprocessorPool.Rent())
                    {
                        ContainsGetOptions = preprocessor.Resource.GetOptionsFunc != null;
                        ContainsModelTransformation = preprocessor.Resource.TransformModelFunc != null;
                    }
                }
                catch (Exception e)
                {
                    _preprocessorPool = null;
                    Logger.LogWarning($"{ScriptName} is not a valid template preprocessor, ignored: {e.Message}");
                }
            }

            if (!string.IsNullOrEmpty(templateResource?.Content) && resourceCollection != null)
            {
                _rendererPool = ResourcePool.Create(() => CreateRenderer(resourceCollection, templateResource), maxParallelism);
                ContainsTemplateRenderer = true;
            }

            if (!ContainsGetOptions && !ContainsModelTransformation && !ContainsTemplateRenderer)
            {
                Logger.LogWarning($"Template {name} contains neither preprocessor to process model nor template to render model. Please check if the template is correctly defined. Allowed preprocessor functions are [exports.getOptions] and [exports.transform].");
            }

            Resources = ExtractDependentResources(Name);
        }
Beispiel #18
0
        public void ConstructorSPWeb_Should_CreatesInstance()
        {
            // Arrange
            var spWeb = new ShimSPWeb
            {
                IDGet   = () => DummyGuid,
                SiteGet = () => new ShimSPSite
                {
                    IDGet = () => DummyGuid
                }
            };

            // Act
            var instance = new ResourcePoolManager(spWeb);

            // Assert
            instance.ShouldNotBeNull();
        }
 public PreprocessorWithResourcePool(Func <ITemplatePreprocessor> creater, int maxParallelism)
 {
     _preprocessorPool = ResourcePool.Create(creater, maxParallelism);
     try
     {
         using (var preprocessor = _preprocessorPool.Rent())
         {
             var inner = preprocessor.Resource;
             ContainsGetOptions          = inner.ContainsGetOptions;
             ContainsModelTransformation = inner.ContainsModelTransformation;
             Path = inner.Path;
             Name = inner.Name;
         }
     }
     catch (Exception e)
     {
         _preprocessorPool = null;
         Logger.LogWarning($"Not a valid template preprocessor, ignored: {e.Message}");
     }
 }
Beispiel #20
0
 void OnDestroy()
 {
     ResourcePoolManager.ClearPools();
 }
 public ConceptualDocumentProcessor()
 {
     _serializerPool = new ResourcePoolManager<JsonSerializer>(GetSerializer, 0x10);
 }
 public ManagedReferenceDocumentProcessor()
 {
     _serializerPool = new ResourcePoolManager<JsonSerializer>(GetSerializer, 0x10);
 }
 public ManagedReferenceDocumentProcessor()
 {
     _serializerPool = new ResourcePoolManager <JsonSerializer>(GetSerializer, 0x10);
 }
 public SchemaDrivenDocumentProcessor()
 {
     _serializerPool = new ResourcePoolManager <JsonSerializer>(GetSerializer, 0x10);
 }
 public ConceptualDocumentProcessor()
 {
     _serializerPool = new ResourcePoolManager <JsonSerializer>(GetSerializer, 0x10);
 }
Beispiel #26
0
 public ResourcePoolController() : base()
 {
     _resourcePoolManager = new ResourcePoolManager();
 }