Thursday, October 1, 2009

How to automatically register CpcView Registration Key Using ASp.NET Web Forms

I came cross problem where i have to register activex control via web application. I thought putting this sample will help other users who can use my code for further registration key which are on provided on third party website. such as cartesiannic where we have to send user and password information and they post regkey on there website. So this is how I have used to register this automatically via web application

If you ever used cartesianinc cpc view controls then you can register components via website automatically

Page 1. will have in html source code: (uncomment code below)
<!--embed type="image/cpi" width="0" height="0" redirect='<%=href%>'-->

Page 1. Code behind will have:

Imports System.Web
Partial Public Class _Default
Inherits System.Web.UI.Page
Dim embed_src As String = "RegisterCPCView.aspx"

Property href() As String
Get
Return embed_src
End Get
Set(ByVal value As String)
embed_src = value
End Set
End Property 'href

End Class

In your Page 2 "RegisterCPCView" form you will write:

Imports System
Imports System.Xml
Imports System.IO
Imports System.Net

Partial Public Class RegisterCPCView
Inherits System.Web.UI.Page

Private accountID As String = "username"
Private accountPW As String = "password"
Private regKey As String = ""
Private myPageInstace As New Control
Private fs As FileStream
Private URL As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'reg.cgi?product=cpcview&build=33&autoreg=0&license=individual&version=6.5.1AX&arch=33333&days=333&docs=33

Dim arch As String = ""
arch = Request.QueryString("arch")
Dim cartesianURL As String = "http://www.cartesianinc.com/Prepaid/Ops/GetLicense.cgi"
URL = cartesianURL + "?accountID=" + accountID + "&" + "accountPW=" + accountPW + "&" + "machineID=" + arch

GetKey()
End If
End Sub

Property href() As String
Get
Return regKey
End Get
Set(ByVal value As String)
regKey = value
End Set
End Property 'href

Private Sub GetKey()
Dim objWebClient As New WebClient()
Dim strURL As String = URL
Dim objUTF8 As New UTF8Encoding()
Dim htrmlSource As String = objUTF8.GetString(objWebClient.DownloadData(strURL))

href = Mid(htrmlSource, 9, 16)

Response.Redirect("~/RegisterCPCViewComplete.aspx?reg=" + href)
End Sub

End Class

In your Page 3 "RegisterCPCViewComplete.aspx" you will register the reterive registration key which you have get back from : "http://www.cartesianinc.com/Prepaid/Ops/GetLicense.cgi" third party

Page 3 Html Source Code:(uncomment code below)
<!--embed type="image/cpi" width="0" height="0" regKey='<%=href%>'-->

Page 3 Code behind:
Public Partial Class RegisterCPCViewComplete
Inherits System.Web.UI.Page
Private regKey As String = ""

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not String.IsNullOrEmpty(Request.QueryString("reg")) Then
href = Request.QueryString("reg")
End If
End Sub

Property href() As String
Get
Return regKey
End Get
Set(ByVal value As String)
regKey = value
End Set
End Property 'href
End Class

Thank You.
Please don't forget to visit:

http://www.netfixllc.com
http://www.lendmyspace.com
http://www.lookfordeal.com

Wednesday, July 1, 2009

Create Store Procedure In Oracle For Count and Call from Vb.NET Code

-----------------------------
Create procedure in Oracle:
-----------------------------
create or replace PROCEDURE SP_GET_UserCOUNT (returnval out number) AS
BEGIN
select count(*) into returnval from (select * from usertable);

END SP_GET_UserCOUNT;

-----------------------------
Call form you vb function
-----------------------------
#Region "getUserCount"
Public Shared Function getUserCount() As Integer
Dim returncount As Integer
Try

'Using conn As OracleConnection = New OracleConnection(connecitonstring)
Using conn As OracleConnection = New OracleConnection(My.Settings.sConnectionString)
conn.Open()

Dim cmdTyProcessTbl As OracleCommand = New OracleCommand("", conn)
cmdTyProcessTbl.CommandText = "SP_GET_UserCOUNT"
cmdTyProcessTbl.CommandType = Data.CommandType.StoredProcedure

Dim prm As OracleParameter = New OracleParameter("a", OracleDbType.Int32)
prm.Direction = Data.ParameterDirection.Output
cmdTyProcessTbl.Parameters.Add(prm)

cmdTyProcessTbl.ExecuteNonQuery()
cmdTyProcessTbl.Dispose()

returncount = prm.Value.ToString

conn.Close()
conn.Dispose()
GC.Collect()
End Using

Return Convert.ToInt32(returncount)

Catch ex As Exception
Throw ex
End Try
End Function
#End Region

Tuesday, June 23, 2009

Learn how to scale your application cache on multiple servers (really cool)

Developer now can scale there .NET application objects in cache from string to binary objects using "Velocity"

Overview: Microsoft project code named “Velocity” provides a highly scalable in-memory application cache for all kinds of data. By using cache, you can significantly improve application performance by avoiding unnecessary calls to the data source. Distributed cache enables your application to match increasing demand with increasing throughput by using a cache cluster that automatically manages the complexities of load balancing. When you use “Velocity,” you can retrieve data by using keys or other identifiers, named “tags.” “Velocity” supports optimistic and pessimistic concurrency models, high availability, and a variety of cache configurations. “Velocity” includes an ASP.NET session provider object that enables you to store ASP.NET session objects in the distributed cache without having to write to databases, which increases the performance and scalability of ASP.NET applications.
You can checkout this webcast for complete understanding:
http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032413050&EventCategory=5&culture=en-US&CountryCode=US

Saturday, June 6, 2009

Retrieve Images that are saved in your Oracle tables as Blog

Ok. If you have images that are saved in your blob field. You can download then into your code as shown below.

Please don't forget visit my website at: www.lendmyspace.com and www.lookfordeal.com

Public Function saveBlobImages() As Single
Dim sqlStr1 As String
Dim cmd As New OracleClient.OracleCommand
Dim oraDa As OracleDataAdapter
Dim conn As OracleConnection = Nothing
Dim ms As MemoryStream = Nothing
Dim dsImage As Data.DataSet = Nothing
Dim myBytes() As Byte = Nothing
Dim imgJPG As System.Drawing.Image = Nothing
Dim msOut As MemoryStream = Nothing

Try

sqlStr1 = "select Image_Name, image_ID, blob_image from image_table where rownum < 100"

' Initialize connection
oraDa = New OracleDataAdapter(sqlStr1, My.Settings.sConnectionString)
conn = oraDa.SelectCommand.Connection
dsImage = New Data.DataSet()
oraDa.Fill(dsImage, "ImageTifImages")

If dsImage.Tables(0).Rows.Count = 0 Then
Throw New Exception("No results returned for rows")
Else

For i As Integer = 0 To dsImage.Tables(0).Rows.Count - 1

myBytes = dsImage.Tables(0).Rows(i)("blob_image")
ms = New MemoryStream
ms.Write(myBytes, 0, myBytes.Length)
imgJPG = Image.FromStream(ms)

'Export to TIF Stream
msOut = New MemoryStream
imgJPG.Save(msOut, System.Drawing.Imaging.ImageFormat.Jpeg)
imgJPG.Dispose()
imgJPG = Nothing
ms.Write(myBytes, 0, myBytes.Length)
imgJPG = System.Drawing.Image.FromStream(ms)
Dim filename As String = dsImage.Tables(0).Rows(i)("Image_Name").ToString + "_" + dsImage.Tables(0).Rows(i)("Image_id").ToString
filename = filename.Replace(".txt", "")
imgJPG.Save(filename + ".Tif")
ms.Close()
Next
End If

Catch ex As Exception
Throw
End Try

End Function

Thursday, May 21, 2009

Azure - Simple Applicaiton - Security Exception Error

I have recently deploy Azure Application to see how Microsoft Cloud Application will work. In this process I come across Security Exception Error which took me while to figure out. So, if you have same issue make sure you do the following:

Here is the error message:

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.

1. In your "could" project make sure you open ".csdef" file and edit the following
WebRole name="WebRole" enableNativeCodeExecution="true">

Make sure you have enableNativeCodeExecution="true"

2. You should also make your "web_role" project open web.config file and make sure you have the following:


3. If you page still gives error message then you set all your <@Page Debug = "true"

4. Make sure you have customErrors mode="Off" in web.config file


This should make your application work on Azure Cloud Please don't forget to visit my website at: http://www.lookfordeal.com

Tuesday, May 12, 2009

Oracle Package - Basics

Here is a sample of oracle package in which I will send startIndex as integer and endIndex as integer. In returns it will return me customer list

create or replace PACKAGE BODY PKG_GET_THANKYOU_customer_LIST AS

procedure getThankyouNames(startIndex IN number, endIndex in number,myMethodCode in varchar2, out_cursor OUT Thank_Cur) AS

localThank_Cursor Thank_cur;
BEGIN
/* TODO implementation required */
/* delete from temp_ty; */
insert into temp_thankyou_cust_list
select t3.customer_sid, ws1.order_sid, t2.order_code,max(ws1.order_date) order_date, rnum,t3.cust_company_name,
t3.cust_name,t3.cust_title, t3.cust_Phone, t3.cust_phone_ext, t3.cust_fax, t3.cust_STREET_ADDR_LINE1,
t3.cust_STREET_ADDR_LINE2,t3.cust_CITY,t3.cust_ZIP_CODE,t3.cust_ZIP_PLUS4,t3.cust_STATE_CODE,
t3.MY_METHOD_CODE
from work_table_order t2, work_spec_table ws1,
(select * from
(select t1.*, rownum rnum from
(select distinct c1.customer_sid, c1.cust_company_name, c1.cust_name,
c1.cust_title, c1.cust_Phone, c1.cust_phone_ext, c1.cust_fax,
c1.cust_STREET_ADDR_LINE1, c1.cust_STREET_ADDR_LINE2, c1.cust_CITY,
c1.cust_ZIP_CODE,c1.cust_ZIP_PLUS4,c1.cust_STATE_CODE,c1.RPC_METHOD_CODE
from customer c1, work_productive_order wp1
where c1.MY_METHOD_CODE = myMethodCode and c1.customer_sid = wp1.customer_sid
and wp1.customer_sid not in (select customer_sid from thankyou_customers)
order by c1.customer_sid
) t1
where rownum <= endIndex
)
where rnum >= startIndex
) t3
where t2.customer_sid = t3.customer_sid and ws1.order_sid = t2.order_sid
group by ws1.order_sid,t2.order_code, t3.customer_sid, rnum, t3.cust_company_name, t3.cust_name,
t3.cust_title, t3.cust_Phone, t3.cust_phone_ext, t3.cust_fax, t3.cust_STREET_ADDR_LINE1,
t3.cust_STREET_ADDR_LINE2,t3.cust_CITY,t3.cust_ZIP_CODE,t3.cust_ZIP_PLUS4,t3.cust_STATE_CODE,t3.MY_METHOD_CODE;
open localThank_Cursor for
select ty1.*, substr(ws1.text_description,1,50)
from temp_thankyou_cust_list ty1, work_spec_table ws1
where ty1.order_sid = ws1.order_sid and ty1.order_date = ws1.order_date
order by ty1.customer_sid, ty1.order_code;
out_cursor := localThank_Cursor;

END getThankyouNames;

END PKG_GET_THANKYOU_cust_LIST;