Thursday, September 22, 2011

GRUB Installation Issue with 2 TB HDD

Few days ago i need across to install  a box with 2 x 2 TB HDD WD  Caviar Green with  Debian Squeeze with RAID 1. So I started the installation.
Even now I have noticed some strange, when partitioning first hd it don't ask me to set primary partition and bootable flag was not exchangeable
Apart from this was going well until the GRUB installation. It failed with the error message below!
Sep 22 01:34:43 grub-installer: grub-setup: warn: This GPT partition label has no BIOS Boot Partition; embedding won’t be possible!
Sep 22 01:34:43 grub-installer: grub-setup: error: Embedding is not possible, but this is required when the root device is on a RAID array or LVM volume
I started googlin for two days, with numeros forum suggestion with technical details about WD caviar green 4KB sector setup on linux and relative bugs, GPT configuration suggestion... all these attemps failed! :(   
Today I decided to try another way... and this time successfully :)
Problems could be solved adding a small partition (200MB) BIOS Boot Partition which was missing on both sda devices.
If this post was useful to you, please follow me.

Tuesday, June 21, 2011

Crystal Reports filed text newline, carriage return, \r\n

Nel mio crystal report ho un textFiled, vorrei settare il suo valore runtime.

rpt.DataDefinition.FormulaFields["fieldTarga"].Text =TextBoxTarga.Text;
Tutto funziona correttamente, fino a quando il valore da assegnare non contiene i caratteri speciali linefeed e carriage return "\r\n". Questo è un bug di Crystal Report for .NET 
Per risolvere il problema, anche se di primo acchito appare insensato, possiamo ovviare usando questa semplice funzione:
string FormatCRField(string s)
        {
            return "'" + s.Replace("\r\n", "' + chr(10) + '") + "'";
        }
Sostituisce "\r\n"  con chr(10) che verrà interpetato correttamente dal "parser" di CR.
Spero che questo possa aiutarti.

Friday, May 20, 2011

c# Activerecord ExecuteQuery isnull sqlite

Come indicato nel precedente post http://brokenpipe-it.blogspot.com/2011/05/sqlite-equivalent-isnull-statement.html la corrispondente sintassi "isnull" è ifnull(x,y) ma si presenta un problema nell'esecuzione del metodo Executequery di Activerecordmediator con query scalare; vediamo un esempio:

     string hql = "SELECT SUM(p.Pz) FROM PackingDetails p " +
                    "WHERE p.Id_packing = :parIdPack "

    ScalarQuery q = new ScalarQuery(typeof(PackingDetails), hql);

    q.SetParameter("parIdPack", IdPack);

    long totalPz = ActiveRecordMediator.ExecuteQuery(q);
              
    return Convert.ToInt32(totalPz);




Nel caso in cui la condizione indicata dalla clausola where non sia verificata ci aspetteremo in uscita 0, ma in realtà ci troveremo , invece, una SystemNullException.
Per ovviare al problema risolviamo così:
     try
      {
      string hql = "SELECT SUM(p.Pz) FROM PackingDetails p " +
                   "WHERE p.Id_packing = :parIdPack " +


     ScalarQuery q = new ScalarQuery(typeof(PackingDetails), hql);

     q.SetParameter("parIdPack", IdPack);

     long? totalPz = (long?)ActiveRecordMediator.ExecuteQuery(q);
               
     return Convert.ToInt32((totalPz.HasValue) ? totalPz : -1);
     }
    catch (Exception ex)
    {
       Console.WriteLine(ex.Message);
       return -1;
    }



 long? totalPz =(long?)ActiveRecordMediator.ExecuteQuery(q);

informerà il compilatore che la variabile totalPz non dovrà obbligatoriamente essere valorizzata e quindi poi utilizzeremo 

       ((totalPz.HasValue) ? totalPz : -1)

per ritornare totalPz se valorizzata e -1 in caso valga null

Considerazioni o altri  suggerimenti sono ben accetti. 

Sqlite equivalent ISNULL statement

Come descritto dalle core function http://www.sqlite.org/lang_corefunc.html#ifnull l'equivalente statement è IFNULL.

Monday, March 28, 2011

c# 3des vs php

I came across the need to perform encryption, exchanging data generated by the php function from C #.

function encrypt($text)
{
$key = "qwertyuiopasdfghjklzxcvb";// 24 bit Key
$iv = "12345678";// 8 bit IV
$bit_check=8;// bit amount for diff algor.
$text_num =str_split($text,$bit_check);
$text_num = $bit_check-strlen($text_num[count($text_num)-1]);
for ($i=0;$i<$text_num; $i++) {$text = $text . chr($text_num);}
$cipher = mcrypt_module_open(MCRYPT_TRIPLEDES,'','cbc','');
mcrypt_generic_init($cipher, $key, $iv);
$decrypted = mcrypt_generic($cipher,$text);
mcrypt_generic_deinit($cipher);
return base64_encode($decrypted);
}


How to decrypt in c #? Here's the solution:

public static string Decrypt(string text)
    {
      try
      {
        string key = "qwertyuiopasdfghjklzxcvb";// 24 bit Key
        string iv = "12345678";// 8 bit IV
        //int bit_check = 8;// bit amount for diff algor.
        ASCIIEncoding asc = new ASCIIEncoding();
        TripleDESCryptoServiceProvider p = new TripleDESCryptoServiceProvider();
        p.Mode = CipherMode.CBC;
        p.Key = Encoding.ASCII.GetBytes(key);
        p.IV = Encoding.ASCII.GetBytes(iv);
        p.Padding = PaddingMode.Zeros;
        ICryptoTransform c = p.CreateDecryptor();
        byte[] DataToDecrypt = Convert.FromBase64String(text);
        byte[] bDencrypted = c.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
        return ASCIIEncoding.UTF8.GetString(bDencrypted);
      }


Note the use of PaddingMode Zeros  to solve offset problems. From both of these functions is easy now rebuilt their mirror functions.