コード例 #1
0
 /// <summary>
 /// Updates an existing <see cref="SamplingPoint"/> with a synchronous operation.
 /// </summary>
 public void UpdateSamplingPoint(string surveyId, SamplingPoint samplingPoint)
 {
     _surveysService.SamplingPointUpdate(surveyId, samplingPoint);
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: veljac/vp-test
        static void Main(string[] args)
        {
            using (IKernel kernel = new StandardKernel())
            {
                InitializeNfield(kernel);

                //const string serverUrl = "http://api.nfieldbeta.com/v1";
                const string serverUrl = "http://api.nfieldmr.com/v1";

                // First step is to get an INfieldConnection which provides services used for data access and manipulation.
                INfieldConnection connection = NfieldConnectionFactory.Create(new Uri(serverUrl));

                // User must sign in to the Nfield server with the appropriate credentials prior to using any of the services.

                connection.SignInAsync("hendal", "veljko", "Klagant61").Wait();

                // Request the Interviewers service to manage dodajs.
                INfieldInterviewersService dodajsService = connection.GetService<INfieldInterviewersService>();
                INfieldFieldworkOfficesService foService = connection.GetService<INfieldFieldworkOfficesService>();
                INfieldSurveysService surveyService = connection.GetService<INfieldSurveysService>();

                // Create a new manager to perform the operations on the service.
                NfieldInterviewersManagement dodajsManager = new NfieldInterviewersManagement(dodajsService);
                NfieldSamplingPointManagement samplingPointsManager = new NfieldSamplingPointManagement(surveyService);
                NfieldFieldworkOfficesManagement foManager = new NfieldFieldworkOfficesManagement(foService);

                IEnumerable<Interviewer> allInterviewers = dodajsService.Query().ToList();
                var lista = allInterviewers.ToArray();

                IEnumerable<FieldworkOffice> uredi = foManager.QueryForOfficesAsync();
                var lista_ureda = uredi.ToArray();

                IEnumerable<SamplingPoint> allSamplingPoints = surveyService.SamplingPointsQuery("58e62847-57c3-4e35-ac82-5b9aba568807").ToList();
                //IEnumerable<SamplingPoint> allSamplingPoints = surveyService.SamplingPointsQuery("ce923d5d-79b6-47d2-b377-8f42174dee65").ToList();
                var allPnts = allSamplingPoints.ToArray();

                int i;

                //StreamReader spwfo = new StreamReader(@"..\..\data\sp3.txt");
                for (i=0; i<allPnts.Count(); i++)
                {
                    var tokens = spwfo.ReadLine().Split('|');
                    var mySamplingPoint = new SamplingPoint
                    {
                        SamplingPointId = tokens[0],
                        FieldworkOfficeId = tokens[1],
                        Name = tokens[2],
                        GroupId = tokens[3],
                    };
                    //samplingPointsManager.AddSamplingPoint("678726fe-5900-47a3-b1b6-7c8b2a1c7ae6", mySamplingPoint);
                    //samplingPointsManager.UpdateSamplingPoint("655059d2-0abb-4716-aaea-34549ecd6882", mySamplingPoint);
                    //Console.WriteLine(i);
                }

                SamplingPointKind spk = 0;
                var mySamplingPoint = new SamplingPoint
                {
                    SamplingPointId = "813031",
                    Description = "Survey name: EB81.3; Start address: Ulica Nikole Tesle 7, 23000, Zadar; GPS: 44.1213173,15.235273099999972",
                    Name = "Zadar - Ulica Nikole Tesle 7",
                    FieldworkOfficeId = "88a39030-c2f0-40b4-9c4e-74abe9bce433",
                    Stratum = "HR03U1",
                    GroupId = "12",
                    Kind = spk,
                };
                //samplingPointsManager.AddSamplingPoint("678726fe-5900-47a3-b1b6-7c8b2a1c7ae6", mySamplingPoint);
                //samplingPointsManager.DeleteSamplingPoint("678726fe-5900-47a3-b1b6-7c8b2a1c7ae6", mydSamplingPoint);
                //samplingPointsManager.UpdateSamplingPoint("58e62847-57c3-4e35-ac82-5b9aba568807", mySamplingPoint);
                //samplingPointsManager.UpdateSamplingPoint("655059d2-0abb-4716-aaea-34549ecd6882", mySamplingPoint);

                Console.WriteLine("Ukupno anketara: {0}", allInterviewers.Count());
                Console.WriteLine("Ukupno ureda: {0}", lista_ureda.Count());
                Console.WriteLine("Ukupno startnih točaka: {0}", allPnts.Count());

                StreamWriter datoteka = new StreamWriter(@"..\..\data\sp3.txt");
                //datoteka.WriteLine("REGIONALNI UREDI:");
                for (i = 0; i < lista_ureda.Count(); i++)
                {
                    //datoteka.WriteLine("{0}|{1}", lista_ureda[i].OfficeId, lista_ureda[i].OfficeName);
                    //Console.WriteLine("{0}|{1}", lista_ureda[i].OfficeId, lista_ureda[i].OfficeName);
                }

                //datoteka.WriteLine("STARTNE TOČKE:");
                for (i = 0; i < allSamplingPoints.Count(); i++)
                {
                    //datoteka.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|{6}", allPnts[i].SamplingPointId, allPnts[i].Description, allPnts[i].Stratum, allPnts[i].FieldworkOfficeId, allPnts[i].Name, allPnts[i].GroupId, allPnts[i].Kind);
                    Console.WriteLine("{0}|{1}|{2}|{3}|{4}", allPnts[i].SamplingPointId, allPnts[i].Name, allPnts[i].Description, allPnts[i].FieldworkOfficeId, allPnts[i].Kind);
                }

                for (i = 503; i < 882; i++)
                {
                //    IEnumerable<Interviewer> tajdodaj = dodajsService.Query().Where(dodaj => string.Equals(dodaj.UserName,"int"+i)).ToList();
                //    var talista = tajdodaj.ToArray();
                //    Interviewer mojint = talista[0];
                //    dodajsService.Remove(mojint);
                //    Console.WriteLine("{0}", "int" + i);
                }
                for (i = 5001; i < 5050; i++)
                {
                    //Console.WriteLine("{0}", "int" + i);
                    Interviewer dodaj = new Interviewer
                    {
                        UserName = "******" + i,
                        Password = "******" + i
                    };
                    //dodajsService.Add(dodaj);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// A synchronous version of <see cref="INfieldSurveysService.SamplingPointDeleteAsync"/>
 /// </summary>
 public static void SamplingPointDelete(this INfieldSurveysService surveysService, string surveyId, SamplingPoint samplingPoint)
 {
     surveysService.SamplingPointDeleteAsync(surveyId, samplingPoint).Wait();
 }
コード例 #4
0
 /// <summary>
 /// Adds a sampling point with a synchronous operation.
 /// </summary>
 /// <param name="surveyId"></param>
 /// <param name="samplingPoint"></param>
 public void AddSamplingPoint(string surveyId, SamplingPoint samplingPoint)
 {
     _surveysService.SamplingPointAdd(surveyId, samplingPoint);
 }
コード例 #5
0
 /// <summary>
 /// See <see cref="INfieldSurveysService.SamplingPointDeleteAsync"/>
 /// </summary>
 public Task SamplingPointDeleteAsync(string surveyId, SamplingPoint samplingPoint)
 {
     if (samplingPoint == null)
     {
         throw new ArgumentNullException("samplingPoint");
     }
     string uri = string.Format(@"{0}{1}/{2}/{3}", SurveysApi.AbsoluteUri, surveyId, SamplingPointsControllerName, samplingPoint.SamplingPointId);
     return Client.DeleteAsync(uri)
                 .FlattenExceptions();
 }
コード例 #6
0
        /// <summary>
        /// See <see cref="INfieldSurveysService.SamplingPointUpdateAsync"/>
        /// </summary>
        public Task<SamplingPoint> SamplingPointUpdateAsync(string surveyId, SamplingPoint samplingPoint)
        {
            if (samplingPoint == null)
            {
                throw new ArgumentNullException("samplingPoint");
            }

            var updatedSamplingPoint = new UpdateSamplingPoint
            {
                Name = samplingPoint.Name,
                Description = samplingPoint.Description,
                FieldworkOfficeId = samplingPoint.FieldworkOfficeId,
                GroupId = samplingPoint.GroupId,
                Stratum = samplingPoint.Stratum
            };

            string uri = string.Format(@"{0}{1}/{2}/{3}", SurveysApi.AbsoluteUri, surveyId, SamplingPointsControllerName, samplingPoint.SamplingPointId);

            return Client.PatchAsJsonAsync(uri, updatedSamplingPoint)
                         .ContinueWith(
                             responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                         .ContinueWith(
                             stringTask => JsonConvert.DeserializeObject<SamplingPoint>(stringTask.Result))
                         .FlattenExceptions();
        }
コード例 #7
0
 /// <summary>
 /// See <see cref="INfieldSurveysService.SamplingPointAddAsync"/>
 /// </summary>
 public Task<SamplingPoint> SamplingPointAddAsync(string surveyId, SamplingPoint samplingPoint)
 {
     string uri = string.Format(@"{0}{1}/{2}", SurveysApi.AbsoluteUri, surveyId, SamplingPointsControllerName);
     return Client.PostAsJsonAsync(uri, samplingPoint)
                  .ContinueWith(task => task.Result.Content.ReadAsStringAsync().Result)
                  .ContinueWith(task => JsonConvert.DeserializeObject<SamplingPoint>(task.Result))
                  .FlattenExceptions();
 }
コード例 #8
0
        public void TestSamplingPointUpdateAsync_SamplingPointExists_ReturnsSamplingPoint()
        {
            const string surveyId = "SurveyId";
            const string samplingPointId = "SamplingPointId";
            const string samplingPointGroupId = "MyGroupId";

            var samplingPoint = new SamplingPoint
            {
                SamplingPointId = samplingPointId,
                Name = "Updated",
                GroupId = samplingPointGroupId
            };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(
                    client =>
                        client.PatchAsJsonAsync<UpdateSamplingPoint>(
                            string.Format("{0}surveys/{1}/samplingpoints/{2}", ServiceAddress, surveyId,
                                samplingPointId), It.IsAny<UpdateSamplingPoint>()))
                .Returns(CreateTask(HttpStatusCode.OK,
                    new StringContent(JsonConvert.SerializeObject(samplingPoint))));

            var target = new NfieldSurveysService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.SamplingPointUpdateAsync(surveyId, samplingPoint).Result;

            Assert.Equal(samplingPoint.Name, actual.Name);
            Assert.Equal(samplingPoint.GroupId, actual.GroupId);
        }
コード例 #9
0
        public void TestSamplingPointRemoveAsync_ServerRemovedSamplingPoint_DoesNotThrow()
        {
            const string samplingPointId = "SamplingPointId";
            const string surveyId = "SurveyId";
            var samplingPoint = new SamplingPoint
            {
                SamplingPointId = samplingPointId
            };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.DeleteAsync(string.Format("{0}surveys/{1}/samplingpoints/{2}", ServiceAddress, surveyId,
                                samplingPointId)))
                .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldSurveysService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            Assert.DoesNotThrow(() => target.SamplingPointDeleteAsync(surveyId, samplingPoint).Wait());
        }
コード例 #10
0
        public void TestSamplingPointQueryAsync_ServerReturnsQuery_ReturnsListWithSamplingPoint()
        {
            var expectedSamplingPoint = new SamplingPoint[]
            { new SamplingPoint { SamplingPointId = "SamplingPointId" },
              new SamplingPoint { SamplingPointId = "AnotherSamplingPointId" }
            };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.GetAsync(ServiceAddress + "surveys/1/samplingpoints"))
                .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedSamplingPoint))));

            var target = new NfieldSurveysService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualSamplingPoint = target.SamplingPointsQueryAsync("1").Result;

            Assert.Equal(expectedSamplingPoint[0].SamplingPointId, actualSamplingPoint.ToArray()[0].SamplingPointId);
            Assert.Equal(expectedSamplingPoint[1].SamplingPointId, actualSamplingPoint.ToArray()[1].SamplingPointId);
            Assert.Equal(2, actualSamplingPoint.Count());
        }
コード例 #11
0
        public void TestSamplingPointAddAsync_ServerAcceptsSamplingPoint_ReturnsSamplingPoint()
        {
            const string samplingPointGroupId = "MyGroupId";
            var office = new FieldworkOffice { OfficeId = "OfficeId" };
            var survey = new Survey(SurveyType.Basic) { SurveyId = "SurveyId" };
            var samplingPoint = new SamplingPoint
            {
                SamplingPointId = "SamplingPointId",
                FieldworkOfficeId = office.OfficeId,
                GroupId = samplingPointGroupId
            };

            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(samplingPoint));
            mockedHttpClient
                .Setup(
                    client =>
                        client.PostAsJsonAsync(
                            string.Format("{0}surveys/{1}/samplingpoints", ServiceAddress, survey.SurveyId),
                            samplingPoint))
                .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldSurveysService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.SamplingPointAddAsync(survey.SurveyId, samplingPoint).Result;

            Assert.Equal(samplingPoint.SamplingPointId, actual.SamplingPointId);
            Assert.Equal(samplingPoint.FieldworkOfficeId, actual.FieldworkOfficeId);
            Assert.Equal(samplingPoint.GroupId, actual.GroupId);
        }