вторник, 12 января 2016 г.

Entityframework ConnectionString

Web.config and App.config

App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Users;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="FortsTicks01" connectionString="Data Source=.\MSSQL12;Initial Catalog=FortsTicks01;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Web.config:

<configuration>
  <configSections>    
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Users;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="TimeSeries01" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TimeSeries01;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

 <appSettings>

Dispose

вторник, 5 января 2016 г.

SQL, Data Types

SQL DateTime Types

FTP C#

BulkInsert EnetityFrameWork

суббота, 2 января 2016 г.

ArrayOfString to Byte Array

http://stackoverflow.com/questions/472906/converting-a-string-to-byte-array-without-using-an-encoding-byte-by-byte

http://stackoverflow.com/questions/14669820/how-to-convert-a-string-array-to-a-byte-array-java


Compress/Decompress

http://www.dotnetperls.com/compress

http://www.dotnetperls.com/decompress


 private byte[] Serialize(IEnumerable<Dto.Bar> bs)
        {
            BinaryFormatter bf = new BinaryFormatter();
            byte[] bytes;
            MemoryStream ms = new MemoryStream();

            var lst = bs.Select(b => b.ToStr()).ToList();

            bf.Serialize(ms, lst);
            ms.Seek(0, 0);
            
            var bts = ms.ToArray();

            return bts;
        }

 private IEnumerable<IBarSimple> DeSerialize(byte[] bytes)
        {
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            ms.Write(bytes, 0, bytes.Length);
            ms.Seek(0, 0);

            var ss = (List<string>)bf.Deserialize(ms);
            var bs = ss.Select(s => s.ToBarDto()).ToList();
            return bs;

        }

 private byte[] Compress(byte[] bytes)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (GZipStream gzip = new GZipStream(ms, CompressionMode.Compress, true))
                {
                    gzip.Write(bytes, 0, bytes.Length);
                }
                return ms.ToArray();
            }

        }

 private byte[] DeCompress(byte[] bytes)
        {
            using (GZipStream gzstream = new GZipStream(new MemoryStream(bytes), CompressionMode.Decompress))
            {
                const int size = 4096;
                byte[] buffer = new byte[size];
                using (MemoryStream mstr = new MemoryStream())
                {
                    int count = 0;
                    do
                    {
                        count = gzstream.Read(buffer, 0, size);
                        if (count > 0)
                        {
                            mstr.Write(buffer, 0, count);
                        }
                    } while (count > 0);
                    return mstr.ToArray();
                }
            }

        }