Esempio n. 1
0
        // add mode for the fixture
        public override void HandleRequest(HttpListenerContext context)
        {
            var q = context.Request.QueryString;

            try
            {
                var fixIds     = getIntArgArray(q.Get(KEY_FIXTURE_ID));
                var name       = q.Get(KEY_MODE_NAME);
                var cols       = int.Parse(q.Get(KEY_MODE_COLS));
                var rows       = int.Parse(q.Get(KEY_MODE_ROWS));
                var setCurrent = bool.Parse(q.Get(KEY_SET_CURRENT));

                var fixtures = StateManager.Instance.State.GetFixtures(fixIds);

                foreach (var f in fixtures)
                {
                    f.AddMode(RestCreateFixtureHandler.GetFixtureMode(name));
                }

                SetInfoMessage(
                    "The mode '" + name + " cols:" + cols + ", rows:" + rows + "' added to fixtures: "
                    + fixtures.Aggregate("", (s, f) => s + f.Name + " "),
                    IS_NOT_PART_OF_STATE,
                    Talker.Talk.GetSource()
                    );
            }
            catch (Exception e) {
                SetErrorMessage(e.ToString(), IS_NOT_PART_OF_STATE, Talker.Talk.GetSource());
                WriteErrorMessage(context, e);
            }
        }
        public override void HandleRequest(HttpListenerContext context)
        {
            var q = context.Request.QueryString;

            try
            {
                var fids     = getIntArgArray(q.Get(KEY_FIXTURE_ID));
                var modesStr = (q.Get(KEY_MODES));

                if (fids == null || modesStr == null)
                {
                    throw new ArgumentNullException("Some of fixture edit properties was null");
                }

                var fixtures = StateManager.Instance.State.GetFixtures(fids);

                //validate pixel and mode values
                // The validation method will throw an Argument exception if mode values are not valid
                var modes = RestCreateFixtureHandler.GetFixtureModes(modesStr);
                foreach (var fix in fixtures)
                {
                    RestCreateFixtureHandler.ValidateModeValues(modes, fix.PixelPatch);
                }

                // modes are valid ..
                foreach (var fix in fixtures)
                {
                    fix.SetModes(modes);
                }

                SetInfoMessage(
                    "The modes for fixture: " + Fixture.GetFixtureListNameString(fixtures)
                    + "is set to: " + Mode.ModeListToString(modes),
                    IS_PART_OF_STATE,
                    Talker.Talk.GetSource()
                    );

                string state = StateManager.Instance.GetStateSerialized();
                WriteResponse(context, RestConst.RESPONSE_OK, RestConst.CONTENT_TEXT_JSON, state);
            }
            catch (Exception e)
            {
                SetErrorMessage(e.ToString(), IS_NOT_PART_OF_STATE, Talker.Talk.GetSource());
                WriteErrorMessage(context, e);
            }
        }
        public override void HandleRequest(HttpListenerContext context)
        {
            var q = context.Request.QueryString;

            try
            {
                var fids  = getIntArgArray(q.Get(KEY_FIXTURE_ID));
                var patch = q.Get(KEY_PATCH_TYPE);

                if (fids == null || patch == null)
                {
                    throw new ArgumentNullException("Some of fixture edit properties was null");
                }

                var fixtures = StateManager.Instance.State.GetFixtures(fids);


                foreach (var f in fixtures)
                {
                    f.TrySetPatch(RestCreateFixtureHandler.getPixelPatch(patch));
                }

                SetInfoMessage(
                    "Pixel patch for fixtures: " + Fixture.GetFixtureListNameString(fixtures)
                    + " is set to: " + RestCreateFixtureHandler.getPixelPatch(patch).ToString(),
                    IS_PART_OF_STATE,
                    Talker.Talk.GetSource()
                    );

                string state = StateManager.Instance.GetStateSerialized();
                WriteResponse(context, RestConst.RESPONSE_OK, RestConst.CONTENT_TEXT_JSON, state);
            }
            catch (Exception e)
            {
                SetErrorMessage(e.ToString(), IS_NOT_PART_OF_STATE, Talker.Talk.GetSource());
                WriteErrorMessage(context, e);
            }
        }
        public override void HandleRequest(HttpListenerContext context)
        {
            var q = context.Request.QueryString;

            try
            {
                var fids      = getIntArgArray(q.Get(KEY_FIXTURE_ID));
                var name      = q.Get(KEY_NAME);
                var port      = getIntArgArray(q.Get(KEY_PORT));
                var addr      = q.Get(KEY_ADDRESS);
                var mode      = q.Get(KEY_MODE);
                var patch     = q.Get(KEY_PATCH_TYPE);
                var increment = bool.Parse(q.Get(KEY_INCREMENT));

                if (fids == null || name == null || port == null ||
                    addr == null || mode == null || patch == null)
                {
                    throw new ArgumentNullException("Some of fixture edit properties was null");
                }

                var portObj = new Port()
                {
                    Net      = port[0],
                    SubNet   = port[1],
                    Universe = port[2]
                };

                Address address = new Address()
                {
                    DmxAddress = int.Parse(addr),
                    Port       = portObj
                };

                var fixtures = StateManager.Instance.State.GetFixtures(fids);

                var i = 0;
                foreach (var f in fixtures)
                {
                    f.TrySetPatch(RestCreateFixtureHandler.getPixelPatch(patch));
                    f.SetMode(RestCreateFixtureHandler.GetFixtureMode(mode));

                    f.Name = name + " " + i;
                    if (increment)
                    {
                        f.Address             = address.Clone();
                        f.Address.DmxAddress += f.CurrentInputAddressCount * i;
                    }
                    else
                    {
                        f.Address = address.Clone();
                    }
                    i++;
                }

                SetInfoMessage(
                    "Fixtures: " + Fixture.GetFixtureListNameString(fixtures)
                    + " edit successfull",
                    IS_PART_OF_STATE,
                    Talker.Talk.GetSource());

                string state = StateManager.Instance.GetStateSerialized();
                WriteResponse(context, RestConst.RESPONSE_OK, RestConst.CONTENT_TEXT_JSON, state);
            }
            catch (Exception e) {
                SetErrorMessage(e.ToString(), IS_NOT_PART_OF_STATE, Talker.Talk.GetSource());
                WriteErrorMessage(context, e);
            }
        }