Example #1
0
        public void setInitialize()
        {
            VO_MessageHeader vo_MessageHeader = new VO_MessageHeader();

            vo_MessageHeader.StrAction = "BargainFinderMax_ADRQ";
            vo_MessageHeader.StrValue  = "Air Shopping Service";
            this.Vo_MessageHeader      = vo_MessageHeader;
        }
        /// <summary>
        /// For invoking Sabre Webservices, it's requiered to add to the request the atribute
        /// MessageHeader which is the same for all SWS classes. This method dinamically loads this atribute
        /// by usgin reflexion.
        /// </summary>
        /// <param name="typeMessageHeader">Type of class expected</param>
        /// <param name="vo_MessageHeader">Parameters to fill the MessageHeader object</param>
        /// <returns></returns>
        internal object getMessageHeader(Type typeMessageHeader, VO_MessageHeader vo_MessageHeader)
        {
            object messageHeader = Activator.CreateInstance(typeMessageHeader);

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

            //MessageData
            DateTime dtmDate = DateTime.UtcNow;
            string   strDate = dtmDate.ToString("s") + "Z";

            PropertyInfo propertyInfoMessageData = messageHeader.GetType().GetProperty("MessageData");
            Type         typeMessageData         = assembly.GetType(propertyInfoMessageData.PropertyType.FullName);
            object       messageData             = Activator.CreateInstance(typeMessageData);

            messageData.GetType().GetProperty("Timestamp").SetValue(messageData, strDate, null);
            messageData.GetType().GetProperty("MessageId").SetValue(messageData, vo_MessageHeader.StrMessageId, null);

            //Service
            System.Reflection.PropertyInfo propertyInfoService = messageHeader.GetType().GetProperty("Service");
            Type   typeService = assembly.GetType(propertyInfoService.PropertyType.FullName);
            object service     = Activator.CreateInstance(typeService);

            service.GetType().GetProperty("Value").SetValue(service, vo_MessageHeader.StrValue, null);
            messageHeader.GetType().GetProperty("Service").SetValue(messageHeader, service, null);

            messageHeader.GetType().GetProperty("MessageData").SetValue(messageHeader, messageData, null);
            messageHeader.GetType().GetProperty("CPAId").SetValue(messageHeader, vo_MessageHeader.StrCPAId, null);
            messageHeader.GetType().GetProperty("Action").SetValue(messageHeader, vo_MessageHeader.StrAction, null);

            //From
            System.Reflection.PropertyInfo propertyInfoFrom = messageHeader.GetType().GetProperty("From");
            Type   typeFrom = assembly.GetType(propertyInfoFrom.PropertyType.FullName);
            object from     = Activator.CreateInstance(typeFrom);

            //PartyIdFrom
            PropertyInfo propertyInfoPartyID = from.GetType().GetProperty("PartyId");
            Type         typeFromPartyIds    = assembly.GetType(propertyInfoPartyID.PropertyType.FullName);
            Array        partyIdsAuxiliar    = Array.CreateInstance(typeFromPartyIds, 1);
            Type         typeFromPartyId     = typeFromPartyIds.GetElementType();
            Array        partyIds            = Array.CreateInstance(typeFromPartyId, 1);

            object fromPartyId = Activator.CreateInstance(typeFromPartyId);

            fromPartyId.GetType().GetProperty("Value").SetValue(fromPartyId, vo_MessageHeader.StrTo, null);
            partyIds.SetValue(fromPartyId, 0);
            from.GetType().GetProperty("PartyId").SetValue(from, partyIds, null);
            messageHeader.GetType().GetProperty("From").SetValue(messageHeader, from, null);

            //To
            System.Reflection.PropertyInfo propertyInfoTo = messageHeader.GetType().GetProperty("To");
            Type   typeTo = assembly.GetType(propertyInfoTo.PropertyType.FullName);
            object to     = Activator.CreateInstance(typeTo);

            //PartyIdTo
            partyIds    = Array.CreateInstance(typeFromPartyId, 1);
            fromPartyId = Activator.CreateInstance(typeFromPartyId);
            fromPartyId.GetType().GetProperty("Value").SetValue(fromPartyId, vo_MessageHeader.StrTo, null);
            partyIds.SetValue(fromPartyId, 0);
            to.GetType().GetProperty("PartyId").SetValue(to, partyIds, null);
            messageHeader.GetType().GetProperty("To").SetValue(messageHeader, to, null);

            //ConversationId
            messageHeader.GetType().GetProperty("ConversationId").SetValue(messageHeader, vo_MessageHeader.StrConversationId, null);

            return(messageHeader);
        }