/// <summary> /// Method to prepare XML file based on information about filled out survey. /// </summary> /// <returns>Return result in proper XML format.</returns> public XDocument PrepareResultDocument() { _isResultCompleted = true; DateOperations operationsOnDate = new DateOperations(); XDocument resultDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); DateTime centuryBegin = new DateTime(2001, 1, 1); string userId = OperationsOnSettings.Instance.IMEI; string time = operationsOnDate.DateTimeToMiliseconds(DateTime.Now).ToString(); ResultInfo.Time = time; ResultInfo.ParentId = Id; string resultId; if (string.IsNullOrEmpty(ResultInfo.Id)) { ResultInfo.Id = GenerateUniqueID(); } resultId = ResultInfo.Id; XElement root = new XElement("result", new XAttribute("r_id", resultId), new XAttribute("s_id", Id), new XAttribute("u_id", userId), new XAttribute("time", time), new XAttribute("version", 2)); if (((ResultInfo.Latitude == null) || (ResultInfo.Longitude == null))) { if (OperationsOnSettings.Instance.GPS) { var position = GPSService.Instance.Location; if (position != null) { IsGpsSet = true; XElement latitude = new XElement("latitude"); XElement longitude = new XElement("longitude"); latitude.Value = position.Latitude.ToString(); longitude.Value = position.Longitude.ToString(); ResultInfo.Latitude = position.Latitude.ToString(); ResultInfo.Longitude = position.Longitude.ToString(); root.Add(latitude); root.Add(longitude); OperationsOnListOfResults listOperator = new OperationsOnListOfResults(Id); listOperator.UpdateLocation(ResultInfo.Id, position.Latitude.ToString(), position.Longitude.ToString()); } else { IsGpsSet = false; } } else { IsGpsSet = true; } } else { XElement latitude = new XElement("latitude"); XElement longitude = new XElement("longitude"); latitude.Value = ResultInfo.Latitude; longitude.Value = ResultInfo.Longitude; root.Add(latitude); root.Add(longitude); IsGpsSet = true; } XElement titleElement = new XElement("title"); if (!string.IsNullOrEmpty(ResultInfo.Title)) { titleElement.Value = ResultInfo.Title; } root.Add(titleElement); foreach (Category category in Categories) { XElement categoryXElement = new XElement("category", new XAttribute("name", category.Name), new XAttribute("id", category.Id)); if (!category.AddResult(categoryXElement)) { _isResultCompleted = false; } root.Add(categoryXElement); } resultDocument.AddFirst(root); ResultInfo.IsResultCompleted = _isResultCompleted; return(resultDocument); }
/// <summary> /// Method to prepare XML file based on information about filled out survey. /// </summary> /// <returns>Return result in proper XML format.</returns> public XDocument PrepareResultDocument() { _isResultCompleted = true; DateOperations operationsOnDate = new DateOperations(); XDocument resultDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); DateTime centuryBegin = new DateTime(2001, 1, 1); string userId = OperationsOnSettings.Instance.IMEI; string time = operationsOnDate.DateTimeToMiliseconds(DateTime.Now).ToString(); ResultInfo.Time = time; ResultInfo.ParentId = Id; string resultId; if (string.IsNullOrEmpty(ResultInfo.Id)) { ResultInfo.Id = GenerateUniqueID(); } resultId = ResultInfo.Id; XElement root = new XElement("result", new XAttribute("r_id", resultId), new XAttribute("s_id", Id), new XAttribute("u_id", userId), new XAttribute("time", time), new XAttribute("version", 2)); if (((ResultInfo.Latitude == null) || (ResultInfo.Longitude == null))) { if (OperationsOnSettings.Instance.GPS) { var position = GPSService.Instance.Location; if (position != null) { IsGpsSet = true; XElement latitude = new XElement("latitude"); XElement longitude = new XElement("longitude"); latitude.Value = position.Latitude.ToString(); longitude.Value = position.Longitude.ToString(); ResultInfo.Latitude = position.Latitude.ToString(); ResultInfo.Longitude = position.Longitude.ToString(); root.Add(latitude); root.Add(longitude); OperationsOnListOfResults listOperator = new OperationsOnListOfResults(Id); listOperator.UpdateLocation(ResultInfo.Id, position.Latitude.ToString(), position.Longitude.ToString()); } else { IsGpsSet = false; } } else { IsGpsSet = true; } } else { XElement latitude = new XElement("latitude"); XElement longitude = new XElement("longitude"); latitude.Value = ResultInfo.Latitude; longitude.Value = ResultInfo.Longitude; root.Add(latitude); root.Add(longitude); IsGpsSet = true; } XElement titleElement = new XElement("title"); if (!string.IsNullOrEmpty(ResultInfo.Title)) titleElement.Value = ResultInfo.Title; root.Add(titleElement); foreach (Category category in Categories) { XElement categoryXElement = new XElement("category", new XAttribute("name", category.Name), new XAttribute("id", category.Id)); if (!category.AddResult(categoryXElement)) { _isResultCompleted = false; } root.Add(categoryXElement); } resultDocument.AddFirst(root); ResultInfo.IsResultCompleted = _isResultCompleted; return resultDocument; }