Using existing membership information + chat + Allow Anonymous= Error!!!

Last post 12-22-2009, 12:23 PM by dspoh. 8 replies.
Sort Posts: Previous Next
  •  12-01-2009, 2:52 AM 57517

    Using existing membership information + chat + Allow Anonymous= Error!!!

    I've successfully integrated the messenger into our website with our existing database.
    I'm able to add, remove, block contacts in the cute web messenger to my database and its working very well, so im pretty sure im getting there.
     
    But when i try to use the cute chat using annoymous login, it prompts error.
    And im pretty sure its these two methods that cause the problem:
    1.   myCreateDataManagerInstance.GetContacts(ByVal identity As ChatIdentity) as As IChatUserInfo()
    2.   myCreateDataManagerInstance.GetIgnores(ByVal identity As ChatIdentity) As IChatUserInfo()
     
    I'm not very sure how to return the IChatUserInfo() when "ChatProvider.Instance.FromUserId(identity.UniqueId)" gives me an empty string (therefore no contacts or Ignores can be found).
    Even i return "nothing", it will cause an error:
     
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.] CuteChat.ChatPlaceUser.RenderContactInfo(IChatUserInfo info, String msgid) +26 CuteChat.ChatPlaceUser.d() +122 CuteChat.ChatManager.AddPlaceConnection(ChatConnection conn) +54 CuteChat.ChatManager.InternalConnect(ChatIdentity identity, ChatCookie cookie, NameValueCollection nvc) +1448 CuteChat.ChatManager.Connect(ChatIdentity identity, ChatCookie cookie, NameValueCollection nvc) +18 CuteChat.ChatAjaxHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +1440 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +100 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +173

    Please help, thanks
     
  •  12-02-2009, 2:14 AM 57532 in reply to 57517

    Re: Using existing membership information + chat + Allow Anonymous= Error!!!

    Hi dspoh,
     
    Try this way
     
    1. Dim portal As CuteChat.ChatPortal = CuteChat.ChatSystem.Instance.GetCurrentPortal()    
    2. SyncLock portal    
    3.     Dim myid As CuteChat.ChatIdentity = New CuteChat.AppChatIdentity("nickname"False"User:ken""0.0.0.0")    
    4.        
    5.     Dim contacts As CuteChat.IChatUserInfo() = portal.DataManager.GetContacts(myid)    
    6.     For i As Integer = 0 To contacts.Length - 1    
    7.         Response.Write(contacts(i).UserId)    
    8.            
    9.     Next    
    10. End SyncLock   

    Regards,
     
    Ken
  •  12-02-2009, 2:31 AM 57533 in reply to 57532

    Re: Using existing membership information + chat + Allow Anonymous= Error!!!

    Thanks for the reply!
     
    For my case it seems not to be as complicated as a locking or sync issue. Its just a method of return the right object when the login is anonymous.
     
    Here is my implementation:
     
    I've create two class that implements both the CuteChat.ChatProvider and AppDataManager.
     
    In my ChatProvider, it overrides the method CreateDataManagerInstance so that it will use my own DataManager:
    1. Public Overrides Function CreateDataManagerInstance(ByVal portal As AppPortal) As AppDataManager   
    2.     Return New myCreateDataManagerInstance(portal)   
    3. End Function  
    In my DataManager, it will implement the GetContacts and GetIgnores method.
    It works fine getting authenticated users, this is how it looks like:
    1. Public Overrides Function GetContacts(ByVal identity As ChatIdentity) As IChatUserInfo()   
    2.     Dim loginname As String = ChatProvider.Instance.FromUserId(identity.UniqueId)   
    3.        
    4.     If loginname = "" then   
    5.         Return Nothing  
    6.     End if   
    7.        
    8.     Dim friends() as string = myDATABASE.getcontacts(loginname)   
    9.   
    10.     Dim arr(friends.Length - 1) As IChatUserInfo   
    11.   
    12.     For i = 0 To friends.Length - 1   
    13.         Dim friendid as string = ChatProvider.Instance.ToUserId(friends(i))   
    14.         arr(i) = MyBase.GetUserInfo(friendid)   
    15.     Next  
    16.   
    17.     Return arr   
    18. End Function  
    The problem araise when its anonymous, the login name provided is a empty string and i've had to return "Nothing", it will cause the error.
     
    Please help.
     
  •  12-09-2009, 2:30 AM 57673 in reply to 57517

    Re: Using existing membership information + chat + Allow Anonymous= Error!!!

    Anyone??
  •  12-09-2009, 5:27 AM 57677 in reply to 57673

    Re: Using existing membership information + chat + Allow Anonymous= Error!!!

    Hi dspoh,
     
    Try this way
     
    1. If LoginName = "" Then  
    2.            Dim portal As CuteChat.ChatPortal = CuteChat.ChatSystem.Instance.GetCurrentPortal()   
    3.       
    4.            Dim myid As CuteChat.ChatIdentity = New CuteChat.AppChatIdentity("nickname"False"User:empty""0.0.0.0")   
    5.           
    6.            Dim contacts As CuteChat.IChatUserInfo() = portal.DataManager.GetContacts(myid)   
    7.           
    8.            Return contacts   
    9.        End If  
     
    This code will return an empty IChatUserInfo.
     
    "User:empty" is not a real user, you can easily use a name (any name).
     
    Regards,
     
    ken
  •  12-09-2009, 10:42 AM 57689 in reply to 57677

    Re: Using existing membership information + chat + Allow Anonymous= Error!!!

    Hi ken,
       Thanks for your reply but your solution wouldn't work cause i'm implementing my own datamanager as mentioned in my previous post.
    Here is the recap:
    1. Public Overrides Function CreateDataManagerInstance(ByVal portal As AppPortal) As AppDataManager      
    2.     Return New myCreateDataManagerInstance(portal)      
    3. End Function    
    So by using your code and my function:
    1. Public Overrides Function GetContacts(ByVal identity As ChatIdentity) As IChatUserInfo()      
    2.     Dim loginname As String = ChatProvider.Instance.FromUserId(identity.UniqueId)      
    3.           
    4.     If loginname = "" then        
    5.            Dim portal As CuteChat.ChatPortal = CuteChat.ChatSystem.Instance.GetCurrentPortal()      
    6.            Dim myid As CuteChat.ChatIdentity = New CuteChat.AppChatIdentity("nickname"False"User:empty""0.0.0.0")      
    7.            Dim contacts As CuteChat.IChatUserInfo() = portal.DataManager.GetContacts(myid) 'CALLING itself again!!!        
    8.            Return contacts   
    9.     End if      
    10.           
    11.     Dim friends() as string = myDATABASE.getcontacts(loginname)      
    12.      
    13.     Dim arr(friends.Length - 1) As IChatUserInfo      
    14.      
    15.     For i = 0 To friends.Length - 1      
    16.         Dim friendid as string = ChatProvider.Instance.ToUserId(friends(i))      
    17.         arr(i) = MyBase.GetUserInfo(friendid)      
    18.     Next     
    19.      
    20.     Return arr      
    21. End Function    
    I't just basically asking my function to call itself and later return something that does not exist again!
     
    So the question is, what should i return in mydatamanager.getContacts() when the username is Anonymous (invalid or "" or not in my database), ie guest, that will not cause the chat to create the error. 
    1. If loginname = "" then        
    2.       'What should i return if "nothing" won't work?   
    3.       return nothing '<- It won't work.   
    4. End if    
     
    Need help, thanks.

     

     
  •  12-16-2009, 3:25 AM 57775 in reply to 57689

    Re: Using existing membership information + chat + Allow Anonymous= Error!!!

    Anyone??
  •  12-17-2009, 9:45 AM 57819 in reply to 57775

    Re: Using existing membership information + chat + Allow Anonymous= Error!!!

    i think i found my answer:
     

    1. if loginname = "" then   
    2.    dim empty(0) as IChatUserInfo   
    3.    return empty   
    4. end if  

    :)
  •  12-22-2009, 12:23 PM 57900 in reply to 57819

    Re: Using existing membership information + chat + Allow Anonymous= Error!!!

    dspoh:
    i think i found my answer:
     

    1. if loginname = "" then   
    2.    dim empty(0) as IChatUserInfo   
    3.    return empty   
    4. end if  

    :)


    My bad, empty(0) doesn't not return an empty collection, should be like this instead:
    1. if loginname = "" then   
    2.     Dim empty(-1) as IChatUserInfo   
    3.     return empty   
    4. end if  

View as RSS news feed in XML