Last active
May 1, 2024 18:05
-
-
Save ChrisMoney/2095e0b7c978f3e097abb6aedb64ac53 to your computer and use it in GitHub Desktop.
ESL Sign Pairing - Pair digital sign with updated price data from API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Associate (link/bind) an ESL to an item | |
/// </summary> | |
/// <param name="store">Store Number</param> | |
/// <param name="itemID">Item Identifier</param> | |
/// <param name="eslID">ESL Identifier</param> | |
/// <returns>Link response</returns> | |
public HanshowIntegrationResponse Pair(int store, string itemID, string eslID, string useFamilyDescription, string userId) | |
{ | |
try | |
{ | |
//Ideally we would log this if we see a success from hanshow. | |
// Todo confirm success in the future | |
try | |
{ | |
Task.Run(() => LogESLPairing(store, eslID, ServicesConstants.ESLLogStatus.ESLPaired, userId)); | |
} | |
catch | |
{ | |
//Do nothing. This should not have an affect on any processes | |
} | |
var serviceURL = $"/esl/update-bind/schnucks/{store}"; | |
var linkRequest = new HanshowLinkRequest(store, itemID.ToString(), eslID, useFamilyDescription); | |
var t = DateTime.Now; | |
var response = new HanshowAPIUtilities().PostAPI<HanshowIntegrationResponse, HanshowLinkRequest>(serviceURL, linkRequest); | |
//// Temporary conditional logging -- remove once we had a application monitoring tool | |
if (new SystemAttributeFactory().GetSystemAttributeByAttributeID(SystemAttributeName.LogESLPairingResponseTime).AttributeValue == "Y") | |
{ | |
new DirectEventLogHandler().SendMessageToEventLog($"Hanshow ESL Pairing Response Time : {DateTime.Now.Subtract(t).Milliseconds} ms" + " | Store : " + store + " | ESL ID : " + eslID); | |
} | |
return response; | |
} | |
catch (WebException ex) | |
{ | |
throw new Exception("Error linking ESL.", ex); | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception("Error linking ESL.", ex); | |
} | |
} | |
/// </summary> | |
/// <param name="store">Store Number</param> | |
/// <param name="itemID">Item Identifier</param> | |
/// <param name="eslID">ESL Identifier</param> | |
/// <returns>Link response</returns> | |
public HanshowIntegrationResponse PairLocationTag(int store, string LocationCode, string LocationText, string eslID, string userId) | |
{ | |
try | |
{ | |
//Ideally we would log this if we see a success from hanshow. | |
// Todo confirm success in the future | |
try | |
{ | |
Task.Run(() => LogESLPairing(store, eslID, ServicesConstants.ESLLogStatus.ESLPaired, userId)); | |
} | |
catch | |
{ | |
//Do nothing. This should not have an affect on any processes | |
} | |
var serviceURL = $"/esl/update-bind/schnucks/{store}"; | |
var linkRequest = new HanshowLocationLinkRequest(store, LocationCode, LocationText, eslID); | |
var response = new HanshowAPIUtilities().PostAPI<HanshowIntegrationResponse, HanshowLocationLinkRequest>(serviceURL, linkRequest); | |
return response; | |
} | |
catch (WebException ex) | |
{ | |
throw new Exception("Error linking ESL.", ex); | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception("Error linking ESL.", ex); | |
} | |
} | |
/// <summary> | |
/// Disassociate (unlink/unbind) an ESL with an item | |
/// </summary> | |
/// <param name="store">Store Number</param> | |
/// <param name="itemID">Item Identifier</param> | |
/// <param name="eslID">ESL Identifier</param> | |
/// <returns>Unlink response</returns> | |
public HanshowESLResponse Unpair(int store, string eslID, string userId) | |
{ | |
try | |
{ | |
var environment = Connections.GetEnvironment(); | |
//Ideally we would log this if we see a success from hanshow. | |
// Todo confirm success in the future | |
try | |
{ | |
Task.Run(() => LogESLPairing(store, eslID, ServicesConstants.ESLLogStatus.ESLUnpaired, userId)); | |
} | |
catch | |
{ | |
//Do nothing. This should not have an affect on any processes | |
} | |
if (environment.LongName.ToUpper() == "PRODUCTION") | |
{ | |
var serviceURL = $"/esl/unbind;jsessionid={new StoreFactory().GetStoreJSessionID(store)}"; | |
var unlinkRequest = new List<HanshowUnlinkRequest>() | |
{ | |
new HanshowUnlinkRequest(eslID) | |
}; | |
var response = new HanshowAPIUtilities().PostAPI<HanshowESLResponse, List<HanshowUnlinkRequest>>(serviceURL, unlinkRequest); | |
return response; | |
} | |
else | |
return new HanshowESLResponse(); | |
} | |
catch (WebException ex) | |
{ | |
throw new Exception("Error unlinking ESL.", ex); | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception("Error unlinking ESL.", ex); | |
} | |
} | |
public HanshowLabelResponse GetLabelsByEslID(int store, string eslID) | |
{ | |
try | |
{ | |
var serviceURL = $"/esl/getPr;jsessionid={new StoreFactory().GetStoreJSessionID(store)}"; | |
var labelRequest = new List<HanshowLabelRequestByLabel>() | |
{ | |
new HanshowLabelRequestByLabel(eslID) | |
}; | |
var response = new HanshowAPIUtilities().PostAPI<HanshowLabelResponse, List<HanshowLabelRequestByLabel>>(serviceURL, labelRequest); | |
return response; | |
} | |
catch (WebException ex) | |
{ | |
throw new Exception("Error getting ESL.", ex); | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception("Error getting ESL.", ex); | |
} | |
} | |
public HanshowESLResponse FlashEslLabelsByItem(int store, string itemID, int loopCount, HandshowColors color) | |
{ | |
try | |
{ | |
HanshowESLResponse response; | |
var serviceURL = $"/esl/setEslControl;jsessionid={new StoreFactory().GetStoreJSessionID(store)}"; | |
var labels = GetLabelsByItemID(store, itemID); | |
if (labels.data[0].eslId == null) | |
{ | |
// We will get no response from hanshow here because there is no ESL ID to pass | |
// So create our own response for consumers | |
response = new HanshowESLResponse | |
{ | |
result = "failed", | |
message = "No ESL paired to item." | |
}; | |
} | |
else | |
{ | |
var flashingRequests = new List<HanshowFlashRequest>(); | |
foreach (ShelfMan.Models.ESL.Hanshow.Datum label in labels.data) | |
{ | |
flashingRequests.Add(new HanshowFlashRequest(label.eslId.ToString(), color, loopCount)); | |
} | |
response = new HanshowAPIUtilities().PostAPI<HanshowESLResponse, List<HanshowFlashRequest>>(serviceURL, flashingRequests); | |
} | |
return response; | |
} | |
catch (WebException ex) | |
{ | |
throw new Exception("Error flashing ESL.", ex); | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception("Error flashing ESL.", ex); | |
} | |
} | |
private void LogESLPairing(int store, string eslID, ServicesConstants.ESLLogStatus logStatus, string userId) | |
{ | |
ServicesFunctions servicesFunctions = new ServicesFunctions(); | |
servicesFunctions.PutESLLog(store, eslID, logStatus, userId); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment