Exemplo n.º 1
0
        public virtual void DoWork(object obj)
        {
            NAVWSControl NS = new NAVWSControl();

            while (!_shouldStop)
            {
                if (NS.Ping())
                {
                    DoWork2();
                }
                else
                {
                    Log.WriteLog("Endpoint is unavailable, re-trying in 1 minute...\n" +
                                 WebConfigurationManager.AppSettings["WebServiceUrl"], EventLogEntryType.Error);
                }
                Thread.Sleep(60 * 1000);
            }
        }
Exemplo n.º 2
0
        public virtual void DoWork2()
        {
            NAVWSControl  NS = new NAVWSControl();
            DirectoryInfo info;

            FileInfo[] files;
            int        NoOfDays;

            while (!_shouldStop)
            {
                try
                {
                    info  = new DirectoryInfo(WebConfigurationManager.AppSettings["FileLocation"]);
                    files = info.GetFiles("*.xml").OrderBy(p => p.Name).ToArray();

                    if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["ProcessedFileLocation"]) &&
                        !string.IsNullOrEmpty(WebConfigurationManager.AppSettings["KeepInProcessed"]))
                    {
                        if (Int32.TryParse(WebConfigurationManager.AppSettings["KeepInProcessed"], out NoOfDays))
                        {
                            Directory.GetFiles(WebConfigurationManager.AppSettings["ProcessedFileLocation"])
                            .Select(f => new FileInfo(f))
                            .Where(f => f.CreationTime < DateTime.Now.AddDays(-NoOfDays))
                            .ToList()
                            .ForEach(f => f.Delete());
                        }
                    }
                }
                catch
                {
                    Log.WriteLog("Folder unavailable or dont' have access. \n" +
                                 WebConfigurationManager.AppSettings["FileLocation"], EventLogEntryType.Error);
                    return;
                }

                foreach (FileInfo file in files)
                {
                    XmlDocument doc = new XmlDocument();
                    if (!IsFileLocked(file))
                    {
                        try
                        {
                            doc.Load(file.FullName);

                            NS.ProcessRequest(doc.OuterXml);
                            //if (!NS.sentOk)
                            //  {
                            // The NAV WS is unavailable - back to DoWork() where Ping is executed until back online.
                            //    return;
                            //  }
                            //if (NS.returnedOk)
                            if (NS.sentOk)
                            {
                                MoveToProcessed(file.DirectoryName, file.Name);
                            }
                            else
                            {
                                MoveToFailed(file.DirectoryName, file.Name, NS.GetResponseMessage());
                            }
                        }
                        catch (Exception e)
                        {
                            MoveToFailed(file.DirectoryName, file.Name, NS.GetResponseMessage());
                        }
                    }
                }
                Thread.Sleep(1000);
            }
        }