public static void FolderType(FileSystemEventArgs e)
        {
            AttacheConfiguration FolderNames = ZudelloSetup.GetAttacheSettings();
            string status = "";

            foreach (var folder in FolderNames.AttacheMonitor.ToArray())
            {
                if (e.FullPath.Contains(folder))
                {
                    status = folder;
                }
            }
            //Get QueueID to update SQL
            int index1 = e.FullPath.LastIndexOf('_');

            try
            {
                string queueId = Regex.Match(e.FullPath.Substring(index1), @"\d+").Value;
                if (updateQueue(queueId, status) == true)
                {
                    Console.WriteLine("Queue ID: {0} has been updated", queueId);
                }
            }

            catch
            {
            }
        }
Exemplo n.º 2
0
        public static bool SaveToKfi(string order, string obj, string uuid, string queueID, string kfiRendered)
        {
            string currentTime = string.Format("{0:yyyy-MM-dd_hh-mm-ss-fff}", DateTime.Now); // Regex.Replace(DateTime.Now.ToString("hh.mm.ss.ffffff"), @"[^0-9a-zA-Z]+", "");
            string inboxPath   = ZudelloSetup.GetAttacheSettings().AttacheInbox;

            try
            {
                File.WriteAllText(inboxPath + String.Format("{0}_{1}_{2}_{3}_{4}.kfi", order, currentTime, obj.Replace(":", ""), uuid, queueID), kfiRendered.RemoveEmptyTags());
                return(true);
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
        public static void watchFiles()
        {
            AttacheConfiguration folders = ZudelloSetup.GetAttacheSettings();

            FileSystemWatcher watcher  = new FileSystemWatcher();
            string            filePath = folders.AttacheInbox;

            watcher.Path = filePath;

            watcher.NotifyFilter = NotifyFilters.LastWrite;
            watcher.NotifyFilter = NotifyFilters.FileName;
            watcher.Filter       = "*.*";

            // will track changes in sub-folders as well
            watcher.IncludeSubdirectories = true;
            watcher.Created += new FileSystemEventHandler(OnChanged);
            watcher.Renamed += new RenamedEventHandler(OnRenamed);

            new System.Threading.AutoResetEvent(true).WaitOne();
            watcher.EnableRaisingEvents = true;
        }
Exemplo n.º 4
0
        public static List <ErrorData> KfiErrorGetter()
        {
            List <ErrorData> errList = new List <ErrorData>();

            try
            {
                using (var db = new ZudelloContext())
                {
                    //Get a list of all failed items.
                    var failureQueue = db.Zqueue.Where(i => i.Status == "Failure").Select(s => s.Id).ToList();



                    //Get a List of all .eer Files
                    AttacheConfiguration FolderNames = ZudelloSetup.GetAttacheSettings();

                    var           Fdir  = FolderNames.AttacheInbox + "Failure";
                    DirectoryInfo d     = new DirectoryInfo(Fdir);
                    FileInfo[]    Files = d.GetFiles("*.err");

                    List <string> err = new List <string>();
                    foreach (FileInfo file in Files)
                    {
                        ErrorData errData = new ErrorData();
                        //Check if failed item is part of queue
                        try
                        {
                            int    index1  = file.FullName.LastIndexOf('_');
                            string queueId = Regex.Match(file.FullName.Substring(index1), @"\d+").Value;

                            // Convert to int to check
                            int id = 0;
                            Int32.TryParse(queueId, out id);

                            if (failureQueue.Contains(id))
                            {
                                //Send to Zudello this error File.

                                errData.errorFile = File.ReadAllText(file.FullName);

                                // Console.WriteLine(File.ReadAllText(file.FullName));
                                FileInfo[] originalKfi = d.GetFiles(String.Format("*_{0}.kfi", id.ToString()));
                                //Get the Original KFI

                                //Console.WriteLine(File.ReadAllText(originalKfi.FirstOrDefault().FullName));
                                try
                                {
                                    errData.originalFile = File.ReadAllText(originalKfi.FirstOrDefault().FullName);

                                    // Console.ReadLine();
                                }

                                catch (Exception ex)
                                {
                                    //If we cannot locate original
                                    errData.originalFile = ex.Message;
                                }
                                //Bool check to confirm error file was sent to zudello.


                                var updateQuery = db.Zqueue.Where(i => i.Id == id).FirstOrDefault();
                                errData.body       = JsonConvert.DeserializeObject(updateQuery.Body);
                                updateQuery.Status = "ZudelloReview";
                                db.SaveChanges();

                                errList.Add(errData);
                            }
                            else
                            {
                                //Next Item already been sent to Zudello
                                continue;
                            }
                        }

                        catch (Exception ex)
                        {
                            return(errList);
                        }
                    }

                    return(errList);
                }
            }
            catch (Exception ex)
            {
                return(errList);
            }
        }
Exemplo n.º 5
0
        public static async Task ProcessRecords()
        {
            AttacheConfiguration Folder = ZudelloSetup.GetAttacheSettings();


            using (var db = new ZudelloContext())
            {
                List <int> Success            = new List <int>();
                var        MasterDataAwaiting = (from a in db.Zqueue
                                                 join c in db.Zmapping on a.MappingId equals c.Id
                                                 where c.IsMasterData == 1 && a.Status == "Processing"
                                                 select a).Count();


                //The Cleaner Should be checking if these are in which folders
                if (MasterDataAwaiting > 0)
                {
                    //run procedure to check folders
                    return;
                }


                if (MasterDataAwaiting == 0)
                {
                    //Get All Master Data in waiting status
                    var MasterData = (from queue in db.Zqueue
                                      join map in db.Zmapping on queue.MappingId equals map.Id
                                      where map.IsMasterData == 1 && queue.Status.Trim() == "Waiting" //Will make more generic later
                                      select new { queue, map }).ToList();

                    if (MasterData.Count() > 0)
                    {
                        foreach (var queueData in MasterData)
                        {
                            bool success = ProcessMethod(queueData);

                            if (success == true)
                            {
                                //Mark Record as processing
                                queueData.queue.Status = "Processing";
                                db.SaveChanges();
                            }
                        }
                        return; //exit
                    }
                }

                //Process transactional Data

                var TransData = (from queue in db.Zqueue
                                 join map in db.Zmapping on queue.MappingId equals map.Id
                                 where map.IsMasterData == 0 && queue.Status.Trim() == "Waiting"      //Will make more generic later
                                 select new { queue, map }).ToList();

                foreach (var queueData in TransData)
                {
                    bool success = ProcessMethod(queueData);

                    if (success == true)
                    {
                        queueData.queue.Status = "Processing";
                        db.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static List <ResponseObject> KfiErrorGetter()
        {
            List <ResponseObject> Response  = new List <ResponseObject>();
            List <Zqueue>         queueList = new List <Zqueue>();
            List <string>         fileDir   = new List <string>();

            try
            {
                using (var db = new ZudelloContext())
                {
                    //Get a list of all failed items.
                    //var failureQueue = db.Zqueue.Where(i => i.Status == "Failure" || i.Status == "Success" && ( i.ResponseSent == 0)).Select();
                    queueList = db.Zqueue.Where(i => i.Status == "Failure" && (i.ResponseSent == 0) || i.Status == "NotProcessed" && (i.ResponseSent == 0)).ToList();


                    //Get a List of all .eer Files
                    AttacheConfiguration FolderNames = ZudelloSetup.GetAttacheSettings();

                    var Fdir = FolderNames.AttacheInbox + "Failure";
                    fileDir.Add(Fdir);
                    Fdir = FolderNames.AttacheInbox + "NotProcessed";
                    fileDir.Add(Fdir);

                    foreach (var dir in fileDir)
                    {
                        DirectoryInfo d     = new DirectoryInfo(dir);
                        FileInfo[]    Files = d.GetFiles("*.err");

                        List <string> err = new List <string>();
                        foreach (FileInfo file in Files)
                        {
                            ResponseObject SendFailedData = new ResponseObject();
                            ErrorFiles     Errors         = new ErrorFiles();
                            //Check if failed item is part of queue
                            try
                            {
                                int    index1  = file.FullName.LastIndexOf('_');
                                string queueId = Regex.Match(file.FullName.Substring(index1), @"\d+").Value;

                                // Convert to int to check
                                int id      = 0;
                                int counter = 0;
                                Int32.TryParse(queueId, out id);
                                try
                                {
                                    counter = queueList.Where(i => i.Id == id).Count();
                                }

                                catch (Exception ex)
                                {
                                }

                                if (counter > 0)
                                {
                                    try
                                    {
                                        //Send to Zudello this error File.

                                        Errors.errorFile = File.ReadAllText(file.FullName);

                                        // Console.WriteLine(File.ReadAllText(file.FullName));
                                        FileInfo[] originalKfi = d.GetFiles(String.Format("*_{0}.kfi", id.ToString()));
                                        //Get the Original KFI

                                        //Console.WriteLine(File.ReadAllText(originalKfi.FirstOrDefault().FullName));
                                        try
                                        {
                                            Errors.originalFile = File.ReadAllText(originalKfi.FirstOrDefault().FullName);

                                            // Console.ReadLine();
                                        }

                                        catch (Exception ex)
                                        {
                                            //If we cannot locate original
                                            Errors.originalFile = ex.Message;
                                        }
                                        //Bool check to confirm error file was sent to zudello.

                                        ZudelloLogin.SendProcessResponse();
                                        var updateQuery = db.Zqueue.Where(i => i.Id == id).FirstOrDefault();

                                        //get the} Syn Histry Uuid
                                        dynamic Body = JObject.Parse(updateQuery.Body);
                                        SendFailedData.body    = JsonConvert.SerializeObject(Errors);
                                        SendFailedData.status  = 500;
                                        SendFailedData.uuid    = Body.uuid;
                                        SendFailedData.queueid = updateQuery.Id;

                                        Response.Add(SendFailedData);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                        //Will be issue with items and customers need to revise
                                        continue;
                                    }
                                }
                                else
                                {
                                    //Next Item already been sent to Zudello Redundant now
                                    continue;
                                }
                            }

                            catch (Exception ex)
                            {
                                return(Response);
                            }
                        }
                    }
                    //Add the success data to return Object

                    return(Response);
                }
            }
            catch (Exception ex)
            {
                return(Response);
            }
        }