Ibirite's Blog

Programmatic Publish for an ASP.NET Project

Posted in C# Winforms by ibirite on June 11, 2014

A few days ago, I was googling in order to find something explaining how to Publish a Web Application into filesistem, as long as it’s not done by calling MSBuild.exe on Process.Execute. Finally, I have found by myself that you can use the class Microsoft.Build.Execution.BuildManager.DefaultBuildManager.Build to achieve this goal. Simple and easy, specially because you dont have to parse the output command to separate Errors and Warnings: the BuildManager already fix this for you.

Firebird Mistery

Posted in Uncategorized by ibirite on July 19, 2011

I have re-installed Windows Seven in my notebook a few days ago, but at this time, I have decided to use the x64 version to get a better performance in some applications. But I have forgot that I’m using firebird embedded in some of my .net apps… After getting a lot of  “System.BadImageFormatException” when trying to connect to Firebird, I finally realized that the problem could rely in the fact that my .net app Plataform target is “Any CPU”…

Voilá… Another stupid mistake that took me hours long to solve it..

ASP Net: CheckBoxList Inside DataRepeater

Posted in Uncategorized by ibirite on May 8, 2010

Yesterday, one of my friends asked for help in a asp.net project. he needed to put a CheckBoxList inside a DataRepeater. He also needed to get the state of each control after a postback. The problem was : he was trying to get the DataItem from the RepeaterControl AFTER the postback. Of course, at that time, DataItem is always null. The solution is:


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
      <script runat="server">
         protected void Page_Load(object sender, EventArgs e)
         {
            if (!this.IsPostBack)
            {
               DataSet ds = new DataSet()
               {
                  Tables =
                  {
                     new DataTable()
                     {
                        TableName = "tb01",
                        Columns =
                        {
                           new DataColumn("codigo",typeof(int)),
                           new DataColumn("nome",typeof(string))
                        },
                        Rows =
                        {
                           {1,"Christiano Coutinho de Moraes"},
                           {2,"Marco Castro"},
                           {3,"Walerson Moreira"}
                        }
                     },

                     new DataTable()
                     {
                        TableName = "tb02",
                        Columns =
                        {
                           new DataColumn("codigo",typeof(int)),
                           new DataColumn("pessoa",typeof(int)),
                           new DataColumn("nomeGosto",typeof(string)),
                           new DataColumn("selecionado",typeof(bool))
                        },
                        Rows =
                        {
                           {1, 1 , "Gosto 01",true},{2, 1 , "Gosto 02",false}, {3, 1 , "Gosto 03",false},
                           {4, 2 , "Gosto 04",true},{5, 2 , "Gosto 05",false}, {6, 2 , "Gosto 06",false},
                           {7, 3 , "Gosto 07",true},{8, 3 , "Gosto 08",false}, {9, 3 , "Gosto 09",false},
                        }
                     }
                  }
               };
               ds.Relations.Add(new DataRelation("relmd", ds.Tables["tb01"].Columns["codigo"], ds.Tables["tb02"].Columns["pessoa"]));
               Repeater1.DataSource = ds.Tables["tb01"];
               Repeater1.DataBind();
            }
            else
            {
               StringBuilder sb = new StringBuilder();
               foreach (RepeaterItem i in Repeater1.Items)
               {
                  Label l = (Label)i.FindControl("Desejo");
                  CheckBoxList cbl = (CheckBoxList)i.FindControl("Gostos");
                  sb.AppendFormat("<br/> Seleção da Pessoa: {0} <br/>", l.Text);
                     foreach(ListItem li in cbl.Items)
                        if(li.Selected)
                           sb.AppendFormat(" - {0}<br/>",li.Text);
                  sb.Append("<hr/>");
               }
               Label1.Text = sb.ToString();
            }
         }

         protected void CheckBoxList1_DataBinding(object sender, EventArgs e)
         {
            System.Data.DataView rws = (System.Data.DataView)(sender as CheckBoxList).DataSource;
            DataTable dt = rws.ToTable();
            for(int i = 0;i< dt.Rows.Count-1;i++)
               (sender as CheckBoxList).Items[i].Selected = Convert.ToBoolean(dt.Rows[i]["selecionado"]);
         }

         protected void Button1_Click(object sender, EventArgs e)
         {
            TextBox1.Text = "Postback Feito!";
         }

   </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
       <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
          Text="Faz Postback" />
       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       <asp:Repeater ID="Repeater1" runat="server">
           <HeaderTemplate>
                 <table width="700" border="1" cellspacing="0" cellpadding="0">
                     <tr>
                         <th valign="top" style="text-align: left; width: 255px" scope="col">
                             Mais informações:
                         </th>
                         <th valign="top" style="text-align: left" scope="col">
                             &nbsp;
                         </th>
                     </tr>
             </HeaderTemplate>
             <ItemTemplate>
                 <tr>
                     <td valign="top" style="text-align: left; width: auto">
                     <br />
                         <asp:HiddenField ID="DesejoId" runat="server"
                             Value='<%# DataBinder.Eval(Container.DataItem, "codigo") %>' />
                         <asp:Label ID="Desejo" runat="server" Font-Bold="true" Text='<%# DataBinder.Eval(Container.DataItem, "nome") %>' />&nbsp;&nbsp;
                     </td>
                     <td valign="top" style="text-align: left" align="left">
                     <br />
                         <asp:CheckBoxList ID="Gostos" runat="server"
                           RepeatDirection="Vertical" RepeatColumns="0"
                           OnDataBound="CheckBoxList1_DataBinding"
                           DataSource='<%# DataBinder.Eval(Container.DataItem, "relmd") %>'
                           DataTextField="nomeGosto">
                         </asp:CheckBoxList>
                     </td>
                 </tr>
             </ItemTemplate>
             <FooterTemplate>
                 </table>
             </FooterTemplate>
       </asp:Repeater>
    </div>
    <asp:Panel ID="Panel1" runat="server" Width="400px">
       <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </asp:Panel>
    <br />
    </form>
</body>
</html>

Delphi mysteries: can PARADOX configuration affect SQL Databases in BDE?

Posted in Delphi by ibirite on April 30, 2010
The answer is YES…  When you perform complex queries or enable cache schema on BDE, the core engine of this tool
stores the recordset retrieved from your database into temporary PARADOX files. How your Delphi program can be
affected by this? When retrieving large datasets in a query, the error message “9476 :  Temporary table resource limit”
will certanly be thrown.
Workaround to fix this: Go into BDE Administrator. Select TAB “Configuration” -> Drivers -> Native -> PARADOX.
Set the following values: BLOCK SIZE = 32768, LEVEL =7
Please, understand that this workaround works, but it should be avoided for the following reasons:
  • If you got the previous error message ( Temporary table resource limit ), then you are really fetching a large amount of data. Is this really necessary? If not, try to fetch less records in your routine…
  • The performance of your application will be poor, because PARADOX is CRAP.
  • Is BDE really necessary? Avoid it as much as you can!
  • Is Delphi really necessary? There are dozens of better RAD tools!😉

ASP.NET and XslCompiledTransform

Posted in Uncategorized by ibirite on April 29, 2010

Yesterday a solved a big problem in a Client’s asp.net website: XslCompiledTransform was used exactly like XslTransform in that application. The big deal is the fact that you cannot use it this way: XslCompiledTransform really compiles something every time you Create a new object of it, and the application do not release the loaded assembly until it’s finished. The solution is to create a Factory-Singleton ( a mix between these 2 patterns) to give you a single instance of the object and avoid loading multiple assemblies that are equivalent.

Remember: you need to compile one object to each XSL file.

It can also be done by using static fields, but I recommend to create this static field in Global.asax.

EZIRIZ .net Reactor : Simply the best

Posted in Uncategorized by ibirite on April 23, 2010

After looking for a good protection/licensing tool in .net, I finally have found an amazing product: EZIRIZ  .NET  REACTOR.

I couldn’t belive how they can sell such amazing tool for such low price. Take a look on this product comparsion:
http://www.eziriz.com/comparison.htm

Notice that EZIRIZ is compared among some of the top products on the market. Take a look on the main features of it:

  • NET Framework 1.1/2.0/3.0/3.5/4.0, .NET CF 1.1/2.0/3.5, Silverlight 2.0, 3.0, Mono 1.x, 2.x
  • .NET Reactor supports 32-bit and 64-bit Assemblies.
  • .NET Reactor can merge or embed multiple .NET files into one executable(.exe) or library(.dll).
  • .NET Reactor is able to compress applications and embedded files up to 50-75%.
  • NecroBit is a powerful protection technology which stops decompilation. NecroBit replaces the CIL code within methods with encrypted code. This way it is not possible to decompile/reverse engineer your method source code.
  • No tool can disassemble/decompile .NET Reactor protected code. ILDASM(the Microsoft Intermediate Language disassembler) will actually report that it cannot interpret .NET Reactor protected assemblies.
  • .NET Reactor is able to generate a native x86 EXE file stub for your application. This way it is not possible to directly open your protected application in a decompiler. The decompiler recognizes your protected application as a native EXE file.
  • In combination with the Native EXE File feature and NecroBit, .NET Reactor is able to convert managed methods into REAL x86 native code. Only methods which doesn’t affect the runtime and platform behavior (mostly small methods like property getters/setters…) are converted into native code. By nature this feature has an built-in protection against assembly modification.
  • In addition to source protection, .NET Reactor provides thorough class and member obfuscation complemented by different exclusion schemes, use of non-printable characters in obfuscated names, and even incremental obfuscation, which always generates the same obfuscation strings for type and member names.
  • Declarative Obfuscation support allows you to directly define which types and members should be excluded from obfuscation. This can be done by using the custom attribute System.Reflection.ObfuscationAttribute in your source code. .NET Reactor automatically detects the attribute and excludes the corresponding types and members from obfuscation.
  • Control Flow Obfuscation converts the code inside your methods into spaghetti code, which whilst retaining the function of the code makes it extremely difficult for human eyes and decompilers to follow the program logic. Decompilers are not able to decompile the spaghetti code back to your original source code.
  • String encryption makes it difficult for a hacker to understand your code and to attempt a code patch of your assembly, as he will be unable to identify the text of messages or other useful strings, making it much more difficult to identify where to patch your code. This feature has a built-in protection against assembly manipulation.
  • Strong Name Removal Protection prevents your protected assembly from being tampered by hacker tools as they are not able to correctly resign the assembly with a different stong name.
  • .NET Reactor can improve protection and assembly size by compressing and encrypting your managed resources. At runtime, when required the resources are automatically decompressed and decrypted.
  • Powerful  and flexible, the .NET Reactor licensing features allow you to enforce your license conditions and protect your revenue stream by using hardware and software locks. The license manager can build trial or permanent licenses, in a matter of seconds. A fully documented software development kit (SDK), complete with examples, allows you to call the licensing system directly from your code, allowing you to create custom extensions to the licensing system.
  • .NET Reactor is a mature product which has attracted third party development of add-ons.
  • .NET Reactor supports all types of managed assemblies (C#, VB.NET, Managed C++, ASP.NET, Delphi.NET, J#…).
  • An intuitive, easy-to-operate GUI provides quick, comfortable operation.
  • All features support command line invocation, and event driven invocation by Visual Studio Build Events. .NET Reactor produces the finished product in the same way you do.
  • Everyone needs .NET Reactor, and .NET Reactor is priced to make ownership affordable — Compare with other products and features
  • Further tools and features include a ShareIt Module Generator, Standalone License Generation Tool, Multi Assembly Protection, Strong Name Support, Digital Certificate Support, and even a Phone License Activation System.
  • Windows Windows Forms Applications, Console Applications, Windows Services, Control & Class Libraries, WPF Applications & LibrariesWeb ASP.NET Applications & Libraries, ASP.NET Services, WCF Services, Sharepoint WebPartsSilverlight Silverlight Applications & LibrariesSmart Device Compact Framework Applications & LibrariesOthers SQL Server CLR Assemblies, Mono Applications & Libraries
  • .NET Reactor offers full protection support for your ASP.NET Applications and Libraries.
  • .NET Reactor supports all .NET Framework implementations, including Compact Framework, Silverlight and Mono:NET Framework 1.1/2.0/3.0/3.5/4.0, .NET CF 1.1/2.0/3.5, Silverlight 2.0, 3.0, Mono 1.x, 2.x
  • .NET Reactor supports 32-bit and 64-bit Assemblies.
  • .NET Reactor can merge or embed multiple .NET files into one executable(.exe) or library(.dll).
  • .NET Reactor is able to compress applications and embedded files up to 50-75%.
  • NecroBit is a powerful protection technology which stops decompilation. NecroBit replaces the CIL code within methods with encrypted code. This way it is not possible to decompile/reverse engineer your method source code.
  • No tool can disassemble/decompile .NET Reactor protected code. ILDASM(the Microsoft Intermediate Language disassembler) will actually report that it cannot interpret .NET Reactor protected assemblies.
  • .NET Reactor is able to generate a native x86 EXE file stub for your application. This way it is not possible to directly open your protected application in a decompiler. The decompiler recognizes your protected application as a native EXE file.
  • In combination with the Native EXE File feature and NecroBit, .NET Reactor is able to convert managed methods into REAL x86 native code. Only methods which doesn’t affect the runtime and platform behavior (mostly small methods like property getters/setters…) are converted into native code. By nature this feature has an built-in protection against assembly modification.
  • In addition to source protection, .NET Reactor provides thorough class and member obfuscation complemented by different exclusion schemes, use of non-printable characters in obfuscated names, and even incremental obfuscation, which always generates the same obfuscation strings for type and member names.
  • Declarative Obfuscation support allows you to directly define which types and members should be excluded from obfuscation. This can be done by using the custom attribute System.Reflection.ObfuscationAttribute in your source code. .NET Reactor automatically detects the attribute and excludes the corresponding types and members from obfuscation.
  • Control Flow Obfuscation converts the code inside your methods into spaghetti code, which whilst retaining the function of the code makes it extremely difficult for human eyes and decompilers to follow the program logic. Decompilers are not able to decompile the spaghetti code back to your original source code.
  • String encryption makes it difficult for a hacker to understand your code and to attempt a code patch of your assembly, as he will be unable to identify the text of messages or other useful strings, making it much more difficult to identify where to patch your code. This feature has a built-in protection against assembly manipulation.
  • Strong Name Removal Protection prevents your protected assembly from being tampered by hacker tools as they are not able to correctly resign the assembly with a different stong name.
  • .NET Reactor can improve protection and assembly size by compressing and encrypting your managed resources. At runtime, when required the resources are automatically decompressed and decrypted.
  • Powerful  and flexible, the .NET Reactor licensing features allow you to enforce your license conditions and protect your revenue stream by using hardware and software locks. The license manager can build trial or permanent licenses, in a matter of seconds. A fully documented software development kit (SDK), complete with examples, allows you to call the licensing system directly from your code, allowing you to create custom extensions to the licensing system.
  • .NET Reactor is a mature product which has attracted third party development of add-ons.
  • .NET Reactor supports all types of managed assemblies (C#, VB.NET, Managed C++, ASP.NET, Delphi.NET, J#…).
  • An intuitive, easy-to-operate GUI provides quick, comfortable operation.
  • All features support command line invocation, and event driven invocation by Visual Studio Build Events. .NET Reactor produces the finished product in the same way you do.
  • Everyone needs .NET Reactor, and .NET Reactor is priced to make ownership affordable — Compare with other products and features
  • Further tools and features include a ShareIt Module Generator, Standalone License Generation Tool, Multi Assembly Protection, Strong Name Support, Digital Certificate Support, and even a Phone License Activation System.

I have tried to break the protection 0f .Net Reactor. Even the infamous Salamander were no match for the Necrobit and native Win32 conversion. If you really want to protect you code, .net Reactor it’s the right choice!

PS: I’m a licensed user of .net Reactor since November/2009.

TableLayoutPanel going crazy

Posted in C# Winforms by ibirite on April 20, 2010

Recently, I was working in a project where it was necessary to create an WinForm with dynamic controls binded to a binding source. Some tables used on this project had more than 100 columns, and I decided to use a tableLayoutPanel as a placeholder for them.

It’s amazing, but  my first try was enough to find a bug:  the panel was rendered correctly, but when changing the focus on his controls, the scrollbar didn’t scroll correctly, and even when rolling down the scrollbar and try to select another control, the scrollbar rolled up!

The code to reproduce this  problem :

private void Form1_Load(object sender, EventArgs e)
{
  this.Size = new Size(400, 400);
  this.CenterToScreen();
  TableLayoutPanel tlp = new TableLayoutPanel()
  {
    AutoScroll = true,
    Dock = DockStyle.Fill,
    ColumnCount = 2,
    RowCount = 50,
    Parent = this
  };
  this.Controls.Add(tlp);
  for (int i = 0; i &lt; 100; i++)
    tlp.Controls.Add(
      ((i % 2 == 0)
        ? (Control)new Label() { Text = i.ToString(), Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleRight}
        : (Control)new TextBox() { Text = i.ToString(), Dock = DockStyle.Bottom, TextAlign = HorizontalAlignment.Center })
      );
}

Run it and press Tab key until you can see the bug… If you change the textbox.Dock = DockStyle.Bottom to any other DosckStyle, the problem disappears!