コード例 #1
0
        public List <TicketsDetailsResponse> GetTicketDetails(TicketsDetailsRequest req)
        {
            try
            {
                TicketsServicesSoap ticketSoap = new TicketsServicesSoapClient();

                var reqObj = new GetTicketsRequest()
                {
                    PlateInfo = new ADPTicketsServiceReference.PlateKey()
                    {
                        PlateNo         = req.PlateNo,
                        PlateOrgNo      = req.PlateOrgNo,
                        PlateColorCode  = req.PlateColorCode,
                        PlateKindCode   = req.PlateKindCode,
                        PlateTypeCode   = req.PlateTypeCode,
                        PlateSourceCode = req.PlateSourceCode
                    },
                    LicenseInfo = new ADPTicketsServiceReference.LicenseKey()
                    {
                        LicenseNo         = req.LicenseNumber,
                        LicenseSourceCode = req.LicenseSourceCode
                    },
                    TrafficProfile = new ADPTicketsServiceReference.TrafficNo()
                    {
                        TcfNo = req.TcfNo
                    },

                    DateFrom   = req.DateFrom,
                    DateTo     = req.DateTo,
                    SystemCode = systemCode,
                    UserID     = userId
                };

                var header = new ADPTicketsServiceReference.ADPSoapHeaderIn()
                {
                    UserName = username,
                    Password = password
                };

                var result = ticketSoap.GetTickets(new GetTicketsRequest1 {
                    request = reqObj, ADPSoapHeaderIn = header
                });

                if (result != null)
                {
                    return(result.GetTicketsResult.ConvertToTicketsDetails());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Utility.WriteErrorLog(ex);

                return(null);
            }
        }
コード例 #2
0
        static void GetTickets(MagentoService service, string siteUrl, string token)
        {
            var getTicketsRequest = new GetTicketsRequest()
            {
                connection_id = "1",
                from          = new DateTime(2017, 7, 1).ToString("yyyy-MM-dd hh:mm:ss"),
                to            = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"),
            };
            var result = service.GetTickets(siteUrl, token, getTicketsRequest);

            if (result.HasError)
            {
                Console.WriteLine("GetTickets " + result.Error);
            }
            else
            {
                Console.WriteLine("GetTickets " + result.Result.Count);
            }
        }
コード例 #3
0
        public void Proceed(Services.Models.Connection connection)
        {
            TextBuffer.WriteLine("EbayMagentoProcessor - Start");
            TextBuffer.WriteLine("EbayMagentoProcessor - Proceed Connection " + connection.Id);

            var syncTime = DateTime.UtcNow;

            connection.Status = ConnectionStatus.Synchronizing;
            connectionService.Update(connection);

            var userChannelEbay    = userChannelService.GetUserChannel(connection.UserChannelSource);
            var userChannelMagento = userChannelService.GetUserChannel(connection.UserChannelTarget);

            var channelEbay    = channelEbayService.GetChannel(userChannelEbay.ChannelId);
            var channelMagento = channelMagentoService.GetChannel(userChannelMagento.ChannelId);
            var channelMagento_TimeZoneOffset =
                TimeZoneInfo.GetSystemTimeZones()
                .FirstOrDefault(x => x.DisplayName == channelMagento.TimeZoneDisplayName)
                .BaseUtcOffset;

            if (!ebayService.IsValidToken(channelEbay.Token).Result)
            {
                connection.Status         = ConnectionStatus.Error;
                connection.Message        = "Invalid Ebay Token";
                connection.LastSyncedDate = syncTime;
                connection.NextSyncedDate = connection.LastSyncedDate.Value.AddMinutes(ebayMagentoTaskIntervalInMinutes);
                connection.Counter++;
                connectionService.Update(connection);
                return;
            }

            var magentoTokenCall = magentoService.GetToken(channelMagento.Host, channelMagento.Username, channelMagento.Password);

            if (magentoTokenCall.HasError)
            {
                connection.Status         = ConnectionStatus.Error;
                connection.Message        = "Invalid Magento Token";
                connection.LastSyncedDate = syncTime;
                connection.NextSyncedDate = connection.LastSyncedDate.Value.AddMinutes(ebayMagentoTaskIntervalInMinutes);
                connection.Counter++;
                connectionService.Update(connection);
                return;
            }
            var magentoToken = magentoTokenCall.Result;


            #region Ebay to Magento
            //1. Pull Ebay MemberMessage and persist to local DB
            #region Pull MemberMessage from Ebay
            var lastSyncDate_Ebay_MemberMessage = channelEbay.LastSyncedDateMemberMessage ?? DateTime.UtcNow;
            var ebayMessageApi = ebayService.GetMemberMessage(channelEbay.Token, lastSyncDate_Ebay_MemberMessage, DateTime.UtcNow, MessageTypeCodeType.All, MessageStatusTypeCodeType.Unanswered);
            var ebayTickets    = new List <TicketEbay>();
            var ebayMessages   = new List <MessageEbay>();
            if (ebayMessageApi.HasError)
            {
                channelEbay.Message += ebayMessageApi.Error;
            }
            else
            {
                var memberMessages = ebayMessageApi.Result;
                foreach (var memberMessage in memberMessages)
                {
                    var ticketEbay = GetOrCreateTicketEbay(memberMessage, connection, syncTime);
                    ebayTickets.Add(ticketEbay);

                    var messageEbay = CreateMessageEbay(memberMessage, ticketEbay, syncTime);
                    ebayMessages.Add(messageEbay);
                }
            }

            channelEbay.LastSyncedDateMemberMessage = syncTime;
            channelEbayService.Update(channelEbay);
            #endregion

            //2. Transfer Ebay MemberMessage to Magento local DB
            #region Transfer Ebay MemberMessage to Magento local DB
            foreach (var ebayTicket in ebayTickets)
            {
                var magentoTicket = mapper.Map <TicketMagento>(ebayTicket);
                magentoTicket.Id = ticketMagentoService.CreateTicket(magentoTicket);

                ticketEbayMagentoService.Create(ebayTicket.Id, magentoTicket.Id);
                var ebayMessagesFilterByTicketId = ebayMessages.Where(x => x.TicketId == ebayTicket.Id);
                foreach (var ebayMessage in ebayMessagesFilterByTicketId)
                {
                    var magentoMessage = mapper.Map <MessageMagento>(ebayMessage);
                    magentoMessage.TicketId = magentoTicket.Id;
                    magentoMessage.Id       = messageMagentoService.CreateMessage(magentoMessage);

                    messageEbayMagentoService.Create(ebayMessage.Id, magentoMessage.Id);
                }
            }
            #endregion

            //3. Push Magento Ticket and Message from local DB to remote site
            #region Push Magento Ticket and Message to Remote Site
            var magentoTickets = ticketMagentoService.GetMagentoTicketsForSyncByConnectionId(connection.Id);
            foreach (var magentoTicket in magentoTickets)
            {
                var createTicketRequest = CreateTicketMagentoRequest(magentoTicket, connection, channelMagento);
                var result = magentoService.CreateTicket(channelMagento.Host, magentoToken, createTicketRequest);
                if (result.HasError)
                {
                    magentoTicket.SyncStatus       = SyncStatus.Error;
                    magentoTicket.SyncErrorMessage = result.Error;
                }
                else
                {
                    magentoTicket.SyncStatus       = SyncStatus.Ok;
                    magentoTicket.SyncErrorMessage = string.Empty;
                    magentoTicket.MagentoId        = result.Result.ToString();

                    var magentoMessages = messageMagentoService.GetMessagesForSyncByTicketId(magentoTicket.Id);
                    foreach (var magentoMessage in magentoMessages)
                    {
                        var sendMessageRequest = SendMessageMagentoRequest(magentoMessage, magentoTicket);
                        var sendMsgResult      = magentoService.SendMessage(channelMagento.Host, magentoToken, sendMessageRequest);
                        if (sendMsgResult.HasError)
                        {
                            magentoMessage.SyncStatus       = SyncStatus.Error;
                            magentoMessage.SyncErrorMessage = sendMsgResult.Error;
                        }
                        else
                        {
                            magentoMessage.SyncStatus       = SyncStatus.Ok;
                            magentoMessage.SyncErrorMessage = string.Empty;
                            magentoMessage.MagentoId        = sendMsgResult.Result.ToString();
                        }
                        magentoMessage.LastSynchronizedDate = syncTime;
                        messageMagentoService.UpdateMessage(magentoMessage);
                    }
                }
                magentoTicket.LastSynchronizedDate = syncTime;

                ticketMagentoService.UpdateTicket(magentoTicket);
            }
            #endregion

            #endregion

            #region Magento to Ebay

            //4. Pull Ticket and Message from Magento
            #region Pull Ticket/Message from Magento
            var lastSyncDate_Magento_Ticket = channelMagento.LastSyncedDateTicket ?? DateTime.UtcNow;
            var getTicketsMagentoRequest    = new GetTicketsRequest()
            {
                connection_id = connection.Id.ToString(),
                from          = lastSyncDate_Magento_Ticket.ToString(Shared.Constants.DateTimeFormat_Magento),
                to            = syncTime.ToString(Shared.Constants.DateTimeFormat_Magento),
            };
            var getTicketsResult = magentoService.GetTickets(channelMagento.Host, magentoToken, getTicketsMagentoRequest);
            if (getTicketsResult.HasError)
            {
                channelMagento.Message += getTicketsResult.Error;
            }
            else
            {
                channelMagento.LastSyncedDateTicket = syncTime;
            }

            var lastSyncDate_Magento_Message = channelMagento.LastSyncedDateMessage ?? DateTime.UtcNow;
            var getMessagesMagentoRequest    = new GetMessagesRequest()
            {
                connection_id = connection.Id.ToString(),
                from          = lastSyncDate_Magento_Message.ToString(Shared.Constants.DateTimeFormat_Magento),
                to            = syncTime.ToString(Shared.Constants.DateTimeFormat_Magento),
            };
            var getMessagesResult = magentoService.GetMessages(channelMagento.Host, magentoToken, getMessagesMagentoRequest);
            if (getMessagesResult.HasError)
            {
                channelMagento.Message += ". " + getTicketsResult.Error;
            }
            else
            {
                channelMagento.LastSyncedDateMessage = syncTime;
            }
            channelMagentoService.Update(channelMagento);
            #endregion

            //5. Persist Message reply by admin to local db
            #region Persist Message reply by admin to local db
            var pulledMagentMessages = new List <MessageMagento>();
            if (!getMessagesResult.HasError)
            {
                foreach (var magentoMessage in getMessagesResult.Result)
                {
                    var ticket = ticketMagentoService.Get(magentoMessage.ticket_id);
                    if (ticket != null && !messageMagentoService.IsExisting(magentoMessage.message_id))
                    {
                        var message = new MessageMagento()
                        {
                            MagentoId            = magentoMessage.message_id,
                            SenderId             = ticket.RecipientId,
                            SenderEmail          = string.Empty,
                            TicketId             = ticket.Id,
                            Message              = magentoMessage.message,
                            CreatedDate          = DateTime.Parse(magentoMessage.created_date),
                            LastModifiedDate     = DateTime.Parse(magentoMessage.last_modified_date),
                            Note                 = string.Empty,
                            LastSynchronizedDate = syncTime,
                            SyncStatus           = SyncStatus.Ok,
                            SyncErrorMessage     = string.Empty,
                        };

                        message.Id = messageMagentoService.CreateMessage(message);
                        pulledMagentMessages.Add(message);
                    }
                }
            }
            #endregion

            //6. Transfer Magento message to Ebay message
            #region Transfer Magento message to Ebay message
            foreach (var message in pulledMagentMessages)
            {
                var ebayMessage  = mapper.Map <MessageEbay>(message);
                var ebayTicketId = ticketEbayMagentoService.GetByTicketMagentoId(message.TicketId).IdEbay;
                ebayMessage.TicketId = ebayTicketId;

                ebayMessage.Id = messageEbayService.CreateMessage(ebayMessage);
            }
            #endregion

            //7. Push Transfered ebay message to remote site
            #region Push Tranfered ebay message to remote site
            var transferEbayMessages = messageEbayService.GetMessagesForSyncByConnectionId(connection.Id);
            foreach (var message in transferEbayMessages)
            {
                var ticket      = ticketEbayService.GetTicketById(message.TicketId);
                var ebayMessage = new Channels.Ebay.Models.MemberMessage()
                {
                    ItemId          = ticket.ItemId,
                    ParentMessageId = ticket.EbayId,
                    SenderId        = message.SenderId,
                    SenderEmail     = message.SenderEmail,
                    RecipientId     = ticket.CreatorId,
                    Body            = message.Message,
                    CreatedDate     = message.CreatedDate,
                };

                var result = ebayService.SendMessage(channelEbay.Token, ticket.Subject, ticket.EbayId, ebayMessage);
                if (result.HasError)
                {
                    message.SyncStatus = SyncStatus.Error;
                    message.Message    = result.Error;
                }
                else
                {
                    message.SyncStatus = SyncStatus.Ok;
                    message.Message    = string.Empty;
                }
                message.LastSynchronizedDate = syncTime;
                messageEbayService.UpdateMessage(message);
            }
            #endregion

            #endregion

            connection.Status         = ConnectionStatus.Connected;
            connection.LastSyncedDate = syncTime;
            connection.NextSyncedDate = connection.LastSyncedDate.Value.AddMinutes(ebayMagentoTaskIntervalInMinutes);
            connection.Counter++;
            connectionService.Update(connection);

            TextBuffer.WriteLine("EbayMagentoProcessor - End Connection " + connection.Id);
        }
コード例 #4
0
        public MagentoServiceResponse <IList <TicketResponse> > GetTickets(string siteUrl, string token, GetTicketsRequest getTicketsRequest)
        {
            var client          = CreateRestClient(siteUrl, token);
            var serviceResponse = new MagentoServiceResponse <IList <TicketResponse> >();
            var request         = CreateRequest("/rest/aheadworks/helpdesk/gettickets", Method.POST);

            request.AddBody(getTicketsRequest);

            try
            {
                var response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var content = SimpleJson.DeserializeObject <JsonArray>(response.Content);
                    if (content == null)
                    {
                        serviceResponse.Error = "Can not deserialize content";
                    }
                    else
                    {
                        if (content[1].ToString() == string.Empty)
                        {
                            serviceResponse.Result = SimpleJson.DeserializeObject <IList <TicketResponse> >(content[0].ToString());
                        }
                        else
                        {
                            serviceResponse.Error = content[1].ToString();
                        }
                    }
                }
                else
                {
                    serviceResponse.Error = response.Content;
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Error = ex.Message;
            }

            return(serviceResponse);
        }
コード例 #5
0
 void AndGivenCommandPrepared()
 {
     _request = new GetTicketsRequest();
 }