Exemple #1
0
            object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider)
            {
                if (serviceProvider == null)
                {
                    throw new ArgumentNullException(nameof(serviceProvider));
                }

                var targetRD = (serviceProvider.GetService(typeof(Xaml.IProvideValueTarget)) as Xaml.IProvideValueTarget)?.TargetObject as ResourceDictionary;

                if (targetRD == null)
                {
                    return(null);
                }

                var rootObjectType = (serviceProvider.GetService(typeof(Xaml.IRootObjectProvider)) as Xaml.IRootObjectProvider)?.RootObject.GetType();

                if (rootObjectType == null)
                {
                    return(null);
                }

                var lineInfo       = (serviceProvider.GetService(typeof(Xaml.IXmlLineInfoProvider)) as Xaml.IXmlLineInfoProvider)?.XmlLineInfo;
                var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType);
                var uri            = new Uri(value, UriKind.Relative); //we don't want file:// uris, even if they start with '/'
                var resourcePath   = GetResourcePath(uri, rootTargetPath);

                targetRD.SetAndLoadSource(uri, resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo);
                return(uri);
            }
        public void XamlResourceIdAttributeConstructor()
        {
            tlog.Debug(tag, $"XamlResourceIdAttributeConstructor START");

            XamlResourceIdAttribute x1 = new XamlResourceIdAttribute("myId", "myPath", typeof(string));

            tlog.Debug(tag, $"XamlResourceIdAttributeConstructor END (OK)");
            Assert.Pass("XamlResourceIdAttributeConstructor");
        }
Exemple #3
0
            public void XRIDIsGeneratedForRDWithoutCodeBehind()
            {
                var asm        = typeof(ResourceDictionaryWithSource).Assembly;
                var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(asm, "AppResources/Colors.xaml");

                Assert.That(resourceId, Is.Not.Null);
                var type = XamlResourceIdAttribute.GetTypeForResourceId(asm, resourceId);

                Assert.That(type, Is.Null);
            }
        public void XamlResourceIdAttributeConstructor()
        {
            tlog.Debug(tag, $"XamlResourceIdAttributeConstructor START");

            XamlResourceIdAttribute x1 = new XamlResourceIdAttribute("myId", "myPath", typeof(string));

            Assert.IsNotNull(x1, "null XamlResourceIdAttribute");
            Assert.IsInstanceOf <XamlResourceIdAttribute>(x1, "Should return XamlResourceIdAttribute instance.");
            tlog.Debug(tag, $"XamlResourceIdAttributeConstructor END");
        }
Exemple #5
0
            public void CodeBehindIsGeneratedForRDWithXamlComp()
            {
                var asm        = typeof(ResourceDictionaryWithSource).Assembly;
                var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(asm, "AppResources/CompiledColors.xaml");

                Assert.That(resourceId, Is.Not.Null);
                var type = XamlResourceIdAttribute.GetTypeForResourceId(asm, resourceId);

                Assert.That(type, Is.Not.Null);
                var rd = Activator.CreateInstance(type);

                Assert.That(rd as ResourceDictionary, Is.Not.Null);
            }
        public void XamlResourceIdAttributeGetResourceIdForType()
        {
            tlog.Debug(tag, $"XamlResourceIdAttributeGetResourceIdForType START");

            try
            {
                XamlResourceIdAttribute.GetResourceIdForType(typeof(string));
            }
            catch (Exception e)
            {
                Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            tlog.Debug(tag, $"XamlResourceIdAttributeGetResourceIdForType END");
        }
        public void XamlResourceIdAttributeGetTypeForPath()
        {
            tlog.Debug(tag, $"XamlResourceIdAttributeGetTypeForPath START");

            try
            {
                AssemblyImplent assembly = new AssemblyImplent();
                XamlResourceIdAttribute.GetTypeForPath(assembly, "myPath");
            }
            catch (Exception e)
            {
                tlog.Debug(tag, e.Message.ToString());
                tlog.Debug(tag, $"XamlResourceIdAttributeGetTypeForPath END (OK)");
                Assert.Pass("Caught Exception : passed!");
            }
        }
Exemple #8
0
        public void SetAndLoadSource(Uri value, string resourcePath, Assembly assembly, global::System.Xml.IXmlLineInfo lineInfo)
        {
            _source = value;

            //this will return a type if the RD as an x:Class element, and codebehind
            var type = XamlResourceIdAttribute.GetTypeForPath(assembly, resourcePath);

            if (type != null)
            {
                _mergedInstance = s_instances.GetValue(type, (key) => (ResourceDictionary)Activator.CreateInstance(key));
            }
            else
            {
                _mergedInstance = DependencyService.Get <IResourcesLoader>().CreateFromResource <ResourceDictionary>(resourcePath, assembly, lineInfo);
            }
            OnValuesChanged(_mergedInstance.ToArray());
        }
        public void XamlResourceIdAttributeGetTypeForPath2()
        {
            tlog.Debug(tag, $"XamlResourceIdAttributeGetTypeForPath2 START");

            try
            {
                var ret = XamlResourceIdAttribute.GetTypeForPath(typeof(UIElement).Assembly, "none.xaml");
                Assert.IsNull(ret, "Should be null");
            }
            catch (Exception e)
            {
                Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            tlog.Debug(tag, $"XamlResourceIdAttributeGetTypeForPath2 END");
        }
        public void XamlResourceIdAttributeGetTypeForPath()
        {
            tlog.Debug(tag, $"XamlResourceIdAttributeGetTypeForPath START");

            try
            {
                var ret = XamlResourceIdAttribute.GetTypeForPath(typeof(UIElement).Assembly, "testcase.public.Xaml.TotalSample.ClockView.xaml");
                Assert.IsNotNull(ret, "Shouldn't be null");
            }
            catch (Exception e)
            {
                Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            tlog.Debug(tag, $"XamlResourceIdAttributeGetTypeForPath END");
        }
        public void XamlResourceIdAttributeGetPathForType()
        {
            tlog.Debug(tag, $"XamlResourceIdAttributeGetPathForType START");

            try
            {
                var ret = XamlResourceIdAttribute.GetPathForType(typeof(TotalSample));
                Assert.IsNotNull(ret, "Shouldn't be null");
            }
            catch (Exception e)
            {
                Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            tlog.Debug(tag, $"XamlResourceIdAttributeGetPathForType END");
        }
            object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider)
            {
                if (serviceProvider == null)
                {
                    throw new ArgumentNullException(nameof(serviceProvider));
                }

                if (!((serviceProvider.GetService(typeof(Xaml.IProvideValueTarget)) as Xaml.IProvideValueTarget)?.TargetObject is ResourceDictionary targetRD))
                {
                    return(null);
                }

                var rootObjectType = (serviceProvider.GetService(typeof(Xaml.IRootObjectProvider)) as Xaml.IRootObjectProvider)?.RootObject.GetType();

                if (rootObjectType == null)
                {
                    return(null);
                }

                var lineInfo       = (serviceProvider.GetService(typeof(Xaml.IXmlLineInfoProvider)) as Xaml.IXmlLineInfoProvider)?.XmlLineInfo;
                var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType);
                var assembly       = rootObjectType.GetTypeInfo().Assembly;

#if !NETSTANDARD1_0
                if (value.Contains(";assembly="))
                {
                    var parts = value.Split(new[] { ";assembly=" }, StringSplitOptions.RemoveEmptyEntries);
                    value = parts[0];
                    var asmName = parts[1];
                    assembly = Assembly.Load(asmName);
                }
#endif
                var uri          = new Uri(value, UriKind.Relative);        //we don't want file:// uris, even if they start with '/'
                var resourcePath = GetResourcePath(uri, rootTargetPath);

                //Re-add the assembly= in all cases, so HotReload doesn't have to make assumptions
                uri = new Uri($"{value};assembly={assembly.GetName().Name}", UriKind.Relative);
                targetRD.SetAndLoadSource(uri, resourcePath, assembly, lineInfo);

                return(uri);
            }
        public void SetAndLoadSource(Uri value, string resourceID, Assembly assembly, System.Xml.IXmlLineInfo lineInfo)
        {
            _source = value;
            if (_mergedWith != null)
            {
                throw new ArgumentException("Source can not be used with MergedWith");
            }

            //this will return a type if the RD as an x:Class element, and codebehind
            var type = XamlResourceIdAttribute.GetTypeForResourceId(assembly, resourceID);

            if (type != null)
            {
                _mergedInstance = s_instances.GetValue(type, (key) => (ResourceDictionary)Activator.CreateInstance(key));
            }
            else
            {
                _mergedInstance = DependencyService.Get <IResourcesLoader>().CreateResourceDictionary(resourceID, assembly, lineInfo);
            }
            OnValuesChanged(_mergedInstance.ToArray());
        }
 public void Destroy()
 {
     resourceId = null;
     tlog.Info(tag, "Destroy() is called!");
 }
 public void Init()
 {
     tlog.Info(tag, "Init() is called!");
     resourceId = new XamlResourceIdAttribute("myId", "myPath", typeof(string));
 }