working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,379 snippets matching: transaction

    public by AnghelLeonard modified Aug 28, 2016  212316  2  5  0

    Hibernate JPA - programmatically set the transaction isolation level for the current connection

    Hibernate JPA - programmatically set the transaction isolation level for the current connection
    entityManager = entityManagerFactory.createEntityManager();
                Session session = (Session) entityManager.getDelegate();            
                session.doWork((Connection connection) -> {
                    connection.setTransactionIsolation(
                            Connection.TRANSACTION_READ_COMMITTED);
                });

    public by Geometry modified Jul 31, 2016  148352  0  3  0

    GetCommandBuffer: Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket using the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;b...

    Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket using the The command to be converted. The buffer containing the bytes representing the command. The command must be terminated by \r\n. The Nagle algorithm is disabled on the socket to speed things up, so it's
    C#
    using System;
    using System.IO;
    using System.Text;
    using System.Collections.Generic;
    
    /// <summary>
    /// Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket
    /// using the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;byte&gt;&gt;)"/>
    /// </summary>
    /// <param name="value">The command to be converted.</param>
    /// <returns>The buffer containing the bytes representing the command. The command must be terminated by \r\n.</returns>
    /// <remarks>The Nagle algorithm is disabled on the socket to speed things up, so it's recommended to convert a command into a buffer
    /// and use the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;byte&gt;&gt;)"/> to send the command and the additional buffers in one transaction.</remarks>
    public unsafe static IList<ArraySegment<byte>> GetCommandBuffer(string value)
    {
    	var data = new ArraySegment<byte>(Encoding.ASCII.GetBytes(value));
    
    	return new ArraySegment<byte>[] { data };
    }

    public by Geometry modified Jul 31, 2016  87772  2  4  0

    PubKeyToScript: For POS coins - used to format wallet address pubkey to use in generation transaction's output.

    For POS coins - used to format wallet address pubkey to use in generation transaction's output. nodejs: https://github.com/zone117x/node-stratum-pool/blob/3586ec0d7374b2acc5a72d5ef597da26f0e39d54/lib/util.js#L243 nodejs: http://runnable.com/me/VCFHE0RrZnwbsQ6y
    using System;
    using System.IO;
    using System.Linq;
    using CoiniumServ.Coin.Address;
    using CoiniumServ.Coin.Address.Exceptions;
    using CoiniumServ.Cryptology;
    using CoiniumServ.Utils.Extensions;
    using CoiniumServ.Utils.Numerics;
    using Gibbed.IO;
    using Serilog;
    
    /// <summary>
    /// For POS coins - used to format wallet address pubkey to use in generation transaction's output.
    /// </summary>
    /// <param name="key"></param>
    /// <example>
    /// nodejs: https://github.com/zone117x/node-stratum-pool/blob/3586ec0d7374b2acc5a72d5ef597da26f0e39d54/lib/util.js#L243
    /// nodejs: http://runnable.com/me/VCFHE0RrZnwbsQ6y
    /// </example>
    /// <returns></returns>
    public static byte[] PubKeyToScript(string key)
    {
        var pubKey = key.HexToByteArray();
    
        if (pubKey.Length != 33)
        {
            Log.Error("invalid pubkey length for {0:l}", key);
            return null;
        }
    
        byte[] result;
    
        using (var stream = new MemoryStream())
        {
            stream.WriteValueU8(0x21);
            stream.WriteBytes(pubKey);
            stream.WriteValueU8(0xac);
            result = stream.ToArray();
        }
    
        return result;
    }

    public by cghersi @ MailUp API DEV modified Aug 29, 2018  1675  46  5  0

    MailUp REST API - How to send a transactional email message

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server. The credentials of the SMTP+ user are passed as parameter in the body of the request. Explore the MessageDTO object in order to understand how you can customize the message you want to send.
    public static void SendMessage()
    {
      // 1) Required values
      string username = "<your_username>";
    	string password = "<your_password>";
    
    	string clientid = "<your_clientid>";
    	string clientsecret = "<your_clientsecret>";
    
    	string smtpplus_username = "<your_smtpplus_username>";
    	string smtpplus_password = "<your_smtpplus_password>";
      
      // 2) Setup the MailUp Client:
    	MailUpClient client = new MailUpClient(clientid, clientsecret);
    	client.RetrieveAccessToken( username, password );
    
      // 3) prepare the input:
      MessageDTO msg = new MessageDTO()
      {
        Html = new HtmlDTO()
        {
          Body = "<div>Hello Mr. [firstname][lastname] !!!</div><br><img width='600' height='397' src='cid:img001'>",
          BodyTag = "<body>"
        },
        Text = "Hello world!!!",
        Subject = "Hello friend!",
        From = new EmailAddressDTO() { Name = "Test User", Email = "test@mailup.it" },
        To = new List<EmailAddressDTO>() { new EmailAddressDTO() { Name = "Massimo", Email = "info@mailup.it" } },
        Cc = new List<EmailAddressDTO>(),
        Bcc = new List<EmailAddressDTO>(),
        ReplyTo = null,
        CharSet = "utf-8",
        ExtendedHeaders = null,
        Attachments = null,
        EmbeddedImages = new List<MessagePartDTO>() {
          new MessagePartDTO() {
            Filename = "Image.jpg",
            ContentId = "img001",
            Body = new byte[] { 0x01, 0x02, 0x03, 0x04 }
          }
        },
        XSmtpAPI = new XSmtpAPIDTO()
        {
          CampaignName = "Test Campaign",
          CampaignCode = "1001",
          Header = null,
          Footer = null,
          ClickTracking = null,
          ViewTracking = null,
          Priority = null,
          Schedule = null,
          DynamicFields = new List<NameValueDTO>() {
            new NameValueDTO() { N = "firstname", V = "Mario"},
            new NameValueDTO() { N = "lastname", V = "Rossi"}
          },
          CampaignReport = null,
          SkipDynamicFields = null
        },
        User = new SmtpUserDTO() { Username = smtpplus_username, Secret = smtpplus_password }
      };
    
      // 4) Invoke the web method:
      SendResponseDTO result = null;
      try
      {
        result = client.SendMessage(msg);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Cannot perform the operation due to " + ex.Message);
        return;
      }
    
      // 5) Print results:
      if (result != null)
        Console.WriteLine("Result of sending task:" + result.Message);
      else
        Console.WriteLine("An error occurred while sending message.");
    }
    						

    public by cghersi @ MailUp API DEV modified Aug 29, 2018  2232  12  5  0

    MailUp REST API - How to send a transactional email message that follows a template

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server. The credentials of the SMTP+ user are passed as parameter in the body of the request. Explore the TemplateDTO object in order to understand how you can customize the message you want to send.
    public static void SendTemplate()
    {
      // 1) Required values
      string username = "<your_username>";
    	string password = "<your_password>";
    
    	string clientid = "<your_clientid>";
    	string clientsecret = "<your_clientsecret>";
    
    	string smtpplus_username = "<your_smtpplus_username>";
    	string smtpplus_password = "<your_smtpplus_password>";
      
      // 2) Setup the MailUp Client:
    	MailUpClient client = new MailUpClient(clientid, clientsecret);
    	client.RetrieveAccessToken( username, password );
    
      // 3) prepare the input:
      TemplateDTO msg = new TemplateDTO()
      {
        TemplateId = 694,
        Subject = "Test message from template",
        From = new EmailAddressDTO() { Name = "Test User", Email = "test@mailup.it" },
        To = new List<EmailAddressDTO>() { new EmailAddressDTO() { Name = "Massimo", Email = "info@mailup.it" } },
        Cc = new List<EmailAddressDTO>(),
        Bcc = new List<EmailAddressDTO>(),
        ReplyTo = null,
        CharSet = "utf-8",
        ExtendedHeaders = null,
        Attachments = null,
        EmbeddedImages = new List<MessagePartDTO>() {
          new MessagePartDTO() {
            Filename = "Image.jpg",
            ContentId = "img001",
            Body = new byte[] { 0x01, 0x02, 0x03, 0x04 }
          }
        },
        XSmtpAPI = null,
        User = new SmtpUserDTO() { Username = smtpplus_username, Secret = smtpplus_password }
      };
    
      // 4) Invoke the web method:
      SendResponseDTO result = null;
      try
      {
        result = client.SendTemplate(msg);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Cannot perform the operation due to " + ex.Message);
        return;
      }
    
      // 5) Print results:
      if (result != null)
        Console.WriteLine("Result of sending task:" + result.Message);
      else
        Console.WriteLine("An error occurred while sending template.");
    }
    												

    public by cghersi @ MailUp API DEV modified Aug 29, 2018  1750  8  5  0

    MailUp REST API - How to retrieve information of SMTP+ Users

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server. The credentials of the SMTP+ user are passed as parameter in the body of the request. You can optionally specify a username as third parameter in order to filter the resulting list.
    public static void GetUserInfo()
    {
      // 1) Required values
      string username = "<your_username>";
    	string password = "<your_password>";
    
    	string clientid = "<your_clientid>";
    	string clientsecret = "<your_clientsecret>";
    
    	string smtpplus_username = "<your_smtpplus_username>";
    	string smtpplus_password = "<your_smtpplus_password>";
      
      // 2) Setup the MailUp Client:
    	MailUpClient client = new MailUpClient(clientid, clientsecret);
    	client.RetrieveAccessToken( username, password );
    
      // 3) Invoke the web method:
      List<UserInfoDTO> result = null;
      try
      {
        result = client.ListUserInfo(smtpplus_username, smtpplus_password);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Cannot perform the operation due to " + ex.Message);
        return;
      }
    
      // 4) Print results:
      if (result != null)
        Console.WriteLine("Retrieved users total:" + result.Count);
      else
        Console.WriteLine("An error occurred while retrieving users.");
    }
    																		

    public by p.kontalis modified Nov 30, 2015  2308  0  6  0

    Simple SQL Transaction

    typical transaction method
    -- start a transaction
    start transaction;
    -- get latest order number
    select @orderNumber := max(orderNUmber) from orders;
    -- set new order number
    set @orderNumber = @orderNumber  + 1;
     
    -- insert a new order for customer 145
    insert into orders(orderNumber,
                       orderDate,
                       requiredDate,
                       shippedDate,
                       status,
                       customerNumber)
    values(@orderNumber,
           now(),
           date_add(now(), INTERVAL 5 DAY),
           date_add(now(), INTERVAL 2 DAY),
           'In Process',
            145);
    -- insert 2 order line items
    insert into orderdetails(orderNumber,
                             productCode,
                             quantityOrdered,
                             priceEach,
                             orderLineNumber)
    values(@orderNumber,'S18_1749', 30, '136', 1),
          (@orderNumber,'S18_2248', 50, '55.09', 2); 
    -- commit changes    
    commit;       
    -- get the new inserted order
    select * from orders a 
    inner join orderdetails b on a.ordernumber = b.ordernumber
    where a.ordernumber = @ordernumber;                                    

    public by AnghelLeonard modified Aug 13, 2016  1559  0  3  0

    Hibernate JPA - Get the transaction isolation level in a readable fashion

    Hibernate JPA - Get the transaction isolation level in a readable fashion
    Session session = (Session) entityManager.getDelegate();
                session.doWork((Connection connection) -> {
                    String result;
                    int til = connection.getTransactionIsolation();
                    switch (til) {
                        case Connection.TRANSACTION_READ_COMMITTED:
                            result = "TRANSACTION_READ_COMMITTED";
                            break;
                        case Connection.TRANSACTION_READ_UNCOMMITTED:
                            result = "TRANSACTION_READ_UNCOMMITTED";
                            break;
                        case Connection.TRANSACTION_REPEATABLE_READ:
                            result = "TRANSACTION_REPEATABLE_READ";
                            break;
                        case Connection.TRANSACTION_SERIALIZABLE:
                            result = "TRANSACTION_SERIALIZABLE";
                            break;
                        default:
                            result = "TRANSACTION_NONE";
                            break;
                    }
                    LOG.info("Current transaction isolation level: " + result);
                });

    public by AnghelLeonard modified Aug 14, 2016  1454  0  5  0

    EntityManager joining a JTA transaction

    EntityManager joining a JTA transaction
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo_PU");
    EntityManager em = emf.createEntityManager();
    
    // specific to JBossStandAloneJtaPlatform
    javax.transaction.TransactionManager tx = 
                    com.arjuna.ats.jta.TransactionManager.transactionManager();        
    // or
    javax.transaction.UserTransaction tx_ = 
                    com.arjuna.ats.jta.UserTransaction.userTransaction();
    
    try {
        tx.begin();
        em.joinTransaction();
        em.persist(transientInstance);
        tx.commit();
        ...

    public by cghersi modified Dec 14, 2013  7179  29  8  0

    How to correctly Shrink Log File for SQL Server

    In case your transaction log reaches abnormal dimension (e.g. you forgot the backup of the log in your maintenace plan...) it is highly useful this script that allows you to safely shrink the transaction log to the wanted dimension
    USE AdventureWorks
    GO
    
    -- Use some dynamic SQL just only not to re-write several times the name 
    -- of your db, or to insert this snippet into a loop for all your databases...
    DECLARE @dbname varchar(50) = 'AdventureWorks';
    DECLARE @logFileName varchar(50) = @dbname  + '_log';
    DECLARE @SQL nvarchar(max);
    SET @SQL = REPLACE('ALTER DATABASE {dbname} SET RECOVERY FULL;', '{dbname}', @dbname);
    EXECUTE(@SQL);
    
    DECLARE @path nvarchar(255) = N'F:\BCK_DB\logBCK' + CONVERT(CHAR(8), GETDATE(), 112) + '_'
      + REPLACE(CONVERT(CHAR(8), GETDATE(), 108),':','') + '.trn';
    
    BACKUP LOG @dbname TO DISK = @path WITH INIT, COMPRESSION;
    
    DBCC SHRINKFILE(@logFileName);
    
    -- determine here the new file size and growth rate:
    SET @SQL = REPLACE('ALTER DATABASE {dbname} MODIFY FILE (NAME = ' + @logFileName + ', SIZE = 32000MB, FILEGROWTH = 10%);', 
    	'{dbname}', @dbname);
    EXECUTE(@SQL);
    GO
    • Public Snippets
    • Channels Snippets