예제 #1
0
        public TrulyObservableCollection <Series> Load()
        {
            var env = Properties.Settings.Default.UsageEnv;

            if (env == UsageEnvironments.Local.ToString())
            {
                return(LoadFromAppData());
            }
            else if (env == UsageEnvironments.Nas.ToString())
            {
                var appDataData = LoadFromAppData();
                var result      = new TrulyObservableCollection <Series>();

                foreach (var itemFromAppData in appDataData)
                {
                    var currentFileFromInFolder = LoadCurrentFileNameFromSeriesFolder(itemFromAppData.FolderPath);
                    var folder = itemFromAppData.FolderPath;
                    var file   = currentFileFromInFolder ?? itemFromAppData.CurrentFileName;
                    var series = new Series()
                    {
                        FolderPath = folder, CurrentFileName = file
                    };
                    result.Add(series);
                }
                return(result);
            }
            else
            {
                Properties.Settings.Default.UsageEnv = UsageEnvironments.Local.ToString();
                Properties.Settings.Default.Save();
                throw new ApplicationException("Unknown usage env - has been reset");
            }
        }
예제 #2
0
        private void SaveAllDataToAppData(TrulyObservableCollection <Series> list)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            collectionSerializer.Serialize(sw, list);
            string xmlResult = sw.GetStringBuilder().ToString();

            Directory.CreateDirectory(Path.GetDirectoryName(appDataFile));
            File.WriteAllText(appDataFile, xmlResult);
        }
예제 #3
0
        private void SaveCurrentFileToEachFolder(TrulyObservableCollection <Series> list)
        {
            foreach (var item in list)
            {
                string dataFile = Path.Combine(item.FolderPath, inFolderFileName);

                if (File.Exists(dataFile))
                {
                    File.SetAttributes(dataFile, FileAttributes.Normal);
                }
                File.WriteAllText(dataFile, item.CurrentFileName, Encoding.UTF8);
                File.SetAttributes(dataFile, FileAttributes.Hidden);
            }
        }
예제 #4
0
        public void Persist(TrulyObservableCollection <Series> list)
        {
            var env = Properties.Settings.Default.UsageEnv;

            if (env == UsageEnvironments.Local.ToString())
            {
                SaveAllDataToAppData(list);
            }
            else if (env == UsageEnvironments.Nas.ToString())
            {
                SaveAllDataToAppData(list);
                SaveCurrentFileToEachFolder(list);
            }
            else
            {
                throw new ApplicationException("Unknown usage env");
            }
        }