Example #1
0
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     dataContext.Set(_repositories);
 }
        protected override void Supply(
            IRenderContext renderContext,
            IDataContext dataContext,
            IDataDependency dependency)
        {
            if (dependency == null || string.IsNullOrEmpty(dependency.ScopeName))
            {
                dataContext.Set(_desktopMenu);
                return;
            }

            switch (dependency.ScopeName.ToLower())
            {
            case "mobile":
                dataContext.Set(_mobileMenu, dependency.ScopeName);
                break;

            case "desktop":
                dataContext.Set(_desktopMenu, dependency.ScopeName);
                break;

            case "sitemap":
                dataContext.Set(_sitemapMenu, dependency.ScopeName);
                break;

            default:
                dataContext.Set(_desktopMenu);
                break;
            }
        }
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     dataContext.Set(_functionalAreas);
 }
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     dataContext.Set(_menu, dependency.ScopeName);
 }
        public void Should_register_supplies_without_scope()
        {
            var dependencyFactory = SetupMock <IDataDependencyFactory>();

            IDataDependency actionDependency = null;
            Action <IRenderContext, IDataContext, IDataDependency> action =
                (rc, dc, dd) => actionDependency = dd;

            var registeredDependency = dependencyFactory.Create(typeof(int));

            _dataSupplier.Add(registeredDependency, action);

            Assert.IsTrue(_dataSupplier.IsSupplierOf(registeredDependency));
            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(int), "test-scope")));
            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(int), "other-scope")));
            Assert.IsTrue(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(int))));

            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(long))));
            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(long), "test-scope")));
            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(long), "other-scope")));

            var dataSupply = _dataSupplier.GetSupply(dependencyFactory.Create(typeof(int)));

            Assert.IsNotNull(dataSupply);

            dataSupply.Supply(null, null);

            Assert.AreEqual(registeredDependency, actionDependency);
        }
        public IDataSupplier FindSupplier(IDataDependency dependency)
        {
            List <IDataSupplier> suppliers;

            if (!Suppliers.TryGetValue(dependency.DataType, out suppliers))
            {
                return(null);
            }

            IDataSupplier supplier;

            if (string.IsNullOrEmpty(dependency.ScopeName))
            {
                supplier = suppliers.FirstOrDefault(s => s.CanSupplyUnscoped(dependency.DataType) && s.IsSupplierOf(dependency));
            }
            else
            {
                supplier = suppliers.FirstOrDefault(s => s.CanSupplyScoped(dependency.DataType) && s.IsSupplierOf(dependency));
            }

            if (supplier == null)
            {
                supplier = suppliers.FirstOrDefault(s => s.IsSupplierOf(dependency));
            }

            return(supplier);
        }
Example #7
0
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     if (dependency == null)
     {
         dataContext.Set <TextEffectsPackage.VerticalText>(null);
     }
     else if (dependency.DataType == typeof(TextEffectsPackage.VerticalText))
     {
         TextEffectsPackage.VerticalText verticalTextInfo = null;
         var area = GetContentArea(renderContext);
         if (area != null)
         {
             area             = char.ToUpper(area[0]) + area.Substring(1);
             verticalTextInfo = new TextEffectsPackage.VerticalText(area, 60, 160)
             {
                 Background = null,
                 TextStyle  = "font: 30px serif; fill: white;"
             };
         }
         dataContext.Set(verticalTextInfo);
     }
     else
     {
         throw new Exception(GetType().DisplayName() + " can not supply " +
                             dependency.DataType.DisplayName());
     }
 }
Example #8
0
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     dataContext.Set(_customers);
 }
Example #9
0
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     dataContext.Set(_applicationInfo);
 }
Example #10
0
        public void AddSupplier(
            IDataSupplier supplier,
            IDataDependency dependencyToSupply)
        {
            if (supplier == null)
            {
                throw new ArgumentNullException("supplier");
            }
            if (dependencyToSupply == null)
            {
                throw new ArgumentNullException("dependencyToSupply");
            }

            lock (_lock)
            {
                var suppliedDependency = SuppliedDependencies
                                         .FirstOrDefault(d => d.Item1 == supplier && d.Item2.Equals(dependencyToSupply));

                if (suppliedDependency != null)
                {
                    return;
                }

                SuppliedDependencies.Add(new Tuple <IDataSupplier, IDataDependency>(supplier, dependencyToSupply));
            }
        }
        protected override void Supply(
            IRenderContext renderContext,
            IDataContext dataContext,
            IDataDependency dependency)
        {
            SiteMap.Project         project    = null;
            SiteMap.Document        document   = null;
            SiteMap.Repository      repository = null;
            SiteMap.RepositoryOwner owner      = null;

            if (dependency != null && dependency.DataType == typeof(SiteMap.Project))
            {
                project = GetProject(renderContext);
                if (project != null)
                {
                    document   = project.Document;
                    repository = project.Repository;
                    if (repository != null)
                    {
                        owner = repository.Owner;
                    }
                }
            }

            dataContext.Set(project);
            dataContext.Set(document);
            dataContext.Set(repository);
            dataContext.Set(owner);
        }
        public void HasDependency(IDataSupplier dataSupplier, IDataDependency dependency)
        {
            if (ReferenceEquals(dataSupplier, null))
            {
                throw new ArgumentNullException("dataSupplier");
            }

            if (dataSupplier == null)
            {
                throw new Exception("Data provider " + dataSupplier + " is not a supplier of data");
            }

            if (ReferenceEquals(dependency, null))
            {
                dependency = dataSupplier.DefaultDependency;
            }

            if (!dataSupplier.IsSupplierOf(dependency))
            {
                throw new Exception("Data provider " + dataSupplier + " is not a supplier of " + dependency);
            }

            if (DataSupplierDependencies == null)
            {
                DataSupplierDependencies = new List <Tuple <IDataSupplier, IDataDependency> >();
            }

            DataSupplierDependencies.Add(new Tuple <IDataSupplier, IDataDependency>(dataSupplier, dependency));
        }
Example #13
0
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     dataContext.Set(new VerticalText("Vertical", 60, 160));
 }
 public bool Equals(IDataDependency other)
 {
     if (ReferenceEquals(other, null))
     {
         return(false);
     }
     return(DataType == other.DataType && ScopeName == other.ScopeName);
 }
Example #15
0
 void IDataConsumer.HasDependency(IDataProvider dataProvider, IDataDependency dependency)
 {
     if (_dataConsumer == null)
     {
         return;
     }
     _dataConsumer.HasDependency(dataProvider, dependency);
 }
Example #16
0
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     dataContext.Set(new Person {
         FirstName = "John", LastName = "Doe"
     });
 }
Example #17
0
 protected override void Supply(
     IRenderContext renderContext,
     IDataContext dataContext,
     IDataDependency dependency)
 {
     dataContext.Set(new Person {
         FirstName = "Martin", LastName = "Halliday"
     });
 }
Example #18
0
 public void Add(
     IDataDependency dependency,
     Action <IRenderContext, IDataContext, IDataDependency> action)
 {
     _dependency   = dependency;
     _action       = action;
     SuppliedTypes = new List <Type> {
         dependency.DataType
     };
 }
Example #19
0
        protected override void Supply(
            IRenderContext renderContext,
            IDataContext dataContext,
            IDataDependency dependency)
        {
            var gameId = renderContext.OwinContext.Request.Query["g"];
            var game   = new Game {
                GameId = gameId
            };

            dataContext.Set(game);
        }
 public bool Equals(IDataDependency other)
 {
     if (ReferenceEquals(other, null))
     {
         return(false);
     }
     if (DataType != other.DataType)
     {
         return(false);
     }
     return(string.Equals(ScopeName, other.ScopeName, StringComparison.OrdinalIgnoreCase));
 }
Example #21
0
 public bool IsInScope(IDataDependency dependency)
 {
     if (_parent == null)
     {
         return(true);
     }
     if (_dataScopes == null)
     {
         return(false);
     }
     return(_dataScopes.Any(scope => scope.IsMatch(dependency)));
 }
Example #22
0
        public IDataSupplier FindSupplier(IDataDependency dependency)
        {
            var type = dependency.DataType;

            if (type == null)
            {
                throw new Exception("Data dependencies must include the data type thay are dependent on");
            }

            SupplierRegistration[] registrations;
            if (!_registrations.TryGetValue(type, out registrations))
            {
                return(null);
            }

            SupplierRegistration unscopedRegistration = null;
            SupplierRegistration scopedRegistration   = null;

            for (var i = 0; i < registrations.Length; i++)
            {
                var registration = registrations[i];
                var supplier     = registration.Supplier;
                if (supplier.IsSupplierOf(dependency))
                {
                    if (registration.CanSupplyScoped)
                    {
                        if (scopedRegistration == null || scopedRegistration.DependencyScore > registration.DependencyScore)
                        {
                            scopedRegistration = registration;
                        }
                    }
                    if (registration.CanSupplyUnscoped)
                    {
                        if (unscopedRegistration == null || unscopedRegistration.DependencyScore > registration.DependencyScore)
                        {
                            unscopedRegistration = registration;
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(dependency.ScopeName))
            {
                return(unscopedRegistration == null
                    ? (scopedRegistration == null ? null : scopedRegistration.Supplier)
                    : unscopedRegistration.Supplier);
            }

            return(scopedRegistration == null
                ? (unscopedRegistration == null ? null : unscopedRegistration.Supplier)
                : scopedRegistration.Supplier);
        }
Example #23
0
            public SuppliedDependency(IDataSupplier dataSupplier, IDataDependency dataDependency)
            {
                DataSupplier      = dataSupplier;
                DataDependency    = dataDependency;
                DependentSupplies = new List <IDataSupply>();

                if (DataDependency != null && !DataSupplier.IsSupplierOf(DataDependency))
                {
                    throw new Exception("Supplier '" + DataSupplier + "' is not a supplier of '" + DataDependency + "'");
                }

                DataSupply = DataSupplier.GetSupply(DataDependency);
            }
Example #24
0
        IDataSupply IDataSupplier.GetSupply(IDataDependency dependency)
        {
            var supply = _dataSupplies.FirstOrDefault(s => s.IsMatch(dependency));

            return(supply == null
                ? null
                : new DataSupply
            {
                DataSupplier = this,
                Dependency = supply.Dependency,
                Action = supply.Action,
                IsStatic = true
            });
        }
Example #25
0
        public bool IsMatch(IDataDependency dependency)
        {
            if (string.IsNullOrEmpty(ScopeName))
            {
                return(DataType == dependency.DataType);
            }

            if (DataType == null)
            {
                return(string.Equals(ScopeName, dependency.ScopeName, StringComparison.OrdinalIgnoreCase));
            }

            return((DataType == dependency.DataType) &&
                   string.Equals(ScopeName, dependency.ScopeName, StringComparison.OrdinalIgnoreCase));
        }
 public bool IsInScope(IDataDependency dependency)
 {
     if (dependency == null)
     {
         return(false);
     }
     if (dependency.DataType != ScopeType)
     {
         return(false);
     }
     if (string.IsNullOrEmpty(dependency.ScopeName) || string.IsNullOrEmpty(ScopeName))
     {
         return(true);
     }
     return(string.Equals(dependency.ScopeName, ScopeName, StringComparison.OrdinalIgnoreCase));
 }
        public void AddMissingData(IRenderContext renderContext, IDataDependency missingDependency)
        {
#if TRACE
            renderContext.Trace(() => "Data context builder #" + Id + " has been notified of a missing dependency on " + missingDependency);
#endif

            ResolveDataDependencySupplies(missingDependency);

            var root = this;
            while (!ReferenceEquals(root._parent, null))
            {
                root = root._parent;
            }

            renderContext.DeleteDataContextTree();
            root.SetupDataContext(renderContext);
        }
Example #28
0
        void IDataSupplier.Add(IDataDependency dependency, Action <IRenderContext, IDataContext, IDataDependency> action)
        {
            if (ReferenceEquals(dependency.DataType, null))
            {
                throw new Exception("Dependencies must specify a data type");
            }

            _dataSupplies.Add(new RegisteredSupply
            {
                Dependency = dependency,
                Action     = action
            });

            if (!SuppliedTypes.Contains(dependency.DataType))
            {
                SuppliedTypes.Add(dependency.DataType);
            }
        }
Example #29
0
        protected override void Supply(
            IRenderContext renderContext,
            IDataContext dataContext,
            IDataDependency dependency)
        {
            SiteMap.Document document = null;

            if (dependency != null && dependency.DataType == typeof(SiteMap.Document))
            {
                var interfaceDefinition = dataContext.Get <SiteMap.InterfaceDefinition>();
                if (interfaceDefinition != null)
                {
                    document = interfaceDefinition.Document;
                }
            }

            dataContext.Set(document);
        }
        protected override void Supply(
            IRenderContext renderContext,
            IDataContext dataContext,
            IDataDependency dependency)
        {
            SiteMap.Document document = null;

            if (dependency != null && dependency.DataType == typeof(SiteMap.Document))
            {
                var functionalArea = dataContext.Get <SiteMap.FunctionalArea>();
                if (functionalArea != null)
                {
                    document = functionalArea.Document;
                }
            }

            dataContext.Set(document);
        }
Example #31
0
		///	<summary> 
		///		This method copy's each database field which is in the <paramref name="includedColumns"/> 
		///		from the <paramref name="source"/> interface to this data row.
		/// </summary>
		public void Copy_From_But_TakeOnly(IDataDependency source, params string[] includedColumns)
		{
			if (includedColumns.Contains(DataDependenciesTable.IdCol)) this.Id = source.Id;
			if (includedColumns.Contains(DataDependenciesTable.ActuallBezeichnerCol)) this.ActuallBezeichner = source.ActuallBezeichner;
			if (includedColumns.Contains(DataDependenciesTable.DataElementeTemplatesIdCol)) this.DataElementeTemplatesId = source.DataElementeTemplatesId;
			if (includedColumns.Contains(DataDependenciesTable.SortOrderCol)) this.SortOrder = source.SortOrder;
			if (includedColumns.Contains(DataDependenciesTable.VisibilityCol)) this.Visibility = source.Visibility;
			if (includedColumns.Contains(DataDependenciesTable.DescriptionCol)) this.Description = source.Description;
			if (includedColumns.Contains(DataDependenciesTable.RelatedDataDependencyIdCol)) this.RelatedDataDependencyId = source.RelatedDataDependencyId;
			if (includedColumns.Contains(DataDependenciesTable.DefaultAccessRightsIdCol)) this.DefaultAccessRightsId = source.DefaultAccessRightsId;
			if (includedColumns.Contains(DataDependenciesTable.LastUpdateTokenCol)) this.LastUpdateToken = source.LastUpdateToken;
			if (includedColumns.Contains(DataDependenciesTable.RootDataTemplatesIdCol)) this.RootDataTemplatesId = source.RootDataTemplatesId;
			if (includedColumns.Contains(DataDependenciesTable.TypIdCol)) this.TypId = source.TypId;
			if (includedColumns.Contains(DataDependenciesTable.ItemCol)) this.Item = source.Item;
			if (includedColumns.Contains(DataDependenciesTable.ItemContentCol)) this.ItemContent = source.ItemContent;
		}
Example #32
0
		///	<summary> This method copy's each database field from the <paramref name="source"/> interface to this data row.</summary>
		public void Copy_From(IDataDependency source, bool includePrimaryKey = false)
		{
			if (includePrimaryKey) this.Id = source.Id;
			this.ActuallBezeichner = source.ActuallBezeichner;
			this.DataElementeTemplatesId = source.DataElementeTemplatesId;
			this.SortOrder = source.SortOrder;
			this.Visibility = source.Visibility;
			this.Description = source.Description;
			this.RelatedDataDependencyId = source.RelatedDataDependencyId;
			this.DefaultAccessRightsId = source.DefaultAccessRightsId;
			this.LastUpdateToken = source.LastUpdateToken;
			this.RootDataTemplatesId = source.RootDataTemplatesId;
			this.TypId = source.TypId;
			this.Item = source.Item;
			this.ItemContent = source.ItemContent;
		}
Example #33
0
		///	<summary> This method copy's each database field into the <paramref name="target"/> interface. </summary>
		public void Copy_To(IDataDependency target, bool includePrimaryKey = false)
		{
			if (includePrimaryKey) target.Id = this.Id;
			target.ActuallBezeichner = this.ActuallBezeichner;
			target.DataElementeTemplatesId = this.DataElementeTemplatesId;
			target.SortOrder = this.SortOrder;
			target.Visibility = this.Visibility;
			target.Description = this.Description;
			target.RelatedDataDependencyId = this.RelatedDataDependencyId;
			target.DefaultAccessRightsId = this.DefaultAccessRightsId;
			target.LastUpdateToken = this.LastUpdateToken;
			target.RootDataTemplatesId = this.RootDataTemplatesId;
			target.TypId = this.TypId;
			target.Item = this.Item;
			target.ItemContent = this.ItemContent;
		}