Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            double currentTemperature;

            if (double.TryParse(Request.QueryString["temperature"], out currentTemperature))
            {
                var activeRoast = new Roast();
                activeRoast.CurrentTemp = currentTemperature;
                activeRoast.Save();
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var activeRoast = new Roast();

            if (activeRoast.ProfileId.HasValue)
            {
                var activeProfile = new Profile(activeRoast.ProfileId.Value);
                ProfileLiteral.Text = activeProfile.ProfileText;
            }
            else
            {
                ProfileLiteral.Text  = "0";
                activeRoast.StatusId = (int)Classes.RoastStatus.ErrorUnspecified;
                activeRoast.Save();
            }
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var jsonString = Request.Form["data"];

            if (String.IsNullOrEmpty(jsonString))
            {
                return;
            }
            var interfaceObject = new JavaScriptSerializer().Deserialize <InterfaceObject>(jsonString);
            //var interfaceObject = new InterfaceObject();

            var roast = new Roast();

            switch (interfaceObject.Action)
            {
            case (int)InterfaceAction.SetStatus:
                if (IsNewStatusValid(roast, interfaceObject.StatusCode))
                {
                    if (interfaceObject.StatusCode == (int)RoastStatus.StartManualRoasting &&
                        roast.CurrentTemp.HasValue)
                    {
                        roast.CurrentTargetTemp = Math.Floor(roast.CurrentTemp.Value);
                    }

                    roast.StatusId = interfaceObject.StatusCode;
                    roast.Save();
                }
                break;

            case (int)InterfaceAction.SaveProfile:
                interfaceObject.Profile.Save();
                break;

            case (int)InterfaceAction.GetProfile:
                var profileId = 0;
                if (interfaceObject.ProfileId > 0)
                {
                    profileId = interfaceObject.ProfileId;
                }
                else if (roast.ProfileId.HasValue)
                {
                    profileId = roast.ProfileId.Value;
                }
                interfaceObject.Profile = new Profile(profileId);
                break;

            case (int)InterfaceAction.GetProfiles:
                interfaceObject.Profiles = LoadProfilesFromDb();
                break;

            case (int)InterfaceAction.SetProfile:
                if (GetElapsedTime(roast.Id ?? 0) == 0 &&
                    (roast.StatusId == (int)RoastStatus.RoasterOnlineReady))
                {
                    roast.StatusId  = (int)RoastStatus.LoadProfile;
                    roast.ProfileId = interfaceObject.ProfileId;
                    roast.Save();
                }
                break;

            case (int)InterfaceAction.GetStatus:
                interfaceObject.StatusCode  = roast.StatusId ?? 0;
                interfaceObject.CurrentTemp = roast.CurrentTemp;
                interfaceObject.ElapsedTime = GetElapsedTime(roast.Id ?? 0);
                interfaceObject.ProfileId   = roast.ProfileId ?? 0;
                if (roast.StatusId == (int)RoastStatus.StartManualRoasting ||
                    roast.StatusId == (int)RoastStatus.InitiatingManualRoastInsertingBulb ||
                    roast.StatusId == (int)RoastStatus.RoastingWithManualControl)
                {
                    interfaceObject.ManualTargetTemp = roast.CurrentTargetTemp;
                }
                break;

            case (int)InterfaceAction.SetManualRoastTemperature:
                roast.CurrentTargetTemp = interfaceObject.ManualTargetTemp;
                roast.Save();
                break;

            case (int)InterfaceAction.GetManualRoastTemperature:
                interfaceObject.ManualTargetTemp = roast.CurrentTargetTemp;
                break;

            case (int)InterfaceAction.DeleteProfile:
                var profile = new Profile(interfaceObject.ProfileId);
                profile.Delete();
                break;

            case (int)InterfaceAction.MasterReset:
                roast.CreateNewRoast();
                break;

            case (int)InterfaceAction.RemoveProfile:
                if (roast.StatusId == (int)RoastStatus.ProfileLoadedReadyForRoastingWithProfile)
                {
                    roast.ProfileId = null;
                    roast.StatusId  = (int)RoastStatus.RemoveProfile;
                    roast.Save();
                }
                break;

            case (int)InterfaceAction.SetFirstCrack:
                int FirstElapsed = (int)GetElapsedTime(roast.Id ?? 0);
                if (FirstElapsed > 0)
                {
                    roast.FirstCrackElapsed = FirstElapsed;
                    roast.FirstCrackTemp    = GetTemperatureAverage(roast.Id ?? 0, 3);
                    roast.Save();
                }
                break;

            case (int)InterfaceAction.SetSecondCrack:
                int SecondElapsed = (int)GetElapsedTime(roast.Id ?? 0);
                if (SecondElapsed > 0)
                {
                    roast.SecondCrackElapsed = SecondElapsed;
                    roast.SecondCrackTemp    = GetTemperatureAverage(roast.Id ?? 0, 3);
                    roast.Save();
                }
                break;
            }

            var json = new JavaScriptSerializer().Serialize(interfaceObject);

            StatusLiteral.Text = json;
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int receivedCode;

            int.TryParse(Request.QueryString["code"], out receivedCode);

            var roast = new Roast();

            switch (receivedCode)
            {
            case 105:     // Load profile
            case 115:     // Start roasting
            case 205:     // Start manual roasting
            case 305:
                roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                break;

            case 30:     // Roaster online - ready
                if (roast.StatusId == (int)RoastStatus.NoCommunicationYet ||
                    roast.StatusId == (int)RoastStatus.RemoveProfile ||
                    roast.StatusId == (int)RoastStatus.EndingRoast ||
                    roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb ||
                    roast.StatusId == receivedCode)
                {
                    if ((roast.StatusId == (int)RoastStatus.EndingRoast ||
                         roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb) &&
                        roast.EndTime == null)
                    {
                        roast.EndTime = DateTime.Now;
                        roast.Save();
                        roast.CreateNewRoast();
                    }

                    roast.StatusId = receivedCode;
                }
                else if (roast.StatusId == (int)RoastStatus.LoadProfile ||
                         roast.StatusId == (int)RoastStatus.StartManualRoasting)
                {
                    // roast status correct - already set - send to roaster
                }
                else
                {
                    roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                }
                break;

            case 106:     // Started loading profile
                if (roast.StatusId == (int)RoastStatus.LoadProfile ||
                    roast.StatusId == receivedCode)
                {
                    roast.StatusId = receivedCode;
                }
                else if (roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb)
                {
                    // roast status correct - already set - send to roaster
                }
                else
                {
                    roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                }
                break;

            case 110:     // Profile loaded - ready for roasting with profile
                if (roast.StatusId == (int)RoastStatus.LoadProfile ||
                    roast.StatusId == (int)RoastStatus.StartedLoadingProfile ||
                    roast.StatusId == receivedCode)
                {
                    roast.StatusId = receivedCode;
                }
                else if (roast.StatusId == (int)RoastStatus.StartRoasting ||
                         roast.StatusId == (int)RoastStatus.RemoveProfile ||
                         roast.StatusId == (int)RoastStatus.StartManualRoasting ||
                         roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb)
                {
                    // roast status correct - already set - send to roaster
                }
                else
                {
                    roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                }
                break;

            case 120:     // Initiating profile roast (inserting bulb)
                if (roast.StatusId == (int)RoastStatus.StartRoasting ||
                    roast.StatusId == receivedCode)
                {
                    roast.StatusId = receivedCode;
                }
                else if (roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb)
                {
                    // roast status correct - already set - send to roaster
                }
                else
                {
                    roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                }
                break;

            case 130:     // Roasting with profile
                if (roast.StatusId == (int)RoastStatus.StartRoasting ||
                    roast.StatusId == (int)RoastStatus.InitiatingProfileRoastInsertingBulb ||
                    roast.StatusId == receivedCode)
                {
                    if (roast.StartTime == null)
                    {
                        roast.StartTime = DateTime.Now;

                        PushNotification pn = new PushNotification();
                        pn.SendNotification();
                    }

                    if (String.IsNullOrEmpty(roast.ProfileText))
                    {
                        Profile profile = new Profile((int)roast.ProfileId);
                        roast.ProfileText = profile.ProfileText;
                    }

                    roast.StatusId = receivedCode;
                }
                else if (roast.StatusId == (int)RoastStatus.StartManualRoasting ||
                         roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb)
                {
                    // roast status correct - already set - send to roaster
                }
                else
                {
                    roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                }
                break;

            case 210:     // Initiating manual roast (inserting bulb)
                if (roast.StatusId == (int)RoastStatus.StartManualRoasting ||
                    roast.StatusId == receivedCode)
                {
                    roast.StatusId = receivedCode;
                }
                else if (roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb)
                {
                    // roast status correct - already set - send to roaster
                }
                else
                {
                    roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                }
                break;

            case 220:     // Roasting with manual control
                if (roast.StatusId == (int)RoastStatus.StartManualRoasting ||
                    roast.StatusId == (int)RoastStatus.InitiatingManualRoastInsertingBulb ||
                    roast.StatusId == receivedCode)
                {
                    if (roast.StartTime == null)
                    {
                        roast.StartTime = DateTime.Now;

                        PushNotification pn = new PushNotification();
                        pn.SendNotification();
                    }
                    if (roast.ManualControlStartTime == null)
                    {
                        roast.ManualControlStartTime = DateTime.Now;
                    }

                    roast.StatusId = receivedCode;
                }
                else if (roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb)
                {
                    // roast status correct - already set - send to roaster
                }
                else
                {
                    roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                }
                break;

            case 310:     // Ending roast (will return to 30)
                if (roast.StatusId == (int)RoastStatus.ResetEgEndRoastEjectBulb ||
                    roast.StatusId == receivedCode)
                {
                    roast.StatusId = receivedCode;
                }
                else
                {
                    roast.StatusId = (int)RoastStatus.ErrorCurrentStatusIsNotValidForTheCurrentStateOfTheRoaster;
                }
                break;

            case 400:     // Error - unspecified
            case 401:     // Error - Current status is not valid for the current state of the roaster
            case 402:     // Error - Roaster not online
                roast.StatusId = receivedCode;
                break;
            }

            roast.Save();

            StatusLiteral.Text = "{" + roast.StatusId + "}"; // for now: send back the current status code
        }