//--------------------------------------------------------------------------------------------- /// <summary> /// private Constructor for internal use only /// </summary> private PollingService() { FDatabase = VAT100Database.Instance; pollingTimer = new System.Timers.Timer(); StopPolling(); pollingTimer.Interval = DEFAULT_POLLING_INTERVAL; pollingTimer.Elapsed += OnTimerElapsedEvent; FPendingDocument = SelectNextDocument(); if (FPendingDocument != null) { PrepareHMRCRequest(FPendingDocument); } else { // Log.Add("Polling Service ready, but no VAT submissions are pending"); // Switch back to the default polling interval pollingTimer.Interval = DEFAULT_POLLING_INTERVAL; } // Documents could arrive at any time, so poll continuously StartPolling(); }
//--------------------------------------------------------------------------------------------- /// <summary> /// Constructor /// </summary> public HMRCFilingServiceProcessor() { thisPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // Create a database handler dbHandler = VAT100Database.Instance; // For now, direct all logging to the main Exchequer directory Log.Path = dbHandler.tToolkit.Configuration.EnterpriseDirectory; Log.Add("HMRC Filing Service started"); // Create a Response Handler FPollingService = PollingService.Instance; SetWebServiceURL(); }
private VAT100Database dbHandler = null; // Has a COM Toolkit we can use /// <summary> /// Constructor /// </summary> public UpdateChecker() { DateTime now = DateTime.Now; UPDATE_CHECK_TIME_1 = new DateTime(now.Year, now.Month, now.Day, 7, 0, 0, 0); // 07:00 UPDATE_CHECK_TIME_2 = new DateTime(now.Year, now.Month, now.Day, 21, 0, 0, 0); // 21:00 dbHandler = VAT100Database.Instance; // Get the directories sourceDir = dbHandler.tToolkit.Configuration.EnterpriseDirectory + @"HMRC Filing Service\"; destDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // Create the timer and set its interval updateTimer = new System.Timers.Timer(60000); // Once per minute updateTimer.Elapsed += TimerCallback; updateTimer.AutoReset = true; updateTimer.Enabled = true; // Do an initial check at the first minute (don't do it straight away, because the service // needs time to finish starting up). performInitialCheck = true; }
/// <summary> /// Adds a new VAT Return Submission to the VAT100 database table following receipt of an Acknowledgement. /// </summary> /// <param name="companyCode"></param> /// <param name="documentType"></param> /// <param name="userName"></param> /// <param name="request"></param> /// <param name="acknowledgement"></param> /// <returns></returns> public bool Add(string companyCode, string documentType, string userName, VAT100_GovTalkMessage request, VAT100_Acknowledgement acknowledgement) { // Create a Document for use by the Polling functions. DocumentRecord newDocument = new DocumentRecord(); newDocument.theDocument = new VAT100Record(); newDocument.companyCode = companyCode; newDocument.companyPath = FDatabase.GetCompanyPath(companyCode); // Fill in the details newDocument.theDocument.correlationID = acknowledgement.Header.MessageDetails.CorrelationID; newDocument.theDocument.IRMark = request.Body.IRenvelope.IRheader.IRMark.Value; DateTime timeNow = DateTime.Now; newDocument.theDocument.dateSubmitted = timeNow.ToString("ddMMyyyy HHmmss"); newDocument.theDocument.documentType = documentType; newDocument.theDocument.VATPeriod = request.Body.IRenvelope.IRheader.PeriodID; newDocument.theDocument.username = userName; newDocument.theDocument.status = (short)SubmissionStatus.ssSubmitted; newDocument.theDocument.pollingInterval = acknowledgement.Header.MessageDetails.ResponseEndPoint.PollInterval; newDocument.theDocument.VATDueOnOutputs = request.Body.IRenvelope.VATDeclarationRequest.VATDueOnOutputs; newDocument.theDocument.VATDueOnECAcquisitions = request.Body.IRenvelope.VATDeclarationRequest.VATDueOnECAcquisitions; newDocument.theDocument.VATTotal = request.Body.IRenvelope.VATDeclarationRequest.TotalVAT; newDocument.theDocument.VATReclaimedOnInputs = request.Body.IRenvelope.VATDeclarationRequest.VATReclaimedOnInputs; newDocument.theDocument.VATNet = request.Body.IRenvelope.VATDeclarationRequest.NetVAT; newDocument.theDocument.netSalesAndOutputs = request.Body.IRenvelope.VATDeclarationRequest.NetSalesAndOutputs; newDocument.theDocument.netPurchasesAndInputs = request.Body.IRenvelope.VATDeclarationRequest.NetPurchasesAndInputs; newDocument.theDocument.netECSupplies = request.Body.IRenvelope.VATDeclarationRequest.NetECSupplies; newDocument.theDocument.netECAcquisitions = request.Body.IRenvelope.VATDeclarationRequest.NetECAcquisitions; // PKR. 16/09/2015. ABSEXCH-16865. Add a temporary narrative so that the Submission record isn't empty. newDocument.theDocument.hmrcNarrative = "Acknowledgement received from HMRC."; newDocument.theDocument.PollingURL = acknowledgement.Header.MessageDetails.ResponseEndPoint.EndPoint; // Save the pending document int Res = 0; // CJS 2016-06-06 - ABSEXCH-17494 - VAT submission returning HMRC message to wrong company. // If we are not polling, it probably means that we are searching for or processing // an existing document, in which case it is not safe to use the VAT100Database singleton, // because it is already being used and might be open in the wrong company. Instead use // a new instance. if (!pollingTimer.Enabled) { Res = VAT100Database.GetNewInstance().AddVAT100Entry(newDocument.theDocument, companyCode); } else { Res = VAT100Database.Instance.AddVAT100Entry(newDocument.theDocument, companyCode); } if (Res != 0) { Log.Add(string.Format("Failed to save pending document for {0}. Error code : {1}", companyCode, Res)); return(false); } else { return(true); } }
//--------------------------------------------------------------------------------------------- /// <summary> /// Constructor /// </summary> public HMRCFilingService() { InitializeComponent(); appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Logger.Log("HMRC Filing Service", false); // Start a new log file by specifying append = false. Logger.Log("==================="); #if DEBUG Logger.Log("HMRCFilingService is hosted at : " + baseAddress.AbsoluteUri); #endif // Create a database handler try { // PKR. 24/09/2015. ABSEXCH-16919. // Services don't know about mapped drives as they are not created until a user logs in // So we read them from an INI file and map them locally to the service. // Read the list of mapped drives from the INI file #if DEBUG Logger.Log("Checking mapped drives"); #endif string[] mappedDrives; if (System.IO.File.Exists(Path.Combine(appPath, "MappedDrives.ini"))) { #if DEBUG Logger.Log("Opening MappedDrives.ini"); #endif mappedDrives = System.IO.File.ReadAllLines(Path.Combine(appPath, "MappedDrives.ini")); foreach (string mappedDrive in mappedDrives) { string[] exploder = mappedDrive.Split('='); if (exploder.Count() > 1) { // Get the drive letter. This doesn't have a trailing backslash, // but the mcmDrive letter does. string mapDrive = exploder[0]; // If the mapped drive already exists, ignore it. if (!Directory.Exists(mapDrive)) { // Get the UNC path string UNCpath = exploder[1]; // Strip trailing backslashes because MapNetworkDrive doesn't like them. UNCpath = UNCpath.TrimEnd(new[] { '/', '\\' }); MapNetworkDrive(mapDrive, UNCpath); if (!Directory.Exists(mapDrive)) { // Mapping failed Logger.Log("Could not map drive " + mapDrive + " to " + UNCpath); } else { Logger.Log("Mapped drive " + mapDrive + " to " + UNCpath); } } } } // foreach mapped drive } else { Logger.Log("Couldn't find mapped drive list"); } dbHandler = VAT100Database.Instance; #if DEBUG string epath = dbHandler.tToolkit.Configuration.EnterpriseDirectory; FileVersionInfo tkFVI = FileVersionInfo.GetVersionInfo(Path.Combine(epath, "EntToolk.exe")); Logger.Log("COM Toolkit version : " + tkFVI.FileVersion); #endif } catch (Exception ex) { Logger.Log("Error getting dbHandler : " + ex.Message); Logger.Log(VAT100Database.GetLastErrorString()); } #if DEBUG Logger.Log("Setting WebServiceURL"); #endif SetWebServiceURL(); }