示例#1
0
        public void GetToken()
        {
            SpinWait.SpinUntil(() => Postman.CheckInternet());
            TokenResponse tokens = new TokenResponse();

            if (!String.IsNullOrWhiteSpace(this.refreshToken))
            {
                RestRequest request = new RestRequest(Method.POST);
                request.AddParameter("grant_type", "refresh_token", ParameterType.GetOrPost);
                request.AddParameter("refresh_token", this.refreshToken, ParameterType.GetOrPost);

                tokens = JSON.Deserialize <TokenResponse>(tokenClient.Execute(request).Content);
            }
            else
            {
                RestRequest request = new RestRequest(Method.POST);

                request.AddParameter("grant_type", "password", ParameterType.GetOrPost);
                request.AddParameter("username", "*****@*****.**", ParameterType.GetOrPost);
                request.AddParameter("password", "!Pest6547!", ParameterType.GetOrPost);

                //request.AddParameter("application/x-www-form-urlencoded", "grant_type=password&username=pestpacapi%40insightpest.com&password=!Pest6547!", ParameterType.RequestBody);
                tokens            = JSON.Deserialize <TokenResponse>(tokenClient.Execute(request).Content);
                this.refreshToken = tokens.refresh_token;
                Form1.config.Append("RefreshToken", this.refreshToken);
            }

            client.RemoveDefaultParameter("Authorization");
            client.AddDefaultHeader("Authorization", "Bearer " + tokens.access_token);
        }
示例#2
0
        public void UploadNotes()
        {
            string  logName = type + " - Uploaded";
            Postman postman = new Postman(Logger);

            string[] keys     = responses.Keys.ToArray();
            string   noteCode = type == "Retention" ? null : "FEEDBACK";
            bool     nullCode = String.IsNullOrWhiteSpace(noteCode);

            var result = Parallel.ForEach(keys, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 8
            }, key =>
                                          //foreach(string key in keys)
            {
                var temp = responses[key];
                Dictionary <string, string> info = fields.Zip(temp.Key, (k, v) => new { k, v }).ToDictionary(kv => kv.k, kv => kv.v);
                if (!Postman.locationCodes.TryGetValue(info["LocationCode"], out string id))
                {
                    //missingLocationCodes.TryWriteLineAsync(info["LocationCode"]);
                    Logger.Enqueue(
                        new LogUpdate(
                            "MissingLocationCodes",
                            info["LocationCode"]
                            )
                        );
                    this.responses.TryRemove(key, out _);
                }
                string[] answers = temp.Value;
                temp             = new KeyValuePair <string[], string[]>();

                string note = String.Format(format, questions.Zip(answers, (q, r) => String.IsNullOrWhiteSpace(r) ? "" : q + r + "\r\n").ToArray());
                RGX_FORMAT.Matches(note).Cast <Match>().ToList().ForEach(
                    m => note = note.Replace(
                        m.Value, info[m.Groups[1].Value]
                        )
                    );

                string tempCode = nullCode ? info["NoteCode"] : noteCode;
                if (
                    !postman.GetNotes(
                        id, tempCode,
                        DateTime.Parse(info["Date"])
                        ).Any(/*n => n.CreatedByUser == "ADMN" || !n.Note.StartsWith("Work Date:")*/)
                    )
                {
                    postman.UploadNote(
                        id, note,
                        String.Format(
                            dateString,
                            info["Date"]) +
                        (info.TryGetValue("Source", out string source) ?
                         "Source: " + source : "") +
                        "\r\n",
                        tempCode
                        );
                }