/// <summary> /// Create any non-existing PI points based on a list of point definitions on a given PI Data Archive /// </summary> /// <param name="targetPI"></param> /// <param name="pointDefinitions"></param> private static void CreatePIPoints(PIServer targetPI, IDictionary<string, IDictionary<string, object>> pointDefinitions) { IEnumerable<string> pointNames = pointDefinitions.Keys; // See what points exist var resolvedPoints = new HashSet<string>(PIPoint.FindPIPoints(targetPI, pointNames) .Select(pt => pt.Name)); // Filter out existing points var pointsToCreate = pointDefinitions .Where(p => !resolvedPoints.Contains(p.Key)) .ToDictionary(p => p.Key, p => p.Value); // Create any points with default PI point attributes IEnumerable<string> pointsWithDefaultAttributes = pointsToCreate .Where(p => p.Value == null) .Select(p => p.Key) .ToList(); targetPI.CreatePIPoints(pointsWithDefaultAttributes); // Create other PI points foreach (var pt in pointsWithDefaultAttributes) { pointsToCreate.Remove(pt); } targetPI.CreatePIPoints(pointsToCreate); }
public void Run() { PIServers piServers = new PIServers(); PIServer piServer = piServers["<AFSERVER>"]; // Use PICommonPointAttributes so we don't have to remember the strings for point attributes. string floatpoint = "sample_floatpoint"; Dictionary <string, object> floatpoint_attributes = new Dictionary <string, object>(); floatpoint_attributes.Add(PICommonPointAttributes.PointClassName, "classic"); floatpoint_attributes.Add(PICommonPointAttributes.Descriptor, "Hello floating world"); floatpoint_attributes.Add(PICommonPointAttributes.PointType, "float32"); string digitalpoint = "sample_digitalpoint"; Dictionary <string, object> digitalpoint_attributes = new Dictionary <string, object>(); digitalpoint_attributes.Add(PICommonPointAttributes.PointClassName, "classic"); digitalpoint_attributes.Add(PICommonPointAttributes.Descriptor, "Hello digital world"); digitalpoint_attributes.Add(PICommonPointAttributes.PointType, "digital"); digitalpoint_attributes.Add(PICommonPointAttributes.DigitalSetName, "modes"); Dictionary <string, IDictionary <string, object> > pointDict = new Dictionary <string, IDictionary <string, object> >(); pointDict.Add(floatpoint, floatpoint_attributes); pointDict.Add(digitalpoint, digitalpoint_attributes); AFListResults <string, PIPoint> results = piServer.CreatePIPoints(pointDict); }
private static IList <PIPoint> GetOrCreatePIPoints(PIServer dataArchive, IEnumerable <string> inputTagNames, string prefix) { // Build a set of output tag names by sticking the prefix on each input tag name. var outputTagNames = inputTagNames.Select(name => $"{prefix}{name}"); // Let's see if the output tags already exist. Part of the exercise is to notify the end-user. // It'd be nice to have this as a List instead of IList so we can later use AddRange. var outputTags = GetPIPoints(dataArchive, outputTagNames).ToList(); foreach (var tag in outputTags) { Console.WriteLine($"Tag '{tag}' already exists."); } // Let's not think in terms of All Or None, as in either all are missing or none are. // Where's the fun in that? Instead we challenge outselves to check to see if any // individual names are missing and only create that subset. var missingTagNames = outputTagNames.Except(outputTags.Select(tag => tag.Name)); if (missingTagNames.Count() == 0) { // None were missing so we can return now. return(outputTags); } // We have at least one, if not all, to create. // When we fetch the input tag, e.g. "New York_Temperature", we want to also fetch its point attributes. // Since all known inputs are "classic", we will work with that. // But we don't need the Tag (Name) since we must use brand new names to create the output tags. var classicAttrs = GetPointAttributes(dataArchive, "classic").Except(ExcludedPointAttributes).ToArray(); // Simultaneously find tags and load the point attributes. // Note the points we want to find are those input tags where we do not have an existing output tag. var inputTags = GetPIPoints(dataArchive, missingTagNames.Select(name => name.Substring(prefix.Length)), classicAttrs); // Prep a dictionary of tag definitions var definitions = new Dictionary <string, IDictionary <string, object> >(); foreach (var tag in inputTags) { definitions[$"{prefix}{tag.Name}"] = tag.GetAttributes(classicAttrs); } // Make a bulk call to create all missing tags in one call. var createdPoints = dataArchive.CreatePIPoints(definitions); // Add the new tags to our output list. outputTags.AddRange(createdPoints.Results); return(outputTags); }
public void CreateAllPIPoints(List <string> newPIPointNames) { if (newPIPointNames.Count > 0) { List <string> filteredNewPIPointNames = newPIPointNames.Where(p => allPIPointNames.Contains(p) == false).ToList(); if (filteredNewPIPointNames.Count > 0) { IDictionary <string, object> attributes = new Dictionary <string, object>(); attributes.Add("pointtype", "int32"); AFListResults <string, PIPoint> results = piServer.CreatePIPoints(filteredNewPIPointNames.AsEnumerable(), attributes); } } }
/// <summary> /// Create any non-existing PI points based on a list of point definitions on a given PI Data Archive /// </summary> /// <param name="targetPI"></param> /// <param name="pointDefinitions"></param> private static void CreatePIPoints(PIServer targetPI, IDictionary <string, IDictionary <string, object> > pointDefinitions) { IEnumerable <string> pointNames = pointDefinitions.Keys; // See what points exist var resolvedPoints = new HashSet <string>(PIPoint.FindPIPoints(targetPI, pointNames) .Select(pt => pt.Name)); // Filter out existing points var pointsToCreate = pointDefinitions .Where(p => !resolvedPoints.Contains(p.Key)) .ToDictionary(p => p.Key, p => p.Value); // Create any points with default PI point attributes IEnumerable <string> pointsWithDefaultAttributes = pointsToCreate .Where(p => p.Value == null) .Select(p => p.Key) .ToList(); var results = targetPI.CreatePIPoints(pointsWithDefaultAttributes); if (results.Errors.Count > 0) { throw new AggregateException(results.Errors.Values); } // Create other PI points foreach (var pt in pointsWithDefaultAttributes) { pointsToCreate.Remove(pt); } results = targetPI.CreatePIPoints(pointsToCreate); if (results.Errors.Count > 0) { throw new AggregateException(results.Errors.Values); } }
private IList <PIPoint> CreatePoints(PIServer server) { var tagNames = GeneratePointNames(NameSuffix, NumStart, NumEnd); Logger.Info("Creating the PI Points on the server"); var result = server.CreatePIPoints(tagNames, GetPointAttributes()); if (result != null && result.HasErrors) { result.Errors.ToList().ForEach(e => Logger.Error("Error with: " + e.Key, e.Value)); } Logger.Info("operation completed."); // if results are not nul returns the results, otherwise, returns null return(result?.Results); }
private IList<PIPoint> CreatePoints(PIServer server) { var tagNames = GeneratePointNames(NameSuffix, NumStart, NumEnd); Logger.Info("Creating the PI Points on the server"); var result = server.CreatePIPoints(tagNames, GetPointAttributes()); if (result != null && result.HasErrors) result.Errors.ToList().ForEach(e => Logger.Error("Error with: " + e.Key, e.Value)); Logger.Info("operation completed."); // if results are not nul returns the results, otherwise, returns null return result?.Results; }