private static void WriteViolationsToOutpuFile(List <InputDataUnit> violatedOutputRules) { var violatedFilePath = ApplicationSettingsUtility.GetViolatedRulesOutputFilePath(); if (string.IsNullOrEmpty(violatedFilePath)) { var currExeDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var currOutputDirPath = Path.Combine(currExeDirPath, "Output"); if (!Directory.Exists(currOutputDirPath)) { Directory.CreateDirectory(currOutputDirPath); } violatedFilePath = Path.Combine(currOutputDirPath, "violated_rules_dataunit.json"); File.Create(violatedFilePath).Dispose(); } try { JSONService.WriteOutputData(violatedFilePath, violatedOutputRules); Console.WriteLine($"There were some rule violations, which are displayed on screen \nAnd also copied to {violatedFilePath} file"); } catch (Exception) { Console.WriteLine($"Couldn't write violated rules to output file : {violatedFilePath}, So Only displayed on screen"); } }
public HomePageViewModel() { places = new ObservableCollection <PlaceItem>(); JSONService j = new JSONService(); //j.CodeASupprimer(); //PlaceItem t = j.GetPlace(0); //places = t.Result; places.Add(new PlaceItem { Title = "Paris", Description = "embouteillé et polué", ImageId = 0, Id = 1 }); /*places.Add(new PlaceItem { Title = "Bruxelles", Description = "un tres beau voyage", ImageId = 0, Id = 0 }); * * places.Add(new PlaceItem { Title = "JeSaisPasOU", Description = "c'est moche", ImageId = 0, Id = 2}); * //places.Add(new Lieu { Name = "Paris", Description = "embouteillé et polué", ImagePath= "drawable/autumn.jpg" }); * //places.Add(new Lieu { Name = "JeSaisPasOU", Description = "c'est moche", ImagePath = "drawable/autumn.jpg" }); * PlaceItem lieu = new PlaceItem { Title = "JeSaisPasOU", Description = "c'est moche", ImageId = 0, Id = 3}; * List<CommentItem> list = new List<CommentItem>(); * list.Add(new CommentItem { Author = new UserItem(), Text = "text1", Date = new DateTime() }); * lieu.Comments = list; * places.Add(lieu);*/ //dt = new DataTemplate(typeof(CustomVeggieCell)); //PressMeCommand = new Command(pressMeAction); }
public async Task <IActionResult> SearchResultsAsync(SearchModel model) { var jsonService = new JSONService(); var results = await jsonService.GetResults(model.query, model.searchType, model.limit); return(View(results)); }
public void LoadSettings() { try { if (File.Exists(path)) { instance = JSONService <AppSettingsProvider> .Deserialize(path).Result; } } catch { } }
private async void pressMeAction2(object sender, EventArgs e) { Console.WriteLine("pressMeAction2"); //binder.lieuCourant = sender.; JSONService j = new JSONService(); j.CodeASupprimer(); //await j.GetPlaces(); PlaceItem t = await j.GetPlace(0); binder.places.Add(t); }
public ReportWindowViewModel(ref SummitSystem theSummitLeft, ref SummitSystem theSummitRight, ILog _log) { this._log = _log; this.theSummitLeft = theSummitLeft; this.theSummitRight = theSummitRight; jSONService = new JSONService(_log); //Medication and Condition list for report window. //Both of these collection data come from the same json file MedicationList = new ObservableCollection <MedicationCheckBoxClass>(); ConditionList = new ObservableCollection <ConditionCheckBoxClass>(); //These two methods are implemented in ReportViewModel.cs reportModel = jSONService?.GetReportModelFromFile(reportFilePath); if (reportModel == null) { return; } GetListOfMedicationsConditionsFromModel(); }
public MontageViewModel(ref SummitSystem theSummitLeft, ref SummitSystem theSummitRight, ILog _log, AppModel appModel) { this.theSummitLeft = theSummitLeft; this.theSummitRight = theSummitRight; this.isBilateral = appModel.Bilateral; this._log = _log; this.appModel = appModel; IsMontageEnabled = true; summitSensing = new SummitSensing(_log); jSONService = new JSONService(_log); stimParameterLeft = new StimParameterModel("", "", "", "", null); stimParameterRight = new StimParameterModel("", "", "", "", null); montageModel = jSONService.GetMontageModelFromFile(MONTAGE_FILEPATH); if (montageModel == null) { MessageBox.Show("The montage config file could not be read from the file. Please check that it exists.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } montageSweepConfigListLeft = montageSweepConfigListRight = LoadSenseJSONFilesForMontage(MONTAGE_BASEFILEPATH, MONTAGE_FILETYPE, montageModel); if (montageSweepConfigListLeft == null || montageSweepConfigListRight == null) { IsMontageEnabled = false; return; } //Get total time left and total time for montage. Display on progress bar timeLeftForMontage = totalTimeForMontage = GetTotalTimeForMontage(montageModel); TimeSpan time = TimeSpan.FromSeconds(timeLeftForMontage); //here backslash is must to tell that colon is //not the part of format, it just a character that we want in output string str = time.ToString(@"hh\:mm\:ss"); MontageTimeTextBox = "Total Montage Time: " + str; InstructionsTextBox = montageModel?.Instructions; }
private static Tuple <bool, List <InputDataUnit> > GetViolationsTuple(string inputFilePath, Rules rules) { var violationTuple = new Tuple <bool, List <InputDataUnit> >(false, null); List <InputDataUnit> violatedOutputRules = new List <InputDataUnit>(); try { foreach (var inputData in JSONService.ReadInputData(inputFilePath)) { if (!RulesService.IsValidRule(inputData, rules)) { Console.WriteLine($"{inputData.Signal}\t :\t {inputData.ValueType}\t :\t {inputData.Value}"); violatedOutputRules.Add(inputData); } } } catch (Exception ex) { Console.WriteLine("Error in raw_data.json file. " + ex.Message); return(violationTuple); } return(new Tuple <bool, List <InputDataUnit> >(true, violatedOutputRules)); }
/// <summary> /// convert data from an input file to a new format and output to a new file /// this function could be broken down into smaller functions /// i.e. getData, convertData, writeData functions /// </summary> /// <param name="inputFile"></param> /// <param name="outputFile"></param> /// <param name="convertTo"></param> static void ConvertData(string inputFile, string outputFile, string convertTo) { // initialise variables CSVService inputService = null; IService <string, string, string> outputService = null; IBuilder builder = null; Converter converter = null; // get data inputService = new CSVService(inputFile); var lines = inputService.GetAllData(); // create builder and output services dependent on new format required switch (convertTo.ToLower()) { case "xml": builder = new XMLBuilder("root", "entity"); outputService = new XMLService(outputFile); break; case "json": builder = new JSONBuilder(); outputService = new JSONService(outputFile); break; default: throw new ArgumentNullException("Invalid file format to convert to"); } // do the conversion converter = new Converter(builder); var data = converter.ConvertCSV(lines.headings, lines.data); // write the new file outputService.WriteData(data); WriteLine($"Created {convertTo} file: {outputFile}"); }
public string GetUserByID(string uid) { User user = UserDB.FetchUserByID(uid); return(JSONService.SerializeToJson(user)); }
public ActionResult CreateDictionary(string s) { string path; path = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); string localPath = new Uri(path).LocalPath; string userPreferencesFile = "C:/Users/swapn/Desktop/Thesis/ThesisProject/ThesisProject/Data/UserPreference.json"; string trainingSetFile = "C:/Users/swapn/Desktop/Thesis/ThesisProject/ThesisProject/Data/TrainingSet.json"; JSONService<UserPreference> userPreferenceReader = new JSONService<UserPreference>(); UserPreference up = userPreferenceReader.ConvertJSONToObject(userPreferencesFile); JSONService<List<TrainingSet>> trainingSetReader = new JSONService<List<TrainingSet>>(); List<TrainingSet> ts = trainingSetReader.ConvertJSONToObject(trainingSetFile); Dictionary<string, List<string>> keywordDict = new Dictionary<string, List<string>>(); foreach (string item in up.ShoppingDomain) { foreach (TrainingSet t in ts) { if (t.From.Contains(item)) { List<string> subjectWords = new List<string>(t.Subject.Split(' ')); List<string> bodyWords = new List<string>(t.Body.Split(' ')); List<string> allWords = new List<string>(); subjectWords = (from x in subjectWords where IsWordAStopWord(x) == false select x).ToList(); bodyWords = (from x in bodyWords where IsWordAStopWord(x) == false select x).ToList(); allWords.AddRange(subjectWords); allWords.AddRange(bodyWords); List<string> mostFreqWords = GetWordsWithMostFrequency(allWords, 1); if (keywordDict.ContainsKey("ShoppingDomain")) { List<string> keywordList = keywordDict["ShoppingDomain"]; keywordList.AddRange(mostFreqWords); } else // no key exists...create a key and assign the value { keywordDict["ShoppingDomain"] = mostFreqWords; } } } } string keywordjson = JsonConvert.SerializeObject(keywordDict); //System.IO.File.Delete(localPath + @"\Data\KeywordDictFile.json"); System.IO.File.WriteAllText("C:/Users/swapn/Desktop/Thesis/ThesisProject/ThesisProject/Data/KeywordDictFile.json", keywordjson); Dictionary<string, List<string>> key = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(keywordjson); return View(); }
public ActionResult UserHome() { JSONService<UserPreference> jsonReader = new JSONService<UserPreference>(); string path; path = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); string localPath = new Uri(path).LocalPath; //UserPreference up = jsonReader.ConvertJSONToObject(localPath + @"\Data\UserPreference.json"); UserPreference up = jsonReader.ConvertJSONToObject("C:/Users/swapn/Desktop/Thesis/ThesisProject/ThesisProject/Data/UserPreference.json"); return View(up); }
public string GetUserWalletsByKey(long userID) => JSONService.SerializeToJson(WalletDB.FetchUserWallets(userID));
public string GetWalletByKey(string address) { Wallet wallet = WalletDB.FetchWalletByKey(address); return(JSONService.SerializeToJson(wallet)); }
public async void SaveSettings() { await JSONService <AppSettingsProvider> .Serialize(instance, path); }