static void Main(string[] args) { logger.Info("The application has started."); PISystem pisystem = new PISystems().DefaultPISystem; pisystem.Connect(); logger.Info($"Connecting as: {pisystem.CurrentUserIdentityString}"); AFDatabase configuration = pisystem.Databases["Configuration"]; AFElements preferences = configuration.Elements["LimitCalculator"].Elements; logger.Info($"Will process {preferences.Count} preferences"); List <DatabaseMonitoring> monitoredDB = new List <DatabaseMonitoring> { }; Parallel.ForEach(preferences, (preference) => { string JSON = (string)preference.Attributes["configuration"].GetValue().Value; logger.Info($"Configuration for preference: {JSON}"); LimitCalculation calc = new LimitCalculation(CalculationPreference.CalculationPreferenceFromJSON(JSON), preference.Name); monitoredDB.Add(new DatabaseMonitoring(calc)); }); WaitForQuit(); }
private static void ListElements(AFElement parentElement, StreamWriter outputFile) { AFElements elements = parentElement.Elements; foreach (AFElement element in elements) { ListAttributes(element, outputFile); ListElements(element, outputFile); } }
public static void WriteAttributes(AFDatabase database, string outputFile) { using (StreamWriter outputStreamWriter = new StreamWriter(outputFile)) { AFElements elements = database.Elements; foreach (AFElement element in elements) { ListAttributes(element, outputStreamWriter); ListElements(element, outputStreamWriter); } } }
static void PrintRootElements(AFDatabase database) { Console.WriteLine("Print Root Elements: {0}", database.Elements.Count); AFElements afEl = database.Elements; foreach (AFElement element in afEl) { Console.WriteLine(" {0}", element.Name); } Console.WriteLine(); }
public void ShowElements(AFElements elements) { ++depth; foreach (AFElement e in elements) { WriteElementDepthString(); Console.WriteLine("Element: {0}", e.Name); ShowAttributes(e.Attributes); ShowElements(e.Elements); } --depth; }
/// <summary> /// This is a custom implementation of AF SDK's CreateConfig() that does not require a 1-by-1 element check out/in. /// Create PI Points according to configstring values. /// Modify the configstring afterward by stripping off the trailing key-value pairs. /// </summary> private void CreatePIPoints() { EventHandler <AFProgressEventArgs> PIPointCreationEventHandler = new EventHandler <AFProgressEventArgs>(NotifyPIPointCreationToConsole); AFElements leafElements = _afContext.Database.Elements["LeafElements"].Elements; OrderablePartitioner <Tuple <int, int> > rangePartition = Partitioner.Create(0, _conf.TotalLeafs, _conf.PointsChunkSize / 2); Parallel.ForEach(rangePartition, new ParallelOptions { MaxDegreeOfParallelism = _conf.MaxParallel }, range => { List <AFElement> chunk = new List <AFElement>(); for (int i = range.Item1; i < range.Item2; i++) { chunk.Add(leafElements[i]); } ElementCreator.CreateorUpdatePIPointDataReference(chunk, PIPointCreationEventHandler); }); }