3 Replies Latest reply on Sep 15, 2016 1:26 PM by pmartin

    Notification it doesn't work correctly

    Maksim

      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();
      
        • Re: Notification it doesn't work correctly
          pmartin

          Hi Maksim,

           

          I seem to be unable to reproduce your issue.  Did you check the file itself after you ran through this code?  Changing the file won't change the DisplayName, that's a separate property.

           

          For reference, here is the code I used:

          AFNotification n = AFNotification.FindNotifications(db, "AnyChange", AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, 1).FirstOrDefault();
          AFNotificationContent content = n.Contents[1];
          string path = Path.Combine(Path.GetTempPath(), "TestUpload.txt");
          using (File.Create(path)) { }
          AFFile upload = new AFFile(content.Attribute);
          upload.Upload(path);
          content.Attribute.SetValue(upload, null);
          content.DisplayName = "TestUpload.txt";
          n.ApplyChanges();