コード例 #1
0
ファイル: NewDataTypeAction.cs プロジェクト: basp/calico
        public void Execute(NewDataTypeArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);
                    var cmd  = new NewDataTypeCommand(repo);
                    var req  = Mapper.Map <NewDataTypeRequest>(args);
                    var res  = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Created data type {DataTypeName} with id {DataTypeId}",
                            x.DataType.Name,
                            x.DataType.Id);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Could not create data type {DataTypeName}",
                            req.Name);
                    });
                }
        }
コード例 #2
0
ファイル: NewStyleAction.cs プロジェクト: basp/calico
        public void Execute(NewStyleArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);
                    var cmd  = new NewStyleCommand(repo);
                    var req  = Mapper.Map <NewStyleRequest>(args);
                    var res  = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Created style {StyleName} with id {StyleId}",
                            x.Style.Name,
                            x.Style.Id);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Failed to create style {StyleName}",
                            args.Name);
                    });
                }
        }
コード例 #3
0
        public void Execute(ImportAttributeValuesArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo     = new SqlRepository(session);
                    var provider = new ShapefileFeatureCollectionProvider(args.PathToShapefile);
                    var cmd      = new ImportAttributeValuesCommand(repo, provider.Get);
                    var req      = Mapper.Map <ImportAttributeValuesRequest>(args);
                    var res      = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Imported {RowCount} values from {Shapefile} into data set {DataSetId}",
                            x.RowCount,
                            args.PathToShapefile,
                            args.DataSetId);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Failed to import attribute values from {Shapefile}",
                            args.PathToShapefile);
                    });
                }
        }
コード例 #4
0
ファイル: ScanShapefileAction.cs プロジェクト: basp/calico
        public void Execute(ScanShapefileArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo     = new SqlRepository(session);
                    var provider = new ShapefileFeatureCollectionProvider(args.PathToShapefile);
                    var cmd      = new ScanShapefileCommand(repo, provider.Get);
                    var req      = Mapper.Map <ScanShapefileRequest>(args);
                    var res      = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        var json = JsonConvert.SerializeObject(x);
                        Console.WriteLine(json);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(x, "Could not scan shapefile {Shapefile}", req.PathToShapefile);
                    });
                }
        }
コード例 #5
0
        public void Execute(NewDataSetArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);
                    var cmd  = new NewDataSetCommand(repo);
                    var req  = Mapper.Map <NewDataSetRequest>(args);
                    var res  = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Created data set {DataSetName} with id {DataSetId}",
                            x.DataSet.Name,
                            x.DataSet.Id);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Failed to create data set {DataSetName} for plot {PlotId}",
                            req.Name,
                            req.PlotId);
                    });
                }
        }
コード例 #6
0
ファイル: Global.asax.cs プロジェクト: basp/calico
        private static Container InitializeContainer()
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            container.Register(
                () => new CalicoSchema(
                    x => (GraphType)container.GetInstance(x)),
                Lifestyle.Scoped);

            container.Register <ISession>(
                () => SqlSession.Open(new SqlConnection(ConnectionString)),
                Lifestyle.Scoped);

            container.Register <IRepository>(
                () => new SqlRepository(container.GetInstance <ISession>()),
                Lifestyle.Scoped);

            container.Register <Attribute>(Lifestyle.Scoped);
            container.Register <AttributeValue>(Lifestyle.Scoped);
            container.Register <Tenant>(Lifestyle.Scoped);
            container.Register <DataSet>(Lifestyle.Scoped);
            container.Register <DataType>(Lifestyle.Scoped);
            container.Register <Feature>(Lifestyle.Scoped);
            container.Register <FeatureType>(Lifestyle.Scoped);
            container.Register <Plot>(Lifestyle.Scoped);

            container.RegisterWebApiControllers(
                GlobalConfiguration.Configuration);

            return(container);
        }
コード例 #7
0
        public void Execute(GetStylesArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);
                    var cmd  = new GetStylesCommand(repo);
                    var req  = Mapper.Map <GetStylesRequest>(args);
                    var res  = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        var json = JsonConvert.SerializeObject(x.Styles);
                        Console.WriteLine(json);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Could not get styles for feature type {FeatureTypeId}",
                            args.FeatureTypeId);
                    });
                }
        }
コード例 #8
0
        public void Execute(DeleteFeatureTypeArgs args)
        {
            using (var conn = this.connectionFactory())
            {
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);
                    var cmd  = new DeleteFeatureTypeCommand(repo);
                    var req  = Mapper.Map <DeleteFeatureTypeRequest>(args);
                    var res  = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Deleted feature type {FeatureTypeName} with id {FeatureTypeId}",
                            x.FeatureType.Name,
                            x.FeatureType.Id);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Failed to delete feature type {FeatureTypeId}",
                            req.Id);
                    });
                }
            }
        }
コード例 #9
0
        public void Execute(GetDataSetArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);
                    var cmd  = new GetDataSetCommand(repo);
                    var req  = Mapper.Map <GetDataSetRequest>(args);
                    var res  = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        var obj = x.GetFeatureCollection().ToGeoJsonObject();
                        Console.WriteLine(JsonConvert.SerializeObject(obj));
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Could not get data set with id {DataSetId}",
                            req.DataSetId);
                    });
                }
        }
コード例 #10
0
        public void Execute(ImportFeatureTypeArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo     = new SqlRepository(session);
                    var provider = new ShapefileFeatureCollectionProvider(args.PathToShapefile);
                    var cmd      = new ImportFeatureTypeCommand(repo, provider.Get);
                    var req      = Mapper.Map <ImportFeatureTypeRequest>(args);
                    var res      = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Imported feature type {FeatureTypeName} ({FeatureTypeId}) for tenant {TenantName} ({TenantId})",
                            x.FeatureType.Name,
                            x.FeatureType.Id,
                            x.Tenant.Name,
                            x.Tenant.Id);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Failed to import feature type from shapefile {Shapefile}",
                            args.PathToShapefile);
                    });
                }
        }
コード例 #11
0
        public void Execute(GetDataSetsArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);
                    var cmd  = new GetDataSetsCommand(repo);
                    var req  = Mapper.Map <GetDataSetsRequest>(args);
                    var res  = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        var json = JsonConvert.SerializeObject(x.DataSets);
                        Console.WriteLine(json);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Could not get data sets for plot {PlotId}",
                            req.PlotId);
                    });
                }
        }
コード例 #12
0
ファイル: ImportFeaturesAction.cs プロジェクト: basp/calico
        public void Execute(ImportFeaturesArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo     = new SqlRepository(session);
                    var provider = new ShapefileFeatureCollectionProvider(args.PathToShapefile);
                    var cmd      = new ImportFeaturesCommand(repo, provider.Get);
                    var req      = Mapper.Map <ImportFeaturesRequest>(args);
                    var res      = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Imported {FeatureCount} features from {Shapefile}",
                            x.RowCount,
                            args.PathToShapefile);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Could not import features from shapefile {Shapefile}",
                            args.PathToShapefile);
                    });
                }
        }
コード例 #13
0
        public async void Execute(GraphQLArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);

                    this.container.Register <IRepository>(() => repo);
                    this.container.Register <CalicoQuery>();
                    this.container.Register <Graph.Types.Attribute>();
                    this.container.Register <Graph.Types.Tenant>();
                    this.container.Register <Graph.Types.DataSet>();
                    this.container.Register <Graph.Types.DataType>();
                    this.container.Register <Graph.Types.FeatureType>();
                    this.container.Register <Graph.Types.Plot>();

                    var schema = new CalicoSchema(
                        x => (GraphType)this.container.GetInstance(x));

                    var q      = $"query{args.Query}";
                    var result = await new DocumentExecuter().ExecuteAsync(x =>
                    {
                        x.Schema = schema;
                        x.Query  = q;
                    }).ConfigureAwait(false);

                    var json = new DocumentWriter(indent: true).Write(result);
                    Console.WriteLine(json);
                }
        }
コード例 #14
0
        public void Execute(NewPlotArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo     = new SqlRepository(session);
                    var provider = new ShapefileFeatureCollectionProvider(args.PathToShapefile);
                    var cmd      = new NewPlotCommand(repo, provider.Get);
                    var req      = Mapper.Map <NewPlotRequest>(args);
                    var res      = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Created plot {PlotName} with id {PlotId}",
                            x.Plot.Name,
                            x.Plot.Id);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Failed to create plot from shapefile {Shapefile}",
                            args.PathToShapefile);
                    });
                }
        }
コード例 #15
0
        public void Execute(ImportStyleArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo     = new SqlRepository(session);
                    var provider = new ShapefileFeatureCollectionProvider(args.PathToShapefile);
                    var cmd      = new ImportStyleCommand(repo, provider.Get);
                    var req      = Mapper.Map <ImportStyleRequest>(args);
                    var res      = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                    });
                }
        }
コード例 #16
0
ファイル: ImportDataSetAction.cs プロジェクト: basp/calico
        public void Execute(ImportDataSetArgs args)
        {
            args.Name = string.IsNullOrWhiteSpace(args.Name)
                ? Path.GetFileNameWithoutExtension(args.PathToShapefile)
                : args.Name;

            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo     = new SqlRepository(session);
                    var provider = new ShapefileFeatureCollectionProvider(args.PathToShapefile);
                    var cmd      = new ImportDataSetCommand(repo, provider.Get);
                    var req      = Mapper.Map <ImportDataSetRequest>(args);
                    var res      = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        Log.Information(
                            "Imported {DataSetName} ({DataSetId}) for plot {PlotName} ({PlotId})",
                            x.DataSet.Name,
                            x.DataSet.Id,
                            x.Plot.Name,
                            x.Plot.Id);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Failed to import data set from shapefile {Shapefile}",
                            args.PathToShapefile);
                    });
                }
        }
コード例 #17
0
        public void Execute(GetPlotsArgs args)
        {
            using (var conn = this.connectionFactory())
                using (var session = SqlSession.Open(conn))
                {
                    var repo = new SqlRepository(session);
                    var cmd  = new GetPlotsCommand(repo);
                    var req  = Mapper.Map <GetPlotsRequest>(args);
                    var res  = cmd.Execute(req);

                    res.MatchSome(x =>
                    {
                        session.Commit();
                        var plots = x.Plots.Select(y => new
                        {
                            y.Id,
                            y.TenantId,
                            y.Name,
                            Geometry = y.Wkt,
                            y.SRID,
                        });

                        var json = JsonConvert.SerializeObject(plots);
                        Console.WriteLine(json);
                    });

                    res.MatchNone(x =>
                    {
                        session.Rollback();
                        Log.Error(
                            x,
                            "Could not get plots for tenant {TenantId}",
                            args.TenantId);
                    });
                }
        }