示例#1
0
        /// <summary>
        ///     Read the alarms stored on the disk.
        /// </summary>
        /// <returns>
        ///     A list of alarms that was read from the disk.
        ///     If there is nothing on the disk, return an empty list.
        /// </returns>
        public static async Task <T> ReadFile <T>(AppFiles file, AppFileExtension ext = AppFileExtension.JSON)
        {
            string fileName = GetFullFileName(file, ext);

            //Check if alarm file exists.
            bool alarmFileExists = await DoesFileExist(fileName);

            if (!alarmFileExists)
            {
                await CreateFile(fileName);
            }

            //Fetch  the data from the file. (JSON).
            string data = await ReadFromFile(fileName);

            if (string.IsNullOrEmpty(data))
            {
                //We don't have any stored data, return this.
                return(default(T));
            }
            else
            {
                //Convert from json of what ever was on the disk.
                return(JsonConvert.DeserializeObject <T>(data));
            }
        }
示例#2
0
        /// <summary>
        ///     Save the alarms list to disk in JSON format.
        /// </summary>
        /// <param name="alarms"> The list of alarms we want to serialize to disk.</param>
        /// <returns>Void, but async always needs to return Task.</returns>
        public static async Task SaveFile <T>(AppFiles file, AppFileExtension ext, T data)
        {
            string fileName = GetFullFileName(file, ext);

            //Overwrite the existing file.
            await CreateFile(fileName);

            //Serialize the contents and write it out the disk.
            string content = JsonConvert.SerializeObject(data);

            await WriteToFile(fileName, content);
        }
示例#3
0
        /// <summary>
        ///     Remove the alarms file, clearing out any previous alarms.
        /// </summary>
        /// <returns>Bool wether we actually cleared the alarms file or not.</returns>
        public static async Task <bool> ClearFile(AppFiles file, AppFileExtension ext)
        {
            string fileName        = GetFullFileName(file, ext);
            bool   alarmFileExists = await DoesFileExist(fileName);

            if (alarmFileExists)
            {
                await DeleteFile(fileName);

                return(true);
            }

            return(false);
        }
        public FavoritesPageViewModel()
        {
            favoritesBoxViewModels = new ObservableCollection<FavoritesBoxViewModel>();

            if (!IsInDesignMode)
            {
                appFiles = ((App)App.Current).AppFiles;
                LoadFavoritesFile();
            }
            else
            {
                InitializeDesignModeViewModel();
            }
        }
示例#5
0
        private void Start(object param)
        {
            var file = param as AppFile;
            var af   = AppFiles.First(x => x.ExeName == file.ExeName);

            af.HitNumber++;

            try
            {
                string appFileName = "";
                if (file.ExeName == "Default")
                {
                    return;                            //预留占位
                }
                if (string.IsNullOrEmpty(file.ExeFolderName))
                {
                    appFileName = Environment.CurrentDirectory + "\\tools\\" + file.ExeName + ".exe";
                }
                else
                {
                    appFileName = Environment.CurrentDirectory + "\\tools\\" + file.ExeFolderName + "\\" +
                                  file.ExeName + ".exe";
                }

                if (!System.IO.File.Exists(appFileName))
                {
                    MessageBox.Show("应用不存在!");
                    return;
                }
                try
                {
                    Process proc = Process.Start(appFileName);
                    if (proc != null)
                    {
                        SetForegroundWindow(proc.MainWindowHandle);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    //throw;
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(file.AppName + " 运行失败," + ex.Message);
            }
        }
示例#6
0
        public TopMenuViewModel()
        {
            if (!IsInDesignMode)
            {
                appFiles = ((App)App.Current).AppFiles;
                vml      = App.Current.Resources["Locator"] as ViewModelLocator;

                ZipInput = GetDefaultZip();
                InitializeCommands();
                SearchZip(zipInput);
            }
            else
            {
                ZipInput        = "12345";
                ZipErrorMessage = "Error message for zip-code.";
            }
        }
示例#7
0
 /// <summary>
 ///     Convert the two enums to a consistent file name.
 /// </summary>
 /// <param name="file">The files enum we want to convert</param>
 /// <param name="ext">The files extension enum we want to convert</param>
 /// <returns>THe file name of a combination of file and extension.</returns>
 private static string GetFullFileName(AppFiles file, AppFileExtension ext)
 {
     return($"{file.ToString().ToLower()}.{ext.ToString().ToLower()}");
 }
示例#8
0
 private LocalConfiguration()
 {
     Folders = new AppFolder();
     Files   = new AppFiles(Folders);
 }
示例#9
0
 public App()
 {
     appFiles    = new AppFiles();
     windowPlace = new WindowPlace("window.config");
     LoadFiles();
 }