Ejemplo n.º 1
0
        /// <summary>Creates and returns a WSDL client for the given application system. Will try to connect and log on and select project if applicable. If any fails, an exception will be thrown.</summary>
        /// <param name="applicationSystem">The application system definition.</param>
        /// <returns>A client, as a dynamic type.</returns>
        private dynamic CreateApplicationClient(ApplicationSystem applicationSystem, AccountDetails emailSystem)
        {
            const string METHOD = CLASS + "CreateApplicationClient()";

            _eventLog.EntryLog(METHOD);

            //Create our application server.
            dynamic clientApp;

            if (applicationSystem.ServerType == ApplicationSystem.ApplServerTypeEnum.Spira)
            {
                //Create the client.
                clientApp = ClientFactory.CreateClient_Spira(new Uri(applicationSystem.ServerAPIUrl));

                //Connect.
                _eventLog.WriteTrace(METHOD, "Logging into Spira Client.");
                Settings.SpiraClient.SoapServiceClient spiraClient = (Settings.SpiraClient.SoapServiceClient)clientApp;
                if (spiraClient.Connection_Authenticate2(applicationSystem.UserID, applicationSystem.UserPassword, Common.APP_NAME))
                {
                    _eventLog.WriteTrace(METHOD, "Selecting project in Spira Client.");
                    if (emailSystem.ProductOrProjectId.HasValue && spiraClient.Connection_ConnectToProject(emailSystem.ProductOrProjectId.Value))
                    {
                        //We're successful.
                    }
                    else
                    {
                        throw new Exception("Could not log into project #" + emailSystem.ProductOrProjectId.Value.ToSafeString());
                    }
                }
                else
                {
                    throw new Exception("Could not log into server.");
                }
            }
            else
            {
                //Create the client.
                clientApp = ClientFactory.CreateClient_Krono(new Uri(applicationSystem.ServerAPIUrl));

                //Connect.
                _eventLog.WriteTrace(METHOD, "Logging into Krono Client.");
                Settings.KronoClient.SoapServiceClient kronoClient = (Settings.KronoClient.SoapServiceClient)clientApp;
                if (kronoClient.Connection_Authenticate(applicationSystem.UserID, applicationSystem.UserPassword, Common.APP_NAME, true))
                {
                }
                else
                {
                    throw new Exception("Could not log into server.");
                }
            }
            return(clientApp);
        }