hi,
we wrote the adapters to integrate cutechat but when we try to enter a
room we get an error message which says"Object reference not set to an
instance of an object " we try to give the login information from our
portal to cutechat per session, in which the login.infos should be
stored but obviously cutechat cannot use them...
here is the source of our adapters and the siteconfig:
Siteconfig.cs:
using System.Web.UI;
using SediSys.Portal.Main.WebPL.Core;
namespace SediSys.Portal.Community.WebPL.Chat
{
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
public class SiteConfig
{
static public string ConnectionString
{
get
{
return
ConfigurationSettings.AppSettings["ConnectionString1"];
}
}
static public SqlConnection OpenConnection()
{
SqlConnection conn=new SqlConnection(ConnectionString);
conn.Open();
return conn;
}
static public SqlTransaction BeginTransaction()
{
SqlConnection conn=OpenConnection();
try
{
return conn.BeginTransaction();
}
catch
{
conn.Dispose();
throw;
}
}
static public bool IsAdmin(string loginName)
{
if(loginName==null||loginName.Length==0)
return false;
return
string.Compare(loginName,ConfigurationSettings.AppSettings["AdminLoginName"],true)==0;
}
public static UserData UserDataObj
{
get
{
UserData userData = null;
if ( HttpContext.Current.Session["UserData"] == null
)
{
userData = new UserData();
userData.Username = "Guest";
string[] lang =
HttpContext.Current.Request.UserLanguages;
if ( lang.Length > 0 )
{
userData.Language = lang[0];
}
}
else
{
userData = (UserData)
HttpContext.Current.Session["UserData"];
}
return userData;
}
}
static public void Login(string loginName)
{
HttpContext.Current.Response.Write( "Using our
SiteConfig-login<br>\n" );
HttpContext.Current.Session["ChatLogin"] = loginName;
FormsAuthentication.SetAuthCookie(loginName,false);
}
static public string CurrentLoginName //=currentuseruniquename
{
get
{
HttpContext context=HttpContext.Current;
//if(!context.User.Identity.IsAuthenticated)
//return null;
//return context.User.Identity.Name;
/*
if (HttpContext.Current.Session["ChatLogin"] != null
)
{
//string
globaladmin="globaladmin";
//return globaladmin;
return (string)
HttpContext.Current.Session["ChatLogin"];
}
//return null;
*/
HttpContext.Current.Response.Write( "Using our
SiteConfig-getcurrentuseruniquename<br>\n" );
string globaladmin="12_globaladmin";
return SiteConfig.UserDataObj.Username + "_"
+SiteConfig.UserDataObj.GlobalUserID;
}
}
static public void Logout()
{
FormsAuthentication.SignOut();
}
}
}
our DataProvider:
using System.Security.Principal;
using System.Web;
using CuteChat;
namespace SediSys.Portal.Community.WebPL.Chat
{
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using SediSys.Portal.Main.BF;
using SediSys.Portal.Main.WebPL.Controls.BaseClasses;
public class SediSysSqlDataProvider : CuteChat.SqlServer.SqlDataProvider
{
public SediSysSqlDataProvider(string connstr):base(connstr)
{
}
public override CuteChat.UserInfoData GetUserInfo(string useruniquename)
{
string userName = SiteConfig.UserDataObj.Username;
int userID = SiteConfig.UserDataObj.GlobalUserID;
int groupID = SiteConfig.UserDataObj.GlobalGroupID;
bool admin = false;
if ( groupID == 1 )
{
admin = true;
}
return new
CuteChat.UserInfoData(userName +"_"+userID,userName, admin
);
// string globaladmin= "12_globaladmin";
// return new CuteChat.UserInfoData(globaladmin,globaladmin,admin );
}
public override string[] ListUserUniqueName()
{
HttpContext.Current.Response.Write( "Using
SediSysSqlDataProvider-listuseruniquename<br>\n" );
ArrayList al=new ArrayList();
DataSet ds = new User().GetAllUsers();
//DataRow row = ds.Tables[0].Rows[0];
foreach (DataRow row in ds.Tables[0].Rows)
{
string ids = Convert.ToString( row["ID"] );
string usern = Convert.ToString( row["UserName"] );
al.Add( usern + "_" + ids);
}
//string globaladmin= "12_globaladmin";
//al.Add(globaladmin); //static for testing
only!remove this later!
return (string[])al.ToArray(typeof(string));
}
public override bool IsUserNickNameExists(string nickname)
{
// FIXME: implement once we know how they handle this
return false;
}
}
}
our UserIdentityAdapter:
using CuteChat;
using SediSys.Portal.Main.WebPL.Core;
namespace SediSys.Portal.Community.WebPL.Chat
{
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using SediSys.Portal.Main.WebPL.Controls.BaseClasses;
public class SqlServerUserIdentityAdapter : IUserIdentityAdapter {
public string
GetCurrentUserUniqueName(HttpContext context) {
//(HttpContext context)
UserData userData = null;
if ( context.Session == null )
{
HttpContext.Current.Response.Write( "Fuck
you");
return "globaladmin";
}
if ( context.Session["UserData"] == null )
{
userData = new UserData();
userData.Username = "Guest";
string[] lang = context.Request.UserLanguages;
if ( lang.Length > 0 )
{
userData.Language = lang[0];
}
}
else
{
userData = (UserData) context.Session["UserData"];
}
// return userData;
string useruniquename="12_globaladmin";
//HttpContext.Current.Response.Write( "Using our
UserIdentityAdapter-getcurrentuseruniquename<br>\n" );
return userData.Username + "_" +userData.GlobalUserID;
}
public bool IsAdministrators(string useruniquename) {
using(IDataAccess da=ChatConfig.CreateDataAccess())
{
int userid=da.GetUserInternalId(useruniquename);
if(userid==0)
return false;
DataRow row=da.SelectUser(userid);
if(row==null)
return false;
return Convert.ToBoolean(row["isadmin"]);
}
}
}
}
and our default.aspx:
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using CuteChat;
namespace SediSys.Portal.Community.WebPL.Chat
{
public class _Default : Page // SediSys.Portal.Main.WebPL.Controls.BaseClasses.Page
{
protected Panel Panel2;
protected LinkButton LinkButton1;
protected Label Label1;
protected HyperLink HyperLink1;
protected Repeater Repeater1;
protected Panel Panel1;
private void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
Response.Write(
SiteConfig.UserDataObj.Username);
//SiteConfig.Login( username + "_" + userID );
Label1.Text=SiteConfig.UserDataObj.Username;
SiteConfig.Login(
SiteConfig.UserDataObj.Username + "_" +
SiteConfig.UserDataObj.GlobalUserID );
FormsAuthentication.SetAuthCookie(
SiteConfig.UserDataObj.Username + "_" +
SiteConfig.UserDataObj.GlobalUserID, true); //janus:cookie?default=false
string loginname=SiteConfig.CurrentLoginName;
if ( loginname == null )
{
//Response.Redirect("~/Community/Chat/");
}
if(loginname==null)
{
Panel1.Visible=true;
Panel2.Visible=false;
}
else
{
Panel1.Visible=false;
Panel2.Visible=true;
HyperLink1.Visible=SiteConfig.IsAdmin(loginname);
//
using(SqlConnection
conn=SiteConfig.OpenConnection())
// {
//
using(SqlCommand cmd=conn.CreateCommand())
// {
//
cmd.CommandText="select DisplayName from SampleUsers
where LoginName=@ln";
//
cmd.Parameters.Add("@ln",SqlDbType.NVarChar,20).Value=loginname;
//
//
Label1.Text=Convert.ToString(cmd.ExecuteScalar());
// }
// }
}
using( ChatSystem cs=ChatFactory.CreateChatSystem() )
{
ArrayList al=new ArrayList();
int[] ids=cs.ListRooms();
foreach(int id in ids)
{
DataRow
row=cs.GetRoom(id);
al.Add(new
RoomInfo(row));
}
Repeater1.DataSource=al;
Repeater1.DataBind();
}
}
}
#region Web CODEGEN
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.LinkButton1.Click += new EventHandler(this.LinkButton1_Click);
this.Load += new EventHandler(this.Page_Load);
}
#endregion
private void LinkButton1_Click(object sender, EventArgs e)
{
SiteConfig.Logout();
Response.Redirect("~/");
}
class RoomInfo
{
DataRow _row;
public RoomInfo(DataRow row)
{
_row=row;
}
public int id
{
get
{
return (int)_row["id"];
}
}
public string name
{
get
{
return _row["name"].ToString();
}
}
}
}
}
we would be very grateful for any hints
thx
janus