public string GetEventFrame(string Id) { var db = InitializeAf(); string result; Guid guid = new Guid(Id); AFEventFrame eventFrame = AFEventFrame.FindEventFrame(db.PISystem, guid); var attributes = eventFrame.Attributes; var attributesList = new List <AttributeString>(); foreach (var attribute in attributes) { if (attribute.Attributes.Count > 0) { var att = attribute.Attributes; } var a = new AttributeString { Name = attribute.Name, Type = attribute.Type.ToString() }; if (attribute.GetValue().Value != null) { a.Value = attribute.GetValue().Value.ToString(); } attributesList.Add(a); } var serializer = new JavaScriptSerializer(); result = serializer.Serialize(attributesList); return(result); }
public string GetEventFrameTemplate(string Id) { var db = InitializeAf(); string result; var templates = db.ElementTemplates; var attributesList = new List <Attribute>(); foreach (var template in templates) { if (template.InstanceType.FullName == "OSIsoft.AF.EventFrame.AFEventFrame") { if (template.ID.ToString() == Id) { var attributes = template.AttributeTemplates; foreach (var attribute in attributes) { string type = String.Empty; string value = String.Empty; string parent = String.Empty; bool constant = false; bool required = false; if (attribute.AttributeTemplates["TYPE"] != null) { if (attribute.AttributeTemplates["TYPE"].GetValue(null) != null) { type = attribute.AttributeTemplates["TYPE"].GetValue(null).ToString(); } } if (attribute.AttributeTemplates["VALUE"] != null) { if (attribute.AttributeTemplates["VALUE"].GetValue(null) != null) { value = attribute.AttributeTemplates["VALUE"].GetValue(null).ToString(); } } if (attribute.AttributeTemplates["CONSTANT"] != null) { if (attribute.AttributeTemplates["CONSTANT"].GetValue(null) != null) { constant = Convert.ToBoolean(attribute.AttributeTemplates["CONSTANT"].GetValue(null).ToString()); } } if (attribute.AttributeTemplates["REQUIRED"] != null) { if (attribute.AttributeTemplates["REQUIRED"].GetValue(null) != null) { required = Convert.ToBoolean(attribute.AttributeTemplates["REQUIRED"].GetValue(null).ToString()); } } if (attribute.AttributeTemplates["PARENT"] != null) { if (attribute.AttributeTemplates["PARENT"].GetValue(null) != null) { parent = attribute.AttributeTemplates["PARENT"].GetValue(null).ToString(); } } switch (type) { case "List": var b = new AttributeList { Id = attribute.ID, Name = attribute.Name, Type = type, Value = value, Constant = constant, Required = required, Parent = parent }; b.ValueSet = new List <string>(); var elementValueSet = (AFEnumerationSet)attribute.AttributeTemplates["VALUE"].TypeQualifier; if (elementValueSet != null) { foreach (var currentValueInSet in elementValueSet) { b.ValueSet.Add(currentValueInSet.Name.ToString()); } } attributesList.Add(b); break; case "Dictionary": var c = new AttributeDictionary { Id = attribute.ID, Name = attribute.Name, Type = type, Value = value, Constant = constant, Required = required, Parent = parent }; var el = (AFElement)attribute.AttributeTemplates["VALUE"].GetValue(null); var valueSet = el.Elements.Select(currentValueInSet => new DictionaryValueSet { Id = currentValueInSet.ID.ToString(), Name = currentValueInSet.Name }).ToList(); c.ValueSet = valueSet; attributesList.Add(c); break; default: var a = new AttributeString { Id = attribute.ID, Name = attribute.Name, Type = type, Value = value, Constant = constant, Required = required, Parent = parent }; attributesList.Add(a); break; } } } } } var serializer = new JavaScriptSerializer(); result = serializer.Serialize(attributesList); return(result); }