// --------------------------------------------------------[] private string FeedContent( MipFeedType mipFeedType ) { var template = FeedTemplate( mipFeedType ); switch( mipFeedType ) { case MipFeedType.Product : return template .Replace( "{item.sku}", Item.Sku ) .Replace( "{item.title}", Item.Title ) ; case MipFeedType.Availability : return template .Replace( "{item.sku}", Item.Sku ) .Replace( "{item.quantity}", Item.Quantity.ToString( CultureInfo.CreateSpecificCulture( "en-US" ) ) ) ; case MipFeedType.Distribution : return template .Replace( "{item.sku}", Item.Sku ) .Replace( "{item.price}", Item.Price.ToString( CultureInfo.CreateSpecificCulture( "en-US" ) ) ) ; } throw new SpreadbotException( "Wrong FeedType=[{0}]", mipFeedType ); }
// --------------------------------------------------------[] private static void TestReadFeedStatus( MipFeedType mipFeedType, MipFeedSubmissionOverallStatus mipFeedSubmissionOverallStatus, IMipConnector mipConnector) { var wasTested = false; var feed = new MipFeedDescriptor( mipFeedType ); MipConnectorTestInitializer.TestRequestIds( feed.Type, mipFeedSubmissionOverallStatus ) .ForEach( reqId => { var request = new MipFeedSubmissionDescriptor( feed, reqId ); var response = mipConnector.GetFeedSubmissionOverallStatus( request ); var testInfo = "{0}.{1} checking status".SafeFormat( feed.Type, reqId ); wasTested = true; Assert.That( response.IsSuccessful, testInfo ); Assert.AreEqual( mipFeedSubmissionOverallStatus, response.Result.Status, testInfo ); } ); Assert.AreEqual( true, wasTested, "{0}.{1} was not tested".SafeFormat( mipFeedType, mipFeedSubmissionOverallStatus ) ); }
// --------------------------------------------------------[] public static IEnumerable<string> TestRequestIds( MipFeedType feed, MipFeedSubmissionOverallStatus overallStatus) { return Enumerable.Range( 1, 10 ) .Where( i => FileExists( feed, overallStatus, i ) ) .Select( i => string.Format( "{0}-{1:000}", overallStatus, i ).ToLower() ); }
// --------------------------------------------------------[] private static void _TestReadAllFeedStatuses( MipFeedType mipFeedType ) { var fakeMipConnector = EbayMockHelper.GetMipConnectorUsingLocalData(); TestReadFeedStatus( mipFeedType, MipFeedSubmissionOverallStatus.Success, fakeMipConnector ); TestReadFeedStatus( mipFeedType, MipFeedSubmissionOverallStatus.Failure, fakeMipConnector ); TestReadFeedStatus( mipFeedType, MipFeedSubmissionOverallStatus.Unknown, fakeMipConnector ); }
// --------------------------------------------------------[] private Response<MipGetFeedSubmissionOverallStatusResult> GetSubmissionOverallStatusFromOutput( MipFeedType feedType, Response< MipFindSubmissionResult > response, MipFeedSubmissionDescriptor mipFeedSubmissionDescriptor) { return new Response< MipGetFeedSubmissionOverallStatusResult > { ArgsInfo = MakeSubmissionStatusArgsInfo( mipFeedSubmissionDescriptor ), Result = ReadSubmissionOverallStatus( feedType, response ) }; }
// --------------------------------------------------------[] private static void _TestReadItemId( MipFeedType mipFeedType, IMipConnector mipConnector ) { var feed = new MipFeedDescriptor( mipFeedType ); var request = new MipFeedSubmissionDescriptor( feed, MipConnectorTestInitializer.ItemRequestId ); var response = mipConnector.GetFeedSubmissionOverallStatus( request ); Console.WriteLine( response ); Assert.IsNotNull( response.Result ); Assert.AreEqual( MipConnectorTestInitializer.ProductItemId, response.Result.MipItemId, "{0}.ItemId".SafeFormat( feed.Type ) ); }
// --------------------------------------------------------[] private static MipFeedSubmissionCompleteStatus GetSubmissionCompleteStatusFromContent( MipFeedType feedType, string content) { var statusNodePath = new Dictionary< MipFeedType, string > { { MipFeedType.Product, "/productResponse/status" }, { MipFeedType.Availability, "/inventoryResponse/status" }, { MipFeedType.Distribution, "/distributionResponse/status" }, }; var extraSubmissionStatusControl = new Dictionary < MipFeedType, Func< XmlDocument, MipFeedSubmissionCompleteStatus, MipFeedSubmissionCompleteStatus > > { { MipFeedType.Product, ExtraCheckProductCompleteStatus }, { MipFeedType.Availability, ExtraCheckAvailabilityCompleteStatus }, { MipFeedType.Distribution, ExtraCheckDistributionCompleteStatus }, }; try { var xml = new XmlDocument { InnerXml = content }; var statusNode = xml.SelectSingleNode( statusNodePath[ feedType ] ); if( statusNode != null ) { switch( statusNode.InnerText ) { case "SUCCESS" : return extraSubmissionStatusControl[ feedType ]( xml, MipFeedSubmissionCompleteStatus.Success ); case "FAILURE" : return MipFeedSubmissionCompleteStatus.Failure; } } } catch { // ignored } return MipFeedSubmissionCompleteStatus.Unknown; }
public MipFeedDescriptor( MipFeedType type ) : this() { Type = type; }
// --------------------------------------------------------[] private static bool FileExists( MipFeedType feed, MipFeedSubmissionOverallStatus overallStatus, int i ) { return File.Exists( EbaySettings.LocalBasePath + @"ini\" + string.Format( @"inbox\{0}.{1}-{2:000}.xml", feed, overallStatus, i ).ToLower() ); }
// --------------------------------------------------------[] private static void _TestReadItemId( MipFeedType mipFeedType ) { _TestReadItemId( mipFeedType, EbayMockHelper.GetMipConnectorUsingLocalData() ); }
// --------------------------------------------------------[] private EbaySubmissionTask _CreateEbaySubmissionSubTask( MipFeedType mipFeedType) { return new EbaySubmissionTask { IsCritical = true, MipFeedSubmissionOverallStatus = MipFeedSubmissionOverallStatus.Unknown, ChannelId = EbayAdapter.Instance.Id, ChannelMethod = ChannelMethod.Submit, Args = new EbaySubmissionArgs { MipFeedDescriptor = new MipFeedDescriptor( mipFeedType ) { Content = FeedContent( mipFeedType ), ItemInfo = Item.Sku, }, } }; }
// --------------------------------------------------------[] private static string FeedTemplate( MipFeedType mipFeedType ) { var templateFolder = DemoshopConfig.Instance.DemoshopPaths.EbayTemplatesDir.MapPathToDataDirectory(); var xmlTemplateFilePath = string.Format( @"{0}{1}.xml", templateFolder, mipFeedType ); return File.ReadAllText( xmlTemplateFilePath ); }
// --------------------------------------------------------[] private static string GetSubmissionItemIdFromContent( MipFeedType feedType, string content ) { var itemIdPath = new Dictionary< MipFeedType, string > { { MipFeedType.Product, "/productResponse/responseMessage/response/itemID" }, { MipFeedType.Distribution, "/distributionResponse/responseMessage/itemID" } }; if( !itemIdPath.ContainsKey( feedType ) ) { return null; } var xml = new XmlDocument { InnerXml = content }; var itemIdNode = xml.SelectSingleNode( itemIdPath[ feedType ] ); if( itemIdNode != null ) { return itemIdNode.InnerText; } return null; }
// --------------------------------------------------------[] private static MipGetFeedSubmissionOverallStatusResult MakeSubmissionOverallStatusResultByParsingXmlContent( MipFeedType feedType, string content) { return new MipGetFeedSubmissionOverallStatusResult { Status = ToOverallStatus( GetSubmissionCompleteStatusFromContent( feedType, content ) ), MipItemId = GetSubmissionItemIdFromContent( feedType, content ), Details = content, }; }
// --------------------------------------------------------[] private MipGetFeedSubmissionOverallStatusResult ReadSubmissionOverallStatus( MipFeedType feedType, Response< MipFindSubmissionResult > response) { var fileName = response.Result.RemoteFileName; var remotePath = response.Result.RemoteDir; var localPath = LocalSubmissionResultsFolder(); var content = SftpHelper.GetRemoteFileContent( remotePath, fileName, localPath ); return MakeSubmissionOverallStatusResultByParsingXmlContent( feedType, content ); }