Example #1
0
        public void SendData(ISerializable serializedData)
        {
            Debug.WriteLine("Send Data:" + serializedData.Serialize());
            if (socket != null)
            {
                try {
                    lock (lockObject) {
                        {
                            if (dataWriter == null)
                            {
                                dataWriter = new DataWriter(socket.OutputStream);
                            }

                            // Serialize the Data
                            byte[] dataToSend = serializedData.Serialize();

                            // Send it out
                            dataWriter.WriteInt32(dataToSend.Length);
                            dataWriter.StoreAsync();

                            dataWriter.WriteBytes(dataToSend);
                            dataWriter.StoreAsync();
                        }
                    }
                }
                catch (Exception ex) {
                    Debug.WriteLine("SendMessage: " + ex.Message);
                }
            }
        }
        public static async Task <bool> SaveToStorage(string fileName, ISerializable content)
        {
            if (Consts.isApplicationClosing)
            {
                return(false);
            }

            isSavingComplete = false;

            try {
                Debug.WriteLine("SaveToStorage(): Saving to Storage");
                byte[] data = content.Serialize();

                StorageFolder folder = ApplicationData.Current.LocalFolder;
                StorageFile   file   = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                using (Stream s = await file.OpenStreamForWriteAsync()) {
                    await s.WriteAsync(data, 0, data.Length);
                }
                Debug.WriteLine("Storage Saved: " + fileName);

                isSavingComplete = true;
                return(true);
            }
            catch (Exception) { isSavingComplete = true; return(false); }
        }
Example #3
0
        protected virtual Boolean ImplSerializeObject <RetvalType, ContextType> (
            out RetvalType retVal,
            ISerializable <RetvalType> serMgr,
            Action contextPrologDlg,
            Action contextEpilogDlg,
            Object objValue,
            ContextType context)
            where ContextType : ISerializationContext
        {
            retVal = default(RetvalType);

            if (objValue == null)
            {
                return(false);
            }
            if (serMgr == null)
            {
                return(false);
            }

            //ISerializable<RetvalType> serMgr = null;

            //if ( !objValue.GetSerializationManager ( ref serMgr, context ) )
            //    return false;

            contextPrologDlg?.Invoke();

            try { retVal = serMgr.Serialize(objValue, context); }
            finally { contextEpilogDlg?.Invoke(); }

            return(true);
        } // End of ImplSerializeObject<...> (...)
Example #4
0
 public Item(string name, float price, uint quantity, ISerializable commodity)
 {
     Name      = name;
     Price     = price;
     Quantity  = quantity;
     Commodity = commodity.Serialize();
 }
Example #5
0
        public void SerializeObject(string name, ISerializable serObject)
        {
            XElement subElem = new XElement(name);
            serObject.Serialize(new XmlSerializer(subElem));

            elem.Add(subElem);
        }
Example #6
0
        public bool SaveFile(IFileable f)
        {
            if (f == null)
            {
                return(false);
            }

            ISerializable iser = f as ISerializable;

            if (iser == null)
            {
                return(false);
            }

            object jobj = new JObject();

            if (iser.Serialize(ref jobj) == false)
            {
                return(false);
            }

            var setting = new JsonSerializerSettings();

            setting.Formatting            = Formatting.Indented;          // 들여쓰기, 줄내림(None : 용량 반으로 줄어듬)
            setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // 순환 참조 객체 무시
            string json = JsonConvert.SerializeObject(jobj, setting);

            File.WriteAllText(f.FileInfo.FullFileName, json);

            return(true);
        }
        internal void Serialize_Internal(MyStream stream, object target)
        {
            Type          targetType = target.GetType();
            ISerializable ser        = serializeMap[targetType];

            ser.Serialize(stream, target);
        }
Example #8
0
        public void SendUdp(Player player, EMsgSC type, ISerializable body, bool isNeedDebugSize = false)
        {
            var writer = new Serializer();

            body.Serialize(writer);
            player?.SendUdp(type, writer.CopyData());
        }
        public void Serialize(ISerializable serializable, Stream output)
        {
            var bw = new BinaryWriter(output);

            serializable.Serialize(new BinaryTypeWriter(bw));
            bw.Flush();
        }
Example #10
0
 public static void SaveToFile(this ISerializable obj, string filePath, bool wrapfile)
 {
     using (BinaryWriter writer = new BinaryWriter(OpenFileWrap(filePath, FileMode.Create, wrapfile)))
     {
         obj.Serialize(writer);
     }
 }
        virtual public void Serialize(Stream stream, Encoding encoding)
        {
            foreach (DictionaryEntry de in m_object.Properties)
            {
                Property      p          = (Property)de.Value;
                ISerializable serializer = SerializerFactory.Create(p);
                if (serializer != null)
                {
                    serializer.Serialize(stream, encoding);
                }
            }

            foreach (DictionaryEntry de in m_object.Parameters)
            {
                Parameter     p          = (Parameter)de.Value;
                ISerializable serializer = SerializerFactory.Create(p);
                if (serializer != null)
                {
                    serializer.Serialize(stream, encoding);
                }
            }

            foreach (DDay.iCal.Objects.iCalObject obj in m_object.Children)
            {
                ISerializable serializer = SerializerFactory.Create(obj);
                if (serializer != null)
                {
                    serializer.Serialize(stream, encoding);
                }
            }
        }
Example #12
0
        public void SendUdp(EMsgSC msgId, ISerializable body)
        {
            Serializer serializer = new Serializer();

            body.Serialize(serializer);
            _netUdp?.SendMessage(msgId, serializer.CopyData());
        }
Example #13
0
        public bool SaveFile(IFileable f)
        {
            if (f == null)
            {
                return(false);
            }

            ISerializable iser = f as ISerializable;

            if (iser == null)
            {
                return(false);
            }

            FileStream fs     = new FileStream(f.FileInfo.FullFileName, FileMode.Create, FileAccess.Write);
            object     writer = new BinaryWriter(fs);

            bool success = iser.Serialize(ref writer);

            BinaryWriter bw = writer as BinaryWriter;

            bw.Close();
            fs.Close();

            return(success);
        }
        protected object transmitPacket(ISerializable request, IDeserializable reply = null)
        {
            MemoryStream stream = new MemoryStream();

            request.Serialize(stream);
            byte[] rawRequest = stream.ToArray();

            if (reply == null)
            {
                DebugWrite("transmit:        ", request);
                spiWrite(rawRequest);
                return(null);
            }
            else
            {
                byte[] rawReply = spiReadWrite(rawRequest);
                stream = new MemoryStream(rawReply);
                reply.Deserialize(stream);

                DebugWrite("received:        ", reply);

                if (!((IValidate)reply).IsValid)
                {
                    throw new CheckSumException();
                }

                return(reply);
            }
        }
Example #15
0
    private byte[] Serialize(ISerializable packet, uint objectId, bool reliable, uint packetId)
    {
        PacketHeader header = new PacketHeader();
        MemoryStream stream = new MemoryStream();

        header.id         = packetId;
        header.objectId   = objectId;
        header.senderId   = ConnectionManager.instance.ClientId;
        header.packetType = packet.packetType;
        header.reliable   = reliable;

        header.Serialize(stream);
        packet.Serialize(stream);

        stream.Close();


        PacketSecurity security     = new PacketSecurity();
        Crc32          crc          = new Crc32();
        MemoryStream   packetStream = new MemoryStream();

        byte[] hash = crc.ComputeHash(stream.ToArray());

        security.data = stream.ToArray();
        security.hash = hash;

        security.Serialize(packetStream);

        packetStream.Close();


        return(packetStream.ToArray());
    }
Example #16
0
        public void SendUdp(EMsgSC msgId, ISerializable body)
        {
            var writer = new Serializer();

            writer.PutInt16((short)msgId);
            body?.Serialize(writer);
            _netUdp?.SendMessage(EMsgSC.C2G_UdpMessage, writer.CopyData(), EDeliveryMethod.Unreliable);
        }
Example #17
0
 /// <summary>
 /// Writes a given block to stream.
 /// </summary>
 /// <param name="blocktype">type of given block</param>
 /// <param name="block">block, to write</param>
 public void Write(BlockType blocktype, ISerializable block)
 {
     stream.WriteByte((byte)blocktype);
     if (block != null)
     {
         block.Serialize(this);
     }
 }
Example #18
0
 private void WriteSerializable(ISerializable sData)
 {
     if (sData == null)
     {
         throw new ArgumentNullException(nameof(sData));
     }
     sData.Serialize(this);
 }
Example #19
0
        public Serializer Write(ISerializable v)
        {
            A("o{");
            v.Serialize(this);
            A("};");

            return(this);
        }
Example #20
0
    public void Write(ISerializable obj)
    {
        DataBuffer buffer = new DataBuffer();

        obj.Serialize(buffer);

        Write(buffer.StringFromBytes);
    }
Example #21
0
 public static void Write(this IWriteableBuffer w, ISerializable v)
 {
     w.Write(v != null ? true : false);
     if (v != null)
     {
         v.Serialize(w);
     }
 }
Example #22
0
        ///
        /// <param name="name"></param>
        /// <param name="v"></param>
        public override ISerializable Inout <T>(string name, ISerializable v)
        {
            string        types  = readBuf.ReadString(); // Skip string for non virtual objects, type is known by T
            ISerializable newSer = (ISerializable) new T();

            newSer.Serialize(this);
            return(newSer);
        }
Example #23
0
 /// <summary>
 /// Converts an <see cref="ISerializable"/> object to a byte array.
 /// </summary>
 /// <param name="value">The <see cref="ISerializable"/> object to be converted.</param>
 /// <returns>The converted byte array.</returns>
 public static byte[] ToArray(this ISerializable value)
 {
     using MemoryStream ms     = new();
     using BinaryWriter writer = new(ms, Utility.StrictUTF8, true);
     value.Serialize(writer);
     writer.Flush();
     return(ms.ToArray());
 }
        public void SendMsgLobby(EMsgCL msgId, ISerializable body)
        {
            var writer = new Serializer();

            writer.PutByte((byte)msgId);
            body.Serialize(writer);
            _netProxyLobby.Send(Compressor.Compress(writer));
        }
Example #25
0
 public byte[] Serialize(ISerializable serializable)
 {
     using (var stream = new MemoryStream())
     {
         var writer = new BinaryWriter(stream);
         serializable.Serialize(writer, new Dictionary <object, int>(), 0);
         return(stream.ToArray());
     }
 }
        public void SendMsgRoom(EMsgCS msgId, ISerializable body)
        {
            var writer = new Serializer();

            writer.Put(_playerID);
            writer.Put((byte)msgId);
            body.Serialize(writer);
            _netProxyRoom.Send(Compressor.Compress(writer));
        }
Example #27
0
        public void TestSerialize()
        {
            MemoryStream  stream       = new MemoryStream();
            ECPoint       point        = new ECPoint(null, null, ECCurve.Secp256k1);
            ISerializable serializable = point;

            serializable.Serialize(new BinaryWriter(stream));
            stream.ToArray().Should().BeEquivalentTo(new byte[] { 0 });
        }
Example #28
0
        /// <summary>
        /// Write an object value.
        /// </summary>
        /// <param name="name">Name of member.</param>
        /// <param name="value">Value of member.</param>
        /// <param name="nullable">If this member can be null.</param>
        public void Write(string name, ISerializable value, bool nullable)
        {
            this.WriteNullableFlag(value, nullable);

            if (value != null)
            {
                value.Serialize(this);
            }
        }
Example #29
0
 public KeyBuilder Add(ISerializable key)
 {
     using (BinaryWriter writer = new BinaryWriter(stream, Utility.StrictUTF8, true))
     {
         key.Serialize(writer);
         writer.Flush();
     }
     return(this);
 }
Example #30
0
        public static bool TrySerialize(this ISerializable value, out float[] serialized)
        {
            serialized = new float[value.SerializedSize];
            var position = 0;
            var success  = true;

            success &= value.Serialize(ref serialized, ref position);
            return(success);
        }
        /// <summary>
        ///  Serializes an object to a new <see cref="MemoryStream"/> using the class specified by <typeparamref name="TFormatter"/>.
        /// </summary>
        /// <typeparam name="TFormatter">The <see cref="Type"/> used to serialize the <paramref name="instance"/>.</typeparam>
        /// <param name="instance">The instance to serialize.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"> thrown if the <paramref name="instance"/> or <paramref name="stream"/> is <c>Null</c>.</exception>
        /// <exception cref="ArgumentException"> thrown if the <typeparamref name="TFormatter"/> is not a valid Serialization formatter <see cref="Type"/>.</exception>
        public static MemoryStream Serialize <TFormatter>(this ISerializable instance)
            where TFormatter : class, new()
        {
            MemoryStream stream = new MemoryStream();

            instance.Serialize <TFormatter>(stream);

            return(stream);
        }
        /// <summary>
        /// Identify whether the Rop request contains more than one server object handle. Refers to [MS-OXCROPS] for more details.
        /// </summary>
        /// <param name="ropRequest">ROP request objects.</param>
        /// <returns>Return true if the Rop request contains more than one server object handle, otherwise return false.</returns>
        public static bool IsOutputHandleInRopRequest(ISerializable ropRequest)
        {
            byte ropId = (byte)BitConverter.ToInt16(ropRequest.Serialize(), 0);

            switch (ropId)
            {
                case 0x01: // RopRelease ROP
                case 0x07: // RopGetPropertiesSpecific ROP
                case 0x08: // RopGetPropertiesAll ROP
                case 0x09: // RopGetPropertiesList ROP
                case 0x0A: // RopSetProperties ROP
                case 0x0B: // RopDeleteProperties ROP
                case 0x0D: // RopRemoveAllRecipients ROP
                case 0x0E: // RopModifyRecipients ROP
                case 0x0F: // RopReadRecipients ROP
                case 0x10: // RopReloadCachedInformation ROP
                case 0x12: // RopSetColumns ROP
                case 0x13: // RopSortTable ROP
                case 0x14: // RopRestrict ROP
                case 0x15: // RopQueryRows ROP
                case 0x16: // RopGetStatus ROP
                case 0x17: // RopQueryPosition ROP
                case 0x18: // RopSeekRow ROP
                case 0x19: // RopSeekRowBookmark ROP
                case 0x1A: // RopSeekRowFractional ROP
                case 0x1B: // RopCreateBookmark ROP
                case 0x1D: // RopDeleteFolder ROP
                case 0x1E: // RopDeleteMessages ROP
                case 0x1F: // RopGetMessageStatus ROP
                case 0x20: // RopSetMessageStatus ROP
                case 0x24: // RopDeleteAttachment ROP
                case 0x26: // RopSetReceiveFolder ROP
                case 0x27: // RopGetReceiveFolder ROP
                case 0x2A: // RopNotify ROP
                case 0x2C: // RopReadStream ROP
                case 0x2D: // RopWriteStream ROP
                case 0x2E: // RopSeekStream ROP
                case 0x2F: // RopSetStreamSize ROP
                case 0x30: // RopSetSearchCriteria ROP
                case 0x31: // RopGetSearchCriteria ROP
                case 0x32: // RopSubmitMessage ROP
                case 0x34: // RopAbortSubmit ROP
                case 0x37: // RopQueryColumnsAll ROP
                case 0x38: // RopAbort ROP
                case 0x40: // RopModifyPermissions ROP
                case 0x41: // RopModifyRules ROP
                case 0x42: // RopGetOwningServers ROP
                case 0x43: // RopLongTermIdFromId ROP
                case 0x44: // RopIdFromLongTermId ROP
                case 0x45: // RopPublicFolderIsGhosted ROP
                case 0x47: // RopSetSpooler ROP
                case 0x48: // RopSpoolerLockMessage ROP
                case 0x49: // RopGetAddressTypes ROP
                case 0x4A: // RopTransportSend ROP
                case 0x4E: // RopFastTransferSourceGetBuffer ROP
                case 0x4F: // RopFindRow ROP
                case 0x50: // RopProgress ROP
                case 0x51: // RopTransportNewMail ROP
                case 0x52: // RopGetValidAttachments ROP
                case 0x54: // RopFastTransferDestinationPutBuffer ROP
                case 0x55: // RopGetNamesFromPropertyIds ROP
                case 0x56: // RopGetPropertyIdsFromNames ROP
                case 0x57: // RopUpdateDeferredActionMessages ROP
                case 0x58: // RopEmptyFolder ROP
                case 0x59: // RopExpandRow ROP
                case 0x5A: // RopCollapseRow ROP
                case 0x5B: // RopLockRegionStream ROP
                case 0x5C: // RopUnlockRegionStream ROP
                case 0x5D: // RopCommitStream ROP
                case 0x5E: // RopGetStreamSize ROP
                case 0x5F: // RopQueryNamedProperties ROP
                case 0x60: // RopGetPerUserLongTermIds ROP
                case 0x61: // RopGetPerUserGuid ROP
                case 0x63: // RopReadPerUserInformation ROP
                case 0x64: // RopWritePerUserInformation ROP
                case 0x66: // RopSetReadFlags ROP
                case 0x68: // RopGetReceiveFolderTable ROP
                case 0x6B: // RopGetCollapseState ROP
                case 0x6C: // RopSetCollapseState ROP
                case 0x6D: // RopGetTransportFolder ROP
                case 0x6E: // RopPending ROP
                case 0x6F: // RopOptionsData ROP
                case 0x73: // RopSynchronizationImportHierarchyChange ROP
                case 0x74: // RopSynchronizationImportDeletes ROP
                case 0x75: // RopSynchronizationUploadStateStreamBegin ROP
                case 0x76: // RopSynchronizationUploadStateStreamContinue ROP
                case 0x77: // RopSynchronizationUploadStateStreamEnd ROP
                case 0x78: // RopSynchronizationImportMessageMove ROP
                case 0x79: // RopSetPropertiesNoReplicate ROP
                case 0x7A: // RopDeletePropertiesNoReplicate ROP
                case 0x7B: // RopGetStoreState ROP
                case 0x7F: // RopGetLocalReplicaIds ROP
                case 0x80: // RopSynchronizationImportReadStateChanges ROP
                case 0x81: // RopResetTable ROP
                case 0x86: // RopTellVersion ROP
                case 0x89: // RopFreeBookmark ROP
                case 0x90: // RopWriteAndCommitStream ROP
                case 0x91: // RopHardDeleteMessages ROP
                case 0x92: // RopHardDeleteMessagesAndSubfolders ROP
                case 0x93: // RopSetLocalReplicaMidsetDeleted ROP
                case 0xF9: // RopBackoff ROP
                case 0xFE: // RopLogon ROP
                    return false;
                
                case 0x02: // RopOpenFolder ROP
                case 0x03: // RopOpenMessage ROP
                case 0x04: // RopGetHierarchyTable ROP
                case 0x05: // RopGetContentsTable ROP
                case 0x06: // RopCreateMessage ROP
                case 0x0C: // RopSaveChangesMessage ROP
                case 0x11: // RopSetMessageReadFlag ROP
                case 0x1C: // RopCreateFolder ROP
                case 0x21: // RopGetAttachmentTable ROP
                case 0x22: // RopOpenAttachment ROP
                case 0x23: // RopCreateAttachment ROP
                case 0x25: // RopSaveChangesAttachment ROP
                case 0x29: // RopRegisterNotification ROP
                case 0x2B: // RopOpenStream ROP
                case 0x33: // RopMoveCopyMessages ROP
                case 0x35: // RopMoveFolder ROP
                case 0x36: // RopCopyFolder ROP
                case 0x39: // RopCopyTo ROP
                case 0x3A: // RopCopyToStream ROP
                case 0x3B: // RopCloneStream ROP
                case 0x3E: // RopGetPermissionsTable ROP
                case 0x3F: // RopGetRulesTable ROP
                case 0x46: // RopOpenEmbeddedMessage ROP
                case 0x4B: // RopFastTransferSourceCopyMessages ROP
                case 0x4C: // RopFastTransferSourceCopyFolder ROP
                case 0x4D: // RopFastTransferSourceCopyTo ROP
                case 0x53: // RopFastTransferDestinationConfigure ROP
                case 0x67: // RopCopyProperties ROP
                case 0x69: // RopFastTransferSourceCopyProperties ROP
                case 0x70: // RopSynchronizationConfigure ROP
                case 0x72: // RopSynchronizationImportMessageChange ROP
                case 0x7E: // RopSynchronizationOpenCollector ROP
                case 0x82: // RopSynchronizationGetTransferState ROP
                    return true;

                default:
                    return true;
            }
        }
        /// <summary>
        /// Send ROP request with single operation.
        /// </summary>
        /// <param name="ropRequest">ROP request objects.</param>
        /// <param name="insideObjHandle">Server object handle in request.</param>
        /// <param name="response">ROP response objects.</param>
        /// <param name="rawData">The ROP response payload.</param>
        /// <param name="getPropertiesFlag">The flag indicate the test cases expect to get which object type's properties(message's properties or attachment's properties).</param>
        /// <param name="returnValue">An unsigned integer value indicates the return value of call EcDoRpcExt2 method.</param>
        /// <returns>Server objects handles in response.</returns>
        public List<List<uint>> DoRopCall(ISerializable ropRequest, uint insideObjHandle, ref object response, ref byte[] rawData, GetPropertiesFlags getPropertiesFlag, out uint returnValue)
        {
            List<ISerializable> requestRops = new List<ISerializable>
            {
                ropRequest
            };

            List<uint> requestSOH = new List<uint>
            {
                insideObjHandle
            };

            if (Common.IsOutputHandleInRopRequest(ropRequest))
            {
                // Add an element for server output object handle, set default value to 0xFFFFFFFF
                requestSOH.Add(DefaultOutputHandle);
            }
            
            List<IDeserializable> responseRops = new List<IDeserializable>();
            List<List<uint>> responseSOHs = new List<List<uint>>();

            // 0x10008 specifies the maximum size of the rgbOut buffer to place in Response.
            uint ret = this.oxcropsClient.RopCall(requestRops, requestSOH, ref responseRops, ref responseSOHs, ref rawData, 0x10008);
            returnValue = ret;
            if (ret == OxcRpcErrorCode.ECRpcFormat)
            {
                this.Site.Assert.Fail("Error RPC Format");
            }

            if (ret != 0)
            {
                return responseSOHs;
            }

            if (responseRops != null)
            {
                if (responseRops.Count > 0)
                {
                    response = responseRops[0];
                }
            }
            else
            {
                response = null;
            }

            if (ropRequest.GetType() == typeof(RopReleaseRequest))
            {
                return responseSOHs;
            }

            byte ropId = (byte)BitConverter.ToInt16(ropRequest.Serialize(), 0);

            List<PropertyObj> pts = null;
            switch (ropId)
            {
                case (byte)RopId.RopOpenMessage:
                    RopOpenMessageResponse openMessageResponse = (RopOpenMessageResponse)response;

                    // This check is for the open specification expectation for a particular request with some valid input parameters.
                    if (openMessageResponse.ReturnValue == 0x00000000)
                    {
                        this.VerifyRopOpenMessageResponse(openMessageResponse);
                    }

                    break;

                case (byte)RopId.RopGetPropertiesSpecific:
                    // RopGetPropertiesSpecificRequest
                    pts = PropertyHelper.GetPropertyObjFromBuffer(((RopGetPropertiesSpecificRequest)ropRequest).PropertyTags, (RopGetPropertiesSpecificResponse)response);

                    foreach (PropertyObj pitem in pts)
                    {
                        // Verify capture code for MS-OXCMSG. 
                        this.VerifyMessageSyntaxDataType(pitem);
                    }

                    PropertyObj propertyObjPidTagSubjectPrefix = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagSubjectPrefix);
                    PropertyObj propertyObjPidTagNormalizedSubject = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagNormalizedSubject);

                    // Verify the message of PidTagSubjectPrefixAndPidTagNormalizedSubject
                    if (PropertyHelper.IsPropertyValid(propertyObjPidTagSubjectPrefix) || PropertyHelper.IsPropertyValid(propertyObjPidTagNormalizedSubject))
                    {
                        this.VerifyMessageSyntaxPidTagSubjectPrefixAndPidTagNormalizedSubject(propertyObjPidTagSubjectPrefix, propertyObjPidTagNormalizedSubject);
                    }

                    // Verify the requirements of PidTagAttachmentLinkId and PidTagAttachmentFlags.
                    PropertyObj pidTagAttachmentLinkId = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagAttachmentLinkId);
                    if (PropertyHelper.IsPropertyValid(pidTagAttachmentLinkId))
                    {
                        this.VerifyMessageSyntaxPidTagAttachmentLinkIdAndPidTagAttachmentFlags(pidTagAttachmentLinkId);
                    }

                    PropertyObj pidTagAttachmentFlags = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagAttachmentFlags);
                    if (PropertyHelper.IsPropertyValid(pidTagAttachmentFlags))
                    {
                        this.VerifyMessageSyntaxPidTagAttachmentLinkIdAndPidTagAttachmentFlags(pidTagAttachmentFlags);
                    }

                    // Verify the requirements of PidTagDisplayName
                    PropertyObj pidTagDisplayName = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagDisplayName);
                    PropertyObj pidTagAttachLongFilename = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagAttachLongFilename);

                    if (PropertyHelper.IsPropertyValid(pidTagDisplayName) && PropertyHelper.IsPropertyValid(pidTagAttachLongFilename))
                    {
                        this.VerifyMessageSyntaxPidTagDisplayName(pidTagDisplayName, pidTagAttachLongFilename);
                    }

                    PropertyObj pidTagObjectType = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagObjectType);
                    PropertyObj pidTagRecordKey = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagRecordKey);

                    this.VerifyPidTagObjectTypeAndPidTagRecordKey(pidTagObjectType, pidTagRecordKey);
                    break;

                case (byte)RopId.RopGetPropertiesAll:
                    RopGetPropertiesAllResponse getPropertiesAllResponse = (RopGetPropertiesAllResponse)response;
                    pts = PropertyHelper.GetPropertyObjFromBuffer(getPropertiesAllResponse);

                    foreach (PropertyObj pitem in pts)
                    {
                        // Verify capture code for MS-OXCMSG. 
                        this.VerifyMessageSyntaxDataType(pitem);
                    }

                    // Verify the requirements of PidTagArchiveDate
                    PropertyObj pidTagArchiveDateObj = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagArchiveDate);
                    PropertyObj pidTagStartDateEtc = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagStartDateEtc);

                    if (PropertyHelper.IsPropertyValid(pidTagArchiveDateObj))
                    {
                        if (PropertyHelper.IsPropertyValid(pidTagStartDateEtc))
                        {
                            byte[] byteDest = new byte[8];
                            Array.Copy((byte[])pidTagStartDateEtc.Value, 6, byteDest, 0, 8);
                            this.VerifyMessageSyntaxPidTagArchiveDate(pidTagArchiveDateObj, DateTime.FromFileTimeUtc(BitConverter.ToInt64(byteDest, 0)));
                        }
                    }

                    PropertyObj pidTagAccessLevel = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagAccessLevel);
                    pidTagRecordKey = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagRecordKey);

                    if (getPropertiesFlag == GetPropertiesFlags.MessageProperties)
                    {
                        PropertyObj pidTagAccess = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagAccess);

                        PropertyObj pidTagChangeKey = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagChangeKey);
                        PropertyObj pidTagCreationTime = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagCreationTime);
                        PropertyObj pidTagLastModificationTime = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagLastModificationTime);
                        PropertyObj pidTagLastModifierName = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagLastModifierName);
                        PropertyObj pidTagSearchKey = PropertyHelper.GetPropertyByName(pts, PropertyNames.PidTagSearchKey);

                        // Verify properties PidTagAccess, PidTagAccessLevel, PidTagChangeKey, PidTagCreationTime, PidTagLastModificationTime, PidTagLastModifierName and PidTagSearchKey exist on all Message objects.
                        this.VerifyPropertiesExistOnAllMessageObject(pidTagAccess, pidTagAccessLevel, pidTagChangeKey, pidTagCreationTime, pidTagLastModificationTime, pidTagLastModifierName, pidTagSearchKey);
                    }

                    if (getPropertiesFlag == GetPropertiesFlags.AttachmentProperties)
                    {
                        // Verify properties PidTagAccessLevel and PidTagRecordKey exist on any Attachment object.
                        this.VerifyPropertiesExistOnAllAttachmentObject(pidTagAccessLevel, pidTagRecordKey);
                    }

                    break;

                case (byte)RopId.RopCreateMessage:
                    RopCreateMessageResponse createMessageResponse = (RopCreateMessageResponse)response;

                    // Adapter requirements related with RopCreateMessage will be verified if the response is a successful one.
                    if (createMessageResponse.ReturnValue == 0x00000000)
                    {
                        int hasMessageId = createMessageResponse.HasMessageId;
                        this.VerifyMessageSyntaxHasMessageId(hasMessageId);
                    }

                    break;

                case (byte)RopId.RopReadRecipients:
                    RopReadRecipientsResponse readRecipientsResponse = (RopReadRecipientsResponse)response;

                    // Adapter requirements related with RopReadRecipients will be verified if the response is a successful one.
                    if (readRecipientsResponse.ReturnValue == 0x00000000)
                    {
                        this.VerifyMessageSyntaxRowCount(readRecipientsResponse);
                    }

                    break;

                case (byte)RopId.RopSetMessageStatus:
                    RopSetMessageStatusResponse setMessageStatusResponse = (RopSetMessageStatusResponse)response;

                    // Adapter requirements related with RopSetMessageStatus will be verified if the response is a successful one.
                    if (setMessageStatusResponse.ReturnValue == 0x00000000)
                    {
                        this.VerifyMessageSyntaxMessageStatusFlags(setMessageStatusResponse);
                    }

                    break;

                case (byte)RopId.RopCreateAttachment:
                    RopCreateAttachmentResponse createAttachmentResponse = (RopCreateAttachmentResponse)response;

                    // Adapter requirements related with RopCreateAttachment will be verified if the response is a successful one.
                    if (createAttachmentResponse.ReturnValue == 0x00000000)
                    {
                        int id = (int)createAttachmentResponse.AttachmentID;
                        this.VerifyDataStructureRopCreateAttachmentResponse(createAttachmentResponse, id);
                    }

                    break;

                case (byte)RopId.RopOpenEmbeddedMessage:
                    RopOpenEmbeddedMessageResponse openEmbeddedMessageResponse = (RopOpenEmbeddedMessageResponse)response;

                    // Adapter requirements related with RopOpenEmbeddedMessage will be verified if the response is a successful one.
                    if (openEmbeddedMessageResponse.ReturnValue == 0x00000000)
                    {
                        ulong mid = openEmbeddedMessageResponse.MessageId;
                        this.VerifyDataStructureRopOpenEmbeddedMessageResponse(openEmbeddedMessageResponse, mid);
                    }

                    break;

                case (byte)RopId.RopSetMessageReadFlag:
                    RopSetMessageReadFlagResponse setMessageReadFlagResponse = (RopSetMessageReadFlagResponse)response;

                    // Adapter requirements related with RopSetMessageReadFlag will be verified if the response is a successful one.
                    if (setMessageReadFlagResponse.ReturnValue == 0x00000000)
                    {
                        this.VerifyMessageSyntaxReadStatusChanged(setMessageReadFlagResponse, (RopSetMessageReadFlagRequest)ropRequest);
                    }

                    break;

                case (byte)RopId.RopSetReadFlags:
                    // Adapter requirements related with RopSetReadFlags will be verified if the response is a successful one.
                    if (((RopSetReadFlagsResponse)response).ReturnValue == 0x00000000)
                    {
                        this.VerifyRopSetReadFlagsResponse((RopSetReadFlagsResponse)response);
                    }

                    break;

                case (byte)RopId.RopGetMessageStatus:
                    // Adapter requirements related with RopGetMessageStatus will be verified if the response is a successful one.
                    if (((RopSetMessageStatusResponse)response).ReturnValue == 0x00000000)
                    {
                        this.VerifyGetMessageStatusResponse((RopSetMessageStatusResponse)response);
                    }

                    break;

                default:
                    break;
            }

           this.VerifyMAPITransport();

            return responseSOHs;
        }
Example #34
0
 public void Write(ISerializable structure)
 {
     structure.Serialize(this);
 }
        /// <summary>
        /// Check whether the default invalid handle is needed.
        /// </summary>
        /// <param name="ropRequest">ROP request objects.</param>
        /// <param name="expectedRopResponseType">The expected ROP response type.</param>
        /// <returns>Return true if the default handle is needed in the request, otherwise return false.</returns>
        private bool IsInvalidInputHandleNeeded(ISerializable ropRequest, RopResponseType expectedRopResponseType)
        {
            if (!Common.IsOutputHandleInRopRequest(ropRequest) && expectedRopResponseType == RopResponseType.FailureResponse)
            {
                byte[] request = ropRequest.Serialize();

                // The default handle is also needed by some cases to verify the failure response caused by an invalid input handle.
                // The input handle index is the third byte and its value is 1 in this test suite for this situation.
                byte inputHandleIndex = request[2];
                if (inputHandleIndex == 1)
                {
                    return true;
                }
            }

            return false;
        }