Example #1
0
        /// <summary>
        /// start a new thread for the related content action
        /// </summary>
        /// <param name="currentUserId">current user id</param>
        /// <param name="ideaId">idea id</param>
        /// <param name="emailType">email notification type</param>
        /// <param name="systemType">system notification type</param>
        /// <param name="actionUserId">action user id</param>
        /// <param name="url">target URL</param>
        /// <param name="processId">process id</param>
        /// <param name="elementId">element id</param>
        /// <param name="reason">text reason</param>
        /// <param name="rank">user rank</param>
        /// <param name="previousRank">user previous rank</param>
        /// <param name="context">HTTP context</param>
        /// <param name="language">current language object</param>
        public static void StartRelatedContentUser(
            int currentUserId,
            int ideaId,
            Domain.Entities.Basic.EmailNotificationType?emailType,
            Domain.Entities.Basic.SystemNotificationType?systemType,
            int?actionUserId,
            string url,
            int?processId,
            int elementId,
            string reason,
            string rank,
            string previousRank,
            HttpContextBase context,
            Domain.Entities.Language language)
        {
            SqlSession session = new SqlSession();
            Thread     thread  = new Thread(() => Business.Utilities.Notification.RelatedContentUser(
                                                currentUserId,
                                                ideaId,
                                                emailType,
                                                systemType,
                                                actionUserId,
                                                url,
                                                processId,
                                                elementId,
                                                reason,
                                                rank,
                                                previousRank,
                                                session,
                                                context,
                                                language));

            thread.Start();
        }
Example #2
0
        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);
                    });
                }
        }
Example #3
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);
                    });
                }
        }
Example #4
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);
                    });
                }
        }
Example #5
0
        /// <summary>
        /// start a new thread for the new process action
        /// </summary>
        /// <param name="frienlyname">friendly name of the process</param>
        /// <param name="contentId">content id</param>
        /// <param name="context">HTTP context</param>
        /// <param name="language">Language object</param>
        public static void StartNewProcess(string frienlyname, int contentId, HttpContextBase context, Domain.Entities.Language language)
        {
            SqlSession session = new SqlSession();
            Thread     thread  = new Thread(() => Business.Utilities.Notification.NewProcess(frienlyname, contentId, session, context, language));

            thread.Start();
        }
Example #6
0
        private static IDbTable MockIdentityOutputTable(Model model, SqlSession sqlSession, IList <SqlCommand> commands)
        {
            var identity = model.GetIdentity(false);

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

            var column = identity.Column;

            if (column is _Int32)
            {
                return(sqlSession.MockTempTable <Int32IdentityOutput>(commands));
            }
            else if (column is _Int64)
            {
                return(sqlSession.MockTempTable <Int64IdentityOutput>(commands));
            }
            else if (column is _Int16)
            {
                return(sqlSession.MockTempTable <Int16IdentityOutput>(commands));
            }
            else
            {
                return(null);
            }
        }
Example #7
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);
                    });
                }
        }
        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);
                    });
                }
        }
Example #9
0
        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);
                    });
                }
        }
Example #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);
                    });
                }
        }
Example #11
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);
                    });
                }
            }
        }
Example #12
0
        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);
                    });
                }
        }
Example #13
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);
                    });
                }
        }
Example #14
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);
                }
        }
Example #15
0
        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);
        }
Example #16
0
        /// <summary>
        /// 获得SQLSession实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public SqlSession <T> GetSqlExpression <T>() where T : class
        {
            var temp = new SqlSession <T>();

            conn = new MySqlConnection(connectionString);
            return(temp);
        }
Example #17
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);
                    });
                }
        }
Example #18
0
 public DbSqlSession(DbSqlSessionFactory dbSqlSessionFactory, Connection connection, string catalog, string schema)
 {
     this.dbSqlSessionFactory = dbSqlSessionFactory;
     this.sqlSession          = dbSqlSessionFactory.SqlSessionFactory.openSession(connection);
     this.connectionMetadataDefaultCatalog = catalog;
     this.connectionMetadataDefaultSchema  = schema;
 }
Example #19
0
        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);
                    });
                }
        }
Example #20
0
        internal static DbTable <T> MockTempTable <T>(this SqlSession sqlSession, IList <SqlCommand> commands, T fromModel = null, Action <T> initializer = null)
            where T : Model, new()
        {
            var result = sqlSession.MockTempTable <T>(fromModel, initializer);

            commands.Add(sqlSession.GetCreateTableCommand(result.Model, true));
            return(result);
        }
        public void CreateLeasingSessionForConnectionString()
        {
            var session = new SqlSession(new SqlConnection(ConnectionStrings.AlenosoftTestDb));

            Assert.False(session.OwnsConnection);
            Assert.True(session.ConnectionState == ConnectionState.Closed);
            Assert.Throws<InvalidOperationException>(() => session.OpenConnectionAsync().GetAwaiter().GetResult());
            Assert.True(session.ConnectionState == ConnectionState.Closed);
        }
Example #22
0
        public ClientOutboxPersisterV2TestsFixture()
        {
            Now             = DateTime.UtcNow;
            DateTimeService = new Mock <IDateTimeService>();
            Settings        = new Mock <ReadOnlySettings>();
            Connection      = new Mock <DbConnection>();
            Transaction     = new Mock <DbTransaction> {
                CallBase = true
            };
            Command    = new Mock <DbCommand>();
            Parameters = new Mock <DbParameterCollection>();
            ClientOutboxTransaction = new SqlClientOutboxTransaction(Connection.Object, Transaction.Object);
            EndpointName            = "SFA.DAS.NServiceBus";

            Events = new List <object>
            {
                new FooEvent(Now.AddDays(-1)),
                new BarEvent(Now)
            };

            TransportOperations     = Events.Select(e => new TransportOperation(Guid.NewGuid(), e)).ToList();
            TransportOperationsData = JsonConvert.SerializeObject(TransportOperations, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });
            ClientOutboxMessage        = new ClientOutboxMessageV2(GuidComb.NewGuidComb(), EndpointName, TransportOperations);
            SynchronizedStorageSession = new Mock <SynchronizedStorageSession>();
            SqlSession              = SynchronizedStorageSession.As <ISqlStorageSession>();
            OutboxMessages          = new List <IClientOutboxMessageAwaitingDispatch>();
            CancellationTokenSource = new CancellationTokenSource();
            CancellationToken       = CancellationTokenSource.Token;

            DateTimeService.Setup(d => d.UtcNow).Returns(Now);
            Parameters.Setup(p => p.Add(It.IsAny <DbParameter>()));
            Command.SetupSet(c => c.CommandText = It.IsAny <string>());
            Command.SetupSet(c => c.Transaction = It.IsAny <DbTransaction>());

            Command.Protected().Setup <DbParameter>("CreateDbParameter").Returns(() =>
            {
                var parameter = new Mock <DbParameter> {
                    CallBase = true
                };

                parameter.SetupProperty(p => p.ParameterName);
                parameter.SetupProperty(p => p.Value);

                return(parameter.Object);
            });

            Command.Protected().Setup <DbParameterCollection>("DbParameterCollection").Returns(Parameters.Object);
            Connection.Protected().Setup <DbTransaction>("BeginDbTransaction", IsolationLevel.Unspecified).Returns(Transaction.Object);
            Connection.Protected().Setup <DbCommand>("CreateDbCommand").Returns(Command.Object);
            Settings.Setup(s => s.Get <Func <DbConnection> >("SqlPersistence.ConnectionBuilder")).Returns(() => Connection.Object);
            SqlSession.Setup(s => s.Connection).Returns(Connection.Object);
            SqlSession.Setup(s => s.Transaction).Returns(Transaction.Object);

            ClientOutboxStorage = new ClientOutboxPersisterV2(DateTimeService.Object, Settings.Object);
        }
        public void CreateOwningSessionForConnectionString()
        {
            var session = new SqlSession(ConnectionStrings.AlenosoftTestDb);

            Assert.True(session.OwnsConnection);
            Assert.True(session.ConnectionState == ConnectionState.Closed);

            using (session.OpenConnectionAsync().GetAwaiter().GetResult())
            {
                Assert.True(session.ConnectionState == ConnectionState.Open);
            }

            Assert.True(session.ConnectionState == ConnectionState.Closed);
        }
        public void OpenConnection()
        {
            var session = new SqlSession(ConnectionStrings.AlenosoftTestDb);

            using (session.OpenConnectionAsync().GetAwaiter().GetResult())
            {
                Assert.Equal(ConnectionState.Open, session.ConnectionState);
                var date = (DateTime)session.ExecuteScalarAsync(new SqlCommand(@"SELECT CONVERT(DATETIME, '01-01-3000', 105)")).GetAwaiter().GetResult();
                Assert.Equal(date, new DateTime(3000, 01, 01));
                Assert.Equal(ConnectionState.Open, session.ConnectionState);
            }

            Assert.Equal(ConnectionState.Closed, session.ConnectionState);
        }
        /// <summary>
        /// 获取列表,适用于联表查询
        /// </summary>
        /// <typeparam name="Target">DTO类型</typeparam>
        /// <typeparam name="T">exp代表的Entity类型</typeparam>
        /// <param name="exp">ISqlSession实例</param>
        /// <returns>DTO列表</returns>
        public List <Target> GetList <Target, T>(SqlSession <T> exp) where T : class where Target : class
        {
            var dataTable = GetDataBySql <T>(exp.SqlExpression);
            var result    = new List <Target>();

            foreach (DataRow i in dataTable.Rows)
            {
                var obj = Activator.CreateInstance <Target>();
                foreach (var k in EntityHelper.GetDtoFields <Target>())
                {
                    SetValue(ref obj, i[k], k);
                }
                result.Add(obj);
            }
            return(result);
        }
Example #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testTransactionIsolationLevelOnConnection()
        public virtual void testTransactionIsolationLevelOnConnection()
        {
            ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl)processEngine.ProcessEngineConfiguration;
            SqlSession sqlSession = processEngineConfiguration.DbSqlSessionFactory.SqlSessionFactory.openSession();

            try
            {
                int transactionIsolation = sqlSession.Connection.TransactionIsolation;
                assertEquals("TransactionIsolationLevel for connection is " + transactionIsolation + " instead of " + Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_READ_COMMITTED, transactionIsolation);
            }
            catch (SQLException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
        /// <summary>
        /// 获取列表,适用于单表查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="exp"></param>
        /// <returns></returns>
        public List <T> GetList <T>(SqlSession <T> exp) where T : class
        {
            var dataTable = GetDataBySql <T>(exp.SqlExpression);
            var result    = new List <T>();

            foreach (DataRow i in dataTable.Rows)
            {
                T obj = Activator.CreateInstance <T>();
                foreach (var k in exp.Fields)
                {
                    SetValue(ref obj, i[k], k);
                }
                result.Add(obj);
            }
            return(result);
        }
Example #28
0
                public Void execute(CommandContext commandContext)
                {
                    Connection connection = null;
                    Statement  statement  = null;
                    ResultSet  rs         = null;

                    try
                    {
                        SqlSession sqlSession = commandContext.DbSqlSession.SqlSession;
                        connection = sqlSession.Connection;
                        statement  = connection.createStatement();
                        statement.executeUpdate("INSERT INTO ACT_RU_JOB(ID_, REV_, RETRIES_, TYPE_, EXCLUSIVE_, HANDLER_TYPE_) " + "VALUES (" + "'" + scenarioName + "'," + "1," + "3," + "'timer'," + DbSqlSessionFactory.databaseSpecificTrueConstant[engineConfiguration.DatabaseType] + "," + "'" + TimerStartEventJobHandler.TYPE + "'" + ")");
                        connection.commit();
                        statement.close();
                    }
                    catch (SQLException e)
                    {
                        throw new Exception(e);
                    }
                    finally
                    {
                        try
                        {
                            if (statement != null)
                            {
                                statement.close();
                            }
                            if (rs != null)
                            {
                                rs.close();
                            }
                            if (connection != null)
                            {
                                connection.close();
                            }
                        }
                        catch (SQLException e)
                        {
                            throw new Exception(e);
                        }
                    }
                    return(null);
                }
Example #29
0
        private void NewSqlSession()
        {
            int count = SqlSessions.Count;

            ++count;
            string title = "Query" + count.ToString();

            TabPage page = new TabPage(title);

            //TODO: Configure new SqlSession from Options
            SqlSession editor = new SqlSession(title, string.Empty, ActiveSessionProviderDetails);

            //editor.Font = new System.Drawing.Font()
            //{
            //  Family = "";
            //};

            page.Controls.Add(editor);
            tabControl1.TabPages.Add(page);

            SqlSessions.Add(editor);
        }
Example #30
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();
                    });
                }
        }
Example #31
0
        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);
                    });
                }
        }
Example #32
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);
                    });
                }
        }
Example #33
0
 public DbSqlSession(DbSqlSessionFactory dbSqlSessionFactory)
 {
     this.dbSqlSessionFactory = dbSqlSessionFactory;
     this.sqlSession          = dbSqlSessionFactory.SqlSessionFactory.openSession();
 }
 public SqlSchemaMappingCompiler(string connectionString)
 {
     this.m_session = new SqlSession(connectionString);
 }
Example #35
0
        public void Test()
        {
            var mappingRequest =
                XmlSqlSchemaMappingCompilerInput.FromFile(
                    @"AlenosoftTestDb.schema-mapping-request.xml");

            var mappingResponse = new SqlSchemaMappingCompiler(
                ConnectionStrings.AlenosoftTestDb)
                .CompileAsync(mappingRequest)
                .GetAwaiter()
                .GetResult();

            foreach (var operation in mappingResponse.ExecuteReaderOperations)
            {

            }

            const string spName = "uspParameterlessSimpleSelect";
            const string interfaceName = "IMyResultSet";
            var session = new SqlSession(ConnectionStrings.AlenosoftTestDb);
            var schema =
                session.FillSchema(
                    new SqlCommand($"dbo.{spName}") { CommandType = CommandType.StoredProcedure },
                    new DataSet(),
                    SchemaType.Source).Single();

            var service = new SqlSchemaMappingCompiler(ConnectionStrings.AlenosoftTestDb);
            //var request = new FakeSqlSchemaMappingRequest();
            //var selector = new FakeSqlExecuteReaderStoredProcedureSelector("dbo", spName, "MethodName");

            //var mapping = new FakeResultSetMapping();
            //var resultSetInterface = new FakeResultSetInterface(interfaceName);
            //selector.AddMapping(mapping);

            //foreach (DataColumn column in schema.Columns)
            //{
            //    mapping.AddColumnMapping(
            //        new FakeResultSetColumnMapping
            //            {
            //                InterfaceName = interfaceName,
            //                ColumnName = column.ColumnName,
            //                PropertyName = "My" + column.ColumnName,
            //                PropertyType = column.DataType
            //            });
            //    resultSetInterface.AddProperty("My" + column.ColumnName, column.DataType);
            //}

            //request.StoredProcedureSelectors.Add(selector);
            //request.TableContracts.Add(resultSetInterface);
            //var metadata = service.LoadMetadataAsync(request).GetAwaiter().GetResult();

            //var spInfo = metadata.ExecuteReaderOperations.Single();
            //var resultSetInfo = spInfo.ResultSetInfos.Single();
            //var columnInfos = resultSetInfo.ColumnInfos;
            //Assert.Equal(schema.Columns.Count, columnInfos.Count);
            //var lookup = columnInfos.ToDictionary(ci => ci.ColumnName);
            //foreach (DataColumn column in schema.Columns)
            //{
            //    var info = lookup[column.ColumnName];
            //    Assert.Equal(column.ColumnName, info.ColumnName, StringComparer.OrdinalIgnoreCase);
            //    Assert.Equal(column.Ordinal, info.Ordinal);
            //    Assert.Equal(column.DataType, info.DataType);

            //    var columnMapping = info.RowFieldContracts.Single();
            //    Assert.Equal(column.ColumnName, columnMapping.ColumnName, StringComparer.OrdinalIgnoreCase);
            //    Assert.Equal("My" + column.ColumnName, columnMapping.PropertyName, StringComparer.OrdinalIgnoreCase);
            //    Assert.Equal(column.DataType, columnMapping.PropertyType);
            //    Assert.Equal(interfaceName, columnMapping.InterfaceName);
            //}
        }