Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/03/16 17:13:50 (8 years ago)
Author:
jlodewyc
Message:

#2582 Parameter changing busy, save file, download file and email on pass reset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/ProgressHub.cs

    r13739 r13827  
    66using System.Linq;
    77using System.Threading.Tasks;
     8using HeuristicLab.Data;
     9using System.Reflection;
    810
    911namespace HeuristicLab.Clients.Hive.WebJobManager
     
    2628                userId = Guid.Empty;
    2729            }
    28             else {
     30            else
     31            {
    2932                userId = Guid.Parse(uid);
    3033                fileopener = weblog.getFileOpener(userId);
     
    5154            if (name != null)
    5255                fileopener.Job.Job.Name = name;
    53             if(resource != null && resource != "")
     56            if (resource != null && resource != "")
    5457            {
    5558                fileopener.Job.Job.ResourceNames += "/" + resource;
     
    7073            {//check if upper job
    7174                current.ItemTask.ComputeInParallel = !current.ItemTask.ComputeInParallel;
    72                
    73             }
    74             else {
     75
     76            }
     77            else
     78            {
    7579                for (var i = 0; i < arr.Length; i++)
    7680                {
     
    8993
    9094                    }
    91                     else {//not deep enough, select right path
     95                    else
     96                    {//not deep enough, select right path
    9297                        if (current.ItemTask.Item is BatchRun)
    9398                            current = current.ChildHiveTasks[arr[i][1]]; // select right batch
     
    115120
    116121            }
    117             else {
     122            else
     123            {
    118124                for (var i = 0; i < arr.Length; i++)
    119125                {//loop for depth
     
    132138
    133139                    }
    134                     else {//not deep enough, choose right path
     140                    else
     141                    {//not deep enough, choose right path
    135142                        if (current.ItemTask.Item is BatchRun)
    136143                            current = current.ChildHiveTasks[arr[i][1]]; // select right batch
     
    177184
    178185        }
     186        public void paraEdit(int[][] arr, string problem, string name, string type, string value)
     187        {
     188
     189
     190            loader();
     191            HiveTask current = fileopener.Job.HiveTasks.ToList()[0];
     192            if (arr.Length == 0)
     193            {//check if upper job
     194                if (current.ItemTask.Item is Algorithm)
     195                {
     196                    searchEditPara(current, problem, name, type, value);
     197                }
     198            }
     199            else
     200            {
     201                for (var i = 0; i < arr.Length; i++)
     202                {//loop for depth
     203                    if (i == arr.Length - 1)
     204                    {//Right depth reached, change priority for current
     205                        if (current.ItemTask.Item is BatchRun)
     206                        {
     207                            current = current.ChildHiveTasks[arr[i][1]];
     208                        }
     209                        else if (current.ItemTask.Item is Experiment)
     210                        {
     211                            current = current.ChildHiveTasks[arr[i][0]];
     212                        }
     213                        if (current.ItemTask.Item is Algorithm)
     214                        {
     215                            searchEditPara(current, problem, name, type, value);
     216                        }
     217                    }
     218                    else
     219                    {//not deep enough, choose right path
     220                        if (current.ItemTask.Item is BatchRun)
     221                            current = current.ChildHiveTasks[arr[i][1]]; // select right batch
     222                        else if (current.ItemTask.Item is Experiment)
     223                            current = current.ChildHiveTasks[arr[i][0]]; // select right sub task from experiment
     224                    }
     225                }
     226            }
     227        }
     228        /// <summary>
     229        /// Generic parameter setter
     230        /// </summary>
     231        /// <param name="curr">Current task to edit </param>
     232        /// <param name="problem">Problem parameter or normal parameter</param>
     233        /// <param name="name">Property name</param>
     234        /// <param name="type">Datatype</param>
     235        /// <param name="value">New value</param>
     236        private void searchEditPara(HiveTask curr, string problem, string name, string type, string value)
     237        {
     238            var prob = problem == "True" ? true : false;
     239
     240            var dattype = Type.GetType(type);
     241            if (dattype == null)
     242            {//Use assemblies to find correct datatype
     243                foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
     244                {
     245                    dattype = a.GetType(type);
     246                    if (dattype != null)
     247                        break;
     248                }
     249            }
     250            //find parse method
     251            var parse = dattype.GetMethod("Parse", new[] { typeof(string) });
     252
     253            if (parse != null)
     254            {
     255                //Parses string to correct datatype
     256                var val = parse.Invoke(null, new object[] { value });
     257
     258                //BUGGERS
     259                if (name == "ReevaluateElites")
     260                    name = "ReevaluteElites";
     261                if (name == "DominateOnEqualQualities" || name == "PlusSelection" || name == "ReevaluteElites")
     262                    val = ((BoolValue)val).Value;
     263               
     264               // if (name == "ReduceToPopulationSize")
     265                    //name += "Parameter";
     266
     267                try
     268                {
     269                    Algorithm alg = (Algorithm)curr.ItemTask.Item;
     270                    if (prob)
     271                        alg.Problem.GetType().GetProperty(name).SetValue(alg, val);
     272                    else
     273                        alg.GetType().GetProperty(name).SetValue(alg, val);
     274                }
     275                catch (NullReferenceException e)
     276                {
     277                    Console.WriteLine("NullRefException: " + name + " - " + type);
     278                }
     279                catch(TargetException e)
     280                {
     281                    Console.WriteLine("TargetException: " + name + " - " + type);
     282                }
     283            }
     284
     285        }
    179286
    180287    }
Note: See TracChangeset for help on using the changeset viewer.