Using ADXIESharedMemory to move Dictionary<string,string> across tabs

Add-in Express™ Support Service
That's what is more important than anything else

Using ADXIESharedMemory to move Dictionary<string,string> across tabs
 
SilverStr




Posts: 28
Joined: 2013-03-31
So I am trying to understand how to use ADXIESharedMemory, and every post points to the sample for options in a small amount of GlobalData.

I would like to learn how to pass a block of key/value pairs sitting in a Dictionary<> across tabs. Can you help me to understand how that would be done? I would like to see samples of how each instance would push/pull the Dictionary and learn what boundaries for memory exist. ie: Is there any max size IE has for shared memory like this? Is there any limitations?

Looking forward to hearing how this all works!

Regards,
Dana
Posted 12 Jul, 2013 00:26:41 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hello,

The shared memory is not the IE feature. This is a part of the system memory management:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366525(v=vs.85).aspx
Please read the 'File Mapping' chapter to learn more about the shared memory:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366556(v=vs.85).aspx

I will send you an example of how you can serialize the Dictionary and pass it between tabs/windows.
Posted 12 Jul, 2013 06:41:28 Top
SilverStr




Posts: 28
Joined: 2013-03-31
So, being that this is being written to /Local, what happens if there are tabs in different integrity levels? A protected mode tab runs in LocalLow doesn't it?
Posted 12 Jul, 2013 11:59:28 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hello,

Sorry for the delay. Here is the code that sends the dictionary between tabs/windows in IE. It works with protected mode as well.


        private Dictionary<string, string> myCollection = null;

        public void UpdateCollection(Dictionary<string, string> newCollection)
        {
            if ((this.myCollection != null) && newCollection != null)
            {
                this.myCollection.Clear();

                foreach (string key in newCollection.Keys)
                {
                    this.myCollection.Add(key, newCollection[key]);
                }
            }
        }

        private void IEModule_OnConnect(object sender, int threadId)
        {
            this.myCollection = new Dictionary<string, string>();
        }

        // pass data
        private void adxieContextMenuCommandItem1_OnClick(object sender, object htmlElement)
        {
            this.myCollection.Clear();
            this.myCollection.Add("1", "item 1: " + this.ThreadID.ToString());
            this.myCollection.Add("2", "item 2: " + this.ThreadID.ToString());
            this.myCollection.Add("3", "item 3: " + this.ThreadID.ToString());

            ArrayList moduleList = 
                AddinExpress.IE.ADXIEModule.GetModulesByTypeName(this.GetType().FullName);
            if (moduleList.Count > 0)
            {
                IEModule m;

                for (int i = 0; i < moduleList.Count; i++)
                {
                    m = moduleList[i] as IEModule;
                    if (m != null && m.ThreadID != this.ThreadID)
                    {
                        m.UpdateCollection(this.myCollection);
                    }
                }
            }
        }

        // show data
        private void adxieContextMenuCommandItem2_OnClick(object sender, object htmlElement)
        {
            if (this.myCollection != null)
            {
                string text = String.Empty;

                foreach (string key in this.myCollection.Keys)
                {
                    text += key + " = " + this.myCollection[key] + "
";
                }

                MessageBox.Show(this, text, this.ModuleName);
            }
        }
Posted 16 Jul, 2013 06:10:08 Top