Exemplo n.º 1
0
        public async Task <SaveExOzRegionCommandResult> Synchronize(string obj)
        {
            string line = "";

            _logger.StartMsg("Regions");
            var            postResponse       = HttpWebRequestHelper.ExOz_WebRequestGet("");
            ExOzRegionList exOzRegionResponse = Mapper <ExOzRegionList> .MapFromJson(postResponse);

            var regionList = exOzRegionResponse.regions;

            //Get Region details and prepare list of Operators
            List <ExOzRegionResponse> regionDetailsList = new List <ExOzRegionResponse>();
            OperatorList operatorList = new OperatorList()
            {
                operators = new List <ExOzOperatorResponse>()
            };

            int i = 0;

            foreach (var region in exOzRegionResponse.regions)
            {
                try
                {
                    string             regionDetails = HttpWebRequestHelper.ExOz_WebRequestGet(region.UrlSegment);
                    ExOzRegionResponse objRegion     = Mapper <ExOzRegionResponse> .MapFromJson(regionDetails);

                    foreach (var item in objRegion.Operators)
                    {
                        item.RegionId         = objRegion.Id;
                        item.RegionUrlSegment = objRegion.UrlSegment;
                        operatorList.operators.Add(item);
                    }
                    regionDetailsList.Add(objRegion);
                }
                catch (Exception e)
                {
                    _logger.Log($"Exceptions: {e.Message}");
                }
                i++;
                line = _logger.Update(i, exOzRegionResponse.regions.Count, line);
            }

            //Code to insert Regions
            try
            {
                SaveExOzRegionCommandResult retRegions = await _commandSender.Send <SaveExOzRegionCommand, SaveExOzRegionCommandResult>(new SaveExOzRegionCommand
                {
                    RegionList = regionDetailsList
                });

                _logger.FinishMsg(retRegions.RegionList.Count, "Regions");
                retRegions.OperatorList = operatorList;
                return(retRegions);
            }
            catch (Exception e)
            {
                _logger.Log($"Exception: {e.Message}");
                throw;
            }
        }
Exemplo n.º 2
0
        public bool TrySend(string message, int timeout, int maxRetries)
        {
            _consoleLogger.Log($"Sending command to drone: {message}");
            bool successfullFlag = false;

            while (maxRetries > 0 && successfullFlag == false)
            {
                _client.Client.ReceiveTimeout = timeout;
                _client.Send(Encoding.ASCII.GetBytes(message), message.Length);

                try
                {
                    var bytes         = _client.Receive(ref _sendIpEndPoint);
                    var returnMessage = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
                    _consoleLogger.Log($"Drone responded with: {returnMessage}");
                    if (returnMessage == "ok")
                    {
                        successfullFlag = true;
                    }
                }
                catch (Exception x)
                {
                    _consoleLogger.Log(x.Message);
                    _consoleLogger.Log($"Recieved {x.Message} from the drone, will attempt {maxRetries.ToString()} more times");
                }

                maxRetries--;
            }
            return(successfullFlag);
        }
Exemplo n.º 3
0
        public void Run()
        {
            while (true)
            {
                _consoleLogger.Log("Choose a mission to run.");
                for (int x = 0; x < _missionList.GetMissionList().Count; x++)
                {
                    var currentMission = _missionList.GetMissionList()[x];
                    _consoleLogger.Log($"{x+1}: {currentMission.Item1}");
                }


                var userInput = Convert.ToInt16(Console.ReadLine());
                _missionCommander.RunMission(_missionList.GetMissionList()[userInput - 1].Item2);
            }
        }
Exemplo n.º 4
0
        public UdpClientWrapper(IConsoleLogger consoleLogger)
        {
            _consoleLogger = consoleLogger;
            consoleLogger.Log("Enter Drone IPAddress:");
            var droneIpAddress = Console.ReadLine();

            consoleLogger.Log("Enter Drone Port Number:");
            var dronePortNumber = Convert.ToInt32(Console.ReadLine());

            if (droneIpAddress != null)
            {
                _client         = new UdpClient(droneIpAddress, dronePortNumber);
                _sendIpEndPoint = new IPEndPoint(IPAddress.Parse(droneIpAddress),
                                                 dronePortNumber);
            }
        }
Exemplo n.º 5
0
        public async Task <SaveExOzCountryCommandResult> UpdateCountries()
        {
            _logger.StartMsg("Countries");

            var postResponse = HttpWebRequestHelper.ExOz_WebRequestGet("");

            Contracts.Models.Integrations.ExOz.StateResponseList exOzStateResponse = Mapper <Contracts.Models.Integrations.ExOz.StateResponseList> .MapFromJson(postResponse);

            var countryList = exOzStateResponse.states.Select(m => m.Country).Distinct();

            //Code to insert countries

            try
            {
                var retCountries = await _commandSender.Send <SaveExOzCountryCommand, SaveExOzCountryCommandResult>
                                       (new SaveExOzCountryCommand
                {
                    Names = countryList.ToList()
                });

                _logger.FinishMsg(retCountries.CountryList.Count(), "Countries");

                return(retCountries);
            }
            catch (Exception e)
            {
                _logger.Log($"Exception: {e.Message}");
                throw;
            }
        }
Exemplo n.º 6
0
        public IEnumerable <string> Get()
        {
            /*
             * TODO: Shouldn't be using ConsoleLogger directly. What if we wanted to use a different type of logger?
             */
            loggingService.Log("GET hobbits returning " + database.Size());
            watchService.Lap("Controller");

            return(database.GetData("Hobbit"));
        }
Exemplo n.º 7
0
        public async Task DoFacebook()
        {
            // Get FB account
            var account = await _facebookService.GetAccountAsync(FacebookSettings.AccessToken);

            _consoleLogger.Log(account);

            // Get list of FB pages for that account
            var pages = await _facebookService.GetPagesAsync(FacebookSettings.AccessToken);

            // Get IG accounts associated with FB pages
            foreach (var page in pages)
            {
                await _facebookService.SetInstagramAccounts(page);
            }

            _consoleLogger.Log(pages);

            // Post an Image to IG
            var postedMediaIds = new List <string>();

            foreach (var page in pages)
            {
                // TODO: Doesn't work due to FB api errors
                //var mediaId = await _facebookService.PostImageToInstagram(page, FacebookSettings.TestImageUrl, FacebookSettings.TestCaption);
                //postedMediaIds.Add(mediaId);
            }

            // Get impressions by IG media ID
            var metricsList = new List <InstagramMetrics>();

            foreach (var mediaId in postedMediaIds)
            {
                // TODO: Doesn't work due to FB api errors
                //var metrics = await _facebookService.GetInstagramMetrics(FacebookSettings.AccessToken, mediaId);
                //metricsList.Add(metrics);
            }

            _consoleLogger.Log(metricsList);

            System.Console.ReadLine();
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            IConsoleLogger logger = SelectLogger(args.Length);

            logger.Log(new ConsoleLogEntry()
            {
                Format  = "Log output is {0}",
                Message = "LALALA"
            });

            Console.Read();
        }
Exemplo n.º 9
0
        private JsValue Log(JsValue ctx, JsValue[] args)
        {
            if (_logger != null)
            {
                var objs = new Object[args.Length];

                for (var i = 0; i < args.Length; i++)
                {
                    objs[i] = args[i].FromJsValue();
                }

                _logger.Log(objs);
            }

            return(JsValue.Undefined);
        }
Exemplo n.º 10
0
        public async Task <List <ExOzProductOption> > Synchronize(ProductOptionList productOptionDetails)
        {
            _logger.StartMsg("Options");

            //Insert Options Here
            try
            {
                SaveExOzProductOptionCommandResult retOptions = await _commandSender.Send <SaveExOzProductOptionCommand, SaveExOzProductOptionCommandResult>(new SaveExOzProductOptionCommand
                {
                    OptionList = productOptionDetails.ProductOptions,
                    ModifiedBy = new Guid("C043DDEE-D0B1-48D8-9C3F-309A77F44793")
                });

                _logger.FinishMsg(retOptions.OptionList.Count, "Options");
                return(retOptions.OptionList);
            }
            catch (Exception e)
            {
                _logger.Log($"Exception: {e.Message}");
                throw;
            }
        }
Exemplo n.º 11
0
        public async Task <ProductList> Synchronize(OperatorList operatorList)
        {
            string line = "";

            _logger.StartMsg("Operators");

            int i = 0;

            foreach (var op in operatorList.operators)
            {
                try
                {
                    string input = op.CanonicalRegionUrlSegment + "/" + op.UrlSegment;
                    ExOzOperatorResponse opDetails = new ExOzOperatorResponse();

                    string postResponse = HttpWebRequestHelper.ExOz_WebRequestGet(input);
                    if (postResponse != "0")
                    {
                        opDetails = Mapper <ExOzOperatorResponse> .MapFromJson(postResponse);
                    }
                    if (opDetails.Id != -1 && opDetails.Geolocations != null && opDetails.Geolocations[0].Address != null)
                    {
                        opDetails.RegionId         = op.RegionId;
                        opDetails.RegionUrlSegment = op.RegionUrlSegment;
                        CommonFunctions.replaceSingleQuotes(opDetails.Name);
                        CommonFunctions.replaceSingleQuotes(opDetails.PublicName);
                        CommonFunctions.replaceSingleQuotes(opDetails.Summary);
                        CommonFunctions.replaceSingleQuotes(opDetails.Tips);
                        CommonFunctions.replaceSingleQuotes(opDetails.Description);
                        CommonFunctions.replaceSingleQuotes(opDetails.Address);

                        //operatorList.operators = new List<ExOzOperatorResponse>();
                        OperatorList operatorDetails = new OperatorList()
                        {
                            operators = new List <ExOzOperatorResponse>()
                        };

                        operatorDetails.operators.Add(opDetails);
                        SaveExOzOperatorCommandResult retOperators = new SaveExOzOperatorCommandResult()
                        {
                            OperatorList = new List <ExOzOperator>()
                        };

                        retOperators = await _commandSender.Send <SaveExOzOperatorCommand, SaveExOzOperatorCommandResult>(new SaveExOzOperatorCommand
                        {
                            OperatorList = operatorDetails.operators,
                            ModifiedBy   = new Guid("C043DDEE-D0B1-48D8-9C3F-309A77F44795")
                        });

                        if (opDetails.Products != null)
                        {
                            ProductList productList = new ProductList
                            {
                                Products = new List <ExOzProductResponse>()
                            };

                            foreach (var prod in opDetails.Products)
                            {
                                prod.CanonicalRegionUrlSegment = opDetails.CanonicalRegionUrlSegment;
                                prod.OperatorUrlSegment        = opDetails.UrlSegment;
                                productList.Products.Add(prod);
                            }

                            _logger.StartMsg("Product");
                            SessionList sessionResponse = await _productSynchronizer.Synchronize(productList);
                        }
                    }
                    i++;
                    line = _logger.Update(i, operatorList.operators.Count, line);
                }
                catch (Exception e)
                {
                    _logger.Log($"Exception: {e.Message}");
                    continue;
                }
            }
            ////Insert Operators here
            //try
            //{


            //    _logger.FinishMsg(retOperators.OperatorList.Count, "Operators");
            //    return productList;
            //}
            //catch (Exception e)
            //{
            //    _logger.Log($"Exception: {e.Message}");
            //    throw;
            //}

            return(null);
        }