コード例 #1
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,Name,Host")] CustomConnection customConnection)
        {
            if (id != customConnection.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customConnection);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomConnectionExists(customConnection.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customConnection));
        }
コード例 #2
0
        public async Task <List <string> > GetSequenceList(CustomConnection customConnection)
        {
            var connectionString = Util.GetConnectionString(customConnection);

            var sequenceList = new List <string>();

            const string sequenceListSql = "select SEQUENCE_NAME from user_sequences order by SEQUENCE_NAME";

            using (var oconn = new OracleConnection(connectionString))
            {
                oconn.Open();
                using (var cmd = new OracleCommand
                {
                    Connection = oconn,
                    CommandText = sequenceListSql,
                    CommandType = CommandType.Text
                })
                {
                    var dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        sequenceList.Add(dr.GetString(0));
                    }
                }
            }

            return(sequenceList);
        }
コード例 #3
0
        public async Task <List <string> > GetTableList(CustomConnection customConnection)
        {
            var connectionString = GetConnectionString(customConnection);

            if (ConnectionTableList.ContainsKey(customConnection.Name))
            {
                return(ConnectionTableList[customConnection.Name]);
            }

            var tableList = new List <string>();

            const string tableListSql = "select TABLE_NAME from user_tables order by TABLE_NAME";

            using (var oconn = new OracleConnection(connectionString))
            {
                oconn.Open();
                using (var cmd = new OracleCommand
                {
                    Connection = oconn,
                    CommandText = tableListSql,
                    CommandType = CommandType.Text
                })
                {
                    var dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        tableList.Add(dr.GetString(0));
                    }
                }
            }

            ConnectionTableList[customConnection.Name] = tableList;

            return(tableList);
        }
コード例 #4
0
        private static List <DataModel.CustomConnectionInfo> BuildCustomConnectionList()
        {
            var list = new List <DataModel.CustomConnectionInfo>();

            var allNodes = new List <Type>();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                var types = assembly.GetTypes()
                            .Where(t => typeof(DataModel.Connection).IsAssignableFrom(t));
                allNodes.AddRange(types);
            }

            foreach (var type in allNodes)
            {
                CustomConnection attr =
                    type.GetCustomAttributes(typeof(CustomConnection), false).FirstOrDefault() as CustomConnection;

                if (attr != null)
                {
                    list.Add(new DataModel.CustomConnectionInfo(type, attr));
                }
            }

            return(list);
        }
コード例 #5
0
        public static string GetConnectionString(CustomConnection connection)
        {
            var host     = connection.Host;
            var port     = connection.Port;
            var SID      = connection.SID;
            var user     = connection.Username;
            var password = connection.Password;

            return($"DATA SOURCE=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = {host})(PORT = {port}))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = {SID})));PERSIST SECURITY INFO=True;USER ID={user};Password={password}");
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Host")] CustomConnection customConnection)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customConnection);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customConnection));
        }
コード例 #7
0
        public void InitiateTransfer(CustomConnection connection)
        {
            var id = new PeerId(new Peer("", connection.Uri), rig.Manager);
            id.Connection = connection;
            byte[] data;

            EncryptorFactory.EndCheckEncryption(
                EncryptorFactory.BeginCheckEncryption(id, 68, null, null, new[] {id.TorrentManager.InfoHash}),
                out data);
            decryptor = id.Decryptor;
            encryptor = id.Encryptor;
            TestHandshake(data, connection);
        }
コード例 #8
0
ファイル: SQL.cs プロジェクト: Lyror/EmployeeManagement
		private void InitialzeConnection(string UdlStringOrFileString)
		{
			ConnectionClass cc = new ConnectionClass();
			if (File.Exists(UdlStringOrFileString))
			{
				Connection = cc.CreateConnection(UdlStringOrFileString, true);
				connectionString = cc.ConnectionString;
			}
			else
			{
				Connection = cc.CreateConnection(UdlStringOrFileString, false);
				connectionString = cc.ConnectionString;
			}
			Connection.Open(cc.ConnectionString);
		}
コード例 #9
0
        public async Task SendMetadataCore(string expectedPath)
        {
            CustomConnection connection = pair.Incoming;

            // 1) Send local handshake. We've already received the remote handshake as part
            // of the Connect method.
            var sendHandshake = new HandshakeMessage(rig.Manager.InfoHash, new string ('g', 20), VersionInfo.ProtocolStringV100, true, true);
            await PeerIO.SendMessageAsync(connection, encryptor, sendHandshake);

            ExtendedHandshakeMessage exHand = new ExtendedHandshakeMessage(false, rig.Torrent.Metadata.Length, 5555);

            exHand.Supports.Add(LTMetadata.Support);
            await PeerIO.SendMessageAsync(connection, encryptor, exHand);

            // 2) Receive the metadata requests from the other peer and fulfill them
            byte[]      buffer = rig.Torrent.Metadata;
            int         length = (buffer.Length + 16383) / 16384;
            PeerMessage m;

            while (length > 0 && (m = await PeerIO.ReceiveMessageAsync(connection, decryptor)) != null)
            {
                if (m is ExtendedHandshakeMessage ex)
                {
                    Assert.AreEqual(192, ex.MaxRequests);
                }
                else if (m is LTMetadata metadata)
                {
                    if (metadata.MetadataMessageType == LTMetadata.eMessageType.Request)
                    {
                        metadata = new LTMetadata(LTMetadata.Support.MessageId, LTMetadata.eMessageType.Data, metadata.Piece, buffer);
                        await PeerIO.SendMessageAsync(connection, encryptor, metadata);

                        length--;
                    }
                }
            }

            // We've sent all the pieces. Now we just wait for the torrentmanager to process them all.
            while (rig.Manager.Mode is MetadataMode)
            {
                System.Threading.Thread.Sleep(10);
            }

            Assert.IsTrue(File.Exists(expectedPath), "#1");
            Torrent torrent = Torrent.Load(expectedPath);

            Assert.AreEqual(rig.Manager.InfoHash, torrent.InfoHash, "#2");
        }
コード例 #10
0
        public void TestHandshake(byte[] buffer, CustomConnection connection)
        {
            // 1) Send local handshake
            SendMessage(
                new HandshakeMessage(rig.Manager.Torrent.infoHash, new string('g', 20), VersionInfo.ProtocolStringV100,
                    true, false), connection);

            // 2) Receive remote handshake
            if (buffer == null || buffer.Length == 0)
            {
                buffer = new byte[68];
                Receive(connection, buffer, 0, 68);
                decryptor.Decrypt(buffer);
            }

            var handshake = new HandshakeMessage();
            handshake.Decode(buffer, 0, buffer.Length);
            Assert.Equal(rig.Engine.PeerId, handshake.PeerId);
            Assert.Equal(VersionInfo.ProtocolStringV100, handshake.ProtocolString);
            Assert.Equal(ClientEngine.SupportsFastPeer, handshake.SupportsFastPeer);
            Assert.Equal(ClientEngine.SupportsExtended, handshake.SupportsExtendedMessaging);

            // 2) Send local bitfield
            SendMessage(new BitfieldMessage(rig.Manager.Bitfield), connection);

            // 3) Receive remote bitfield - have none
            var message = ReceiveMessage(connection);
            Assert.True(message is HaveNoneMessage || message is BitfieldMessage, "HaveNone");

            // 4) Send a few allowed fast
            SendMessage(new AllowedFastMessage(1), connection);
            SendMessage(new AllowedFastMessage(2), connection);
            SendMessage(new AllowedFastMessage(3), connection);
            SendMessage(new AllowedFastMessage(0), connection);

            // 5) Receive a few allowed fast
            ReceiveMessage(connection);
            ReceiveMessage(connection);
            ReceiveMessage(connection);
            ReceiveMessage(connection);
            ReceiveMessage(connection);
            ReceiveMessage(connection);
            ReceiveMessage(connection);
            ReceiveMessage(connection);
            ReceiveMessage(connection);
            ReceiveMessage(connection);
        }
コード例 #11
0
        private static void RegisterYoutrackClient(ContainerBuilder builder)
        {
            var youtrackUrl      = ConfigurationManager.AppSettings["youtrackUrl"];
            var youtrackUser     = ConfigurationManager.AppSettings["youtrackUser"];
            var youtrackPort     = int.Parse(ConfigurationManager.AppSettings["youtrackPort"]);
            var youtrackPassword = ConfigurationManager.AppSettings["youtrackPassword"];

            if (!string.IsNullOrEmpty(youtrackUrl) && !string.IsNullOrEmpty(youtrackUser) &&
                !string.IsNullOrEmpty(youtrackPassword))
            {
                builder.Register(c =>
                {
                    var connection = new CustomConnection(youtrackUrl, youtrackPort, true);
                    connection.Authenticate(youtrackUser, youtrackPassword);
                    return(connection);
                }).As <CustomConnection>();
            }
        }
コード例 #12
0
        public async Task RequestMetadata()
        {
            await Setup(false, "path.torrent");

            CustomConnection connection = pair.Incoming;

            // 1) Send local handshake. We've already received the remote handshake as part
            // of the Connect method.
            var sendHandshake = new HandshakeMessage(rig.Manager.Torrent.InfoHash, new string('g', 20), VersionInfo.ProtocolStringV100, true, true);
            await PeerIO.SendMessageAsync(connection, encryptor, sendHandshake);

            ExtendedHandshakeMessage exHand = new ExtendedHandshakeMessage(false, rig.TorrentDict.LengthInBytes(), 5555);

            exHand.Supports.Add(LTMetadata.Support);
            await PeerIO.SendMessageAsync(connection, encryptor, exHand);

            // 2) Send all our metadata requests
            int length = (rig.TorrentDict.LengthInBytes() + 16383) / 16384;

            for (int i = 0; i < length; i++)
            {
                await PeerIO.SendMessageAsync(connection, encryptor, new LTMetadata(LTMetadata.Support.MessageId, LTMetadata.eMessageType.Request, i, null));
            }
            // 3) Receive all the metadata chunks
            PeerMessage m;
            var         stream = new MemoryStream();

            while (length > 0 && (m = await PeerIO.ReceiveMessageAsync(connection, decryptor)) != null)
            {
                LTMetadata metadata = m as LTMetadata;
                if (metadata != null)
                {
                    if (metadata.MetadataMessageType == LTMetadata.eMessageType.Data)
                    {
                        stream.Write(metadata.MetadataPiece, 0, metadata.MetadataPiece.Length);
                        length--;
                    }
                }
            }

            // 4) Verify the hash is the same.
            stream.Position = 0;
            Assert.AreEqual(rig.Torrent.InfoHash, new InfoHash(new SHA1Managed().ComputeHash(stream)), "#1");
        }
コード例 #13
0
        public ClientForm()
        {
            this.connected       = false;
            this.initializing    = false;
            this.lastServerToken = null;

            // --- UI ---
            InitializeComponent();

            this.connectButton.Click    += connectButton_Click;
            this.disconnectButton.Click += disconnectButton_Click;

            this.encryptButton.Click += encryptButton_Click;
            this.signButton.Click    += signButton_Click;

            this.FormClosing += Form1_FormClosing;

            // --- SSPI ---
            this.cred = new ClientCurrentCredential(PackageNames.Negotiate);

            this.context = new ClientContext(
                cred,
                "",
                ContextAttrib.InitIntegrity |
                ContextAttrib.ReplayDetect |
                ContextAttrib.SequenceDetect |
                ContextAttrib.MutualAuth |
                ContextAttrib.Delegate |
                ContextAttrib.Confidentiality
                );

            this.connection               = new CustomConnection();
            this.connection.Received     += connection_Received;
            this.connection.Disconnected += connection_Disconnected;

            // --- UI Fillout ---
            this.usernameTextbox.Text = this.cred.PrincipleName;

            UpdateButtons();
        }
コード例 #14
0
        internal async Task SendMetadataCore(string expectedPath, PeerMessage sendAfterHandshakeMessage, bool metadataOnly = false)
        {
            CustomConnection connection = pair.Incoming;
            var metadataTcs             = new TaskCompletionSource <byte[]> ();

            rig.Manager.MetadataReceived += (o, e) => metadataTcs.TrySetResult(e);

            // 1) Send local handshake. We've already received the remote handshake as part
            // of the Connect method.
            var sendHandshake = new HandshakeMessage(rig.Manager.InfoHash, new string ('g', 20), VersionInfo.ProtocolStringV100, true, true);
            await PeerIO.SendMessageAsync(connection, encryptor, sendHandshake);

            ExtendedHandshakeMessage exHand = new ExtendedHandshakeMessage(false, rig.Torrent.InfoMetadata.Length, 5555);

            exHand.Supports.Add(LTMetadata.Support);
            await PeerIO.SendMessageAsync(connection, encryptor, exHand);

            await PeerIO.SendMessageAsync(connection, encryptor, sendAfterHandshakeMessage);

            bool receivedHaveNone = false;

            // 2) Receive the metadata requests from the other peer and fulfill them
            byte[]      buffer            = rig.Torrent.InfoMetadata;
            var         unrequestedPieces = new HashSet <int> (Enumerable.Range(0, (buffer.Length + 16383) / 16384));
            PeerMessage m;

            while (unrequestedPieces.Count > 0 && (m = await PeerIO.ReceiveMessageAsync(connection, decryptor)) != null)
            {
                if (m is ExtendedHandshakeMessage ex)
                {
                    Assert.IsNull(ex.MetadataSize);
                    Assert.AreEqual(ClientEngine.DefaultMaxPendingRequests, ex.MaxRequests);
                }
                else if (m is HaveNoneMessage)
                {
                    receivedHaveNone = true;
                }
                else if (m is LTMetadata metadata)
                {
                    if (metadata.MetadataMessageType == LTMetadata.eMessageType.Request)
                    {
                        metadata = new LTMetadata(LTMetadata.Support.MessageId, LTMetadata.eMessageType.Data, metadata.Piece, buffer);
                        await PeerIO.SendMessageAsync(connection, encryptor, metadata);

                        unrequestedPieces.Remove(metadata.Piece);

                        // Hack this in because testing is... awkward... for most of this library.
                        // The purpose here is to ensure that duplicate pieces don't reset our data or cause the event
                        // to be emitted multiple times.
                        if (unrequestedPieces.Count > 0)
                        {
                            metadata = new LTMetadata(LTMetadata.Support.MessageId, LTMetadata.eMessageType.Data, 0, buffer);
                            await PeerIO.SendMessageAsync(connection, encryptor, metadata);
                        }

                        // And let's receive many handshake messages from other peers. Ensure we process this on the correct
                        // thread. It needs to be on the main loop as it's run in the context of the ClientEngine loop.
                        if (rig.Manager.Mode is MetadataMode mode)
                        {
                            ClientEngine.MainLoop.Post(state => mode.HandleMessage(PeerId.CreateNull(12389), exHand), null);
                        }
                    }
                }
            }

            // We've sent all the pieces. Now we just wait for the torrentmanager to process them all.
            Torrent torrent;

            if (metadataOnly)
            {
                torrent = Torrent.Load(await metadataTcs.Task.WithTimeout());
            }
            else
            {
                await rig.Manager.WaitForState(TorrentState.Downloading).WithTimeout();

                Assert.IsTrue(File.Exists(expectedPath), "#1");
                torrent = Torrent.Load(expectedPath);
            }

            Assert.AreEqual(rig.Manager.InfoHash, torrent.InfoHash, "#2");
            Assert.AreEqual(1, torrent.AnnounceUrls.Count, "#3");
            Assert.AreEqual(2, torrent.AnnounceUrls[0].Count, "#4");

            Assert.IsTrue(receivedHaveNone, "#6");

            if (!metadataOnly)
            {
                var peer = PeerId.CreateNull(rig.Manager.Bitfield.Length, true, false, true);
                Assert.DoesNotThrow(() => rig.Manager.PieceManager.AddPieceRequests(peer));
            }
        }
コード例 #15
0
 private void SendMessage(PeerMessage message, CustomConnection connection)
 {
     var b = message.Encode();
     encryptor.Encrypt(b);
     var result = connection.BeginSend(b, 0, b.Length, null, null);
     if (!result.AsyncWaitHandle.WaitOne(5000, true))
         throw new Exception("Message didn't send correctly");
     connection.EndSend(result);
 }
コード例 #16
0
 private PeerMessage ReceiveMessage(CustomConnection connection)
 {
     return TransferTest.ReceiveMessage(connection, decryptor, rig.Manager);
 }
コード例 #17
0
ファイル: HomeController.cs プロジェクト: ttufekci/DashCore
        public async Task <IActionResult> AddConnection(CustomConnection connection)
        {
            var info = Request.Form["process"];

            Console.WriteLine(info);

            if (info == "test")
            {
                var connectionString = Util.GetConnectionString(connection);
                var oconn            = new OracleConnection(connectionString);

                oconn.Open();
                oconn.Dispose();

                ViewBag.ConnectionSuccess = "Connection Success";

                return(View(connection));
            }

            if (ModelState.IsValid)
            {
                var tableList = await _util.GetTableList(connection);

                var sequenceList = await _util.GetSequenceList(connection);

                foreach (var table in tableList)
                {
                    var tablemetadata = await _util.GetTableMetadata(connection.Name, table);

                    if (tablemetadata == null)
                    {
                        tablemetadata = new TableMetadata();
                    }

                    tablemetadata.Connection   = connection.Name;
                    tablemetadata.TableName    = table;
                    tablemetadata.SequenceName = Util.FindBestMatch(table, sequenceList);

                    if (tablemetadata.Id > 0)
                    {
                        _context.Update(tablemetadata);
                    }
                    else
                    {
                        _context.Add(tablemetadata);
                    }
                }

                if (connection.Id > 0)
                {
                    _context.Update(connection);
                }
                else
                {
                    _context.Add(connection);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(connection));
        }
コード例 #18
0
ファイル: HomeController.cs プロジェクト: ttufekci/DashCore
        public IActionResult AddConnection()
        {
            var connectionVM = new CustomConnection();

            return(View(connectionVM));
        }
コード例 #19
0
        public static PeerMessage ReceiveMessage(CustomConnection connection, IEncryption decryptor,
            TorrentManager manager)
        {
            var buffer = new byte[4];
            Receive(connection, buffer, 0, buffer.Length);
            decryptor.Decrypt(buffer);

            var count = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(buffer, 0));
            var message = new byte[count + 4];
            Buffer.BlockCopy(buffer, 0, message, 0, 4);

            Receive(connection, message, 4, count);
            decryptor.Decrypt(message, 4, count);

            return PeerMessage.DecodeMessage(message, 0, message.Length, manager);
        }
コード例 #20
0
 public static void Receive(CustomConnection connection, byte[] buffer, int offset, int count)
 {
     while (count > 0)
     {
         var r = connection.BeginReceive(buffer, offset, count, null, null);
         if (!r.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(4)))
             throw new Exception("Could not receive required data");
         var transferred = connection.EndReceive(r);
         if (transferred == 0)
             throw new Exception("The socket was gracefully killed");
         offset += transferred;
         count -= transferred;
     }
 }
コード例 #21
0
        internal async Task SendMetadataCore(string expectedPath, PeerMessage sendAfterHandshakeMessage)
        {
            CustomConnection connection = pair.Incoming;

            // 1) Send local handshake. We've already received the remote handshake as part
            // of the Connect method.
            var sendHandshake = new HandshakeMessage(rig.Manager.InfoHash, new string ('g', 20), VersionInfo.ProtocolStringV100, true, true);
            await PeerIO.SendMessageAsync(connection, encryptor, sendHandshake);

            ExtendedHandshakeMessage exHand = new ExtendedHandshakeMessage(false, rig.Torrent.InfoMetadata.Length, 5555);

            exHand.Supports.Add(LTMetadata.Support);
            await PeerIO.SendMessageAsync(connection, encryptor, exHand);

            await PeerIO.SendMessageAsync(connection, encryptor, sendAfterHandshakeMessage);

            bool receivedHaveNone = false;

            // 2) Receive the metadata requests from the other peer and fulfill them
            byte[]      buffer = rig.Torrent.InfoMetadata;
            int         length = (buffer.Length + 16383) / 16384;
            PeerMessage m;

            while (length > 0 && (m = await PeerIO.ReceiveMessageAsync(connection, decryptor)) != null)
            {
                if (m is ExtendedHandshakeMessage ex)
                {
                    Assert.AreEqual(ClientEngine.DefaultMaxPendingRequests, ex.MaxRequests);
                }
                else if (m is HaveNoneMessage)
                {
                    receivedHaveNone = true;
                }
                else if (m is LTMetadata metadata)
                {
                    if (metadata.MetadataMessageType == LTMetadata.eMessageType.Request)
                    {
                        metadata = new LTMetadata(LTMetadata.Support.MessageId, LTMetadata.eMessageType.Data, metadata.Piece, buffer);
                        await PeerIO.SendMessageAsync(connection, encryptor, metadata);

                        length--;
                    }
                }
            }

            // We've sent all the pieces. Now we just wait for the torrentmanager to process them all.
            await rig.Manager.WaitForState(TorrentState.Downloading).WithTimeout();

            Assert.IsTrue(File.Exists(expectedPath), "#1");
            Torrent torrent = Torrent.Load(expectedPath);

            Assert.AreEqual(rig.Manager.InfoHash, torrent.InfoHash, "#2");
            Assert.AreEqual(2, rig.Manager.Torrent.AnnounceUrls.Count, "#3");
            Assert.AreEqual(2, rig.Manager.Torrent.AnnounceUrls[0].Count, "#4");
            Assert.AreEqual(3, rig.Manager.Torrent.AnnounceUrls[1].Count, "#5");
            Assert.IsTrue(receivedHaveNone, "#6");

            var peer = PeerId.CreateNull(rig.Manager.Bitfield.Length, true, false, true);

            Assert.DoesNotThrow(() => rig.Manager.PieceManager.AddPieceRequests(peer));
        }
コード例 #22
0
 private void SendMessage(PeerMessage message, CustomConnection connection)
 {
     var b = message.Encode();
     encryptor.Encrypt(b);
     Send(connection, b, 0, b.Length);
 }
コード例 #23
0
        public static object ExecuteScalar(string sql, Dictionary <string, object> parameters = null, CustomConnection connection = null)
        {
            object result = null;

            connection = connection ?? new MsSqlConnection();

            IDbCommand command = null;

            using (connection)
            {
                try
                {
                    connection.Connect();

                    command = connection.CreateCommand();

                    command.CommandText = sql;

                    if (parameters != null)
                    {
                        var pKeys = parameters.Select(p => p.Key).ToList();

                        foreach (var key in pKeys)
                        {
                            if (!sql.Contains(key))
                            {
                                parameters.Remove(key);
                            }
                        }

                        command.AddParameters(parameters);
                    }

                    result = command.ExecuteScalar();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            }

            return(result);
        }
コード例 #24
0
        public static List <Dictionary <string, object> > ExecuteQuery(string sql, Dictionary <string, object> parameters = null, CustomConnection connection = null)
        {
            var list = new List <Dictionary <string, object> >();

            IDataReader dataReader = null;
            IDbCommand  command    = null;

            connection = connection ?? new MsSqlConnection();

            using (connection)
            {
                try
                {
                    connection.Connect();

                    command = connection.CreateCommand();

                    command.CommandText = sql;

                    if (parameters != null)
                    {
                        var pKeys = parameters.Select(p => p.Key).ToList();

                        foreach (var key in pKeys)
                        {
                            if (!sql.Contains(key))
                            {
                                parameters.Remove(key);
                            }
                        }

                        command.AddParameters(parameters);
                    }

                    dataReader = command.ExecuteReader();

                    while (dataReader.Read())
                    {
                        var dictionary = new Dictionary <string, object>();

                        for (int i = 0; i < dataReader.FieldCount; i++)
                        {
                            dictionary.Add(dataReader.GetName(i), dataReader.GetValue(i));
                        }

                        list.Add(dictionary);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
                finally
                {
                    if (dataReader != null)
                    {
                        dataReader.Close();
                    }
                }
            }

            return(list);
        }
コード例 #25
0
        public static bool Any(string sql, Dictionary <string, object> parameters = null, CustomConnection connection = null)
        {
            sql = string.Format("select 1 from ({0}) t", sql);

            return(Convert.ToInt32(ExecuteScalar(sql, parameters, connection)) == 1);
        }
コード例 #26
0
ファイル: SQL.cs プロジェクト: Lyror/EmployeeManagement
		internal static void SetConnectionString(CustomConnection con)
		{
			Connection = con;
		}
コード例 #27
0
 public CustomConnectionInfo(Type t, CustomConnection n)
 {
     connection = n;
     type       = t;
 }
コード例 #28
0
 public CustomBulkInsert(CustomConnection customConnection)
 {
     _customConnection = customConnection;
 }