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 void configurationTreeView_AfterSelect(object sender, TreeViewEventArgs e) { AFTreeNode node = (AFTreeNode)e.Node; AFElement selectedCalculation = (AFElement)node.AFObject; if (!selectedCalculation.IsRoot) { calculationName.Text = selectedCalculation.Name; CalculationPreference preference = CalculationPreference.CalculationPreferenceFromJSON((string)selectedCalculation.Attributes["configuration"].GetValue().Value); queryTextBox.Text = preference.eventFrameQuery; Dictionary <AFAttributeTrait, string> limitCalculations = preference.getTraitDictionary(); foreach (AFAttributeTrait trait in AFAttributeTrait.AllLimits) { ComboBox comboBox = (ComboBox)panel1.Controls[trait.Name]; comboBox.Text = "None"; } foreach (KeyValuePair <AFAttributeTrait, string> pair in limitCalculations) { ComboBox comboBox = (ComboBox)panel1.Controls[pair.Key.Name]; comboBox.Text = pair.Value; } offsetSetting.Text = preference.offset.ToString(); AFAttribute sensor = AFAttribute.FindAttribute(preference.sensorPath, db); afDatabasePicker.AFDatabase = sensor.Database; afTreeView.AFRoot = sensor.Database.Elements; afTreeView.AFSelect(sensor, db, preference.sensorPath); afTreeView.SelectedNode.EnsureVisible(); afTreeView.Focus(); } }
public LimitCalculation(CalculationPreference preference, string calculationName) { this.calculationName = calculationName; try { logger.Info($"Starting calculations for {calculationName}"); string afattributepath = preference.sensorPath; string eventQuery = preference.eventFrameQuery; calculationsToPerform = preference.getTraitDictionary(); offset = preference.offset; this.preference = preference; sensor = AFAttribute.FindAttribute(afattributepath, null); pisystem = sensor.PISystem; afdatabase = sensor.Database; foreach (KeyValuePair <AFAttributeTrait, string> pair in calculationsToPerform) { bounds[pair.Key] = new AFValues(); AFAttribute possibleAttribute = sensor.GetAttributeByTrait(pair.Key); boundAttributes[pair.Key] = possibleAttribute; logger.Info($"Will perform calculation for limit: {pair.Key}"); if (possibleAttribute == null) { logger.Error($"{calculationName}: The limit {pair.Key} is not defined yet is used."); } } eventFrameQuery = new AFEventFrameSearch(afdatabase, "eventFrameSearch", eventQuery); } catch (System.Exception e) { logger.Error($"{calculationName} the following error occured: {e.Message}"); } logger.Info($"{calculationName}: Doing the initial run"); InitialRun(); }
private void addToPreference_Click(object sender, EventArgs e) { if (calculationName.Text == "") { MessageBox.Show("Please specify the name of the calculation", "No Name specified", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } AFTreeNode node = (AFTreeNode)afTreeView.SelectedNode; string path = node.AFPath; if (path == "" || path == null) { MessageBox.Show("Please select a attribute", "No attribute specified", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } string query = queryTextBox.Text; double offset = Convert.ToDouble(offsetSetting.Text); Dictionary <string, string> limits = new Dictionary <string, string> { }; foreach (AFAttributeTrait limit in AFAttributeTrait.AllLimits) { ComboBox comboBox = (ComboBox)panel1.Controls[limit.Name]; if (comboBox.Text != "None") { limits[limit.Name] = comboBox.Text; } } CalculationPreference preference = new CalculationPreference(path, query, offset, limits); AFElement preferenceRoot = ((AFElement)configurationTreeView.AFRoot); AFValue configurationValue = new AFValue(preference.JSON()); AFElement preferenceElement = preferenceRoot.Elements[calculationName.Text]; if (preferenceElement == null) { preferenceElement = new AFElement(calculationName.Text); preferenceElement.Attributes.Add("Configuration"); preferenceElement.Attributes["Configuration"].Type = typeof(string); preferenceRoot.Elements.Add(preferenceElement); preferenceRoot.CheckIn(); } preferenceElement.Attributes["Configuration"].SetValue(configurationValue); preferenceElement.CheckIn(); configurationTreeView.Refresh(); configurationTreeView.AFSelect(preferenceElement, preferenceElement.Database, preferenceElement.GetPath()); }