// Sample Code For Perculus Web Service API

// Perculus Web Servis Örnek Kodları

 

/******************************************************************************************************************************

 Burada yer alan kodları, projelerinizde kullanabilirsiniz. SELP, bu kodları örnek teşkil etmesi amacıyla sağlamaktadır. Production ortamında kullanılması tamamiyle kullanıcının sorumluluğundadır. SELP oluşabilecek zararlardan sorumlu değildir.

************************************************************************************************************/

 

// CREATE SESSION

public static int CreatePerculusRoom(int perculusUserId, int testRoomDuration, out string attendCode)

{

            PerculusIntegration pws = new PerculusIntegration();

            attendCode = "";

 

            DateTime classStartTimeToPerculus = DateTime.Now;

            string roomname = "Test Odası";

            WSResponse response = pws.Rooms_AddRoom(0, roomname, "Test Room", classStartTimeToPerculus,

                                                                                                                                    testRoomDuration,

                                                                                                                                    "test",

                                                                                                                                    "#99FF99",

                                                                                                                                    "tr-TR",

                                                                                                                                    "streaming.perculus.com",

                                                                                                                                    22, 4, 0, 200, "", true, false, 0, 0, false, "", false, "elearning","elearning", new string[] {"one2one","elearning"}, new ModuleSetting[] { new ModuleSetting() { key = "showTimer", mname = "Session", Value = "1" }, new ModuleSetting() { key = "warnBefore", mname = "Session", Value = "0" } });

 

            int roomId = 0;

            if (response.success)

            {

                        roomId = ((perculus2.Room)response.data).ROOMID;

                        // add user

                        pws.Rooms_AddAttendees(roomId, perculusUserId.ToString(), "", "e");

                        response = pws.Rooms_GetAttendCode(roomId, perculusUserId);

                        attendCode = (string)response.data;

            }

            else

            {

                        // ERROR

            }

 

          

            pws.Dispose();

            pws = null;

 

            return roomId;

}

 

 

// GET ATTEND CODE

 

public static string GetPerculusAttendCode(int perculusRoomid, int perculusUserId)

{

            string UserAttendCode = "";

            try

            {

                        PerculusIntegration pws = new PerculusIntegration();

                        WSResponse response = pws.Rooms_GetAttendCode(perculusRoomid, perculusUserId);

                        if (response.success)

                                    UserAttendCode = response.data.ToString();

 

                        pws.Dispose();

                        pws = null;

            }

            catch

            {

                        //TODO: WebServis Error Handling.

            }

 

            return UserAttendCode;

}

 

// REGISTER USER TO SESSION

public static string AddSingleUserToPerculusRoom(int perculusUserId, int PerculusRoomId, string userType)

{

   string attendCode = "";

            try

            {

                        PerculusIntegration pws = new PerculusIntegration();

                        WSResponse response = pws.Rooms_RegisterAttendee(PerculusRoomId, perculusUserId, userType);

                        if (response.success)

                        {

                                // success, get attendCode now

               attendCode = (string) response.code;

                        }

                        else

                        {

                                    // ERROR. desc: response.code

                        }

                        pws.Dispose();

                        pws = null;

            }

            catch

            {

                        //TODO: WebServis Error Handling.

            }

            return attendCode;

}

// REGISTER EXTERNAL USER TO SESSION

public static string AddSingleExternalUserToPerculusRoom(string name, string surname, string email, int PerculusRoomId, string userType)

{     

            string attendCode = "";

            try

            {

                        PerculusIntegration pws = new PerculusIntegration();

                        WSResponse response = pws.Rooms_RegisterAttendee(PerculusRoomId, name, surname, email, userType);

                        if (response.success)

                        {

                                // success, get attendCode now

               attendCode = (string) response.code;

                        }

                        else

                        {

                                    // ERROR. desc: response.code

                        }

                        pws.Dispose();

                        pws = null;

            }

            catch

            {

                        //TODO: WebServis Error Handling.

            }

            return attendCode;

}

 

// REGISTER MANY USERS TO SESSION

public static bool AddUsersToPerculusRoom(List<int> perculusUserIdList, int PerculusRoomId, string userType)

{

            try

            {

                        PerculusIntegration pws = new PerculusIntegration();

                        string strUserIdList = "";

                        foreach (int userId in perculusUserIdList)

                        {

                                    strUserIdList = strUserIdList + "," + userId.ToString();

                        }

                        if (!string.IsNullOrEmpty(strUserIdList)) strUserIdList = strUserIdList.Substring(1);

                        WSResponse response = pws.Rooms_RegisterAttendees(PerculusRoomId, strUserIdList, "", userType);

                        if (response.success)

                        {

                                    // success

                        }

                        else

                        {

                                    // ERROR. desc: response.code

                        }

                        pws.Dispose();

                        pws = null;

            }

            catch

            {

                        //TODO: WebServis Error Handling.

            }

            return retVal;

}

 

// DEREGISTER USER

 

public static bool RemoveUserFromPerculusRoom(int perculusUserId, int PerculusRoomId)

{

            bool retVal = false;

            try

            {

                        PerculusIntegration pws = new PerculusIntegration();

                        WSResponse response = pws.Rooms_DeRegisterFromRoom(PerculusRoomId, perculusUserId);

                        if (response.success)

                        {

                                    retVal = true;

                                    // show a message to user

                        }

                        else

                        {

                                    retVal = false;

                                    // todo: error handling

                        }

                        pws.Dispose();

                        pws = null;

            }

            catch

            {

                        //TODO: WebServis Error Handling.

            }

            return retVal;

}

 

// POST FILE

 

public static void PostFileToPerculus(int roomId, int perculusUserId, string filePath)

{

            PerculusIntegration pws = new PerculusIntegration();

            System.IO.FileInfo fi = new System.IO.FileInfo(filePath);

            if (fi.Exists)

            {

                        string fileName = fi.Name;

                        if (fileName != null || fileName.Length != 0)

                        {

                                    byte[] fileContent = new byte[fi.Length];

                                    System.IO.Stream str = fi.OpenRead();

                                    str.Read(fileContent, 0, Convert.ToInt32(fi.Length));

                                    string fileData = Convert.ToBase64String(fileContent);

                                    try

                                    {

                                                WSResponse response = pws.Rooms_PostFile(roomId, perculusUserId, fileName, fileData);

                                    }

                                    catch

                                    {

                                                //TODO: WebServis Error Handling.

                                    }

                                    str.Close();

                                    str.Dispose();

                                  

                        }

            }

            fi = null;

            pws.Dispose();

            pws = null;

}