Beispiel #1
0
        public async Task <IHttpActionResult> UpdateJobTracker(int id, JobTracker entity)
        {
            var existingEntity = await context.JobTrackers.FindAsync(entity.Id);

            if (id != entity.Id)
            {
                return(BadRequest(ModelState));
            }

            if (existingEntity != null && context.Entry(existingEntity).State != EntityState.Detached)
            {
                context.Entry(existingEntity).State = EntityState.Detached;
            }

            var local = context.Set <JobTracker>().Local.FirstOrDefault(f => f.Id == entity.Id);

            if (local != null)
            {
                context.Entry(local).State = EntityState.Detached;
            }

            entity.ModifiedOn = DateTime.Now;

            context.JobTrackers.Attach(entity);
            context.Entry(entity).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(Ok <JobTracker>(entity));
        }
Beispiel #2
0
        public static void OnLoadingPlayer(JSONNode n, Players.Player p)
        {
            if (n.TryGetChild(GameLoader.NAMESPACE + ".Knights", out var knightsNode))
            {
                foreach (var knightNode in knightsNode.LoopArray())
                {
                    var points = new List <Vector3Int>();

                    foreach (var point in knightNode["PatrolPoints"].LoopArray())
                    {
                        points.Add((Vector3Int)point);
                    }

                    if (knightNode.TryGetAs("PatrolType", out string patrolTypeStr))
                    {
                        var patrolMode = (PatrolType)Enum.Parse(typeof(PatrolType), patrolTypeStr);

                        if (!_loadedKnights.ContainsKey(p))
                        {
                            _loadedKnights.Add(p, new List <KnightState>());
                        }

                        _loadedKnights[p].Add(new KnightState()
                        {
                            PatrolPoints = points, patrolType = patrolMode
                        });
                    }
                }
            }

            JobTracker.Update();
        }
        public async Task <IHttpActionResult> CreateJobTrackers(JobTracker entity)
        {
            context.JobTrackers.Add(entity);
            await context.SaveChangesAsync();

            return(Ok <JobTracker>(entity));
        }
Beispiel #4
0
        public void SetUp()
        {
            _jobs  = Substitute.For <IJobManagement>();
            _jobId = NewRandomString();

            _tracker = new JobTracker(_jobs);
        }
Beispiel #5
0
 public virtual void OnRemove()
 {
     Definition.OnRemove(this);
     isValid = false;
     NPC     = null;
     JobTracker.Remove(owner, KeyLocation);
 }
        public ActionResult GetAsyncJobStatus(string identifier)
        {
            var job = JobTracker.GetJob(identifier);

            return(View("AsyncJobStatus", new AsyncActionModel {
                JobIdentifier = identifier, Status = job
            }));
        }
Beispiel #7
0
 public JobsController(
     JobQueue jobQueue,
     JobTracker jobTracker,
     ILogger <JobsController> logger)
 {
     _jobQueue   = jobQueue;
     _logger     = logger;
     _jobTracker = jobTracker;
 }
Beispiel #8
0
 public virtual void OnRemove()
 {
     isValid = false;
     if (usedNPC != null)
     {
         usedNPC.ClearJob();
         usedNPC = null;
     }
     JobTracker.Remove(owner, KeyLocation);
 }
Beispiel #9
0
 public static void AfterWorldLoad()
 {
     foreach (var k in _loadedKnights)
     {
         foreach (var kp in k.Value)
         {
             var knight = new Knight(kp.PatrolPoints, k.Key);
             knight.PatrolType = kp.patrolType;
             JobTracker.Add(knight);
         }
     }
 }
        //GetRoster gets all open and manned jobs
        private SortedDictionary <string, int> GetRoster(Players.Player player, Colony colony)
        {
            SortedDictionary <string, int> roster = new SortedDictionary <string, int>();

            JobTracker.JobFinder jf = (JobTracker.JobFinder)JobTracker.GetOrCreateJobFinder(player);
            List <IJob>          oj = jf.openJobs;

            foreach (IJob j in oj)
            {
                if (roster.ContainsKey(j.NPCType.ToString()))
                {
                    roster[j.NPCType.ToString()]++;
                }
                else
                {
                    roster.Add(j.NPCType.ToString(), 0);
                }
            }
            foreach (NPCBase follower in colony.Followers)
            {
                if (follower.Job != null)
                {
                    string npc = follower.Job.NPCType.ToString();
                    if (roster.ContainsKey(npc))
                    {
                        roster[npc]++;
                    }
                    else
                    {
                        if (follower.Job.NeedsNPC)
                        {
                            roster.Add(npc, 0);
                        }
                        else
                        {
                            roster.Add(npc, 1);
                        }
                    }
                }
                else
                {
                    if (roster.ContainsKey("Laborer"))
                    {
                        roster["Laborer"]++;
                    }
                    else
                    {
                        roster.Add("Laborer", 1);
                    }
                }
            }
            return(roster);
        }
        public static float SpawnChance(Players.Player p, Colony c, PlayerState state)
        {
            var chance        = .3f;
            var remainingBeds = BedBlockTracker.GetCount(p) - c.FollowerCount;

            if (remainingBeds < 1)
            {
                chance -= 0.1f;
            }

            if (remainingBeds >= state.MaxPerSpawn)
            {
                chance += 0.3f;
            }
            else if (remainingBeds > SettlerManager.MIN_PERSPAWN)
            {
                chance += 0.15f;
            }

            var hoursofFood = Stockpile.GetStockPile(p).TotalFood / c.FoodUsePerHour;

            if (hoursofFood > _minFoodHours)
            {
                chance += 0.2f;
            }

            var jobCount = JobTracker.GetOpenJobCount(p);

            if (jobCount > state.MaxPerSpawn)
            {
                chance += 0.4f;
            }
            else if (jobCount > SettlerManager.MIN_PERSPAWN)
            {
                chance += 0.1f;
            }
            else
            {
                chance -= 0.2f;
            }

            if (state.Difficulty != GameDifficulty.Easy)
            {
                if (c.InSiegeMode ||
                    c.LastSiegeModeSpawn != 0 &&
                    Time.SecondsSinceStartDouble - c.LastSiegeModeSpawn > TimeSpan.FromMinutes(5).TotalSeconds)
                {
                    chance -= 0.4f;
                }
            }

            return(chance);
        }
        public static void OnPlayerConnectedEarly(Players.Player p)
        {
            if (p.IsConnected && !Configuration.OfflineColonies)
            {
                var jf = JobTracker.GetOrCreateJobFinder(p) as JobTracker.JobFinder;

                var file =
                    $"{GameLoader.GAMEDATA_FOLDER}/savegames/{ServerManager.WorldName}/players/NPCArchive/{p.ID.steamID.ToString()}.json";

                if (File.Exists(file) && JSON.Deserialize(file, out var followersNode, false))
                {
                    PandaLogger.Log(ChatColor.cyan, $"Player {p.ID.steamID} is reconnected. Restoring Colony.");

                    foreach (var node in followersNode.LoopArray())
                    {
                        try
                        {
                            node.SetAs("id", GetAIID());

                            var npc = new NPCBase(p, node);
                            ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCLoaded, npc, node);

                            foreach (var job in jf.openJobs)
                            {
                                if (node.TryGetAs("JobPoS", out JSONNode pos) && job.KeyLocation == (Vector3Int)pos)
                                {
                                    if (job.IsValid && job.NeedsNPC)
                                    {
                                        npc.TakeJob(job);
                                        job.NPC = npc;
                                        JobTracker.Remove(p, job.KeyLocation);
                                    }

                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            PandaLogger.LogError(ex);
                        }
                    }

                    JSON.Serialize(file, new JSONNode(NodeType.Array));
                    jf.Update();
                }
            }
        }
Beispiel #13
0
        public IActionResult JobTrackerHandler(JobTracker FromForm)
        {
            System.Console.WriteLine($"you have reached the backend of job tracker {FromForm.Title}");
            if (HttpContext.Session.GetInt32("UserId") == null)
            {
                return(RedirectToAction("index"));
            }
            int GetUserbyId = (int)HttpContext.Session.GetInt32("UserId");

            FromForm.UserId = GetUserbyId;


            _context.Add(FromForm);
            _context.SaveChanges();

            return(Json(new { Status = "Success" }));
        }
Beispiel #14
0
        public virtual void InitializeJob(Players.Player owner, Vector3Int position, int desiredNPCID)
        {
            this.position = position;
            this.owner    = owner;

            if (desiredNPCID != 0 && NPCTracker.TryGetNPC(desiredNPCID, out usedNPC))
            {
                usedNPC.TakeJob(this);
            }
            else
            {
                desiredNPCID = 0;
            }
            if (usedNPC == null)
            {
                JobTracker.Add(this);
            }
        }
Beispiel #15
0
        public DefaultFarmerAreaJob(Players.Player owner, Vector3Int min, Vector3Int max, int npcID = 0)
        {
            positionMin = min;
            positionMax = max;
            this.owner  = owner;

            if (npcID != 0 && NPCTracker.TryGetNPC(npcID, out usedNPC))
            {
                usedNPC.TakeJob(this);
            }
            else
            {
                npcID = 0;
            }
            if (usedNPC == null)
            {
                JobTracker.Add(this);
            }
        }
        private void JobFinished(ProgressJob job)
        {
            JobTracker j = jobs[job];

            //jobs.Remove(job);

            Dispatcher?.InvokeOrExecute(delegate
            {
                DownloadsPanel.Children.Remove(j.Container);
                DownloadsPanel.Children.Insert(DownloadsPanel.Children.Count, j.Container);
            });
            if (job is DownloadJob dl)
            {
                logger.Info($"Finished downloading file '{dl.FileName}'.");
            }
            else
            {
                logger.Info($"Finished task '{job.JobName}'.");
            }
        }
Beispiel #17
0
        private static void SetPriorityJobs(Colony colony)
        {
            SortedDictionary <string, IJob> current = new SortedDictionary <string, IJob>();

            JobTracker.JobFinder jobfinder = JobTracker.GetOrCreateJobFinder(colony.Owner) as JobTracker.JobFinder;

            foreach (NPCBase follower in colony.Followers)
            {
                if (follower.Job != null)
                {
                    follower.Job.NPC = null;
                    follower.ClearJob();
                }
            }

            IJob[] openjobs = jobfinder.openJobs.ToArray();
            int    count    = 0;

            Logger.Log("{0} ", openjobs.Length.ToString());
            foreach (string o in PlayerState.GetPlayerState(colony.Owner).LineUp)
            {
                count = 0;
                while (count < openjobs.Length)
                {
                    IJob j = openjobs[count];
                    if (o == j.NPCType.ToString() && j.NeedsNPC)
                    {
                        foreach (NPCBase follower in colony.Followers)
                        {
                            if (follower.Job == null)
                            {
                                Logger.Log("Job set to : {0}", j.NPCType.ToString());
                                follower.TakeJob(j);
                                break;
                            }
                        }
                    }
                    count++;
                }
            }
        }
Beispiel #18
0
        public virtual void InitializeJob(Players.Player owner, Vector3Int position, int desiredNPCID)
        {
            this.position = position;
            this.owner    = owner;

            if (desiredNPCID != 0)
            {
                if (NPCTracker.TryGetNPC(desiredNPCID, out usedNPC))
                {
                    usedNPC.TakeJob(this);
                }
                else
                {
                    Log.WriteWarning("Failed to find npc ID {0}", desiredNPCID);
                }
            }
            if (usedNPC == null)
            {
                JobTracker.Add(this);
            }
        }
Beispiel #19
0
        private static string InfectNPC(Colony c)
        {
            string sickNPC = null;

            if (Pipliz.Random.NextFloat(0.0f, 1.0f) <= Configuration.ChanceOfDiseaseSpread)
            {
                foreach (NPCBase follower in c.Followers)
                {
                    if (!follower.Job.NPCType.Equals(SickJob.SickNPCType))
                    {
                        if (follower.Job != null)
                        {
                            follower.Job.NPC = null;
                            follower.ClearJob();
                        }

                        //Create the sickjob, save the old job so it can be reset with the NPC is health again and if it is available.  Init job and assign the NPC to the sickjob.
                        SickJob sickjob = new SickJob();
                        sickjob.OldJob = (Job)follower.Job;
                        sickjob.InitializeJob(follower.Colony.Owner, follower.Position, follower.ID);
                        sickjob.OnAssignedNPC(follower);
                        follower.TakeJob(sickjob);

                        //add job so it will be saved and loaded with server restarts
                        ColonyManager.AddJobs(sickjob);

                        //Make old job available
                        JobTracker.Add(sickjob.OldJob);

                        //Set so the name of the old job can be returned
                        sickNPC = follower.Job.NPCType.ToString();

                        break;
                    }
                }
            }
            return(sickNPC);
        }
Beispiel #20
0
        private static void Sample_DirectAPI(User user)
        {
            ApiClient client = new ApiClient(user);

            // Healthcheck: "this is online."
            string onlineRes = client.HealthCheck();

            // Basic Work Flow
            string institutionName = "Citibank";
            Guid   institutionId   = client.GetInstitutionsByName(institutionName).ToList().FirstOrDefault().InstitutionID; //choose target bank

            Guid   userId   = user.UserID;
            string username = "******"; //input your bank login name
            string password = "******";  //input your bank login password
            string pin      = string.Empty;

            JobTracker jobTracker = client.CreateUserInstitution(userId, institutionId, username, password, pin);

            HandleMFA(client, jobTracker.JobID);

            // IF MFA Failed -> Retry:
            // JobTracker jobTracker = client.RetryUserInstitution(jobTracker.UserInstitutionID, institutionId, userName, password, pin);
            // HandleMFA(client, jobTracker.JobID)

            // IF MFA Succeed -> Get Account:
            IList <UserInstitutionAccount> accounts = client.GetUserInstitutionAccounts(jobTracker.UserInstitutionID).ToList();

            if (accounts != null && accounts.Count > 0)
            {
                // Refresh Account:
                Guid jobId = client.RefreshUserInstitutionAccount(accounts.FirstOrDefault().AccountID).JobID;
                HandleMFA(client, jobId);

                // IF MFA Succeed -> Get Transactions:
                IList <Transaction> transactionsHistory = client.GetTransactionsByTransactionDate(accounts.FirstOrDefault().AccountID, DateTime.Now.AddDays(-30), DateTime.Now);
            }
        }
Beispiel #21
0
        public async Task <IHttpActionResult> CreateCardDelivery(CardDelivery entity)
        {
            string userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            JobTracker jobTracker = await context.JobTrackers.FindAsync(entity.JobTrackerId);

            Job job = await context.Jobs.FindAsync(jobTracker.JobId);

            var depart = _repo.FindDepartmentByName("Quality Control");

            var jobStatusWIP         = _repo.FindJobStatusByName("WIP");
            var jobStatusCompleted   = _repo.FindJobStatusByName("Completed");
            var jobStatusQueue       = _repo.FindJobStatusByName("Queue");
            var jobStatusNotRequired = _repo.FindJobStatusByName("Not Required");

            var jobTypePersoOnly               = _repo.FindJobTypeByName("Perso Only");
            var jobTypePrintingOnly            = _repo.FindJobTypeByName("Printing Only");
            var jobTypePrintingAndPerso        = _repo.FindJobTypeByName("Printing And Perso");
            var jobTypePrintingPersoAndMailing = _repo.FindJobTypeByName("Printing, Perso And Mailing");
            var jobTypePersoAndMailing         = _repo.FindJobTypeByName("Perso And Mailing");
            var serviceType = job.ServiceTypeId;

            //Todo: Redundant code section
            #region JobTrackerUpdateFlow

            int departmentId = 0;
            var dipatchUnit  = _repo.FindDepartmentByName("Dispatch");
            var mailingUnit  = _repo.FindDepartmentByName("Mailing");

            if (serviceType == jobTypePersoOnly.Id)
            {
                departmentId = dipatchUnit.Id;
            }
            else if (serviceType == jobTypePrintingOnly.Id)
            {
                departmentId = dipatchUnit.Id;
            }
            else if (serviceType == jobTypePrintingAndPerso.Id)
            {
                departmentId = dipatchUnit.Id;
            }
            else if (serviceType == jobTypePersoAndMailing.Id)
            {
                departmentId = mailingUnit.Id;
            }
            else if (serviceType == jobTypePrintingPersoAndMailing.Id)
            {
                departmentId = mailingUnit.Id;
            }

            #endregion

            //1. Create the Appproval
            var newEntity = new CardDelivery()
            {
                JobTrackerId       = entity.JobTrackerId,
                DepartmentId       = depart.Id,
                DeliveredById      = userId,
                ConfirmedById      = userId,
                DeliveredOn        = DateTime.Now,
                ConfirmedOn        = DateTime.Now,
                TargetDepartmentId = departmentId
            };

            context.CardDelivery.Add(newEntity);
            await context.SaveChangesAsync();

            return(Ok <CardDelivery>(entity));
        }
Beispiel #22
0
        public async Task <IHttpActionResult> CreateClients(Sid05QA entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.Sid05QAs.Add(entity);
            await context.SaveChangesAsync();

            // Update JobTracker
            var jobStatusPending     = _repo.FindJobStatusByName("Pending");
            var jobStatusCompleted   = _repo.FindJobStatusByName("Completed");
            var jobStatusQueue       = _repo.FindJobStatusByName("Queue");
            var jobStatusNotRequired = _repo.FindJobStatusByName("Not Required");

            JobTracker jobTracker = await context.JobTrackers.FindAsync(entity.JobTrackerId);

            Job job = await context.Jobs.FindAsync(jobTracker.JobId);

            var jobTypePersoOnly               = _repo.FindJobTypeByName("Perso Only");
            var jobTypePrintingOnly            = _repo.FindJobTypeByName("Printing Only");
            var jobTypePrintingAndPerso        = _repo.FindJobTypeByName("Printing And Perso");
            var jobTypePrintingPersoAndMailing = _repo.FindJobTypeByName("Printing, Perso And Mailing");
            var jobTypePersoAndMailing         = _repo.FindJobTypeByName("Perso And Mailing");
            var serviceType = job.ServiceTypeId;

            // Update JobTracker
            jobTracker.QAId = jobStatusCompleted.Id;

            // JobServiceType
            #region JobTrackerUpdateFlow

            if (serviceType == jobTypePrintingOnly.Id)
            {
                jobTracker.QCId = jobStatusQueue.Id;
            }
            else if (serviceType == jobTypePersoOnly.Id)
            {
                jobTracker.CardEngrResumeId = jobStatusQueue.Id;
            }
            else if (serviceType == jobTypePrintingAndPerso.Id)
            {
                jobTracker.CardEngrResumeId = jobStatusQueue.Id;
            }
            else if (serviceType == jobTypePersoAndMailing.Id)
            {
                jobTracker.CardEngrResumeId = jobStatusQueue.Id;
            }
            else if (serviceType == jobTypePrintingPersoAndMailing.Id)
            {
                jobTracker.CardEngrResumeId = jobStatusQueue.Id;
            }

            #endregion

            jobTracker.ModifiedOn           = DateTime.Now;
            context.Entry(jobTracker).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(Ok <Sid05QA>(entity));
        }
        private void JobStarted(ProgressJob job)
        {
            JobTracker tracker = new JobTracker {
                Job = job
            };

            jobs.Add(job, tracker);

            Dispatcher?.InvokeOrExecute(delegate
            {
                var p             = new StackPanel();
                tracker.Container = p;

                // New progress bar
                ProgressBar bar = new ProgressBar
                {
                    Minimum = 0, Maximum = job.ExpectedSize, Height = 25, Background = Brushes.LightGray,
                };

                // Bind the Progress value to the Value property
                bar.SetBinding(ProgressBar.ValueProperty,
                               new Binding("ProgressCompleted")
                {
                    Source = job,
                    Mode   = BindingMode.OneWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                });


                var colorConverter = new DownloadProgressColorConverter();
                bar.SetBinding(ProgressBar.ForegroundProperty,
                               new Binding("Status")
                {
                    Source = job,
                    Mode   = BindingMode.OneWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Converter           = colorConverter,
                });

                bar.MouseDoubleClick += (s, a) => job.Cancel();

                TextBlock t = new TextBlock();
                t.SetBinding(TextBlock.TextProperty,
                             new Binding("ProgressSinceLastUpdate")
                {
                    Source = job,
                    Mode   = BindingMode.OneWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Converter           = new DownloadProgressTextConverter(job)
                });

                p.Children.Add(bar);
                p.Children.Add(t);
                p.UpdateLayout();

                DownloadsPanel.Children.Insert(0, p);
                DownloadsPanel.ScrollOwner?.ScrollToTop();
                DownloadsPanel.UpdateLayout();
            });

            if (job is FileWriteJob dj)
            {
                string kind = dj is DownloadJob ? "download" : "file write";
                if (job.ProgressCompleted == 0)
                {
                    logger.Info($"Starting {kind} of size {Miscellaneous.ToFileSize(job.ExpectedSize)}, File: '{dj.FileName}'.");
                }
                else
                {
                    logger.Info($"Resuming {kind} at {Miscellaneous.ToFileSize(job.ProgressCompleted)}/{Miscellaneous.ToFileSize(job.ExpectedSize)}, File: '{dj.FileName}'.");
                }
            }
            else
            {
                logger.Info($"Starting job '{job.JobName}'");
            }
        }
        public bool TryDoCommand(Players.Player player, string chat)
        {
            if (player == null || player.ID == NetworkID.Server)
            {
                return(true);
            }

            string[]    array  = CommandManager.SplitCommand(chat);
            Colony      colony = Colony.Get(player);
            PlayerState state  = PlayerState.GetPlayerState(player);

            state.CallToArmsEnabled = !state.CallToArmsEnabled;

            if (state.CallToArmsEnabled)
            {
                PandaChat.Send(player, "Call to arms activated!", ChatColor.red, ChatStyle.bold);

                foreach (var follower in colony.Followers)
                {
                    var job = follower.Job;

                    if (!CanCallToArms(job))
                    {
                        continue;
                    }

                    try
                    {
                        if (job != null)
                        {
                            if (job.GetType() != typeof(CalltoArmsJob))
                            {
                                _Jobs[follower] = job;
                            }

                            job.OnRemovedNPC();
                            follower.ClearJob();
                        }
                    }
                    catch (Exception ex)
                    {
                        PandaLogger.LogError(ex);
                    }

                    var armsJob = new CalltoArmsJob();
                    _callToArmsJobs.Add(armsJob);
                    armsJob.OnAssignedNPC(follower);
                    follower.TakeJob(armsJob);
                }
            }
            else
            {
                PandaChat.Send(player, "Call to arms deactivated.", ChatColor.green, ChatStyle.bold);
                List <NPCBase> assignedWorkers = new List <NPCBase>();

                foreach (var follower in colony.Followers)
                {
                    var job = follower.Job;

                    if (job != null && job.GetType() == typeof(CalltoArmsJob))
                    {
                        follower.ClearJob();
                        job.OnRemovedNPC();
                        ((JobTracker.JobFinder)JobTracker.GetOrCreateJobFinder(player)).openJobs.Remove(job);
                    }

                    if (_Jobs.ContainsKey(follower) && _Jobs[follower].NeedsNPC)
                    {
                        assignedWorkers.Add(follower);
                        follower.TakeJob(_Jobs[follower]);
                        _Jobs[follower].OnAssignedNPC(follower);
                        JobTracker.Remove(player, _Jobs[follower].KeyLocation);
                    }
                }

                _Jobs.Clear();
            }

            foreach (var armsJob in _callToArmsJobs)
            {
                ((JobTracker.JobFinder)JobTracker.GetOrCreateJobFinder(player)).openJobs.Remove(armsJob);
            }

            _callToArmsJobs.Clear();
            JobTracker.Update();
            Colony.SendColonistCount(player);

            return(true);
        }
Beispiel #25
0
 public virtual void OnRemovedNPC()
 {
     usedNPC = null;
     JobTracker.Add(this);
 }
Beispiel #26
0
 public virtual void OnRemove()
 {
     isValid = false;
     NPC     = null;
     JobTracker.Remove(owner, KeyLocation);
 }
Beispiel #27
0
 public Worker(int id, String serviceUrl, String entryUrl)
 {
     this.id    = id;
     jobTracker = new JobTracker(serviceUrl, entryUrl);
 }
Beispiel #28
0
 public override void OnRemovedNPC()
 {
     usedNPC.ClearJob();
     usedNPC = null;
     JobTracker.Remove(owner, position);
 }
Beispiel #29
0
        public async Task <IHttpActionResult> QACheckProcess(Sid05QA entity)
        {
            string   userId   = User.Identity.GetUserId();
            JobSplit jobSplit = await context.JobSplits.FindAsync(entity.JobSplitId);

            JobTracker jobTracker = await context.JobTrackers.FindAsync(entity.JobTrackerId);

            Job job = await context.Jobs.FindAsync(jobTracker.JobId);

            var jobStatusPending     = _repo.FindJobStatusByName("Pending");
            var jobStatusCompleted   = _repo.FindJobStatusByName("Completed");
            var jobStatusQueue       = _repo.FindJobStatusByName("Queue");
            var jobStatusNotRequired = _repo.FindJobStatusByName("Not Required");

            var jobTypePersoOnly               = _repo.FindJobTypeByName("Perso Only");
            var jobTypePrintingOnly            = _repo.FindJobTypeByName("Printing Only");
            var jobTypePrintingAndPerso        = _repo.FindJobTypeByName("Printing And Perso");
            var jobTypePrintingPersoAndMailing = _repo.FindJobTypeByName("Printing, Perso And Mailing");
            var jobTypePersoAndMailing         = _repo.FindJobTypeByName("Perso And Mailing");
            var serviceType = job.ServiceTypeId;

            var printDepartment = _repo.FindDepartmentByName("Printing");
            var persoDepartment = _repo.FindDepartmentByName("Card Engineer");


            // Update Selected Split QA Process
            var t1 = await UpdateQAJobChecks(entity.Id, entity);

            // JobSplit Process
            jobSplit.IsQACompleted = true;
            var t2 = await UpdateJobSplit(jobSplit.Id, jobSplit);

            // If The split category id Printing
            if (jobSplit.DepartmentId == printDepartment.Id)
            {
                // Process Print Stage Scenerio
                var printDepart = _repo.FindPersoJobSplitByQAProcess(jobSplit.JobTrackerId, printDepartment.Id);

                if (printDepart == null) // If there is no item to process
                {
                    jobTracker.PrintQAId  = jobStatusCompleted.Id;
                    jobTracker.PrintQCId  = jobStatusQueue.Id;
                    jobTracker.ModifiedOn = DateTime.Now;

                    context.Entry(jobTracker).State = EntityState.Modified;
                    await context.SaveChangesAsync();
                }
            }
            else
            {
                // Process Perso Scenerio
                var PersoChecker = _repo.FindPersoJobSplitByQAProcess(jobSplit.JobTrackerId, persoDepartment.Id);

                if (PersoChecker == null)
                {
                    // Update the Tracker
                    #region UpdateTracker

                    // Update JobTracker
                    jobTracker.QAId = jobStatusCompleted.Id;

                    // JobServiceType
                    #region JobTrackerUpdateFlow

                    if (serviceType == jobTypePrintingOnly.Id)
                    {
                        jobTracker.QCId = jobStatusQueue.Id;
                    }
                    else if (serviceType == jobTypePersoOnly.Id)
                    {
                        jobTracker.CardEngrResumeId = jobStatusQueue.Id;
                    }
                    else if (serviceType == jobTypePrintingAndPerso.Id)
                    {
                        jobTracker.CardEngrResumeId = jobStatusQueue.Id;
                    }
                    else if (serviceType == jobTypePersoAndMailing.Id)
                    {
                        jobTracker.CardEngrResumeId = jobStatusQueue.Id;
                    }
                    else if (serviceType == jobTypePrintingPersoAndMailing.Id)
                    {
                        jobTracker.CardEngrResumeId = jobStatusQueue.Id;
                    }

                    #endregion

                    jobTracker.ModifiedOn           = DateTime.Now;
                    context.Entry(jobTracker).State = EntityState.Modified;
                    await context.SaveChangesAsync();

                    #endregion
                }
            }

            return(Ok <Sid05QA>(entity));
        }
Beispiel #30
0
        public async Task <IHttpActionResult> CreateNewCardIssuanceX(CardIssuanceModel entity)
        {
            string userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            #region Definations
            var job = await context.Jobs.FindAsync(entity.JobId);

            // ClientStockLog
            var issuanceStatusPartial   = _repo.FindIssuanceStatusByName("Partial");
            var issuanceStatusCompleted = _repo.FindIssuanceStatusByName("Completed");
            var issuanceTypeNew         = _repo.FindIssuanceTypeByName("New Issuance");
            var issuanceJob             = _repo.FindCardIssuanceByJobTrackerId(entity.JobTrackerId);


            //var jobTrackerJobId = _repo.FindJobTrackerByJobId(entity.JobId);
            var jobTracker = await context.JobTrackers.FindAsync(entity.JobTrackerId);

            var jobStatusPartial  = _repo.FindJobStatusByName("Partial");
            var jobStatusComplete = _repo.FindJobStatusByName("Completed");

            var jobTrackerStatusCompleted = _repo.FindJobTrackerStatusByName("Completed");
            var jobTrackerStatusPartial   = _repo.FindJobTrackerStatusByName("Partial");
            var jobTrackerStatusWIP       = _repo.FindJobTrackerStatusByName("WIP");

            // MIS Requirements
            var jobVariant        = _repo.FindJobVariantByJobId(job.Id);
            var clientVaultReport = _repo.FindClientVaultReportBySidProductId(jobVariant.SidProductId);
            //var clientStockReport = _repo.FindClientStocktReportBySidProductId(jobVariant.SidProductId);

            var clientStockReportForTheDay = _repo.FindClientStocktReportForTheDay(jobVariant.SidProductId);
            // ClientStockReportFortheDay

            #endregion

            if (entity.TotalQuantity > job.Quantity)
            {
                return(BadRequest(ModelState));
            }

            if (job != null)
            {
                if (issuanceJob == null)
                {
                    // ClientVaultReport // ClientStockReport
                    #region InitializedSetup

                    if (clientVaultReport == null)
                    {
                        //create new
                        var newClientValutReport = new ClientVaultReport()
                        {
                            SidProductId = jobVariant.SidProductId,
                            OpeningStock = 0,
                            ClosingStock = 0,
                        };

                        var cvr = await CreateClientVaultReport(newClientValutReport);
                    }

                    if (clientStockReportForTheDay == null)
                    {
                        var clientVaultReport2 = _repo.FindClientVaultReportBySidProductId(jobVariant.SidProductId);

                        //create new
                        var newClientStockReport = new ClientStockReport()
                        {
                            SidProductId        = jobVariant.SidProductId,
                            ClientVaultReportId = clientVaultReport2.Id,
                            FileName            = job.JobName,
                            QtyIssued           = 0,
                            WasteQty            = 0,
                            ReturnQty           = 0,
                            OpeningStock        = 0,
                            ClosingStock        = 0,
                            CreatedOn           = DateTime.Now
                        };

                        var csr = await CreateClientStockReport(newClientStockReport);
                    }


                    #endregion

                    #region IssuanceRegion

                    //Todo
                    var clientVaultReport3 = _repo.FindClientVaultReportBySidProductId(jobVariant.SidProductId);

                    // There is enough card in vault
                    if (clientVaultReport3.OpeningStock > job.Quantity)
                    {
                        // Only Issue if ClientValutReport:OpeningStock > Quantity
                        if (job.Quantity == entity.TotalQuantityIssued)
                        {
                            var clientStockReportForTheDay2 = _repo.FindClientStocktReportForTheDay(jobVariant.SidProductId);
                            var clientVaultReport2          = _repo.FindClientVaultReportBySidProductId(jobVariant.SidProductId);

                            #region JobProcessForCompleteIssuance

                            // Update IsJobPartial Status
                            Job updateJob = job;
                            updateJob.IsJobPartial = false;
                            var t0 = await UpdateJob(updateJob.Id, updateJob);

                            //done

                            // Update JobTracker
                            JobTracker updateJobTracker = jobTracker;
                            updateJobTracker.InventoryId        = jobStatusComplete.Id;
                            updateJobTracker.JobTrackerStatusId = jobTrackerStatusWIP.Id;
                            var t1 = await UpdateJobTracker(updateJobTracker.Id, updateJobTracker);

                            //done

                            // Create CardIssuance
                            var newCardIssuance = new CardIssuance()
                            {
                                JobTrackerId        = entity.JobTrackerId,
                                JobId               = entity.JobId,
                                IssuanceId          = userId, //entity.IssuanceId,
                                IssuanceStatusId    = issuanceStatusCompleted.Id,
                                CollectorId         = entity.CollectorId,
                                TotalQuantity       = job.Quantity,
                                TotalQuantityIssued = entity.TotalQuantityIssued,
                                TotalQuantityRemain = 0
                            };
                            var t3 = await CreateCardIssuance(newCardIssuance);


                            // Create CardIssuanceLog
                            var lastIssuance       = _repository.CardIssuances.Where(i => i.JobId == job.Id).OrderByDescending(x => x.Id).Take(1).ToList();
                            var newCardIssuanceLog = new CardIssuanceLog()
                            {
                                CardIssuanceId = lastIssuance[0].Id,
                                IssuanceTypeId = issuanceTypeNew.Id,
                                TotalQuantity  = lastIssuance[0].TotalQuantity,
                                QuantityIssued = lastIssuance[0].TotalQuantityIssued,
                                QuantityRemain = lastIssuance[0].TotalQuantityRemain,
                                IssuanceId     = userId,
                                CollectorId    = entity.CollectorId,
                                IssuedDate     = DateTime.Now
                            };
                            var t4 = await CreateCardIssuanceLog(newCardIssuanceLog);

                            //Todo Where(i => i.CardIssuanceId == lastIssuance[0].Id)
                            //// After all is done
                            //// Create JobBatchTracker
                            var lastIssuanceLog    = _repository.CardIssuanceLogs.OrderByDescending(x => x.Id).Take(1).ToList();
                            var newJobBatchTracker = new JobBatchTracker()
                            {
                                JobId              = job.Id,
                                JobTrackerId       = jobTracker.Id,
                                CardIssuanceId     = lastIssuance[0].Id,
                                JobTrackerStatusId = jobTrackerStatusWIP.Id
                            };

                            var t2 = await CreateJobBatchTracker(newJobBatchTracker);

                            #endregion

                            // Create ClientStockReport for the day,
                            // Use it to create the ClientStockLog
                            // Update ClientVaultReport by reducing it

                            #region MISEntryTest

                            // get ClientStockReport for the day, if null create
                            var newClientStockLog = new ClientStockLog()
                            {
                                ClientStockReportId = clientStockReportForTheDay.Id,
                                CardIssuanceId      = issuanceJob.Id,
                                IssuanceQty         = entity.TotalQuantityIssued,
                                OpeningStock        = clientVaultReport.OpeningStock,
                                ClosingStock        = clientVaultReport.OpeningStock - entity.TotalQuantityIssued,
                            };

                            var csl = await CreateClientStockLog(newClientStockLog);

                            // Update ClientVaultReport
                            ClientVaultReport updateClientVaultReport = clientVaultReport2;
                            updateClientVaultReport.ClosingStock -= job.Quantity;

                            // Update ClientStockReport
                            ClientStockReport updateClientStockReport = clientStockReportForTheDay2;
                            //updateClientStockReport.FileName = job.JobName;
                            updateClientStockReport.QtyIssued     = job.Quantity;
                            updateClientStockReport.ClosingStock -= job.Quantity;

                            #endregion

                            #region MIS Report
                            // get cientVaultReportId

                            if (clientVaultReport == null)
                            {
                                #region clientVaultReportNull

                                // create a new ClientVaultReport and
                                // Continue with the Process
                                //if (clientStockReport == null)
                                //{

                                //    #region clientStockReportNull

                                //    // Create get the last entry
                                //    // and continue

                                //    //// Create ClientStockLog
                                //    //var newClientStockLog = new ClientStockLog()
                                //    //{
                                //    //    lientStockReportId= 1,
                                //    //    CardIssuanceId = 1,

                                //    //    IssuanceQty = 1,
                                //    //    OpeningStock = 1,
                                //    //    ClosingStock = 1
                                //    //};

                                //    #endregion

                                //}
                                //else
                                //{

                                //    #region clientStockReport

                                //    //// Continue
                                //    //// Create ClientStockLog
                                //    //var newClientStockLog = new ClientStockLog()
                                //    //{

                                //    //};

                                //    #endregion

                                //}


                                #endregion
                            }
                            else
                            {
                                #region ClientVaultReport

                                //// Continue with the Process
                                //if (clientStockReport == null)
                                //{
                                //    #region clientStockReportNull

                                //    // Create get the last entry
                                //    // and continue

                                //    //// Create ClientStockLog
                                //    //var newClientStockLog = new ClientStockLog()
                                //    //{

                                //    //};

                                //    #endregion

                                //    // Create and continue
                                //}
                                //else
                                //{
                                //    // Continue
                                //    #region clientStockReport

                                //    //// Continue
                                //    //// Create ClientStockLog
                                //    //var newClientStockLog = new ClientStockLog()
                                //    //{

                                //    //};

                                //    #endregion

                                //}

                                #endregion
                            }

                            // Create ClientStockReport for the day,
                            // Use it to create the ClientStockLog
                            // Update ClientVaultReport

                            // Create ClientStockLog(DailyReport)
                            // { get ClientVaultReport,  }



                            // CardStock
                            // Card Stock Log
                            // ClientStock
                            // ClientStockLog

                            #endregion
                        }
                        else
                        {
                            var clientStockReportForTheDay2 = _repo.FindClientStocktReportForTheDay(jobVariant.SidProductId);
                            var clientVaultReport2          = _repo.FindClientVaultReportBySidProductId(jobVariant.SidProductId);

                            #region JobProcessForPartialIssuance

                            // Update IsJobPartial Status
                            Job updateJob = job;
                            updateJob.IsJobPartial = true; //Marker
                            var t0 = await UpdateJob(updateJob.Id, updateJob);

                            // Update JobTracker
                            JobTracker updateJobTracker = jobTracker;
                            updateJobTracker.InventoryId        = jobStatusComplete.Id;
                            updateJobTracker.JobTrackerStatusId = jobTrackerStatusWIP.Id;
                            var t1 = await UpdateJobTracker(updateJobTracker.Id, updateJobTracker);


                            // Create CardIssuance
                            entity.IssuanceStatusId    = issuanceStatusPartial.Id;
                            entity.TotalQuantityRemain = (job.Quantity - entity.TotalQuantityIssued);

                            var newCardIssuance = new CardIssuance()
                            {
                                JobTrackerId        = entity.JobTrackerId,
                                JobId               = entity.JobId,
                                IssuanceId          = userId, //entity.IssuanceId,
                                IssuanceStatusId    = issuanceStatusPartial.Id,
                                CollectorId         = entity.CollectorId,
                                TotalQuantity       = job.Quantity,
                                TotalQuantityIssued = entity.TotalQuantityIssued,
                                TotalQuantityRemain = entity.TotalQuantityRemain
                            };
                            var t3 = await CreateCardIssuance(newCardIssuance);

                            var lastIssuance = _repository.CardIssuances.Where(i => i.JobId == job.Id).OrderByDescending(x => x.Id).Take(1).ToList();


                            // Create CardIssuanceLog
                            var newCardIssuanceLog = new CardIssuanceLog()
                            {
                                CardIssuanceId = lastIssuance[0].Id,
                                IssuanceTypeId = issuanceTypeNew.Id,
                                TotalQuantity  = lastIssuance[0].TotalQuantity,
                                QuantityIssued = lastIssuance[0].TotalQuantityIssued,
                                QuantityRemain = lastIssuance[0].TotalQuantityRemain,
                                IssuanceId     = userId,
                                CollectorId    = entity.CollectorId,
                                IssuedDate     = DateTime.Now
                            };
                            var t4 = await CreateCardIssuanceLog(newCardIssuanceLog);

                            //Todo Where(i => i.CardIssuanceId == lastIssuance[0].Id)
                            //// After all is done
                            //// Create JobBatchTracker
                            var lastIssuanceLog    = _repository.CardIssuanceLogs.OrderByDescending(x => x.Id).Take(1).ToList();
                            var newJobBatchTracker = new JobBatchTracker()
                            {
                                JobId              = job.Id,
                                JobTrackerId       = jobTracker.Id,
                                CardIssuanceId     = lastIssuance[0].Id,
                                JobTrackerStatusId = jobTrackerStatusWIP.Id
                            };

                            var t2 = await CreateJobBatchTracker(newJobBatchTracker);

                            #endregion


                            #region MISEntryTest

                            // get ClientStockReport for the day, if null create
                            var newClientStockLog = new ClientStockLog()
                            {
                                ClientStockReportId = clientStockReportForTheDay.Id,
                                CardIssuanceId      = issuanceJob.Id,
                                IssuanceQty         = entity.TotalQuantityIssued,
                                OpeningStock        = clientVaultReport.OpeningStock,
                                ClosingStock        = clientVaultReport.OpeningStock - entity.TotalQuantityIssued,
                            };

                            var csl = await CreateClientStockLog(newClientStockLog);

                            // Update ClientVaultReport
                            ClientVaultReport updateClientVaultReport = clientVaultReport2;
                            updateClientVaultReport.ClosingStock -= job.Quantity;

                            // Update ClientStockReport
                            ClientStockReport updateClientStockReport = clientStockReportForTheDay2;
                            //updateClientStockReport.FileName = job.JobName;
                            updateClientStockReport.QtyIssued     = job.Quantity;
                            updateClientStockReport.ClosingStock -= job.Quantity;

                            #endregion
                        }
                    }

                    #endregion
                }
            }

            return(Ok());
        }