public FakeHttpContext()
        {
            Request = new FakeRequest(_fakeWorkerRequest);

            _conextBackup = HttpContext.Current;
            Switchers.Add(_fakeHostEnvironment);

            HttpContext.Current = new HttpContext(_fakeWorkerRequest);

            HttpContext.Current.Request.Browser = new HttpBrowserCapabilities {
                Capabilities = new Hashtable()
            };

            var sessionContainer = new HttpSessionStateContainer(
                "id",
                new SessionStateItemCollection(),
                new HttpStaticObjectsCollection(),
                10,
                true,
                HttpCookieMode.AutoDetect,
                SessionStateMode.InProc,
                false);

            HttpContext.Current.Items["AspSession"] =
                typeof(HttpSessionState).GetConstructor(
                    BindingFlags.NonPublic | BindingFlags.Instance,
                    null,
                    CallingConventions.Standard,
                    new[] { typeof(HttpSessionStateContainer) },
                    null).Invoke(new object[] { sessionContainer });
        }
        public AppDomainDataSwitcher()
        {
            FakeLocalStore =
                new Dictionary <string, object[]>(
                    AppDomain.CurrentDomain.GetPrivateFieldValue <Dictionary <string, object[]> >("_LocalStore")
                    ?? new Dictionary <string, object[]>());

            Switchers.Add(new PrivateFieldSwitcher(AppDomain.CurrentDomain, "_LocalStore", FakeLocalStore));
        }
Exemplo n.º 3
0
        public FakeHostEnvironment()
        {
            if (HostingEnvironment.IsHosted)
            {
                return;
            }

            new HostingEnvironment();
            var hostringEnvironmentType = typeof(HostingEnvironment);
            var theHostingEnvironment   = hostringEnvironmentType.GetPrivateStaticFieldValue("_theHostingEnvironment");

            Switchers.Add(
                new AppDomainDataSwitcher
            {
                { ".appPath", AppDomain.CurrentDomain.BaseDirectory },
                { ".appDomain", "*" },
                { ".appVPath", "/" }
            });
            Switchers.Add(new PrivateFieldSwitcher(theHostingEnvironment, "_appVirtualPath", GetVirtualPath()));
            Switchers.Add(new PrivateFieldSwitcher(theHostingEnvironment, "_configMapPath", _configMapPath));
            Switchers.Add(new PrivateFieldSwitcher(theHostingEnvironment, "_appPhysicalPath", AppDomain.CurrentDomain.BaseDirectory));
        }
Exemplo n.º 4
0
        public FakeHostEnvironment()
        {
            if (_isInstantiated)
            {
                throw new InvalidOperationException(AlreadyInstantiatedMessage);
            }

            Monitor.Enter(SyncObject);
            if (_isInstantiated)
            {
                throw new InvalidOperationException(AlreadyInstantiatedMessage);
            }

            try
            {
                Switchers.Add(new HostingEnvironmentInitializator());
                var hostringEnvironmentType = typeof(HostingEnvironment);
                var theHostingEnvironment   =
                    hostringEnvironmentType.GetPrivateStaticFieldValue("_theHostingEnvironment");

                Switchers.Add(
                    new AppDomainDataSwitcher
                {
                    { ".appPath", AppDomain.CurrentDomain.BaseDirectory },
                    { ".appDomain", "*" },
                    { ".appVPath", "/" }
                });
                Switchers.Add(new PrivateFieldSwitcher(theHostingEnvironment, "_appVirtualPath", GetVirtualPath()));
                Switchers.Add(new PrivateFieldSwitcher(theHostingEnvironment, "_configMapPath", _configMapPath));
                Switchers.Add(new PrivateFieldSwitcher(theHostingEnvironment, "_appPhysicalPath",
                                                       AppDomain.CurrentDomain.BaseDirectory));
                _isInstantiated = true;
            }
            catch
            {
                Monitor.Exit(SyncObject);
                throw;
            }
        }
Exemplo n.º 5
0
        private void CreateDspObjects()
        {
            Debug.Console(2, "Creating DSP Objects");

            var props = JsonConvert.DeserializeObject <TesiraDspPropertiesConfig>(_dc.Properties.ToString());

            if (props == null)
            {
                return;
            }

            Debug.Console(2, this, "Props Exists");
            Debug.Console(2, this, "Here's the props string\n {0}", _dc.Properties.ToString());

            Faders.Clear();
            Presets.Clear();
            Dialers.Clear();
            States.Clear();
            Switchers.Clear();
            ControlPointList.Clear();
            Meters.Clear();
            RoomCombiners.Clear();

            if (props.FaderControlBlocks != null)
            {
                Debug.Console(2, this, "levelControlBlocks is not null - There are {0} of them", props.FaderControlBlocks.Count());
                foreach (var block in props.FaderControlBlocks)
                {
                    var key = block.Key;
                    Debug.Console(2, this, "LevelControlBlock Key - {0}", key);
                    var value = block.Value;

                    Faders.Add(key, new TesiraDspFaderControl(key, value, this));
                    Debug.Console(2, this, "Added LevelControlPoint {0} LevelTag: {1} MuteTag: {2}", key, value.LevelInstanceTag, value.MuteInstanceTag);
                    if (block.Value.Enabled)
                    {
                        //Add ControlPoint to the list for the watchdog
                        ControlPointList.Add(Faders[key]);
                    }
                }
            }

            if (props.SwitcherControlBlocks != null)
            {
                Debug.Console(2, this, "switcherControlBlocks is not null - There are {0} of them", props.FaderControlBlocks.Count());
                foreach (var block in props.SwitcherControlBlocks)
                {
                    var key = block.Key;
                    Debug.Console(2, this, "SwitcherControlBlock Key - {0}", key);
                    var value = block.Value;

                    Switchers.Add(key, new TesiraDspSwitcher(key, value, this));
                    Debug.Console(2, this, "Added TesiraSwitcher {0} InstanceTag {1}", key, value.SwitcherInstanceTag);

                    if (block.Value.Enabled)
                    {
                        //Add ControlPoint to the list for the watchdog

                        ControlPointList.Add(Switchers[key]);
                    }
                }
            }

            if (props.DialerControlBlocks != null)
            {
                Debug.Console(2, this, "DialerControlBlocks is not null - There are {0} of them", props.DialerControlBlocks.Count());
                foreach (var block in props.DialerControlBlocks)
                {
                    var key = block.Key;
                    Debug.Console(2, this, "LevelControlBlock Key - {0}", key);
                    var value = block.Value;
                    Dialers.Add(key, new TesiraDspDialer(key, value, this));
                    Debug.Console(2, this, "Added DspDialer {0} ControlStatusTag: {1} DialerTag: {2}", key, value.ControlStatusInstanceTag, value.DialerInstanceTag);

                    if (block.Value.Enabled)
                    {
                        ControlPointList.Add(Dialers[key]);
                    }
                }
            }

            if (props.StateControlBlocks != null)
            {
                Debug.Console(2, this, "stateControlBlocks is not null - There are {0} of them", props.StateControlBlocks.Count());
                foreach (var block in props.StateControlBlocks)
                {
                    var key   = block.Key;
                    var value = block.Value;
                    States.Add(key, new TesiraDspStateControl(key, value, this));
                    Debug.Console(2, this, "Added DspState {0} InstanceTag: {1}", key, value.StateInstanceTag);

                    if (block.Value.Enabled)
                    {
                        ControlPointList.Add(States[key]);
                    }
                }
            }

            if (props.Presets != null)
            {
                foreach (var preset in props.Presets)
                {
                    var value = preset.Value;
                    var key   = preset.Key;
                    Presets.Add(key, value);
                    Debug.Console(2, this, "Added Preset {0} {1}", value.Label, value.PresetName);
                }
            }

            if (props.MeterControlBlocks != null)
            {
                foreach (var meter in props.MeterControlBlocks)
                {
                    var key   = meter.Key;
                    var value = meter.Value;
                    Meters.Add(key, new TesiraDspMeter(key, value, this));
                    Debug.Console(2, this, "Adding Meter {0} InstanceTag: {1}", key, value.MeterInstanceTag);

                    if (value.Enabled)
                    {
                        ControlPointList.Add(Meters[key]);
                    }
                }
            }

            if (props.CrosspointStateControlBlocks != null)
            {
                foreach (var mixer in props.CrosspointStateControlBlocks)
                {
                    var key   = mixer.Key;
                    var value = mixer.Value;
                    CrosspointStates.Add(key, new TesiraDspCrosspointState(key, value, this));
                    Debug.Console(2, this, "Adding Mixer {0} InstanceTag: {1}", key, value.MatrixInstanceTag);

                    if (value.Enabled)
                    {
                        ControlPointList.Add(CrosspointStates[key]);
                    }
                }
            }
            if (props.RoomCombinerControlBlocks == null)
            {
                return;
            }
            foreach (var roomCombiner in props.RoomCombinerControlBlocks)
            {
                var key   = roomCombiner.Key;
                var value = roomCombiner.Value;
                RoomCombiners.Add(key, new TesiraDspRoomCombiner(key, value, this));
                Debug.Console(2, this, "Adding Mixer {0} InstanceTag: {1}", key, value.RoomCombinerInstanceTag);

                if (value.Enabled)
                {
                    ControlPointList.Add(RoomCombiners[key]);
                }
            }

            //Keep me at the end of this method!
            DeviceManager.AddDevice(new TesiraDspDeviceInfo(String.Format("{0}--DeviceInfo", Key), String.Format("{0}--DeviceInfo", Name, Presets), this, Presets));
        }