public void AddCompany(Models.CompanyInformation source) { logger.Info("Adding new company " + source.CompanyName + "(" + source.CompanyID + ")"); try { System.IO.Directory.CreateDirectory(DatabasePath + source.CompanyID); } catch (Exception e) { logger.Fatal("Error creating directory", e); } try { var temp = new XElement("Settings", source.GetXElement()); File.WriteAllText(DatabasePath + source.CompanyID + "\\Others.xml", temp.ToString(), Encoding.UTF8); } catch (Exception e) { logger.Fatal("Error saving the initial settings document", e); } }
public async Task<bool> ChangeCompany(Models.CompanyInformation target) { logger.Info("Request to change company to " + target.CompanyName + " (" + target.CompanyID + ")"); XElement doc; if (!File.Exists(DatabasePath + "Settings.xml")) { logger.Debug(DatabasePath + "Settings.xml" + " didn't exist. Maybe no company was set before."); doc = new XElement("ApplicationSettings", new XElement("CurrentCompany", target.GetXElement())); } else { //Case when FirstLoad is true try { doc = XElement.Parse(File.ReadAllText(DatabasePath + "Settings.xml", Encoding.UTF8)); doc.Element("CurrentCompany").Element(CurrentCompany.XElementName).ReplaceWith(target.GetXElement()); } catch (Exception e) { logger.Fatal("Error while parsing or replacing the current company. Exiting the methode without changeing the company.", e); return false; } } try { File.WriteAllText(DatabasePath + "Settings.xml", doc.ToString(), Encoding.UTF8); } catch (Exception e) { logger.Fatal("Could not write the changes into the file", e); } logger.Info("Reconnecting database"); return await Connect(); }