private void SavetTestResult(Survey survey, XDocument documentXML) { String dataToSave; if ((bool)OperationsOnSettings.Instance.IsEncryptionEnabled) { AESEncryption encrypter = new AESEncryption(); dataToSave = encrypter.Encrypt(documentXML.ToString(), App.AppDictionary["EncryptionPassword"] as String, "qwhmvbzx"); } else { dataToSave = documentXML.ToString(); } using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { String directoryPath = String.Format("surveys/{0}", survey.Id); string resultFilePath = System.IO.Path.Combine(directoryPath, String.Format("r_{0}.xml", survey.ResultInfo.Id)); if (!isolatedStorage.DirectoryExists(directoryPath)) { isolatedStorage.CreateDirectory(directoryPath); } using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(resultFilePath, FileMode.Create, isolatedStorage)) { StreamWriter writer = new StreamWriter(isoStream); writer.Write(dataToSave); writer.Close(); } } OperationsOnListOfResults operationsOnListOfResults = new OperationsOnListOfResults(SurveyId); operationsOnListOfResults.Add(survey.ResultInfo); }
private bool CheckIfPasswordIsCorrect() { if (!String.IsNullOrEmpty(EncryptionPassword)) { ObservableCollection <SurveyBasicInfo> surveys = new ObservableCollection <SurveyBasicInfo>(); OperationsOnListOfSurveys operations = new OperationsOnListOfSurveys(surveys, new DownloadListStatus()); operations.Read(); foreach (SurveyBasicInfo survey in surveys) { ObservableCollection <ResultBasicInfo> results = new ObservableCollection <ResultBasicInfo>(); OperationsOnListOfResults resultsOperator = new OperationsOnListOfResults(survey.SurveyId, results); resultsOperator.ReadList(); foreach (ResultBasicInfo result in results) { Survey surveyModel = new Survey(); surveyModel.Id = survey.SurveyId; surveyModel.ResultInfo = result; try { surveyModel.GetSavedDocument(); return(true); } catch (CryptographicException) { return(false); } } } return(true); } return(false); }
/// <summary> /// Sends result to server. /// </summary> /// <param name="selectedListBoxItem">Contains information of result that was selected by user and will be send on server.</param> public void SendResult(ResultBasicInfo selectedListBoxItem) { ProgressBar.Information = Languages.AppResources.surveyViewModel_sendingProgressTitle; ProgressBar.IsEnabled = true; Operations = new OperationsOnListOfResults(selectedListBoxItem.ParentId); IsSending = true; ResultSender.Send(selectedListBoxItem.ParentId, selectedListBoxItem); }
/// <summary> /// Constructor which initializes properties and using input surveyId like ID of survey. /// </summary> /// <param name="surveyId">ID of survey.</param> public SurveyViewModel(string surveyId) { ListOfResults = new ObservableCollection <ResultBasicInfo>(); _operations = new OperationsOnListOfResults(surveyId, ListOfResults); SurveyId = surveyId; ProgressBar = new ProcessingBar(); Message = new DialogBox(); _resultSender = new SendResult(); _resultSender.SendingCompleted += (object sender, EventArgs args) => { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { SendResult.SendingEventArgs.SendingStatus status = (args as SendResult.SendingEventArgs).Status; string resultId = (args as SendResult.SendingEventArgs).ResultId; switch (status) { case Model.SendResult.SendingEventArgs.SendingStatus.Sent: Message.Show(Languages.AppResources.surveyViewModel_sendingCompleted); _operations.MarkResultAsSent(resultId); break; case Model.SendResult.SendingEventArgs.SendingStatus.ServerError: Message.Show(Languages.AppResources.surveyViewModel_serverError); break; case Model.SendResult.SendingEventArgs.SendingStatus.UnknownError: Message.Show(Languages.AppResources.surveyViewModel_unknownError); break; case Model.SendResult.SendingEventArgs.SendingStatus.Canceled: break; } ProgressBar.IsEnabled = false; SendingInProgress = false; }); }; }
/// <summary> /// Method to unmark result as sent. After unmark result as sent user can again modify the result. /// </summary> /// <param name="result">Information about which result was selected by user.</param> public void UnmarkSent(ResultBasicInfo result) { Operations = new OperationsOnListOfResults(result.ParentId); Operations.UnmarkSentResult(result.Id); }
private void AddResultToList() { OperationsOnListOfResults operationsOnListOfResults = new OperationsOnListOfResults(Id); operationsOnListOfResults.Add(ResultInfo); }
/// <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); }
private void AddResultToList() { OperationsOnListOfResults operationsOnListOfResults = new OperationsOnListOfResults(Id); operationsOnListOfResults.Add(ResultInfo); }
/// <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; }