Workspace Plugin Init

Hello,

I am using workspace plugin Init() to initialize the html view item. I am trying to access username and password options from OptionsDialog. However it does get the properties. I get error message “Object referece not set to Instance of Object”. Is it not possible to access OptionsDialog at this stage in Init(). Please let me know.

Thanks

Giridhar

If you look at the Property plugin sample, this sample reads and stores a value in the OptionsDialog while it also reads and stores the exact same in the Workspace.

Does this sample work for you? Maybe you can use this sample to compare the code with what you have implemented..

If the sample does not fit what you are trying to achieve please elaborate on what you are trying to achieve and what you have done.

Hello Bo,

Thank you for the mail.

I have a plugin with 4 camera views and a url to load a map in another view. So there are 5 views in total. In the Workspace Init() the views layout are created along with the the url. The url needs username and password which read from OptionsDialog plugin. I tried debugging the code and set the breakpoint on Workspace Init(). I realized that OptionsDialog is still null. I dont know where else I can construct the url and add property to the view. So that as soon as the plugin is loaded the url fetches the html page and displays the content in the view.

public class XYWorkSpacePlugin : WorkSpacePlugin
{
    ...
    ...
    ...
    public override void Init()
    {
        LoadProperties(true);
        
        ....
        ....
        ....
        
        //TODO
        //This code fails
        try {
            if (XYOptionsDialogPlugin._myUserControl.Surl != String.Empty)
            {
                cturl = new Uri(XYOptionsDialogPlugin._myUserControl.Surl);
                protocol = cturl.Substring(0, cturl.IndexOf(":"));
                host = cturl.Host;
                queryStr = cturl.Query;
                url = protocol + "://" + XYOptionsDialogPlugin._myUserControl.UserName + ":" +
                XYOptionsDialogPlugin._myUserControl.Password + "@" + host +
                "/basicAuthApp/" + queryStr;
            }        
        }
        catch(Exception ex) {
            //
        }
        
        properties5.Add("URL", url);
        properties5.Add("Scaling", "4"); // fit in 640x480
        properties5.Add("Addscript", "true");
        properties5.Add("HideNavigationBar", "false");
        ViewAndLayoutItem.InsertBuiltinViewItem(5, ViewAndLayoutItem.HTMLBuiltinId, properties5);
    }
}

I have pasted the template code for your review. I checked the Property plugin sample but could not get much out of it. Any pointer on this would be of great help.

Thank You

Giridhar

Because of what you explain the Property sample sounds more and more to me like a perfect fit. You want configurable variables you can use from plugins and which can be stored by the OptionsDialog.

It boils down reading your property-

System.Xml.XmlNode result = VideoOS.Platform.Configuration.Instance.GetOptionsConfiguration(PropertyDefinition.MyPropertyId, false);
_myUserControl.MyPropShareGlobal = Utility.GetInnerText(result, "Empty");

and writing-

VideoOS.Platform.Configuration.Instance.SaveOptionsConfiguration(Property.PropertyDefinition.MyPropertyId, false, Utility.ToXml("SharedProperty", _myUserControl.MyPropShareGlobal));

Same code in the diferent kind of plugins. Try to revisit the sample.

Hello Bo,

I went through the Properties plugin code. I added the following lines to my plugin.

public class XYOptionsDialogPlugin : OptionsDialogPlugin
{
    ...
    ...
    ...
    public override bool SaveChanges()
    {
        if (_myUserControl == null) return true;
 
        // SetProperty - maintains a dictionary of properties (default implementation)
        SetProperty("Username", _myUserControl.UserName);
        SetProperty("Password", _myUserControl.Password);
        SetProperty("Surl", _myUserControl.Surl);
        VideoOS.Platform.Configuration.Instance.SaveOptionsConfiguration(Id, false, Utility.ToXml("Username", _myUserControl.UserName));
        VideoOS.Platform.Configuration.Instance.SaveOptionsConfiguration(Id, false, Utility.ToXml("Password", _myUserControl.Password));
        VideoOS.Platform.Configuration.Instance.SaveOptionsConfiguration(Id, false, Utility.ToXml("Surl", _myUserControl.Surl));
        SaveProperties(true);
        return true;
    }
}

When checked in the debugger, I could see only “Surl” value stored.

System.Xml.XmlNode result = VideoOS.Platform.Configuration.Instance.GetOptionsConfiguration(XYDefinition.XYOptionsDialog, false);
{Element, Name="root"}
    [System.Xml.XmlElement]: {Element, Name="root"}
    Attributes: {System.Xml.XmlAttributeCollection}
    BaseURI: ""
    ChildNodes: {System.Xml.XmlChildNodes}
    FirstChild: {Element, Name="Surl"}
    HasChildNodes: true
    InnerText: "http://x.y.com/basicAuthApp/?target=abcd/&uiMode=xprotect"
    InnerXml: "<Surl>http://x.y.com/basicAuthApp/?target=abcd/&uiMode=xprotect</Surl>"
    IsReadOnly: false
    LastChild: {Element, Name="Surl"}
    LocalName: "root"
    Name: "root"
    NamespaceURI: ""
    NextSibling: null
    NodeType: Element
    OuterXml: "<root xmlns=\"\"><Surl>http://x.y.com/basicAuthApp/?target=abcd_dev/&uiMode=xprotect</Surl></root>"
    OwnerDocument: {Document}
    ParentNode: {Document}
    Prefix: ""
    PreviousSibling: null
    PreviousText: null
    SchemaInfo: {System.Xml.XmlName}
    Value: null

I do not see Username or Password values stored. Could you please let me know how I can store and retrieve multiple properties.

Thanks

Giridhar

You would get the OptionsConfiguration like this:

System.Xml.XmlNode result = VideoOS.Platform.Configuration.Instance.GetOptionsConfiguration(PropertyDefinition.MyPropertyId, false);

Which make me think you can only have one OptionsConfiguration per Id. I suggest you make a XML with all three values you want to save, alternatively you use multiple Id’s.

I am not sure I have given the best advise. Maybe this is better..

In the AnalyticsOverlay sample you set an option in the OptionsDialog.

Note how it is used in the BackgroundPlugin, not by use of the OptionsDialog but by use of GetOptionsConfiguration (BackgroundOverlayPlugin.cs line 92).

Hello Bo,

Based on your previous comment to add three values to one Definition Id. I could save all three values as below:

doc = Utility.getXmlDocument();
            XmlElement root = Utility.AppendElement(doc, "Username", _myUserControl.UserName);
            root = Utility.AppendElement(doc, "Password", _myUserControl.Password);
            root = Utility.AppendElement(doc, "Surl", _myUserControl.Surl);
 
            VideoOS.Platform.Configuration.Instance.SaveOptionsConfiguration(XYDefinition.MyPropertyId, false, root);

And retrieved the values as below:

try
            {
                System.Xml.XmlNode result = VideoOS.Platform.Configuration.Instance.GetOptionsConfiguration(XYDefinition.MyPropertyId, false);
                if (result != null)
                {
                    cturl = new Uri(result.LastChild.InnerText);
                    urlStr = cturl.Scheme + "://" + result.FirstChild.InnerText + ":" +
                    result.ChildNodes[1].InnerText + "@" + cturl.Host +
                    "/basicAuthApp/" + cturl.Query;
                }
                return urlStr;
            }

Thank You

Giridhar

Hello,

Now in XProtect Client 2020 R2, I start getting errors for reading the properties that are set earlier. This worked in the previous versions.

If I read the xml doc again, it shows all properties in a single string “usernamepasswordurl”. This is bit odd.

Is there any other way that I can read each property separately? Please let me know.

Thank You

Giridhar