How to Increase performance of API call - api

I am using 5 Hotels APIs and trying to combine and pick min price hotel with unique hotels from all APIs. I am following these STEPS
Call All 5 APIsand wait for response.
get all static data from database or if avail my server caching(all 5 APIs like hotels name, images, desc, etc)
Combine into one custom class
get GIATA map codes from caching or database.
Apply GIATA into API result and group all hotels with unique GIATA id.
Pick min price .
Bind UI and show to customer.
string sessionid = sqf;
DS.Models.BL.Common.HotelSearchDetails details = new DS.Models.BL.Common.HotelSearchDetails();
details = (.Models.BL.Common.HotelSearchDetails)Session["Details_" + sessionid];
List<DS.BL.Common.HotelDetails> DOTWhdlist = new List<DS.BL.Common.HotelDetails>();
List<DS.BL.Common.HotelDetails> GTAhdlist = new List<DS.BL.Common.HotelDetails>();
List<DS.BL.Common.HotelDetails> HPhdlist = new List<DS.BL.Common.HotelDetails>();
List<DS.BL.Common.HotelDetails> HBhdlist = new List<DS.BL.Common.HotelDetails>();
List<DS.BL.Common.HotelDetails> TSGhdlist = new List<DS.BL.Common.HotelDetails>();
//GTA City Cache
DS.Models.BL.GTA_Model.Methods.HotelInfo hinfo = new Models.BL.GTA_Model.Methods.HotelInfo();
List<GTA.API.HotelSearch.GTAHotels> hlist = new List<GTA.API.HotelSearch.GTAHotels>();
hlist = hinfo.GethotellistCityWise(details.GTACityCode);
//
/*************************************************
* DOTW cache
*
*************************************************/
DS.BL.DOTW.Method.HotelInfo objhoteldetails = new DS.BL.DOTW.Method.HotelInfo();
Dictionary<string, int> dictionary = objhoteldetails.Gethotelratings();
List<DOTW.Method.searchhotels.DotwHotels> objhotellist = new List<DOTW.Method.searchhotels.DotwHotels>();
objhotellist = objhoteldetails.GethotellistCityWise(details.DOTWCityCode);
//-------------------------------------------------------------------------------------------------------
//------Hotel pro cache city
DS.BL.HotelsPro.Method.GetHotelDetails objhoteldetails_hp = new BL.HotelsPro.Method.GetHotelDetails();
List<HotelsPro.Method.Avail.HotelsProHotels> objhotellist_hp = new List<HotelsPro.Method.Avail.HotelsProHotels>();
objhotellist_hp = objhoteldetails_hp.GethotellistCityWise(details.HotelsProCityCode);
/***************************************************
* Hotelbeds city cache
*
*/
DS.Models.BL.HotelBeds.Methods.HotelInfoController objhotelbeds = new DS.Models.BL.HotelBeds.Methods.HotelInfoController();
List<HotelBeds.Method.SearchHotel.HotelBedsHotels> HBhotellist = new List<HotelBeds.Method.SearchHotel.HotelBedsHotels>();
HBhotellist = objhotelbeds.GethotellistCityWise(details.HBCityCode);
/**************************************************
*
* TSG city cache
*
*/
DS.Models.BL.TSG.Methods.HotelInfo objtsg_hotel = new Models.BL.TSG.Methods.HotelInfo();
List<TSG.API.HotelAvail.TSGHotels> TSGhlist = new List<TSG.API.HotelAvail.TSGHotels>();
TSGhlist = objtsg_hotel.GethotellistCityWise(details.City);
//---------------------------------------------------------------------------------------------------------------------
var dotw = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => Dotw(sqf, details, dictionary, objhotellist));
var gta = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => GTA(sqf, details, hlist));
var hotelpro = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => Hp(sqf, details, objhotellist_hp));
var hotelbeds = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => HB(sqf, details, HBhotellist));
var tsg = Task<List<DS.BL.Common.HotelDetails>>.Factory.StartNew(() => TSG(sqf, details, TSGhlist));
DOTWhdlist = dotw.Result;
TSGhdlist = tsg.Result;
GTAhdlist = gta.Result;
HPhdlist = hotelpro.Result;
HBhdlist = hotelbeds.Result;
ViewBag.sessionId = sessionid;
DOTWhdlist.AddRange(GTAhdlist);
DOTWhdlist.AddRange(HPhdlist);
DOTWhdlist.AddRange(HBhdlist);
DOTWhdlist.AddRange(TSGhdlist);
string[] c = details.CityName.Split(',');
string cityname = c[0];
List<DS.BL.Common.HotelDetails> filterdata = GiataApply(DOTWhdlist, cityname, details.GiataCityid);
List<DS.BL.Common.HotelDetails> tsgdata = filterdata.Where(x => x.giataref == "exclusivelyhotels").ToList();
List<DS.BL.Common.HotelDetails> gtadata = filterdata.Where(x => x.giataref == "gta").ToList();
List<DS.BL.Common.HotelDetails> dotwdata = filterdata.Where(x => x.giataref == "DOTW").ToList();
List<DS.BL.Common.HotelDetails> hpdata = filterdata.Where(x => x.giataref == "metglobal").ToList();
List<DS.BL.Common.HotelDetails> hbdata = filterdata.Where(x => x.giataref == "hotelbeds").ToList();
allSup.dotw = dotwdata;
GIATA APPLY
List<DS.BL.Common.HotelDetails> GiataApply(List<DS.BL.Common.HotelDetails> hlist, string city, int Cityid)
{
DS.Models.BL.Common.GIATA.giataCodes giataCodes = new Models.BL.Common.GIATA.giataCodes();
List<GiataProperty> gcode = new List<GiataProperty>();
gcode = giataCodes.GiataCodes(city, Cityid);
var query = from h in hlist
join g in gcode on new { hotelcode = h.HotelId, supcode = h.giataref }
equals new { hotelcode = g.Hcode, supcode = g.ProviderCode }
select new DS.BL.Common.HotelDetails
{
HotelName = h.HotelName,
HCode = h.HCode,
HotelId = h.HotelId,
Address = h.Address,
image = h.image,
location = h.location,
Currency = h.Currency,
searchId = h.searchId,
Price = h.Price,
rating = h.rating,
hoteldescription = h.hoteldescription,
Latitude = h.Latitude,
Longitude = h.Longitude,
imagelist = h.imagelist,
Source = h.Source,
giataref = h.giataref,
HFullResponse = h.HFullResponse,
AvailableRoomList = h.AvailableRoomList,
HotelRooms = h.HotelRooms,
facilities = h.facilities,
faDetails = h.faDetails,
giata = g.giataId.Value,
hotelservices = h.hotelservices,
gtaIDref = h.gtaIDref
};
var filter = from x in query
group x by x.giata into hotels
select new DS.BL.Common.HotelDetails
{
HotelName = hotels.FirstOrDefault().HotelName,
HCode = hotels.FirstOrDefault().HCode,
HotelId = hotels.FirstOrDefault().HotelId,
Address = hotels.FirstOrDefault().Address,
image = hotels.FirstOrDefault().image,
location = hotels.FirstOrDefault().location,
Currency = hotels.FirstOrDefault().Currency,
searchId = hotels.FirstOrDefault().searchId,
imagelist = hotels.FirstOrDefault().imagelist,
Price = hotels.Min(p => p.Price),
rating = hotels.FirstOrDefault().rating,
hoteldescription = hotels.FirstOrDefault().hoteldescription,
Latitude = hotels.FirstOrDefault().Latitude,
Longitude = hotels.FirstOrDefault().Longitude,
Source = hotels.FirstOrDefault().Source,
giataref = hotels.FirstOrDefault().giataref,
HFullResponse = hotels.FirstOrDefault().HFullResponse,
AvailableRoomList = hotels.FirstOrDefault().AvailableRoomList,
HotelRooms = hotels.FirstOrDefault().HotelRooms,
facilities = hotels.FirstOrDefault().facilities,
faDetails = hotels.FirstOrDefault().faDetails,
giata = hotels.FirstOrDefault().giata,
hotelservices = hotels.FirstOrDefault().hotelservices,
gtaIDref = hotels.FirstOrDefault().gtaIDref
};
return filter.ToList();
//return query.ToList();
}
No this process taking 30-45 sec . i want to reduce i dont know how i do but in API calling i need to reduce time and GIATA apply .
give me idea guys thanks

Find async version of your API calls and use them. That should solve your problem. If no async version is available then you will have to do it in your code of C#. I am not a C# expert so I cannot help you there.

Related

How to duplicate line on itself?

In a JetBrains editor, what is the shortcut (or trick) to duplicate a line on itself without breakline (not like Ctrl + D). In other words, I want to turn this:
constructor(obj: Schema$Car) {
this.brand =
this.id =
this.model =
this.photoBack =
this.photoFront =
this.photoInteriorBack =
this.photoInteriorFront =
this.photoSide =
this.seatCount =
this.year =
}
into this:
constructor(obj: Schema$Car) {
this.brand = obj.brand
this.id = obj.id
this.model = obj.model
this.photoBack = obj.photoBack
this.photoFront = obj.photoFront
this.photoInteriorBack = obj.photoInteriorFront
this.photoInteriorFront = obj.photoInteriorFront
this.photoSide = obj.photoSide
this.seatCount = obj.seatCount
this.year = obj.year
}

DocuSign does not pass values to Salesforce

DocuSign doesn't pass values back into Salesforce. And Even doesn't give me any errors in the logs.
I used a Custom Field like source ID and MergeFieldXml tab option with the write-back = true. But it doesn't work.
Please advise what is wrong?
Merge fields are enabled for the DocuSign account.
My code example:
global class AnnualContract
{
webService static string AM_SendToDocuSign(String id, string strObjType)
{
Docusign_API_Setting__c APISetting = Docusign_API_Setting__c.getInstance('API Settings');
String envelopeId = '';
string DealerName = '';
string DealerId = '';
String accountId = APISetting.AccountId__c;
String userId = APISetting.UserId__c;
String password = APISetting.Password__c;
String integratorsKey = APISetting.IntegratorsKey__c;
String webServiceUrl = APISetting.WebServiceUrl__c;
list<Lead> lstLead = new list<Lead>();
list<Contact> lstContact = new list<Contact>();
if(strObjType == 'Lead')
{
lstLead = [SELECT Name,Status,Email,FirstName,LastName,Owner.Name,Title,FROM Lead where id = : Id limit 1];
}
StaticResource objSR = [SELECT Id,name, SystemModStamp FROM StaticResource WHERE Name = 'AnnualContractPDF' LIMIT 1];
String url_file_ref = '/resource/' + String.valueOf(((DateTime)objSR.get('SystemModStamp')).getTime())+ '/' + objSR.get('Name');
if(strObjType == 'Lead')
{
DealerName = lstLead[0].Name;
}
DocuSignAPI.APIServiceSoap dsApiSend = new DocuSignAPI.APIServiceSoap();
dsApiSend.endpoint_x = webServiceUrl;
//Set Authentication
String auth = '<DocuSignCredentials><Username>'+ userId
+'</Username><Password>' + password
+ '</Password><IntegratorKey>' + integratorsKey
+ '</IntegratorKey></DocuSignCredentials>';
System.debug('Setting authentication to: ' + auth);
dsApiSend.inputHttpHeaders_x = new Map<String, String>();
dsApiSend.inputHttpHeaders_x.put('X-DocuSign-Authentication',
auth);
DocuSignAPI.Envelope envelope = new DocuSignAPI.Envelope();
envelope.Subject = 'Please Sign this Contract' + lstLead[0].Name;
envelope.EmailBlurb = 'This is my new eSignature service, it allows me to get your signoff without having to fax, scan, retype, refile and wait forever';
envelope.AccountId = accountId;
// Render the contract
System.debug('Rendering the contract');
PageReference pageRef = new PageReference(url_file_ref);
Blob pdfBlob = pageRef.getContent();
DocuSignAPI.CustomField field = new DocuSignAPI.CustomField ();
field.Name = '##SFLead';
field.Value = lstLead[0].Id; //value of the external source Id
field.Show = 'false';
field.CustomFieldType = 'Text';
envelope.CustomFields = new DocuSignAPI.ArrayOfCustomField();
envelope.CustomFields.CustomField = new DocuSignAPI.CustomField[1];
envelope.CustomFields.CustomField[0] = field;
// Document
DocuSignAPI.Document document = new DocuSignAPI.Document();
document.ID = 1;
document.pdfBytes = EncodingUtil.base64Encode(pdfBlob);
document.Name = 'Annual Contract';
document.FileExtension = 'pdf';
envelope.Documents = new DocuSignAPI.ArrayOfDocument();
envelope.Documents.Document = new DocuSignAPI.Document[1];
envelope.Documents.Document[0] = document;
// Recipient
System.debug('Building up the recipient');
DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
recipient.ID = 1;
recipient.Type_x = 'Signer';
recipient.RoutingOrder = 1;
recipient.Email = lstLead[0].Email;
recipient.UserName = lstLead[0].FirstName + ' ' + lstLead[0].LastName;
recipient.RequireIDLookup = false;
envelope.Recipients = new DocuSignAPI.ArrayOfRecipient();
envelope.Recipients.Recipient = new DocuSignAPI.Recipient[1];
envelope.Recipients.Recipient[0] = recipient;
// Tab
DocuSignAPI.Tab tab1 = new DocuSignAPI.Tab();
tab1.Type_x = 'SignHere';
tab1.RecipientID = 1;
tab1.DocumentID = 1;
tab1.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab1.AnchorTabItem.AnchorTabString = '/t1/';
tab1.AnchorTabItem.XOffset = 100;
DocuSignAPI.Tab tab2 = new DocuSignAPI.Tab();
tab2.Type_x = 'DateSigned';
tab2.RecipientID = 1;
tab2.DocumentID = 1;
tab2.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab2.AnchorTabItem.AnchorTabString = '/d1/';
DocuSignAPI.Tab tab3 = new DocuSignAPI.Tab();
tab3.CustomTabType = 'Text';
tab3.Name = 'Title';
tab3.Type_x = 'Custom';
tab3.RecipientID = 1;
tab3.DocumentID = 1;
tab3.TabLabel = 'Title';
if(strObjType == 'Lead')
{
if(lstLead[0].Title != null)
{
tab3.Value = ''+lstLead[0].Title+'';
}
}
else
{
if(lstContact[0].Title != null)
{
tab3.Value = ''+lstContact[0].Title+'';
}
}
tab3.CustomTabWidth=100;
tab3.CustomTabRequired=false;
tab3.CustomTabLocked=false;
tab3.CustomTabDisableAutoSize=false;
tab3.TemplateLocked=false;
tab3.TemplateRequired=false;
tab3.ConditionalParentLabel='';
tab3.ConditionalParentValue='';
tab3.SharedTab=true;
tab3.RequireInitialOnSharedTabChange=false;
tab3.ConcealValueOnDocument=false;
tab3.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab3.AnchorTabItem.AnchorTabString = '/t2/';
tab3.AnchorTabItem.XOffset = 42;
tab3.AnchorTabItem.YOffset = -5;
tab3.MergeFieldXml = '<mergeField><allowSenderToEdit>true</allowSenderToEdit><configurationType>salesforce</configurationType><path>Lead.Title</path><row>1</row><writeBack>true</writeBack></mergeField>';
envelope.Tabs = new DocuSignAPI.ArrayOfTab();
envelope.Tabs.Tab = new DocuSignAPI.Tab[3];
envelope.Tabs.Tab[0] = tab1;
envelope.Tabs.Tab[1] = tab2;
envelope.Tabs.Tab[2] = tab3;
System.debug('Calling the API');
try {
DocuSignAPI.EnvelopeStatus es = dsApiSend.CreateAndSendEnvelope(envelope);
envelopeId = es.EnvelopeID;
System.debug('Returned successfully, envelope id = ' + envelopeId );
return '';
} catch ( CalloutException e) {
System.debug('Exception - ' + e );
envelopeId = 'Exception - ' + e;
return '';
}
return '';
}
}
I resolved the issue with the DocuSign support.
MergeFieldXml for SOAP should be like this:
tab3.MergeFieldXml ='<mergefieldconfig configversion="1.0" service="salesforce"><mergefield><writeenabled>true</writeenabled><sendercanedit>true</sendercanedit><queryfrom><obj><type>Lead</type><name>Lead</name><field><fieldtype>string</fieldtype><name>Title</name></field></obj></queryfrom></mergefield></mergefieldconfig>';

How to get Rates from UPS Rate API?

I am using nopcommerce 3.5. I have added plugin of UPS of TransitInTime and Rate API. I want to get rates by calling UPS Rate API. I want all Rates in dropdown on page load.
So for the first I am using test application using webservices of RateWebReference and in which I get only one Rate but I want Rates for all shipping option.
Here is my code of RateWSClient.cs
RateService rate = new RateService();
RateRequest rateRequest = new RateRequest();
UPSSecurity upss = new UPSSecurity();
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = "CC....";
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = "gi..";
upssUsrNameToken.Password = "Ch..";
upss.UsernameToken = upssUsrNameToken;
rate.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "Rate" };
request.RequestOption = requestOption;
rateRequest.Request = request;
ShipmentType shipment = new ShipmentType();
ShipperType shipper = new ShipperType();
shipper.ShipperNumber = "A65V88";
RateWSSample.RateWebReference1.AddressType shipperAddress = new RateWSSample.RateWebReference1.AddressType();
String[] addressLine = { "", "", "" };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "";
shipperAddress.PostalCode = "30076";
shipperAddress.StateProvinceCode = "GA";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipment.Shipper = shipper;
ShipFromType shipFrom = new ShipFromType();
RateWSSample.RateWebReference1.AddressType shipFromAddress = new RateWSSample.RateWebReference1.AddressType();
shipFromAddress.AddressLine = addressLine;
shipFromAddress.City = "";
shipFromAddress.PostalCode = "30076";
shipFromAddress.StateProvinceCode = "GA";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipment.ShipFrom = shipFrom;
ShipToType shipTo = new ShipToType();
ShipToAddressType shipToAddress = new ShipToAddressType();
String[] addressLine1 = { "", "", "" };
shipToAddress.AddressLine = addressLine1;
shipToAddress.City = "";
shipToAddress.PostalCode = "92262";
shipToAddress.StateProvinceCode = "";
shipToAddress.CountryCode = "US";
shipTo.Address = shipToAddress;
shipment.ShipTo = shipTo;
CodeDescriptionType service = new CodeDescriptionType();
//Below code uses dummy date for reference. Please udpate as required.
service.Code = "02";
shipment.Service = service;
PackageType package = new PackageType();
PackageWeightType packageWeight = new PackageWeightType();
packageWeight.Weight = "125";
CodeDescriptionType uom = new CodeDescriptionType();
uom.Code = "LBS";
uom.Description = "pounds";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;
CodeDescriptionType packType = new CodeDescriptionType();
packType.Code = "02";
package.PackagingType = packType;
PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
//Shipping Rate Chart
// ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
//SRO.RateChartIndicator = "";
//shipment.ShipmentRatingOptions= SRO;
//rateRequest.Shipment = shipment;
ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
SRO.NegotiatedRatesIndicator = "";
shipment.ShipmentRatingOptions = SRO;
rateRequest.Shipment = shipment;
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
Console.WriteLine(rateRequest);
RateResponse rateResponse = rate.ProcessRate(rateRequest);
Console.WriteLine("The transaction was a " + rateResponse.Response.ResponseStatus.Description);
Console.WriteLine("Total Shipment Charges " + rateResponse.RatedShipment[0].TotalCharges.MonetaryValue + rateResponse.RatedShipment[0].TotalCharges.CurrencyCode);
Console.ReadKey();
I have resolved this questions. So If you face this kind of problem don't forget to use
String[] requestOption = { "Shop" };
in place of
String[] requestOption = { "Rate" };
Then you will get rates for all shipping options.

Implementing pagination

I have the following action
public ActionResult ViewModelProducts()
{
var listOfProductsBuy = db.ProductsBuy.Select(x => new ProductBuyViewModel
{
Id = x.Id,
Title = x.Title,
ProductBuyId = x.Id,
Author = x.Author,
MasterImageUrl = x.Images.FirstOrDefault().Url,
Price = x.Price,
Values = x.Value,
}).ToList();
var listOfProductsRent = db.ProductsRent.Select(y => new ProductRentViewModel
{
Id = y.Id,
Title = y.Title,
MasterImageUrl = y.ImagesRent.FirstOrDefault().Url,
ProductRentId = y.Id,
Author = y.Author,
Period = y.Period.PeriodOfTime,
Price = y.Price,
Values = y.Value,
}).ToList();
var listOfProductsSearch = db.ProductSearches.Select(z => new ProductSearchViewModel
{
Id = z.Id,
Title = z.Title,
ProductSearchId = z.Id,
Author = z.Author,
MasterImageUrl = z.ImagesSearch.FirstOrDefault().Url,
Price = z.Price,
Values = z.Value,
}).ToList();
var viewModel = new AllProductsViewModel { ProductBuy = listOfProductsBuy, ProductRent = listOfProductsRent, ProductSearch = listOfProductsSearch};
return View(viewModel);
}
I want to implement paging for more than one viewmodel. If there is way with PagedList it will be better, but if there is not it will be ok too.
In order to add paging, you can install PagedList.MVC Nuget package. You can see the exact step by step procedure to add it on Microsoft website here. Check out the section named: "Add Paging to the Students Index Page". Hope this helps.

Restkit response mapping for get API

I'm new for Restkit response mapping. I'm not able to map it properly. I have Event and Venue model with all necessary attributes. Could any one set request mapping for it.
Thanks in advance.
*Printing description of mappingResult:
<RKMappingResult: 0x7b1e2da0, results={
"" = {
events = (
{
date = "Saturday,17 Jan 2015";
"event_list" = (
{
"already_attending" = 0;
attending = 1;
description = "<null>";
"event_end_date" = "Saturday,17 Jan 2015 07:30pm";
"event_start_date" = "Saturday,17 Jan 2015 07:30pm";
id = 54b3e2fe7265646a782f0000;
"is_limited" = 1;
"is_private_community_event" = 1;
name = Drinks;
picture = "http://veozen.systech-soft.com/pictures/original/missing.png";
"user_picture" = "http://veozen.systech-soft.com/profile_pictures/original/missing.png";
venue = {
latitude = "51.505968";
longitude = "-0.027865";
"venue_address" = "4.3";
"venue_name" = "Cafe Brera";
"venue_picture" = "https://maps.googleapis.com/maps/api/place/photo?photoreference=CnRnAAAAZk6z2twchk-xU6AGo-ZwK6ykDWTsf6LWh6TjX0ho7K5gLqr4-FkAtGpSr9MNK4Ytc7ejQerAvTO7w2_-fFUoTFF_W_vG3isNz3rKzxf-WMep-VC2loBE2Exmt4Lbr8q4kTKdwUNpckm5Lqy1b7UXTBIQeZjov6oDTrT21gjtv0XzYBoUetjjOaRuGeX262g6k4V8U0-o1H8&key=AIzaSyDfB1L32kL2bgdd0Wz5IJTeI0OiHONLmbQ&sensor=false&maxwidth=320";
};
}
);
}
);
};
}>*