Exemple #1
0
        public SensorType Build(DbDataReader reader)
        {
            CompoundIdentity parentId   = null;
            Guid             parentGuid = DbReaderUtils.GetGuid(reader, 3);

            if (!Guid.Empty.Equals(parentGuid))
            {
                parentId = new CompoundIdentity(Db.DataStoreIdentity, parentGuid);
            }

            SensorType sensorType = new SensorType(new CompoundIdentity(Db.DataStoreIdentity, DbReaderUtils.GetGuid(reader, 0)), DbReaderUtils.GetString(reader, 1), DbReaderUtils.GetString(reader, 2), parentId);

            string s = DbReaderUtils.GetString(reader, 4);
            JToken t = JRaw.Parse(s);

            if (t is JArray)
            {
                JArray a = (JArray)t;
                HashSet <CompoundIdentity> ids = Db.ToIds(a);
                foreach (CompoundIdentity id in ids)
                {
                    sensorType.InstrumentFamilies.Add(id);
                }
            }

            return(sensorType);
        }
Exemple #2
0
        public static JToken GetProxy(string aInBackendUrl)
        {
            Logger.Writeline("Proxying GET call {0}", aInBackendUrl);
            try
            {
                List <KeyValuePair <string, string> > aInHeaders = new List <KeyValuePair <string, string> >();
                AuthorizationCore.Instance.GetDuploUserHeader(aInHeaders);
                string lResult = Utils.GetData(aInBackendUrl, aInHeaders);
                JToken lObj    = JRaw.Parse(lResult);
                return(lObj);
            }
            catch (WebException webEx)
            {
                if ((HttpWebResponse)webEx.Response == null)
                {
                    throw webEx;
                }

                using (HttpWebResponse response = (HttpWebResponse)webEx.Response)
                {
                    string errMsg = webEx.ToString();
                    Logger.Writeline("WebException in GET API {0} status {1}", errMsg, response.StatusCode);
                }
                throw webEx;
            }
            catch (Exception ex)
            {
                Logger.Writeline("Failed GET API with exception {0}", ex);
                throw ex;
            }
        }
Exemple #3
0
        public async Task <List <FolderDto> > FolderLoadAllFromRemote()
        {
            log.LogEverything("Communicator.FolderLoadAllFromRemote", "called");

            string rawData = await http.FolderLoadAllFromRemote().ConfigureAwait(false);

            List <FolderDto> list = new List <FolderDto>();

            if (!string.IsNullOrEmpty(rawData))
            {
                var parsedData = JRaw.Parse(rawData);

                foreach (JToken item in parsedData)
                {
                    int    microtingUUID = int.Parse(item["id"].ToString());
                    string name          = item["name"].ToString();
                    string description   = item["description"].ToString();
                    int?   parentId      = null;
                    try
                    {
                        parentId = int.Parse(item["parent_id"].ToString());
                    } catch {}


                    FolderDto folderDto = new FolderDto(null, name, description, parentId, null, null, microtingUUID);

                    list.Add(folderDto);
                }
            }

            return(list);
        }
Exemple #4
0
        public async Task <Tuple <SiteDto, UnitDto> > SiteCreate(string name)
        {
            log.LogEverything("Communicator.SiteCreate", "called");
            log.LogVariable("Communicator.SiteCreate", nameof(name), name);

            string response = await http.SiteCreate(name);

            var parsedData = JRaw.Parse(response);

            int     unitId  = int.Parse(parsedData["unit_id"].ToString());
            int     otpCode = int.Parse(parsedData["otp_code"].ToString());
            SiteDto siteDto = new SiteDto(int.Parse(parsedData["id"].ToString()), parsedData["name"].ToString(), "", "", 0, 0, unitId, 0); // WorkerUid is set to 0, because it's used in this context.
            UnitDto unitDto = new UnitDto()
            {
                UnitUId       = unitId,
                CustomerNo    = 0,
                OtpCode       = otpCode,
                SiteUId       = siteDto.SiteId,
                CreatedAt     = DateTime.Parse(parsedData["created_at"].ToString()),
                UpdatedAt     = DateTime.Parse(parsedData["updated_at"].ToString()),
                WorkflowState = Constants.WorkflowStates.Created
            };
            Tuple <SiteDto, UnitDto> result = new Tuple <SiteDto, UnitDto>(siteDto, unitDto);

            return(result);
        }
        public async Task <string> GetResponse([FromQuery] int k)
        {
            IEnumerable <People> peopleList;
            string peopleInfo = string.Empty;

            // var serStr = JsonConvert.SerializeObject(pplList);
            //var deserStr = JsonConvert.DeserializeObject<List<People>>(serStr);

            using (var httpClient = new HttpClient())
            {
                //httpClient.BaseAddress = new Uri("http://localhost:55515/");
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var response = await httpClient.GetAsync("http://localhost:55514/api/people");

                if (response.IsSuccessStatusCode)
                {
                    peopleInfo = await response.Content.ReadAsStringAsync(); //ReadAsAsync<Product>();
                }

                peopleList = JsonConvert.DeserializeObject <List <People> >(JRaw.Parse(peopleInfo).ToString());
            }

            return(peopleInfo);
        }
Exemple #6
0
        public static JToken PostProxy(HttpRequestMessage aInRequest, string aInBackendUrl)
        {
            if (aInRequest.Content == null)
            {
                return(null);
            }

            JToken lObj      = null;
            string jsonInput = string.Empty;

            jsonInput = aInRequest.Content.ReadAsStringAsync().Result;
            if (!string.IsNullOrEmpty(jsonInput))
            {
                lObj      = JRaw.Parse(jsonInput);
                jsonInput = lObj.ToString(Newtonsoft.Json.Formatting.None);
            }

            string lResult = ProxyUtils.PostData(aInRequest, aInBackendUrl, jsonInput);

            if (!string.IsNullOrEmpty(lResult))
            {
                lObj = JRaw.Parse(lResult);
                return(lObj);
            }
            else
            {
                return(null);
            }
        }
        public List <Unit_Dto> UnitLoadAllFromRemote(int customerNo)
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");
            log.LogVariable("Not Specified", nameof(customerNo), customerNo);

            var             parsedData = JRaw.Parse(http.UnitLoadAllFromRemote());
            List <Unit_Dto> lst        = new List <Unit_Dto>();

            foreach (JToken item in parsedData)
            {
                int microtingUid = int.Parse(item["id"].ToString());
                int siteUId      = int.Parse(item["site_id"].ToString());

                bool otpEnabled = bool.Parse(item["otp_enabled"].ToString());
                int  otpCode    = 0;
                if (otpEnabled)
                {
                    otpCode = int.Parse(item["otp_code"].ToString());
                }

                DateTime?createdAt = DateTime.Parse(item["created_at"].ToString());
                DateTime?updatedAt = DateTime.Parse(item["updated_at"].ToString());
                Unit_Dto temp      = new Unit_Dto(microtingUid, customerNo, otpCode, siteUId, createdAt, updatedAt);
                lst.Add(temp);
            }
            return(lst);
        }
Exemple #8
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            this.labelLoadingTime.Visible = false;
            this.labelLoadingTime.Text    = string.Empty;
            this.labelStatus.Visible      = false;
            this.labelStatus.Text         = string.Empty;
            this.requestResponseMessages.ResponseMessage = string.Empty;

            if (this.RaiseSendButton != null)
            {
                try
                {
                    SendEventArgs eventArgs = null;
                    this.InvokeEx(delegate()
                    {
                        HttpRequestMessage hrm = new HttpRequestMessage(this.method, this.textBoxUrl.Text);

                        string payload = this.requestResponseMessages.RequestPayload.Replace("$DateTime.UtcNow", DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture));

                        if (this.method != HttpMethod.Get)
                        {
                            hrm.Content = new StringContent(JRaw.Parse(payload).ToString(), Encoding.UTF8, "application/json");
                        }

                        string hdrsText = this.requestResponseMessages.RequestHeaders;
                        if (string.IsNullOrEmpty(hdrsText) == false)
                        {
                            string[] lines = hdrsText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string line in lines)
                            {
                                var parts      = line.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
                                string hdrname = parts.First().Trim();
                                hrm.Headers.TryAddWithoutValidation(parts.First().Trim(), parts.Last().Trim());
                            }
                            if (hrm.Headers.Contains("x-ms-continuation") == false && this.checkBoxNext.Visible && this.checkBoxNext.Checked && this.checkBoxNext.Tag != null)
                            {
                                hrm.Headers.TryAddWithoutValidation("x-ms-continuation", Convert.ToString(this.checkBoxNext.Tag));
                            }
                        }
                        this.checkBoxNext.Visible = false;
                        this.checkBoxNext.Checked = false;
                        this.checkBoxNext.Tag     = null;
                        eventArgs = new SendEventArgs()
                        {
                            Request = hrm
                        };
                    });

                    this.RaiseSendButton(sender, eventArgs);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.InnerMessage(), "Send HttpRequest failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    this.InvokeEx(delegate() { this.buttonSend.Enabled = true; });
                }
            }
        }
Exemple #9
0
        public async Task <OrganizationDto> OrganizationLoadAllFromRemote(string token)
        {
            log.LogEverything("Communicator.OrganizationLoadAllFromRemote", "called");
            log.LogVariable("Communicator.OrganizationLoadAllFromRemote", nameof(token), token);
            IHttp specialHttp;

            if (token == "abc1234567890abc1234567890abcdef")
            {
                specialHttp = new HttpFake();
            }
            else
            {
                specialHttp = new Http(token, "https://basic.microting.com", "https://srv05.microting.com", "000", "", "https://speechtotext.microting.com");
            }


            JToken orgResult = JRaw.Parse(await specialHttp.OrganizationLoadAllFromRemote());

            OrganizationDto organizationDto = new OrganizationDto(int.Parse(orgResult.First.First["id"].ToString()),
                                                                  orgResult.First.First["name"].ToString(),
                                                                  int.Parse(orgResult.First.First["customer_no"].ToString()),
                                                                  int.Parse(orgResult.First.First["unit_license_number"].ToString()),
                                                                  orgResult.First.First["aws_id"].ToString(),
                                                                  orgResult.First.First["aws_key"].ToString(),
                                                                  orgResult.First.First["aws_endpoint"].ToString(),
                                                                  orgResult.First.First["com_address"].ToString(),
                                                                  orgResult.First.First["com_address_basic"].ToString(),
                                                                  orgResult.First.First["com_speech_to_text"].ToString(),
                                                                  orgResult.First.First["com_address_pdf_upload"].ToString());

            return(organizationDto);
        }
Exemple #10
0
        public async Task <int> FolderCreate(string name, string description, int?parentId)
        {
            var parsedData = JRaw.Parse(await http.FolderCreate(name, description, parentId).ConfigureAwait(false));

            int microtingUUID = int.Parse(parsedData["id"].ToString());

            return(microtingUUID);
        }
Exemple #11
0
        // We need to handle json objects ourself as this isn't directly supported by JwtSecurityHandler yet
        private static JwtPayload AddJsonToPayload(JwtPayload payload, IEnumerable <Claim> jsonClaims)
        {
            var jsonTokens = jsonClaims.Select(x => new { x.Type, JsonValue = JRaw.Parse(x.Value) }).ToArray();

            var jsonObjects      = jsonTokens.Where(x => x.JsonValue.Type == JTokenType.Object).ToArray();
            var jsonObjectGroups = jsonObjects.GroupBy(x => x.Type).ToArray();

            foreach (var group in jsonObjectGroups)
            {
                if (payload.ContainsKey(group.Key))
                {
                    throw new IncompatibleClaimTypesException(string.Format("Can't add two claims where one is a JSON object and the other is not a JSON object ({0})", group.Key));
                }

                if (group.Skip(1).Any())
                {
                    // add as array
                    payload.Add(group.Key, group.Select(x => x.JsonValue).ToArray());
                }
                else
                {
                    // add just one
                    payload.Add(group.Key, group.First().JsonValue);
                }
            }

            var jsonArrays      = jsonTokens.Where(x => x.JsonValue.Type == JTokenType.Array).ToArray();
            var jsonArrayGroups = jsonArrays.GroupBy(x => x.Type).ToArray();

            foreach (var group in jsonArrayGroups)
            {
                if (payload.ContainsKey(group.Key))
                {
                    throw new IncompatibleClaimTypesException(string.Format("Can't add two claims where one is a JSON array and the other is not a JSON array ({0})", group.Key));
                }

                var newArr = new List <JToken>();
                foreach (var arrays in group)
                {
                    var arr = (JArray)arrays.JsonValue;
                    newArr.AddRange(arr);
                }

                // add just one array for the group/key/claim type
                payload.Add(group.Key, newArr.ToArray());
            }

            var unsupportedJsonTokens     = jsonTokens.Except(jsonObjects).Except(jsonArrays);
            var unsupportedJsonClaimTypes = unsupportedJsonTokens.Select(x => x.Type).Distinct();

            if (unsupportedJsonClaimTypes.Any())
            {
                var unsupportedClaimTypes = unsupportedJsonClaimTypes.Aggregate((x, y) => x + ", " + y);
                throw new UnsupportedJsonClaimTypeException($"Unsupported JSON type for claim types: {unsupportedClaimTypes}");
            }

            return(payload);
        }
Exemple #12
0
        async internal static Task GetHistoricValues(int granularity, string currency_pair)
        {
            String URL = "https://api.gdax.com/products/" + currency_pair + "/candles";

            if (granularity != 0)
            {
                URL += "?granularity=" + granularity; //https://api.gdax.com/products/ETH-EUR/candles?granularity=60
            }
            HttpClient httpClient = new HttpClient();

            //Add a user-agent header to the GET request.
            var headers = httpClient.DefaultRequestHeaders;

            //The safe way to add a header value is to use the TryParseAdd method and verify the return value is true,
            //especially if the header value is coming from user input.
            string header = "ie";

            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            Uri requestUri = new Uri(URL);

            HttpResponseMessage httpResponse = new HttpResponseMessage();
            string response = "";

            try {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();

                response = await httpResponse.Content.ReadAsStringAsync();

                var data = JRaw.Parse(response);

                int count = ((JContainer)data).Count;

                pp.Clear();
                //List<PricePoint> p = new List<PricePoint>();
                for (int i = 0; i < count; i++)
                {
                    pp.Add(PricePoint.GetPricePoint(data[i], currency_pair));
                }
            }
            catch (Exception ex) {
                response = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }
        }
Exemple #13
0
        /// <summary>
        /// Get the anomaly value of the Temporal Memory region as double
        /// </summary>
        /// <param name="networkId"></param>
        /// <param name="regionName"></param>
        /// <returns>A <see cref="Task"> object containing the anomaly double as result.</returns>
        public static async Task <double> GetTmAnomalyAsync(string networkId, string regionName)
        {
            string requestUrl = $"{baseUrl}/{networkId}/region/{regionName}/output/anomaly";
            string result     = await GetResponseStringAsync(requestUrl);

            dynamic anomalyScore = JRaw.Parse(result.Trim());
            double  score        = anomalyScore.data[0];

            return(score);
        }
Exemple #14
0
        public JToken SpeechToText(int requestId)
        {
            WebRequest request = WebRequest.Create(addressSpeechToText + "/audio/" + requestId + "?token=" + token + "&sdk_ver=" + dllVersion);

            request.Method = "GET";

            string result     = PostToServer(request);
            JToken parsedData = JRaw.Parse(result);

            return(parsedData);
        }
        public Site_Worker_Dto SiteWorkerCreate(int siteId, int workerId)
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");
            log.LogVariable("Not Specified", nameof(siteId), siteId);
            log.LogVariable("Not Specified", nameof(workerId), workerId);

            string result     = http.SiteWorkerCreate(siteId, workerId);
            var    parsedData = JRaw.Parse(result);
            int    workerUid  = int.Parse(parsedData["id"].ToString());

            return(new Site_Worker_Dto(workerUid, siteId, workerId));
        }
Exemple #16
0
        /// <summary>
        /// Converts the response string into an SDR
        /// </summary>
        /// <param name="responseString"></param>
        /// <returns>A SDR object</returns>
        private static Sdr CreateSdrFromResponse(string responseString)
        {
            dynamic parsedJson    = JRaw.Parse(responseString.Trim());
            string  sdrTypeString = ((string)parsedJson.type).Replace("SDR", string.Empty).Trim('(', ')');

            int[] dimensions = sdrTypeString.Split(',').Select(Int32.Parse).ToArray();
            int[] sparse     = parsedJson.data.ToObject <int[]>();

            SdrLite.Sdr sdr = new SdrLite.Sdr(dimensions);
            sdr.SetSparse(sparse.ToList());
            return(sdr);
        }
Exemple #17
0
        public async Task <SiteWorkerDto> SiteWorkerCreate(int siteId, int workerId)
        {
            log.LogEverything("Communicator.SiteWorkerCreate", "called");
            log.LogVariable("Communicator.SiteWorkerCreate", nameof(siteId), siteId);
            log.LogVariable("Communicator.SiteWorkerCreate", nameof(workerId), workerId);

            string result = await http.SiteWorkerCreate(siteId, workerId);

            var parsedData = JRaw.Parse(result);
            int workerUid  = int.Parse(parsedData["id"].ToString());

            return(new SiteWorkerDto(workerUid, siteId, workerId));
        }
Exemple #18
0
        public async Task <bool> FolderDelete(int id)
        {
            string response = await http.FolderDelete(id).ConfigureAwait(false);

            var parsedData = JRaw.Parse(response);

            if (parsedData["workflow_state"].ToString() == Constants.WorkflowStates.Removed)
            {
                return(true);
            }

            return(false);
        }
Exemple #19
0
        private static async Task <Uri> GetBingImageUrl(string name)
        {
            Uri url = new Uri("http://tempuri.org");

            try
            {
                //https://api.cognitive.microsoft.com/bing/v7.0/images/search
                //Ocp - Apim - Subscription - Key
                //My key that will go away after the hackathon
                //

                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-key", "a54d8d76dd5347f68966c7d7e5d6033b");


                HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, new Uri(string.Format("https://api.cognitive.microsoft.com/bing/v7.0/images/search?q={0}&amp;mkt=en-us&amp;setLang=en ", name)));

                var response = await client.SendAsync(msg);



                var content = await response.Content.ReadAsStringAsync();

                //Current JSON doesn't quite work right for newtonsoft library
                // so remove first " and last " from json stream
                var jsonContent = content.Replace("\\", string.Empty);
                var jToken      = JRaw.Parse(jsonContent);
                var token       = jToken.SelectToken("value");

                //which is an array of urls...
                JArray arr = JArray.Parse(token.ToString());
                foreach (JObject obj in arr.Children <JObject>())
                {
                    //just get the first child
                    JsonSerializerSettings settings = new JsonSerializerSettings();
                    settings.NullValueHandling     = NullValueHandling.Ignore;
                    settings.MissingMemberHandling = MissingMemberHandling.Ignore;

                    var urlToken = obj.SelectToken("contentUrl");
                    url = new Uri(urlToken.ToString().Replace("\\", string.Empty));
                    break;
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message);
            }
            return(url);
        }
        public Worker_Dto WorkerCreate(string firstName, string lastName, string email)
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");
            log.LogVariable("Not Specified", nameof(firstName), firstName);
            log.LogVariable("Not Specified", nameof(lastName), lastName);
            log.LogVariable("Not Specified", nameof(email), email);

            string   result     = http.WorkerCreate(firstName, lastName, email);
            var      parsedData = JRaw.Parse(result);
            int      workerUid  = int.Parse(parsedData["id"].ToString());
            DateTime?createdAt  = DateTime.Parse(parsedData["created_at"].ToString());
            DateTime?updatedAt  = DateTime.Parse(parsedData["updated_at"].ToString());

            return(new Worker_Dto(workerUid, firstName, lastName, email, createdAt, updatedAt));
        }
        public Tuple <Site_Dto, Unit_Dto> SiteCreate(string name)
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");
            log.LogVariable("Not Specified", nameof(name), name);

            string response   = http.SiteCreate(name);
            var    parsedData = JRaw.Parse(response);

            int      unitId  = int.Parse(parsedData["unit_id"].ToString());
            int      otpCode = int.Parse(parsedData["otp_code"].ToString());
            Site_Dto siteDto = new Site_Dto(int.Parse(parsedData["id"].ToString()), parsedData["name"].ToString(), "", "", 0, 0, unitId, 0); // WorkerUid is set to 0, because it's used in this context.
            Unit_Dto unitDto = new Unit_Dto(unitId, 0, otpCode, siteDto.SiteId, DateTime.Parse(parsedData["created_at"].ToString()), DateTime.Parse(parsedData["updated_at"].ToString()));
            Tuple <Site_Dto, Unit_Dto> result = new Tuple <Site_Dto, Unit_Dto>(siteDto, unitDto);

            return(result);
        }
Exemple #22
0
        public async Task <WorkerDto> WorkerCreate(string firstName, string lastName, string email)
        {
            log.LogEverything("Communicator.WorkerCreate", "called");
            log.LogVariable("Communicator.WorkerCreate", nameof(firstName), firstName);
            log.LogVariable("Communicator.WorkerCreate", nameof(lastName), lastName);
            log.LogVariable("Communicator.WorkerCreate", nameof(email), email);

            string result = await http.WorkerCreate(firstName, lastName, email);

            var      parsedData = JRaw.Parse(result);
            int      workerUid  = int.Parse(parsedData["id"].ToString());
            DateTime?createdAt  = DateTime.Parse(parsedData["created_at"].ToString());
            DateTime?updatedAt  = DateTime.Parse(parsedData["updated_at"].ToString());

            return(new WorkerDto(workerUid, firstName, lastName, email, createdAt, updatedAt));
        }
        public List <Site_Worker_Dto> SiteWorkerLoadAllFromRemote()
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");

            var parsedData             = JRaw.Parse(http.SiteWorkerLoadAllFromRemote());
            List <Site_Worker_Dto> lst = new List <Site_Worker_Dto>();

            foreach (JToken item in parsedData)
            {
                int             microtingUid = int.Parse(item["id"].ToString());
                int             siteUId      = int.Parse(item["site_id"].ToString());
                int             workerUId    = int.Parse(item["user_id"].ToString());
                Site_Worker_Dto temp         = new Site_Worker_Dto(microtingUid, siteUId, workerUId);
                lst.Add(temp);
            }
            return(lst);
        }
        public bool SiteWorkerDelete(int workerId)
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");
            log.LogVariable("Not Specified", nameof(workerId), workerId);

            string response   = http.SiteWorkerDelete(workerId);
            var    parsedData = JRaw.Parse(response);

            if (parsedData["workflow_state"].ToString() == "removed")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool SiteWorkerDelete(int workerId)
        {
            log.LogEverything(t.GetMethodName("Comminicator"), "called");
            log.LogVariable(t.GetMethodName("Comminicator"), nameof(workerId), workerId);

            string response   = http.SiteWorkerDelete(workerId);
            var    parsedData = JRaw.Parse(response);

            if (parsedData["workflow_state"].ToString() == Constants.WorkflowStates.Removed)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #26
0
        public async Task <List <SiteWorkerDto> > SiteWorkerLoadAllFromRemote()
        {
            log.LogEverything("Communicator.SiteWorkerLoadAllFromRemote", "called");

            var parsedData           = JRaw.Parse(await http.SiteWorkerLoadAllFromRemote());
            List <SiteWorkerDto> lst = new List <SiteWorkerDto>();

            foreach (JToken item in parsedData)
            {
                int           microtingUid = int.Parse(item["id"].ToString());
                int           siteUId      = int.Parse(item["site_id"].ToString());
                int           workerUId    = int.Parse(item["user_id"].ToString());
                SiteWorkerDto temp         = new SiteWorkerDto(microtingUid, siteUId, workerUId);
                lst.Add(temp);
            }
            return(lst);
        }
Exemple #27
0
 public int SpeechToText(string pathToAudioFile, string language)
 {
     try
     {
         using (WebClient client = new WebClient())
         {
             string url           = addressSpeechToText + "/audio/?token=" + token + "&sdk_ver=" + dllVersion + "&lang=" + language;
             byte[] responseArray = client.UploadFile(url, pathToAudioFile);
             string result        = Encoding.UTF8.GetString(responseArray);
             var    parsedData    = JRaw.Parse(result);
             return(int.Parse(parsedData["id"].ToString()));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Unable to upload the file");
     }
 }
        public List <SiteName_Dto> SiteLoadAllFromRemote()
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");

            var parsedData          = JRaw.Parse(http.SiteLoadAllFromRemote());
            List <SiteName_Dto> lst = new List <SiteName_Dto>();

            foreach (JToken item in parsedData)
            {
                string       name         = item["name"].ToString();
                int          microtingUid = int.Parse(item["id"].ToString());
                DateTime?    createdAt    = DateTime.Parse(item["created_at"].ToString());
                DateTime?    updatedAt    = DateTime.Parse(item["updated_at"].ToString());
                SiteName_Dto temp         = new SiteName_Dto(microtingUid, name, createdAt, updatedAt);
                lst.Add(temp);
            }
            return(lst);
        }
Exemple #29
0
        public async Task <List <SiteNameDto> > SiteLoadAllFromRemote()
        {
            log.LogEverything("Communicator.SiteLoadAllFromRemote", "called");

            var parsedData         = JRaw.Parse(await http.SiteLoadAllFromRemote());
            List <SiteNameDto> lst = new List <SiteNameDto>();

            foreach (JToken item in parsedData)
            {
                string      name         = item["name"].ToString();
                int         microtingUid = int.Parse(item["id"].ToString());
                DateTime?   createdAt    = DateTime.Parse(item["created_at"].ToString());
                DateTime?   updatedAt    = DateTime.Parse(item["updated_at"].ToString());
                SiteNameDto temp         = new SiteNameDto(microtingUid, name, createdAt, updatedAt);
                lst.Add(temp);
            }
            return(lst);
        }
Exemple #30
0
        public async Task <bool> UnitDelete(int unitId)
        {
            log.LogEverything("Communicator.UnitDelete", "called");
            log.LogVariable("Communicator.UnitDelete", nameof(unitId), unitId);

            string response = await http.UnitDelete(unitId);

            var parsedData = JRaw.Parse(response);

            if (parsedData["workflow_state"].ToString() == Constants.WorkflowStates.Removed)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }