Quieres saber lo que es ser un MVP?
Publicado: 27/04/2007 Archivado en: Uncategorized Deja un comentario »
http://images.soapbox.msn.com/flash/soapbox1_1.swf
Video: I Feel Great! – MVP
IQ Test
Publicado: 17/04/2007 Archivado en: Uncategorized 2 Comentarios »Control ASP.net parte III
Publicado: 16/04/2007 Archivado en: Uncategorized 7 Comentarios »Control ASP.net parte II
Publicado: 16/04/2007 Archivado en: Uncategorized Deja un comentario »Clase: ImageEngine.vb
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Drawing
Imports System.Drawing.Imaging
Public Class ImageEngine
: Implements IHttpHandler
Private Const _TotalParams As Integer = 19
Private _ImageWidth As Integer
Private _ImageHeight As Integer
Private _Word As String
Private _FontColor As Brush
Private _BackGroundColor As Color
Private _BorderColor As Pen
Private _FontPostX As Integer
Private _FontPostY As Integer
Private _BorderWidth As Single
Private _RandomMask As Boolean
Private _PicFormat As Boolean
Private _MaskColor As Pen
Private _MaskLevel As Integer
Private _FontType As String
Private _FontStyle As Integer = 0
Private _FontSize As Integer
Private Function AssignValues(ByVal strValueString As String) As Boolean
Dim strSplitter() As String = strValueString.Split(";")
_FontStyle = 0
If strSplitter.Length = _TotalParams Then
Try
_ImageWidth = Unit.Parse(strSplitter(0)).Value
_ImageHeight = Unit.Parse(strSplitter(1)).Value
_Word = CType(strSplitter(2), String)
_FontColor = New System.Drawing.SolidBrush(ColorTranslator.FromHtml(CType(strSplitter(3), String)))
_BackGroundColor = ColorTranslator.FromHtml(CType(strSplitter(4), String))
_BorderWidth = CType(strSplitter(6), Single)
_BorderColor = New System.Drawing.Pen(ColorTranslator.FromHtml(CType(strSplitter(5), String)), CType(strSplitter(6), Single))
_FontPostX = CType(strSplitter(7), Integer)
_FontPostY = CType(strSplitter(8), Integer)
_RandomMask = CType(strSplitter(9), Boolean)
_PicFormat = CType(strSplitter(10), Boolean)
_FontType = CType(strSplitter(11), String)
If _FontType.Length = 0 Then _FontType = "Time New Roman"
If CType(strSplitter(12), Boolean) Then _FontStyle += 1
If CType(strSplitter(13), Boolean) Then _FontStyle += 2
If CType(strSplitter(14), Boolean) Then _FontStyle += 8
If CType(strSplitter(15), Boolean) Then _FontStyle += 4
Select Case strSplitter(16)
Case "Larger", "X-Large", "XX-Large"
_FontSize = 14
Case "Smaller"
_FontSize = 8
Case "XX-Small", "X-Small", "Small"
_FontSize = 6
Case "Medium"
_FontSize = 10
Case "Large"
_FontSize = 12
Case Else
_FontSize = Unit.Parse(strSplitter(16)).Value
End Select
If _FontSize = 0 Then _FontSize = 8
_MaskColor = New System.Drawing.Pen(ColorTranslator.FromHtml(CType(strSplitter(17), String)))
_MaskLevel = CType(strSplitter(18), Integer) * 5
Return True
Catch ex As Exception
Throw ex
End Try
Else
Throw New Exception("Bad parameters")
End If
End Function
Private Function ContextIsValid(ByVal strContext As String) As Boolean
If strContext <> Nothing AndAlso strContext.Length > 0 Then
Return True
Else
Return False
End If
End Function
Public Sub ProcessRequest(ByVal Context As HttpContext) Implements IHttpHandler.ProcessRequest
Try
If ContextIsValid(Context.Request.QueryString("Image")) Then
Dim _Helper As NaturalHelp = New NaturalHelp
If AssignValues(_Helper.DecryptToBase64(Context.Request.QueryString("Image"))) Then
If _PicFormat Then
Context.Response.ContentType = "image/jpeg"
Else
Context.Response.ContentType = "image/gif"
End If
‘Create buffer and set size
Dim oBitmap As Bitmap = New Bitmap(_ImageWidth, _ImageHeight)
Dim oGraphic As Graphics = Graphics.FromImage(oBitmap)
‘Set Background Color
oGraphic.Clear(_BackGroundColor)
‘Assing Word, Font Color, Font Size, Font Family
‘Setting the font style
oGraphic.DrawString(_Word, _
New System.Drawing.Font(_FontType, _FontSize, _FontStyle, GraphicsUnit.Point), _
_FontColor, _FontPostX, _FontPostY)
If _RandomMask Then
Dim _RND As New Random(10)
Dim _RndNumber As Integer
Dim _blnOrientation As Boolean = False
For i As Integer = 0 To _ImageWidth
For j As Integer = 0 To _ImageHeight
_RndNumber = _RND.Next(0, _MaskLevel)
If _RndNumber = 3 Then
If _blnOrientation Then
oGraphic.DrawLine(_MaskColor, i, j, i + 1, j – 1)
Else
oGraphic.DrawLine(_MaskColor, i, j, i – 1, j + 1)
End If
_blnOrientation = Not _blnOrientation
End If
Next
Next
End If
‘Create Border
If _BorderWidth <> 0 Then
oGraphic.DrawLine(_BorderColor, 0, 0, _ImageWidth, 0)
oGraphic.DrawLine(_BorderColor, 0, _ImageHeight – 1, _ImageWidth, _ImageHeight – 1)
oGraphic.DrawLine(_BorderColor, 0, 0, 0, _ImageHeight – 1)
oGraphic.DrawLine(_BorderColor, _ImageWidth – 1, 0, _ImageWidth – 1, _ImageHeight – 1)
End If
‘Write all into the buffer
If _PicFormat Then
oBitmap.Save(Context.Response.OutputStream, ImageFormat.Jpeg)
Else
oBitmap.Save(Context.Response.OutputStream, ImageFormat.Gif)
End If
End If
End If
Catch ex As Exception
Context.Response.ContentType = "image/jpeg"
Dim oBitmap As Bitmap = New Bitmap(150, 50)
Dim oGraphic As Graphics = Graphics.FromImage(oBitmap)
oGraphic.Clear(Color.White)
oGraphic.DrawString(ex.Message, _
New System.Drawing.Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point), _
Brushes.Black, 1, 1)
oBitmap.Save(Context.Response.OutputStream, ImageFormat.Jpeg)
End Try
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
Clase: NaturalHelp.vb
Imports System.Text
Imports System.Drawing
Friend Class NaturalHelp
”’ <summary>
”’ Encrypt a string value to base 64
”’ </summary>
”’ <param name="strText">Text to encrypt</param>
”’ <returns>Base 64 string value</returns>
”’ <remarks></remarks>
Public Function EncryptToBase64(ByVal strText As String) As String
Dim _btyEncoded As Byte() = Encoding.ASCII.GetBytes(strText)
Return Convert.ToBase64String(_btyEncoded)
End Function
”’ <summary>
”’ Decrypt a base 64 string to string
”’ </summary>
”’ <param name="strText">Base 64 string to decrypt</param>
”’ <returns>Decrypted string</returns>
”’ <remarks></remarks>
Public Function DecryptToBase64(ByVal strText As String) As String
Dim _btyDecoded As Byte() = Convert.FromBase64String(strText)
Dim _oByteDecoder As New System.Text.ASCIIEncoding
Return _oByteDecoder.GetString(_btyDecoded)
End Function
End Class
Control ASP.net
Publicado: 16/04/2007 Archivado en: Uncategorized 2 Comentarios »Hace unas semanas atrás di una conferencia sobre creación de controles de usuario y controles personalizados para ASP.net.
En esta, mostré un control personalizado que había realizado hace un tiempo atrás, el cual tiene como objetivo emular esta no tan nueva funcionalidad, pero siendo usada mas comúnmente últimamente en el logueo de usuarios. Básicamente, una imagen con caracteres que validan que el usuario no sea un robot, obligando al usuario (humano) deducir la imagen en cuestión y escribir estos caracteres en una caja de texto, finalizando la validación.
En definitiva, aquí van las tres clases que hacen esto posible (Desde el control que cree).
Clase: AutoImage.vb
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Text
Imports System.ComponentModel
Imports System.Web.UI.WebControls
Imports System.Drawing
Namespace SpecialTools.AutoImage
<ToolboxBitmap("C:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005ProjectsAutoImageTestAutoImageGenAutoImage.bmp")> _
Public Class AutoImage
Inherits WebControl
Implements INamingContainer
#Region "Private Variables"
Public Enum ImageFormat
Gif = 0
Jpg = 1
End Enum
Public Enum MaskLevel
High = 1
Medium = 2
Low = 3
End Enum
Protected _PalletBuffer As New Web.UI.WebControls.Image
Private _FontColor As String
Private _Word As String
Private _BackGroundColor As String
Private _BorderColor As String
Private _BorderWidth As Unit
Private _FontX As Integer
Private _FontY As Integer
Private _RandomMask As Boolean
Private _PicFormat As ImageFormat
Private _MaskColor As String
Private _MaskLevel As MaskLevel
#End Region
#Region "Propiedades"
#Region "Main Properties"
”’ <summary>
”’ Set or Get the text represented by the control
”’ </summary>
”’ <value></value>
”’ <returns></returns>
”’ <remarks></remarks>
<Category("Behavior"), Description("Set or Get the text represented by the control")> _
Public Property Word() As String
Get
EnsureChildControls()
Return _Word
End Get
Set(ByVal value As String)
EnsureChildControls()
_Word = value.Replace(";", ",").ToString()
SetProperties()
End Set
End Property
#End Region
#Region "Overrides Properties"
Public Overrides Property BorderColor() As System.Drawing.Color
Get
EnsureChildControls()
Return Drawing.ColorTranslator.FromHtml(_BorderColor)
End Get
Set(ByVal value As System.Drawing.Color)
EnsureChildControls()
_BorderColor = Drawing.ColorTranslator.ToHtml(value)
SetProperties()
End Set
End Property
Public Overrides Property BorderWidth() As System.Web.UI.WebControls.Unit
Get
EnsureChildControls()
Return _BorderWidth
End Get
Set(ByVal value As System.Web.UI.WebControls.Unit)
EnsureChildControls()
_BorderWidth = value
SetProperties()
End Set
End Property
Public Overrides Property ForeColor() As System.Drawing.Color
Get
EnsureChildControls()
Return Drawing.ColorTranslator.FromHtml(_FontColor)
End Get
Set(ByVal value As Drawing.Color)
EnsureChildControls()
_FontColor = Drawing.ColorTranslator.ToHtml(value)
SetProperties()
End Set
End Property
Public Overrides Property Width() As System.Web.UI.WebControls.Unit
Get
EnsureChildControls()
Return MyBase.Width
End Get
Set(ByVal value As System.Web.UI.WebControls.Unit)
EnsureChildControls()
_PalletBuffer.Width = value
MyBase.Width = value
SetProperties()
End Set
End Property
Public Overrides Property Height() As System.Web.UI.WebControls.Unit
Get
EnsureChildControls()
Return MyBase.Height
End Get
Set(ByVal value As System.Web.UI.WebControls.Unit)
EnsureChildControls()
_PalletBuffer.Height = value
MyBase.Height = value
SetProperties()
End Set
End Property
Public Overrides Property BackColor() As System.Drawing.Color
Get
EnsureChildControls()
Return Drawing.ColorTranslator.FromHtml(_BackGroundColor)
End Get
Set(ByVal value As System.Drawing.Color)
EnsureChildControls()
_BackGroundColor = Drawing.ColorTranslator.ToHtml(value)
SetProperties()
End Set
End Property
Public Overrides ReadOnly Property Font() As System.Web.UI.WebControls.FontInfo
Get
SetProperties()
Return MyBase.Font
End Get
End Property
#End Region
#Region "Behavior Properties"
”’ <summary>
”’ Format of the output picture
”’ </summary>
”’ <value></value>
”’ <returns></returns>
”’ <remarks></remarks>
<Category("Behavior"), Description("Format of the output picture")> _
Public Property PictureFormat() As ImageFormat
Get
EnsureChildControls()
Return _PicFormat
End Get
Set(ByVal value As ImageFormat)
EnsureChildControls()
_PicFormat = value
SetProperties()
End Set
End Property
”’ <summary>
”’ Represent the position over X axis for the text
”’ </summary>
”’ <value></value>
”’ <returns></returns>
”’ <remarks></remarks>
<Category("Behavior"), Description("Represent the position over X axis for the text")> _
Public Property TextPositionX() As Integer
Get
EnsureChildControls()
Return _FontX
End Get
Set(ByVal value As Integer)
EnsureChildControls()
_FontX = value
SetProperties()
End Set
End Property
”’ <summary>
”’ Represent the position over Y axis for the text
”’ </summary>
”’ <value></value>
”’ <returns></returns>
”’ <remarks></remarks>
<Category("Behavior"), Description("Represent the position over Y axis for the text")> _
Public Property TextPositionY() As Integer
Get
EnsureChildControls()
Return _FontY
End Get
Set(ByVal value As Integer)
EnsureChildControls()
_FontY = value
SetProperties()
End Set
End Property
#End Region
#Region "Mask Properties"
”’ <summary>
”’ Enable a randomized mask
”’ </summary>
”’ <value></value>
”’ <returns></returns>
”’ <remarks></remarks>
<Category("Mask Property"), Description("Enable a randomized mask")> _
Public Property RandomMask() As Boolean
Get
EnsureChildControls()
Return _RandomMask
End Get
Set(ByVal value As Boolean)
EnsureChildControls()
_RandomMask = value
SetProperties()
End Set
End Property
”’ <summary>
”’ Default mask color
”’ </summary>
”’ <value></value>
”’ <returns></returns>
”’ <remarks></remarks>
<Category("Mask Property"), Description("Default mask color")> _
Public Property MaskColor() As Drawing.Color
Get
EnsureChildControls()
Return Drawing.ColorTranslator.FromHtml(_MaskColor)
End Get
Set(ByVal value As System.Drawing.Color)
EnsureChildControls()
_MaskColor = Drawing.ColorTranslator.ToHtml(value)
SetProperties()
End Set
End Property
”’ <summary>
”’ Ammount of noise for apply to the mask
”’ </summary>
”’ <value></value>
”’ <returns></returns>
”’ <remarks></remarks>
<Category("Mask Property"), Description("Ammount of noise for apply to the mask")> _
Public Property MaskProperty() As MaskLevel
Get
EnsureChildControls()
Return _MaskLevel
End Get
Set(ByVal value As MaskLevel)
EnsureChildControls()
_MaskLevel = value
SetProperties()
End Set
End Property
#End Region
#End Region
#Region "Common Functions"
Private Sub SetProperties()
Dim _Helper As New NaturalHelp
Dim _strResultBase64 As String
With _PalletBuffer
.ID = Me.ClientID & "_Pallet"
.Visible = True
_strResultBase64 = _Helper.EncryptToBase64(_PalletBuffer.Width.ToString() & _
";" & _PalletBuffer.Height.ToString() & _
";" & _Word & _
";" & _FontColor & _
";" & _BackGroundColor & _
";" & _BorderColor & _
";" & _BorderWidth.Value & _
";" & _FontX.ToString & _
";" & _FontY.ToString & _
";" & _RandomMask.ToString & _
";" & CType(_PicFormat, Integer) & _
";" & MyBase.Font.Name.ToString() & _
";" & MyBase.Font.Bold.ToString & _
";" & MyBase.Font.Italic.ToString & _
";" & MyBase.Font.Strikeout.ToString & _
";" & MyBase.Font.Underline.ToString & _
";" & MyBase.Font.Size.ToString() & _
";" & _MaskColor & _
";" & CType(_MaskLevel, Integer))
.ImageUrl = "UltraToolsImageEngine.aspx?Image=" & _strResultBase64
End With
End Sub
#End Region
Public Sub New()
MyBase.Width = 100
MyBase.Height = 40
‘_Word = "AutoImage from " & vbCrLf & "UltraTools"
With _PalletBuffer
.Width = 100
.Height = 40
End With
_FontX = 1
_FontY = 1
_FontColor = Drawing.ColorTranslator.ToHtml(Drawing.Color.Black)
_BackGroundColor = Drawing.ColorTranslator.ToHtml(Drawing.Color.White)
_BorderColor = Drawing.ColorTranslator.ToHtml(Drawing.Color.White)
_RandomMask = False
_PicFormat = ImageFormat.Gif
_MaskLevel = MaskLevel.Medium
_MaskColor = Drawing.ColorTranslator.ToHtml(Drawing.Color.Blue)
SetProperties()
End Sub
Protected Overrides Sub CreateChildControls()
EnsureChildControls()
Me.Controls.Add(_PalletBuffer)
End Sub
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
SetProperties()
End Sub
Protected Overrides Function SaveViewState() As Object
EnsureChildControls()
Dim state(14) As Object
Dim objBase As Object = MyBase.SaveViewState()
state(0) = objBase
state(1) = _PalletBuffer.Width
state(2) = _PalletBuffer.Height
state(3) = _Word
state(4) = _FontColor
state(5) = _BackGroundColor
state(6) = _BorderColor
state(7) = _BorderWidth
state(8) = _FontX
state(9) = _FontY
state(10) = _RandomMask
state(11) = _PicFormat
state(12) = _MaskColor
state(13) = _MaskLevel
Return state
End Function
Protected Overrides Sub LoadViewState(ByVal savedState As Object)
Dim state() As Object = CType(savedState, Object())
MyBase.LoadViewState(state(0))
EnsureChildControls()
_PalletBuffer.Width = state(1)
_PalletBuffer.Height = state(2)
_Word = state(3)
_FontColor = state(4)
_BackGroundColor = state(5)
_BorderColor = state(6)
_BorderWidth = state(7)
_FontX = state(8)
_FontY = state(9)
_RandomMask = state(10)
_PicFormat = state(11)
_MaskColor = state(12)
_MaskLevel = state(13)
End Sub
End Class
End Namespace
Dilbert … como la vida misma?
Publicado: 10/04/2007 Archivado en: Uncategorized 1 comentario »Como habrán podido notar, hace un tiempito que no coloco nada de código y me paso los post comentando pensamientos propios, indignaciones y demás.
Creo que es mi válvula de escape que, para aquellos que leen este blog, podrán notar que antes, podía pasar un mes sin un post hasta que llegaba uno lleno de código.
Básicamente, ahora es lo mismo, solo que ese espacio entre mes y mes simplemente lo completo con otras cosas que siempre he creído y pensando, pero que no las decía (Muy terapéutico).
A todo esto, y siguiendo con esta nueva modalidad, los invito a reír y llorar con Dilbert. (Supongo que todos los del mundillo informático habrán oído de él)
Cualquier semejanza con la vida real, es porque se hizo a propósito.
… cada uno que ponga un poquito …
Publicado: 09/04/2007 Archivado en: Uncategorized Deja un comentario »Últimamente veo muchos comentarios negativos en blogs que visito sobre .Net y tecnologías en general, y no es por levantar la bandera en pro de Microsoft, pero generalmente estos comentarios se deben a falta de conocimiento de las personas que los hacen. He visto en esos comentarios, lamentablemente, la ausencia de conocimientos sobre la tecnología. No se mal entienda, nadie nace sabiendo, y es indudable que cada vez que sale algo nuevo, son muy pocos los que saben sobre el tema, y todos salimos corriendo a tratar de averiguar de que se trata. Pero, creo que las personas que no solo no conocen sobre el tema, antes de tirarle tierra a algo, seria bueno que se instruyan. Creo que es mucho más productivo.
Esto lo digo porque veo que cuando no se entiende una tecnología MS, es muy fácil decir que no sirve, posiblemente por el trasfondo negativo de la empresa (no para mi), y creerse revolucionario por optar por la otra rama (Java, PHP, etc.), aunque en esta, tampoco se tenga un conocimiento sólido. Pero, al haberse sentido decepcionados por la tecnología Microsoft, todo ese tiempo que deberían haber invertido en aprendizaje, lo terminan invirtiendo en estas otras tecnologías, y que por supuesto, rinde. Ya que se aprende efectivamente como funcionan, reforzando más aun la creencia que la anterior tecnología efectivamente no era buena.
Posiblemente esto se deba al mensaje subliminal que se da por parte de los representantes de la empresa, y cuando digo esto, hablo desde publicidad, hasta personas que dan conferencias. Ya que en la mayoría de los casos, estos últimos, solo se limitan a hacer una carrera rápida, volando a gran altura sobre el foco de la presentación, queriendo hacer ver que todo es fácil. O en todo caso, tratando de agachar la cabeza para que la conferencia en cuestión pase lo más rápido e indoloramente posible.
No pretendo ponerme, aquí, a solucionar el problema del mundo, pero creo que si puedo dar dos sugerencias, uno para cada bando.
Primero, para aquellos que simplemente entierran todo lo que Microsoft saca solo por ser de esta marca, simplemente, antes de mal decir (no maldecir) argumentos que afecten a la tecnología presentada por la empresa, que lo hagan sabiendo. No solo por leer artículos que mal dicen a esta tecnología. Siempre es bueno conocer a fondo al enemigo!
Segundo, para el otro lado, para aquellos que promueven la tecnología. A veces, la mejor forma de vender, es vendiendo el verdadero valor del producto, no lo que se ve por fuera. Veamos la forma de llegar a lo que el usuario realmente necesita. Ver la máxima potencia del producto es muy bueno, pero en las empresas, eso se usa muy poco. O mejor dicho, el desarrollador esta sujeto a alguien más, y por lo general, hace un 99% de trabajo rutinario, donde, lo que realmente quiere es que ese trabajo sea mucho más fácil.
A ver si ambos bandos tratamos de ir para el mismo lado, que es la única forma de avanzar.
Te golpeas el pecho, pero son solo palabras…
Publicado: 09/04/2007 Archivado en: Uncategorized Deja un comentario »Mucha gente se golpea el pecho (como los monos), se rasga las vestiduras, pero son solo morisquetas para argumentar su indignación, que en la mayoría de los casos es debido a la exigencia de acciones, y no palabras.
No seas de esos que se hacen los enojados cuando te preguntan que haz hecho por los otros. No te llenes de palabras la boca. Boca de donde sale mal aliento, y no hechos.
Miles de niños sufren porque simplemente tratamos de salvarnos nosotros, sin importarnos para nada el de al lado. Se el que haga el cambio.
Estudia, ayuda, y veras que si se pueden hacer las cosas de mejor forma.
Todo esto, que espero te haya aunque sea hecho levantar una ceja, se debe a la campaña que Microsoft esta sacando para que vos, nabo, gil, tontito, estudies y con ese mínimo esfuerzo, además, ayudes a esos que a pocos les importa. Los niños:
http://www.mslatam.com/latam/msdn/comunidad/dce2005/solidaria/default.aspx


