コード例 #1
0
ファイル: Service1.svc.cs プロジェクト: tarikkumar7/legacy
        //public void RemoveServiceBlockFromService(Guid ServiceBlockId)
        //{
        //    using (SqlConnection sqlCon = new SqlConnection(ConnectionString))
        //    {
        //        using (SqlCommand sqlCom = new SqlCommand(
        //                    "Delete router.ServiceBlock where id = @ServiceBlockId"
        //                    , sqlCon))
        //        {
        //            sqlCom.Parameters.AddWithValue("@ServiceBlockId", ServiceBlockId);
        //            sqlCom.ExecuteNonQuery();
        //        }
        //    }
        //} 
        #endregion

        #region AddData
        public void SaveServiceBlock(ServiceBlock serviceBlock)
        {
            //1. очищаем БД от старых блоков, вход в сервисный блок  
            //foreach (var block in serviceBlock.blocks)
            RemoveBlockFromServiceBlock(serviceBlock.id);
            
            //2. добавляем 
            foreach (var block in serviceBlock.blocks)
                SaveBlock(block, serviceBlock.id);

            foreach (var block in serviceBlock.blocks)
            // добавляем связи между блоками
            foreach (var link in block.links)
                SaveLink(link, block.blockEntryId);
    
        }
コード例 #2
0
ファイル: Service1.svc.cs プロジェクト: tarikkumar7/legacy
//        List<string> GetServiceExpressions(Guid id)
//        {
//            List<string> result = new List<string>();
//            using (SqlConnection con = new SqlConnection(ConnectionString))
//            {
//                con.Open();
//                using (SqlCommand cmd = new SqlCommand(
//                    @"select expression
//                      from router.RegularExpression
//                      where ServiceId = @ServId", con))
//                {

//                    cmd.Parameters.AddWithValue("@ServId", id);
//                    using (SqlDataReader dr = cmd.ExecuteReader())
//                    {
//                        while (dr.Read())
//                        {
//                            result.Add((string)dr["expression"]);
//                        }
//                    }
//                }
//            }
//            return result;
//        }

        //______________________________________________________________________________________________//

        public ServiceBlock GetServiceBlock(Guid ID, string Name)
        {
            ServiceBlock sBlock = new ServiceBlock();
            sBlock.name = Name; 
            List<Block> blocks = new List<Block>();


            //1. Качаем из БД блоки, входящие в данный сервисный блок (с типом блока)
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand(

                                        #if OldScheme
                                        @"select b.*, bt.Name as blockTypeName from router.Block b
                                            inner join router.BlockType bt on bt.Id = b.BlockTypeId
                                            where ServiceBlockID  = @ServBlockId" 

                                        #else
                                        @"select 
	                                        be.IsVerification, 
                                            be.Id as BlockEntryId,
	                                        bt.Name as BlockTypeName, 
	                                        b.Id,
	                                        b.BlockTypeId,
	                                        b.Name,
	                                        b.Settings
                                        from 
	                                        router.BlockEntry be 
	                                        inner join router.Block b on b.Id = be.BlockId
	                                        inner join router.BlockType bt on bt.Id = b.BlockTypeId
                                        where 
	                                        be.ServiceBlockId = @ServBlockId"
                                            #endif
                                            , con))
                {

                    cmd.Parameters.AddWithValue("@ServBlockId", ID);
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            blocks.Add(
                                new Block
                                {
                                    id = (Guid)dr["id"],
                                    isVerification = (bool)dr["isVerification"],
                                    name = (string)dr["name"],
                                    typeid = (Guid)dr["blockTypeid"],
                                    typename = (string)dr["blockTypeName"],
                                    settingsString = (string)dr["settings"],
                                    blockEntryId = (Guid)dr["BlockEntryId"]
                                });
                        }
                    }
                }
            }

            foreach (Block item in blocks)
            {
                //3. Разбираем XML, запихиваем в класс, проверяем валидность
                item.settings = BaseBlock.GetBlockSettings(item.typename, item.settingsString);
                //4. Качаем из БД ссылки для блоков
                item.links = GetBlockLinks(item.blockEntryId);
            }
            sBlock.blocks = blocks;
            sBlock.id = ID;
            return sBlock;

        }