예제 #1
0
        /// <summary>
        /// Returns one or more rows from a table, beginning at the current cursor position.
        /// </summary>
        /// <param name="lRowCount">Maximum number of rows to be returned.</param>
        /// <param name="sRows">an SRow array holding the table rows.</param>
        /// <returns></returns>
        public bool QueryRows(int lRowCount, out SRow[] sRows)
        {
            IntPtr  pRowSet = IntPtr.Zero;
            HRESULT hr      = tb_.QueryRows(lRowCount, 0, out pRowSet);

            if (hr != HRESULT.S_OK)
            {
                MAPINative.MAPIFreeBuffer(pRowSet);
            }

            uint cRows = (uint)Marshal.ReadInt32(pRowSet);

            sRows = new SRow[cRows];

            if (cRows < 1)
            {
                MAPINative.MAPIFreeBuffer(pRowSet);
                return(false);
            }

            int    pIntSize = IntPtr.Size, intSize = Marshal.SizeOf(typeof(Int32));
            int    sizeOfSRow = 2 * intSize + pIntSize;
            IntPtr rows       = pRowSet + intSize;

            for (int i = 0; i < cRows; i++)
            {
                IntPtr pRowOffset = rows + i * sizeOfSRow;
                uint   cValues    = (uint)Marshal.ReadInt32(pRowOffset + pIntSize);
                IntPtr pProps     = Marshal.ReadIntPtr(pRowOffset + pIntSize + intSize);

                IPropValue[] lpProps = new IPropValue[cValues];
                for (int j = 0; j < cValues; j++) // each column
                {
                    SPropValue lpProp = (SPropValue)Marshal.PtrToStructure(pProps + j * Marshal.SizeOf(typeof(SPropValue)), typeof(SPropValue));
                    lpProps[j] = new MAPIProp(lpProp);
                }
                sRows[i].propVals = lpProps;
            }
            MAPINative.MAPIFreeBuffer(pRowSet);
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Returns one or more rows from a table, beginning at the current cursor position.
        /// </summary>
        /// <param name="lRowCount">Maximum number of rows to be returned.</param>
        /// <param name="sRows">an SRow array holding the table rows.</param>
        /// <returns></returns>
        public bool QueryRows(int lRowCount, out SRow[] sRows)
        {
            IntPtr pRowSet = IntPtr.Zero;
            HRESULT hr = tb_.QueryRows(lRowCount, 0, out pRowSet);
            if (hr != HRESULT.S_OK)
            {
                MAPINative.MAPIFreeBuffer(pRowSet);
            }

            uint cRows = (uint)Marshal.ReadInt32(pRowSet);
            sRows = new SRow[cRows];

            if (cRows < 1)
            {
                MAPINative.MAPIFreeBuffer(pRowSet);
                return false;
            }

            int pIntSize = IntPtr.Size, intSize = Marshal.SizeOf(typeof(Int32));
            int sizeOfSRow = 2 * intSize + pIntSize;
            IntPtr rows = pRowSet + intSize;
            for (int i = 0; i < cRows; i++)
            {
                IntPtr pRowOffset = rows + i * sizeOfSRow;
                uint cValues = (uint)Marshal.ReadInt32(pRowOffset + pIntSize);
                IntPtr pProps = Marshal.ReadIntPtr(pRowOffset + pIntSize + intSize);

                IPropValue[] lpProps = new IPropValue[cValues];
                for (int j = 0; j < cValues; j++) // each column
                {
                    SPropValue lpProp = (SPropValue)Marshal.PtrToStructure(pProps + j * Marshal.SizeOf(typeof(SPropValue)), typeof(SPropValue));
                    lpProps[j] = new MAPIProp(lpProp);
                }
                sRows[i].propVals = lpProps;
            }
            MAPINative.MAPIFreeBuffer(pRowSet);
            return true;
        }
예제 #3
0
            //~MAPIProp() { }
            public IPropValue[] GetProps(PropTags[] tags)
            {
                uint[] t = new uint[tags.Length + 1];
                t[0] = (uint)tags.Length;
                for (int i = 0; i < tags.Length; i++)
                    t[i + 1] = (uint)tags[i];

                IntPtr propVals = IntPtr.Zero;
                uint count = 0;
                HRESULT hr = pIMAPIPropGetProps(this.ptr, t, out count, ref propVals);
                if (hr != HRESULT.S_OK)
                    throw new Exception("GetProps failed: " + hr.ToString());

                IPropValue[] props = new IPropValue[count];
                uint pProps = (uint)propVals;
                for (int i = 0; i < count; i++)
                {
                    pSPropValue lpProp = (pSPropValue)Marshal.PtrToStructure((IntPtr)(pProps + i * cemapi.SizeOfSPropValue), typeof(pSPropValue));
                    props[i] = new SPropValue(lpProp);
                }
                cemapi.MAPIFreeBuffer(propVals);
                return props;
            }
예제 #4
0
 private MetaProperty(IPropValue simplePropValue)
 {
     SimplePropValue = simplePropValue;
 }
예제 #5
0
 public static void JudgePropIsMetaProp(IPropValue propValue, out MetaProperty metaProperty)
 {
     if (JudgePropIsMetaProp(propValue.PropIdWithType))
     {
         metaProperty = new MetaProperty(propValue);
         return;
     }
     throw new ArgumentException("Property is not Metaproperty.");
 }
예제 #6
0
 private void CreateTransferUnit()
 {
     var propertyTag = FTStreamParseContext.Instance.ReadPropertyTag();
     _unit = FTFactory.Instance.CreatePropValue(propertyTag);
 }
예제 #7
0
 protected virtual void BuildEachProperty(IStorage storage, IStream propertyStream, IPropValue property)
 {
     WritePropertyInfoToPropertyStream(propertyStream, property);
     WritePropertyValueToStorage(storage, property);
 }
예제 #8
0
 protected override int ModifyPropertyLength(IPropValue property)
 {
     if (property.PropTag.PropertyId == 0x0FF9)
     {
         return 4;
     }
     return base.ModifyPropertyLength(property);
 }
예제 #9
0
 protected override byte[] ModifyPropertyValue(IPropValue property)
 {
     if (property.PropTag.PropertyId == 0x0FF9)
     {
         return BitConverter.GetBytes((int)_attachIndex);
     }
     return base.ModifyPropertyValue(property);
 }
예제 #10
0
 internal void AddProperty(IPropValue propValue)
 {
     CurrentPropCollection.AddProperties(propValue);
 }
예제 #11
0
            public SRow[] QueryRows(int lRowCount)
            {
                if (lRowCount > MaxQueryRowCount)
                    throw new Exception("Max row count is " + MaxQueryRowCount.ToString());
                IntPtr pRowSet = IntPtr.Zero;
                HRESULT hr = pIMAPITableQueryRows(this.ptr, lRowCount, out pRowSet);
                if (hr != HRESULT.S_OK)
                {
                    cemapi.MAPIFreeBuffer(pRowSet);
                    throw new Exception("QueryRows failed: " + hr.ToString());
                }

                uint cRows = (uint)Marshal.ReadInt32(pRowSet);
                SRow[] sRows = new SRow[cRows];

                if (cRows < 1)
                {
                    FreeProws(pRowSet);
                    return sRows;
                }

                int pIntSize = IntPtr.Size, intSize = Marshal.SizeOf(typeof(Int32));
                IntPtr rows = (IntPtr)(((uint)pRowSet) + intSize);
                for (int i = 0; i < cRows; i++)
                {
                    uint pRowOffset = (uint)(rows) + (uint)(i * SizeOfSRow);
                    uint cValues = (uint)Marshal.ReadInt32((IntPtr)(pRowOffset + intSize));
                    uint pProps = (uint)Marshal.ReadInt32((IntPtr)(pRowOffset + intSize * 2));

                    IPropValue[] lpProps = new IPropValue[cValues];
                    for (int j = 0; j < cValues; j++) // each column
                    {
                        pSPropValue lpProp = (pSPropValue)Marshal.PtrToStructure((IntPtr)(pProps + j * cemapi.SizeOfSPropValue), typeof(pSPropValue));
                        lpProps[j] = new SPropValue(lpProp);
                    }
                    sRows[i].propVals = lpProps;
                }
                FreeProws(pRowSet);
                return sRows;
            }
예제 #12
0
        public void AddProperty(IPropValue property)
        {
            var tag = BaseStruct.GetPropertyTag(property.PropTag);

            if (property is ISpecialValue && Properties.ContainsKey((uint)tag))
            {
                return;
            }
            Properties[(uint)tag] = property;
        }
예제 #13
0
        public virtual void AddProperties(IPropValue property)
        {
            if (property.PropInfo is NamePropInfo)
            {
                uint changedId = 0;
                var dic = NamedPropIdToChangedId;
                if (!dic.TryGetValue(property.PropTag.PropertyTag, out changedId))
                {
                    changedId = (uint)dic.Count + (uint)0x8000;
                    changedId = (changedId << 16) | property.PropTag.PropertyType;
                    dic.Add(property.PropTag.PropertyTag, changedId);
                }

                ModifyPropertyTag(property, changedId);

                NamedProperties[property.PropTag.PropertyId] = property;
            }
            Properties.AddProperty(property);
        }
예제 #14
0
        private void WritePropertyValueToStorage(IStorage storage, IPropValue property)
        {
            if (property is VarPropValue || PropertyTag.IsGuidType(property.PropTag) || property is SpecialVarBaseProperty)
            {
                var streamName = GetPropertyStreamName(property.PropTag); // string.Format("__substg1.0_{0:X8}", GetPropertyTag(property.PropTag));
                IStream varPropStream = null;
                try
                {
                    varPropStream = CompoundFileUtil.Instance.GetChildStream(streamName, true, storage);
                    varPropStream.Write(ModifyPropertyValue(property));
                    varPropStream.Commit(0);
                }
                finally
                {
                    CompoundFileUtil.Instance.ReleaseComObj(varPropStream);
                }
            }
            else if (property is MvPropValue)
            {
                if (PropertyTag.IsMultiVarType((ushort)property.PropTag.PropertyTag)) // MVVarValue
                {
                    // write length stream
                    var streamName = GetPropertyStreamName(property.PropTag); //string.Format("__substg1.0_{0:X8}", GetPropertyTag(property.PropTag));
                    IStream propStream = null;
                    try
                    {
                        propStream = CompoundFileUtil.Instance.GetChildStream(streamName, true, storage);

                        if (property.PropTag.PropertyTag == (int)PropertyType.PT_MV_BINARY)
                        {
                            foreach (var item in (MvVarSizeValue)property.PropValue)
                            {
                                MvVarSizeItem mvItem = item as MvVarSizeItem;

                                propStream.Write(mvItem.GetValueLength());
                                propStream.WriteZero(4);
                            }
                        }
                        else if (property.PropTag.PropertyTag == (int)PropertyType.PT_MV_STRING8 || ((property.PropTag.PropertyTag & 0x9000) == 0x9000))
                        {
                            foreach (var item in (MvVarSizeValue)property.PropValue)
                            {
                                MvVarSizeItem mvItem = item as MvVarSizeItem;
                                propStream.Write(mvItem.GetValueLength());
                            }
                        }
                        else
                            throw new ArgumentException("Mv propertyTag is wrong.");

                        propStream.Commit(0);
                    }
                    finally
                    {
                        CompoundFileUtil.Instance.ReleaseComObj(propStream);
                    }

                    // write value stream
                    int itemIndex = 0;
                    foreach (var item in (MvVarSizeValue)property.PropValue)
                    {
                        MvVarSizeItem mvItem = item as MvVarSizeItem;
                        string valueStreamName = GetMvVarPropertyStreamName(property.PropTag, itemIndex); // string.Format("__substg1.0_{0:X8}-{1:X8}", GetPropertyTag(property.PropTag), itemIndex);
                        IStream valueStream = null;
                        try
                        {
                            valueStream = CompoundFileUtil.Instance.GetChildStream(valueStreamName, true, Storage);
                            valueStream.Write(mvItem.GetValueBytes());
                            valueStream.Commit(0);
                        }
                        finally
                        {
                            CompoundFileUtil.Instance.ReleaseComObj(valueStream);
                        }
                        itemIndex++;
                    }
                }
                else
                {
                    var streamName = GetPropertyStreamName(property.PropTag); // string.Format("__substg1.0_{0:X8}", property.PropTag.PropertyTag);
                    IStream propStream = null;
                    try
                    {
                        propStream = CompoundFileUtil.Instance.GetChildStream(streamName, true, storage);
                        propStream.Write(((MvFixedSizeValue)property.PropValue).GetItemValueByte());
                        propStream.Commit(0);
                    }
                    finally
                    {
                        CompoundFileUtil.Instance.ReleaseComObj(propStream);
                    }
                }
            }
        }
예제 #15
0
 private void ModifyPropertyTag(IPropValue property, uint changedId)
 {
     property.PropTag = new PropertyTag((uint)changedId);
 }
예제 #16
0
        protected virtual void WritePropertyInfoToPropertyStream(IStream propertyStream, IPropValue property)
        {
            if ((property is FixPropValue && !PropertyTag.IsGuidType(property.PropTag)) || (property is SpecialFixProperty))
            {
                // 1.2.1 Set fixed data
                // 1.2.1.1 Set Tag
                propertyStream.Write(property.PropTag.Bytes);
                // 1.2.1.2 Set Flag
                propertyStream.Write((Int32)0x06);
                // 1.2.1.3 Set Value
                var value = ModifyPropertyValue(property);
                propertyStream.Write(value);
                propertyStream.WriteZero(8 - value.Length);
            }
            else if((property is SpecialFixProperty) && property.PropTag.PropertyType == (short)PropertyType.PT_OBJECT)
            {
                // 1.2.1 Set fixed data
                // 1.2.1.1 Set Tag
                propertyStream.Write(property.PropTag.Bytes);
                // 1.2.1.2 Set Flag
                propertyStream.Write((Int32)0x06);
                // 1.2.1.3 Set Value
                var value = ModifyPropertyValue(property);
                propertyStream.Write(value);
                propertyStream.WriteZero(8 - value.Length);
            }
            else if (property is VarPropValue || PropertyTag.IsGuidType(property.PropTag) || property is SpecialVarBaseProperty)
            {
                // 1.2.2 Set variable data
                // 1.2.2.1 Set Tag
                var tag = GetPropertyTag(property.PropTag);
                propertyStream.Write(tag);
                // 1.2.2.2 Set Flag
                propertyStream.Write((Int32)0x06);
                // 1.2.2.3 Set Size
                var valueSize = ModifyPropertyLength(property);
                //var valueSize = property.PropValue.BytesCountForMsg;
                //if (property.PropValue is VarStringValue)
                //{

                //    if (valueSize == 0)
                //        propertyStream.Write((Int32)2);
                //    else
                //        propertyStream.Write(valueSize);
                //}
                //else
                //{
                propertyStream.Write(valueSize);
                //}
                // 1.2.2.4 Set Reserve , todo if contain embed message, it must set 0x01, if OLE, set 0x04;
                propertyStream.WriteZero(4);
            }
            else if (property is MvPropValue)
            {
                // 1.2.3 Set variable data
                // 1.2.3.1 Set Tag
                var tag = GetPropertyTag(property.PropTag);
                propertyStream.Write(tag);
                // 1.2.3.2 Set Flag
                propertyStream.Write((Int32)0x06);
                // 1.2.3.3 Set Size, todo must check the length is all value's bytes total length;
                if (PropertyTag.IsMultiVarType((ushort)property.PropTag.PropertyType))
                {
                    propertyStream.Write((Int32)(((ISizeValue)property.PropValue).ItemCount) * 4);
                }
                else
                {
                    propertyStream.Write((Int32)(((ISizeValue)property.PropValue).ItemCount) * PropertyTag.GetFixPropertyTypeLength((ushort)property.PropTag.PropertyType));
                }
                // 1.2.3.4 Set Reserve , todo if contain embed message, it must set 0x01, if OLE, set 0x04;
                propertyStream.WriteZero(4);
            }
        }
예제 #17
0
 protected virtual byte[] ModifyPropertyValue(IPropValue property)
 {
     return property.PropValue.BytesForMsg;
 }
예제 #18
0
 protected virtual int ModifyPropertyLength(IPropValue property)
 {
     return property.PropValue.BytesCountForMsg;
 }