public OutputListenerViewModel(SettingViewModel owner, OutputListener model) { this.owner = owner; if (model.LocalEndPoint.Address.Equals(System.Net.IPAddress.Any)) { address = "IPv4 Any"; } else if (model.LocalEndPoint.Address.Equals(System.Net.IPAddress.IPv6Any)) { address = "IPv6 Any"; } else { address = model.LocalEndPoint.Address.ToString(); } port = model.LocalEndPoint.Port; globalRelay = (model.GlobalOutputAccepts & OutputStreamType.Relay) != 0; globalPlay = (model.GlobalOutputAccepts & OutputStreamType.Play) != 0; globalInterface = (model.GlobalOutputAccepts & OutputStreamType.Interface) != 0; globalAuthRequired = model.GlobalAuthorizationRequired; localRelay = (model.LocalOutputAccepts & OutputStreamType.Relay) != 0; localPlay = (model.LocalOutputAccepts & OutputStreamType.Play) != 0; localInterface = (model.LocalOutputAccepts & OutputStreamType.Interface) != 0; localAuthRequired = model.LocalAuthorizationRequired; authId = model.AuthenticationKey != null ? model.AuthenticationKey.Id : null; authPassword = model.AuthenticationKey != null ? model.AuthenticationKey.Password : null; isOpen = null; RegenerateAuthKey = new Command(DoRegenerateAuthKey); }
public void Compile(string fileNameBase, string fileNameDefinition, string fileNameOutput) { if (_OutputListener == null) { _OutputListener = new ConsoleOutputListener(); } XmlSerializer serializer = new XmlSerializer(typeof(ModelType)); StreamReader streamBase = new StreamReader(fileNameBase); StreamReader streamDef = new StreamReader(fileNameDefinition); using (streamBase) { var modelBM = (ModelType)serializer.Deserialize(streamBase); FMTreeNode root = MAXTreeNodeUtils.ToTree(modelBM, treeNodes); baseName = root.baseModelObject.name; using (streamDef) { ModelType modelCI = (ModelType)serializer.Deserialize(streamDef); var objectsCI = new Dictionary <string, ObjectType>(); foreach (ObjectType maxObj in modelCI.objects) { objectsCI[maxObj.id] = maxObj; } /** * Bind compiler instructions to the related base element nodes * and add new nodes. * * TODO: Child nodes may come before (new) parent is added. Figure out how to fix this. */ foreach (RelationshipType rel in modelCI.relationships) { /** * Check if destination is inside Profile Definition. * E.g. for internal relationships in Profile Definition or for new elements. * Then create empty PLACEHOLDER, cleaned up afterwards. */ if (!treeNodes.ContainsKey(rel.destId) && objectsCI.ContainsKey(rel.destId)) { FMTreeNode placeholder = new FMTreeNode(); placeholder.baseModelObject = objectsCI[rel.destId]; placeholder.isNew = true; placeholder.isPlaceholder = true; treeNodes[rel.destId] = placeholder; if (DEBUG) { _OutputListener.writeOutput("[DEBUG] Created PLACEHOLDER for {0}", objectsCI[rel.destId].name); } } /** * Check if both source and destination objects are there, if not ignore this relationship. */ if (treeNodes.ContainsKey(rel.destId) && objectsCI.ContainsKey(rel.sourceId)) { FMTreeNode node = treeNodes[rel.destId]; /** * Dependency with Generalization/Aggregation-stereotype is used as Work-around * for Package Generalization/Aggregation (which is not possible / allowed in UML) * e.g. used for new Functions */ if (rel.type == RelationshipTypeEnum.Dependency) { if ("Generalization".Equals(rel.stereotype)) { rel.type = RelationshipTypeEnum.Generalization; } if ("Aggregation".Equals(rel.stereotype)) { rel.type = RelationshipTypeEnum.Aggregation; } } /** * Generalization relationship means this is a change to an existing base model element */ if (rel.type == RelationshipTypeEnum.Generalization) { node.instructionObject = objectsCI[rel.sourceId]; node.includeInProfile = true; } /** * Aggregation relationship means this is a new child element */ else if (rel.type == RelationshipTypeEnum.Aggregation) { if (treeNodes.ContainsKey(rel.sourceId) && treeNodes[rel.sourceId].isPlaceholder) { FMTreeNode placeholder = treeNodes[rel.sourceId]; placeholder.parent = node; placeholder.isPlaceholder = false; placeholder.includeInProfile = true; setCompilerInclusionReason(placeholder, "New from ProfileDefinition; via PLACEHOLDER"); node.children.Add(placeholder); if (!node.includeInProfile) { node.includeInProfile = true; setCompilerInclusionReason(node, "Because of new child"); } } else if (objectsCI[rel.sourceId].tag != null && objectsCI[rel.sourceId].tag.Any(t => TV_INCLUSIONREASON.Equals(t.name))) { _OutputListener.writeOutput("[WARN] Already new {0}. Check Aggregation relationships!", objectsCI[rel.sourceId].name); } else { // Create the new node FMTreeNode newNode = new FMTreeNode(); newNode.baseModelObject = objectsCI[rel.sourceId]; newNode.baseModelObject.parentId = node.baseModelObject.id; newNode.parent = node; newNode.isNew = true; newNode.includeInProfile = true; setCompilerInclusionReason(newNode, "New from ProfileDefinition"); node.children.Add(newNode); if (!node.includeInProfile) { node.includeInProfile = true; setCompilerInclusionReason(node, "Because of new child"); } treeNodes[rel.sourceId] = newNode; } } /** * Other relationship types not supported */ else { if (DEBUG) { _OutputListener.writeOutput("[DEBUG] Ignored {0}", rel.type); } } } else { if (DEBUG) { /** * Check if destination is inside Profile Definition. * E.g. for internal relationships in Profile Definition or for new elements. */ if (objectsCI.ContainsKey(rel.destId)) { string srcName = rel.sourceId; if (objectsCI[rel.sourceId].name != null) { srcName = objectsCI[rel.sourceId].name.Split(new[] { ' ' })[0]; } string dstName = rel.sourceId; if (objectsCI[rel.destId].name != null) { dstName = objectsCI[rel.destId].name.Split(new[] { ' ' })[0]; } _OutputListener.writeOutput("[DEBUG] Ignored {0} from {1} to {2} inside ProfileDefinition", rel.type, srcName, dstName, parseIdForConsole(rel.sourceId)); } else { // E.g. for ExternalReferences _OutputListener.writeOutput("[DEBUG] Ignored {0} from {1} to id={2} outside BaseModel", rel.type, objectsCI[rel.sourceId].name, rel.destId, parseIdForConsole(rel.sourceId)); } } } } ObjectType profileDefinition = objectsCI.Values.Single(o => R2Const.ST_FM_PROFILEDEFINITION.Equals(o.stereotype)); string rootid = root.baseModelObject.id; root.baseModelObject = new ObjectType() { id = rootid, name = profileDefinition.name, stereotype = R2Const.ST_FM_PROFILE, type = ObjectTypeEnum.Package, typeSpecified = true, tag = profileDefinition.tag }; } // Only follow ConsequenceLinks for ProfileType != Companion bool doFollowConsequenceLinks = true; if (root.baseModelObject.tag.Any(t => "Type".Equals(t.name))) { TagType typeTag = FirstOrDefaultNonEmptyValue(root.baseModelObject.tag, "Type"); doFollowConsequenceLinks = !"Companion".Equals(typeTag.value); } // Exclude and exclude consequenceLinks when Criterion is Excluded exclude(root); // Now auto include parents and criterions and included consequenceLinks autoInclude(root, doFollowConsequenceLinks); // Compile aka execute compiler instructions executeInstructions(root, PRIORITY_ESSENTIALNOW); // Give profile elements new unique ids // Only what is still in the Tree! List <ObjectType> objects = root.ToObjectList(); Dictionary <string, string> idOrg2idNew = new Dictionary <string, string>(); foreach (ObjectType maxObj in objects) { string idOrg = maxObj.id; string idNew = Guid.NewGuid().ToString(); idOrg2idNew[idOrg] = idNew; maxObj.id = idNew; // Also remove modified date maxObj.modifiedSpecified = false; } // Set new (gu)id's in objects parentId foreach (ObjectType maxObj in objects) { if (!string.IsNullOrEmpty(maxObj.parentId)) { if (idOrg2idNew.ContainsKey(maxObj.parentId)) { maxObj.parentId = idOrg2idNew[maxObj.parentId]; } else { // object already has new id assigned, which is also not an integer! _OutputListener.writeOutput("[WARN] Already has new id: {0}", maxObj.name.Split(new[] { ' ' })[0], -1); } } } // Set new (gu)id's for relationships List <RelationshipType> relationships = root.ToRelationshipList(); foreach (RelationshipType maxRel in relationships) { if (idOrg2idNew.ContainsKey(maxRel.sourceId)) { maxRel.sourceId = idOrg2idNew[maxRel.sourceId]; } if (idOrg2idNew.ContainsKey(maxRel.destId)) { maxRel.destId = idOrg2idNew[maxRel.destId]; } } // Remove relationships to objects that are not included foreach (RelationshipType maxRel in relationships.ToArray()) { if (!objects.Any(t => t.id == maxRel.sourceId)) { string sourceId = idOrg2idNew.Single(t => t.Value == maxRel.sourceId).Key; string destName = objects.Single(t => t.id == maxRel.destId).name; _OutputListener.writeOutput("[WARN] Relationship from not included object removed (sourceId={0} destId={1} stereotype={2} destName={3})", sourceId, maxRel.destId, maxRel.stereotype, destName); relationships.Remove(maxRel); } if (!objects.Any(t => t.id == maxRel.destId)) { string sourceId = idOrg2idNew.Single(t => t.Value == maxRel.sourceId).Key; string sourceName = objects.Single(t => t.id == maxRel.sourceId).name; _OutputListener.writeOutput("[WARN] Relationship to not included object removed (sourceId={0} destId={1} stereotype={2} sourceName={3})", sourceId, maxRel.destId, maxRel.stereotype, sourceName); relationships.Remove(maxRel); } } // Convert back to MAX model ModelType model = new ModelType(); model.exportDate = Util.FormatLastModified(DateTime.Now); model.objects = objects.ToArray(); model.relationships = relationships.ToArray(); // Save compiled profile as MAX XML XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.NewLineChars = "\n"; using (XmlWriter writer = XmlWriter.Create(fileNameOutput, settings)) { serializer.Serialize(writer, model); } } }
public XUnitTestFluentGherkin(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; OutputListener.SetListener(_testOutputHelper); }
public PortListItem(OutputListener listener) { Listener = listener; }
protected void LogStep(String stepMessage) { OutputListener.GetListener().WriteLine(stepMessage); }