AnsweredAssumed Answered

Notification it doesn't work correctly

Question asked by Maksim on Sep 14, 2016
Latest reply on Sep 15, 2016 by pmartin

If you change an attribute through Pi Systems Explorer Notification is work, but through the code doesn't work.

Notification trigger monitoring attribute LastTimeUpdated

AF SDK 2.7.5.7166

 

                string path = Application.StartupPath + @"\Images";
                Directory.CreateDirectory(path);
                Directory.CreateDirectory(path + "\\" + img_name);
                AFFile file = new AFFile();
                Bitmap bmp = GetGraphics(type);
                string NotificationFileName = path + "\\" + img_name + ".png";
                bmp.Save(NotificationFileName, System.Drawing.Imaging.ImageFormat.Png);


                string filename = path + "\\" + img_name + "\\" + afElem_name + "_" + part_of_filename + ".png";
                bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
                file.Upload(filename);


                AFNamedCollectionList<AFNotification> notification = AFNotification.FindNotifications(myAFDB, notif_name, AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, 10);
                AFNotification afN = notification.Where(x => x.Name.Equals(notif_name)).First();
                if (afN.Contents.Contains(img_name + ".png"))
                {
                    Hlogger.WriteLogMessage("StatisticsGeneration", "AFNotification сontains " + img_name + ".png", E_ERROR_TYPE.Info);
                    AFNotificationContent content = afN.Contents[img_name + ".png"];
                    AFFile img_file = new AFFile(content.Attribute);
                    img_file.Upload(filename);
                    content.Attribute.SetValue(img_file, null);
                    afN.ApplyChanges();
                    
                }
                else
                {
                    Hlogger.WriteLogMessage("StatisticsGeneration", String.Format("File name {0} does not exist on notification {1}", img_name, notification.ToString()), E_ERROR_TYPE.Error);
                }


                elemRoot.Elements[afElem_name].Attributes["Image"].SetValue(file, null);
                elemRoot.Elements[afElem_name].Attributes["LastTimeUpdated"].SetValue(DateTime.Now, null);
                elemRoot.Elements[afElem_name].CheckIn();

Outcomes