예제 #1
0
 public Output FindOutputById(string id)
 {
     if (Outputs == null)
     {
         return(null);
     }
     return(Outputs.FirstOrDefault((o) => o.OutputId == id));
 }
예제 #2
0
 public Output FindOutput(string displayName)
 {
     if (Outputs == null)
     {
         return(null);
     }
     return(Outputs.FirstOrDefault((o) => o.DisplayName == displayName));
 }
        void ProcessCreateTableStatement(TSQLUnknownStatement complexStatement)
        {
            var recordset = new DataTable();

            recordset.Columns.Add("records_affected", typeof(int));
            recordset.Rows.Add(AdvancedRecordset.ExecuteNonQuery(AdvancedRecordset.ReturnSql(complexStatement.Tokens)));
            var outputName = Outputs.FirstOrDefault(e => e.MappedFrom == "records_affected").MappedTo;

            AdvancedRecordset.ApplyScalarResultToEnvironment(outputName, int.Parse(recordset.Rows[0].ItemArray[0].ToString()));
        }
예제 #4
0
        internal void UpdateSubscriptions(Models.Settings.Device.Subscription theUpdatedSubscriptions)
        {
            bool SubChangesMade = false;

            BBSubscription Subscription = null;

            bool CreateNew = string.Equals(theUpdatedSubscriptions.SubscriptionGuid, "new", System.StringComparison.OrdinalIgnoreCase);

            BBOutput OutputSearch = null;

            OutputSearch = Outputs.FirstOrDefault(o => o.Name == theUpdatedSubscriptions.OutputId);

            if (OutputSearch != null && !CreateNew)
            {
                Subscription = OutputSearch.Subscriptions.FirstOrDefault(s => s.Guid == theUpdatedSubscriptions.SubscriptionGuid);
            }

            if (CreateNew && OutputSearch != null)
            {
                OutputSearch.Add(theUpdatedSubscriptions.SubscriptionId, new BBSubscriptionProperties
                {
                    HighSubject = theUpdatedSubscriptions.HighKey,
                    HighValue   = theUpdatedSubscriptions.HighValue,
                    LowSubject  = theUpdatedSubscriptions.LowKey,
                    LowValue    = theUpdatedSubscriptions.LowValue
                });

                SubChangesMade = true;
            }
            else
            {
                if (Subscription != null)
                {
                    if (Subscription.Id != theUpdatedSubscriptions.SubscriptionId)
                    {
                        SubChangesMade  = true;
                        Subscription.Id = theUpdatedSubscriptions.SubscriptionId;
                    }


                    Subscription.Update(new BBSubscriptionProperties
                    {
                        HighSubject = theUpdatedSubscriptions.HighKey,
                        HighValue   = theUpdatedSubscriptions.HighValue,
                        LowSubject  = theUpdatedSubscriptions.LowKey,
                        LowValue    = theUpdatedSubscriptions.LowValue
                    });
                }
            }

            if (SubChangesMade)
            {
                ConstructSubscriptions();
            }
        }
예제 #5
0
        void ProcessUpdateStatement(TSQLUnknownStatement complexStatement, int update, ref bool started)
        {
            var tokens = complexStatement.Tokens;
            var outputRecordsetName = "";

            for (int i = 0; i < complexStatement.Tokens.Count; i++)
            {
                if (i == 1 && tokens[i].Type.ToString() == "Identifier" && (tokens[i - 1].Text.ToUpper() == "UPDATE"))
                {
                    outputRecordsetName = tokens[i].Text;
                }
                if (tokens[i].Type.ToString() == "Keyword" && (tokens[i].Text.ToUpper() == "INSERT"))
                {
                    outputRecordsetName = tokens[i + 2].Text;
                }
                if (tokens[i].Type.ToString() == "Identifier" && (tokens[i].Text.ToUpper() == "REPLACE"))
                {
                    outputRecordsetName = tokens[i + 2].Text;
                }
                if (tokens[i].Type.ToString() == "Keyword" && (tokens[i].Text.ToUpper() == "DELETE"))
                {
                    outputRecordsetName = tokens[i + 2].Text;
                }
            }

            var sqlQuery = AdvancedRecordset.UpdateSqlWithHashCodes(complexStatement);

            var recordset = new DataTable();

            recordset.Columns.Add("records_affected", typeof(int));
            recordset.Rows.Add(AdvancedRecordset.ExecuteNonQuery(sqlQuery));
            object sumObject;

            sumObject         = recordset.Compute("Sum(records_affected)", "");
            _recordsAffected += Convert.ToInt16(sumObject.ToString());
            var mapping = Outputs.FirstOrDefault(e => e.MappedFrom == "records_affected");


            if (mapping != null)
            {
                AdvancedRecordset.ApplyScalarResultToEnvironment(mapping.MappedTo, _recordsAffected);
            }
            var results = AdvancedRecordset.ExecuteQuery("SELECT * FROM " + AdvancedRecordset.HashedRecSets.FirstOrDefault(x => x.recSet == outputRecordsetName).hashCode);

            foreach (DataTable dt in results.Tables)
            {
                AdvancedRecordset.ApplyResultToEnvironment(outputRecordsetName, Outputs, dt.Rows.Cast <DataRow>().ToList(), true, update, ref started);
            }
        }
예제 #6
0
        public void UpdateBattery(int?batteryLevel)
        {
            Output output = Outputs.FirstOrDefault(x => x.Name == "Battery");

            if (output == null)
            {
                output = new Output {
                    Name = "Battery"
                };
                output.SlotIndex = Int32.MaxValue;
                AddOutput(output);
                UpdateMeInEditor();
            }

            output.Value = batteryLevel.ToString();
            UpdateMeInDb();
        }
예제 #7
0
        public Node GetNodeFromIdentifier(uint nodeIdentifier)
        {
            // Tries to find the first relation where the input node has the given identifier or return default.
            OrganismInputNode organismInputNode = Inputs.FirstOrDefault(n => n.InputNode.NodeIdentifier == nodeIdentifier);

            // if the organism input node is not default return the input node.
            if (organismInputNode != default)
            {
                return(organismInputNode.InputNode);
            }

            // Tries to find the first relation where the output node has the given identifier, else return default.
            OrganismOutputNode organismOutputNode = Outputs.FirstOrDefault(n => n.OutputNode.NodeIdentifier == nodeIdentifier);

            // if the organism output node is not default return the output node.
            if (organismOutputNode != default)
            {
                return(organismOutputNode.OutputNode);
            }

            // Tries to find a hidden node with the given identifier; otherwise, create and return a new hidden node.
            return(HiddenNodes.FirstOrDefault(node => node.NodeIdentifier == nodeIdentifier) ?? CreateAndAddNode(nodeIdentifier));
        }
예제 #8
0
        public Output GetOutput(string name)
        {
            Output output = Outputs.FirstOrDefault(x => x.Name == name);

            return(output);
        }
예제 #9
0
        public void RemoveOutput(string name)
        {
            Output output = Outputs.FirstOrDefault(x => x.Name == name);

            RemoveOutput(output);
        }
예제 #10
0
        /// <summary>
        /// Rebuild structure so we get layer information to make sure there are not circular dependencies.
        /// </summary>
        private void RebuildStructure()
        {
            // Clear the temporary node storage.
            _tempNodes.Clear();

            // Load all nodes for each connection gene.
            ConnectionGenes.ForEach(LoadNodes);

            // Find all the node in the connection genes.
            _tempNodes.AddRange(ConnectionGenes.SelectMany(p => new[] { p.InNode, p.OutNode }).Distinct());

            // Add all input nodes
            _tempNodes.AddRange(Inputs.Select(p => p.InputNode));

            // Add all output nodes.
            _tempNodes.AddRange(Outputs.Select(p => p.OutputNode));

            // For each node of type OutputNode set the layer to 0, otherwise set the layer to the minimum value and force to true.
            foreach (Node node in _tempNodes)
            {
                if (node is OutputNode)
                {
                    SetLayer(node, 0);
                }
                else
                {
                    SetLayer(node, uint.MinValue, true);
                }
            }

            // For each node of type InputNode set the layer to minimum value and force to true.
            foreach (InputNode node in _tempNodes.OfType <InputNode>())
            {
                SetLayer(node, uint.MaxValue, true);
            }

            void SetLayer(Node node, uint layer, bool force = false)
            {
                // Set the layer depending on force and if the current layer is higher than the layer given.
                node.Layer = force ? layer : (layer > node.Layer ? layer : node.Layer);

                // If force is true, return early.
                if (force)
                {
                    return;
                }

                // For each connection gene where the out node identifier is the same as the given node identifier
                // set the layer to the node's layer plus one.
                foreach (ConnectionGene connectionGene in ConnectionGenes)
                {
                    if (connectionGene.OutNodeIdentifier.Equals(node.NodeIdentifier))
                    {
                        SetLayer(connectionGene.InNode, node.Layer + 1);
                    }
                }
            }

            void LoadNodes(ConnectionGene connectionGene)
            {
                // Get or create the In and Out nodes based on the given node identifiers.
                connectionGene.InNode  = GetOrCreateNodeForNodeId(connectionGene.InNodeIdentifier);
                connectionGene.OutNode = GetOrCreateNodeForNodeId(connectionGene.OutNodeIdentifier);
            }

            Node GetOrCreateNodeForNodeId(uint nodeIdentifier)
            {
                // Tries to get a node for the given id, if not found returns a default.
                Node node = GetNodeForId(nodeIdentifier);

                // If the node is not equal to default return the given node.
                if (node != default)
                {
                    return(node);
                }

                // Tries to find the node in the hidden nodes list, if not found returns a default.
                node = _hiddenNodes.FirstOrDefault(n => n.NodeIdentifier == nodeIdentifier);

                // If the node is not equal to default return the given node.
                if (node != default)
                {
                    return(node);
                }

                // If no node was found then create a hidden node.
                node = new HiddenNode(nodeIdentifier);

                // Add it to the hidden nodes list.
                _hiddenNodes.Add((HiddenNode)node);

                // Return the hidden node.
                return(node);
            }

            Node GetNodeForId(uint nodeIdentifier)
            {
                // Tries to find the first relation where the input node has the given identifier or return default.
                OrganismInputNode organismInputNode = Inputs.FirstOrDefault(n => n.InputNode.NodeIdentifier == nodeIdentifier);

                // if the organism input node is not default return the input node.
                if (organismInputNode != default)
                {
                    return(organismInputNode.InputNode);
                }

                // Tries to find the first relation where the output node has the given identifier, else return default.
                return(Outputs.FirstOrDefault(n => n.OutputNode.NodeIdentifier == nodeIdentifier)?.OutputNode);
            }
        }
예제 #11
0
 public DataOutput GetDataOutputByName(string name)
 => Outputs.FirstOrDefault(o => o.Name == name);