Ejemplo n.º 1
0
        /// <summary>
        /// Stops the current job by injecting M29
        /// </summary>
        public void KillJob()
        {
            //mode = 3;
            mode = jobMode.abortedJob;
            lock (jobList)
            {
                if (dataComplete == false && jobList.Count == 0)
                {
                    return;
                }
                dataComplete = false;
                jobFinished  = DateTime.Now;
                jobList.Clear();
                totalLines = linesSend;
            }
            exclusive = false;
            connection.injectManualCommandFirst("M29");
            foreach (GCodeShort code in Main.main.editor.getContentArray(3))
            {
                connection.injectManualCommand(code.text);
            }
            //Main.main.Invoke(Main.main.UpdateJobButtons);
            //Main.main.Invoke(Main.main.mainHelp.UpdateJobButtons);
            UpdateAll updateAll = Main.main.mainUpdaterHelper.UpdateEverythingInMain;

            Main.main.Invoke(updateAll);

            connection.firePrinterAction(Trans.T("L_JOB_KILLED")); //"Job killed");
            DoEndKillActions();
            Main.main.manulControl.Invoke(Main.main.manulControl.SetStatusJobKilled);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Upgrade(UpgradeSystem selected)
        {
            UpdateAll upengine = new UpdateAll();
            var       Town     = await _context.Towns.LastOrDefaultAsync(x => x.UserId == User.GetUserId());

            var Player = await _userManager.FindByIdAsync(User.GetUserId());

            UpgradeSystem buildings = new UpgradeSystem(_context, Player);

            buildings.BuildingPage(Town);
            var production = buildings.Upgrades.ElementAt(selected.UpgradeIndex);

            upengine.UpdateResource(Town);
            upengine.UpdateBuildings(Town);
            await _context.SaveChangesAsync();

            if (ModelState.IsValid && production.Cost_Iron <= Town.TownIRON &&
                production.Cost_Meat <= Town.TownMEAT && production.Cost_Wheat
                <= Town.TownWHEAT && production.Cost_Wood <= Town.TownWOOD)
            {
                Town.TownWHEAT = Town.TownWHEAT - production.Cost_Wheat;
                Town.TownMEAT  = Town.TownMEAT - production.Cost_Meat;
                Town.TownIRON  = Town.TownIRON - production.Cost_Iron;
                Town.TownWOOD  = Town.TownWOOD - production.Cost_Wood;

                UpgradeSystem Engine     = new UpgradeSystem(_context, Player);
                UpgradeQueue  NewUpgrade = new UpgradeQueue();

                NewUpgrade.BuildingINDEX = production.index;
                NewUpgrade.TownID        = Town.TownId;

                NewUpgrade.ProductionTime = DateTime.Now.AddSeconds(production.Buildtime);

                _context.upgradeQueue.Add(NewUpgrade);

                await _context.SaveChangesAsync();

                return(View("Buildings", buildings));
            }
            else
            {
                await _context.SaveChangesAsync();

                ModelState.AddModelError("", "Not Enough Resources");
                return(View("Buildings", buildings));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Buildings()
        {
            var Town = await _context.Towns.LastOrDefaultAsync(x => x.UserId == User.GetUserId());

            var Player = await _userManager.FindByIdAsync(User.GetUserId());

            var Set = await _context.UserGameSettings.LastOrDefaultAsync(x => x.UserId == User.GetUserId());

            UpgradeSystem model  = new UpgradeSystem();
            UpdateAll     Engine = new UpdateAll();

            Engine.UpdateResource(Town);
            Engine.UpdateBuildings(Town);
            model.BuildingPage(Town);

            await _context.SaveChangesAsync();

            return(View(model));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Begins a new printing job. Resets many of the varriables.
        /// </summary>
        public void BeginJob()
        {
            connection.firePrinterAction(Trans.T("L_BUILDING_PRINT_JOB...")); //"Building print job...");
            dataComplete = false;
            jobList.Clear();
            //times.Clear();
            totalLines                 = 0;
            linesSend                  = 0;
            computedPrintingTime       = 0;
            connection.lastlogprogress = -1000;
            maxLayer = -1;
            mode     = jobMode.printingJob;
            ana      = new GCodeAnalyzer(true);
            connection.analyzer.StartJob();

            //Main.main.Invoke(Main.main.mainHelp.UpdateJobButtons);
            UpdateAll updateAll = Main.main.mainUpdaterHelper.UpdateEverythingInMain;

            Main.main.Invoke(updateAll);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Ends the current printing job. If another one is in que then it resets some the the varriables.
        /// </summary>
        public void EndJob()
        {
            // If no more jobs to do.
            if (jobList.Count == 0)
            {
                mode = 0;
                connection.firePrinterAction(Trans.T("L_IDLE"));
                //Main.main.Invoke(Main.main.UpdateJobButtons);
                //Main.main.Invoke(Main.main.mainHelp.UpdateJobButtons);
                UpdateAll updateAll = Main.main.mainUpdaterHelper.UpdateEverythingInMain;
                Main.main.Invoke(updateAll);

                Main.main.manulControl.Invoke(Main.main.manulControl.SetStatusJobFinished);
                return;
            }
            else // if more jobs to do.
            {
                dataComplete = true;
                jobStarted   = DateTime.Now;
                connection.firePrinterAction(Trans.T("L_PRINTING..."));
            }
        }
Ejemplo n.º 6
0
        public GCode PopData()
        {
            GCode gc       = null;
            bool  finished = false;

            lock (jobList)
            {
                if (jobList.Count == 0)
                {
                    return(null);
                }
                try
                {
                    gc = new GCode(jobList.First.Value);
                    jobList.RemoveFirst();
                    linesSend++;

                    /*PrintTime pt = new PrintTime();
                     * pt.line = linesSend;
                     * pt.time = DateTime.Now.Ticks;
                     * lock (times)
                     * {
                     *  times.AddLast(pt);
                     *  if (times.Count > 1500)
                     *      times.RemoveFirst();
                     * }*/
                }
                catch
                {
                };

                //finished = jobList.Count == 0 && mode != 3;
                finished = jobList.Count == 0 && mode != jobMode.abortedJob;
            }
            if (finished)
            {
                dataComplete = false;
                mode         = Printjob.jobMode.finishedJob;
                jobFinished  = DateTime.Now;
                long ticks = (jobFinished.Ticks - jobStarted.Ticks) / 10000;
                long hours = ticks / 3600000;
                ticks -= 3600000 * hours;
                long min = ticks / 60000;
                ticks -= 60000 * min;
                long sec = ticks / 1000;
                //Main.conn.log("Printjob finished at " + jobFinished.ToShortDateString()+" "+jobFinished.ToShortTimeString(),false,3);
                Main.connection.log(Trans.T1("L_PRINTJOB_FINISHED_AT", jobFinished.ToShortDateString() + " " + jobFinished.ToShortTimeString()), false, 3);
                StringBuilder s = new StringBuilder();
                if (hours > 0)
                {
                    s.Append(Trans.T1("L_TIME_H:", hours.ToString())); //"h:");
                }
                if (min > 0)
                {
                    s.Append(Trans.T1("L_TIME_M:", min.ToString()));
                }
                s.Append(Trans.T1("L_TIME_S", sec.ToString()));
                //Main.conn.log("Printing time:"+s.ToString(),false,3);
                //Main.conn.log("Lines send:" + linesSend.ToString(), false, 3);
                //Main.conn.firePrinterAction("Finished in "+s.ToString());
                Main.connection.log(Trans.T1("L_PRINTING_TIME:", s.ToString()), false, 3);
                Main.connection.log(Trans.T1("L_LINES_SEND:X", linesSend.ToString()), false, 3);
                Main.connection.firePrinterAction(Trans.T1("L_FINISHED_IN", s.ToString()));
                DoEndKillActions();
                //.main.Invoke(Main.main.UpdateJobButtons);
                //Main.main.Invoke(Main.main.mainHelp.UpdateJobButtons);
                UpdateAll updateAll = Main.main.mainUpdaterHelper.UpdateEverythingInMain;
                Main.main.Invoke(updateAll);

                Main.main.manulControl.Invoke(Main.main.manulControl.SetStatusJobFinished);
                RepetierHost.view.SoundConfig.PlayPrintFinished(false);
            }
            return(gc);
        }