Question

in my solution Explorer i have tow Project one for windows service BridgeWS and the other Project Vytru.Platform.Bridge.Configuration have a static class SharedData.cs

My Problem : i want use this static property SharedData.DeviceList to get my list of Device object in BridgeWS Service but it Always equal null ?

this is my solution

enter image description here

some code from my static class

public static  class SharedData
    {
        public const string CONFIGURATION_XML_PATH = @"\Configuration.xml";
        private static List<Device> _deviceList;

        public static void Initialize()
        {
            APPLICATION_LOCAL_PATH = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            if (!string.IsNullOrEmpty(APPLICATION_LOCAL_PATH)) CONFIGURATION_FULL_PATH = APPLICATION_LOCAL_PATH + CONFIGURATION_XML_PATH;

            _deviceList = new List<Device>();
            _tempDeviceList = new List<Device>();
            _deviceAgent = new DeviceManager();
            _deviceAgent.Initialize();
        }           


        public static bool AddToTempDeviceList(Device device)
        {
            if (_tempDeviceList != null)
            {
                if (!_deviceAgent.IsExist(device, true))
                {
                    _tempDeviceList.Add(device);
                    return true;
                }
            }
            return false;
        }

        public static bool UpdateFile()
        {
            _deviceList = _tempDeviceList;
            return _deviceAgent.Save();
        }

          public static List<Device> DeviceList
        {
            get { return _deviceList; }
            set { _deviceList = value; }
        }

        public static List<Device> TempDeviceList
        {
            get { return _tempDeviceList; }
            set { _tempDeviceList = value; }
        }

        public static DeviceManager DeviceAgent
        {
            get { return _deviceAgent; }
            set { _deviceAgent = value; }
        }
    }

thanks and sorry for my bad English.

Was it helpful?

Solution

You can call Initialize method first. If you don't, properties will be null because of these part of code

_deviceList = new List<Device>();
            _tempDeviceList = new List<Device>();
            _deviceAgent = new DeviceManager();
            _deviceAgent.Initialize();

In BridgeWS

SharedData.Initialize();
SharedData.TempDeviceList; // not null
SharedData.DeviceList; // not null
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top