Exemple #1
0
        private static ApexSharpConfig GetNewConnection(ApexSharpConfig config)
        {
            var xml = @"
                <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:enterprise.soap.sforce.com"">
                    <soapenv:Header>
                        <urn:LoginScopeHeader>
                        <urn:organizationId></urn:organizationId>
                        <urn:portalId></urn:portalId>
                        </urn:LoginScopeHeader>
                    </soapenv:Header>
                    <soapenv:Body>
                        <urn:login>
                            <urn:username>" + config.SalesForceUserId + "</urn:username>" +
                      "<urn:password>" + config.SalesForcePassword + config.SalesForcePasswordToken + "</urn:password>" +
                      "</urn:login>" +
                      "</soapenv:Body>" +
                      "</soapenv:Envelope>";


            var returnXml = PostLoginTask(config.SalesForceSoapUrl, xml);

            if (returnXml.Contains("INVALID_LOGIN"))
            {
                throw new SalesForceInvalidLoginException("Invalid Login");
            }
            else if (returnXml.Contains("API_DISABLED_FOR_ORG"))
            {
                throw new SalesForceInvalidLoginException("Webservice API is disabled for this login or organization.");
            }

            try
            {
                Envelope envelope = UtilXml.DeSerilizeFromXML <Envelope>(returnXml);


                var soapIndex =
                    envelope.Body.loginResponse.result.serverUrl.IndexOf(@"/Soap", StringComparison.Ordinal);
                var restUrl       = envelope.Body.loginResponse.result.serverUrl.Substring(0, soapIndex);
                var restSessionId = "Bearer " + envelope.Body.loginResponse.result.sessionId;


                config.SalesForceSoapUrl       = envelope.Body.loginResponse.result.serverUrl;
                config.RestUrl                 = restUrl;
                config.RestSessionId           = restSessionId;
                config.SessionCreationDateTime = DateTimeOffset.Now.ToUnixTimeSeconds() +
                                                 envelope.Body.loginResponse.result.userInfo.sessionSecondsValid;

                return(config);
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("Fix the error and restart " + e);
                Console.ReadLine();
                System.Environment.Exit(0);
            }

            return(null);
        }
Exemple #2
0
        public static ApexSharpConfig CreateSession(ApexSharpConfig config)
        {
            config.SalesForceSoapUrl = config.SalesForceSoapUrl + "services/Soap/c/" + config.SalesForceApiVersion + ".0/";
            config = GetNewConnection(config);

            string json = JsonConvert.SerializeObject(config, Formatting.Indented);

            Directory.CreateDirectory(Path.GetDirectoryName(config.ConfigLocation));
            File.WriteAllText(config.ConfigLocation, json);

            return(config);
        }
        private static ApexSharpConfig GetNewConnection(ApexSharpConfig config)
        {
            var xml = @"
                <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:enterprise.soap.sforce.com"">
                    <soapenv:Header>
                        <urn:LoginScopeHeader>
                        <urn:organizationId></urn:organizationId>
                        <urn:portalId></urn:portalId>
                        </urn:LoginScopeHeader>
                    </soapenv:Header>
                    <soapenv:Body>
                        <urn:login>
                            <urn:username>" + config.SalesForceUserId + "</urn:username>" +
                      "<urn:password>" + config.SalesForcePassword + config.SalesForcePasswordToken + "</urn:password>" +
                      "</urn:login>" +
                      "</soapenv:Body>" +
                      "</soapenv:Envelope>";


            var retrunXml = PostLoginTask(config.SalesForceUrl, xml);

            if (retrunXml.Contains("INVALID_LOGIN"))
            {
                throw new SalesForceInvalidLoginException("Invalid Login");
            }
            Envelope envelope = UtilXml.DeSerilizeFromXML <Envelope>(retrunXml);

            var soapIndex     = envelope.Body.loginResponse.result.serverUrl.IndexOf(@"/Soap", StringComparison.Ordinal);
            var restUrl       = envelope.Body.loginResponse.result.serverUrl.Substring(0, soapIndex);
            var restSessionId = "Bearer " + envelope.Body.loginResponse.result.sessionId;


            config.SalesForceUrl           = envelope.Body.loginResponse.result.serverUrl;
            config.SessionId               = envelope.Body.loginResponse.result.sessionId;
            config.RestUrl                 = restUrl;
            config.RestSessionId           = restSessionId;
            config.SessionCreationDateTime = DateTimeOffset.Now.ToUnixTimeSeconds() + envelope.Body.loginResponse.result.userInfo.sessionSecondsValid;

            return(config);
        }
Exemple #4
0
        public static ApexSharpConfig GetSession(string configFileLocation)
        {
            if (configFileLocation == null)
            {
                if (Session == null)
                {
                    throw new ApexSharpNoConfigFoundException("No Session Exists Create One");
                }

                if (Session.SessionCreationDateTime <= DateTimeOffset.Now.ToUnixTimeSeconds())
                {
                    Log.ForContext <ConnectionUtil>().Information("Session Expired, Creating a New Session");
                    Session = CreateSession(Session);
                }
                return(Session);
            }

            FileInfo loadFileInfo = new FileInfo(configFileLocation);

            if (loadFileInfo.Exists)
            {
                string json = File.ReadAllText(loadFileInfo.FullName);
                Session = JsonConvert.DeserializeObject <ApexSharpConfig>(json);

                if (Session.SessionCreationDateTime <= DateTimeOffset.Now.ToUnixTimeSeconds())
                {
                    Log.ForContext <ConnectionUtil>().Information("Session Expired, Creating a New Session");
                    Session = CreateSession(Session);
                    return(Session);
                }

                Log.ForContext <ConnectionUtil>().Information("Found Session On {configFileLocation}", configFileLocation);
                return(Session);
            }
            throw new ApexSharpNoConfigFoundException(loadFileInfo.FullName);
        }
Exemple #5
0
 public BulkApi()
 {
     _connectionDetail = ApexSharp.GetSession();
 }
Exemple #6
0
 public BulkApi()
 {
     _connectionDetail = ConnectionUtil.GetSession();
 }