/// <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;
                });
            };
        }
Пример #2
0
        /// <summary>
        /// Deletes single survey from IsolatedStorage.
        /// </summary>
        /// <param name="surveyId">Id of survey you want to delete.</param>
        public void Delete(string surveyId)
        {
            Read();
            IEnumerable <SurveyBasicInfo> surveys;

            surveys = from SurveyBasicInfo in _list where SurveyBasicInfo.SurveyId == surveyId select SurveyBasicInfo;
            try
            {
                OperationsOnListOfResults resultsOperations = new OperationsOnListOfResults(surveyId);
                resultsOperations.DeleteAllResults();
                SurveyBasicInfo survey = surveys.First <SurveyBasicInfo>();
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    string filePath         = System.IO.Path.Combine("surveys", string.Format("{0}.xml", survey.SurveyId));
                    string directoryPath    = System.IO.Path.Combine("surveys", survey.SurveyId);
                    string listOfResultPath = System.IO.Path.Combine(directoryPath, "listOfResults.xml");
                    try
                    {
                        isoStore.DeleteFile(filePath);
                        isoStore.DeleteFile(listOfResultPath);
                        isoStore.DeleteDirectory(directoryPath);
                    }
                    catch (IsolatedStorageException) { /*that means that this files doesn't exists*/ }
                }
                _list.Remove(survey);
                Write();
            }
            catch (InvalidOperationException) { }
        }
Пример #3
0
        /// <summary>
        /// Removes result from list. Uses <see cref="OperationsOnListOfResults"/> to remove data from IsolatedStorage.
        /// </summary>
        /// <param name="result">Instance of <see cref="ResultBasicInfo"/> class which holds that of result you want to remove.</param>
        public void DeleteResult(ResultBasicInfo result)
        {
            var results = from item in App.AppDictionary["FilteredResults"] as ObservableCollection <ResultsFilter.GroupedOC <ResultBasicInfo> > where item.Contains(result) select item;
            GroupedOC <ResultBasicInfo> entity = results.First <GroupedOC <ResultBasicInfo> >();

            entity.Remove(result);
            if (entity.Count == 0)
            {
                (App.AppDictionary["FilteredResults"] as ObservableCollection <ResultsFilter.GroupedOC <ResultBasicInfo> >).Remove(entity);
            }
            OperationsOnListOfResults operations = new OperationsOnListOfResults(result.ParentId);

            operations.DeleteResult(result.Id);
        }
 /// <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);
 }
 /// <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>
        /// Deletes single survey from IsolatedStorage.
        /// </summary>
        /// <param name="surveyId">Id of survey you want to delete.</param>
        public void Delete(string surveyId)
        {
            Read();
            IEnumerable<SurveyBasicInfo> surveys;
            surveys = from SurveyBasicInfo in _list where SurveyBasicInfo.SurveyId == surveyId select SurveyBasicInfo;
            try
            {
                OperationsOnListOfResults resultsOperations = new OperationsOnListOfResults(surveyId);
                resultsOperations.DeleteAllResults();
                SurveyBasicInfo survey = surveys.First<SurveyBasicInfo>();
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    string filePath = System.IO.Path.Combine("surveys", string.Format("{0}.xml", survey.SurveyId));
                    string directoryPath = System.IO.Path.Combine("surveys", survey.SurveyId);
                    string listOfResultPath = System.IO.Path.Combine(directoryPath, "listOfResults.xml");
                    try
                    {
                        isoStore.DeleteFile(filePath);
                        isoStore.DeleteFile(listOfResultPath);
                        isoStore.DeleteDirectory(directoryPath);
                    }
                    catch (IsolatedStorageException) { /*that means that this files doesn't exists*/ }
                }
                _list.Remove(survey);
                Write();

            }
            catch (InvalidOperationException) { }
        }
        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);
        }