Exemple #1
0
        internal static KinectBase.MasterSettings LoadSettings(string fileName)
        {
            KinectBase.MasterSettings settings     = null;
            XmlSerializer             serializer   = new XmlSerializer(typeof(SerializableSettings));
            SerializableSettings      tempSettings = null;

            FileInfo info = new FileInfo(fileName);

            if (info.Exists)
            {
                using (FileStream file = new FileStream(fileName, FileMode.Open))
                {
                    tempSettings = (SerializableSettings)serializer.Deserialize(file);
                    file.Close();
                    file.Dispose();
                }
            }
            else
            {
                throw new Exception("File does not exist!");
            }

            //Copy the settings from the serializable settings object to the real settings object
            settings = tempSettings.masterSettings;
            settings.kinectOptionsList = new List <IKinectSettings>();
            for (int i = 0; i < tempSettings.kinectV1Settings.Length; i++)
            {
                settings.kinectOptionsList.Add(tempSettings.kinectV1Settings[i]);
            }
            for (int i = 0; i < tempSettings.kinectV2Settings.Length; i++)
            {
                settings.kinectOptionsList.Add(tempSettings.kinectV2Settings[i]);
            }
            for (int i = 0; i < tempSettings.networkKinectSettings.Length; i++)
            {
                settings.kinectOptionsList.Add(tempSettings.networkKinectSettings[i]);
            }

            settings.kinectOptionsList.Sort(new KinectBase.KinectSettingsComparer());

            return(settings);
        }
Exemple #2
0
        internal static void SaveSettings(string fileName, KinectBase.MasterSettings settings)
        {
            //Create a serializable version of the settings (basically, move the Kinect options from the Master settings to a type specific array)
            List <KinectV1Wrapper.Settings>      kinect1Settings = new List <KinectV1Wrapper.Settings>();
            List <KinectV2Wrapper.Settings>      kinect2Settings = new List <KinectV2Wrapper.Settings>();
            List <NetworkKinectWrapper.Settings> networkSettings = new List <NetworkKinectWrapper.Settings>();

            for (int i = 0; i < settings.kinectOptionsList.Count; i++)
            {
                if (settings.kinectOptionsList[i].version == KinectVersion.KinectV1)
                {
                    kinect1Settings.Add((KinectV1Wrapper.Settings)settings.kinectOptionsList[i]);
                }
                else if (settings.kinectOptionsList[i].version == KinectVersion.KinectV2)
                {
                    kinect2Settings.Add((KinectV2Wrapper.Settings)settings.kinectOptionsList[i]);
                }
                else if (settings.kinectOptionsList[i].version == KinectVersion.NetworkKinect)
                {
                    networkSettings.Add((NetworkKinectWrapper.Settings)settings.kinectOptionsList[i]);
                }
            }
            SerializableSettings serialSettings = new SerializableSettings();

            serialSettings.masterSettings        = settings;
            serialSettings.kinectV1Settings      = kinect1Settings.ToArray();
            serialSettings.kinectV2Settings      = kinect2Settings.ToArray();
            serialSettings.networkKinectSettings = networkSettings.ToArray();

            //Do the actual serialization
            XmlSerializer serializer = new XmlSerializer(typeof(SerializableSettings));

            using (FileStream file = new FileStream(fileName, FileMode.Create))
            {
                serializer.Serialize(file, serialSettings);
                file.Close();
                file.Dispose();
            }
        }
Exemple #3
0
        internal static void SaveSettings(string fileName, KinectBase.MasterSettings settings)
        {
            //Create a serializable version of the settings (basically, move the Kinect options from the Master settings to a type specific array)
            List<KinectV1Wrapper.Settings> kinect1Settings = new List<KinectV1Wrapper.Settings>();
            List<KinectV2Wrapper.Settings> kinect2Settings = new List<KinectV2Wrapper.Settings>();
            List<NetworkKinectWrapper.Settings> networkSettings = new List<NetworkKinectWrapper.Settings>();
            for (int i = 0; i < settings.kinectOptionsList.Count; i++)
            {
                if (settings.kinectOptionsList[i].version == KinectVersion.KinectV1)
                {
                    kinect1Settings.Add((KinectV1Wrapper.Settings)settings.kinectOptionsList[i]);
                }
                else if (settings.kinectOptionsList[i].version == KinectVersion.KinectV2)
                {
                    kinect2Settings.Add((KinectV2Wrapper.Settings)settings.kinectOptionsList[i]);
                }
                else if (settings.kinectOptionsList[i].version == KinectVersion.NetworkKinect)
                {
                    networkSettings.Add((NetworkKinectWrapper.Settings)settings.kinectOptionsList[i]);
                }
            }
            SerializableSettings serialSettings = new SerializableSettings();
            serialSettings.masterSettings = settings;
            serialSettings.kinectV1Settings = kinect1Settings.ToArray();
            serialSettings.kinectV2Settings = kinect2Settings.ToArray();
            serialSettings.networkKinectSettings = networkSettings.ToArray();

            //Do the actual serialization
            XmlSerializer serializer = new XmlSerializer(typeof(SerializableSettings));
            using (FileStream file = new FileStream(fileName, FileMode.Create))
            {
                serializer.Serialize(file, serialSettings);
                file.Close();
                file.Dispose();
            }
        }