示例#1
0
        static async Task <List <DatafeedEvent> > RunAsync(SymConfig symConfig, Datafeed datafeed, DatafeedClient datafeedClient)
        {
            List <DatafeedEvent> events = new List <DatafeedEvent>();

            try
            {
                events = await GetEventAsync(symConfig, datafeed, datafeedClient);

                return(events);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(events);
            }
        }
        public HttpResponseMessage executePostFormRequest(object data, String url, SymConfig symConfig)
        {
            var         message       = (OutboundMessage)data;
            HttpContent stringContent = new StringContent(message.message);

            using (var client = new HttpClient())
                using (var formData = new MultipartFormDataContent())
                {
                    formData.Add(stringContent, "message", "message");
                    if (message.attachments != null)
                    {
                        foreach (var attachment in message.attachments)
                        {
                            byte[] buffer = null;
                            buffer = new byte[attachment.Length];
                            attachment.Read(buffer, 0, (int)attachment.Length);
                            HttpContent byteArrayContent = new ByteArrayContent(buffer);

                            byteArrayContent.Headers.Add("Content-Type", "application/octet-stream");
                            var fileName = Path.GetFileName(attachment.Name);
                            formData.Add(byteArrayContent, "attachment", fileName);
                        }
                    }
                    if (message.data != null)
                    {
                        HttpContent jsonData = new StringContent(message.data);
                        formData.Add(jsonData, "data", "data");
                    }

                    client.DefaultRequestHeaders.Add("sessionToken", symConfig.authTokens.sessionToken);
                    if (symConfig.authTokens.keyManagerToken != null)
                    {
                        client.DefaultRequestHeaders.Add("keyManagerToken", symConfig.authTokens.keyManagerToken);
                    }

                    var response = client.PostAsync(url, formData).Result;

                    // ensure the request was a success
                    if (!response.IsSuccessStatusCode)
                    {
                        Debug.WriteLine(response.ToString());
                        return(null);
                    }

                    return(response);
                }
        }
        public void OBOUserLookUpTest()
        {
            SymConfig       symConfig       = new SymConfig();
            SymConfigLoader symConfigLoader = new SymConfigLoader();

            symConfig = symConfigLoader.loadFromFile("C:/Users/Michael/Documents/Visual Studio 2017/Projects/apiClientDotNet/apiClientDotNetTest/Resources/testConfig3.json");
            SymOBOAuth oboAuth = new SymOBOAuth(symConfig);

            oboAuth.sessionAppAuthenticate();
            SymOBOUserAuth auth   = oboAuth.getUserAuth("*****@*****.**");
            SymOBOClient   client = SymOBOClient.initOBOClient(symConfig, auth);

            UserClient userClient = client.getUsersClient();
            UserInfo   user       = userClient.getUserFromUsername("*****@*****.**");

            Assert.IsTrue(user != null);
        }
示例#4
0
        static void Main(string[] args)
        {
            string filePath = Path.GetFullPath("config.json");

            SymBotClient          symBotClient          = new SymBotClient();
            DatafeedEventsService datafeedEventsService = new DatafeedEventsService();

            symConfig = symBotClient.initBot(filePath);


            RoomListener   botLogic       = new BotLogic();
            DatafeedClient datafeedClient = datafeedEventsService.init(symConfig);
            Datafeed       datafeed       = datafeedEventsService.createDatafeed(symConfig, datafeedClient);

            datafeedEventsService.addRoomListener(botLogic);
            datafeedEventsService.getEventsFromDatafeed(symConfig, datafeed, datafeedClient);
        }
示例#5
0
        public static void Init(TestContext context)
        {
            // Load integration test settings
            var integrationConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "integration.parameters.json");

            config = new ConfigurationBuilder().AddJsonFile(integrationConfigPath).Build();

            // Create SymBotClient
            var symConfig       = new SymConfig();
            var symConfigLoader = new SymConfigLoader();
            var configPath      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "config.json");

            symConfig = symConfigLoader.loadFromFile(configPath);
            var botAuth = new SymBotRSAAuth(symConfig);

            botAuth.authenticate();
            symBotClient = SymBotClient.initBot(symConfig, botAuth);
        }
示例#6
0
        public void removeMemberFromRoom(String streamId, long userId)
        {
            SymConfig symConfig = botClient.getConfig();
            NumericId id        = new NumericId();

            id.id = userId;
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url  = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.REMOVEMEMBER.Replace("{id}", streamId);
            HttpWebResponse    resp = restRequestHandler.executeRequest(null, url, false, WebRequestMethods.Http.Post, symConfig, true);

            if (resp.StatusCode == HttpStatusCode.NoContent)
            {
                throw new Exception("No user found.");
            }
            else if (resp.StatusCode == HttpStatusCode.OK)
            {
                string body = restRequestHandler.ReadResponse(resp);
            }
        }
        public InboundMessage sendMessage(String streamId, OutboundMessage message, Boolean appendTags)
        {
            SymConfig          symConfig          = botClient.getConfig();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url = "https://" + symConfig.agentHost + ":" + symConfig.agentPort + "/agent/v4/stream/" + streamId + "/message/create";

            if (botClient is SymOBOClient)
            {
                symConfig.authTokens.sessionToken = botClient.getSymAuth().getSessionToken();
            }
            if (appendTags && message.message != null)
            {
                message.message = "<messageML>" + message.message + "</messageML>";
            }
            HttpResponseMessage resp           = restRequestHandler.executePostFormRequest(message, url, symConfig);
            InboundMessage      inboundMessage = JsonConvert.DeserializeObject <InboundMessage>(resp.Content.ReadAsStringAsync().Result);

            return(inboundMessage);
        }
示例#8
0
        //TODO: CHECK WHY 500
        public RoomSearchResult searchRooms(RoomSearchQuery query, int skip, int limit)
        {
            RoomSearchResult result    = null;
            SymConfig        symConfig = botClient.getConfig();

            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.SEARCHROOMS;


            if (skip > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&skip=" + skip;
                }
                else
                {
                    url = url + "?skip=" + skip;
                }
            }
            if (limit > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&limit=" + limit;
                }
                else
                {
                    url = url + "?limit=" + limit;
                }
            }
            if (query.labels == null)
            {
                query.labels = new List <String>();
            }
            HttpWebResponse resp = restRequestHandler.executeRequest(query, url, false, WebRequestMethods.Http.Post, symConfig, true);
            string          body = restRequestHandler.ReadResponse(resp);

            result = JsonConvert.DeserializeObject <RoomSearchResult>(body);

            return(result);
        }
        public UserInfo getUserFromEmail(String email, Boolean local)
        {
            SymConfig          symConfig          = botClient.getConfig();
            UserInfo           info               = null;
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url  = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.GETUSERSV3 + "?email=" + email + "&local=" + local;
            HttpWebResponse    resp = restRequestHandler.executeRequest(null, url, false, WebRequestMethods.Http.Get, symConfig, true);

            if (resp.StatusCode == HttpStatusCode.NoContent)
            {
                throw new Exception("No user found.");
            }
            else if (resp.StatusCode == HttpStatusCode.OK)
            {
                string body = restRequestHandler.ReadResponse(resp);
                info = JsonConvert.DeserializeObject <UserInfo>(body);
            }

            return(info);
        }
        public SignalSubscriptionResult subscribeSignal(String id, Boolean self, List<long> uids, Boolean pushed)
        {

            SymConfig symConfig = botClient.getConfig();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            HttpWebResponse resp;
            if (self) {
                string url = CommonConstants.HTTPSPREFIX + symConfig.agentHost + ":" + symConfig.agentPort + AgentConstants.SUBSCRIBESIGNAL.Replace("{id}", id);
                resp = restRequestHandler.executeRequest(null, url, false, WebRequestMethods.Http.Post, symConfig, true);
                
             } else {

                string url = CommonConstants.HTTPSPREFIX + symConfig.agentHost + ":" + symConfig.agentPort + AgentConstants.SUBSCRIBESIGNAL.Replace("{id}", id) + "?pushed=" + pushed;
                resp = restRequestHandler.executeRequest(uids, url, false, WebRequestMethods.Http.Post, symConfig, true);
                
            }

            string body = restRequestHandler.ReadResponse(resp);
            return JsonConvert.DeserializeObject<SignalSubscriptionResult>(body);
        }
示例#11
0
        public RoomInfo createRoom(Room room)
        {
            SymConfig          symConfig          = botClient.getConfig();
            RoomInfo           roomInfo           = new RoomInfo();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url  = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.CREATEROOM;
            HttpWebResponse    resp = restRequestHandler.executeRequest(room, url, false, WebRequestMethods.Http.Post, symConfig, true);

            if (resp.StatusCode == HttpStatusCode.NoContent)
            {
                throw new Exception("No user found.");
            }
            else if (resp.StatusCode == HttpStatusCode.OK)
            {
                string body = restRequestHandler.ReadResponse(resp);
                roomInfo = JsonConvert.DeserializeObject <RoomInfo>(body);
            }

            return(roomInfo);
        }
示例#12
0
        public String getUserListIM(List <long> userIdList)
        {
            SymConfig          symConfig          = botClient.getConfig();
            StringId           id                 = new StringId();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url                = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.GETIM;
            HttpWebResponse    resp               = restRequestHandler.executeRequest(userIdList, url, false, WebRequestMethods.Http.Post, symConfig, true);

            if (resp.StatusCode == HttpStatusCode.NoContent)
            {
                throw new Exception("No user found.");
            }
            else if (resp.StatusCode == HttpStatusCode.OK)
            {
                string body = restRequestHandler.ReadResponse(resp);
                id = JsonConvert.DeserializeObject <StringId>(body);
            }

            return(id.id);
        }
        public void UserListStreams()
        {
            SymConfig       symConfig       = new SymConfig();
            SymConfigLoader symConfigLoader = new SymConfigLoader();

            symConfig = symConfigLoader.loadFromFile("C:/Users/Michael/Documents/Visual Studio 2017/Projects/apiClientDotNet/apiClientDotNetTest/Resources/testConfig.json");
            SymBotAuth botAuth = new SymBotAuth(symConfig);

            botAuth.authenticate();
            SymBotClient botClient = SymBotClient.initBot(symConfig, botAuth);

            StreamClient  streamClient = botClient.getStreamsClient();
            List <string> streamTypes  = new List <string>();

            streamTypes.Add("IM");
            streamTypes.Add("ROOM");
            List <StreamListItem> result = streamClient.getUserStreams(streamTypes, false);

            Assert.IsTrue(result != null);
        }
示例#14
0
        //TODO: CHECK WHY 404
        public StreamInfo getStreamInfo(String streamId)
        {
            SymConfig          symConfig          = botClient.getConfig();
            StreamInfo         streamInfo         = new StreamInfo();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url  = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.GETSTREAMINFO.Replace("{id}", streamId);
            HttpWebResponse    resp = restRequestHandler.executeRequest(null, url, false, WebRequestMethods.Http.Get, symConfig, true);

            if (resp.StatusCode == HttpStatusCode.NoContent)
            {
                throw new Exception("No stream found.");
            }
            else if (resp.StatusCode == HttpStatusCode.OK)
            {
                string body = restRequestHandler.ReadResponse(resp);

                streamInfo = JsonConvert.DeserializeObject <StreamInfo>(body);
            }
            return(streamInfo);
        }
示例#15
0
        public RoomInfo updateRoom(String streamId, Room room)
        {
            SymConfig          symConfig          = botClient.getConfig();
            RoomInfo           roomInfo           = new RoomInfo();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url  = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.UPDATEROOMINFO.Replace("{id}", streamId);
            HttpWebResponse    resp = restRequestHandler.executeRequest(room, url, false, WebRequestMethods.Http.Post, symConfig, true);

            //.post(Entity.entity(room, MediaType.APPLICATION_JSON));
            if (resp.StatusCode == HttpStatusCode.NoContent)
            {
                throw new Exception("No user found.");
            }
            else if (resp.StatusCode == HttpStatusCode.OK)
            {
                string body = restRequestHandler.ReadResponse(resp);

                roomInfo = JsonConvert.DeserializeObject <RoomInfo>(body);
            }
            return(roomInfo);
        }
        public void SearchRoom()
        {
            SymConfig       symConfig       = new SymConfig();
            SymConfigLoader symConfigLoader = new SymConfigLoader();

            symConfig = symConfigLoader.loadFromFile("C:/Users/Michael/Documents/Visual Studio 2017/Projects/apiClientDotNet/apiClientDotNetTest/Resources/testConfig.json");
            SymBotAuth botAuth = new SymBotAuth(symConfig);

            botAuth.authenticate();
            SymBotClient botClient = SymBotClient.initBot(symConfig, botAuth);

            StreamClient    streamClient    = botClient.getStreamsClient();
            RoomSearchQuery roomSearchQuery = new RoomSearchQuery();

            roomSearchQuery.query     = "APITestRoom";
            roomSearchQuery.active    = true;
            roomSearchQuery.isPrivate = true;
            RoomSearchResult result = streamClient.searchRooms(roomSearchQuery, 0, 0);

            Assert.IsTrue(result != null);
        }
        public SymConfig loadFromFile(String fileLocation)
        {
            SymConfig symConfig = new SymConfig();

            try
            {
                using (StreamReader sr = new StreamReader(fileLocation))
                {
                    String json = sr.ReadToEnd();
                    symConfig = JsonConvert.DeserializeObject <SymConfig>(json);
                    Console.WriteLine(symConfig.sessionAuthHost);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            return(symConfig);
        }
示例#18
0
        public List <RoomMember> getRoomMembers(String streamId)
        {
            SymConfig          symConfig          = botClient.getConfig();
            List <RoomMember>  roomMembers        = new List <RoomMember>();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url  = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.GETROOMMEMBERS.Replace("{id}", streamId);
            HttpWebResponse    resp = restRequestHandler.executeRequest(null, url, false, WebRequestMethods.Http.Get, symConfig, true);

            if (resp.StatusCode == HttpStatusCode.NoContent)
            {
                throw new Exception("No stream found.");
            }
            else if (resp.StatusCode == HttpStatusCode.OK)
            {
                string body = restRequestHandler.ReadResponse(resp);

                roomMembers = JsonConvert.DeserializeObject <List <RoomMember> >(body);
            }

            return(roomMembers);
        }
        private HttpWebResponse postApi(SymConfig symConfig, string url, object data, bool isAgent)
        {
            var targetUri = new System.Uri(url);
            var request   = (HttpWebRequest)WebRequest.Create(targetUri);

            SetProxy(request, symConfig);
            request.Method      = "POST";
            request.ContentType = "application/json";
            request.Accept      = "application/json";

            //request.Headers["Pragma"] = "no-cache";
            var json = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(data, Formatting.Indented));

            if (isAgent)
            {
                request.Headers.Add("sessionToken", symConfig.authTokens.sessionToken);
                request.Headers.Add("keyManagerToken", symConfig.authTokens.keyManagerToken);
            }
            else
            {
                request.Headers.Add("sessionToken", symConfig.authTokens.sessionToken);
            }

            request.Method      = "POST";
            request.ContentType = "application/json";
            if (data != null)
            {
                request.ContentLength = json.Length;

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(json, 0, json.Length);
                }
            }

            var response = (HttpWebResponse)request.GetResponse();

            return(response);
        }
        public List <Signal> listSignals(int skip, int limit)
        {
            List <Signal>      result             = new List <Signal>();
            SymConfig          symConfig          = botClient.getConfig();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url = CommonConstants.HTTPSPREFIX + symConfig.agentHost + ":" + symConfig.agentPort + AgentConstants.LISTSIGNALS;


            if (skip > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&skip=" + skip;
                }
                else
                {
                    url = url + "?skip=" + skip;
                }
            }
            if (limit > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&limit=" + limit;
                }
                else
                {
                    url = url + "?limit=" + limit;
                }
            }
            HttpWebResponse resp = restRequestHandler.executeRequest(null, url, false, WebRequestMethods.Http.Get, symConfig, true);
            string          body = restRequestHandler.ReadResponse(resp);

            resp.Close();
            result = JsonConvert.DeserializeObject <List <Signal> >(body);

            return(result);
        }
示例#21
0
        public string generateJWT(SymConfig config)
        {
            string   jwt       = "";
            DateTime otherTime = DateTime.Now.AddMinutes(4);

            var payload = new JwtPayload
            {
                { "sub", config.botUsername },
                { "exp", ToUtcSeconds(otherTime) }
            };

            var tokenHandler = new JwtSecurityTokenHandler();
            var certificate  = new X509Certificate2(config.botPrivateKeyPath + config.botPrivateKeyName, "changeit");
            var securityKey  = new Microsoft.IdentityModel.Tokens.X509SecurityKey(certificate);
            var credentials  = new Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, SecurityAlgorithms.RsaSha512);
            var header       = new JwtHeader(credentials);
            var secToken     = new JwtSecurityToken(header, payload);
            var handler      = new JwtSecurityTokenHandler();

            var tokenString = handler.WriteToken(secToken);

            return(tokenString);
        }
        public SignalSubscriberList getSignalSubscribers(String id, int skip, int limit)
        {
            SymConfig          symConfig          = botClient.getConfig();
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url = CommonConstants.HTTPSPREFIX + symConfig.agentHost + ":" + symConfig.agentPort + AgentConstants.GETSUBSCRIBERS.Replace("{id}", id);

            if (skip > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&skip=" + skip;
                }
                else
                {
                    url = url + "?skip=" + skip;
                }
            }
            if (limit > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&limit=" + limit;
                }
                else
                {
                    url = url + "?limit=" + limit;
                }
            }


            HttpWebResponse resp = restRequestHandler.executeRequest(null, url, false, WebRequestMethods.Http.Get, symConfig, true);
            string          body = restRequestHandler.ReadResponse(resp);

            resp.Close();
            return(JsonConvert.DeserializeObject <SignalSubscriberList>(body));
        }
示例#23
0
        public List <InboundMessage> getMessagesFromStream(String streamId, int since, int skip, int limit)
        {
            List <InboundMessage> result    = null;
            SymConfig             symConfig = botClient.getConfig();

            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             getMessageUrl      = AgentConstants.GETMESSAGES.Replace("{sid}", streamId);
            string             url = CommonConstants.HTTPSPREFIX + symConfig.agentHost + ":" + symConfig.agentPort + getMessageUrl + "?since=" + since.ToString();


            if (skip > 0)
            {
                url = url + "&skip=" + skip;
            }
            if (limit > 0)
            {
                url = url + "&limit=" + limit;
            }
            HttpWebResponse       resp            = restRequestHandler.executeRequest(null, url, false, WebRequestMethods.Http.Get, symConfig, true);
            string                body            = restRequestHandler.ReadResponse(resp);
            List <InboundMessage> inboundMessages = JsonConvert.DeserializeObject <List <InboundMessage> >(body);

            return(inboundMessages);
        }
        public void OBOUserAndRoomSeaerch()
        {
            SymConfig       symConfig       = new SymConfig();
            SymConfigLoader symConfigLoader = new SymConfigLoader();

            symConfig = symConfigLoader.loadFromFile("C:/Users/Michael/Documents/Visual Studio 2017/Projects/apiClientDotNet/apiClientDotNetTest/Resources/testConfig3.json");
            SymOBOAuth oboAuth = new SymOBOAuth(symConfig);

            oboAuth.sessionAppAuthenticate();
            SymOBOUserAuth auth   = oboAuth.getUserAuth("*****@*****.**");
            SymOBOClient   client = SymOBOClient.initOBOClient(symConfig, auth);

            UserClient userClient = client.getUsersClient();
            UserInfo   user       = userClient.getUserFromUsername("*****@*****.**");

            StreamClient  streamClient = client.getStreamsClient();
            List <string> streamTypes  = new List <string>();

            streamTypes.Add("IM");
            streamTypes.Add("ROOM");
            List <StreamListItem> result = streamClient.getUserStreams(streamTypes, false);

            Assert.IsTrue(user != null);
        }
示例#25
0
        public static void Init(TestContext context)
        {
            // Load integration test settings
            var integrationConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "integration.parameters.json");

            config = new ConfigurationBuilder().AddJsonFile(integrationConfigPath).Build();

            // Create SymBotClient
            var symConfig       = new SymConfig();
            var symConfigLoader = new SymConfigLoader();
            var configPath      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "config.json");

            symConfig = symConfigLoader.loadFromFile(configPath);
            var botAuth = new SymBotRSAAuth(symConfig);

            botAuth.authenticate();
            symBotClient = SymBotClient.initBot(symConfig, botAuth);

            var userReceiverEmail = config.GetSection(typeof(ConnectionsClientIntegrationTest).Name).GetSection("test_email_address_user_receiver").Value;

            UserClient userClient = new UserClient(symBotClient);

            userReceiver = userClient.getUserFromEmail(userReceiverEmail, false)[0];
        }
        public void OBOIMCreateTest()
        {
            SymConfig       symConfig       = new SymConfig();
            SymConfigLoader symConfigLoader = new SymConfigLoader();

            symConfig = symConfigLoader.loadFromFile("C:/Users/Michael/Documents/Visual Studio 2017/Projects/apiClientDotNet/apiClientDotNetTest/Resources/testConfig3.json");
            SymOBOAuth oboAuth = new SymOBOAuth(symConfig);

            oboAuth.sessionAppAuthenticate();
            SymOBOUserAuth auth   = oboAuth.getUserAuth("*****@*****.**");
            SymOBOClient   client = SymOBOClient.initOBOClient(symConfig, auth);

            UserClient userClient = client.getUsersClient();
            UserInfo   user       = userClient.getUserFromUsername("*****@*****.**");

            StreamClient streamClient = new StreamClient(client);

            List <long> userids = new List <long>();

            userids.Add(user.id);
            String streamid = streamClient.getUserListIM(userids);

            Assert.IsTrue(streamid != null);
        }
示例#27
0
        public Datafeed createDatafeed(SymConfig symConfig, DatafeedClient datafeedClient)
        {
            Datafeed datafeed = datafeedClient.createDatafeed(symConfig);

            return(datafeed);
        }
        public HttpWebResponse executeRequest(object data, String url, bool isAuth, string method, SymConfig symConfig, bool isAgent)
        {
            HttpWebResponse response = null;

            //If POST and not Auth set response to postApi
            if (method == WebRequestMethods.Http.Post && isAuth != true)
            {
                response = postApi(symConfig, url, data, isAgent);
            }
            //If not create HttpWebRequest
            else
            {
                var request = (HttpWebRequest)WebRequest.Create(url);
                SetProxy(request, symConfig);

                request.Credentials = CredentialCache.DefaultCredentials;
                request.Method      = method;

                //If Auth Call
                if (isAuth)
                {
                    //If RSAAuth
                    if (url.EndsWith("pubkey/authenticate"))
                    {
                        request.Credentials = null;
                        if (data != null)
                        {
                            var json      = JsonConvert.SerializeObject(data);
                            var jsonBytes = Encoding.ASCII.GetBytes(json);
                            request.ContentLength = jsonBytes.Length;

                            using (var stream = request.GetRequestStream())
                            {
                                stream.Write(jsonBytes, 0, jsonBytes.Length);
                            }
                        }
                    }
                    else
                    {
                        Certificates = new X509CertificateCollection();
                        var cert = File.ReadAllBytes(symConfig.botCertPath + symConfig.botCertName + ".p12");
                        Certificates.Add(new X509Certificate2(cert, symConfig.botCertPassword));
                        request.ClientCertificates.AddRange(Certificates);
                        if (symConfig.authTokens != null)
                        {
                            request.Headers.Add("sessionToken", symConfig.authTokens.sessionToken);
                        }
                    }
                }
                else
                {
                    //If not Auth call add sessionToken and if Agent keyManagerToken
                    request.Headers.Add("sessionToken", symConfig.authTokens.sessionToken);
                    if (isAgent)
                    {
                        request.Headers.Add("keyManagerToken", symConfig.authTokens.keyManagerToken);
                    }
                }

                //Make request and get response
                try
                {
                    response = (HttpWebResponse)request.GetResponse();
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        var errorHandler = new ErrorHandler();
                        errorHandler.handleError(response);
                    }

                    return(response);
                }
                catch (WebException we)
                {
                    response = we.Response as HttpWebResponse;
                    Console.Write(response);
                }

                response = null;
            }

            return(response);
        }
示例#29
0
 public static SymOBOClient initOBOClient(SymConfig config, ISymAuth symBotAuth)
 {
     botClient = new SymOBOClient(config, symBotAuth);
     return(botClient);
 }
示例#30
0
 private SymOBOClient(SymConfig config, ISymAuth symBotAuth)
 {
     this.symBotAuth = symBotAuth;
     this.config     = config;
 }