Exemplo n.º 1
0
        private IMarquee ReadRecord(IDataRecord record, MetadataCategory category)
        {
            var location = record.GetUri("Location");
            var name     = record.GetString("Name");
            var fromDate = record.GetDateTime("FromDate");
            var toDate   = record.GetDateTime("ToDate");

            var subtitle = new StringBuilder(string.Empty);

            if (fromDate != DateTime.MinValue && fromDate != DateTime.MaxValue)
            {
                subtitle.Append(fromDate.ToShortDateString());
            }
            if (toDate != DateTime.MinValue && toDate != DateTime.MaxValue)
            {
                if (subtitle.Length > 0)
                {
                    subtitle.Append(" - ");
                }

                subtitle.Append(toDate.ToShortDateString());
            }

            return(new Marquee(location, category, name, subtitle.ToString()));
        }
        public IMarqueePage GetMarqueePage(MetadataCategory category, int pageIndex, int pageSize)
        {
            if (pageIndex < 0)
                throw new ArgumentException("pageIndex cannot be less than 0");
            if (pageSize < 1)
                throw new ArgumentException("pageSize cannot be less than 1");

            var offset = pageIndex * pageSize;

            var countBuilder = new CommandBuilder();
            countBuilder.AppendFormat("select count(Location) from {0};", category);
            var numberOfPages = 1;
            var scalar = ExecuteScalar(countBuilder);
            if (scalar != null)
            {
                var result = 0;
                if (int.TryParse(scalar.ToString(), out result) && result > 0)
                {
                    numberOfPages = (int)Math.Ceiling((double)result / (double)pageSize);
                }
            }

            var builder = new CommandBuilder();
            builder.AppendFormat("select Location, Name, FromDate, ToDate from {0} order by Name limit {1}", category, pageSize);
            if (offset > 0)
                builder.AppendFormat(" offset {0};", offset);
            else
                builder.Append(";");

            var items = GetRecords<IMarquee>(builder, record => ReadRecord(record, category));

            return new MarqueePage(items, numberOfPages, pageIndex, pageSize);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method is an extension point that can provide additional metadata-based dependencies to compiled method bodies.
        /// </summary>
        public void GetDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, MethodDesc method)
        {
            if (method.HasInstantiation)
            {
                ExactMethodInstantiationsNode.GetExactMethodInstantiationDependenciesForMethod(ref dependencies, factory, method);
            }

            GetDependenciesDueToMethodCodePresence(ref dependencies, factory, method);

            MetadataCategory category = GetMetadataCategory(method);

            if ((category & MetadataCategory.Description) != 0)
            {
                GetMetadataDependenciesDueToReflectability(ref dependencies, factory, method);
            }

            if ((category & MetadataCategory.RuntimeMapping) != 0)
            {
                if (IsReflectionInvokable(method))
                {
                    // We're going to generate a mapping table entry for this. Collect dependencies.
                    CodeBasedDependencyAlgorithm.AddDependenciesDueToReflectability(ref dependencies, factory, method);
                }
            }
        }
 private static object GetIcon(MetadataCategory category)
 {
     switch (category)
     {
         case MetadataCategory.Album:
             return "pack://application:,,,/Images/scarab.gif";
         case MetadataCategory.Artist:
             return "pack://application:,,,/Images/crown.png";
         case MetadataCategory.Clip:
             return "pack://application:,,,/Images/eye_of_horus.jpg";
         case MetadataCategory.Doc:
             return "pack://application:,,,/Images/scroll.gif";
         case MetadataCategory.Feed:
             return "pack://application:,,,/Images/ouroboros.jpg";
         case MetadataCategory.Pic:
             return "pack://application:,,,/Images/tablet.gif";
         case MetadataCategory.Playlist:
             return "pack://application:,,,/Images/hawk.gif";
         case MetadataCategory.Program:
             return "pack://application:,,,/Images/abacus.gif";
         case MetadataCategory.Track:
             return "pack://application:,,,/Images/lyre.jpg";
         case MetadataCategory.FeedItem:
         case MetadataCategory.PlaylistItem:
         case MetadataCategory.None:
         default:
             return "pack://application:,,,/Images/sphinx_circle.png";
     }    
 }
Exemplo n.º 5
0
        /// <summary>
        /// This method is an extension point that can provide additional metadata-based dependencies to generated EETypes.
        /// </summary>
        public void GetDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
        {
            MetadataCategory category = GetMetadataCategory(type);

            if ((category & MetadataCategory.Description) != 0)
            {
                GetMetadataDependenciesDueToReflectability(ref dependencies, factory, type);
            }
        }
Exemplo n.º 6
0
        public MarqueeView GetMarqueeView(MetadataCategory category)
        {
            var controller = new MarqueeController(logger, marqueeRepository, category);

            var view = new MarqueeView();

            view.Initialize(logger, controller);
            return(view);
        }
        public MarqueeController(ILogger logger, IMarqueeRepository repository, MetadataCategory category)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");
            if (repository == null)
                throw new ArgumentNullException("repository");

            this.logger = logger;
            this.repository = repository;
            this.category = category;
        }
 public MetadataEventArgs(MetadataCommand command, MetadataCategory category, MetadataScope scope, bool finished, string reason, int successCount, int totalCount, bool canceled)
 {
     Command      = command;
     Category     = category;
     Scope        = scope;
     Finished     = finished;
     Reason       = reason;
     SuccessCount = successCount;
     TotalCount   = totalCount;
     Canceled     = canceled;
 }
        protected override MetadataCategory GetMetadataCategory(TypeDesc type)
        {
            MetadataCategory category = 0;

            if (!IsReflectionBlocked(type))
            {
                category = MetadataCategory.RuntimeMapping;

                if (_compilationModuleGroup.ContainsType(type.GetTypeDefinition()))
                    category |= MetadataCategory.Description;
            }

            return category;
        }
Exemplo n.º 10
0
        public async Task <SaveMetadataCategoryResponse> SaveAsync(MetadataCategory category)
        {
            try
            {
                await _metadataCategoryRepository.AddAsync(category);

                return(new SaveMetadataCategoryResponse(category));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveMetadataCategoryResponse($"An error occurred when saving the category: {ex.Message}"));
            }
        }
Exemplo n.º 11
0
        public Marquee(Uri location, MetadataCategory category, string name, string subtitle)
        {
            if (location == null)
                throw new ArgumentNullException("location");
            if (name == null)
                throw new ArgumentNullException("name");
            if (subtitle == null)
                throw new ArgumentNullException("subtitle");

            this.location = location;
            this.category = category;
            this.name = name;
            this.subtitle = subtitle;
        }
        protected override MetadataCategory GetMetadataCategory(MethodDesc method)
        {
            MetadataCategory category = 0;

            if (!IsReflectionBlocked(method))
            {
                category = MetadataCategory.RuntimeMapping;

                if (_compilationModuleGroup.ContainsType(method.GetTypicalMethodDefinition().OwningType))
                    category |= MetadataCategory.Description;
            }

            return category;
        }
Exemplo n.º 13
0
        /// <summary>
        /// This method is an extension point that can provide additional metadata-based dependencies to generated fields.
        /// </summary>
        public void GetDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, FieldDesc field)
        {
            MetadataCategory category = GetMetadataCategory(field);

            if ((category & MetadataCategory.Description) != 0)
            {
                GetMetadataDependenciesDueToReflectability(ref dependencies, factory, field);
            }

            if ((category & MetadataCategory.RuntimeMapping) != 0)
            {
                TypeDesc owningCanonicalType = field.OwningType.ConvertToCanonForm(CanonicalFormKind.Specific);
                GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, owningCanonicalType);
            }
        }
Exemplo n.º 14
0
        public MarqueeController(ILogger logger, IMarqueeRepository repository, MetadataCategory category)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            this.logger     = logger;
            this.repository = repository;
            this.category   = category;
        }
Exemplo n.º 15
0
        protected override MetadataCategory GetMetadataCategory(FieldDesc field)
        {
            MetadataCategory category = 0;

            if (!IsReflectionBlocked(field))
            {
                category = MetadataCategory.RuntimeMapping;

                if (_compilationModuleGroup.ContainsType(field.GetTypicalFieldDefinition().OwningType))
                {
                    category |= MetadataCategory.Description;
                }
            }

            return(category);
        }
Exemplo n.º 16
0
        /// <summary>
        /// This method is an extension point that can provide additional metadata-based dependencies to generated EETypes.
        /// </summary>
        public void GetDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
        {
            MetadataCategory category = GetMetadataCategory(type);

            if ((category & MetadataCategory.Description) != 0)
            {
                GetMetadataDependenciesDueToReflectability(ref dependencies, factory, type);
            }

            if ((category & MetadataCategory.RuntimeMapping) != 0)
            {
                // We're going to generate a mapping table entry for this. Collect dependencies.

                // Nothing for now - the mapping table only refers to the EEType and we already generated one because
                // we got the callback.
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// This method is an extension point that can provide additional metadata-based dependencies to compiled method bodies.
        /// </summary>
        public void GetDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, MethodDesc method)
        {
            MetadataCategory category = GetMetadataCategory(method);

            if ((category & MetadataCategory.Description) != 0)
            {
                GetMetadataDependenciesDueToReflectability(ref dependencies, factory, method);
            }

            if ((category & MetadataCategory.RuntimeMapping) != 0)
            {
                if (IsReflectionInvokable(method))
                {
                    // We're going to generate a mapping table entry for this. Collect dependencies.
                    ReflectionInvokeMapNode.AddDependenciesDueToReflectability(ref dependencies, factory, method);
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// This method is an extension point that can provide additional metadata-based dependencies to generated EETypes.
        /// </summary>
        public void GetDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
        {
            MetadataCategory category = GetMetadataCategory(type);

            if ((category & MetadataCategory.Description) != 0)
            {
                GetMetadataDependenciesDueToReflectability(ref dependencies, factory, type);
            }

            if ((category & MetadataCategory.RuntimeMapping) != 0)
            {
                // We're going to generate a mapping table entry for this. Collect dependencies.

                // Nothing special is needed for the mapping table (we only emit the EEType and we already
                // have one, since we got this callback). But check if a child wants to do something extra.
                GetRuntimeMappingDependenciesDueToReflectability(ref dependencies, factory, type);
            }
        }
Exemplo n.º 19
0
        public IMarqueePage GetMarqueePage(MetadataCategory category, int pageIndex, int pageSize)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentException("pageIndex cannot be less than 0");
            }
            if (pageSize < 1)
            {
                throw new ArgumentException("pageSize cannot be less than 1");
            }

            var offset = pageIndex * pageSize;

            var countBuilder = new CommandBuilder();

            countBuilder.AppendFormat("select count(Location) from {0};", category);
            var numberOfPages = 1;
            var scalar        = ExecuteScalar(countBuilder);

            if (scalar != null)
            {
                var result = 0;
                if (int.TryParse(scalar.ToString(), out result) && result > 0)
                {
                    numberOfPages = (int)Math.Ceiling((double)result / (double)pageSize);
                }
            }

            var builder = new CommandBuilder();

            builder.AppendFormat("select Location, Name, FromDate, ToDate from {0} order by Name limit {1}", category, pageSize);
            if (offset > 0)
            {
                builder.AppendFormat(" offset {0};", offset);
            }
            else
            {
                builder.Append(";");
            }

            var items = GetRecords <IMarquee>(builder, record => ReadRecord(record, category));

            return(new MarqueePage(items, numberOfPages, pageIndex, pageSize));
        }
Exemplo n.º 20
0
        public Marquee(Uri location, MetadataCategory category, string name, string subtitle)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (subtitle == null)
            {
                throw new ArgumentNullException("subtitle");
            }

            this.location = location;
            this.category = category;
            this.name     = name;
            this.subtitle = subtitle;
        }
        protected override MetadataCategory GetMetadataCategory(MethodDesc method)
        {
            MetadataCategory category = 0;

            if (!IsReflectionBlocked(method))
            {
                // Can't do mapping for uninstantiated things
                if (!method.IsGenericMethodDefinition && !method.OwningType.IsGenericDefinition)
                {
                    category = MetadataCategory.RuntimeMapping;
                }

                if (_compilationModuleGroup.ContainsType(method.GetTypicalMethodDefinition().OwningType))
                {
                    category |= MetadataCategory.Description;
                }
            }

            return(category);
        }
        private IMarquee ReadRecord(IDataRecord record, MetadataCategory category)
        {
            var location = record.GetUri("Location");
            var name = record.GetString("Name");
            var fromDate = record.GetDateTime("FromDate");
            var toDate = record.GetDateTime("ToDate");
            
            var subtitle = new StringBuilder(string.Empty);
            if (fromDate != DateTime.MinValue && fromDate != DateTime.MaxValue)
                subtitle.Append(fromDate.ToShortDateString());
            if (toDate != DateTime.MinValue && toDate != DateTime.MaxValue)
            {
                if (subtitle.Length > 0)
                    subtitle.Append(" - ");

                subtitle.Append(toDate.ToShortDateString());
            }

            return new Marquee(location, category, name, subtitle.ToString());
        }
Exemplo n.º 23
0
        public void MarqueeBrowse(MetadataCategory category, string name, object icon)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            try
            {
                var view        = taskController.GetMarqueeView(category);
                var description = string.Format("Browse: {0}", name);

                Action workFunction  = () => view.RefreshItems();
                var    taskViewModel = new SimpleTaskViewModel(logger, workFunction, name, description, icon);

                var tabItem = new TabItem();

                //TextBlock header = new TextBlock();
                //header.Inlines.Add(name);
                //header.ToolTip = description;
                tabItem.Header = new TaskHeader(logger, taskViewModel);

                tabItem.Content = view;
                resultControl.Items.Add(tabItem);
                tabItem.IsSelected = true;

                AddViewModel(taskViewModel, tabItem);

                if (taskViewModel.Status == TaskStatus.Ready)
                {
                    taskViewModel.Start();
                }
            }
            catch (Exception ex)
            {
                logger.Error("  TaskResultView.MarqueeBrowse", ex);
            }
        }
Exemplo n.º 24
0
        private static object GetIcon(MetadataCategory category)
        {
            switch (category)
            {
            case MetadataCategory.Album:
                return("pack://application:,,,/Images/scarab.gif");

            case MetadataCategory.Artist:
                return("pack://application:,,,/Images/crown.png");

            case MetadataCategory.Clip:
                return("pack://application:,,,/Images/eye_of_horus.jpg");

            case MetadataCategory.Doc:
                return("pack://application:,,,/Images/scroll.gif");

            case MetadataCategory.Feed:
                return("pack://application:,,,/Images/ouroboros.jpg");

            case MetadataCategory.Pic:
                return("pack://application:,,,/Images/tablet.gif");

            case MetadataCategory.Playlist:
                return("pack://application:,,,/Images/hawk.gif");

            case MetadataCategory.Program:
                return("pack://application:,,,/Images/abacus.gif");

            case MetadataCategory.Track:
                return("pack://application:,,,/Images/lyre.jpg");

            case MetadataCategory.FeedItem:
            case MetadataCategory.PlaylistItem:
            case MetadataCategory.None:
            default:
                return("pack://application:,,,/Images/sphinx_circle.png");
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// This method is an extension point that can provide additional metadata-based dependencies to compiled method bodies.
        /// </summary>
        public void GetDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, MethodDesc method)
        {
            MetadataCategory category = GetMetadataCategory(method);

            if ((category & MetadataCategory.Description) != 0)
            {
                GetMetadataDependenciesDueToReflectability(ref dependencies, factory, method);
            }

            if ((category & MetadataCategory.RuntimeMapping) != 0)
            {
                if (IsReflectionInvokable(method))
                {
                    // We're going to generate a mapping table entry for this. Collect dependencies.
                    ReflectionInvokeMapNode.AddDependenciesDueToReflectability(ref dependencies, factory, method);

                    ReflectionInvokeSupportDependencyAlgorithm.GetDependenciesFromParamsArray(ref dependencies, factory, method);
                }

                GenericMethodsTemplateMap.GetTemplateMethodDependencies(ref dependencies, factory, method);
                GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, method.OwningType);
            }
        }
 /// <summary>
 /// Creates a success response.
 /// </summary>
 /// <param name="metadata">Saved metadata.</param>
 /// <returns>Response.</returns>
 public SaveMetadataCategoryResponse(MetadataCategory category) : this(true, string.Empty, category)
 {
 }
 private SaveMetadataCategoryResponse(bool success, string message, MetadataCategory category) : base(success, message)
 {
     Category = category;
 }
Exemplo n.º 28
0
 public ReflectableEntity(TEntity entity, MetadataCategory category)
 {
     Entity   = entity;
     Category = category;
 }
Exemplo n.º 29
0
        public MarqueeView GetMarqueeView(MetadataCategory category)
        {
            var controller = new MarqueeController(logger, marqueeRepository, category);

            var view = new MarqueeView();
            view.Initialize(logger, controller);
            return view;
        }
Exemplo n.º 30
0
        //This is where we create new tables
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity <Municipality>().ToTable("Municipalities");
            builder.Entity <Municipality>().HasKey(p => p.Name);
            builder.Entity <Municipality>().Property(p => p.ShieldFileName).IsRequired().ValueGeneratedOnAdd();
            builder.Entity <Municipality>().HasMany(p => p.MetadataList).WithOne(p => p.Owner).HasForeignKey(p => p.MunicipalityName).IsRequired();

            builder.Entity <Municipality>().HasData
            (
                new Municipality {
                Name = "Bodø", MailDomain = "bodo.kommune.no", ShieldFileName = "404.png"
            },
                new Municipality {
                Name = "Test", MailDomain = "test.kommune.no", ShieldFileName = "404.png"
            },
                new Municipality {
                Name = "Bærum", MailDomain = "baerum.kommune.no", ShieldFileName = "404.png"
            },
                new Municipality {
                Name = "Oslo", MailDomain = "oslo.kommune.no", ShieldFileName = "404.png"
            },
                new Municipality {
                Name = "Trondheim", MailDomain = "trondheim.kommune.no", ShieldFileName = "404.png"
            },
                new Municipality {
                Name = "Asker", MailDomain = "asker.kommune.no", ShieldFileName = "404.png"
            }
            );


            builder.Entity <User>().ToTable("Users");
            builder.Entity <User>().HasKey(p => p.Mail);
            builder.Entity <User>().Property(p => p.Password).IsRequired();
            builder.Entity <User>().Property(p => p.PasswordSalt).IsRequired();
            builder.Entity <User>().HasOne(p => p.Municipality);

            builder.Entity <Backend>().ToTable("Backends");
            builder.Entity <Backend>().HasKey(p => p.Name);
            builder.Entity <Backend>().Property(p => p.Description).IsRequired();
            builder.Entity <Backend>().Property(p => p.Url).IsRequired();

            builder.Entity <Backend>().HasData(
                new Backend {
                Name = "Django", Description = "Just django", Url = "https://www.django-rest-framework.org/"
            },
                new Backend {
                Name = "CKAN", Description = "CKAN is an open source data portal software", Url = "https://ckan.org/"
            }
                );

            builder.Entity <DataFormat>().ToTable("DataFormats");
            builder.Entity <DataFormat>().HasKey(p => p.MimeType);
            builder.Entity <DataFormat>().Property(p => p.Name).IsRequired();
            builder.Entity <DataFormat>().Property(p => p.Description).IsRequired();
            builder.Entity <DataFormat>().Property(p => p.DocumentationUrl);

            builder.Entity <DataFormat>().HasData(
                new DataFormat {
                Name = "json", MimeType = "application/json", Description = "Just json", DocumentationUrl = "https://www.json.org/json-en.html"
            },
                new DataFormat {
                Name = "csv", MimeType = "text/csv", Description = "Comma seperated values", DocumentationUrl = "https://tools.ietf.org/html/rfc4180"
            },
                new DataFormat {
                Name = "xml", MimeType = "application/xml", Description = "Extensible markup language", DocumentationUrl = "https://www.w3.org/XML/"
            },
                new DataFormat {
                Name = "yaml", MimeType = "application/x.yaml", Description = "Yet Another Markup Language: a human-readable approach to serializable data", DocumentationUrl = "https://yaml.org/"
            },
                new DataFormat {
                Name = "js", MimeType = "application/javascript", Description = "Javascript", DocumentationUrl = "https://developer.mozilla.org/en-US/docs/Web/JavaScript"
            },
                new DataFormat {
                Name = "rdf", MimeType = "application/rdf+xml", Description = "Resource Description Framework: A syntax for expressing metadata in xml", DocumentationUrl = "https://www.w3.org/TR/rdf-syntax-grammar/"
            },
                new DataFormat {
                Name = "xlsx", MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Description = ".xlsx Excel spreadsheet", DocumentationUrl = "https://www.office.com/"
            },
                new DataFormat {
                Name = "xml", MimeType = "text/xml", Description = "Extensible markup language", DocumentationUrl = "https://www.w3.org/XML/"
            },
                new DataFormat {
                Name = "jsonld", MimeType = "application/ld+json", Description = "JSON for linking data", DocumentationUrl = "https://json-ld.org/"
            },
                new DataFormat {
                Name = "wms", MimeType = "application/x.wms", Description = "Web Map Service", DocumentationUrl = ""
            },
                new DataFormat {
                Name = "ualf", MimeType = "application/x.ualf", Description = "File format for describing lightening events", DocumentationUrl = "https://github.com/Gipphe/ualf"
            },
                new DataFormat {
                Name = "zip", MimeType = "application/zip", Description = "Zip file format", DocumentationUrl = "https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"
            },
                new DataFormat {
                Name = "pdf", MimeType = "application/pdf", Description = "Portable document format", DocumentationUrl = "https://acrobat.adobe.com/us/en/acrobat/about-adobe-pdf.html"
            },
                new DataFormat {
                Name = "xls", MimeType = "application/vnd.sealed-xls", Description = "Compressed Microsoft Excel spreadsheet", DocumentationUrl = "https://www.office.com/"
            },
                new DataFormat {
                Name = "sosi", MimeType = "application/x-­ogc-sosi", Description = "Norwegian file format for map data: Samordnet Opplegg for Stedfestet Informasjon", DocumentationUrl = "https://www.kartverket.no/data/sosi-brukerveiledning/"
            },
                new DataFormat {
                Name = "sql", MimeType = "application/sql", Description = "SQL dump", DocumentationUrl = ""
            },
                new DataFormat {
                Name = "html", MimeType = "text/html", Description = "Hypertext Markup Language", DocumentationUrl = "https://www.w3.org/TR/html51/"
            },
                new DataFormat {
                Name = "geojson", MimeType = "application/vnd.geo+json", Description = "GeoJSON", DocumentationUrl = "https://geojson.org/"
            },
                new DataFormat {
                Name = "gml", MimeType = "application/gml+xml", Description = "Geography Markup Language", DocumentationUrl = "https://www.iana.org/assignments/media-types/application/gml+xml"
            },
                new DataFormat {
                Name = "tiff", MimeType = "image/tiff", Description = "Tagged Image File Format", DocumentationUrl = "http://www.libtiff.org/document.html"
            },
                new DataFormat {
                Name = "wfs", MimeType = "application/x.wfs", Description = "Web Feature Service", DocumentationUrl = "https://www.ogc.org/standards/wfs"
            },
                new DataFormat {
                Name = "N-Triples", MimeType = "application/n-triples", Description = "A line-based syntax for an RDF graph", DocumentationUrl = "https://www.w3.org/TR/n-triples/"
            },
                new DataFormat {
                Name = "kml", MimeType = "application/vnd.google-earth.kml+xml", Description = "Keyhole Markup Language: A file format used to display geographic data in an Earth browser such as Google Earth", DocumentationUrl = "https://developers.google.com/kml/documentation/kml_tut"
            },
                new DataFormat {
                Name = "Terse RDF Triple Language", MimeType = "text/turtle", Description = "A syntax and file format for expressing data in the Resource Description Framework (RDF) data model", DocumentationUrl = "https://www.w3.org/TR/turtle/"
            },
                new DataFormat {
                Name = "ods", MimeType = "application/vnd.oasis.opendocument.spreadsheet", Description = "OpenDocument spreadsheet, mainly used in OpenOffice, but also supported by the Microsoft Office suite.", DocumentationUrl = "https://www.iso.org/standard/43485.html"
            },
                new DataFormat {
                Name = "txt", MimeType = "text/plain", Description = "Plain text", DocumentationUrl = ""
            },
                new DataFormat {
                Name = "gtfs", MimeType = "application/x.gtfs", Description = "General Transit Feed Specification", DocumentationUrl = "http://gtfs.org"
            },
                new DataFormat {
                Name = "netex", MimeType = "application/x.netex", Description = "Network Timetable Exchange", DocumentationUrl = "http://netex-cen.eu/"
            },
                new DataFormat {
                Name = "gpx", MimeType = "application/gpx+xml", Description = "GPS exchange format", DocumentationUrl = "https://www.topografix.com/gpx.asp"
            }
                );

            builder.Entity <MetadataCategory>().ToTable("MetadataCategory");
            builder.Entity <MetadataCategory>().HasKey(c => c.Uuid);
            builder.Entity <MetadataCategory>().Property(c => c.Name).IsRequired();
            builder.Entity <MetadataCategory>().Property(c => c.HasChildren).IsRequired();
            builder.Entity <MetadataCategory>()
            .HasMany(c => c.Children)
            .WithOne(c => c.Parent)
            .HasForeignKey(c => c.ParentUuid);
            builder.Entity <MetadataCategory>()
            .HasMany(c => c.Types)
            .WithOne(c => c.Category)
            .HasForeignKey(c => c.CategoryUuid);

            //Build some tree structure we can play around with
            var travel = new MetadataCategory {
                Uuid = Guid.NewGuid(), Name = "Travel", HasChildren = true
            };
            var cars = new MetadataCategory {
                Uuid = Guid.NewGuid(), Name = "Cars", ParentUuid = travel.Uuid
            };
            var bike = new MetadataCategory {
                Uuid = Guid.NewGuid(), Name = "Bikes", ParentUuid = travel.Uuid
            };
            var population = new MetadataCategory {
                Uuid = Guid.NewGuid(), Name = "Population"
            };
            var govtProp = new MetadataCategory {
                Uuid = Guid.NewGuid(), Name = "Government property", HasChildren = true
            };
            var powerConsumption = new MetadataCategory {
                Uuid = Guid.NewGuid(), Name = "Power consumption", ParentUuid = govtProp.Uuid
            };

            var health = new MetadataCategory {
                Uuid = Guid.NewGuid(), Name = "Health & wellbeing"
            };

            var organization = new MetadataCategory {
                Uuid = Guid.NewGuid(), Name = "Organization and cooperation"
            };

            builder.Entity <MetadataCategory>().HasData(
                travel, cars, bike, govtProp, population, powerConsumption,
                health, organization
                );

            builder.Entity <MetadataType>().ToTable("MetadataTypes");
            builder.Entity <MetadataType>().HasKey(p => p.Uuid);
            builder.Entity <MetadataType>().Property(nameof(MetadataType.Name)).IsRequired();
            //builder.Entity<MetadataType>().Property(nameof(MetadataType.Description)).IsRequired();
            builder.Entity <MetadataType>().HasMany(p => p.MetadataList).WithOne(p => p.Type).HasForeignKey(p => p.MetadataTypeUuid).IsRequired();

            builder.Entity <MetadataTypeDescription>().ToTable("MetadataTypeDescription");
            builder.Entity <MetadataTypeDescription>().HasKey(d => d.Uuid);
            builder.Entity <MetadataTypeDescription>().Property(d => d.Content).IsRequired();
            builder.Entity <MetadataTypeDescription>().Property(d => d.AuthorMail).IsRequired();
            builder.Entity <MetadataTypeDescription>().Property(d => d.MetadataTypeUuid).IsRequired();

            builder.Entity <MetadataTypeDescriptionVote>().ToTable("MetadataTypeDescriptionVote");
            builder.Entity <MetadataTypeDescriptionVote>().HasKey(p => new { p.UserMail, p.MetadataTypeDescriptionUuid });
            builder.Entity <MetadataTypeDescriptionVote>().Property(v => v.MetadataTypeDescriptionUuid).IsRequired();
            builder.Entity <MetadataTypeDescriptionVote>().Property(v => v.UserMail).IsRequired();


            //Define metadata types
            var type_cycle = new MetadataType {
                Uuid = Guid.NewGuid(), Name = "Cycle history", CategoryUuid = bike.Uuid
            };
            var type_cycle_theft = new MetadataType {
                Uuid = Guid.NewGuid(), Name = "Cycle theft", CategoryUuid = bike.Uuid
            };
            var type_population = new MetadataType {
                Uuid = Guid.NewGuid(), Name = "Populasjon", CategoryUuid = population.Uuid
            };
            var type_kindergarden = new MetadataType {
                Uuid = Guid.NewGuid(), Name = "Kindergarden statistics", CategoryUuid = health.Uuid
            };
            var type_corona = new MetadataType {
                Uuid = Guid.NewGuid(), Name = "Corona virus cases", CategoryUuid = health.Uuid
            };
            var type_car = new MetadataType {
                Uuid = Guid.NewGuid(), Name = "Car history", CategoryUuid = cars.Uuid
            };

            builder.Entity <MetadataType>().HasData(
                type_cycle, type_cycle_theft, type_population, type_kindergarden, type_corona, type_car
                );

            builder.Entity <DataSource>().ToTable("DataSource");
            builder.Entity <DataSource>().HasKey(d => d.Uuid);
            builder.Entity <DataSource>().HasOne(d => d.DataFormat);
            builder.Entity <DataSource>().HasOne(d => d.Metadata);

            builder.Entity <Metadata>().ToTable("Metadata");
            builder.Entity <Metadata>().HasKey(p => p.Uuid);
            builder.Entity <Metadata>().Property(p => p.Description).IsRequired();
            builder.Entity <Metadata>().Property(p => p.ReleaseState).IsRequired();
            builder.Entity <Metadata>().HasMany(p => p.DataSource).WithOne(d => d.Metadata).HasForeignKey(d => d.MetadataUuid);

            builder.Entity <MetadataExperiencePostMapping>().ToTable("MetadataExperiencePostMapping");
            builder.Entity <MetadataExperiencePostMapping>().HasKey(p => new { p.ExperiencePostUuid, p.MetadataUuid });
            builder.Entity <MetadataExperiencePostMapping>().HasOne(m => m.Metadata).WithMany(e => e.ExperiencePosts).HasForeignKey(m => m.MetadataUuid);
            builder.Entity <MetadataExperiencePostMapping>().HasOne(p => p.ExperiencePost).WithMany().HasForeignKey(p => p.ExperiencePostUuid);

            builder.Entity <Metadata>().HasData(
                new Metadata {
                Uuid             = Guid.NewGuid(),
                Description      = "Pling Plong", ReleaseState = EReleaseState.Released, MunicipalityName = "Trondheim",
                MetadataTypeUuid = type_cycle.Uuid
            },
                new Metadata {
                Uuid             = Guid.NewGuid(),
                Description      = "We have a lot of bikes", ReleaseState = EReleaseState.Yellow, MunicipalityName = "Oslo",
                MetadataTypeUuid = type_cycle.Uuid
            },

                new Metadata {
                Uuid             = Guid.NewGuid(),
                Description      = "Cycle theft for Trondheim. Contains city bike theft", ReleaseState = EReleaseState.Green, MunicipalityName = "Trondheim",
                MetadataTypeUuid = type_cycle_theft.Uuid
            },
                new Metadata {
                Uuid             = Guid.NewGuid(),
                Description      = "We have a lot of bikes. Some get stolen. Not the city bikes though.", ReleaseState = EReleaseState.Released, MunicipalityName = "Oslo",
                MetadataTypeUuid = type_cycle_theft.Uuid
            },

                new Metadata {
                Uuid             = Guid.NewGuid(),
                Description      = "", ReleaseState = EReleaseState.Released, MunicipalityName = "Trondheim",
                MetadataTypeUuid = type_population.Uuid
            },
                new Metadata {
                Uuid             = Guid.NewGuid(),
                Description      = "", ReleaseState = EReleaseState.Green, MunicipalityName = "Oslo",
                MetadataTypeUuid = type_population.Uuid
            },
                new Metadata {
                Uuid             = Guid.NewGuid(),
                Description      = "", ReleaseState = EReleaseState.Red, MunicipalityName = "Bodø",
                MetadataTypeUuid = type_population.Uuid
            },
                new Metadata {
                Uuid             = Guid.NewGuid(),
                Description      = "", ReleaseState = EReleaseState.Released, MunicipalityName = "Test",
                MetadataTypeUuid = type_population.Uuid
            }
                );

            builder.Entity <Comment>().ToTable("Comment");
            builder.Entity <Comment>().HasKey(c => c.Uuid);
            builder.Entity <Comment>().Property(c => c.Content).IsRequired();
            builder.Entity <Comment>().Property(c => c.UserMail).IsRequired();
            builder.Entity <Comment>().Property(c => c.Published).IsRequired();
            builder.Entity <Comment>().Property(c => c.Edited).IsRequired();
            builder.Entity <Comment>().Property(c => c.HasChildren).IsRequired();
            builder.Entity <Comment>()
            .HasMany(c => c.ChildComments)
            .WithOne(c => c.ParentComment)
            .HasForeignKey(c => c.ParentCommentUuid);


            builder.Entity <MetadataCommentMapping>().HasKey(p => new { p.MetadataUuid, p.CommentUuid });
            builder.Entity <MetadataCommentMapping>()
            .HasOne(m => m.Metadata)
            .WithMany(m => m.Comments)
            .HasForeignKey(m => m.MetadataUuid);
            builder.Entity <ExperiencePostCommentMapping>().HasKey(p => new { p.ExperiencePostUuid, p.CommentUuid });
            builder.Entity <ExperiencePostCommentMapping>()
            .HasOne(m => m.ExperiencePost)
            .WithMany(e => e.Comments)
            .HasForeignKey(m => m.ExperiencePostUuid);


            builder.Entity <Tag>().ToTable("Tags");
            builder.Entity <Tag>().HasKey(p => p.Name);

            builder.Entity <Tag>().HasData(
                new Tag {
                Name = "Public activity"
            },
                new Tag {
                Name = "Public property"
            },
                new Tag {
                Name = "Traffic"
            }
                );

            builder.Entity <MetadataTypeTagMapping>().ToTable("MetadataTypeTagMapping");
            builder.Entity <MetadataTypeTagMapping>().HasKey(p => new { p.TagName, p.MetadataTypeUuid });
            builder.Entity <MetadataTypeTagMapping>().HasOne(p => p.Type).WithMany(p => p.Tags).HasForeignKey(p => p.MetadataTypeUuid);
            builder.Entity <MetadataTypeTagMapping>().HasOne(p => p.Tag).WithMany().HasForeignKey(p => p.TagName);

            builder.Entity <Like>().ToTable("Likes");
            builder.Entity <Like>().HasKey(p => new { p.LikeUserEmail, p.MetadataUuid });
            builder.Entity <Like>().HasOne(p => p.LikeUser).WithMany().HasForeignKey(p => p.LikeUserEmail);
            builder.Entity <Like>().HasOne(p => p.Metadata).WithMany(p => p.Likes).HasForeignKey(p => p.MetadataUuid);

            builder.Entity <MetadataTypeTagMapping>().HasData(
                new MetadataTypeTagMapping {
                TagName = "Public activity", MetadataTypeUuid = type_cycle.Uuid
            },
                new MetadataTypeTagMapping {
                TagName = "Public activity", MetadataTypeUuid = type_car.Uuid
            },
                new MetadataTypeTagMapping {
                TagName = "Traffic", MetadataTypeUuid = type_car.Uuid
            }
                );

            builder.Entity <ExperiencePost>().ToTable("ExperiencePost");
            builder.Entity <ExperiencePost>().HasKey(p => p.Uuid);
            builder.Entity <ExperiencePost>().Property(p => p.Contents).IsRequired();
            builder.Entity <ExperiencePost>().HasOne(p => p.LastEditedBy);
            builder.Entity <ExperiencePost>().Property(p => p.Created).IsRequired();
            builder.Entity <ExperiencePost>().Property(p => p.Modified).IsRequired();

            builder.Entity <ExperiencePostTagMapping>().ToTable("ExperiencePostTagMapping");
            builder.Entity <ExperiencePostTagMapping>().HasKey(p => new { p.TagName, p.ExperiencePostUuid });
            builder.Entity <ExperiencePostTagMapping>().HasOne(p => p.Post).WithMany(p => p.Tags).HasForeignKey(p => p.ExperiencePostUuid);
            builder.Entity <ExperiencePostTagMapping>().HasOne(p => p.Tag).WithMany().HasForeignKey(p => p.TagName);
        }
        public void MarqueeBrowse(MetadataCategory category, string name, object icon)
        {
            if (name == null)
                throw new ArgumentNullException("name");

            try
            {
                var view = taskController.GetMarqueeView(category);
                var description = string.Format("Browse: {0}", name);

                Action workFunction = () => view.RefreshItems();
                var taskViewModel = new SimpleTaskViewModel(logger, workFunction, name, description, icon);

                var tabItem = new TabItem();

                //TextBlock header = new TextBlock();
                //header.Inlines.Add(name);
                //header.ToolTip = description;
                tabItem.Header = new TaskHeader(logger, taskViewModel);

                tabItem.Content = view;
                resultControl.Items.Add(tabItem);
                tabItem.IsSelected = true;

                AddViewModel(taskViewModel, tabItem);

                if (taskViewModel.Status == TaskStatus.Ready)
                {
                    taskViewModel.Start();
                }
            }
            catch (Exception ex)
            {
                logger.Error("  TaskResultView.MarqueeBrowse", ex);
            }
        }
Exemplo n.º 32
0
 public async Task AddAsync(MetadataCategory category)
 {
     await _context.MetadataCategory.AddAsync(category);
 }