Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to show textual events/progress in a moduleHow to show textual events/progress in a module
Previous
 
Next
New Post
3/7/2010 2:04 AM
 

Hi Experts,

I want to implement a module which calls methods from a DLL containing the business logic.

This DLL was used in a windows application and should be reused in a new dotnetnuke project.

This DLL throws events (with text) to show the progress/state of the method (which calculate something).

Whats the best way tho show this events and not using the progress bar.

Instead a simple lable control would be enough.

Many thanks in advance and

Best regarst

 
New Post
3/8/2010 2:02 AM
 

Hi,

meantime I have found this example for dealing with long processes:
http://www.ajaxmatters.com/articles/asp/long_run_process_p1.aspx

Instead of calling one Thread.Sleeping in the method LongRunningMethod I am callin ga "BusinessLogic" class with throws all 60 seconds an event.

    private void LongRunningMethod(string name)
    {
        BusinessLogic BL = new BusinessLogic();
        BL.StatusEvent += StatusEventHandler;
        BL.DoSomething();
       //Thread.Sleep(60000 * 5);//This will run for 5 mins
    }

    private void StatusEventHandler(object sender, CustomEventArgs e)
    {
        Messages.Add(e.Message);
    }

The messagelist I have handled in this method:

    public string GetCallbackResult()
    {
        if (Session["result"] != null)
        {
            IAsyncResult res = (IAsyncResult)Session["result"];
            if (res.IsCompleted)//Checking whether process is over or not
            {
                return "SUCCESS";
            }
            else
            {
                System.Text.StringBuilder MessageText = new System.Text.StringBuilder();
                foreach (string item in Messages)
                {
                    MessageText.AppendLine("Message:" + item);
                }
                return MessageText.ToString();
            }
        }
        return "FAIL";

    }

In the javascript code I have extended the code as following:

function ShowResult(eventArgument,context)
{
    if(eventArgument == "SUCCESS")
    {
        Done');
    }
    else {
    window.document.getElementById("Message").innerText = eventArgument;
    setTimeout("CallServer()",20000);//Priodic call to server.
    }
}

But the webpage does not show the events!

Whats wrong?

 
New Post
3/8/2010 2:06 AM
 

Here ist the complete code:

Business Logic:

using System;
using System.Collections.Generic;
using System.Web;

public class CustomEventArgs : EventArgs
{
    public CustomEventArgs(string s)
    {
        message = s;
    }
    private string message;

    public string Message
    {
        get { return message; }
        set { message = value; }
    }
}

/// <summary>
/// Summary description for BusinessLogic
/// </summary>
public class BusinessLogic
{

    public event EventHandler<CustomEventArgs> StatusEvent;

 public BusinessLogic()
 {
       
 }

    public void DoSomething()
    {
        RaiseStatusEvent("Start");

        System.Threading.Thread.Sleep(60000);
        RaiseStatusEvent("Status 1");

        System.Threading.Thread.Sleep(60000);
        RaiseStatusEvent("Status 2");

        System.Threading.Thread.Sleep(60000);
        RaiseStatusEvent("Status 3");

        RaiseStatusEvent("Ende");
    }

    private void RaiseStatusEvent(string Info)
    {
        if (this.StatusEvent != null)
            StatusEvent(Info,new CustomEventArgs(Info));
    }

}

Default.aspx.c

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.Remoting.Messaging;
using System.Threading;

public partial class _Default : System.Web.UI.Page,ICallbackEventHandler
{
    static System.Collections.Generic.List<string> Messages;

    protected void Page_Load(object sender, EventArgs e)
    {
        Messages = new System.Collections.Generic.List<string>();
    }

    private void LongRunningMethod(string name)
    {
        BusinessLogic BL = new BusinessLogic();
        BL.StatusEvent += StatusEventHandler;
        BL.DoSomething();
       //Thread.Sleep(60000 * 5);//This will run for 5 mins
    }

    private void StatusEventHandler(object sender, CustomEventArgs e)
    {
        Messages.Add(e.Message);
    }

    private delegate void LongRun(string name);
    private delegate void Status(string Info);

    private IAsyncResult DoSomthing()
    {
        LongRun Long = new LongRun(LongRunningMethod);// Delegate will call LongRunningMethod
        IAsyncResult ar = Long.BeginInvoke("CHECK",new AsyncCallback(CallBackMethod),null);
        //”CHECK” will go as function parameter to LongRunningMethod
        return ar; //Once LongRunningMethod get over CallBackMethod method will be invoked.
    }
    private void CallBackMethod(IAsyncResult ar)
    {
        AsyncResult Result = (AsyncResult)ar;
        LongRun Long = (LongRun)Result.AsyncDelegate;
        Long.EndInvoke(Result);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("Long running process is started");
        Session["result"] = null;
        IAsyncResult res = DoSomthing();
        Session["result"] = res;
        //You can redirect to some other page, prcoess will continue..
        //since we are using session variable it will be available on another page also
        //and you just need to check for process completion as we did in GetCallbackResult().
        //On that page also we will have to use ICallback for priodic check.
    }

    public string GetCallbackResult()
    {
        if (Session["result"] != null)
        {
            IAsyncResult res = (IAsyncResult)Session["result"];
            if (res.IsCompleted)//Checking whether process is over or not
            {
                return "SUCCESS";
            }
            else
            {
                System.Text.StringBuilder MessageText = new System.Text.StringBuilder();
                foreach (string item in Messages)
                {
                    MessageText.AppendLine("Message:" + item);
                }
                return MessageText.ToString();
            }
        }
        return "FAIL";

    }
   
    public void RaiseCallbackEvent(string args)
    {
    //IF any operation do it here.
    }

}

And finaly the html code of default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" EnableSessionState="True"
    Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml...">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Long Running Process</title>
</head>
<body onload="CallServer();">
    <form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <div id="Wait">
        Click button to start long running process.</div>
    <div id="Message">
        Message goes here</div>

    <script language="javascript">
function CallServer()
{
window.document.getElementById("Wait").innerText = window.document.getElementById("Wait").innerText + ".";
<%= ClientScript.GetCallbackEventReference(this,"", "ShowResult", null) %>;
}
function ShowResult(eventArgument,context)
{
    if(eventArgument == "SUCCESS")
    {
        Done');
    }
    else {
    window.document.getElementById("Message").innerText = eventArgument;
    setTimeout("CallServer()",20000);//Priodic call to server.
    }
}  
    </script>

    </form>
</body>
</html>

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to show textual events/progress in a moduleHow to show textual events/progress in a module


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out