Ejemplo n.º 1
0
        public void SerializeObject(string name, ISerializable serObject)
        {
            XElement subElem = new XElement(name);
            serObject.Serialize(new XmlSerializer(subElem));

            elem.Add(subElem);
        }
 public void LoguearObservaciones( string mensaje, ISerializable serializable )
 {
     if ( !string.IsNullOrEmpty( mensaje ) )
     {
         this.Loguear( serializable.Serializar() + "\r\n" + mensaje );
     }
 }
Ejemplo n.º 3
0
 public static void SerializeObject(String filename, ISerializable objectToSerialize)
 {
     Stream stream = File.Open(filename, FileMode.Create);
     var bFormatter = new BinaryFormatter();
     bFormatter.Serialize(stream, objectToSerialize);
     stream.Close();
 }
Ejemplo n.º 4
0
		protected byte[] Serialize(ISerializable obj)
		{
			MemoryStream memoryStream = new MemoryStream();
			this.binaryFormatter.Serialize(memoryStream, obj);
			byte[] array = new byte[memoryStream.Length];
			Array.Copy(memoryStream.GetBuffer(), array, memoryStream.Length);
			return array;
		}
        public SNKeyPairDerived SNKeyPairDerivedClone(ISerializable inter)
        {
            SerializationInfo info = new SerializationInfo(typeof(StrongNameKeyPair), new FormatterConverter());
            StreamingContext context = new StreamingContext();

            inter.GetObjectData(info, context);

            return new SNKeyPairDerived(info, context);
        }
Ejemplo n.º 6
0
		protected void SendMessage(ISerializable request)
		{
			byte[] array = this.Serialize(request);
			LengthRecord obj = new LengthRecord(array.Length);
			byte[] array2 = this.Serialize(obj);
			D.Assert(array2.Length == 147);
			this.WriteBuffer(array2, array2.Length);
			this.WriteBuffer(array, array.Length);
		}
Ejemplo n.º 7
0
        public void QueueForIndex(ISerializable serializable, int size)
        {
            IndexInfo info;

            info.size = size;

            info.typeCode = serializable.TypeReference;	//For guilds, this will automagically be zero.
            info.serial = serializable.SerialIdentity;

            this._orderedIndexInfo.Add(info);
        }
Ejemplo n.º 8
0
		internal bool Server(object genericRequest, ref ISerializable reply)
		{
			if (genericRequest is OpenRequest)
			{
				OpenRequest openRequest = (OpenRequest)genericRequest;
				if (this.foxitViewer != null)
				{
					reply = new ExceptionMessageRecord("Already open");
					return true;
				}
				try
				{
					this.foxitViewer = new FoxitViewer(openRequest.filename, openRequest.pageNumber);
					reply = new RectangleFRecord(this.foxitViewer.GetPageSize());
					bool result = true;
					return result;
				}
				catch (Exception ex)
				{
					reply = new ExceptionMessageRecord(ex.Message);
					bool result = false;
					return result;
				}
			}
			if (genericRequest is RenderRequest)
			{
				RenderRequest renderRequest = (RenderRequest)genericRequest;
				if (this.foxitViewer == null)
				{
					reply = new ExceptionMessageRecord("Not open");
					return true;
				}
				try
				{
					reply = this.foxitViewer.RenderBytes(renderRequest.outputSize, renderRequest.topLeft, renderRequest.pageSize, renderRequest.transparentBackground);
					bool result = true;
					return result;
				}
				catch (Exception ex2)
				{
					reply = new ExceptionMessageRecord(ex2.Message);
					bool result = true;
					return result;
				}
			}
			if (genericRequest is QuitRequest)
			{
				reply = new AckRecord();
				return false;
			}
			reply = new ExceptionMessageRecord("Unrecognized request type " + genericRequest.GetType().ToString());
			return true;
		}
        private void TestWrite(ISerializable serializable, Action<BinaryReader> check)
        {
            using (var ms = new MemoryStream())
            using (var writer = new BinaryWriter(ms))
            {
                var serializer = new BinaryWriteSerializer();
                serializer.Serialize(serializable, writer);

                ms.Seek(0, SeekOrigin.Begin);

                using (var reader = new BinaryReader(ms))
                {
                    check(reader);
                }
            }
        }
 public SurrogateForISerializable(ISerializable serializable)
 {
     var serializationInfo = new SerializationInfo(serializable.GetType(), new FormatterConverter());
     var streamingContext = new StreamingContext(StreamingContextStates.Clone);
     serializable.GetObjectData(serializationInfo, streamingContext);
     keys = new string[serializationInfo.MemberCount];
     values = new object[serializationInfo.MemberCount];
     var i = 0;
     foreach(var entry in serializationInfo)
     {
         keys[i] = entry.Name;
         values[i] = entry.Value;
         i++;
     }
     assemblyQualifiedName = serializable.GetType().AssemblyQualifiedName;
 }
Ejemplo n.º 11
0
                private void serializeFromISerializable(ISerializable data)
                {
                    m_CustomData = new Dictionary<string,CustomTypedEntry>();

                    var info = new SerializationInfo(data.GetType(), new FormatterConverter());
                    StreamingContext streamingContext = new StreamingContext(StreamingContextStates.Persistence);
                    data.GetObjectData(info, streamingContext);

                    var senum = info.GetEnumerator();
                    while(senum.MoveNext())
                    {
                        var value = new CustomTypedEntry();
                        value.TypeIndex = MetaType.GetExistingOrNewMetaTypeIndex( m_Document, senum.ObjectType );
                        value.Data = m_Document.NativeDataToPortableData( senum.Value );
                        m_CustomData[senum.Name] = value;
                    }
                    
                }
 public void LoguearObservaciones( List<CAEDetalleRespuesta> caeDetResp, ISerializable serializable )
 {
     string mensaje = "";
     foreach ( CAEDetalleRespuesta detalle in caeDetResp )
     {
         if ( detalle.Observaciones != null )
         {
             foreach ( Observacion observacion in detalle.Observaciones )
             {
                 mensaje = mensaje + "\r\n" +
                             observacion.Mensaje + " (" + observacion.Codigo + ")";
             }
         }
     }
     if ( !mensaje.Equals( "" ) )
     {
         this.Loguear( serializable.Serializar() + "\r\n" + mensaje );
     }
 }
Ejemplo n.º 13
0
		public object RobustRPC(ISerializable request)
		{
			object result;
			try
			{
				this.Establish();
				result = this.namedPipeServer.RPC(request);
			}
			catch (Exception)
			{
				this.Teardown();
				this.Establish();
				result = this.namedPipeServer.RPC(request);
			}
			this.namedPipeServer.childProcess.Refresh();
			if (this.namedPipeServer.childProcess.VirtualMemorySize64 > 1073741824L || this.namedPipeServer.childProcess.HandleCount > 512)
			{
				this.Teardown();
			}
			return result;
		}
Ejemplo n.º 14
0
        public static bool SaveISerializeAbleObjectToFile(String _File, ISerializable _ISerializableObject)
        {
            String var_Path = _File.Remove(_File.LastIndexOf("/"));

            if (CreatePath(var_Path))
            {
                try
                {
                    Utility.Serializer.SerializeObject(_File, _ISerializableObject);
                    return true;
                }
                catch
                {
                    // Error!
                }
            }
            else
            {
                // Error!
            }
            return false;
        }
Ejemplo n.º 15
0
        public void Start()
        {
            try
            {
                using (FileStream fs = File.OpenRead("option.ini"))
                {
                    byte[] array = new byte[fs.Length];
                    fs.Read(array, 0, array.Length);
                    type = System.Text.Encoding.Default.GetString(array).ToUpper();
                    switch (type)
                    {
                        case "XML":
                            ser = new XmlSerialization();
                            break;
                        case "BIN":
                              ser = new BinarySerialization();
                              break;
                        default:
                            ser = new BinarySerialization();
                              break;

                    }
                   LoadDatabase(ser);
                }
            }
            catch (FileNotFoundException ex)
            {
                type = "BIN";
                using (FileStream fs = new FileStream("option.ini", FileMode.Create))
                {
                    byte[] array = System.Text.Encoding.Default.GetBytes(type);
                    fs.Write(array, 0, array.Length);
                }
                ser = new BinarySerialization();
                LoadDatabase(ser);
            }
        }
Ejemplo n.º 16
0
 private async Task<bool> SendMessageAsync(string command, ISerializable payload = null)
 {
     return await SendMessageAsync(Message.Create(command, payload));
 }
        // TODO: Implement
        /*

        private SIF_Request createSIF_Request( ElementDef objectType, String refId, Zone zone )
        {
           SIF_Request request = new SIF_Request();
           request.getHeader().setSIF_MsgId( MSG_GUID );
           request.getHeader().setSIF_SourceId( "foo" );
           request.setSIF_MaxBufferSize("32768");
           request.setSIF_Version( ADK.getSIFVersion().toString() );
           Query query = new Query(objectType);
           query.addCondition(SifDtd.SIF_REPORTOBJECT_REFID, Condition.EQ, refId);

           SIF_Query q = SIFPrimitives.createSIF_Query(query, zone);
           SIF_QueryObject sqo = new SIF_QueryObject();
           sqo.setObjectName( objectType.name() );

           q.setSIF_QueryObject(sqo);
           request.setSIF_Query(q);

           return request;
        }

         */
        private SIF_Response createSIF_Response(IElementDef objType, bool storeInRequestCache, ISerializable stateObject)
        {
            SIF_Request req = createSIF_Request(objType);

             if (storeInRequestCache)
             {
            Query q = new Query(objType);
            q.UserData = stateObject;
            RequestCache.GetInstance(fAgent).StoreRequestInfo(req, q, fZone);
             }

             SIF_Response resp = new SIF_Response();
             resp.SIF_RequestMsgId = req.Header.SIF_MsgId;
             SIF_ObjectData sod = new SIF_ObjectData();
             resp.SIF_ObjectData = sod;

             Object responseObject = null;
             try
             {
            responseObject = ClassFactory.CreateInstance(objType.FQClassName, false);
             }
             catch (Exception cfe)
             {
            throw new AdkException("Unable to create instance of " + objType.Name, fZone, cfe);
             }

             sod.AddChild((SifElement)responseObject);
             return resp;
        }
Ejemplo n.º 18
0
 public static void Write(this BinaryWriter writer, ISerializable value)
 {
     value.Serialize(writer);
 }
Ejemplo n.º 19
0
 public static Byte[] Serialize(ISerializable obj)
 {
     return(Serialize(obj.Serialize));
 }
Ejemplo n.º 20
0
        static public iCalendar LoadFromFile(Type iCalendarType, string Filepath, Encoding encoding, ISerializable serializer)
        {
            FileStream fs = new FileStream(Filepath, FileMode.Open);

            iCalendar iCal = LoadFromStream(iCalendarType, fs, encoding, serializer);

            fs.Close();
            return(iCal);
        }
Ejemplo n.º 21
0
 internal void GetObjectData(ISerializable obj, SerializationInfo serInfo, StreamingContext context)
 {
     // Demand the serialization formatter permission every time
     Globals.SerializationFormatterPermission.Demand();
     obj.GetObjectData(serInfo, context);
 }
Ejemplo n.º 22
0
 ///
 /// <param name="name"></param>
 /// <param name="v"></param>
 public abstract ISerializable Inout <T>(string name, ISerializable v) where T : new();
        /// <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;
        }
Ejemplo n.º 24
0
 public static ScriptBuilder EmitPush(this ScriptBuilder sb, ISerializable data)
 {
     return(sb.EmitPush(data.ToArray()));
 }
Ejemplo n.º 25
0
 public void NetTypes(
     bool p1, sbyte p2, byte p3, short p4, ushort p5, int p6, uint p7, long p8, ulong p9, BigInteger p10,
     byte[] p11, string p12, IInteroperable p13, ISerializable p14, int[] p15, ContractParameterType p16,
     object p17)
 {
 }
Ejemplo n.º 26
0
 private void BroadcastMessage(string command, ISerializable payload = null)
 {
     BroadcastMessage(Message.Create(command, payload));
 }
Ejemplo n.º 27
0
 private static string ObtenerPreciosBD(ISerializable obj)
 {
     return(obj.ObtenerPreciosBD());
 }
Ejemplo n.º 28
0
        public override void Serialize(Stream stream, Encoding encoding)
        {
            // Open the component
            byte[] open = encoding.GetBytes("BEGIN:" + m_component.Name + "\r\n");
            stream.Write(open, 0, open.Length);

            // Get a list of fields and properties
            List <object> items = this.FieldsAndProperties;

            // Alphabetize the list of fields & properties we just obtained
            items.Sort(new FieldPropertyAlphabetizer());

            // Iterate through each item and attempt to serialize it
            foreach (object item in items)
            {
                FieldInfo    field     = null;
                PropertyInfo prop      = null;
                Type         itemType  = null;
                string       itemName  = null;
                object[]     itemAttrs = null;

                if (item is FieldInfo)
                {
                    field    = (FieldInfo)item;
                    itemType = field.FieldType;
                    itemName = field.Name;
                }
                else
                {
                    prop     = (PropertyInfo)item;
                    itemType = prop.PropertyType;
                    itemName = prop.Name;
                }

                // Get attributes that are attached to each item
                itemAttrs = (field != null) ? field.GetCustomAttributes(true) : prop.GetCustomAttributes(true);

                // Get the item's value
                object obj = (field == null) ? prop.GetValue(m_component, null) : field.GetValue(m_component);

                // Adjust the items' name to be iCal-compliant
                if (obj is iCalObject)
                {
                    iCalObject ico = (iCalObject)obj;
                    if (ico.Name == null)
                    {
                        ico.Name = itemName.ToUpper().Replace("_", "-");
                    }

                    // If the property is non-standard, then replace
                    // it with an X-name
                    if (!ico.Name.StartsWith("X-"))
                    {
                        foreach (object attr in itemAttrs)
                        {
                            if (attr is NonstandardAttribute)
                            {
                                ico.Name = "X-" + ico.Name;
                                break;
                            }
                        }
                    }
                }

                // Retrieve custom attributes for this field/property
                if (obj is iCalDataType)
                {
                    ((iCalDataType)obj).Attributes = itemAttrs;
                }

                // Get the default value of the object, if available
                object defaultValue = null;
                foreach (Attribute a in itemAttrs)
                {
                    if (a is DefaultValueAttribute)
                    {
                        defaultValue = ((DefaultValueAttribute)a).Value;
                    }
                }

                // Create a serializer for the object
                ISerializable serializer = SerializerFactory.Create(obj);

                // To continue, the default value must either not be set,
                // or it must not match the actual value of the item.
                if (defaultValue == null ||
                    (serializer != null && !serializer.SerializeToString().Equals(defaultValue.ToString())))
                {
                    // FIXME: enum values cannot name themselves; we need to do it for them.
                    // For this to happen, we probably need to wrap enum values into a
                    // class that inherits from iCalObject.
                    if (itemType.IsEnum)
                    {
                        byte[] data = encoding.GetBytes(itemName.ToUpper().Replace("_", "-") + ":");
                        stream.Write(data, 0, data.Length);
                    }

                    // Actually serialize the object
                    if (serializer != null)
                    {
                        serializer.Serialize(stream, encoding);
                    }
                }
            }

            // If any extra serialization is necessary, do it now
            base.Serialize(stream, encoding);

            // Close the component
            byte[] close = encoding.GetBytes("END:" + m_component.Name + "\r\n");
            stream.Write(close, 0, close.Length);
        }
Ejemplo n.º 29
0
 public static void Deserialize(ISerializable obj, byte[] byteData)
 {
     Deserialize(obj.Deserialize, byteData);
 }
Ejemplo n.º 30
0
 ///
 /// <param name="name"></param>
 /// <param name="v"></param>
 public abstract ISerializable Inout(string name, ISerializable v);
Ejemplo n.º 31
0
 static public iCalendar LoadFromStream(Type iCalendarType, Stream s, Encoding e, ISerializable serializer)
 {
     return((iCalendar)serializer.Deserialize(s, e, iCalendarType));
 }
Ejemplo n.º 32
0
 internal protected StorageKey CreateStorageKey(byte prefix, ISerializable key)
 {
     return(CreateStorageKey(prefix, key.ToArray()));
 }
 public SerializableWrapper(ISerializable ser)
 {
     _ser = ser;
 }
Ejemplo n.º 34
0
 public static Message Create(string command, ISerializable payload = null)
 {
     return(Create(command, payload == null ? new byte[0] : payload.ToArray()));
 }
Ejemplo n.º 35
0
        static IObjectMemberInfo[] GetMembers(ISerializable value, Type type)
        {
            IObjectMemberInfo[] mis = null;
            if (value == null)
            {
                if (serialCache.TryGetValue(type, out mis)) return mis;

                // 尝试创建type的实例
                value = GetDefaultObject(type) as ISerializable;
            }

            SerializationInfo info = new SerializationInfo(type, new FormatterConverter());

            value.GetObjectData(info, DefaultStreamingContext);

            List<IObjectMemberInfo> list = new List<IObjectMemberInfo>();
            foreach (SerializationEntry item in info)
            {
                list.Add(CreateObjectMemberInfo(item.Name, item.ObjectType, item.Value));
            }
            mis = list.ToArray();

            if (!serialCache.ContainsKey(type))
            {
                lock (serialCache)
                {
                    if (!serialCache.ContainsKey(type)) serialCache.Add(type, mis);
                }
            }

            return mis;
        }
Ejemplo n.º 36
0
 public SerializeDecorator(ISerializable component, string path)
 {
     _component = component;
     _path      = path;
 }
Ejemplo n.º 37
0
 public virtual void rpc_Handle(ISerializable msg, OnRpcReturn <ISerializable> cb)
 {
     zone_rpc_call_handler?.Invoke(msg, (rsp, err) => { cb(rsp as ISerializable, err); });
 }
 private static bool HasObjectTypeIntegrity(ISerializable serializable)
 {
     return(!PlatformDetection.IsNetFramework ||
            !(serializable is NotFiniteNumberException));
 }
Ejemplo n.º 39
0
 public void EnqueueMessage(string command, ISerializable payload = null)
 {
     EnqueueMessage(command, payload, false);
 }
Ejemplo n.º 40
0
        public static StorageKey CreateStorageKey(this NativeContract contract, byte prefix, ISerializable key = null)
        {
            var k = new KeyBuilder(contract.Id, prefix);

            if (key != null)
            {
                k = k.Add(key);
            }
            return(k);
        }
        /// <summary>
        /// Send ROP request with single operation and get ROP response.
        /// </summary>
        /// <param name="serverId">A 32-bit signed integer represent the Identity of server.</param>
        /// <param name="ropRequest">ROP request object.</param>
        /// <param name="inputHandle">Server object handle in request.</param>
        /// <returns>ROP response object.</returns>
        private IDeserializable Process(int serverId, ISerializable ropRequest, uint inputHandle)
        {
            List<ISerializable> inputBuffer = new List<ISerializable>
            {
                ropRequest
            };
            List<uint> requestSOH = new List<uint>();
            requestSOH.Add(inputHandle);
            if (Common.IsOutputHandleInRopRequest(ropRequest))
            {
                requestSOH.Add(0xFFFFFFFF);
            }

            List<IDeserializable> responses = new List<IDeserializable>();
            List<List<uint>> responseSOHTable = new List<List<uint>>();
            byte[] rawData = null;
            this.ropResult = this.oxcropsClient[serverId].RopCall(inputBuffer, requestSOH, ref responses, ref responseSOHTable, ref rawData, 0x10008);

            if (this.ropResult == OxcRpcErrorCode.ECNone)
            {
                this.responseSOHs = responseSOHTable[0];
                this.VerifyMAPITransport();
            }

            if (responses.Count > 0)
            {
                return responses[0];
            }
            else
            {
                return null;
            }
        }
    private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
    {
      if (!JsonTypeReflector.FullyTrusted)
      {
        throw JsonSerializationException.Create(null, writer.ContainerPath, @"Type '{0}' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.
To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.".FormatWith(CultureInfo.InvariantCulture, value.GetType()), null);
      }

      contract.InvokeOnSerializing(value, Serializer.Context);
      _serializeStack.Add(value);

      WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty);

      SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());
      value.GetObjectData(serializationInfo, Serializer.Context);

      foreach (SerializationEntry serializationEntry in serializationInfo)
      {
        writer.WritePropertyName(serializationEntry.Name);
        SerializeValue(writer, serializationEntry.Value, GetContractSafe(serializationEntry.Value), null, null, member);
      }

      writer.WriteEndObject();

      _serializeStack.RemoveAt(_serializeStack.Count - 1);
      contract.InvokeOnSerialized(value, Serializer.Context);
    }
        public void Deserialize(string serName, ISerializable ser)
        {
            XElement subElem = this.elem.Element(serName);

            ser.Deserialize(new XmlDeserializer(subElem));
        }
Ejemplo n.º 44
0
 public StringWriter(ISerializable data) : this()
 {
     data.Write(this);
 }
Ejemplo n.º 45
0
 /// <summary>
 /// Set the data bound to a particular key
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void SetTraceData(string key, ISerializable value)
 {
     Thread.SetData(Thread.GetNamedDataSlot(key), value);
 }
Ejemplo n.º 46
0
 public override bool IsOfType(ISerializable data) => data is Environ;
Ejemplo n.º 47
0
        static bool TryGetKeyContainer(ISerializable key_pair, out byte [] key, out string key_container)
        {
            var info = new SerializationInfo (typeof (StrongNameKeyPair), new FormatterConverter ());
            key_pair.GetObjectData (info, new StreamingContext ());

            key = (byte []) info.GetValue ("_keyPairArray", typeof (byte []));
            key_container = info.GetString ("_keyPairContainer");
            return key_container != null;
        }
Ejemplo n.º 48
0
 public BinaryWriter(ISerializable data) : this()
 {
     data.Write(this);
 }
 /// <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>
 /// <returns>Server objects handles in response.</returns>
 public List<List<uint>> DoRopCall(ISerializable ropRequest, uint insideObjHandle, ref object response, ref byte[] rawData, GetPropertiesFlags getPropertiesFlag)
 {
     uint retValue;
     return this.DoRopCall(ropRequest, insideObjHandle, ref response, ref rawData, getPropertiesFlag, out retValue);
 }
Ejemplo n.º 50
0
 public static async Task <T> DeserializeGenericTypeAsync <T>(
     this ISerializable serializable, string data) where T : class
 {
     return(await((ISerializable)ActivateInstanceOf <T> .Instance()).DeserializeAsync <T>(data));
 }
Ejemplo n.º 51
0
            public bool Contains(ISerializable data)
            {
                if (HasData)
                {
                    if (Data.Equals(data))
                    {
                        return true;
                    }
                }

                if (HasNestedData)
                {
                    foreach (SingleRunTraceData srtd in NestedData)
                    {
                        if (srtd.Contains(data))
                            return true;
                    }
                }

                return false;
            }
Ejemplo n.º 52
0
 public virtual void rpc_Invoke(ISerializable msg)
 {
 }
		private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract)
		{
			contract.InvokeOnSerializing(value, Serializer.Context);
			SerializeStack.Add(value);

			writer.WriteStartObject();

			SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());
			value.GetObjectData(serializationInfo, Serializer.Context);

			foreach (SerializationEntry serializationEntry in serializationInfo)
			{
				writer.WritePropertyName(serializationEntry.Name);
				SerializeValue(writer, serializationEntry.Value, GetContractSafe(serializationEntry.Value), null, null);
			}

			writer.WriteEndObject();

			SerializeStack.RemoveAt(SerializeStack.Count - 1);
			contract.InvokeOnSerialized(value, Serializer.Context);
		}
Ejemplo n.º 54
0
 public virtual void rpc_Call(ISerializable msg, OnRpcReturn <ISerializable> cb)
 {
 }
Ejemplo n.º 55
0
 private void OnDragDataReceived(object sender, DragDataReceivedArgs e)
 {
     byte[] data = e.SelectionData.Data;
     Int64 value = BitConverter.ToInt64(data, 0);
     if (value != 0)
     {
         GCHandle handle = (GCHandle)new IntPtr(value);
         DragDropData = (ISerializable)handle.Target;
     }
 }
Ejemplo n.º 56
0
 public virtual void rpc_Handle(ISerializable msg)
 {
     zone_rpc_invoke_handler?.Invoke(msg);
 }
Ejemplo n.º 57
0
 internal void GetObjectData(ISerializable obj, SerializationInfo serInfo, StreamingContext context)
 {
     obj.GetObjectData(serInfo, context);
 }
Ejemplo n.º 58
0
 private void EnqueueMessage(MessageCommand command, ISerializable payload = null)
 {
     EnqueueMessage(Message.Create(command, payload));
 }
Ejemplo n.º 59
0
 public void SendSerializable(ISerializable serializable)
 {
     new Thread(new ParameterizedThreadStart(tSendSerializable)).Start(serializable);
 }
Ejemplo n.º 60
0
 private static bool Deserializar(ISerializable obj)
 {
     return(obj.DeserializarXML());
 }