private static bool CanSerializeAsInnerDefaultString(string filter, string name, Type type, ObjectPersistData persistData, PersistenceMode mode, DataBindingCollection dataBindings, ExpressionBindingCollection expressions)
 {
     if (((((type == typeof(string)) && (filter.Length == 0)) && ((mode == PersistenceMode.InnerDefaultProperty) || (mode == PersistenceMode.EncodedInnerDefaultProperty))) && ((dataBindings == null) || (dataBindings[name] == null))) && ((expressions == null) || (expressions[name] == null)))
     {
         if (persistData == null)
         {
             return true;
         }
         ICollection propertyAllFilters = persistData.GetPropertyAllFilters(name);
         if (propertyAllFilters.Count == 0)
         {
             return true;
         }
         if (propertyAllFilters.Count == 1)
         {
             foreach (PropertyEntry entry in propertyAllFilters)
             {
                 if ((entry.Filter.Length == 0) && (entry is ComplexPropertyEntry))
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /// <internalonly/>
 public PersistenceModeAttribute(PersistenceMode mode)
 {
     if (mode < PersistenceMode.Attribute || mode > PersistenceMode.EncodedInnerDefaultProperty)
     {
         throw new ArgumentOutOfRangeException("mode");
     }
     this.mode = mode;
 }
 public PersistenceModeAttribute(PersistenceMode mode)
 {
     if ((mode < PersistenceMode.Attribute) || (mode > PersistenceMode.EncodedInnerDefaultProperty))
     {
         throw new ArgumentOutOfRangeException("mode");
     }
     this.mode = mode;
 }
Ejemplo n.º 4
0
        private IPersistence <TState> CreatePersistence <TState>(TKey key, PersistenceMode mode, Func <TState, Task> applySnapshot, Func <Envelope <IEvent>, Task> applyEvent)
        {
            Guard.NotDefault(key, nameof(key));

            var snapshotStore = (ISnapshotStore <TState, TKey>)services.GetService(typeof(ISnapshotStore <TState, TKey>));

            return(new Persistence <TOwner, TState, TKey>(key, invalidate, failed, eventStore, eventDataFormatter, snapshotStore, streamNameResolver, mode, applySnapshot, applyEvent));
        }
        //Private

        #region 获取持久化模式 —— static InstanceCompletionAction GetInstanceCompletionAction()
        /// <summary>
        /// 获取持久化模式
        /// </summary>
        /// <returns>持久化模式</returns>
        private static InstanceCompletionAction GetInstanceCompletionAction()
        {
            PersistenceMode persistenceMode = WorkflowExtension.GetPersistenceMode();
            int             enumValue       = (int)persistenceMode;

            InstanceCompletionAction instanceCompletionAction = (InstanceCompletionAction)enumValue;

            return(instanceCompletionAction);
        }
Ejemplo n.º 6
0
        public async Task PassesPersistenceToPersister(
            IGroupRun groupRun,
            PersistenceMode persistenceMode,
            IReadOnlySet <ModKey> blacklist,
            string?persistencePath,
            GroupRunPreparer sut)
        {
            await sut.Prepare(groupRun, blacklist, persistenceMode, persistencePath);

            sut.PersistencePreparer.Received(1).Prepare(persistenceMode, persistencePath);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a new CardTrigger to the list.
        /// </summary>
        /// <param name="persistenceMode">SingleRun, or SingleBattle</param>
        /// <param name="cardTriggerEffect"></param>
        /// <param name="buffEffectType"></param>
        /// <param name="paramInt"></param>
        /// <returns></returns>
        public CardTriggerData AddCardTrigger(PersistenceMode persistenceMode, string cardTriggerEffect, string buffEffectType, int paramInt)
        {
            CardTriggerData trigger = new CardTriggerData();

            trigger.persistenceMode   = persistenceMode;
            trigger.cardTriggerEffect = cardTriggerEffect;
            trigger.buffEffectType    = buffEffectType;
            trigger.paramInt          = paramInt;

            CardTriggerEffects.Add(trigger);
            return(trigger);
        }
Ejemplo n.º 8
0
        private IPersistence <T> CreatePersistence(Type owner, DomainId key, PersistenceMode mode, HandleSnapshot <T>?applySnapshot, HandleEvent?applyEvent)
        {
            Guard.NotNull(key, nameof(key));

            return(new Persistence <T>(key, owner,
                                       snapshotStore,
                                       eventStore,
                                       eventDataFormatter,
                                       streamNameResolver,
                                       mode,
                                       applySnapshot,
                                       applyEvent));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name">Name of the dictionary and its backing file</param>
        /// <param name="capacity">Number of buckets for the hash</param>
        /// <param name="persistenceMode"></param>
        public BackingUnknownSize(string name, int capacity       = 1000,
                                  PersistenceMode persistenceMode = PersistenceMode.TemporaryPersist)
        {
            _capacity = HashHelpers.GetNextPrime(capacity);
            SetStorageFilenames(name);

            SetDefaultKeyValueSize();

            _hashCodeLookup = new Array <long>((long)_capacity, _hashFile, true, persistenceMode);
            _keys           = new Array <byte>((long)(_capacity * _defaultKeySize), _keyFile, true, persistenceMode);
            _values         = new Array <byte>((long)(_capacity * _defaultKeySize), _valueFile, true, persistenceMode);

            InitDictionary();
        }
Ejemplo n.º 10
0
 public async Task Prepare(
     IGroupRun groupRun,
     IReadOnlySet <ModKey> blackListedMods,
     PersistenceMode persistenceMode = PersistenceMode.None,
     string?persistencePath          = null)
 {
     await Task.WhenAll(
         Task.Run(() =>
     {
         GroupRunLoadOrderPreparer.Write(groupRun, blackListedMods);
     }),
         Task.Run(() =>
     {
         PersistencePreparer.Prepare(persistenceMode, persistencePath);
     })).ConfigureAwait(false);
 }
Ejemplo n.º 11
0
        public async Task ThrowingPersistencePrepareStillRunsLoadOrderPrepare(
            IGroupRun groupRun,
            PersistenceMode persistenceMode,
            IReadOnlySet <ModKey> blacklist,
            string?persistencePath,
            GroupRunPreparer sut)
        {
            sut.PersistencePreparer.When(x => x.Prepare(Arg.Any <PersistenceMode>(), Arg.Any <string?>()))
            .Do(_ => throw new NotImplementedException());
            await Assert.ThrowsAsync <NotImplementedException>(async() =>
            {
                await sut.Prepare(groupRun, blacklist, persistenceMode, persistencePath);
            });

            sut.GroupRunLoadOrderPreparer.Received(1).Write(groupRun, blacklist);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="maxCapacity">Maximum capacity of MMF</param>
        /// <param name="persistenceMode"></param>
        public FileManager(string filePath, long maxCapacity, PersistenceMode persistenceMode = PersistenceMode.TemporaryPersist)
        {
            // sometimes we won't be able to clean the temp file. must be able to distinguish b/w persistent and temp-persistent
            if (persistenceMode == PersistenceMode.TemporaryPersist) {
                filePath = filePath + ".temp";
                var name = Path.GetFileName(filePath) + "-file-semaphore";
                _tempSemaphore = new Semaphore(_MAX_SHARED_ACCESS, _MAX_SHARED_ACCESS, name);
                _tempSemaphore.WaitOne();
            }
            FileMutex = new Mutex(Path.GetFileName(filePath) + "-file-mutex");

            _fileName = filePath;
            Capacity = maxCapacity;
            PersistenceMode = persistenceMode;

            Mmf = CreateOrOpenFile(_fileName, Capacity, PersistenceMode, FileMutex, false);
        }
Ejemplo n.º 13
0
        public string?Prepare(PersistenceMode persistenceMode, string?persistencePath)
        {
            switch (persistenceMode)
            {
            case PersistenceMode.None:
                return(null);

            case PersistenceMode.Text:
                TextFileSharedFormKeyAllocator.Initialize(persistencePath ?? throw new ArgumentNullException("Persistence mode specified, but no path provided"), _fileSystem);
                break;

            default:
                throw new NotImplementedException();
            }

            return(persistencePath);
        }
Ejemplo n.º 14
0
        internal ComponentInstanceManager(Type componentType, PropertyCollection configuration, PipelineType pipelineType)
        {
            syncLock = new ReaderWriterLock();

            instanceDictionary = new Dictionary <object, PipelineComponent>();

            this.componentType        = componentType;
            this.configuration        = configuration;
            this.pipelineType         = pipelineType;
            this.componentConstructor = componentType.GetConstructor(new Type[] { typeof(PropertyCollection) });

            if (configuration != null)
            {
                configuration.Lock();
            }

            persistenceMode = ((PersistenceAttribute)componentType.GetCustomAttributes(typeof(PersistenceAttribute), true)[0]).PersistenceMode;
        }
Ejemplo n.º 15
0
 public Persistence(TKey ownerKey,
                    IEventStore eventStore,
                    IEventDataFormatter eventDataFormatter,
                    ISnapshotStore <TSnapshot, TKey> snapshotStore,
                    IStreamNameResolver streamNameResolver,
                    PersistenceMode persistenceMode,
                    Func <TSnapshot, Task> applyState,
                    Func <Envelope <IEvent>, Task> applyEvent)
 {
     this.ownerKey           = ownerKey;
     this.applyState         = applyState;
     this.applyEvent         = applyEvent;
     this.eventStore         = eventStore;
     this.eventDataFormatter = eventDataFormatter;
     this.persistenceMode    = persistenceMode;
     this.snapshotStore      = snapshotStore;
     this.streamNameResolver = streamNameResolver;
 }
Ejemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="maxCapacity">Maximum capacity of MMF</param>
        /// <param name="persistenceMode"></param>
        public FileManager(string filePath, long maxCapacity, PersistenceMode persistenceMode = PersistenceMode.TemporaryPersist)
        {
            // sometimes we won't be able to clean the temp file. must be able to distinguish b/w persistent and temp-persistent
            if (persistenceMode == PersistenceMode.TemporaryPersist)
            {
                filePath = filePath + ".temp";
                var name = Path.GetFileName(filePath) + "-file-semaphore";
                _tempSemaphore = new Semaphore(_MAX_SHARED_ACCESS, _MAX_SHARED_ACCESS, name);
                _tempSemaphore.WaitOne();
            }
            FileMutex = new Mutex(Path.GetFileName(filePath) + "-file-mutex");

            _fileName       = filePath;
            Capacity        = maxCapacity;
            PersistenceMode = persistenceMode;

            Mmf = CreateOrOpenFile(_fileName, Capacity, PersistenceMode, FileMutex, false);
        }
Ejemplo n.º 17
0
 public Persistence(TKey ownerKey, Type ownerType,
                    IEventStore eventStore,
                    IEventDataFormatter eventDataFormatter,
                    ISnapshotStore <TSnapshot, TKey> snapshotStore,
                    IStreamNameResolver streamNameResolver,
                    PersistenceMode persistenceMode,
                    HandleSnapshot <TSnapshot> applyState,
                    HandleEvent applyEvent)
 {
     this.ownerKey           = ownerKey;
     this.ownerType          = ownerType;
     this.applyState         = applyState;
     this.applyEvent         = applyEvent;
     this.eventStore         = eventStore;
     this.eventDataFormatter = eventDataFormatter;
     this.persistenceMode    = persistenceMode;
     this.snapshotStore      = snapshotStore;
     this.streamNameResolver = streamNameResolver;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Set the position before setting or getting data
        /// </summary>
        //[Obsolete("Work with accessor")]
        //public long Position { get; set; }

        #endregion

        /// <summary>
        /// Create a new memory mapped array
        /// </summary>
        /// <param name="capacity">The number of elements to allocate in the array</param>
        /// <param name="fileName">File name of the MMF (relative to the DataPath)</param>
        /// <param name="autoGrow">Decide if the array can expand or not</param>
        /// <param name="persistenceMode"></param>
        public Array(long capacity, string fileName, bool autoGrow = false, PersistenceMode persistenceMode = PersistenceMode.TemporaryPersist)
        {
            switch (persistenceMode)
            {
            case PersistenceMode.Persist:
            case PersistenceMode.TemporaryPersist:
                fileName = Path.Combine(Config.DataPath, fileName);
                break;

            case PersistenceMode.Ephemeral:
                break;

            default:
                throw new ArgumentOutOfRangeException("persistenceMode");
            }

            _dataSize = Marshal.SizeOf(typeof(T));
            AutoGrow  = autoGrow;
            Fm        = new FileManager(fileName, capacity * _dataSize, persistenceMode);
        }
Ejemplo n.º 19
0
        public async Task Run(
            IEnumerable <IGroupRun> groupRuns,
            PersistenceMode persistenceMode,
            bool localize,
            Language targetLanguage,
            CancellationToken cancel)
        {
            var outputDir = new DirectoryPath(Path.Combine(_profileDirectories.WorkingDirectory, "Output"));

            _fileSystem.Directory.DeleteEntireFolder(outputDir.Path);
            await _executeRun.Run(
                groups : groupRuns.ToArray(),
                cancel : cancel,
                outputDir : outputDir,
                runParameters : new RunParameters(
                    targetLanguage,
                    Localize: localize,
                    persistenceMode,
                    Path.Combine(_profileDirectories.ProfileDirectory, "Persistence"))).ConfigureAwait(false);
        }
Ejemplo n.º 20
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();

            services
            .AddScoped <IGiftCardRepository, GiftCardRepository>();

            // change the following value to switch persistence mode
            PersistenceMode persistenceMode = PersistenceMode.S3;

            switch (persistenceMode)
            {
            case PersistenceMode.FileSystem:
                ConfigureServicesForFileSystem(services);
                break;

            case PersistenceMode.CosmosDB:
                ConfigureServicesForCosmosDB(services);
                break;

            case PersistenceMode.DynamoDB:
                ConfigureServicesForDynamoDB(services);
                break;

            case PersistenceMode.EfCore:
                ConfigureServicesForEfCore(services);
                break;

            case PersistenceMode.S3:
                ConfigureServicesForS3(services);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 21
0
        ///// <summary>
        ///// Get a working view for the current thread
        ///// </summary>
        ///// <param name="threadId"></param>
        ///// <returns></returns>
        //public Stream GetView(int threadId)
        //{
        //    return Mmf.CreateViewStream();
        //}


        private static MemoryMappedFile CreateOrOpenFile(string fileName,
                                                         long capacity, PersistenceMode persistenceMode, Mutex mutex, bool forGrowth)
        {
            try {
                mutex.WaitOne();
                switch (persistenceMode)
                {
                case PersistenceMode.TemporaryPersist:
                    // we are first to the party since have created the mutex, will create new file instead of previous
                    // we could avoid using semaphore here because mutex.Created = semaphore.Created
                    if (mutex.Created && !forGrowth)
                    {
                        DeleteBackingFileIfExists(fileName);
                    }
                    goto case PersistenceMode.Persist;

                case PersistenceMode.Persist:
                    var fileStream = new FileStream(fileName, FileMode.OpenOrCreate,
                                                    FileAccess.ReadWrite, FileShare.ReadWrite);
                    var mmfs = new MemoryMappedFileSecurity();
                    capacity = Math.Max(fileStream.Length, capacity);
                    return(MemoryMappedFile.CreateFromFile(fileStream,
                                                           Path.GetFileName(fileName), capacity,
                                                           MemoryMappedFileAccess.ReadWrite, mmfs, HandleInheritability.Inheritable,
                                                           false));

                case PersistenceMode.Ephemeral:
                    return(MemoryMappedFile.CreateOrOpen(Path.GetFileName(fileName), capacity, MemoryMappedFileAccess.ReadWrite));

                default:
                    throw new ArgumentOutOfRangeException("persistenceMode");
                }
            } finally {
                mutex.ReleaseMutex();
            }
        }
Ejemplo n.º 22
0
        private IPersistence <TState> CreatePersistence <TState>(Type owner, TKey key, PersistenceMode mode, Func <TState, Task> applySnapshot, Func <Envelope <IEvent>, Task> applyEvent)
        {
            Guard.NotNull(key, nameof(key));

            var snapshotStore = GetSnapshotStore <TState>();

            return(new Persistence <TState, TKey>(key, owner, eventStore, eventDataFormatter, snapshotStore, streamNameResolver, mode, applySnapshot, applyEvent));
        }
        /// <summary>
        ///    <para>
        ///       Persists the properties of a
        ///       string.
        ///    </para>
        /// </summary>
        /// <param name='persistMode'>
        ///    The persistance mode to use.
        /// </param>
        /// <param name=' sw'>
        ///    The string writer to use.
        /// </param>
        /// <param name=' component'>
        ///    The component to persist.
        /// </param>
        /// <param name=' propDesc'>
        ///    A property descriptor for the string properties.
        /// </param>
        private static void PersistStringProperty(TextWriter sw, object component, PropertyDescriptor propDesc, PersistenceMode mode) {
            Debug.Assert(propDesc.PropertyType == typeof(string),
                "Invalid string property : " + propDesc.Name);
            Debug.Assert((mode == PersistenceMode.InnerDefaultProperty) || (mode == PersistenceMode.EncodedInnerDefaultProperty),
                         "Inner string properties must be marked as either InnerDefaultProperty or EncodedInnerDefaultProperty");

            object propValue = propDesc.GetValue(component);
            if (propValue == null) {
                return;
            }

            if (mode == PersistenceMode.InnerDefaultProperty) {
                sw.Write((string)propValue);
            }
            else {
                HttpUtility.HtmlEncode((string)propValue, sw);
            }
        }
        /// <include file='doc\WebControlPersister.uex' path='docs/doc[@for="ControlPersister.PersistCollectionProperty"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Persists a collection property.
        ///    </para>
        /// </devdoc>
        private static void PersistCollectionProperty(TextWriter sw, object component, PropertyDescriptor propDesc, PersistenceMode persistMode, IDesignerHost host)
        {
            Debug.Assert(typeof(ICollection).IsAssignableFrom(propDesc.PropertyType),
                         "Invalid collection property : " + propDesc.Name);

            ICollection propValue = (ICollection)propDesc.GetValue(component);

            if ((propValue == null) || (propValue.Count == 0))
            {
                return;
            }

            sw.WriteLine();
            if (persistMode == PersistenceMode.InnerProperty)
            {
                sw.Write('<');
                sw.Write(propDesc.Name);
                sw.WriteLine('>');
            }

            IEnumerator e = propValue.GetEnumerator();

            while (e.MoveNext())
            {
                object collItem     = e.Current;
                string itemTypeName = GetDeclarativeType(collItem.GetType(), host);

                sw.Write("<");
                sw.Write(itemTypeName);
                PersistAttributes(sw, collItem, String.Empty, null);
                sw.Write(">");

                if (collItem is Control)
                {
                    PersistChildrenAttribute pca =
                        (PersistChildrenAttribute)TypeDescriptor.GetAttributes(collItem.GetType())[typeof(PersistChildrenAttribute)];

                    // asurt 106696: ensure the parent control's visibility is set to true.
                    Control parentControl = (Control)collItem;

                    bool oldVisible = parentControl.Visible;
                    try {
                        parentControl.Visible = true;
                        if (pca.Persist == true)
                        {
                            if (parentControl.HasControls())
                            {
                                PersistChildControls(sw, parentControl.Controls, host);
                            }
                        }
                        else
                        {
                            PersistInnerProperties(sw, collItem, host);
                        }
                    }
                    finally {
                        parentControl.Visible = oldVisible;
                    }
                }
                else
                {
                    PersistInnerProperties(sw, collItem, host);
                }

                sw.Write("</");
                sw.Write(itemTypeName);
                sw.WriteLine(">");
            }

            if (persistMode == PersistenceMode.InnerProperty)
            {
                sw.Write("</");
                sw.Write(propDesc.Name);
                sw.WriteLine('>');
            }
        }
Ejemplo n.º 25
0
 public PersistenceModeAttribute(PersistenceMode mode)
 {
     this.mode = mode;
 }
Ejemplo n.º 26
0
        private IPersistence <TState> CreatePersistence <TState>(Type owner, TKey key, PersistenceMode mode, HandleSnapshot <TState> applySnapshot, HandleEvent applyEvent)
        {
            Guard.NotNull(key, nameof(key));

            var snapshotStore = GetSnapshotStore <TState>();

            return(new Persistence <TState, TKey>(key, owner, eventStore, eventEnricher, eventDataFormatter, snapshotStore, streamNameResolver, mode, applySnapshot, applyEvent));
        }
 public PersistenceModeAttribute(PersistenceMode mode)
 {
 }
Ejemplo n.º 28
0
        /// <summary>
        ///    <para>
        ///       Persists the inner properties of the control.
        ///    </para>
        /// </summary>
        /// <param name='sw'>
        ///    The string writer to use.
        /// </param>
        /// <param name=' component'>
        ///    The component to persist.
        /// </param>
        /// <param name='host'>
        ///    The services interface exposed by the webforms designer.
        /// </param>
        internal static void PersistInnerProperties(TextWriter sw, object component, IDesignerHost host)
        {
            PropertyDescriptorCollection propDescs = TypeDescriptor.GetProperties(component);

            for (int i = 0; i < propDescs.Count; i++)
            {
                // Only deal with inner attributes that need to be persisted
                if (propDescs[i].SerializationVisibility == DesignerSerializationVisibility.Hidden)
                {
                    continue;
                }

                PersistenceModeAttribute persistenceMode = (PersistenceModeAttribute)propDescs[i].Attributes[typeof(PersistenceModeAttribute)];
                if (persistenceMode.Mode == PersistenceMode.Attribute)
                {
                    continue;
                }

                if (propDescs[i].PropertyType == typeof(string))
                {
                    // String based property...

                    DataBindingCollection dataBindings = null;
                    if (component is IDataBindingsAccessor)
                    {
                        dataBindings = ((IDataBindingsAccessor)component).DataBindings;
                    }
                    if (dataBindings == null || dataBindings[propDescs[i].Name] == null)
                    {
                        PersistenceMode mode = persistenceMode.Mode;
                        if ((mode == PersistenceMode.InnerDefaultProperty) ||
                            (mode == PersistenceMode.EncodedInnerDefaultProperty))
                        {
                            PersistStringProperty(sw, component, propDescs[i], mode);
                        }
                        else
                        {
                            Debug.Fail("Cannot persist inner string property marked with PersistenceMode.InnerProperty");
                        }
                    }
                }
                else if (typeof(ITemplate).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    // Template based property...
                    if (persistenceMode.Mode == PersistenceMode.InnerProperty)
                    {
                        PersistTemplateProperty(sw, component, propDescs[i]);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist template property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty");
                    }
                }
/* AUI change 03/21/01 */
                else if (propDescs[i].DisplayName.Equals("Templates") &&
                         component is DeviceSpecificChoice &&
                         typeof(IDictionary).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    IDictionary templateCollection = (IDictionary)propDescs[i].GetValue(component);
                    foreach (String templateName in templateCollection.Keys)
                    {
                        ITemplate template = (ITemplate)templateCollection[templateName];
                        PersistTemplateProperty(sw, templateName, template);
                    }
                }
/* End of AUI change*/
                else if (typeof(ICollection).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    // Collection based property...
                    if ((persistenceMode.Mode == PersistenceMode.InnerProperty) ||
                        (persistenceMode.Mode == PersistenceMode.InnerDefaultProperty))
                    {
                        PersistCollectionProperty(sw, component, propDescs[i], persistenceMode.Mode, host);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist collection property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty or PersistenceMode.InnerDefaultProperty");
                    }
                }
                else
                {
                    // Other complex property...
                    if (persistenceMode.Mode == PersistenceMode.InnerProperty)
                    {
                        PersistComplexProperty(sw, component, propDescs[i], host);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist complex property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty");
                    }
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        ///    <para>
        ///       Persists the properties of a
        ///       string.
        ///    </para>
        /// </summary>
        /// <param name='persistMode'>
        ///    The persistance mode to use.
        /// </param>
        /// <param name=' sw'>
        ///    The string writer to use.
        /// </param>
        /// <param name=' component'>
        ///    The component to persist.
        /// </param>
        /// <param name=' propDesc'>
        ///    A property descriptor for the string properties.
        /// </param>
        private static void PersistStringProperty(TextWriter sw, object component, PropertyDescriptor propDesc, PersistenceMode mode)
        {
            Debug.Assert(propDesc.PropertyType == typeof(string),
                         "Invalid string property : " + propDesc.Name);
            Debug.Assert((mode == PersistenceMode.InnerDefaultProperty) || (mode == PersistenceMode.EncodedInnerDefaultProperty),
                         "Inner string properties must be marked as either InnerDefaultProperty or EncodedInnerDefaultProperty");

            object propValue = propDesc.GetValue(component);

            if (propValue == null)
            {
                return;
            }

            if (mode == PersistenceMode.InnerDefaultProperty)
            {
                sw.Write((string)propValue);
            }
            else
            {
                HttpUtility.HtmlEncode((string)propValue, sw);
            }
        }
 public PersistenceModeAttribute(PersistenceMode mode)
 {
 }
        /// <summary>
        ///    <para>
        ///       Persists a collection property.
        ///    </para>
        /// </summary>
        /// <param name='persistMode'>
        ///    The persistance mode to use.
        /// </param>
        /// <param name=' sw'>
        ///    The string writer to use.
        /// </param>
        /// <param name=' component'>
        ///    The component to persist.
        /// </param>
        /// <param name=' propDesc'>
        ///    A property descriptor for the collection property.
        /// </param>
        /// <param name='host'>
        ///    The services interface exposed by the webforms designer.
        /// </param>
        private static void PersistCollectionProperty(TextWriter sw, object component, PropertyDescriptor propDesc, PersistenceMode persistMode, IDesignerHost host) {
            Debug.Assert(typeof(ICollection).IsAssignableFrom(propDesc.PropertyType),
                "Invalid collection property : " + propDesc.Name);

            ICollection propValue = (ICollection)propDesc.GetValue(component);
            if ((propValue == null) || (propValue.Count == 0))
                return;

// Begin AUI Change #3785
// Original: sw.WriteLine();
            if (!(component is DeviceSpecific))
            {
                sw.WriteLine();
            }
// End of Change #3785

            if (persistMode == PersistenceMode.InnerProperty) {
                sw.Write('<');
                sw.Write(propDesc.Name);
                sw.WriteLine('>');
            }

            IEnumerator e = propValue.GetEnumerator();
            while (e.MoveNext()) {
                object collItem = e.Current;

                // Begin of AUI Change

                //string itemTypeName = GetDeclarativeType(collItem.GetType(), host);
                string itemTypeName;
                
                // AUI : To fix Hashtable objects used in Mobile Controls, only persist the value part
                if (collItem is DictionaryEntry)
                {
                    collItem = ((DictionaryEntry)collItem).Value;
                }
                
                // AUI : First check if the control already has a Default Persist Name,
                //       if not, use the Type as its name

                PersistNameAttribute pna = 
                    (PersistNameAttribute)TypeDescriptor.GetAttributes(collItem.GetType())[typeof(PersistNameAttribute)];

                // attribute should returns default value if it's null.
                // this is unlikely to happen, but just to be on the safe side.
                Debug.Assert (pna != null, "PersistNameAttribute returns null!");

                string persistName = (string)pna.Name;

                if (persistName != null && persistName.Length > 0)
                {
                    itemTypeName = persistName;
                }
/* AUI Change #3911 */
/* Original : else if (collItem is Control) */
                else if (collItem is Control || collItem.GetType() == typeof(System.Web.UI.MobileControls.Style))
                {
                    itemTypeName = GetDeclarativeType(collItem.GetType(), host);
                }
                else
                {
                    itemTypeName = collItem.GetType().Name;
                }
                // End of AUI Change

                sw.Write("<");
                sw.Write(itemTypeName);
                PersistAttributes(sw, collItem, String.Empty, null);
                sw.Write(">");
                
                if (collItem is Control) {
                    PersistChildrenAttribute pca =
                        (PersistChildrenAttribute)TypeDescriptor.GetAttributes(collItem.GetType())[typeof(PersistChildrenAttribute)];

                    if (pca.Persist == true) {
                        // asurt 106696: ensure the parent control's visibility is set to true.
                        Control parentControl = (Control)collItem;
                        if (parentControl.HasControls()) 
                        {
                            bool oldVisible = parentControl.Visible;
                            try 
                            {
                                parentControl.Visible = true;
                                PersistChildControls(sw, parentControl.Controls, host);
                            }
                            finally 
                            {
                                parentControl.Visible = oldVisible;
                            }
                        }
                    }
                    else {
                        PersistInnerProperties(sw, collItem, host);
                    }
                }
                else {
                    PersistInnerProperties(sw, collItem, host);
                }
                
                sw.Write("</");
                sw.Write(itemTypeName);
                sw.WriteLine(">");
            }

            if (persistMode == PersistenceMode.InnerProperty) {
                sw.Write("</");
                sw.Write(propDesc.Name);
                sw.WriteLine('>');
            }
        }
        /// <include file='doc\WebControlPersister.uex' path='docs/doc[@for="ControlPersister.PersistInnerProperties1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Persists the inner properties of the control.
        ///    </para>
        /// </devdoc>
        public static void PersistInnerProperties(TextWriter sw, object component, IDesignerHost host)
        {
            PropertyDescriptorCollection propDescs = TypeDescriptor.GetProperties(component);

            for (int i = 0; i < propDescs.Count; i++)
            {
                // Only deal with inner attributes that need to be persisted
                if (propDescs[i].SerializationVisibility == DesignerSerializationVisibility.Hidden)
                {
                    continue;
                }

                PersistenceModeAttribute persistenceMode = (PersistenceModeAttribute)propDescs[i].Attributes[typeof(PersistenceModeAttribute)];
                if (persistenceMode.Mode == PersistenceMode.Attribute)
                {
                    continue;
                }

                if (propDescs[i].PropertyType == typeof(string))
                {
                    // String based property...

                    DataBindingCollection dataBindings = null;
                    if (component is IDataBindingsAccessor)
                    {
                        dataBindings = ((IDataBindingsAccessor)component).DataBindings;
                    }
                    if (dataBindings == null || dataBindings[propDescs[i].Name] == null)
                    {
                        PersistenceMode mode = persistenceMode.Mode;
                        if ((mode == PersistenceMode.InnerDefaultProperty) ||
                            (mode == PersistenceMode.EncodedInnerDefaultProperty))
                        {
                            PersistStringProperty(sw, component, propDescs[i], mode);
                        }
                        else
                        {
                            Debug.Fail("Cannot persist inner string property marked with PersistenceMode.InnerProperty");
                        }
                    }
                }
                else if (typeof(ICollection).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    // Collection based property...
                    if ((persistenceMode.Mode == PersistenceMode.InnerProperty) ||
                        (persistenceMode.Mode == PersistenceMode.InnerDefaultProperty))
                    {
                        PersistCollectionProperty(sw, component, propDescs[i], persistenceMode.Mode, host);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist collection property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty or PersistenceMode.InnerDefaultProperty");
                    }
                }
                else if (typeof(ITemplate).IsAssignableFrom(propDescs[i].PropertyType))
                {
                    // Template based property...
                    if (persistenceMode.Mode == PersistenceMode.InnerProperty)
                    {
                        PersistTemplateProperty(sw, component, propDescs[i]);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist template property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty");
                    }
                }
                else
                {
                    // Other complex property...
                    if (persistenceMode.Mode == PersistenceMode.InnerProperty)
                    {
                        PersistComplexProperty(sw, component, propDescs[i], host);
                    }
                    else
                    {
                        Debug.Fail("Cannot persist complex property " + propDescs[i].Name + " not marked with PersistenceMode.InnerProperty");
                    }
                }
            }
        }
Ejemplo n.º 33
0
 public StateVariable(string name, DataType dataType, XMLFieldOutputMode xmlFieldOutputMode, PersistenceMode persistenceMode, T value)
 {
     this.Name               = name;
     this.DataType           = dataType;
     this.XMLFieldOutputMode = xmlFieldOutputMode;
     this.PersistenceMode    = persistenceMode;
     this.Value              = value;
 }
 private static void SerializeStringProperty(object obj, IDesignerHost host, PropertyDescriptor propDesc, ObjectPersistData persistData, PersistenceMode persistenceMode, TextWriter writer, string filter)
 {
     string name = propDesc.Name;
     DataBindingCollection dataBindings = null;
     if (obj is IDataBindingsAccessor)
     {
         dataBindings = ((IDataBindingsAccessor) obj).DataBindings;
     }
     ExpressionBindingCollection expressions = null;
     if (obj is IExpressionsAccessor)
     {
         expressions = ((IExpressionsAccessor) obj).Expressions;
     }
     if ((persistenceMode == PersistenceMode.InnerProperty) || CanSerializeAsInnerDefaultString(filter, name, propDesc.PropertyType, persistData, persistenceMode, dataBindings, expressions))
     {
         ArrayList list = new ArrayList();
         if (((dataBindings == null) || (dataBindings[name] == null)) || ((expressions == null) || (expressions[name] == null)))
         {
             string y = string.Empty;
             object objA = propDesc.GetValue(obj);
             if (objA != null)
             {
                 y = objA.ToString();
             }
             bool flag = true;
             if (filter.Length == 0)
             {
                 bool flag2;
                 bool flag3 = GetShouldSerializeValue(obj, name, out flag2);
                 if (flag2)
                 {
                     flag = flag3;
                 }
                 else
                 {
                     object objB = GetPropertyDefaultValue(propDesc, name, persistData, filter, host);
                     flag = !object.Equals(objA, objB);
                 }
             }
             else
             {
                 object obj4 = GetPropertyDefaultValue(propDesc, name, persistData, filter, host);
                 flag = !object.Equals(objA, obj4);
             }
             if (flag)
             {
                 IDictionary z = GetExpandos(filter, name, persistData);
                 list.Add(new Triplet(filter, y, z));
             }
         }
         if (persistData != null)
         {
             foreach (PropertyEntry entry in persistData.GetPropertyAllFilters(name))
             {
                 if ((string.Compare(entry.Filter, filter, StringComparison.OrdinalIgnoreCase) != 0) && (entry is ComplexPropertyEntry))
                 {
                     ComplexPropertyEntry entry2 = (ComplexPropertyEntry) entry;
                     string str3 = entry2.Builder.BuildObject().ToString();
                     IDictionary dictionary2 = GetExpandos(entry.Filter, name, persistData);
                     list.Add(new Triplet(entry.Filter, str3, dictionary2));
                 }
             }
         }
         foreach (Triplet triplet in list)
         {
             bool flag4 = false;
             IDictionary third = triplet.Third as IDictionary;
             if (((list.Count == 1) && (triplet.First.ToString().Length == 0)) && ((third == null) || (third.Count == 0)))
             {
                 if (persistenceMode == PersistenceMode.InnerDefaultProperty)
                 {
                     writer.Write(triplet.Second.ToString());
                     flag4 = true;
                 }
                 else if (persistenceMode == PersistenceMode.EncodedInnerDefaultProperty)
                 {
                     HttpUtility.HtmlEncode(triplet.Second.ToString(), writer);
                     flag4 = true;
                 }
             }
             if (!flag4)
             {
                 string str4 = triplet.First.ToString();
                 WriteInnerPropertyBeginTag(writer, str4, name, third, true);
                 writer.Write(triplet.Second.ToString());
                 WriteInnerPropertyEndTag(writer, str4, name);
             }
         }
     }
 }
 private static void SerializeCollectionProperty(object obj, IDesignerHost host, PropertyDescriptor propDesc, ObjectPersistData persistData, PersistenceMode persistenceMode, TextWriter writer, string filter)
 {
     string name = propDesc.Name;
     bool flag = false;
     ICollection is2 = propDesc.GetValue(obj) as ICollection;
     int count = 0;
     if (is2 != null)
     {
         count = is2.Count;
     }
     int num2 = 0;
     ObjectPersistData objectPersistData = null;
     if (persistData != null)
     {
         ComplexPropertyEntry filteredProperty = persistData.GetFilteredProperty(string.Empty, name) as ComplexPropertyEntry;
         if (filteredProperty != null)
         {
             objectPersistData = filteredProperty.Builder.GetObjectPersistData();
             num2 = objectPersistData.CollectionItems.Count;
         }
     }
     if (filter.Length == 0)
     {
         flag = true;
     }
     else if (persistData != null)
     {
         if (persistData.GetFilteredProperty(filter, name) is ComplexPropertyEntry)
         {
             flag = true;
         }
         else if (num2 != count)
         {
             flag = true;
         }
         else if (objectPersistData != null)
         {
             IEnumerator enumerator = is2.GetEnumerator();
             IEnumerator enumerator2 = objectPersistData.CollectionItems.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 enumerator2.MoveNext();
                 ComplexPropertyEntry current = (ComplexPropertyEntry) enumerator2.Current;
                 if (enumerator.Current.GetType() != current.Builder.ControlType)
                 {
                     flag = true;
                     break;
                 }
             }
         }
     }
     bool flag2 = false;
     ArrayList list = new ArrayList();
     if (count > 0)
     {
         StringWriter writer2 = new StringWriter(CultureInfo.InvariantCulture);
         IDictionary table = new Hashtable(ReferenceKeyComparer.Default);
         if (objectPersistData != null)
         {
             foreach (ComplexPropertyEntry entry3 in objectPersistData.CollectionItems)
             {
                 ObjectPersistData data2 = entry3.Builder.GetObjectPersistData();
                 if (data2 != null)
                 {
                     data2.AddToObjectControlBuilderTable(table);
                 }
             }
         }
         if (!flag)
         {
             flag2 = true;
             foreach (object obj2 in is2)
             {
                 string tagName = GetTagName(obj2.GetType(), host);
                 ObjectPersistData data3 = null;
                 ControlBuilder builder = (ControlBuilder) table[obj2];
                 if (builder != null)
                 {
                     data3 = builder.GetObjectPersistData();
                 }
                 writer2.Write('<');
                 writer2.Write(tagName);
                 SerializeAttributes(obj2, host, string.Empty, data3, writer2, filter);
                 writer2.Write('>');
                 SerializeInnerProperties(obj2, host, data3, writer2, filter);
                 writer2.Write("</");
                 writer2.Write(tagName);
                 writer2.WriteLine('>');
             }
             IDictionary z = GetExpandos(filter, name, objectPersistData);
             list.Add(new Triplet(string.Empty, writer2, z));
         }
         else
         {
             foreach (object obj3 in is2)
             {
                 string str3 = GetTagName(obj3.GetType(), host);
                 if (obj3 is Control)
                 {
                     SerializeControl((Control) obj3, host, writer2, string.Empty);
                 }
                 else
                 {
                     writer2.Write('<');
                     writer2.Write(str3);
                     ObjectPersistData data4 = null;
                     ControlBuilder builder2 = (ControlBuilder) table[obj3];
                     if (builder2 != null)
                     {
                         data4 = builder2.GetObjectPersistData();
                     }
                     if ((filter.Length == 0) && (data4 != null))
                     {
                         SerializeAttributes(obj3, host, string.Empty, data4, writer2, string.Empty);
                         writer2.Write('>');
                         SerializeInnerProperties(obj3, host, data4, writer2, string.Empty);
                     }
                     else
                     {
                         SerializeAttributes(obj3, host, string.Empty, null, writer2, string.Empty);
                         writer2.Write('>');
                         SerializeInnerProperties(obj3, host, null, writer2, string.Empty);
                     }
                     writer2.Write("</");
                     writer2.Write(str3);
                     writer2.WriteLine('>');
                 }
             }
             IDictionary dictionary3 = GetExpandos(filter, name, persistData);
             list.Add(new Triplet(filter, writer2, dictionary3));
         }
     }
     else if (num2 > 0)
     {
         IDictionary dictionary4 = GetExpandos(filter, name, persistData);
         list.Add(new Triplet(filter, new StringWriter(CultureInfo.InvariantCulture), dictionary4));
     }
     if (persistData != null)
     {
         foreach (ComplexPropertyEntry entry4 in persistData.GetPropertyAllFilters(name))
         {
             StringWriter writer3 = new StringWriter(CultureInfo.InvariantCulture);
             if ((string.Compare(entry4.Filter, filter, StringComparison.OrdinalIgnoreCase) != 0) && (!flag2 || (entry4.Filter.Length > 0)))
             {
                 ObjectPersistData data5 = entry4.Builder.GetObjectPersistData();
                 data5.CollectionItems.GetEnumerator();
                 foreach (ComplexPropertyEntry entry5 in data5.CollectionItems)
                 {
                     object obj4 = entry5.Builder.BuildObject();
                     if (obj4 is Control)
                     {
                         SerializeControl((Control) obj4, host, writer3, string.Empty);
                     }
                     else
                     {
                         string str4 = GetTagName(obj4.GetType(), host);
                         ObjectPersistData data6 = entry5.Builder.GetObjectPersistData();
                         writer3.Write('<');
                         writer3.Write(str4);
                         SerializeAttributes(obj4, host, string.Empty, data6, writer3, string.Empty);
                         writer3.Write('>');
                         SerializeInnerProperties(obj4, host, data6, writer3, string.Empty);
                         writer3.Write("</");
                         writer3.Write(str4);
                         writer3.WriteLine('>');
                     }
                 }
                 IDictionary dictionary5 = GetExpandos(entry4.Filter, name, persistData);
                 list.Add(new Triplet(entry4.Filter, writer3, dictionary5));
             }
         }
     }
     foreach (Triplet triplet in list)
     {
         string str5 = triplet.First.ToString();
         IDictionary third = (IDictionary) triplet.Third;
         if ((((list.Count == 1) && (str5.Length == 0)) && (persistenceMode != PersistenceMode.InnerProperty)) && ((third == null) || (third.Count == 0)))
         {
             writer.Write(triplet.Second.ToString());
         }
         else
         {
             string str6 = triplet.Second.ToString().Trim();
             if (str6.Length > 0)
             {
                 WriteInnerPropertyBeginTag(writer, str5, name, third, true);
                 writer.WriteLine(str6);
                 WriteInnerPropertyEndTag(writer, str5, name);
             }
         }
     }
 }
Ejemplo n.º 36
0
 ///// <summary>
 ///// Get a working view for the current thread
 ///// </summary>
 ///// <param name="threadId"></param>
 ///// <returns></returns>
 //public Stream GetView(int threadId)
 //{
 //    return Mmf.CreateViewStream();
 //}
 private static MemoryMappedFile CreateOrOpenFile(string fileName,
     long capacity, PersistenceMode persistenceMode, Mutex mutex, bool forGrowth)
 {
     try {
         mutex.WaitOne();
         switch (persistenceMode) {
             case PersistenceMode.TemporaryPersist:
                 // we are first to the party since have created the mutex, will create new file instead of previous
                 // we could avoid using semaphore here because mutex.Created = semaphore.Created
                 if (mutex.Created && !forGrowth) { DeleteBackingFileIfExists(fileName); }
                 goto case PersistenceMode.Persist;
             case PersistenceMode.Persist:
                 var fileStream = new FileStream(fileName, FileMode.OpenOrCreate,
                     FileAccess.ReadWrite, FileShare.ReadWrite);
                 var mmfs = new MemoryMappedFileSecurity();
                 capacity = Math.Max(fileStream.Length, capacity);
                 return MemoryMappedFile.CreateFromFile(fileStream,
                     Path.GetFileName(fileName), capacity,
                     MemoryMappedFileAccess.ReadWrite, mmfs, HandleInheritability.Inheritable,
                     false);
             case PersistenceMode.Ephemeral:
                 return MemoryMappedFile.CreateOrOpen(Path.GetFileName(fileName), capacity, MemoryMappedFileAccess.ReadWrite);
             default:
                 throw new ArgumentOutOfRangeException("persistenceMode");
         }
     } finally {
         mutex.ReleaseMutex();
     }
 }
		public PersistenceModeAttribute (PersistenceMode mode)
		{
			this.mode = mode;
		}
Ejemplo n.º 38
0
        /// <summary>
        /// Construct an instance of a ReflectedControlProperty, given the control for this property and the
        /// pre-reflected PropertyInfo for the property in question.
        /// </summary>
        /// <param name="reflectedControl">The control that owns this property.</param>
        /// <param name="propertyInfo">The pre-reflected PropertyInfo for this property.</param>
        public ReflectedControlProperty(ReflectedControl reflectedControl, PropertyInfo propertyInfo)
        {
            ReflectedControl = reflectedControl;
            PropertyInfo     = propertyInfo;


            var custAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.PersistenceModeAttribute));

            if (custAtts.Any())
            {
                var parseAtt = custAtts.First();

                // public PersistenceModeAttribute(PersistenceMode mode);
                if (parseAtt.ConstructorArguments.Count == 1)
                {
                    PersistenceMode val = (PersistenceMode)parseAtt.ConstructorArguments[0].Value;
                    PersistenceModeAttribute = new System.Web.UI.PersistenceModeAttribute(val);
                    //public ParseChildrenAttribute();
                }
            }
            else
            {
                PersistenceModeAttribute = null;
            }



            //System.Web.UI.PersistenceModeAttribute[] persistenceModeAttributes = (System.Web.UI.PersistenceModeAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.PersistenceModeAttribute), true);
            //PersistenceModeAttribute = persistenceModeAttributes.Length == 0 ? null : persistenceModeAttributes[0];

            IsTemplateProperty   = typeof(System.Web.UI.ITemplate).IsAssignableFrom(PropertyInfo.PropertyType);
            IsCollectionProperty = typeof(IEnumerable).IsAssignableFrom(PropertyInfo.PropertyType) && !IsTemplateProperty;

            if (IsTemplateProperty)
            {
                var custTemplateInstanceAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.TemplateInstanceAttribute));
                if (custTemplateInstanceAtts.Any())
                {
                    var parseAtt = custTemplateInstanceAtts.First();

                    // public TemplateInstanceAttribute(TemplateInstance instances);
                    if (parseAtt.ConstructorArguments.Count == 1)
                    {
                        TemplateInstance val = (TemplateInstance)parseAtt.ConstructorArguments[0].Value;
                        TemplateInstanceAttribute = new System.Web.UI.TemplateInstanceAttribute(val);
                        //public ParseChildrenAttribute();
                    }
                }
                else
                {
                    TemplateInstanceAttribute = null;
                }


                //System.Web.UI.TemplateInstanceAttribute[] templateInstanceAttributes = (System.Web.UI.TemplateInstanceAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.TemplateInstanceAttribute), true);
                //TemplateInstanceAttribute = templateInstanceAttributes.Length == 0 ? null : templateInstanceAttributes[0];


                var custTemplateContainerAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.TemplateContainerAttribute));
                if (custTemplateContainerAtts.Any())
                {
                    var parseAtt = custTemplateContainerAtts.First();


                    if (parseAtt.ConstructorArguments.Count == 1)
                    {
                        // public TemplateContainerAttribute(Type containerType);
                        Type val = (Type)parseAtt.ConstructorArguments[0].Value;
                        TemplateContainerAttribute = new System.Web.UI.TemplateContainerAttribute(val);
                    }
                    else if (parseAtt.ConstructorArguments.Count == 2)
                    {
                        // public TemplateContainerAttribute(Type containerType, BindingDirection bindingDirection);
                        Type             val = (Type)parseAtt.ConstructorArguments[0].Value;
                        BindingDirection dir = (BindingDirection)parseAtt.ConstructorArguments[1].Value;
                        TemplateContainerAttribute = new System.Web.UI.TemplateContainerAttribute(val, dir);
                    }
                }
                else
                {
                    TemplateContainerAttribute = null;
                }

                //System.Web.UI.TemplateContainerAttribute[] templateContainerAttributes = (System.Web.UI.TemplateContainerAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.TemplateContainerAttribute), true);
                //TemplateContainerAttribute = templateContainerAttributes.Length == 0 ? null : templateContainerAttributes[0];
            }
            else if (IsCollectionProperty)
            {
                CollectionItemTypes = GetCollectionItemTypes(PropertyInfo.PropertyType);
            }
        }
Ejemplo n.º 39
0
        /// <summary>
        ///    <para>
        ///       Persists a collection property.
        ///    </para>
        /// </summary>
        /// <param name='persistMode'>
        ///    The persistance mode to use.
        /// </param>
        /// <param name=' sw'>
        ///    The string writer to use.
        /// </param>
        /// <param name=' component'>
        ///    The component to persist.
        /// </param>
        /// <param name=' propDesc'>
        ///    A property descriptor for the collection property.
        /// </param>
        /// <param name='host'>
        ///    The services interface exposed by the webforms designer.
        /// </param>
        private static void PersistCollectionProperty(TextWriter sw, object component, PropertyDescriptor propDesc, PersistenceMode persistMode, IDesignerHost host)
        {
            Debug.Assert(typeof(ICollection).IsAssignableFrom(propDesc.PropertyType),
                         "Invalid collection property : " + propDesc.Name);

            ICollection propValue = (ICollection)propDesc.GetValue(component);

            if ((propValue == null) || (propValue.Count == 0))
            {
                return;
            }

// Begin AUI Change #3785
// Original: sw.WriteLine();
            if (!(component is DeviceSpecific))
            {
                sw.WriteLine();
            }
// End of Change #3785

            if (persistMode == PersistenceMode.InnerProperty)
            {
                sw.Write('<');
                sw.Write(propDesc.Name);
                sw.WriteLine('>');
            }

            IEnumerator e = propValue.GetEnumerator();

            while (e.MoveNext())
            {
                object collItem = e.Current;

                // Begin of AUI Change

                //string itemTypeName = GetDeclarativeType(collItem.GetType(), host);
                string itemTypeName;

                // AUI : To fix Hashtable objects used in Mobile Controls, only persist the value part
                if (collItem is DictionaryEntry)
                {
                    collItem = ((DictionaryEntry)collItem).Value;
                }

                // AUI : First check if the control already has a Default Persist Name,
                //       if not, use the Type as its name

                PersistNameAttribute pna =
                    (PersistNameAttribute)TypeDescriptor.GetAttributes(collItem.GetType())[typeof(PersistNameAttribute)];

                // attribute should returns default value if it's null.
                // this is unlikely to happen, but just to be on the safe side.
                Debug.Assert(pna != null, "PersistNameAttribute returns null!");

                string persistName = (string)pna.Name;

                if (persistName != null && persistName.Length > 0)
                {
                    itemTypeName = persistName;
                }
/* AUI Change #3911 */
/* Original : else if (collItem is Control) */
                else if (collItem is Control || collItem.GetType() == typeof(System.Web.UI.MobileControls.Style))
                {
                    itemTypeName = GetDeclarativeType(collItem.GetType(), host);
                }
                else
                {
                    itemTypeName = collItem.GetType().Name;
                }
                // End of AUI Change

                sw.Write("<");
                sw.Write(itemTypeName);
                PersistAttributes(sw, collItem, String.Empty, null);
                sw.Write(">");

                if (collItem is Control)
                {
                    PersistChildrenAttribute pca =
                        (PersistChildrenAttribute)TypeDescriptor.GetAttributes(collItem.GetType())[typeof(PersistChildrenAttribute)];

                    if (pca.Persist == true)
                    {
                        // asurt 106696: ensure the parent control's visibility is set to true.
                        Control parentControl = (Control)collItem;
                        if (parentControl.HasControls())
                        {
                            bool oldVisible = parentControl.Visible;
                            try
                            {
                                parentControl.Visible = true;
                                PersistChildControls(sw, parentControl.Controls, host);
                            }
                            finally
                            {
                                parentControl.Visible = oldVisible;
                            }
                        }
                    }
                    else
                    {
                        PersistInnerProperties(sw, collItem, host);
                    }
                }
                else
                {
                    PersistInnerProperties(sw, collItem, host);
                }

                sw.Write("</");
                sw.Write(itemTypeName);
                sw.WriteLine(">");
            }

            if (persistMode == PersistenceMode.InnerProperty)
            {
                sw.Write("</");
                sw.Write(propDesc.Name);
                sw.WriteLine('>');
            }
        }
Ejemplo n.º 40
0
 public ObjectStateVariable(string name, string objectClassName, PersistenceMode persistenceMode, Dictionary <string, IStateVariable> value)
     : base(name, DataType.Object, XMLFieldOutputMode.Element, persistenceMode, value)
 {
     this.ObjectClassName = objectClassName;
 }