public static void fillValuesNet(
            ValuesNet emptyValuesMap,
            string folder,
            ProgressChangedEventHandler processHandler,
            RunWorkerCompletedEventHandler completeHandler)
        {
            List <string> directories = new List <string>();
            List <string> files       = new List <string>();

            foreach (string path in Directory.GetDirectories(folder))
            {
                if (Directory.Exists(path))
                {
                    directories.Add(path);
                }
                else if (File.Exists(path))
                {
                    files.Add(path);
                }
            }

            List <CPDataGeo> data = new List <CPDataGeo>();

            Dictionary <SensorType, CPData> CPdata;

            BackgroundWorker bw = new BackgroundWorker();

            bw.WorkerReportsProgress = true;
            bw.DoWork += (sender, e) =>
            {
                double i = 0;
                foreach (string path in directories)
                {
                    CPdata = CPData.fromDirectory(path);
                    if (CPdata.ContainsKey(SensorType.ACCELEROMETER) && CPdata.ContainsKey(SensorType.GPS))
                    {
                        data.Add(new CPDataGeo(CPdata[SensorType.ACCELEROMETER], CPdata[SensorType.GPS]));
                    }
                    i++;

                    bw.ReportProgress((int)(i / directories.Count * 100));
                }

                CPdata = CPData.fromDirectory(folder);
                if (CPdata.ContainsKey(SensorType.ACCELEROMETER) && CPdata.ContainsKey(SensorType.GPS))
                {
                    data.Add(new CPDataGeo(CPdata[SensorType.ACCELEROMETER], CPdata[SensorType.GPS]));
                }
            };
            bw.ProgressChanged    += processHandler;
            bw.RunWorkerCompleted += delegate
            {
                fillValuesNet(emptyValuesMap, data, processHandler, completeHandler);
            };
            bw.RunWorkerAsync();
        }
Beispiel #2
0
        public static Dictionary <SensorType, CPData> fromDirectory(string path)
        {
            if (!Directory.Exists(path))
            {
                throw new DirectoryNotFoundException("No such directory!");
            }

            Dictionary <SensorType, CPData> data = new Dictionary <SensorType, CPData>();

            string[] files = Directory.GetFiles(path);
            foreach (string p in files)
            {
                CPData cpd = new CPData(p);
                data.Add(cpd.sensor, cpd);
            }

            return(data);
        }