Пример #1
0
        public static NamedConnection GetConnection(this IDictionary <ConnectionName, NamedConnection> connections, ConnectionName connectionName, IConnectedElement owner)
        {
            if (connections.TryGetValue(connectionName, out var namedConnection))
            {
                return(namedConnection);
            }

            namedConnection             = new NamedConnection(connectionName, owner);
            connections[connectionName] = namedConnection;
            return(namedConnection);
        }
Пример #2
0
        public void ApplyConnection(string id, NamedConnection connection)
        {
            IList <NamedConnection> existing;

            if (!connections.TryGetValue(id, out existing))
            {
                connections.Add(id, new List <NamedConnection>
                {
                    connection
                });
                return;
            }

            foreach (var c in existing)
            {
                connection.ConnectTo(c);
            }
            existing.Add(connection);
        }
Пример #3
0
        protected Task WaitFor(NamedConnection connection, ushort messageId, CommandMessage mustBeType)
        {
            ManualResetEvent available = new ManualResetEvent(false);

            Action <MqttCommand> ready = (cmd) =>
            {
                if (cmd.CommandMessage != mustBeType)
                {
                    throw new ProtocolException(
                              string.Format("ERROR: Expected {0} for message ID {1} but received {2}",
                                            mustBeType, messageId, cmd.CommandMessage));
                }

                available.Set();
            };

            return(Task.Factory.StartNew(() =>
            {
                connection.Desire(messageId, ready);
                available.WaitOne();
            }, TaskCreationOptions.LongRunning));
        }
Пример #4
0
        private PartialProcessOperation PrepareOutputOperation(Process process, NamedConnection output)
        {
            var partial = new PartialProcessOperation(process);

            partial.Register(new FilterOutputOperation(output.ShouldRun)
            {
                EntityName = _entity.Name
            });

            if (output.Connection.Type == ProviderType.Internal)
            {
                partial.Register(_collectors[output.Name]);
            }
            else
            {
                if (Process.IsFirstRun || !_entity.DetectChanges)
                {
                    partial.Register(new EntityAddTflFields(process, _entity));
                    partial.Register(output.Connection.Insert(process, _entity));
                }
                else
                {
                    partial.Register(new EntityJoinAction(process, _entity).Right(output.Connection.ExtractCorrespondingKeysFromOutput(_entity)));
                    var branch = new BranchingOperation()
                                 .Add(new PartialProcessOperation(process)
                                      .Register(new EntityActionFilter(process, _entity, EntityAction.Insert))
                                      .Register(output.Connection.Insert(process, _entity)))
                                 .Add(new PartialProcessOperation(process)
                                      .Register(new EntityActionFilter(process, _entity, EntityAction.Update))
                                      .Register(output.Connection.Update(_entity)));

                    partial.Register(branch);
                }
            }
            return(partial);
        }
Пример #5
0
 public static bool IsConnectedTo(this NamedConnection connection, NamedConnection other)
 {
     return(connection == other || connection.ConnectedTo.Contains(other));
 }
Пример #6
0
        protected override void Initialize()
        {
            Register(new EntityKeysPartial(_process, _entity));

            if (_entity.Input.Count == 1)
            {
                Register(_entity.Input.First().Connection.Extract(_process, _entity, _process.IsFirstRun));
            }
            else
            {
                var union = new ParallelUnionAllOperation();
                foreach (var input in _entity.Input)
                {
                    union.Add(input.Connection.Extract(_process, _entity, Process.IsFirstRun));
                }
                Register(union);
            }

            if (!_entity.Sampled && _entity.Sample > 0m && _entity.Sample < 100m)
            {
                Register(new SampleOperation(_entity.Sample)
                {
                    EntityName = _entity.Name
                });
            }

            Register(new ApplyDefaults(true, new Fields(_entity.Fields, _entity.CalculatedFields))
            {
                EntityName = _entity.Name
            });

            foreach (var transform in _entity.OperationsBeforeAggregation)
            {
                Register(transform);
            }

            if (_entity.HasSort())
            {
                Register(new SortOperation(_entity)
                {
                    EntityName = _entity.Name
                });
            }

            if (_entity.Group)
            {
                Register(new EntityAggregation(_entity));
            }

            foreach (var transform in _entity.OperationsAfterAggregation)
            {
                Register(transform);
            }

            Register(new TruncateOperation(_entity.Name, _entity.Fields, _entity.CalculatedFields));

            var standardOutput = new NamedConnection {
                Connection = _process.OutputConnection, Name = STANDARD_OUTPUT
            };

            if (_entity.Output.Count > 0)
            {
                var branch = new BranchingOperation()
                             .Add(PrepareOutputOperation(_process, standardOutput));
                foreach (var output in _entity.Output)
                {
                    _collectors[output.Name] = new CollectorOperation();
                    branch.Add(PrepareOutputOperation(_process, output));
                }
                Register(branch);
            }
            else
            {
                Register(PrepareOutputOperation(_process, standardOutput));
            }
        }
Пример #7
0
 public PingReceived(MqttCommand cmd, NamedConnection connection)
 {
     _command    = cmd;
     _connection = connection;
 }
Пример #8
0
 public UnsubscribeReceived(MqttCommand cmd, NamedConnection connection)
 {
     _command    = cmd;
     _connection = connection;
 }
Пример #9
0
 public PublishReceive(MqttCommand cmd, NamedConnection connection)
 {
     _command    = cmd;
     _connection = connection;
 }
Пример #10
0
        public void ReadElements(CircuitDiagramDocument document,
                                 XElement elements,
                                 ReaderContext context)
        {
            var components = from el in elements.Descendants()
                             where el.Name == Ns.Document + "c"
                             select el;

            foreach (var componentElement in components)
            {
                var typeAttr = componentElement.Attribute("tp");
                if (typeAttr == null)
                {
                    context.Log(ReaderErrorCodes.MissingRequiredAttribute, componentElement, "tp");
                    continue;
                }

                var componentType = context.GetComponentType(ParseType(typeAttr.Value));
                if (componentType == null)
                {
                    context.Log(ReaderErrorCodes.UnknownComponentType, typeAttr, typeAttr.Value);
                    continue;
                }

                Component component;

                if (componentElement.Attribute("x") != null)
                {
                    component = new PositionalComponent(componentType, new LayoutInformation());

                    // Layout
                    ReadLayout((PositionalComponent)component, componentElement, context);
                }
                else
                {
                    component = new Component(componentType);
                }

                // Properties

                var propertiesElement = componentElement.Elements(Ns.Document + "prs").SingleOrDefault();
                var properties        = propertiesElement != null
                    ? from el in propertiesElement.Elements()
                                        where el.Name == Ns.Document + "p"
                                        select el
                    : new XElement[0];

                foreach (var propertyElement in properties)
                {
                    var keyAttr = propertyElement.Attribute("k");
                    if (keyAttr == null)
                    {
                        context.Log(ReaderErrorCodes.MissingRequiredAttribute, propertyElement, "k");
                        continue;
                    }

                    var valueAttr = propertyElement.Attribute("v");
                    if (valueAttr == null)
                    {
                        context.Log(ReaderErrorCodes.MissingRequiredAttribute, propertyElement, "v");
                        continue;
                    }

                    component.Properties[keyAttr.Value] = PropertyValue.Dynamic(valueAttr.Value);
                }

                // Connections

                var connectionsElement = componentElement.Elements(Ns.Document + "cns").SingleOrDefault();
                var connections        = connectionsElement != null
                    ? from el in connectionsElement.Elements()
                                         where el.Name == Ns.Document + "cn"
                                         select el
                    : new XElement[0];

                foreach (var connectionElement in connections)
                {
                    var idAttr = connectionElement.Attribute("id");
                    if (idAttr == null)
                    {
                        context.Log(ReaderErrorCodes.MissingRequiredAttribute, connectionElement, "id");
                        continue;
                    }

                    var pointAttr = connectionElement.Attribute("pt");
                    if (pointAttr == null)
                    {
                        context.Log(ReaderErrorCodes.MissingRequiredAttribute, connectionElement, "pt");
                        continue;
                    }

                    var namedConnection = component.Connections.FirstOrDefault(x => x.Value.Name.Value == pointAttr.Value).Value;
                    if (namedConnection == null)
                    {
                        // Connection not defined on component (loading without a component description)
                        var connectionName = new ConnectionName(pointAttr.Value);
                        namedConnection = new NamedConnection(connectionName, component, idAttr.Value);
                        component.Connections[connectionName] = namedConnection;
                    }
                    context.ApplyConnection(idAttr.Value, namedConnection);
                }

                document.Elements.Add(component);
            }

            var wires = from el in elements.Elements()
                        where el.Name == Ns.Document + "w"
                        select el;

            foreach (var wireElement in wires)
            {
                var wire = new Wire(new LayoutInformation());
                ReadLayout(wire, wireElement, context);

                document.Elements.Add(wire);
            }
        }