public ProfilePropertyCollection(ProfilePropertyCollection collection) : base()
 {
     foreach (string name in collection.Names)
     {
         this.BaseSet(name, collection[name]);
     }
 }
Beispiel #2
0
        protected virtual void RefreshProperties()
        {
            this.m_extendedAttributes.PropertyChanged -= new PropertyChangedEventHandler(extendedAttributes_PropertyChanged);

            IProfileStorage data       = this.SerializerData ?? new ProfileSerializerData();
            var             attributes = ProfileSerializer.ConvertToProfilePropertyCollection(data.PropertyNames, data.PropertyValuesString, data.PropertyValuesBinary);

            ProfilePropertyCollection collection = attributes ?? new ProfilePropertyCollection();

            this.m_extendedAttributes.Clear();
            foreach (string name in collection.Names)
            {
                this.m_extendedAttributes.Add(name, collection[name]);
            }

            this.m_extendedAttributes.PropertyChanged -= new PropertyChangedEventHandler(extendedAttributes_PropertyChanged);
            this.m_extendedAttributes.PropertyChanged += new PropertyChangedEventHandler(extendedAttributes_PropertyChanged);
        }
Beispiel #3
0
        public ProfileExtender(bool binarySupported = true, bool lazyRefresh = true, IProfileStorage storage = null)
        {
            this.m_extendedAttributes = new ProfilePropertyCollection();
            this.m_extendedAttributes.PropertyChanged += new PropertyChangedEventHandler(extendedAttributes_PropertyChanged);
            this.m_data = storage ?? new ProfileSerializerData();
            this.RefreshProperties();
            this.m_data.PropertyChanged += new PropertyChangedEventHandler(m_data_PropertyChanged);
            this._binarySupported        = binarySupported;
            this._lazyRefresh            = lazyRefresh;

            Expression <Func <IProfileStorage, String> > exNames = s => s.PropertyNames;

            this._propertyNamesPropertyName = exNames.GetMemberName();

            Expression <Func <IProfileStorage, String> > propertValueNames = s => s.PropertyValuesString;

            this._propertyStringPropertyName = propertValueNames.GetMemberName();

            Expression <Func <IProfileStorage, byte[]> > propertBinaryValueNames = s => s.PropertyValuesBinary;

            this._propertyBinaryPropertyName = propertBinaryValueNames.GetMemberName();
        }
Beispiel #4
0
        public static ProfilePropertyCollection ConvertToProfilePropertyCollection(string allNames, string valuesString, byte[] valuesBinary)
        {
            ProfilePropertyCollection collection = new ProfilePropertyCollection();

            if (allNames.IsNullOrEmpty() || allNames.Split(':').Length < 4)
            {
                return(collection);
            }
            string[] names  = allNames.Split(':');
            string   values = valuesString ?? String.Empty;

            byte[] buf = valuesBinary ?? new byte[0];
            for (int iter = 0; iter < names.Length / 4; iter++)
            {
                string name     = names[iter * 4];
                object proValue = null;

                int startPos = Int32.Parse(names[iter * 4 + 2], CultureInfo.InvariantCulture);
                int length   = Int32.Parse(names[iter * 4 + 3], CultureInfo.InvariantCulture);

                if (names[iter * 4 + 1] == "S" && startPos >= 0 && length > 0 && values.Length >= startPos + length)
                {
                    proValue = values.Substring(startPos, length);
                }

                if (names[iter * 4 + 1] == "B" && startPos >= 0 && length > 0 && buf.Length >= startPos + length)
                {
                    byte[] buf2 = new byte[length];

                    Buffer.BlockCopy(buf, startPos, buf2, 0, length);

                    proValue = buf2;
                }
                collection.Add(name, proValue);
            }
            return(collection);
        }
Beispiel #5
0
        public static void ConvertFromProfilePropertyCollection(ProfilePropertyCollection properties, out string allNames, out string valuesString, out byte[] valuesBinary, bool binarySupported)
        {
            StringBuilder names  = new StringBuilder();
            StringBuilder values = new StringBuilder();

            valuesBinary = null;
            MemoryStream ms = (binarySupported ? new System.IO.MemoryStream() : null);

            try
            {
                foreach (string name in properties.Names)
                {
                    int    len = 0, startPos = 0;
                    string propValue = null;

                    object sVal = properties[name];

                    if (sVal == null)
                    {
                        len = -1;
                    }
                    else
                    {
                        if (!(sVal is string) && !binarySupported)
                        {
                            sVal = Convert.ToBase64String((byte[])sVal);
                        }

                        if (sVal is string)
                        {
                            propValue = (string)sVal;
                            len       = propValue.Length;
                            startPos  = values.Length;
                        }
                        else
                        {
                            byte[] b2 = (byte[])sVal;
                            startPos = (int)ms.Position;
                            ms.Write(b2, 0, b2.Length);
                            ms.Position = startPos + b2.Length;
                            len         = b2.Length;
                        }
                    }

                    names.Append(name + ":" + ((propValue != null) ? "S" : "B") +
                                 ":" + startPos.ToString(CultureInfo.InvariantCulture) + ":" + len.ToString(CultureInfo.InvariantCulture) + ":");
                    if (propValue != null)
                    {
                        values.Append(propValue);
                    }
                }

                if (binarySupported)
                {
                    valuesBinary = ms.ToArray();
                }
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                }
            }
            allNames     = names.ToString();
            valuesString = values.ToString();
        }