Exemplo n.º 1
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            try
            {
                Trace.Initialize(typeof(VidyoEventId), "VidyoIntegration");

                var uriList = new List <Uri>();

                // Add CIC url
                if (!string.IsNullOrEmpty(ConfigurationProperties.CicServiceEndpointUri))
                {
                    uriList.Add(new Uri(ConfigurationProperties.CicServiceEndpointUri));
                }

                // Add Vidyo URL
                if (!string.IsNullOrEmpty(ConfigurationProperties.VidyoServiceEndpointUri) &&
                    !ConfigurationProperties.VidyoServiceEndpointUri.Equals(
                        ConfigurationProperties.CicServiceEndpointUri))
                {
                    uriList.Add(new Uri(ConfigurationProperties.VidyoServiceEndpointUri));
                }

                // Make sure we got at least one URI
                if (uriList.Count == 0)
                {
                    throw new Exception("At least one endpoint URI must be specified!");
                }

                // Dynamically run services as the user that is executing this application
                var username = (string.IsNullOrEmpty(Environment.UserDomainName)
                    ? Environment.MachineName
                    : Environment.UserDomainName)
                               + "\\" + Environment.UserName;
                var hostConfig = new HostConfiguration
                {
                    UrlReservations = new UrlReservations
                    {
                        CreateAutomatically = true,
                        User = username
                    }
                };

                // Create the Nancy host
                _host = new NancyHost(hostConfig, uriList.ToArray());

                // Finds any public services in the module and starts them
                _host.Start();

                // Call the initialize method
                try
                {
                    var url = ConfigurationProperties.CicServiceEndpointUri;
                    url  = url.Trim(new[] { '/' });
                    url += "/ininvid/v1";
                    var client   = new RestClient(url);
                    var request  = new RestRequest("coreservice/initialize", Method.POST);
                    var response = client.Execute(request);

                    if (response.StatusCode != HttpStatusCode.NoContent)
                    {
                        var msg = "Response from initialization was \"" + ((int)response.StatusCode) + " " +
                                  response.StatusDescription + "\"";
                        Trace.WriteEventMessage(msg, EventLogEntryType.Warning, EventId.GenericWarning);
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error initializing service! " + ex.Message;
                    Trace.WriteEventError(ex, msg, EventId.GenericError);
                }

                // Done
                Trace.WriteRegisteredMessage(EventId.ApplicationInitialized,
                                             "Registered endpoints: " + Environment.NewLine +
                                             uriList.Select(uri => uri.ToString()).Aggregate((a, b) => a + Environment.NewLine + b));
            }
            catch (Exception ex)
            {
                Trace.WriteEventError(ex, "Error initializing services: " + ex.Message,
                                      EventId.ApplicationInitializationCriticalFailure);

                // Throw to cause the service to stop/fail to start
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes the room and all participants
        /// </summary>
        /// <param name="roomId"></param>
        internal bool DeleteRoom(int roomId)
        {
            using (Trace.Vidyo.scope())
            {
                try
                {
                    // See if the room is valid first
                    try
                    {
                        var stopwatch = new Stopwatch();
                        stopwatch.Start();
                        var room = _vidyoAdminService.getRoom(new GetRoomRequest
                        {
                            roomID = roomId,
                        });
                        stopwatch.Stop();
                        Trace.Vidyo.note("Got room in {}ms", stopwatch.ElapsedMilliseconds);
                    }
                    catch (Exception ex)
                    {
                        // If the room does not exist,
                        Trace.Vidyo.warning("Room {} does not exist! Error: ", roomId, ex.Message);
                        return(true);
                    }

                    // Kick all participants
                    var participants = GetParticipants(roomId);
                    if (participants != null)
                    {
                        foreach (var participant in participants)
                        {
                            KickParticipant(roomId, participant);
                        }
                    }
                    else
                    {
                        Trace.WriteEventMessage("Failed to get participant list!", EventLogEntryType.Warning,
                                                EventId.GenericWarning);
                    }

                    // Delete the room
                    var sw = new Stopwatch();
                    sw.Start();
                    _vidyoAdminService.deleteRoom(new DeleteRoomRequest
                    {
                        roomID = roomId
                    });
                    sw.Stop();
                    Trace.Vidyo.note("Deleted room {} in {}ms", roomId, sw.ElapsedMilliseconds);

                    // Remove from cache list
                    lock (_getRoomLocker)
                    {
                        if (_rooms.ContainsKey(roomId))
                        {
                            _rooms.Remove(roomId);
                        }
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    Trace.WriteEventError(ex, "Error in DeleteRoom: " + ex.Message, EventId.GenericError);
                    return(false);
                }
            }
        }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            try
            {
                Trace.Initialize(typeof(VidyoEventId), "VidyoIntegration");

                var uriList = new List <Uri>();

                // Add CIC url
                if (!string.IsNullOrEmpty(ConfigurationProperties.CicServiceEndpointUri))
                {
                    uriList.Add(new Uri(ConfigurationProperties.CicServiceEndpointUri));
                }

                // Add Vidyo URL
                if (!string.IsNullOrEmpty(ConfigurationProperties.VidyoServiceEndpointUri) &&
                    !ConfigurationProperties.VidyoServiceEndpointUri.Equals(
                        ConfigurationProperties.CicServiceEndpointUri))
                {
                    uriList.Add(new Uri(ConfigurationProperties.VidyoServiceEndpointUri));
                }

                // Make sure we got at least one URI
                if (uriList.Count == 0)
                {
                    throw new Exception("At least one endpoint URI must be specified!");
                }

                // Dynamically run services as the user that is executing this application
                var username = (string.IsNullOrEmpty(Environment.UserDomainName)
                    ? Environment.MachineName
                    : Environment.UserDomainName)
                               + "\\" + Environment.UserName;
                var hostConfig = new HostConfiguration
                {
                    UrlReservations = new UrlReservations
                    {
                        CreateAutomatically = true,
                        User = username
                    }
                };

                // Start the Nancy host
                using (var host = new NancyHost(hostConfig, uriList.ToArray()))
                {
                    // Finds any public services in the module and starts them
                    host.Start();
                    Console.WriteLine("Your application is running on: ");
                    foreach (var uri in uriList)
                    {
                        Console.WriteLine(uri);
                    }

                    // Call the initialize method
                    try
                    {
                        Console.WriteLine("Initializing...");
                        var url = ConfigurationProperties.CicServiceEndpointUri;
                        url  = url.Trim(new[] { '/' });
                        url += "/ininvid/v1";
                        var client   = new RestClient(url);
                        var request  = new RestRequest("coreservice/initialize", Method.POST);
                        var response = client.Execute(request);

                        if (response.StatusCode != HttpStatusCode.NoContent)
                        {
                            var msg = "Response from initialization was \"" + ((int)response.StatusCode) + " " +
                                      response.StatusDescription + "\"";
                            Console.WriteLine(msg);
                            Trace.WriteEventMessage(msg, EventLogEntryType.Warning, EventId.GenericWarning);
                        }
                    }
                    catch (Exception ex)
                    {
                        var msg = "Error initializing service! " + ex.Message;
                        Console.WriteLine(msg);
                        Trace.WriteEventError(ex, msg, EventId.GenericError);
                    }

                    // Wait for it to end
                    Console.WriteLine("Service is running. Press [Enter] to close the host.");
                    Trace.WriteRegisteredMessage(EventId.ApplicationInitialized);
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteEventError(ex, "Error initializing services: " + ex.Message, EventId.ApplicationInitializationCriticalFailure);
                Console.WriteLine(ex);
                Console.WriteLine("Fatal error. Press any key to continue.");
                Console.ReadKey();
            }
            finally
            {
                Trace.WriteRegisteredMessage(VidyoEventId.ApplicationShutdown);
            }
        }