Monday, November 18, 2013

page load asynchronous code after UI rendering (execute code after page render complete using script manager)

problem :
i have some events ( functions) should executed in page load but it consume some time to executed so i need to load the page first and silently load these funcitons to load page in little time.

solution :
using ajax script manager with EnablePageMethods="true"  to execute asynchronous functions
using javascipt PageMethods function.

copy and past the following code in new web site to test
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Async="true" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">


        function CallServerSideFunction2() {
            //calling our page method 'CallFromClient1'
            debugger;
            PageMethods.CallFromClient2(OnSucceeded2, OnFailed2);
            return false;
        }


        function OnSucceeded2(result) {
            var div1 = $get("Div1");
            var oNewNode = document.createElement("LI");
            div1.appendChild(oNewNode);
            oNewNode.innerText = result;
        }


        function OnFailed2(error) {
            // Alert user to the error.
            alert(error.get_message());
        }
    </script>
</head>
<body>
    <form id="form2" runat="server">
           <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
        <div runat="server" id="Div1"></div>

        <div>

        You page Html  goes here 
        </div>
    </form>
</body>
</html>

vb file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "getprice", "CallServerSideFunction2();", true);

   

    }


    [WebMethod]
    //This is our page method!
    //This function can carry out the server processing like fetching the values from DB
    public static string CallFromClient2()
    {
        Thread.Sleep(5000);
        return "$1120";
    }
}
--------------------------
the idea is using static web method to handle the event consuming time and register startup script using script manager then get value from web method and bind it to page control using javascript handlers for the script manager .
this manner let the page loads and then call web service function to get long time operation and bind result value silently to page control using normal javascript.

problem : the web method must be static to be accessed by script manager javascript function PageMethods
so if you need to use session inside the web method you can use :HttpContext.Current.Session[""].ToString

Tuesday, November 5, 2013

SMPP Client Program Using Jamaa SMPP Client

the following code working for SMPP request using jamaa smpp library.
download dss from the following link
https://jamaasmpp.codeplex.com/releases/view/65964

then create new windows application or console application and paste the following code and change you SMSC provider data
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using JamaaTech.Smpp.Net.Client;
using JamaaTech.Smpp.Net.Lib;
using JamaaTech.Smpp.Net.Lib.Protocol;

namespace SMPP_Test
{
    public partial class Form1 : Form
    {
        SmppClient mmclient = new SmppClient();
        SmppConnectionProperties mmproperties;
        TextMessage mymsg = new TextMessage();
        public Form1()
        {
            InitializeComponent();
            mmproperties = mmclient.Properties;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            mmproperties.SystemID = "YourSystemID";
            mmproperties.Password = "YourPassword";
            mmproperties.Port = 23651; //IP port to use
            mmproperties.Host = "xxx.net"; //SMSC host name or IP Address
            mmproperties.SystemType = "";
         

            //Resume a lost connection after 30 seconds
            mmclient.AutoReconnectDelay = 3000;
            //Send Enquire Link PDU every 30 seconds
            mmclient.KeepAliveInterval = 30000;
            //Start smpp client
          
           // mmclient.Connect
            mmclient.Properties.InterfaceVersion = InterfaceVersion.v34;
            mmclient.Properties.DefaultEncoding = DataCoding.SMSCDefault;
            mmclient.Properties.SourceAddress = "MadinaWater";
            mmclient.Properties.AddressNpi = NumberingPlanIndicator.Unknown;
            mmclient.Properties.AddressTon = TypeOfNumber.Unknown;
            mmclient.Properties.SystemType = "transceiver";
            mmclient.Properties.DefaultServiceType = ServiceType.DEFAULT;// "transceiver";      
            
            mmclient.MessageReceived += mmclient_MessageReceived;
            mmclient.MessageDelivered += mmclient_MessageDelivered;
            mmclient.MessageSent += mmclient_MessageSent;


            mymsg.DestinationAddress = "+966562824865"; //Receipient number
            mymsg.SourceAddress = "ShortCodeRelated Your Provider"; //Originating number
            mymsg.Text = "Hello, this is my simple client test message!";
            mymsg.RegisterDeliveryNotification = true; //I want delivery notification for this message
         
            mmclient.Start();
            if(mmclient.ConnectionState != SmppConnectionState.Connected )
                mmclient.ForceConnect(5000);
            mmclient.SendMessage(mymsg,1000);
           

            //Provide a handler for the SmppClient.MessageReceived event
          
            mmclient.Shutdown();
           
            ////Resume a lost connection after 30 seconds
            //client.AutoReconnectDelay = 3000;
            ////Send Enquire Link PDU every 15 seconds
            //client.KeepAliveInterval = 15000;

            ////Start smpp client
            //client.Start();
            //TextMessage msg = new TextMessage();
            //msg.DestinationAddress = "+966562824865";
            //msg.Text = "تجربة الإرسال من ال SMPP";
            //msg.SourceAddress = "MWater";
            //client.SendMessage(msg,3000);
           


        }

        void mmclient_MessageSent(object sender, MessageEventArgs e)
        {

            JamaaTech.Smpp.Net.Client.TextMessage textMsg = e.ShortMessage as JamaaTech.Smpp.Net.Client.TextMessage;
            MessageBox.Show(textMsg.Text);

            TextMessage msg = e.ShortMessage as TextMessage;
            string SegID = msg.SegmentID.ToString(); //Gives the message ID from the SMPP on Send 
            string Seg = msg.SequenceNumber.ToString(); //Give the status of the message - Enroute

            MessageBox.Show(msg.Text); //Display message

        }

        void mmclient_MessageDelivered(object sender, MessageEventArgs e)
        {
            JamaaTech.Smpp.Net.Client.TextMessage textMsg = e.ShortMessage as JamaaTech.Smpp.Net.Client.TextMessage;
            MessageBox.Show(textMsg.Text);
           
        }

        void mmclient_MessageReceived(object sender, MessageEventArgs e)
        {
            //The event argument e contains more information about the received message       

            JamaaTech.Smpp.Net.Client.TextMessage textMsg = e.ShortMessage as JamaaTech.Smpp.Net.Client.TextMessage; //This is the received text message                  

           //richTextBox1.Text = richTextBox1.Text + textMsg + " Step 1";
            
            string msgInfo = string.Format("Sender: {0}, Receiver: {1}, Message content: {2}", textMsg.SourceAddress, textMsg.DestinationAddress, textMsg.Text);

            //Display message             MessageBox.Show(msgInfo);       

            //     richTextBox1.Text = richTextBox1.Text + msgInfo;

        }
    }
}

Saturday, March 23, 2013

window server 2008 r2 remove Failover Cluster

to remove FailOver Cluster from server follow these steps

Run powershell as an administrator

Import-Module FailoverClusters

then clear-clusternode

Monday, November 5, 2012

change RadGrid Telrik Control Filter Globalization Text

the function to change filter Text to be in arabic language for radGrid Control
Imports Telerik.Web.UI
Public Sub ChangeRadGridFilterText()
        Dim Menu As GridFilterMenu = RadGrid1.FilterMenu
        Dim item As RadMenuItem
        For Each item In Menu.Items

            Select Case item.Text

                Case "NoFilter"
                    item.Text = "كل العناصر بدون تصفية"
                Case "Contains"
                    item.Text = "يحتوي على"
                Case "DoesNotContain"
                    item.Text = "لا يحتوي على"
                Case "StartsWith"
                    item.Text = "يبدأ ب "
                Case "EndsWith"
                    item.Text = "ينتهي ب "
                Case "EqualTo"
                    item.Text = "يساوي قيمة "
                Case "NotEqualTo"
                    item.Text = "لا يساوي قيمة "
                Case "GreaterThan"
                    item.Text = "أكبر من  "
                Case "LessThan"
                    item.Text = "أقل من  "
                Case "GreaterThanOrEqualTo"
                    item.Text = "أكبر من أو يساوي  "
                Case "LessThanOrEqualTo"
                    item.Text = "أقل من أو يساوي  "
                Case "Between"
                    item.Text = "بين رقمين "
                Case "NotBetween"
                    item.Text = "ليس بين رقمين "
                Case "IsEmpty"
                    item.Text = "قيمة فارغ  "
                Case "NotIsEmpty"
                    item.Text = "ليس قيمة فارغة  "
                Case "IsNull"
                    item.Text = "يساوي Null "
                Case "NotIsNull"
                    item.Text = "لا يساوي Null "
            End Select
        Next
    End Sub

Friday, September 7, 2012

set flash in object tag transparent to all page contents such as menues

  <object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj2" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
            border="0" width="400px" height="288px" usemap="images/MapStatement.swf">
            <param name="movie" value="images/MapStatement.swf" />
            <param name="quality" value="High" />
            <param name="wmode" value="transparent" />
            <embed src="images/map.swf" pluginspage="http://www.macromedia.com/go/getflashplayer"
                type="application/x-shockwave-flash" name="obj2" width="400px" height="288px"
                wmode="transparent" /></object>



as the example we have wmode property and wmode parameter to affects on flash transparency .



Monday, July 23, 2012

Read Rss feed using vb.net

the following code sample read from Rss Xml File and write file content as html inside iframe in web page .
Imports System.Xml
Imports System.ServiceModel.Syndication

 Sub Press_News_Get()
 
        Try
            Dim ARB As String = Server.MapPath("intranet/Saudi_Press_Agent.xml")
            Dim reader As New XmlTextReader(ARB)
            Dim feed As SyndicationFeed = SyndicationFeed.Load(reader)

            For Each item As SyndicationItem In feed.Items
                Dim NewTitle As String = item.Title.Text
                Dim url As String = item.Links(0).Uri.ToString()
                Dim lnk As New HtmlAnchor
                lnk.InnerHtml = NewTitle
                lnk.HRef = url
                lnk.Target = "_blank"
                ml.Controls.Add(New LiteralControl("<span class=""sep"">وكالة الأنباء السعودية</span>"))
                ml.Controls.Add(lnk)
                ml.Attributes.Add("style", "color:blue;;margin:0px;padding:0px")

                ml.Controls.Add(New LiteralControl("&nbsp;&nbsp;&nbsp;&nbsp;"))
                lnk.Attributes.Add("style", "text-decoration:none;margin:0px;padding:0px")
            Next
 Catch ex As Exception
            Response.Write(ex.Message)
        End Try

    End Sub

Sunday, July 22, 2012

Create Rss Using System.ServiceModel.Syndication

To Create Rss Using System.ServiceModel.Syndication
add reference for the library in your project .

step2: Create your Rss XML using this function sample
Public Function GetNewsRss() As Rss20FeedFormatter
        Dim feed As SyndicationFeed = New SyndicationFeed()
        feed.Authors.Add(New SyndicationPerson("info@mwa.gov.sa"))
        'feed.Categories.Add(New SyndicationCategory("How To Sample Code"))
        feed.Description = New TextSyndicationContent("أخر الاخبار الخاصة بالمديرية العامة للمياه بمنطقة المدينة المنورة")
        feed.Title = New TextSyndicationContent("أخبار المديرية العامة للمياه بمنطقة المدينة المنورة")
        feed.Copyright = New TextSyndicationContent("جميع الحقوق محفوظة لموقع المديرية العامة للمياه بمنطقة المدينة المنورة")
        feed.Links.Add(New SyndicationLink(New Uri("http://www.mwa.gov.sa/index.aspx")))

        Dim objConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("mwa_mwa_gov_saConnectionString").ConnectionString)
        Dim sql As String = "SELECT News.FrontID,News.Headline, News.InnerNews, NewsImage.NImage, News.NImage_ID, News.LinkType, News.MoreLink, News.Headline FROM News LEFT OUTER JOIN NewsImage ON News.NImage_ID = NewsImage.NImage_ID WHERE (News.ShowFront = 'true') ORDER BY News.FColOrder"
        Dim adp As New SqlDataAdapter(sql, objConnection)
        Dim ds As New DataSet
        objConnection.Open()
        adp.Fill(ds)
        objConnection.Close()
        Dim items As New List(Of SyndicationItem)()
        If (ds.Tables(0).Rows.Count > 0) Then
            Dim i As Integer
            For i = 0 To ds.Tables(0).Rows.Count - 1
                Dim NewItem As SyndicationItem = New SyndicationItem( _
                           ds.Tables(0).Rows(i)("Headline").ToString(), _
                           ds.Tables(0).Rows(i)("InnerNews").ToString(), _
                           New Uri("http://www.mwa.gov.sa/News.aspx?ID=" & ds.Tables(0).Rows(i)("FrontID").ToString()), _
                           "New_" & i, _
                            DateTime.Now)
                items.Add(NewItem)

            Next
            feed.Items = items
        End If
        Return New Rss20FeedFormatter(feed)
    End Function

------------------------------------------------------------------------
step3: Response in page load with Rss20FeedFormatter returned from your previous function .

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Clear()
        Response.ContentEncoding = System.Text.Encoding.UTF8
        Response.ContentType = "text/xml"

        Dim rssWriter As XmlWriter = XmlWriter.Create(Response.Output)
        Dim rssFormatter As New Rss20FeedFormatter()
        rssFormatter = GetNewsRss()
        rssFormatter.WriteTo(rssWriter)
        rssWriter.Close()

        Response.End()

    End Sub