Ejemplo n.º 1
0
        /// <summary>
        /// Establishes a hosting agreement with a profile server and initializes a profile.
        /// </summary>
        /// <param name="Server">Profile server to host the identity.</param>
        /// <returns>true if the function succeeded, false otherwise.</returns>
        public async Task <bool> InitializeProfileHosting(ProfileServer Server)
        {
            log.Trace("(Server.Name:'{0}')", Server.Name);
            bool res = false;

            profileServer = Server;
            InitializeTcpClient();

            try
            {
                await ConnectAsync(Server.IpAddress, Server.ClientNonCustomerInterfacePort, true);

                if (await EstablishProfileHostingAsync(type))
                {
                    hostingActive = true;
                    CloseTcpClient();

                    InitializeTcpClient();
                    await ConnectAsync(Server.IpAddress, Server.ClientCustomerInterfacePort, true);

                    if (await CheckInAsync())
                    {
                        if (await InitializeProfileAsync(name, profileImage, location, null))
                        {
                            profileInitialized = true;
                            if (profileImage != null)
                            {
                                if (await GetProfileThumbnailImage())
                                {
                                    res = true;
                                }
                                else
                                {
                                    log.Error("Unable to obtain identity's thumbnail image from profile server '{0}'.", Server.Name);
                                }
                            }
                            else
                            {
                                res = true;
                            }
                        }
                        else
                        {
                            log.Error("Unable to initialize profile on profile server '{0}'.", Server.Name);
                        }
                    }
                    else
                    {
                        log.Error("Unable to check-in to profile server '{0}'.", Server.Name);
                    }
                }
                else
                {
                    log.Error("Unable to establish profile hosting with server '{0}'.", Server.Name);
                }
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }

            CloseTcpClient();

            log.Trace("(-):{0}", res);
            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize a new instance of a profile server.
        /// </summary>
        /// <returns>true if the function succeeds, false otherwise.</returns>
        public bool Initialize()
        {
            log.Trace("()");

            bool res = false;

            try
            {
                instanceDirectory = GetInstanceDirectoryName();
                Directory.CreateDirectory(instanceDirectory);

                if (Helpers.DirectoryCopy(CommandProcessor.ProfileServerBinariesDirectory, instanceDirectory))
                {
                    string configFinal = Path.Combine(instanceDirectory, ConfigFileName);
                    if (InitializeConfig(configFinal))
                    {
                        locServer = new LocServer(this);
                        res       = locServer.Start();
                    }
                    else
                    {
                        log.Error("Unable to initialize configuration file '{0}' for server '{1}'.", configFinal, name);
                    }
                }
                else
                {
                    log.Error("Unable to copy files from directory '{0}' to '{1}'.", CommandProcessor.ProfileServerBinariesDirectory, instanceDirectory);
                }
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }

            log.Trace("(-):{0}", res);
            return(res);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts the TCP server.
        /// </summary>
        /// <returns>true if the function succeeds, false otherwise.</returns>
        public bool Start()
        {
            log.Trace("()");

            bool res = false;

            try
            {
                log.Trace("Listening on '{0}:{1}'.", ipAddress, port);
                listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                listener.Start();
                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }

            if (res)
            {
                acceptThread = new Thread(new ThreadStart(AcceptThread));
                acceptThread.Start();
            }


            log.Trace("(-):{0}", res);
            return(res);
        }