Example #1
0
        static void Main()
        {
            // Example of using the Nfield SDK with a user defined IoC container.
            // In most cases the IoC container is created and managed through the application.
            using (IKernel kernel = new StandardKernel())
            {
                InitializeNfield(kernel);

                const string serverUrl = "http://*****:*****@"*QUESTION 1 *CODES 61L1
                               Do you watch TV?
                                1:Yes
                                2:No
                                *END"
                };
                var updatedScript = surveyScriptService.PostAsync("surveyWithOdinScriptId", myScript).Result;
                // Upload survey script with file path
                var scriptFilePath  = @"C:\SimpleQ.odin";
                var myUpdatedScript =
                    surveyScriptService.PostAsync("surveyWithOdinScriptId", scriptFilePath).Result;

                // Create survey
                var newSurvey = surveysService.AddAsync(new Survey(SurveyType.Basic)
                {
                    ClientName  = "clientName",
                    Description = "description",
                    SurveyName  = "abc"
                }).Result;

                surveyScriptService.PostAsync(newSurvey.SurveyId, myScript).Wait();

                var surveyFieldworkService = connection.GetService <INfieldSurveyFieldworkService>();
                //Get survey fieldwork status
                var surveyFieldworkStatus = surveyFieldworkService.GetStatusAsync(newSurvey.SurveyId).Result; //Should be under construction

                // Start the fieldwork for the survey
                surveyFieldworkService.StartFieldworkAsync(newSurvey.SurveyId).Wait();
                surveyFieldworkStatus = surveyFieldworkService.GetStatusAsync(newSurvey.SurveyId).Result; //Should be started

                // Example of a download data request: filtering testdata collected today
                var surveyDataService = connection.GetService <INfieldSurveyDataService>();

                var myRequest = new SurveyDownloadDataRequest
                {
                    DownloadSuccessfulLiveInterviewData    = false,
                    DownloadNotSuccessfulLiveInterviewData = false,
                    DownloadOpenAnswerData             = true,
                    DownloadClosedAnswerData           = true,
                    DownloadSuspendedLiveInterviewData = false,
                    DownloadCapturedMedia     = false,
                    DownloadParaData          = false,
                    DownloadTestInterviewData = true,
                    DownloadFileName          = "MyFileName",
                    StartDate = DateTime.Today.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture),            // UTC time start of today
                    EndDate   = DateTime.Today.AddDays(1).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture), // UTC time end of today
                    SurveyId  = "SomeSurveyId"
                };

                var task = surveyDataService.PostAsync(myRequest).Result;

                // request the background tasks service
                var backgroundTasksService = connection.GetService <INfieldBackgroundTasksService>();

                // Example of performing operations on background tasks.
                var backgroundTaskQuery = backgroundTasksService.QueryAsync().Result.Where(s => s.Id == task.Id);
                var mybackgroundTask    = backgroundTaskQuery.FirstOrDefault();

                if (mybackgroundTask != null)
                {
                    var status = mybackgroundTask.Status;
                }

                // Example of creating a new translation
                const string surveyName      = "Language";
                const string languageName    = "Dutch";
                const string translationName = "ButtonNext";
                const string translationText = "Volgende";
                // First create the survey if it does not exist
                var languageSurvey = surveysService.QueryAsync().Result
                                     .SingleOrDefault(s => s.SurveyName == surveyName);
                if (languageSurvey == null)
                {
                    languageSurvey = surveysService.AddAsync(
                        new Survey(SurveyType.Basic)
                    {
                        SurveyName = surveyName
                    }).Result;
                }
                // Then find the language we wish to change a translation for
                var languageService = connection.GetService <INfieldLanguagesService>();
                var language        = languageService.QueryAsync(languageSurvey.SurveyId)
                                      .Result.SingleOrDefault(l => l.Name == languageName);
                if (language == null)
                {
                    language = languageService.AddAsync(languageSurvey.SurveyId,
                                                        new Language {
                        Name = languageName
                    }).Result;
                }
                // Now add or update a translation
                var translationsService = connection.GetService <INfieldTranslationsService>();
                var translation         = translationsService.QueryAsync(languageSurvey.SurveyId,
                                                                         language.Id).Result.SingleOrDefault(t => t.Name == translationName);
                if (translation == null)
                {
                    translationsService.AddAsync(languageSurvey.SurveyId,
                                                 language.Id, new Translation
                    {
                        Name = translationName,
                        Text = translationText
                    }).Wait();
                }
                else
                {
                    translation.Text = translationText;
                    translationsService.UpdateAsync(languageSurvey.SurveyId,
                                                    language.Id, translation).Wait();
                }
            }
        }
Example #2
0
        static void Main()
        {
            // Example of using the Nfield SDK with a user defined IoC container.
            // In most cases the IoC container is created and managed through the application.
            using(IKernel kernel = new StandardKernel())
            {
            #if DEBUG
                ServicePointManager.ServerCertificateValidationCallback +=
                        (sender, cert, chain, sslPolicyErrors) => true;
            #endif
                InitializeNfield(kernel);

                const string serverUrl = "http://*****:*****@"*QUESTION 1 *CODES 61L1
                               Do you watch TV?
                                1:Yes
                                2:No
                                *END"
                };
                var updatedScript = surveyScriptService.PostAsync("surveyWithOdinScriptId", myScript).Result;
                // Upload survey script with file path
                var scriptFilePath = @"C:\SimpleQ.odin";
                var myUpdatedScript =
                    surveyScriptService.PostAsync("surveyWithOdinScriptId", scriptFilePath).Result;

                // Create survey
                var newSurvey = surveysService.AddAsync(new Survey(SurveyType.Basic)
                {
                    ClientName = "clientName",
                    Description = "description",
                    SurveyName = "abc"
                }).Result;

                surveyScriptService.PostAsync(newSurvey.SurveyId, myScript).Wait();

                var surveyFieldworkService = connection.GetService<INfieldSurveyFieldworkService>();
                //Get survey fieldwork status
                var surveyFieldworkStatus = surveyFieldworkService.GetStatusAsync(newSurvey.SurveyId).Result; //Should be under construction

                // Start the fieldwork for the survey
                surveyFieldworkService.StartFieldworkAsync(newSurvey.SurveyId).Wait();
                surveyFieldworkStatus = surveyFieldworkService.GetStatusAsync(newSurvey.SurveyId).Result; //Should be started

                // Example of a download data request: filtering testdata collected today
                var surveyDataService = connection.GetService<INfieldSurveyDataService>();

                var myRequest = new SurveyDownloadDataRequest
                {
                    DownloadSuccessfulLiveInterviewData = false,
                    DownloadNotSuccessfulLiveInterviewData = false,
                    DownloadOpenAnswerData = true,
                    DownloadClosedAnswerData = true,
                    DownloadSuspendedLiveInterviewData = false,
                    DownloadCapturedMedia = false,
                    DownloadParaData = false,
                    DownloadTestInterviewData = true,
                    DownloadFileName = "MyFileName",
                    StartDate = DateTime.Today.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture), // UTC time start of today
                    EndDate = DateTime.Today.AddDays(1).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture), // UTC time end of today
                    SurveyId = "SomeSurveyId"
                };

                var task = surveyDataService.PostAsync(myRequest).Result;

                // request the background tasks service
                var backgroundTasksService = connection.GetService<INfieldBackgroundTasksService>();

                // Example of performing operations on background tasks.
                var backgroundTaskQuery = backgroundTasksService.QueryAsync().Result.Where(s => s.Id == task.Id);
                var mybackgroundTask = backgroundTaskQuery.FirstOrDefault();

                if (mybackgroundTask != null)
                {
                    var status = mybackgroundTask.Status;
                }

                // Example of creating a new translation
                const string surveyName = "Language";
                const string languageName = "Dutch";
                const string translationName = "ButtonNext";
                const string translationText = "Volgende";
                // First create the survey if it does not exist
                var languageSurvey = surveysService.QueryAsync().Result
                        .SingleOrDefault(s => s.SurveyName == surveyName);
                if (languageSurvey == null)
                    languageSurvey = surveysService.AddAsync(
                        new Survey(SurveyType.Basic)
                        {
                            SurveyName = surveyName
                        }).Result;
                // Then find the language we wish to change a translation for
                var languageService = connection.GetService<INfieldLanguagesService>();
                var language = languageService.QueryAsync(languageSurvey.SurveyId)
                    .Result.SingleOrDefault(l => l.Name == languageName);
                if (language == null)
                {
                    language = languageService.AddAsync(languageSurvey.SurveyId,
                            new Language { Name = languageName }).Result;
                }
                // Now add or update a translation
                var translationsService = connection.GetService<INfieldTranslationsService>();
                var translation = translationsService.QueryAsync(languageSurvey.SurveyId,
                        language.Id).Result.SingleOrDefault(t => t.Name == translationName);
                if (translation == null)
                {
                    translationsService.AddAsync(languageSurvey.SurveyId,
                        language.Id, new Translation
                        {
                            Name = translationName,
                            Text = translationText
                        }).Wait();
                }
                else
                {
                    translation.Text = translationText;
                    translationsService.UpdateAsync(languageSurvey.SurveyId,
                        language.Id, translation).Wait();
                }

            }
        }