Top

Message Retrieve Problem WPF?

Comments

10 comments

  • Dinesh92d

    Hi Christophe IRLES,

       I Already developed and tested in Windows Form Application it was working smoothly. I am getting a message first time also. but the only problem occurs in the WPF application. that only I am asking again. Please check once with the WPF application. thank you for your support.

    Regards

    Dinesh D

     

     

    1
    Comment actions Permalink
  • Dinesh92d

    Hi, Christophe IRLES can you please validate my code. It was fulfilled as SDK required.

     

     

    using System;
    using System.Collections.Generic;
    using Rainbow.Model;
    using System.Configuration;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Speech.Synthesis;
    using System.Threading;
    using System.Windows;
    using Windows.UI.Notifications;
    using Rainbow;

    namespace WpfApp1
    {

    public partial class MainWindow : Window
    {
    private static Mutex mutex = null;
    const string AppName = "Notification POC";

    string APP_ID = Convert.ToString(ConfigurationManager.AppSettings["ApplicationID"]);
    string APP_SECRET_KEY = Convert.ToString(ConfigurationManager.AppSettings["ApplicationSecretKey"]);
    string HOST_NAME = Convert.ToString(ConfigurationManager.AppSettings["Rainbow.Api.Url"]);

    string LOGIN_USER = "Email"; // Convert.ToString(ConfigurationManager.AppSettings["FromEmailAddress"]);
    string PASSWORD_USER = "Password"; // Convert.ToString(ConfigurationManager.AppSettings["EmailPassWord"]);

     

    #region Declaration

    // Define Rainbow objects
    Rainbow.Application rainbowApplication; // To store Rainbow Application object
    Contacts rainbowContacts; // To store Rainbow Contacts object
    Conversations rainbowConversations; // To store Rainbow Conversations object
    InstantMessaging rainbowInstantMessaging; // To store Rainbow InstantMessaging object

    List<Contact> rainbowContactsList; // To store contacts list of my roster

    #endregion


    public MainWindow()
    {

    InitializeComponent();

    InitializeRainbowSDK();
    AppLogin();
    }

    #region InitializeSDK

    public void InitializeRainbowSDK()
    {
    rainbowApplication = new Rainbow.Application();
    rainbowApplication.SetTimeout(10000);

    rainbowApplication.SetApplicationInfo(APP_ID, APP_SECRET_KEY);
    rainbowApplication.SetHostInfo(HOST_NAME);

    // Get Rainbow main objects
    rainbowContacts = rainbowApplication.GetContacts();
    rainbowConversations = rainbowApplication.GetConversations();
    rainbowInstantMessaging = rainbowApplication.GetInstantMessaging();

    // EVENTS WE WANT TO MANAGE
    rainbowApplication.ConnectionStateChanged += RainbowApplication_ConnectionStateChanged;
    rainbowContacts.RosterContactAdded += RainbowContacts_RosterContactAdded;
    rainbowInstantMessaging.MessageReceived += RainbowInstantMessaging_MessageReceived;

    rainbowContactsList = new List<Contact>();
    }
    #endregion

    public void AppLogin()
    {

    if (!rainbowApplication.IsConnected())
    {
    rainbowApplication.Login(LOGIN_USER, PASSWORD_USER, callback =>
    {
    if (callback.Result.Success)
    {
    //string logLine = String.Format("Impossible to logout:\r\n{0}", Util.SerialiseSdkError(callback.Result));
    //AddStateLine(logLine);
    //log.WarnFormat(logLine);
    }
    });
    }
    }

     

     


    #region RainbowApplication_ConnectionStateChanged

    private void RainbowApplication_ConnectionStateChanged(object sender, Rainbow.Events.ConnectionStateEventArgs e)
    {
    //string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    //string basedir = System.AppDomain.CurrentDomain.BaseDirectory;

    string applicationDir = IconLocation();

    if (e.State == Rainbow.Model.ConnectionState.Connected)
    {
    // _notifyIcon.Icon = new System.Drawing.Icon(applicationDir + "/Content/mywilco-gr.ico");
    }
    else if (e.State == Rainbow.Model.ConnectionState.Connecting)
    {

    }
    else if (e.State == Rainbow.Model.ConnectionState.Disconnected)
    {

    // _notifyIcon.Icon = new System.Drawing.Icon(applicationDir + "/Content/mywilco-rd.ico");
    // rainbowContactsList.Clear();
    AppLogin();

    }
    }
    #endregion


    #region RainbowContacts_RosterContactAdded
    private void RainbowContacts_RosterContactAdded(object sender, Rainbow.Events.JidEventArgs e)
    {
    // AddStateLine($"A Contact has been added:[{e.Jid}]");
    //UpdateContactsListComboBox();
    }
    #endregion

     

    #region RainbowInstantMessaging_MessageReceived
    private void RainbowInstantMessaging_MessageReceived(object sender, Rainbow.Events.MessageEventArgs e)
    {
    try
    {

    if (e.CarbonCopy == false)
    {

    String Msgcontent = e.Message.Content;
    string messageId = "";

    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("LOGIN_USER:- " + LOGIN_USER + " && PASSWORD_USER:- " + PASSWORD_USER + " && app.xaml Received " + " " + ex.Message);
    }

    }
    #endregion

    }
    }

    1
    Comment actions Permalink
  • Christophe IRLES

    Hi,

    I notice several pb in the code snippet provided ...

    1) You call twice InitializeComponent() (in App() method and in InitializeSDK())

    2) Create main SDK objects (Contacts, Conversations, InstantMessaing, etc ...) before to use login method

    3) Define events (ConnectionStateChanged, MessageReceived , etc ...) also before to use login method

    4) As described in the documentation here you need to received event InitializationPerformed from Application object before to use any feature of the SDK

    Once all thess problems has been corrected, do you still have the same trouble ?

    0
    Comment actions Permalink
  • Dinesh92d

    Christophe IRLES Exactly I'm using this code in my Project Still am getting the same issue. Pls, Guide me.

     

    using log4net;
    using Rainbow.Model;
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Threading;
    using System.Windows;
    using RainbowModel = Rainbow;

    using System.ComponentModel;
    using System.Management;

     

    namespace WpfApp1
    {

    public partial class App : Application
    {

     


    Rainbow.Application rainbowApplication = new RainbowModel.Application();
    RainbowModel.Contacts rainbowContacts; // To store Rainbow Contacts object
    RainbowModel.Conversations rainbowConversations; // To store Rainbow Conversations object
    RainbowModel.InstantMessaging rainbowInstantMessaging; // To store Rainbow InstantMessaging object
    RainbowModel.Invitations rainbowinvitations;

     

    RainbowModel.Model.Conversation rainbowConversation=new Conversation();
    Contact rainbowMyContact; // To store My contact (i.e. the one connected to Rainbow Server)
    List<Contact> rainbowContactsList; // To store contacts list of my roster
    List<Conversation> rainbowConversationsList;// To store conversations list


    string APP_ID = Convert.ToString(ConfigurationManager.AppSettings["ApplicationID"]);
    string APP_SECRET_KEY = Convert.ToString(ConfigurationManager.AppSettings["ApplicationSecretKey"]);
    string HOST_NAME = Convert.ToString(ConfigurationManager.AppSettings["Rainbow.Api.Url"]);

    string LOGIN_USER = ""; 
    string PASSWORD_USER = "";

     


    // [STAThread]
    public App()
    {
    try
    {
    InitializeSDK();}
    catch(Exception ex)
    {
    MessageBox.Show("app.xaml App " + " " + ex.Message);
    }
    }

    public void InitializeSDK()
    {

    this.InitializeComponent();

    rainbowApplication = new Rainbow.Application();
    rainbowApplication.SetApplicationInfo(APP_ID, APP_SECRET_KEY);
    rainbowApplication.SetHostInfo(HOST_NAME);

    // Get Rainbow main objects
    rainbowContacts = rainbowApplication.GetContacts();
    rainbowConversations = rainbowApplication.GetConversations();
    rainbowInstantMessaging = rainbowApplication.GetInstantMessaging();
    rainbowinvitations = rainbowApplication.GetInvitations();

    if (!rainbowApplication.IsConnected())
    {
    rainbowApplication.Login(LOGIN_USER, PASSWORD_USER, callback =>
    {
    if (callback.Result.Success)
    {
    rainbowContacts = rainbowApplication.GetContacts();
    rainbowConversations = rainbowApplication.GetConversations();
    rainbowInstantMessaging = rainbowApplication.GetInstantMessaging();
    rainbowinvitations = rainbowApplication.GetInvitations();


    rainbowApplication.ConnectionStateChanged += RainbowApplication_ConnectionStateChanged;
    rainbowInstantMessaging.MessageReceived += RainbowInstantMessaging_MessageReceived;
    rainbowContacts.RosterContactAdded += RainbowContacts_RosterContactAdded;

    rainbowContactsList = new List<Contact>();
    }
    });
    }
    }

    private void RainbowInstantMessaging_MessageReceived(object sender, Rainbow.Events.MessageEventArgs e)
    {
    try
    {

     

    }

    catch(exception ex)

    {

     

    }

    }

    0
    Comment actions Permalink
  • Christophe IRLES

    First, Fix your code with all the points I have described previously

    0
    Comment actions Permalink
  • Dinesh92d

    already done what you tell...

    0
    Comment actions Permalink
  • Christophe IRLES

    1) InitializeComponent must be done in App() - not after.

    2) rainbowContacts objects (and others) is created twice and still after login

    3) events are still created after login

    4) InitializationPerformed  event is not managed ...

    So you did  very few updates ...

    0
    Comment actions Permalink
  • Christophe IRLES

    Hi,

    I have updated the InstantMessaging sample with an option to allow auto-logon when the application sample is started (previously you must have connected successfully with a valid account / password since we get info from the cache to get credentials)

    There is no problem to receive the first incoming message (and all others).

    Regards,
    Christophe

     

    0
    Comment actions Permalink
  • Christophe IRLES

    Rainbow C# SDK is built as a .Net Standard library. So it's compatible with any superior layer of .Net including WPF.

    As example a full mobile application (for Android and IOS) is available in Xamarin Forms using this SDK without any trouble. I use this mobile Application every day on my own Android device for my work.

    I spent already a lot of time with your question ... It would have been better to clearly describe it from the start.

    And again, your latest code snippet shows a lot of your misunderstanding in coding in C #. I really think the problem is more here than in the SDK.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Still can't find what you need?

  • Contact Us

    Do you have any question about Rainbow? Leave us a message to get more information.

    Contact
  • Ask the Community

    Do you need help? Ask your questions to the Community and get answers from other Rainbow users.

    Post message