public void OnCellDefinitionChanged(CellDefinition newCellDefinition, SolutionHead newDeployment)
        {
            var oldCellDefinition     = _cellDefinition;
            var newAssemblies         = newCellDefinition.Assemblies;
            var newEntryPointTypeName = newCellDefinition.EntryPointTypeName;

            _cellDefinition = newCellDefinition;
            _deployment     = newDeployment;

            var entryPoint = _entryPoint;

            if (entryPoint == null)
            {
                return;
            }

            if (!oldCellDefinition.Assemblies.Equals(newAssemblies) ||
                !StringComparer.Ordinal.Equals(oldCellDefinition.EntryPointTypeName, newEntryPointTypeName))
            {
                // cancel will stop the cell and unload the AppDomain, but then automatically
                // start again with the new assemblies and entry point
                entryPoint.Cancel();
                return;
            }

            entryPoint.AppplyChangedSettings(newCellDefinition.SettingsXml);
        }
        /// <remarks>Never run a cell process entry point more than once per AppDomain.</remarks>
        public void Run(CellDefinition cellDefinition, IDeploymentReader deploymentReader, ApplicationEnvironment environment)
        {
            // Load Assemblies into AppDomain
            var assemblies = deploymentReader.GetAssembliesAndSymbols(cellDefinition.Assemblies).ToList();
            var loader = new AssemblyLoader();
            loader.LoadAssembliesIntoAppDomain(assemblies, environment);

            // Create the EntryPoint
            var entryPointTypeName = cellDefinition.EntryPointTypeName;
            if (string.IsNullOrEmpty(entryPointTypeName))
            {
                entryPointTypeName = "Lokad.Cloud.Services.AppEntryPoint.EntryPoint, Lokad.Cloud.Services.AppEntryPoint";
            }

            var entryPointType = Type.GetType(entryPointTypeName);
            if (entryPointType == null)
            {
                throw new InvalidOperationException("Type " + entryPointTypeName + " not found.");
            }

            _appEntryPoint = (IApplicationEntryPoint)Activator.CreateInstance(entryPointType);

            var settings = string.IsNullOrEmpty(cellDefinition.SettingsXml) ? new XElement("Settings") : XElement.Parse(cellDefinition.SettingsXml);

            // Run
            _appEntryPoint.Run(settings, deploymentReader, environment, _externalCancellationTokenSource.Token);
        }
Exemple #3
0
 protected override void ApplyProperties(CellDefinition cd, CellDescriptor d)
 {
     base.ApplyProperties(cd, d);
     cd.IsEnabledBindingSource    = this.isItemEnabledSource;
     cd.IsEnabledBindingParameter = "yes";
     cd.IsEnabledBindingPath      = d.BindingPath;
 }
Exemple #4
0
        public void AddCatchment()
        {
            GlobalDefinition    gd        = new GlobalDefinition();
            CatchmentDefinition catchment = new CatchmentDefinition {
                Id = "catchment-124"
            };

            const int numCells = 9;

            for (int cells = 0; cells < numCells; cells++)
            {
                CellDefinition cell = new CellDefinition {
                    Id = "cell-" + cells
                };
                catchment.Cells.Add(cell);
            }

            gd.AddCatchment(catchment);

            Assert.That(gd.Count, Is.EqualTo(1));

            List <CellDefinition> gdCells = gd.GetFlatCellList();

            Assert.AreEqual(gdCells.Count, numCells);
            foreach (CellDefinition cell in gdCells)
            {
                Assert.That(catchment.Cells, Contains.Item(cell));
            }
        }
        protected virtual void SetWorkPackage(WorkPackage work)
        {
            MyWork = work;

            // Create the models
            if (MyWork != null && MyWork.Cells.Length > 0)
            {
                Log.DebugFormat("Rank {0}: creating {1} model evaluators", WorldRank, MyWork.Cells.Length);
                Models = new ICatchmentCellModelRunner[MyWork.Cells.Length];
                for (int i = 0; i < MyWork.Cells.Length; i++)
                {
                    CellDefinition cellDefinition = MyWork.Cells[i];
                    Log.DebugFormat("Rank {0}: model instance {1}, catchment {2}, cell {3}", WorldRank, i, cellDefinition.CatchmentId, cellDefinition.Id);
                    var inputs = (TIME.Tools.Metaheuristics.Persistence.Gridded.ModelInputsDefinition)cellDefinition.ModelRunDefinition.Inputs;
                    if (inputs != null && !File.Exists(inputs.NetCdfDataFilename))
                    {
                        string msg = String.Format(
                            "Rank {0}: Input netcdf file '{1}' not found. Catchment: {2}, cell {3}",
                            WorldRank,
                            inputs.NetCdfDataFilename,
                            cellDefinition.CatchmentId,
                            cellDefinition.Id);
                        throw new ConfigurationException(msg);
                    }
#if USE_TOY_MODEL
                    Models[i] = new GriddedCatchmentToyModel(MyWork.Cells[i]);
#else
                    Log.DebugFormat("Rank {0}: creating cell evaluator", rank);
                    Models[i] = GridModelHelper.CreateCellEvaluator(cellDefinition);
                    Log.DebugFormat("Rank {0}: Evaluator created", rank);
#endif
                }
                Log.DebugFormat("Rank {0}: models created", WorldRank);
            }
        }
Exemple #6
0
        public static void AssertThatDefinitionsAreEquivalent(GlobalDefinition a, GlobalDefinition b)
        {
            // compare the catchments
            Assert.That(a.Count, Is.EqualTo(b.Count));
            for (int i = 0; i < b.Count; i++)
            {
                CatchmentDefinition aCatchment = a[i];
                CatchmentDefinition bCatchment = b[i];
                Assert.That(aCatchment.Id, Is.EqualTo(bCatchment.Id));
                Assert.That(aCatchment.Cells.Count, Is.EqualTo(bCatchment.Cells.Count));

                for (int j = 0; j < bCatchment.Cells.Count; j++)
                {
                    Assert.That(aCatchment.Cells[j].Id, Is.EqualTo(bCatchment.Cells[j].Id));
                }
            }

            // Compare the cells
            List <CellDefinition> aCells = a.GetFlatCellList();
            List <CellDefinition> bCells = b.GetFlatCellList();

            Assert.That(aCells.Count, Is.EqualTo(bCells.Count));
            for (int i = 0; i < bCells.Count; i++)
            {
                CellDefinition ac = aCells[i];
                CellDefinition bc = bCells[i];
                Assert.That(ac.Id, Is.EqualTo(bc.Id));
                AssertThatModelRunDefinitionsAreEqual(ac.ModelRunDefinition, bc.ModelRunDefinition);
            }
        }
Exemple #7
0
        /// <remarks>Never run a cell process entry point more than once per AppDomain.</remarks>
        public void Run(CellDefinition cellDefinition, IDeploymentReader deploymentReader, ApplicationEnvironment environment)
        {
            // Load Assemblies into AppDomain
            var assemblies = deploymentReader.GetAssembliesAndSymbols(cellDefinition.Assemblies).ToList();
            var loader     = new AssemblyLoader();

            loader.LoadAssembliesIntoAppDomain(assemblies, environment);

            // Create the EntryPoint
            var entryPointTypeName = cellDefinition.EntryPointTypeName;

            if (string.IsNullOrEmpty(entryPointTypeName))
            {
                entryPointTypeName = "Lokad.Cloud.Services.AppEntryPoint.EntryPoint, Lokad.Cloud.Services.AppEntryPoint";
            }

            var entryPointType = Type.GetType(entryPointTypeName);

            if (entryPointType == null)
            {
                throw new InvalidOperationException("Type " + entryPointTypeName + " not found.");
            }

            _appEntryPoint = (IApplicationEntryPoint)Activator.CreateInstance(entryPointType);

            var settings = string.IsNullOrEmpty(cellDefinition.SettingsXml) ? new XElement("Settings") : XElement.Parse(cellDefinition.SettingsXml);

            // Run
            _appEntryPoint.Run(settings, deploymentReader, environment, _externalCancellationTokenSource.Token);
        }
Exemple #8
0
        private IList <CellDefinition> CreatedArrangedCellDefinitions(IList <ReportParameter> parameters, out int numberOfRows, out int numberOfColumns)
        {
            int num  = 0;
            int num2 = 0;

            numberOfRows    = 1;
            numberOfColumns = 1;
            List <CellDefinition> list  = new List <CellDefinition>();
            List <CellInfo>       list2 = new List <CellInfo>();
            int num3 = 0;
            int num4 = 1;

            for (int i = 0; i < parameters.Count; i++)
            {
                ReportParameter parameter = parameters[i];
                bool            flag      = i < parameters.Count - 1 && !IsParameterHidden(parameters[i + 1]);
                numberOfColumns = Math.Max(num2 + 1, numberOfColumns);
                numberOfRows    = num + 1;
                bool flag2 = false;
                bool flag3 = false;
                if (!IsParameterHidden(parameters[i]))
                {
                    num3++;
                    flag2 = (num3 % 2 == 0);
                    if (flag2)
                    {
                        num4 = Math.Max(num2, num4);
                    }
                    flag3 = flag2;
                }
                else if (flag)
                {
                    flag3 = (num3 % 2 == 0);
                }
                list2.Add(new CellInfo
                {
                    RowIndex              = num,
                    ColumnIndex           = num2,
                    Parameter             = parameter,
                    IsSecondVisibleColumn = flag2
                });
                if (num2 == 7 || flag3)
                {
                    num++;
                    num2 = 0;
                }
                else
                {
                    num2++;
                }
            }
            foreach (CellInfo item2 in list2)
            {
                CellDefinition item = CreateCellDefinition(item2.Parameter, item2.RowIndex, item2.IsSecondVisibleColumn ? num4 : item2.ColumnIndex);
                list.Add(item);
            }
            return(list);
        }
        public static void DrawCell(this char[,] table, CellDefinition cellDefinition, IReadOnlyList <Interval> rowsBreaks, IReadOnlyList <Interval> columnsBreaks)
        {
            var columnInterval = columnsBreaks[cellDefinition.Column];
            var rowInterval    = rowsBreaks[cellDefinition.Row];

            var cellRender = new CellRender(cellDefinition);

            cellRender.Draw(table, rowInterval.Start, rowInterval.End, columnInterval.Start, columnInterval.End);
        }
        private CellDefinition CreateCellDefinition(ReportParameter parameters, int rowIndex, int columnIndex)
        {
            CellDefinition cellDefinition = new CellDefinition();

            cellDefinition.ParameterName = parameters.Name;
            cellDefinition.ColumnIndex   = columnIndex;
            cellDefinition.RowIndex      = rowIndex;
            return(cellDefinition);
        }
 private Cell(IHostContext hostContext, Action<IHostCommand> sendCommand, CellDefinition cellDefinition, SolutionHead deployment, string solutionName, CancellationToken cancellationToken)
 {
     _hostContext = hostContext;
     _sendCommand = sendCommand;
     _solutionName = solutionName;
     _cellName = cellDefinition.CellName;
     _cellDefinition = cellDefinition;
     _deployment = deployment;
     _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
 }
Exemple #12
0
 private Cell(IHostContext hostContext, Action <IHostCommand> sendCommand, CellDefinition cellDefinition, SolutionHead deployment, string solutionName, CancellationToken cancellationToken)
 {
     _hostContext             = hostContext;
     _sendCommand             = sendCommand;
     _solutionName            = solutionName;
     _cellName                = cellDefinition.CellName;
     _cellDefinition          = cellDefinition;
     _deployment              = deployment;
     _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
 }
Exemple #13
0
        private void addCell(string catId, CellDefinition cellDefinition)
        {
            if (!models.ContainsKey(catId))
            {
                models[catId] = new Dictionary <string, Tuple <CellDefinition, IPointTimeSeriesSimulation> >();
            }
            IPointTimeSeriesSimulation mr =
                SimulationXmlFilesRepository.BuildModelRunner(cellDefinition.ModelRunDefinition);

            models[catId][cellDefinition.Id] = Tuple.Create(cellDefinition, mr);
        }
Exemple #14
0
    public static IEnumerator MessageBox(CellDefinition definition, Cell cell, Player player)
    {
        var text   = definition.GetParameter("text", defaultValue: "");
        var title  = definition.GetParameter("title", defaultValue: "Message Box");
        var msgBox = Dialog.Spawn <MessageBox>();

        msgBox.titleControl.text = title;
        msgBox.textControl.text  = text;

        yield return(new WaitForObjectDestroyed(msgBox.gameObject));
    }
 public static Cell Run(
     IHostContext hostContext,
     Action<IHostCommand> sendCommand,
     CellDefinition cellDefinition,
     SolutionHead deployment,
     string solutionName,
     CancellationToken cancellationToken)
 {
     var process = new Cell(hostContext, sendCommand, cellDefinition, deployment, solutionName, cancellationToken);
     process.Run();
     return process;
 }
 protected override GameElement Factory(CellDefinition <char> part, VectorInt2 startState)
 {
     return(new GameElement()
     {
         Position = startState,
         PositionOld = startState,
         StartState = startState,
         Game = this,
         Type = part,
         Paint = PaintCell,
         ZIndex = part.MemberOf.All.IndexOf(part)
     });
 }
Exemple #17
0
        public static Cell Run(
            IHostContext hostContext,
            Action <IHostCommand> sendCommand,
            CellDefinition cellDefinition,
            SolutionHead deployment,
            string solutionName,
            CancellationToken cancellationToken)
        {
            var process = new Cell(hostContext, sendCommand, cellDefinition, deployment, solutionName, cancellationToken);

            process.Run();
            return(process);
        }
Exemple #18
0
    public void ApplyCellDefinition(Cell cell, CellDefinition definition)
    {
        //TODO after creating special asset fix this step
        if (cell.isCorner)
        {
            cell.transform.localScale = new Vector3(cellHeight, 1, cellHeight) / 10.0f;
        }
        else
        {
            cell.transform.localScale = new Vector3(cellHeight, 1, cellLength) / 10.0f;
        }

        definition.ApplyDefinition(cell);
    }
Exemple #19
0
    IEnumerator RunCell(CellDefinition cell, Animatable2[] objects)
    {
        var startTime = cell.startTime.RandomValue();

        yield return(new WaitForSeconds(startTime));

        // probably multiple methods
        foreach (var obj in objects)
        {
            var arg1     = cell.arg1.RandomValue();
            var arg2     = cell.arg2.RandomValue();
            var vec      = new Vector2(arg1, arg2);
            var endTime  = cell.endTime.RandomValue();
            var duration = endTime < float.Epsilon ? float.PositiveInfinity : endTime - startTime;

            switch (cell.type)
            {
            case CellType.VelocityEvent:
                obj.velocity = vec;
                break;

            case CellType.VelocityForce:
                StartCoroutine(AddForce(obj, vec, duration));
                break;

            case CellType.Rotation:
                obj.angularVelocity = cell.arg1.RandomValue();
                break;

            case CellType.Scale:
                break;

            case CellType.Centripetal:
                StartCoroutine(Centripetal(obj, arg1, duration));
                break;
            }
        }

        /*
         * var c = target.GetComponent<SpriteRenderer>().material.color;
         * c.a = Random.Range(0.3f, 0.8f);
         * target.GetComponent<SpriteRenderer>().material.color = c;
         *
         */
    }
Exemple #20
0
        protected BasicCellDefinition(CellDefinition father, HtmlNode htmlNode)
        {
            Border.Left   = htmlNode.BorderLeft(htmlNode.Edge(htmlNode.Border(father?.Border?.Left ?? Border.Left)));
            Border.Top    = htmlNode.BorderTop(htmlNode.Edge(htmlNode.Border(father?.Border?.Top ?? Border.Top)));
            Border.Right  = htmlNode.BorderRight(htmlNode.Edge(htmlNode.Border(father?.Border?.Right ?? Border.Right)));
            Border.Bottom = htmlNode.BorderBottom(htmlNode.Edge(htmlNode.Border(father?.Border?.Bottom ?? Border.Bottom)));

            Border.TopLeft     = htmlNode.BorderTopLeft(htmlNode.Corner(htmlNode.Border(father?.Border?.TopLeft ?? Border.TopLeft)));
            Border.TopRight    = htmlNode.BorderTopRight(htmlNode.Corner(htmlNode.Border(father?.Border?.TopRight ?? Border.TopRight)));
            Border.BottomRight = htmlNode.BorderBottomRight(htmlNode.Corner(htmlNode.Border(father?.Border?.BottomRight ?? Border.BottomRight)));
            Border.BottomLeft  = htmlNode.BorderBottomLeft(htmlNode.Corner(htmlNode.Border(father?.Border?.BottomLeft ?? Border.BottomLeft)));

            HorizontalAlign = htmlNode.HorizontalAlign(father?.HorizontalAlign ?? HorizontalAlign);
            VerticalAlign   = htmlNode.VerticalAlign(father?.VerticalAlign ?? VerticalAlign);

            Value    = htmlNode.InnerText;
            PadValue = htmlNode.PadValue(father?.PadValue ?? PadValue);
        }
Exemple #21
0
        public SokobanPixel this[CellDefinition <char> c]
        {
            get
            {
                if (c == c.MemberOf.Wall)
                {
                    return(new SokobanPixel(c.Underlying, Wall));
                }
                if (c == c.MemberOf.Void)
                {
                    return(new SokobanPixel(c.Underlying, Void));
                }
                if (c == c.MemberOf.Floor)
                {
                    return(new SokobanPixel(c.Underlying, Floor));
                }
                if (c == c.MemberOf.Goal)
                {
                    return(new SokobanPixel(c.Underlying, Goal));
                }

                if (c == c.MemberOf.Crate)
                {
                    return(new SokobanPixel(c.Underlying, Crate));
                }
                if (c == c.MemberOf.CrateGoal)
                {
                    return(new SokobanPixel(c.Underlying, CrateGoal));
                }

                if (c == c.MemberOf.Player)
                {
                    return(new SokobanPixel(c.Underlying, Player));
                }
                if (c == c.MemberOf.PlayerGoal)
                {
                    return(new SokobanPixel(c.Underlying, PlayerGoal));
                }

                return(new SokobanPixel(c.Underlying, Default));
            }
        }
        static public void RandomCatchments(this GlobalDefinition globalDef, int numCatchments, int minCellCount = 1, int maxCellCount = 50)
        {
            for (int i = 0; i < numCatchments; i++)
            {
                CatchmentDefinition catchment = new CatchmentDefinition {
                    Id = "catchment-" + Rand.Next()
                };

                int numCells = Rand.Next(minCellCount, maxCellCount + 1);
                for (int cells = 0; cells < numCells; cells++)
                {
                    CellDefinition cell = new CellDefinition {
                        Id = "cell-" + Rand.Next(), CatchmentId = catchment.Id
                    };
                    cell.ModelRunDefinition.PopulateWithTestData();
                    catchment.Cells.Add(cell);
                }

                globalDef.AddCatchment(catchment);
            }
        }
Exemple #23
0
    public static IEnumerator DrawCard(CellDefinition definition, Cell cell, Player player)
    {
#if UNITY_EDITOR
        Deck debugDeck = null;
        if (GameController.instance.decks.TryGetValue("debug", out debugDeck))
        {
            if (debugDeck.deckSize > 0)
            {
                return(debugDeck.DrawCard(player));
            }
        }
#endif

        var  deckName = definition.GetParameter("deck", defaultValue: "default");
        Deck deck     = null;
        if (!GameController.instance.decks.TryGetValue(deckName, out deck))
        {
            Debug.LogFormat("<color=red>[Failed]</color> Deck with name {0} doesn't exists!", deckName);
            return(null);
        }

        return(deck.DrawCard(player));
    }
        public static ICatchmentCellModelRunner CreateCellEvaluator(CellDefinition cellDefinition)
        {
            ModelRunner runner = SimulationXmlFilesRepository.BuildModelRunner(cellDefinition.ModelRunDefinition);

            return(new GridCellModel(runner, cellDefinition));
        }
        public void OnCellDefinitionChanged(CellDefinition newCellDefinition, SolutionHead newDeployment)
        {
            var oldCellDefinition = _cellDefinition;
            var newAssemblies = newCellDefinition.Assemblies;
            var newEntryPointTypeName = newCellDefinition.EntryPointTypeName;

            _cellDefinition = newCellDefinition;
            _deployment = newDeployment;

            var entryPoint = _entryPoint;
            if (entryPoint == null)
            {
                return;
            }

            if (!oldCellDefinition.Assemblies.Equals(newAssemblies)
                || !StringComparer.Ordinal.Equals(oldCellDefinition.EntryPointTypeName, newEntryPointTypeName))
            {
                // cancel will stop the cell and unload the AppDomain, but then automatically
                // start again with the new assemblies and entry point
                entryPoint.Cancel();
                return;
            }

            entryPoint.AppplyChangedSettings(newCellDefinition.SettingsXml);
        }
Exemple #26
0
 public TrCellDefinition(CellDefinition father, HtmlNode htmlNode)
     : base(father, htmlNode)
 {
 }
Exemple #27
0
 public bool containsCellDefinition(CellDefinition cellDef)
 {
     foreach (CellInstance cellInstance in cells)
     {
         if (cellInstance.CellInstanceDefinition.Name.Equals(cellDef.Name))
         {
             return true;
         }
     }
     return false;
 }
Exemple #28
0
 public static IEnumerator Announce(CellDefinition definition, Cell cell, Player player)
 {
     Debug.LogFormat(player, "{0} at {1}", player.name, definition.name);
     return(null);
 }
 public TdCellDefinition(CellDefinition father, HtmlNode htmlNode, int row, int column)
     : base(father, htmlNode)
 {
     Row    = row;
     Column = column;
 }
Exemple #30
0
 public GriddedCatchmentToyModel(CellDefinition cell)
 {
     Cell            = cell;
     timeSeriesCount = (int)(cell.ModelRunDefinition.EndDate - cell.ModelRunDefinition.StartDate).TotalDays;
     //timeSeriesCount = 100;
 }
Exemple #31
0
 public WorkPackage(int cellCount)
 {
     Catchments = new HashSet <CatchmentDefinition>();
     Cells      = new CellDefinition[cellCount];
 }
Exemple #32
0
 public CellRender(CellDefinition cellDefinition)
 {
     _cellDefinition = cellDefinition;
 }
 public GridCellModel(ModelRunner modelRunner, CellDefinition cell)
 {
     this.modelRunner = modelRunner;
     Cell             = cell;
 }
 protected override void ApplyProperties(CellDefinition cd, CellDescriptor d)
 {
     base.ApplyProperties(cd, d);
     cd.BackgroundBindingSource = this.backgroundSource;
     cd.BackgroundBindingPath   = d.BindingPath;
 }
Exemple #35
0
 public HtmlViewCellArrangeInfo(CellDefinition cell, GridViewColumn column)
     : base(column)
 {
     this.cell = cell;
 }