private State CreateNewOcxState(State oldOcxState)
        {
            this.NoComponentChangeEvents++;
            try
            {
                if (this.GetOcState() < 2)
                {
                    return null;
                }
                try
                {
                    PropertyBagStream pPropBag = null;
                    if (this.iPersistPropBag != null)
                    {
                        pPropBag = new PropertyBagStream();
                        this.iPersistPropBag.Save(pPropBag, true, true);
                    }
                    MemoryStream dataStream = null;
                    switch (this.storageType)
                    {
                        case 0:
                        case 1:
                            dataStream = new MemoryStream();
                            if (this.storageType != 0)
                            {
                                break;
                            }
                            this.iPersistStream.Save(new System.Windows.Forms.UnsafeNativeMethods.ComStreamFromDataStream(dataStream), true);
                            goto Label_00A9;

                        case 2:
                            if (oldOcxState == null)
                            {
                                return null;
                            }
                            return oldOcxState.RefreshStorage(this.iPersistStorage);

                        default:
                            return null;
                    }
                    this.iPersistStreamInit.Save(new System.Windows.Forms.UnsafeNativeMethods.ComStreamFromDataStream(dataStream), true);
                Label_00A9:
                    if (dataStream != null)
                    {
                        return new State(dataStream, this.storageType, this, pPropBag);
                    }
                    if (pPropBag != null)
                    {
                        return new State(pPropBag);
                    }
                }
                catch (Exception)
                {
                }
            }
            finally
            {
                this.NoComponentChangeEvents--;
            }
            return null;
        }
Example #2
0
        private State CreateNewOcxState(State oldOcxState) {
            NoComponentChangeEvents++;

            try {
                if (GetOcState() < OC_RUNNING) {
                    return null;
                }

                try {
                    PropertyBagStream propBag = null;

                    if (iPersistPropBag != null) {
                        propBag = new PropertyBagStream();
                        iPersistPropBag.Save(propBag, true, true);
                    }

                    MemoryStream ms = null;
                    switch (storageType) {
                        case STG_STREAM:
                        case STG_STREAMINIT:
                            ms = new MemoryStream();
                            if (storageType == STG_STREAM) {
                                iPersistStream.Save(new UnsafeNativeMethods.ComStreamFromDataStream(ms), true);
                            }
                            else {
                                iPersistStreamInit.Save(new UnsafeNativeMethods.ComStreamFromDataStream(ms), true);
                            }
                            break;
                        case STG_STORAGE:
                            Debug.Assert(oldOcxState != null, "we got to have an old state which holds out scribble storage...");
                            if (oldOcxState != null) return oldOcxState.RefreshStorage(iPersistStorage);
                            return null;
                        default:
                            Debug.Fail("unknown storage type.");
                            return null;
                    }
                    if (ms != null) {
                        return new State(ms, storageType, this, propBag);
                    }
                    else if (propBag != null) {
                        return new State(propBag);
                    }
                }
                catch (Exception e) {
                    Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Could not create new OCX State: " + e.ToString());
                }
            }
            finally {
                NoComponentChangeEvents--;
            }

            return null;
        }