示例#1
0
        public void SaveWtmSettings()
        {
            string json          = JsonConverter.ConvertToJson(WtmSettings);
            string jsonFormatted = JsonConverter.FormatJson(json);

            Helpers.WriteToTxtFile(Constants.WtmSettingsFile, jsonFormatted);
        }
示例#2
0
        private async void ExportWorkersCommand(object parameter)
        {
            var window = new SelectWorkers();

            window.SizeToContent = SizeToContent.WidthAndHeight;
            var vm = new SelectWorkersVM();

            vm.Workers = Workers.WorkerList;

            bool[] queries = SaveQueries();

            window.DataContext = vm;
            vm.Title           = "Export Workers";
            vm.ButtonTitle     = "Export";
            var dialogResult = window.ShowDialog();

            if (dialogResult == false)
            {
                RestoreQueries(queries);
                return;
            }

            var workersToSave = Workers.WorkerList.Where(x => x.Query).ToList();

            if (workersToSave == null || workersToSave.Count == 0)
            {
                RestoreQueries(queries);
                return;
            }

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter          = "JSON file|*.json";
            saveFileDialog.OverwritePrompt = true;
            var saveDialogResult = saveFileDialog.ShowDialog();

            if (saveDialogResult == false)
            {
                RestoreQueries(queries);
                return;
            }

            var json = JsonConverter.ConvertToJson(workersToSave);

            if (json == null)
            {
                await Task.Delay(100);

                MessageBox.Show("Failed to convert selected workers to JSON format", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                RestoreQueries(queries);
                return;
            }
            string jsonFormatted = JsonConverter.FormatJson(json);

            Helpers.WriteToTxtFile(saveFileDialog.FileName, jsonFormatted);
            RestoreQueries(queries);
        }
示例#3
0
 public static bool SaveWorkers(Workers workers)
 {
     try
     {
         string json          = JsonConverter.ConvertToJson(workers);
         string jsonFormatted = JsonConverter.FormatJson(json);
         Helpers.WriteToTxtFile(Constants.WorkersFile, jsonFormatted);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#4
0
        private void ExportCommand(object parameter)
        {
            bool           emptyLineRequired = (ProfitTables.Tables.Count > 1);
            SaveFileDialog saveFileDialog    = new SaveFileDialog();

            saveFileDialog.Filter          = "CSV file|*.csv|JSON file|*.json|XML File|*.xml";
            saveFileDialog.OverwritePrompt = true;
            var dialogResult = saveFileDialog.ShowDialog();

            if (dialogResult == false)
            {
                return;
            }
            string       path      = saveFileDialog.FileName;
            string       extension = Path.GetExtension(path).ToLower();
            StreamWriter writer    = null;

            try { writer = new StreamWriter(path); }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (writer != null)
            {
                try
                {
                    var selectedWorkers = Workers.WorkerList.Where(x => x.Query).Select(x => x.Name);
                    var selectedTables  = ProfitTables.Tables.Where(x => selectedWorkers.Contains(x.Name));

                    switch (extension)
                    {
                    case ".csv":
                        writer.WriteLine("Values in," + WtmSettings.DisplayCurrency);
                        writer.WriteLine();

                        foreach (var table in selectedTables)
                        {
                            writer.WriteLine("Worker," + "\"" + table.Name + "\"");
                            writer.WriteLine("Description," + "\"" + table.Description + "\"");
                            writer.WriteLine("Computers," + "\"" + string.Join(", ", table.ComputerNames) + "\"");
                            writer.WriteLine("Name," + "Symbol," + "Algorithm," + "Hashrate," + "Path," + "Arguments," + "Revenue," + "Profit Day," + "Profit Week," + "Profit Month," + "Profit Year," + "Notes,");
                            foreach (var list in table.ProfitList)
                            {
                                if (WtmSettings.DisplayCurrency != "USD")
                                {
                                    var rate = WtmSettings.DisplayCurrencyList[WtmSettings.DisplayCurrency];
                                    list.Revenue     /= rate;
                                    list.ProfitDay   /= rate;
                                    list.ProfitWeek  /= rate;
                                    list.ProfitMonth /= rate;
                                    list.ProfitYear  /= rate;
                                }
                                var line = $"\"{list.Name}\",\"{list.Symbol}\",\"{list.Algorithm}\",\"{list.Hashrate}\",\"{list.Path}\",\"{list.Arguments}\",\"{list.Revenue}\",\"{list.ProfitDay}\",\"{list.ProfitWeek}\",\"{list.ProfitMonth}\",\"{list.ProfitYear}\",\"{list.Notes}\"";
                                writer.WriteLine(line);
                            }
                            if (emptyLineRequired)
                            {
                                writer.WriteLine("");
                            }
                            writer.Flush();
                        }
                        break;

                    case ".json":
                        var json = JsonConverter.ConvertToJson(selectedTables);
                        json = JsonConverter.FormatJson(json);
                        writer.Write(json);
                        break;

                    case ".xml":
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <ProfitTable>));
                        xmlSerializer.Serialize(writer, selectedTables.ToList());
                        break;
                    }
                }
                catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); }
                finally { writer.Dispose(); }
            }
        }