ViewFolder::AddView() not working

Hello,

The following code illustrate my problem:

private void CreateView()
{
  var ms = new ManagementServer(EnvironmentManager.Instance.MasterSite);
  var destination = ms.ViewGroupFolder.ViewGroups.First(v => v.DisplayName == "Test").ViewGroupFolder.ViewGroups.First(v => v.DisplayName == "Views");
 
  var layoutGroup = ms.LayoutGroupFolder.LayoutGroups.First(l => l.DisplayName == "4:3");
  var layout = layoutGroup.LayoutFolder.Layouts.First(l => l.DisplayName == "3 x 3");
 
  var xml = System.Xml.Linq.XElement.Parse(layout.DefinitionXml);
  var layoutType = xml.Attribute("ViewLayoutType").Value;
  var layoutCustomId = xml.Attribute("Id").Value;
  var layoutViewItems = xml.Element("ViewItems").ToString();
  var layoutIcon = xml.Element("ViewLayoutIcon").Value;
 
  // ------ 1 START ------
  //  NOT WORKING
  //var task = destination.ViewFolder.AddView("Demo", "", layoutType, layoutCustomId, layoutIcon, layoutViewItems);
  //while (task.State != StateEnum.Error && task.State != StateEnum.Success)
  //{
  //  System.Threading.Thread.Sleep(10);
  //  task.UpdateState();
  //}
  //var view = new Task(EnvironmentManager.Instance.MasterSite.ServerId, task.Path);
  // ------ 1 END ------
 
  // ------ 2 START ------
  //  WORKING but deprecated
  var task = destination.ViewFolder.AddView(layoutViewItems);
  task.SetProperty("Name", "Demo");
  task.ExecuteDefault();
  var view = new Task(EnvironmentManager.Instance.MasterSite.ServerId, task.Path);
  // ------ 2 END ------
 
  var items = view.ViewItemChildItems.ToList();
  if (items.Count != 9)
    throw new Exception("Error");
}

Basically, only the deprecated version of ViewFolder::AddView works.

What happens is that the number of ViewItemChildItems when using the first code block is always 2, and when using the deprecated version then it’s correctly set to 9.

In both cases the views are created it’s just the number of ViewItemChildItems that is not correct.

Before going deeper please tell, what version is the XProtect server?

Hello,

MIP SDK 22.3.0 & XProtect Server 22.2a

@Bo Ellegård Andersen (Milestone Systems)​ any answer about my ViewFolder::AddView() question?

I am sorry for delayed reply. Milestone Development had started an investigation for this issue, and then they have fixed it. The fix will be released on 2023 R1.