Ejemplo n.º 1
0
        public RequestFormModel(ExtendedConfiguration config)
        {
            this.config = config;
            RegionsText = "51.53,-0.18\n55.77,37.64\n-23.10,-43.22";

            YearsMode           = Models.YearsMode.Cells;
            YearCellStart       = "1980";
            YearCellEnd         = "2000";
            YearCellSize        = "20";
            IndividualYearStart = "1980";
            IndividualYearEnd   = "2000";
            IndividualYearStep  = "5";

            DaysMode           = Models.DaysMode.MonthlyCells;
            DayCellStart       = "1";
            DayCellEnd         = "365";
            DayCellSize        = "7";
            IndividualDayStart = "1";
            IndividualDayStep  = "7";
            IndividualDayEnd   = "365";

            HoursMode           = Models.HoursMode.EntireDay;
            HourCellStart       = "0";
            HourCellEnd         = "24";
            HourCellSize        = "6";
            IndividualHourStart = "0";
            IndividualHourEnd   = "24";
            IndividualHourStep  = "6";
        }
Ejemplo n.º 2
0
    public int Calculate(int userId, Configuration configuration)
    {
        var extendedConfig = new ExtendedConfiguration {
            Max = configuration.Max,
            Min = configuration.Min
        };

        return(e.Max - e.Min);
    }
Ejemplo n.º 3
0
        public RequestFormModel(ExtendedConfiguration config, Stream requestStream) : this(config)
        {
            try
            {
                StreamReader reader   = new StreamReader(requestStream, Encoding.UTF8);
                var          requests =
                    JsonConvert.DeserializeObject <Microsoft.Research.Science.FetchClimate2.Serializable.FetchRequest[]>(reader.ReadToEnd());
                if (requests.Length > 0)
                {
                    var firstVariable = requests[0].EnvironmentVariableName;
                    for (var i = 0; i < requests.Length && requests[i].EnvironmentVariableName == firstVariable; i++)
                    {
                        if (requests[i].Domain.SpatialRegionType == "Points")
                        {
                            points.AddRange(requests[i].Domain.Lats.Zip(requests[i].Domain.Lons, (lat, lon) => new GeoPoint(lat, lon)));
                        }
                        else if (requests[i].Domain.SpatialRegionType == "CellGrid")
                        {
                            grids.Add(new GeoGrid(requests[i].Domain.Lats, requests[i].Domain.Lons));
                        }
                        else
                        {
                            throw new Exception("Region type \'" + requests[i].Domain.SpatialRegionType + "\' is not supported");
                        }
                    }

                    foreach (var r in requests)
                    {
                        if (!variables.ContainsKey(r.EnvironmentVariableName))
                        {
                            if (!config.EnvironmentalVariables.Any(vd => vd.Name == r.EnvironmentVariableName))
                            {
                                throw new Exception("Variable " + r.EnvironmentVariableName + " is not availble in current service configuration");
                            }
                            variables.Add(r.EnvironmentVariableName, r.ParticularDataSources.ToList());
                        }
                    }
                }
                RegionsText = GetRegionsText();
            }
            catch (Exception exc)
            {
                RequestUploadErrors = exc.Message;
            }
        }
Ejemplo n.º 4
0
        public RequestFormModel(ExtendedConfiguration config, NameValueCollection form, bool fromPost) : this(config)
        {
            if (fromPost)
            {
                // Get selected variables from form
                foreach (string key in form)
                {
                    if (key.StartsWith("variable_"))
                    {
                        int           idx   = key.LastIndexOf("_");
                        var           vname = key.Substring(9, idx - 9);
                        var           dsID  = Int32.Parse(key.Substring(idx + 1));
                        List <string> dsList;
                        if (!variables.TryGetValue(vname, out dsList))
                        {
                            dsList = new List <string>();
                            variables.Add(vname, dsList);
                        }
                        dsList.Add(config.DataSources.Where(ds => ds.ID == dsID).First().Name);
                    }
                }
                if (variables.Count == 0)
                {
                    variableErrors = "No variables selected";
                }

                try
                {
                    ParseRegion(RegionsText = form["regionText"]);
                }
                catch (Exception exc)
                {
                    regionErrors = exc.Message;
                }

                YearCellStart       = (string)form["yearCellStart"];
                YearCellEnd         = (string)form["yearCellEnd"];
                YearCellSize        = (string)form["yearCellSize"];
                IndividualYearStart = (string)form["indYearStart"];
                IndividualYearEnd   = (string)form["indYearEnd"];
                IndividualYearStep  = (string)form["indYearStep"];
                try
                {
                    switch ((string)form["yearsMode"])
                    {
                    case "cells":
                        tr        = tr.GetYearlyTimeseries(Int32.Parse(YearCellStart), Int32.Parse(YearCellEnd), Int32.Parse(YearCellSize), true);
                        YearsMode = Models.YearsMode.Cells;
                        break;

                    case "years":
                        tr        = tr.GetYearlyTimeseries(Int32.Parse(IndividualYearStart), Int32.Parse(IndividualYearEnd), Int32.Parse(IndividualYearStep), true);
                        YearsMode = Models.YearsMode.Points;
                        break;
                    }
                }
                catch (Exception exc)
                {
                    intervalErrors = "Year axis specification has errors: " + exc.Message;
                }

                DayCellStart       = (string)form["dayCellStart"];
                DayCellEnd         = (string)form["dayCellEnd"];
                DayCellSize        = (string)form["dayCellSize"];
                IndividualDayStart = (string)form["inDayStart"];
                IndividualDayEnd   = (string)form["inDayEnd"];
                IndividualDayStep  = (string)form["inDayStep"];
                try
                {
                    switch ((string)form["daysMode"])
                    {
                    case "cells":
                        tr = tr.GetSeasonlyTimeseries(Int32.Parse(DayCellStart), Int32.Parse(DayCellEnd), Int32.Parse(DayCellSize), true);
                        break;

                    case "days":
                        tr = tr.GetSeasonlyTimeseries(Int32.Parse(IndividualDayStart), Int32.Parse(IndividualDayEnd), Int32.Parse(IndividualDayEnd), true);
                        break;

                    case "monthly":
                        tr = tr.GetMonthlyTimeseries();
                        break;
                    }
                }
                catch (Exception exc)
                {
                    if (!String.IsNullOrEmpty(intervalErrors))
                    {
                        intervalErrors += "\n";
                    }
                    intervalErrors += "Days axis specification has errors: " + exc.Message;
                }

                HourCellStart       = (string)form["hourCellStart"];
                HourCellEnd         = (string)form["hourCellEnd"];
                HourCellSize        = (string)form["hourCellSize"];
                IndividualHourStart = (string)form["indHourStart"];
                IndividualHourEnd   = (string)form["indHourEnd"];
                IndividualHourStep  = (string)form["indHourStep"];
                try
                {
                    switch ((string)form["hoursMode"])
                    {
                    case "cells":
                        tr = tr.GetHourlyTimeseries(Int32.Parse(HourCellStart), Int32.Parse(HourCellEnd), Int32.Parse(HourCellSize), true);
                        break;

                    case "hours":
                        tr = tr.GetHourlyTimeseries(Int32.Parse(IndividualHourStart), Int32.Parse(IndividualHourEnd), Int32.Parse(IndividualHourStep), true);
                        break;
                    }
                }
                catch (Exception exc)
                {
                    if (!String.IsNullOrEmpty(intervalErrors))
                    {
                        intervalErrors += "\n";
                    }
                    intervalErrors += "Hours axis specification has errors: " + exc.Message;
                }
            }
            else // From get
            {
                string v = form["v"];
                if (!String.IsNullOrEmpty(v))
                {
                    var names = Uri.UnescapeDataString(v).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var n in names)
                    {
                        if (config.EnvironmentalVariables.Any(vd => vd.Name == n))
                        {
                            variables.Add(n,
                                          config.DataSources.Where(d => d.ProvidedVariables.Contains(n)).Select(d => d.Name).ToList());
                        }
                    }
                }

                string p = form["p"];
                if (!String.IsNullOrEmpty(p))
                {
                    var latLons = Uri.UnescapeDataString(p).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < latLons.Length - 1; i += 2)
                    {
                        double lat, lon;
                        if (Double.TryParse(latLons[i], out lat) && Double.TryParse(latLons[i + 1], out lon))
                        {
                            points.Add(new GeoPoint(lat, lon));
                        }
                    }
                }

                string g = form["g"];
                if (!String.IsNullOrEmpty(g))
                {
                    var gp = Uri.UnescapeDataString(g).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < gp.Length; i += 6)
                    {
                        double latmin, latmax, lonmin, lonmax;
                        int    latcount, loncount;
                        if (Double.TryParse(gp[0], out latmin) && Double.TryParse(gp[1], out latmax) && Int32.TryParse(gp[2], out latcount) &&
                            Double.TryParse(gp[3], out lonmin) && Double.TryParse(gp[4], out lonmax) && Int32.TryParse(gp[5], out loncount) &&
                            latmin < latmax && lonmin < lonmax && latcount > 1 && loncount > 1)
                        {
                            grids.Add(new GeoGrid(latmin, latmax, latcount, lonmin, lonmax, loncount));
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void ExecuteEvents(TimelineHandler handler)
        {
            try
            {
                foreach (TimelineEvent timelineEvent in handler.TimeLineEvents)
                {
                    WorkingHours.Is(handler);

                    if (timelineEvent.DelayBefore > 0)
                    {
                        Thread.Sleep(timelineEvent.DelayBefore);
                    }

                    RequestConfiguration config;

                    IWebElement element;
                    Actions     actions;

                    switch (timelineEvent.Command)
                    {
                    case "random":
                        while (true)
                        {
                            if (Driver.CurrentWindowHandle == null)
                            {
                                throw new Exception("Browser window handle not available");
                            }

                            config = RequestConfiguration.Load(timelineEvent.CommandArgs[new Random().Next(0, timelineEvent.CommandArgs.Count)]);
                            if (config.Uri.IsWellFormedOriginalString())
                            {
                                MakeRequest(config);
                                Report(handler.HandlerType.ToString(), timelineEvent.Command, config.ToString(), timelineEvent.TrackableId);
                            }
                            Thread.Sleep(timelineEvent.DelayAfter);
                        }

                    case "random-extended":
                        while (true)
                        {
                            if (Driver.CurrentWindowHandle == null)
                            {
                                throw new Exception("Browser window handle not available");
                            }

                            var extendedConfig = ExtendedConfiguration.Load(timelineEvent.CommandArgs[0]);

                            config = RequestConfiguration.Load(extendedConfig.Sites[new Random().Next(0, extendedConfig.Sites.Length)]);
                            if (config.Uri.IsWellFormedOriginalString())
                            {
                                MakeRequest(config);
                                Report(handler.HandlerType.ToString(), timelineEvent.Command, config.ToString(), timelineEvent.TrackableId);
                            }

                            var random = new Random();

                            //now some percentage of the time should stay on this site
                            if (random.Next(100) < extendedConfig.Stickiness)
                            {
                                var loops = random.Next(extendedConfig.DepthMin, extendedConfig.DepthMax);
                                for (var loopNumber = 0; loopNumber < loops; loopNumber++)
                                {
                                    try
                                    {
                                        //get all links
                                        var links = Driver.FindElements(By.TagName("a"));

                                        var linkSelected = random.Next(links.Count);
                                        var href         = links[linkSelected].GetAttribute("href");
                                        while (!href.StartsWith("http"))
                                        {
                                            foreach (var l in links)
                                            {
                                                href = l.GetAttribute("href");
                                            }
                                        }

                                        config.Method = "GET";
                                        config.Uri    = new Uri(href);

                                        MakeRequest(config);
                                        Report(handler.HandlerType.ToString(), timelineEvent.Command, config.ToString(),
                                               timelineEvent.TrackableId);
                                    }
                                    catch (Exception e)
                                    {
                                        _log.Error(e);
                                    }
                                }
                            }

                            Thread.Sleep(timelineEvent.DelayAfter);
                        }

                    case "browse":
                        config = RequestConfiguration.Load(timelineEvent.CommandArgs[0]);
                        if (config.Uri.IsWellFormedOriginalString())
                        {
                            MakeRequest(config);
                            Report(handler.HandlerType.ToString(), timelineEvent.Command, config.ToString(), timelineEvent.TrackableId);
                        }
                        break;

                    case "download":
                        if (timelineEvent.CommandArgs.Count > 0)
                        {
                            element = Driver.FindElement(By.XPath(timelineEvent.CommandArgs[0].ToString()));
                            element.Click();
                            Report(handler.HandlerType.ToString(), timelineEvent.Command, string.Join(",", timelineEvent.CommandArgs), timelineEvent.TrackableId);
                            Thread.Sleep(1000);
                        }
                        break;

                    case "type":
                        element = Driver.FindElement(By.Name(timelineEvent.CommandArgs[0].ToString()));
                        actions = new Actions(Driver);
                        actions.SendKeys(element, timelineEvent.CommandArgs[1].ToString()).Build().Perform();
                        break;

                    case "typebyid":
                        element = Driver.FindElement(By.Id(timelineEvent.CommandArgs[0].ToString()));
                        actions = new Actions(Driver);
                        actions.SendKeys(element, timelineEvent.CommandArgs[1].ToString()).Build().Perform();
                        break;

                    case "click":
                        element = Driver.FindElement(By.Name(timelineEvent.CommandArgs[0].ToString()));
                        actions = new Actions(Driver);
                        actions.MoveToElement(element).Click().Perform();
                        break;

                    case "clickbyid":
                        element = Driver.FindElement(By.Id(timelineEvent.CommandArgs[0].ToString()));
                        actions = new Actions(Driver);
                        actions.MoveToElement(element).Click().Perform();
                        break;
                    }

                    if (timelineEvent.DelayAfter > 0)
                    {
                        Thread.Sleep(timelineEvent.DelayAfter);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }