using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { Singleton SingletonObject = Singleton.GetObject(); SingletonObject.Print("How World"); //Here created the new object and print the value Singleton SingletonObject1 = Singleton.GetObject(); SingletonObject1.Print("Hi World"); //Here using the existing object and print the value Singleton SingletonObject2 = Singleton.GetObject(); SingletonObject2.Print("Code World"); //Here using the existing object and print the value Console.ReadLine(); } } public class Singleton { protected static Singleton _obj ; private Singleton() { } public static Singleton GetObject() { if (_obj == null) { Console.WriteLine(5); //First time print the value _obj = new Singleton(); //Here object created for first time only, when _obj value is null, if _obj is not null then it's using the same object with out creating new one(Object) } if (_obj != null) { Console.WriteLine(10); //Rest of time using same object and here _obj value is not null, So it's print the value first too } return _obj; } public void Print(string s) { Console.WriteLine(s); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { Singleton SingletonObject = Singleton.GetObject(); SingletonObject.Print("How World"); Singleton SingletonObject1 = Singleton.GetObject(); SingletonObject1.Print("Hi World"); Singleton SingletonObject2 = Singleton.GetObject(); SingletonObject2.Print("Code World"); Console.ReadLine(); } } public class Singleton { protected static Singleton _obj ; private Singleton() { } public static Singleton GetObject() { if (_obj == null) { Console.WriteLine(5); _obj = new Singleton(); } if (_obj != null) { Console.WriteLine(10); } return _obj; } public void Print(string s) { Console.WriteLine(s); } } }
using System; namespace RectangleApplication { class Rectangle { // member variables double length; double width; public void Acceptdetails() { length = 56.2; width = 23.6; } public double GetArea() { return length * width; } public void Display() { Console.WriteLine("长度: "+ length); Console.WriteLine("宽度: "+ width); Console.WriteLine("面积: "+ GetArea()); } } class ExecuteRectangle { static void Main(string[] args) { Rectangle r = new Rectangle(); r.Acceptdetails(); r.Display(); Console.ReadLine(); } } }
using System.IO; using System; class Program { static void Main() { Console.WriteLine("Hello, World!"); } }
using System; public class pnz { public static void Main() { int num; Console.Write("\n\n"); Console.Write("Check whether a number is positive or negative:\n"); Console.Write("----------------------------------------------"); Console.Write("\n\n"); Console.Write("Input an integer : "); num= Convert.ToInt32(Console.ReadLine()); if (num >= 0) Console.WriteLine("{0} is a positive number.\n",num); else Console.WriteLine("{0} is a negative number. \n", num); } }
using System.IO; using System; class Program { static void Main() { int value = 511; Console.WriteLine("value={0}, SetBits={1}", value, CountSetBits(value)); } static public int CountSetBits(int value) { int x = value; x = (x & 0x55555555) + ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); x = (x & 0x0000FFFF) + ((x >> 16)& 0x0000FFFF); return x; } }
using System.IO; using System; class Program { static void Main() { Console.WriteLine("Hello, World!"); Console.WriteLine("Hello again."); } }
using System.IO; using System; class Program { static void Main() { //ulong a = 76561198139571510; byte[ ] byteArray = BitConverter.GetBytes(76561198139571510); Console.WriteLine(BitConverter.GetBytes(76561198139571510)); //a = a << 1; //Console.WriteLine("{0}",a); } }
using System; namespace HelloWorldApplication { class HelloWorld { static void Main(string[] args) { /* my first program in C# */ Console.WriteLine("Hello World"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using FinIQ.SVCLib.Core.DB; using FinIQ.NDLib.Core.ExtendedMethods; using FinIQ.SVCLib.Core.Com; using FinIQ.DataContracts.EDistRateFeed; using FinIQ.DB_Provider.EDistRateFeed; using FinIQ.DataContracts.INTMap; using FinIQ.SVCLib.Core.Util; using System.Net; using System.IO; using System.Web.Script.Serialization; using System.Collections; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Net.Http; using FinIQ.Services.EDistRateFeed.ServiceProvider; using FinIQ.NDLib.Core.Com; using FinIQ.NDLib.Core.SysUtil; namespace FinIQ.Services.EDistRateFeed { class EDistRateFeed : IEDistRateFeed { FinIQ.NDLib.Core.Com.Logger oLogger; Logger oLogger_ISR; Logger oLogger_DealEntry; static DateTime previousUpdatedAt_DealEntry = DateTime.MinValue; static DateTime previousUpdatedAt_ISR = DateTime.MinValue; static DateTime UpdatedAt_DealEntry = DateTime.MinValue; static DateTime UpdatedAt_ISR = DateTime.MinValue; public EDistRateFeed() { } public string Save_Spot_Rate_Feed(EDistFeedRateDTO[] arrEDistRateFeed) { try { DB_EDistRateFeed objEDistRateFeed = new DB_EDistRateFeed(); return objEDistRateFeed.DB_Save_EDist_Rate_Feed(arrEDistRateFeed); } catch (Exception ex) { throw new FinIQServiceException(ex, "Error occurred at Save_EDist_Rate_Feed : " + ex.Message); } } public bool Save_FX_Tier_Spread(SpreadManagementDTO[] arrSpreadData, string instrument, string SourceSystem, long EntityId, string UserId) { try { DB_EDistRateFeed objSpread = new DB_EDistRateFeed(); return objSpread.DB_Save_FX_Tier_Spread(arrSpreadData, instrument, SourceSystem, EntityId, UserId); } catch (Exception ex) { throw new FinIQServiceException(ex, "Error occurred at Save_FX_Tier_Spread : " + ex.Message); } } public bool Save_FX_EOD_Rates(long EntityId, string UserId) { try { DB_EDistRateFeed objRate = new DB_EDistRateFeed(); return objRate.DB_Save_FX_EOD_Rates(EntityId, UserId); } catch (Exception ex) { throw new FinIQServiceException(ex, "Error occurred at Save_FX_EOD_Rates : " + ex.Message); } } public CrossDefDTO[] CrossDef() { try { DB_EDistRateFeed objcrossdef = new DB_EDistRateFeed(); return objcrossdef.DB_CrossDef(); } catch (Exception ex) { throw new FinIQServiceException(ex, "Error occurred at CrossDef : " + ex.Message); } } public RateFeedStatusDTO[] GetRateFeedRunningStatus(int ThresholdToAlertOpsInSecond) { try { DB_EDistRateFeed objEDistRateFeed = new DB_EDistRateFeed(); return objEDistRateFeed.DB_GetRateFeedRunningStatus(ThresholdToAlertOpsInSecond).ToList<RateFeedStatusDTO>().ToArray(); } catch (Exception ex) { throw new FinIQServiceException(ex); } } public EDistFeedRateDTO[] GetNonCrossRates() { try { DB_EDistRateFeed objEDistRateFeed = new DB_EDistRateFeed(); return objEDistRateFeed.DB_GetNonCrossRates().ToList<EDistFeedRateDTO>().ToArray(); } catch (Exception ex) { throw new FinIQServiceException(ex); } } public bool InitiateFXTierSpreadSaving(SPMParamsDTO oParams) { FinIQFTPTemplateDetailsDTO oINTMAP; string SpreadJSONData = string.Empty; try { InitializeLogger("SpreadImport", oParams.LoginID); oLogger.LogDebugMessage("Request received for SPM spread refresh."); oLogger.LogDebugMessage(oParams.TryGetXML()); oINTMAP = GetINTMAPSetting(oParams.TemplateCode, oParams.EventCode, oParams.ProductCode, oParams.EntityID); SpreadJSONData = GetSpreadDataFromAPI(oParams, oINTMAP); if (!string.IsNullOrEmpty(SpreadJSONData)) { return ParseAndSaveSpreadData(oParams, SpreadJSONData); } else { return false; } } catch (Exception ex) { throw new FinIQServiceException(ex); } } public bool RefreshConfigurationCache() { try { FinIQ.SVCLib.Core.LSS.FINIQ_ENTITY_CONFIG.Instance().LoadConfigs(); return true; } catch (Exception) { return false; } } private string getSpreadRequestData(string Instrument, string Channel) { StringBuilder strRestRequestData; try { oLogger.LogDebugMessage("getSpreadRequestData : passing paramters to url in json format"); strRestRequestData = new StringBuilder(); strRestRequestData.Append("{"); strRestRequestData.Append("\"instrument\":\"" + Instrument.Trim() + "\","); strRestRequestData.Append("\"channel\":\"" + Channel.Trim() + "\"}"); oLogger.LogDebugMessage("getSpreadRequestData : Parameters " + Instrument + " & " + Channel + " passed successfully to URL. "); return strRestRequestData.ToString(); } catch (Exception) { oLogger.LogErrorMessage("getSpreadRequestData : Error while passing parameters" + Instrument + "&" + Channel + " to URL in json format"); throw; } } private string GetSpreadDataFromAPI(SPMParamsDTO oParams, FinIQFTPTemplateDetailsDTO oINTMAP) { WebRequest oWebRequest; HttpWebRequest oHttpWebRequest; HttpWebResponse webResp = null; Stream oStream; StreamWriter oStreamWriter; StreamReader oStreamReader; string SpreadPairData = string.Empty; string strReaderStream = String.Empty; string SPMFeedClientCeritifacteName = string.Empty; string _PerformCertificateBasedSPMFeedAuthentication = string.Empty; bool PerformCertificateBasedSPMFeedAuthentication = false; try { oWebRequest = WebRequest.Create(oINTMAP.FTPServerName.Trim()); oLogger.LogInformationMessage("SPM URL for feed Interface : " + oINTMAP.FTPServerName.Trim()); oHttpWebRequest = (HttpWebRequest)oWebRequest; oHttpWebRequest.Method = "POST"; oHttpWebRequest.Accept = "application/json"; oHttpWebRequest.ContentType = "application/json"; oHttpWebRequest.Credentials = CredentialCache.DefaultCredentials; ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); _PerformCertificateBasedSPMFeedAuthentication = SVCLib.Core.LSS.FINIQ_ENTITY_CONFIG.Instance().GetConfigValue("PerformCertificateBasedSPMFeedAuthentication", oParams.EntityID); switch (_PerformCertificateBasedSPMFeedAuthentication.ToUpper().Trim()) { case "Y": case "YES": PerformCertificateBasedSPMFeedAuthentication = true; break; default: PerformCertificateBasedSPMFeedAuthentication = false; break; } SPMFeedClientCeritifacteName = SVCLib.Core.LSS.FINIQ_ENTITY_CONFIG.Instance().GetConfigValue("SPMFeedClientCeritifacteName", oParams.EntityID); if (PerformCertificateBasedSPMFeedAuthentication) { oHttpWebRequest.ClientCertificates.Add(GetClientCertificate(SPMFeedClientCeritifacteName)); } oStream = oHttpWebRequest.GetRequestStream(); oStreamWriter = new StreamWriter(oStream, Encoding.ASCII); oStreamWriter.Write(getSpreadRequestData(oParams.Instrument, oParams.Channel)); oStreamWriter.Flush(); oStreamWriter.Close(); try { oLogger.WriteMethodBeginDebugSymbol(); oLogger.LogDebugMessage("GetSpreadDataFromAPI : calling rest api for spread rates."); #if DEBUG oWebRequest = WebRequest.Create("https://localhost/FinIQService/Server_EDistRateFeed_Json.svc/Server_Get_Spread_Json?channel=Mighty&instrument=FXC"); #else webResp = (HttpWebResponse)oHttpWebRequest.GetResponse(); #endif } catch (WebException ex) { #if DEBUG #else using (WebResponse response = ex.Response) { var httpResponse = (HttpWebResponse)response; using (Stream data = response.GetResponseStream()) { StreamReader sr = new StreamReader(data); throw new Exception(sr.ReadToEnd()); } } #endif } #if DEBUG oStreamReader = GetDummyData(); #else oStreamReader = new StreamReader(webResp.GetResponseStream()); #endif strReaderStream = oStreamReader.ReadToEnd().ToString(); oLogger.LogDebugMessage("Spread JSON data recieved : " + strReaderStream); return strReaderStream; } catch (Exception) { oLogger.LogErrorMessage("GetSpreadDatafromRestAPI : Error while receiving spread JSON data from API."); throw; } finally { oLogger.WriteMethodEndDebugSymbol(); oStream = null; oStreamWriter = null; strReaderStream = null; } } public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; } private FinIQFTPTemplateDetailsDTO GetINTMAPSetting(string TemplateCode, string EventCode, string ProductCode, long EntityId) { FinIQ.Services.INTMAP.FinIQINTMAPService oINTMAPService; try { oLogger.WriteMethodBeginDebugSymbol(); oLogger.LogDebugMessage("GetINTMAPSetting : Reading INTMAP Setting parameters."); oINTMAPService = new INTMAP.FinIQINTMAPService(); oLogger.LogDebugMessage("INTMAP Parameters reading completed."); return oINTMAPService.GetFTPTemplateInfo(TemplateCode, Convert.ToInt32(EntityId), ProductCode, EventCode); } catch (Exception) { throw; } finally { oINTMAPService = null; oLogger.WriteMethodEndDebugSymbol(); } } private bool ParseAndSaveSpreadData(SPMParamsDTO oParams, string SpreadJSONData) { JavaScriptSerializer oJavaScriptSerializer; List<SpreadManagementDTO> objSpreadData; StringBuilder combindedString = new StringBuilder(); SpreadManagementDTO objSpreadDetails = null; try { oLogger.LogDebugMessage("Spread JSON received : " + SpreadJSONData); oJavaScriptSerializer = new JavaScriptSerializer(); objSpreadData = new List<SpreadManagementDTO>(); dynamic objSpreadJson = oJavaScriptSerializer.Deserialize<dynamic>(SpreadJSONData); oLogger.LogDebugMessage("ParseAndSaveSpreadData() : Parsing of JSON Spread data done successfully. Adding parsed data to datacontract."); for (int iRecordNumber = 0; iRecordNumber < ((ICollection)objSpreadJson).Count; iRecordNumber++) { try { objSpreadDetails = new SpreadManagementDTO(); objSpreadDetails.id = (objSpreadJson[iRecordNumber]["id"] == null ? 0 : Int32.Parse(objSpreadJson[iRecordNumber]["id"].ToString())); objSpreadDetails.channel = (objSpreadJson[iRecordNumber]["channel"] == null ? string.Empty : objSpreadDetails.channel = objSpreadJson[iRecordNumber]["channel"].ToString()); objSpreadDetails.instrument = (objSpreadJson[iRecordNumber]["instrument"] == null ? string.Empty : objSpreadDetails.instrument = objSpreadJson[iRecordNumber]["instrument"].ToString()); objSpreadDetails.product = (objSpreadJson[iRecordNumber]["product"] == null ? string.Empty : objSpreadJson[iRecordNumber]["product"].ToString()); objSpreadDetails.segment = (objSpreadJson[iRecordNumber]["segment"] == null ? string.Empty : objSpreadJson[iRecordNumber]["segment"].ToString()); objSpreadDetails.tier = (objSpreadJson[iRecordNumber]["tier"] == null ? string.Empty : objSpreadJson[iRecordNumber]["tier"].ToString()); objSpreadDetails.schedule = (objSpreadJson[iRecordNumber]["schedule"] == null ? string.Empty : objSpreadJson[iRecordNumber]["schedule"].ToString()); objSpreadDetails.tenor = (objSpreadJson[iRecordNumber]["tenor"] == null ? string.Empty : objSpreadJson[iRecordNumber]["tenor"].ToString()); objSpreadDetails.interpolation = (objSpreadJson[iRecordNumber]["interpolation"] == null ? string.Empty : objSpreadJson[iRecordNumber]["interpolation"].ToString()); objSpreadDetails.ccy1 = objSpreadJson[iRecordNumber]["ccy1"].ToString(); objSpreadDetails.ccy2 = objSpreadJson[iRecordNumber]["ccy2"].ToString(); objSpreadDetails.bid = (objSpreadJson[iRecordNumber]["bid"] == null ? string.Empty : Convert.ToDouble(objSpreadJson[iRecordNumber]["bid"].ToString())); objSpreadDetails.ask = (objSpreadJson[iRecordNumber]["ask"] == null ? string.Empty : Convert.ToDouble(objSpreadJson[iRecordNumber]["ask"].ToString())); objSpreadDetails.minAmt = (objSpreadJson[iRecordNumber]["min"] == null ? string.Empty : Convert.ToDouble(objSpreadJson[iRecordNumber]["min"].ToString())); objSpreadDetails.maxAmt = (objSpreadJson[iRecordNumber]["max"] == null ? string.Empty : Convert.ToDouble(objSpreadJson[iRecordNumber]["max"].ToString())); objSpreadDetails.createdOn = (objSpreadJson[iRecordNumber]["createdOn"] == null ? null : ParseJsonMillisecondsToDateTime(Convert.ToDouble(objSpreadJson[iRecordNumber]["createdOn"]))); objSpreadDetails.createdBy = (objSpreadJson[iRecordNumber]["createdBy"] == null ? string.Empty : objSpreadJson[iRecordNumber]["createdBy"].ToString()); objSpreadDetails.updatedOn = (objSpreadJson[iRecordNumber]["updatedOn"] == null ? null : ParseJsonMillisecondsToDateTime(Convert.ToDouble(objSpreadJson[iRecordNumber]["updatedOn"]))); objSpreadDetails.updatedBy = (objSpreadJson[iRecordNumber]["updatedBy"] == null ? string.Empty : objSpreadJson[iRecordNumber]["updatedBy"].ToString()); objSpreadDetails.deleted = (objSpreadJson[iRecordNumber]["deleted"] == null ? string.Empty : objSpreadJson[iRecordNumber]["deleted"].ToString()); objSpreadDetails.createdById = (objSpreadJson[iRecordNumber]["createdById"] == null ? string.Empty : objSpreadJson[iRecordNumber]["createdById"].ToString()); objSpreadDetails.updatedById = (objSpreadJson[iRecordNumber]["updatedById"] == null ? string.Empty : objSpreadJson[iRecordNumber]["updatedById"].ToString()); objSpreadDetails.valid = (objSpreadJson[iRecordNumber]["valid"] == null ? string.Empty : objSpreadJson[iRecordNumber]["valid"].ToString()); objSpreadData.Add(objSpreadDetails); } catch (Exception ex) { oLogger.LogErrorMessage("Error while processing record number " + (iRecordNumber + 1) + " : " + ex.GetBaseException().Message); continue; } } oLogger.LogDebugMessage("ParseAndSaveSpreadData (): <Records Count> : " + objSpreadData.Count + " Record(s) Prepared for database saving : " + "\r\n" + objSpreadData.ToArray().TryGetXML()); if (objSpreadData.Count > 0) { DB_EDistRateFeed objSpread = new DB_EDistRateFeed(); if (objSpread.DB_Save_FX_Tier_Spread(objSpreadData.ToArray(), oParams.Instrument, oParams.Channel, oParams.EntityID, oParams.LoginID)) { try { oLogger.LogDebugMessage("DB_Save_FX_Tier_Spread () function executed successfully."); Thread tTargetRefresh = new Thread(RefreshTargetRates); tTargetRefresh.Start(); } catch (Exception) { oLogger.LogDebugMessage("Error while executing DB_Save_FX_Tier_Spread () function."); } return true; } else { return false; } } else { return false; } } catch (Exception ex) { oLogger.LogErrorMessage("Error whie ParseAndSaveSpreadData : " + ex.GetBaseException().Message); oLogger.LogErrorMessage("Stack Trace : " + ex.StackTrace.ToString()); return false; } finally { oJavaScriptSerializer = null; objSpreadData = null; } } internal X509Certificate2 GetClientCertificate(string SPMFeedClientCeritifacteName) { X509Store userCaStore = new X509Store(StoreName.My, StoreLocation.LocalMachine); X509Certificate2 clientCertificate = null; string[] CertificateThumbPrint = null; bool IsSuccess = false; try { oLogger.WriteMethodBeginDebugSymbol(); oLogger.LogInformationMessage("Fetching certificate details for Thumbprint : '" + SPMFeedClientCeritifacteName + "'."); userCaStore.Open(OpenFlags.ReadOnly); X509Certificate2Collection certificatesInStore = userCaStore.Certificates; if (certificatesInStore != null && certificatesInStore.Count > 0) { oLogger.LogInformationMessage("Total " + certificatesInStore.Count + " certificate available in store."); CertificateThumbPrint = SPMFeedClientCeritifacteName.Split(';').ToArray(); foreach (string certThumbPrint in CertificateThumbPrint) { X509Certificate2Collection findResult = certificatesInStore.Find(X509FindType.FindByThumbprint, certThumbPrint, true); if (findResult.Count == 1) { oLogger.LogInformationMessage("Certificate found for Thumbprint : " + certThumbPrint + "."); clientCertificate = findResult[0]; IsSuccess = true; } else { oLogger.LogDebugMessage("Unable to locate the client certificate for Thumbprint : " + certThumbPrint + "."); } } if (IsSuccess) { return clientCertificate; } else { throw new Exception("Unable to locate the client certificate."); } } else { throw new Exception("No certificate found in Certificate Store."); } } catch (Exception ex) { oLogger.LogErrorMessage(ex.GetBaseException().Message); throw; } finally { userCaStore.Close(); oLogger.WriteMethodEndDebugSymbol(); } } public void InitializeLogger(string Mode, string LoginId) { try { oLogger = new FinIQ.NDLib.Core.Com.Logger(LoginId, Mode, "", System.IO.Path.GetDirectoryName(FINIQ_INI_READER.Instance().Read("LOG", "ServiceLogPath")), false, FINIQ_INI_READER.Instance().Read("LOG", "LogLevel"), FINIQ_INI_READER.Instance().Read("LOG", "WriteLogFileFormat")); if (FINIQ_INI_READER.Instance().Read("LOG", "ControlLogFileGrowth", "NO") == "YES" || FINIQ_INI_READER.Instance().Read("LOG", "ControlLogFileGrowth", "NO") == "Y") { oLogger.SetLogSizeControlParams(true, Convert.ToInt32(FINIQ_INI_READER.Instance().Read("LOG", "MaximumSizeAllowedForLogFileInKiloBytes", "1024"))); } } catch (Exception) { oLogger = new FinIQ.NDLib.Core.Com.Logger(LoginId, Mode, "", System.IO.Path.GetDirectoryName(FINIQ_INI_READER.Instance().Read("LOG", "ServiceLogPath")), false, "DEBUG", "INTERNAL"); } } //Saurabh Panjwani 22-01-2019 internal static Logger InitializeLogger_ICX(string SystemName, string LoginID = "Auto", bool AppendUID = false) { FinIQ.NDLib.Core.Com.Logger oLogger = null; try { oLogger = new FinIQ.NDLib.Core.Com.Logger(LoginID, SystemName, "", System.IO.Path.GetDirectoryName(FINIQ_INI_READER.Instance().Read("LOG", "ServiceLogPath")), false, FINIQ_INI_READER.Instance().Read("LOG", "LogLevel"), FINIQ_INI_READER.Instance().Read("LOG", "WriteLogFileFormat"), AppendUID); if (FINIQ_INI_READER.Instance().Read("LOG", "ControlLogFileGrowth", "NO") == "YES" || FINIQ_INI_READER.Instance().Read("LOG", "ControlLogFileGrowth", "NO") == "Y") oLogger.SetLogSizeControlParams(true, Convert.ToInt32(FINIQ_INI_READER.Instance().Read("LOG", "MaximumSizeAllowedForLogFileInKiloBytes", "1024"))); return oLogger; } catch (Exception) { oLogger = new FinIQ.NDLib.Core.Com.Logger(LoginID, SystemName, "", System.IO.Path.GetDirectoryName(FINIQ_INI_READER.Instance().Read("LOG", "ServiceLogPath")), false, "DEBUG", "INTERNAL"); if (FINIQ_INI_READER.Instance().Read("LOG", "ControlLogFileGrowth", "NO") == "YES" || FINIQ_INI_READER.Instance().Read("LOG", "ControlLogFileGrowth", "NO") == "Y") oLogger.SetLogSizeControlParams(true, Convert.ToInt32(FINIQ_INI_READER.Instance().Read("LOG", "MaximumSizeAllowedForLogFileInKiloBytes", "1024"))); return oLogger; } } // ---------------------------------------------------------------------------------------- private DateTime ParseJsonMillisecondsToDateTime(double MiliSeconds) { DateTime parsedDateTime; try { parsedDateTime = new DateTime(1970, 1, 1); parsedDateTime = parsedDateTime.AddMilliseconds(MiliSeconds); } catch (Exception ex) { oLogger.LogWarningMessage("Parsing JSON datetime object failed. returning current date time." + ex.ToString()); parsedDateTime = DateTime.Now; } return parsedDateTime; } private void RefreshTargetRates() { DB_EDistRateFeed oDBClass; try { InitializeLogger("RefreshLimitOrders", "SYSTEM"); oDBClass = new DB_EDistRateFeed(); oDBClass.DB_RefreshLimitOrderTarget(); } catch (Exception ex) { oLogger.LogErrorMessage("Error while RefreshTargetRates : " + ex.GetBaseException().Message); oLogger.LogErrorMessage("Stack Trace : " + ex.StackTrace.ToString()); } } public RateDistributionFeedSetup[] GetRateFeedDetails(string FeedSubType, bool RateFeed_UseCurrencyPair_With_Tenor_SwapFeed_Subscription) { try { DB_EDistRateFeed objcrossdef = new DB_EDistRateFeed(); return objcrossdef.DB_RateDistributionFeedSetup_Details(FeedSubType, RateFeed_UseCurrencyPair_With_Tenor_SwapFeed_Subscription).ToList<RateDistributionFeedSetup>().ToArray(); } catch (Exception ex) { throw new FinIQServiceException(ex, "Error occurred while extracting data from RateDistributionFeedSetup : " + ex.Message); } } public string Save_Rate_Feed_Generic(EDistFeedRateDTO[] arrEDistRateFeed, ProductType oProducttype) { string TimeDifference = string.Empty; string publishedAt = String.Empty; bool boolISR = true, boolDealEntry = true; string messageISR = null, messageDealEntry = null; try { if (arrEDistRateFeed != null && arrEDistRateFeed.Length > 0) { DB_EDistRateFeed objEDistRateFeed = new DB_EDistRateFeed(); // ------------------- INTIALISING THE ISR LOGGER ------------------------------ if (oLogger_ISR == null) { oLogger_ISR = InitializeLogger_ICX("EdistPublish_ISR", "EDIST"); } // ------------------------ INTIALISING THE DEAL ENTRY LOGGER ----------------------------- if (oLogger_DealEntry == null) { oLogger_DealEntry = InitializeLogger_ICX("EdistPublish_DealEntry", "EDIST"); } if (oLogger == null) { oLogger = InitializeLogger_ICX("EdistPublish", "EDIST"); } // ****************************** SPOT *************************************************************** if (oProducttype == ProductType.Spot) { // To intialize the static dictionary of static dictionary of if (DB_EDistRateFeed.dt_RateDistributionFeedSetup == null) { objEDistRateFeed.DB_Get_RateFieldDistributionSetupForSpot(); } if (DB_EDistRateFeed.static_dict_spot_ISR == null) { objEDistRateFeed.DB_IntializeStaticMemoryForSpot_ISR(); } if (DB_EDistRateFeed.static_dict_spot_DealEntry == null) { objEDistRateFeed.DB_IntializeStaticMemoryForSpot_DealEntry(); } // Function to check Throttling CheckThrottling(arrEDistRateFeed, ref boolISR, ref boolDealEntry, ref previousUpdatedAt_DealEntry, ref previousUpdatedAt_ISR); if (boolDealEntry == true) // Added Arun Shukla { TimeDifference = objEDistRateFeed.DB_Save_EDist_Rate_Feed(arrEDistRateFeed, oProducttype); //Writing Log in Logger of DealEntry oLogger_DealEntry.LogInformationMessage("[" + arrEDistRateFeed[0].currencyPair + "][Edist_Batch] Bid Rates : " + arrEDistRateFeed[0].bid + " & Ask Rate : " + arrEDistRateFeed[0].ask + " saved in DB, now publishing to FX cash rates service started......"); } if (boolISR == true || boolDealEntry == true) // LAB1 { FinIQ.Services.EDistRateFeed.FXCashRatesService.FXAllSpotDTO oFXAllSpotDTO = null; oFXAllSpotDTO = new FinIQ.Services.EDistRateFeed.FXCashRatesService.FXAllSpotDTO(); oFXAllSpotDTO.Spot_CurrencyPair = arrEDistRateFeed[0].currencyPair; oFXAllSpotDTO.Spot_AskRate = arrEDistRateFeed[0].ask; oFXAllSpotDTO.Spot_BidRate = arrEDistRateFeed[0].bid; oFXAllSpotDTO.Spot_PreviousAskRate = arrEDistRateFeed[0].prevAsk; oFXAllSpotDTO.Spot_PreviousBidRate = arrEDistRateFeed[0].prevBid; if (boolDealEntry) { messageDealEntry = null; oFXAllSpotDTO.Spot_UpdatedAt = Convert.ToDateTime(TimeDifference); UpdatedAt_DealEntry = Convert.ToDateTime(TimeDifference); oFXAllSpotDTO.Spot_PreviousUpdatedAt = previousUpdatedAt_DealEntry; messageDealEntry = "[" + arrEDistRateFeed[0].currencyPair + "][Edist_Batch]. Bid Rate : " + oFXAllSpotDTO.Spot_BidRate + " |Ask Rate : " + oFXAllSpotDTO.Spot_AskRate + "| Rates Broadcasted to : "; } else { oFXAllSpotDTO.Spot_UpdatedAt = UpdatedAt_DealEntry; oFXAllSpotDTO.Spot_PreviousUpdatedAt = previousUpdatedAt_DealEntry; } if (boolISR) { messageISR = null; oFXAllSpotDTO.Spot_UpdatedAt_ISR = Convert.ToDateTime(DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["UpdatedAt"]); UpdatedAt_ISR = Convert.ToDateTime(DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["UpdatedAt"]); oFXAllSpotDTO.Spot_PreviousUpdatedAt_ISR = previousUpdatedAt_ISR; messageISR = "[" + arrEDistRateFeed[0].currencyPair + "][Edist_Batch]. Bid Rate : " + oFXAllSpotDTO.Spot_BidRate + " |Ask Rate : " + oFXAllSpotDTO.Spot_AskRate + "| Rates Broadcasted to : "; } else { oFXAllSpotDTO.Spot_UpdatedAt_ISR = UpdatedAt_ISR; oFXAllSpotDTO.Spot_PreviousUpdatedAt_ISR = previousUpdatedAt_ISR; } publishedAt = CashRatesServiceProvider.publishRates("SPOT", oFXAllSpotDTO, null, "SYSTEM", boolISR, boolDealEntry); if (boolDealEntry) { messageDealEntry = messageDealEntry + publishedAt; oLogger_DealEntry.LogInformationMessage(messageDealEntry); } if (boolISR) { messageISR = messageISR + publishedAt; oLogger_ISR.LogInformationMessage(messageISR); } } // end of LAB1 } //************************************************** SWAP ************************************************************************************* else if (oProducttype == ProductType.Swap) { TimeDifference = objEDistRateFeed.DB_Save_EDist_Rate_Feed(arrEDistRateFeed, oProducttype); FinIQ.Services.EDistRateFeed.FXCashRatesService.FXAllSwapDTO oFXAllSwapDTO = null; oFXAllSwapDTO = new FinIQ.Services.EDistRateFeed.FXCashRatesService.FXAllSwapDTO(); oFXAllSwapDTO.Swap_CurrencyPair = arrEDistRateFeed[0].currencyPair; oFXAllSwapDTO.Swap_AskPoints = arrEDistRateFeed[0].ask; oFXAllSwapDTO.Swap_BidPoints = arrEDistRateFeed[0].bid; oFXAllSwapDTO.Swap_TenorCode = arrEDistRateFeed[0].tenor; oFXAllSwapDTO.Swap_UpdatedAt = Convert.ToDateTime(TimeDifference); oFXAllSwapDTO.Swap_SwapPointsCode = "COVERPLAIN"; publishedAt = CashRatesServiceProvider.publishRates("SWAP", null, oFXAllSwapDTO, "SYSTEM", boolISR, boolDealEntry); oLogger.LogDebugMessage("[" + arrEDistRateFeed[0].currencyPair + "][Edist_Batch], Rates Broadcasting to:->" + publishedAt); } //************************************************ NDF ****************************************************************************************** else if (oProducttype == ProductType.NDF) { TimeDifference = objEDistRateFeed.DB_Save_EDist_Rate_Feed(arrEDistRateFeed, oProducttype); FinIQ.Services.EDistRateFeed.FXCashRatesService.FXAllSwapDTO oFXAllSwapDTO = null; oFXAllSwapDTO = new FinIQ.Services.EDistRateFeed.FXCashRatesService.FXAllSwapDTO(); oFXAllSwapDTO.Swap_CurrencyPair = arrEDistRateFeed[0].currencyPair; oFXAllSwapDTO.Swap_AskPoints = arrEDistRateFeed[0].ask; oFXAllSwapDTO.Swap_BidPoints = arrEDistRateFeed[0].bid; oFXAllSwapDTO.Swap_TenorCode = arrEDistRateFeed[0].tenor; oFXAllSwapDTO.Swap_UpdatedAt = Convert.ToDateTime(TimeDifference); oFXAllSwapDTO.Swap_SwapPointsCode = "NDF"; publishedAt = CashRatesServiceProvider.publishRates("NDF", null, oFXAllSwapDTO, "SYSTEM", boolISR, boolDealEntry); oLogger.LogDebugMessage("[" + arrEDistRateFeed[0].currencyPair + "][Edist_Batch], Rates Broadcasting to:->" + publishedAt); } /*****************************/ } // end of if // Author : Arun shukla , Saurabh Panjawni 14 JAN 2019 // Throttling Function - end //For fx rates publish to the Cash rates service for RFS and indicative streaming rates viweer screen //END //NIkhil Pakhale, Arun Shukla //10th Jan 2019 } catch (Exception ex) { throw new FinIQServiceException(ex); } return TimeDifference; } // // Added Arun Shukla , Saurabh Panjwani 14-01-2019 start internal void CheckThrottling(EDistFeedRateDTO[] arrEDistRateFeed, ref bool boolISR, ref bool boolDealEntry, ref DateTime previousUpdatedAt_DealEntry, ref DateTime previousUpdatedAt_ISR ) { TimeSpan TimeDiff_DealEntry, TimeDiff_ISR; bool boolISRTime=true, boolDealEntryTime=true, boolISRRate=true, boolDealEntryRate=true; double currentBid_DealEntry, newBid_DealEntry, currentAsk_DealEntry, newAsk_DealEntry, DiffAsk_DealEntry, DiffBid_DealEntry; double currentBid_ISR, newBid_ISR, currentAsk_ISR, newAsk_ISR, DiffAsk_ISR, DiffBid_ISR; double ISRRateDiff, DealEntryRateDiff; string message = null; string PerformThorttlingISR = string.Empty, PerformThorttlingDealEntry = string.Empty; try { PerformThorttlingISR = SVCLib.Core.LSS.FINIQ_ENTITY_CONFIG.Instance().GetConfigValue("RemoveThrottlingISR", 0); PerformThorttlingDealEntry = SVCLib.Core.LSS.FINIQ_ENTITY_CONFIG.Instance().GetConfigValue("RemoveThrottlingDealEntry", 0); DataRow[] getRateDistributionRow = DB_EDistRateFeed.dt_RateDistributionFeedSetup.Select("FeedIdentifier = '" + arrEDistRateFeed[0].currencyPair + "'"); /*************************** DEAL ENTRY START**************************************/ if (PerformThorttlingDealEntry.ToUpper() == "N" || PerformThorttlingDealEntry.ToUpper() == "NO") { /*<TimeDiff>*/ DateTime currentTime_DealEntry = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")); DateTime oldTIme_DealEntry = Convert.ToDateTime(DB_EDistRateFeed.static_dict_spot_DealEntry[arrEDistRateFeed[0].currencyPair]["UpdatedAt"]); TimeDiff_DealEntry = currentTime_DealEntry - oldTIme_DealEntry; double totalMillisecsDealEntry = TimeDiff_DealEntry.TotalMilliseconds; if (getRateDistributionRow.Length == 1) { /*<DealEntry TimeDiff>*/ //-------------------------------------------------------------------------------------------------- // IMPORTANT if (getRateDistributionRow[0].ItemArray[3] == null) { getRateDistributionRow[0].ItemArray[3] = 0; } double getDealEntryTimeInterval = Convert.ToDouble(getRateDistributionRow[0].ItemArray[3].ToString()); if (getDealEntryTimeInterval < totalMillisecsDealEntry) { //send the new rates. boolDealEntryTime = true; // Maintaining the previous timestamp of Deal Entry previousUpdatedAt_DealEntry = oldTIme_DealEntry; } else { boolDealEntryTime = false; } //--------------------------------------------------------------------------------------------------------------------------------- currentBid_DealEntry = Convert.ToDouble(DB_EDistRateFeed.static_dict_spot_DealEntry[arrEDistRateFeed[0].currencyPair]["SpotBidQuote"]); newBid_DealEntry = Convert.ToDouble(arrEDistRateFeed[0].bid); currentAsk_DealEntry = Convert.ToDouble(DB_EDistRateFeed.static_dict_spot_DealEntry[arrEDistRateFeed[0].currencyPair]["SpotAskQuote"]); newAsk_DealEntry = Convert.ToDouble(arrEDistRateFeed[0].ask); DiffBid_DealEntry = Math.Abs(currentBid_DealEntry - newBid_DealEntry); DiffBid_DealEntry = Math.Round((DiffBid_DealEntry / currentBid_DealEntry) * 100, 4); DiffAsk_DealEntry = Math.Abs(currentAsk_DealEntry - newAsk_DealEntry); DiffAsk_DealEntry = Math.Round((DiffAsk_DealEntry / currentAsk_DealEntry) * 100, 4); if (getRateDistributionRow[0].ItemArray[4] == null) { getRateDistributionRow[0].ItemArray[4] = 0; } DealEntryRateDiff = Convert.ToDouble(getRateDistributionRow[0].ItemArray[4]); if ((DiffAsk_DealEntry > DealEntryRateDiff) || (DiffBid_DealEntry > DealEntryRateDiff)) { boolDealEntryRate = true; } else { boolDealEntryRate = false; } boolDealEntry = ((boolDealEntryRate) || (boolDealEntryTime)); if (boolDealEntry == false) { message = null; message = "[" + arrEDistRateFeed[0].currencyPair + "][Edist]. Rates not updated for Deal entry page."; message = message + "Time difference is " + totalMillisecsDealEntry + "ms."; message = message + "Old Bid Rate : " + currentBid_DealEntry + "| Old Ask Rate :" + currentAsk_DealEntry + " | New Bid Rate : " + newBid_DealEntry + " | New Ask Rate : " + newAsk_DealEntry + " | .Bid Rate Difference : " + DiffBid_DealEntry + " % | Ask Rate Difference : " + DiffAsk_DealEntry + " %."; if (boolDealEntryTime == false) { message = message + "Time difference is less than " + getDealEntryTimeInterval + " millseconds."; } if (boolDealEntryRate == false) { message = message + "Bid and ask rate difference is less than" + DealEntryRateDiff + " %."; } oLogger_DealEntry.LogInformationMessage(message); } } } else { boolDealEntry = true; // if true then it pass to the publish function } if (boolDealEntry == true) { // Updating the NewBid and NewAsk Rate into the Dictionary DB_EDistRateFeed.static_dict_spot_DealEntry[arrEDistRateFeed[0].currencyPair]["SpotBidQuote"] = Convert.ToString(Convert.ToDouble(arrEDistRateFeed[0].bid)); DB_EDistRateFeed.static_dict_spot_DealEntry[arrEDistRateFeed[0].currencyPair]["SpotAskQuote"] = Convert.ToString(Convert.ToDouble(arrEDistRateFeed[0].ask)); // Maintaining the previous timestamp of ISR previousUpdatedAt_ISR = Convert.ToDateTime(DB_EDistRateFeed.static_dict_spot_DealEntry[arrEDistRateFeed[0].currencyPair]["UpdatedAt"]); DB_EDistRateFeed.static_dict_spot_DealEntry[arrEDistRateFeed[0].currencyPair]["UpdatedAt"] = Convert.ToString(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")).ToString("yyyy-MM-dd HH:mm:ss.ffff")); } /*************************** DEAL ENTRY END**************************************/ /*********************************************************************************************************************************************************/ /************************* ISR START ******************************************/ if (PerformThorttlingISR.ToUpper() == "N" || PerformThorttlingISR.ToUpper() == "NO") { /*<ISR RateDiff>*/ if (getRateDistributionRow[0].ItemArray[2] == null) { getRateDistributionRow[0].ItemArray[2] = 0; } if (getRateDistributionRow[0].ItemArray[1] == null) { getRateDistributionRow[0].ItemArray[1] = 0; } double getISRTimeInterval = Convert.ToDouble(getRateDistributionRow[0].ItemArray[1].ToString()); ISRRateDiff = Convert.ToDouble(getRateDistributionRow[0].ItemArray[2]); currentBid_ISR = Convert.ToDouble(DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["SpotBidQuote"]); newBid_ISR = Convert.ToDouble(arrEDistRateFeed[0].bid); currentAsk_ISR = Convert.ToDouble(DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["SpotAskQuote"]); newAsk_ISR = Convert.ToDouble(arrEDistRateFeed[0].ask); DiffBid_ISR = Math.Abs(currentBid_ISR - newBid_ISR); DiffBid_ISR = Math.Round((DiffBid_ISR / currentBid_ISR) * 100, 4); DiffAsk_ISR = Math.Abs(currentAsk_ISR - newAsk_ISR); DiffAsk_ISR = Math.Round((DiffAsk_ISR / currentAsk_ISR) * 100, 4); if ((DiffAsk_ISR > ISRRateDiff) || (DiffBid_ISR > ISRRateDiff)) { boolISRRate = true; } else { boolISRRate = false; } //DateTime currentTime_ISR = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")); DateTime currentTime_ISR = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")); DateTime oldTime_ISR = Convert.ToDateTime(DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["UpdatedAt"]); TimeDiff_ISR = currentTime_ISR - oldTime_ISR; double totalMillisecsISR = TimeDiff_ISR.TotalMilliseconds; if (getISRTimeInterval < totalMillisecsISR) { //send the new rates. boolISRTime = true; } else { boolISRTime = false; } boolISR = (boolISRRate) || (boolISRTime); message = null; if (boolISR == false) { message = null; message = "[" + arrEDistRateFeed[0].currencyPair + "][Edist]. Rates not updated for Indicative streaming page."; message = message + "Time difference is " + totalMillisecsISR + "ms."; message = message + "Old Bid Rate : " + currentBid_ISR + "| Old Ask Rate :" + currentAsk_ISR + " | New Bid Rate : " + newBid_ISR + " | New Ask Rate : " + newAsk_ISR + " | .Bid Rate Difference : " + DiffBid_ISR + " % | Ask Rate Difference : " + DiffAsk_ISR + " %."; if (boolISRTime == false) { message = message + "Time difference is less than " + getISRTimeInterval + " millseconds."; } if (boolISRRate == false) { message = message + "Bid and ask rate difference is less than " + ISRRateDiff + " %."; } oLogger_ISR.LogInformationMessage(message); } } else { boolISR = true; } if (boolISR == true) { // Updating the NewBid and NewAsk Rate into the Dictionary DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["SpotBidQuote"] = Convert.ToString(Convert.ToDouble(arrEDistRateFeed[0].bid)); DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["SpotAskQuote"] = Convert.ToString(Convert.ToDouble(arrEDistRateFeed[0].ask)); // Maintaining the previous timestamp of ISR previousUpdatedAt_ISR = Convert.ToDateTime(DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["UpdatedAt"]); DB_EDistRateFeed.static_dict_spot_ISR[arrEDistRateFeed[0].currencyPair]["UpdatedAt"] = Convert.ToString(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")).ToString("yyyy-MM-dd HH:mm:ss.ffff")); } /****************ISR END *****************/ } catch (Exception ex) { throw new FinIQServiceException(ex); } } // Added Arun Shukla , Saurabh Panjwani 14-01-2019 End //public string Save_Rate_Feed_Generic(RatesFeedDTO[] arrRatesFeedDTO,ProductType oProducttype) //{ // try // { // DB_EDistRateFeed objEDistRateFeed = new DB_EDistRateFeed(); // return objEDistRateFeed.DB_Save_EDist_Rate_Feed(arrRatesFeedDTO, oProducttype); // } // catch (Exception ex) // { // throw ex; // } //} #if DEBUG private StreamReader GetDummyData() { byte[] byteArray = null; MemoryStream stream; try { StringBuilder DummyResponse = new StringBuilder(); byteArray = Encoding.UTF8.GetBytes(DummyResponse.ToString()); stream = new MemoryStream(byteArray); return new StreamReader(stream); } catch (Exception) { // Program.oLogger.LogErrorMessage("Error while GetDummyData()"); throw; } } #endif } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more