public override void ExecuteCRMWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext crmWorkflowContext) { crmWorkflowContext.TracingService.Trace("CDOGS PDF converter has been started!"); //Read the Assignment Id var assignmentId = Assignment.Get <EntityReference>(context).Id; //Fetch configurations from Configuration Entity in Dynamics to prepare for HTTP API Call var configs = Helper.GetSystemConfigurations(crmWorkflowContext.OrganizationService, ConfigConstants.CONTRACT, string.Empty); string authURL = Helper.GetConfigKeyValue(configs, ConfigConstants.AUTH_URL, ConfigConstants.CONTRACT); string cdogsURL = Helper.GetConfigKeyValue(configs, ConfigConstants.CDOGS_URL, ConfigConstants.CONTRACT); string authKey = Helper.GetConfigKeyValue(configs, ConfigConstants.AUTH_KEY, ConfigConstants.CONTRACT); Uri authUri = new Uri(authURL, UriKind.Absolute); Uri cdogsUri = new Uri(cdogsURL, UriKind.Absolute); string token = null; var result = Helper.GetToken(authKey, authUri).Result; //extract the token using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(result))) { DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(NestData)); NestData bsObj2 = (NestData)deserializer.ReadObject(ms); token = bsObj2.access_token; } //start setting the parameters of the new file var documentdetails = Helper.GetContent(crmWorkflowContext.OrganizationService, assignmentId); string fileName = documentdetails.Item1; string documentBody = documentdetails.Item2; //setting the file extension var pdfFileName = Path.ChangeExtension(fileName, ".pdf"); byte[] doc = Helper.ConvertDoc(token, documentBody, cdogsUri).Result; string encodedData = Convert.ToBase64String(doc); Entity AnnotationEntityObject = new Entity("annotation"); //associate the annotation to the assignment then set filename, content etc. details EntityReference entityReference = new EntityReference("educ_assignment", assignmentId); AnnotationEntityObject.Attributes["filename"] = pdfFileName; AnnotationEntityObject.Attributes["subject"] = pdfFileName; AnnotationEntityObject.Attributes["notetext"] = pdfFileName; AnnotationEntityObject.Attributes["documentbody"] = encodedData; AnnotationEntityObject.Attributes["objectid"] = entityReference; AnnotationEntityObject.Attributes["objecttypecode"] = "educ_assignment"; AnnotationEntityObject.Attributes["mimetype"] = @"application\pdf"; crmWorkflowContext.OrganizationService.Create(AnnotationEntityObject); }
public static void CollectAndPushThings() { using (var db = new HAMSContext()) { foreach (var participant in db.Participants.Where(p => p.NestAuthCode != null)) { if (!participant.HVPersonId.HasValue || !participant.HVRecordId.HasValue) { continue; } NestData data = GetData(participant.NestAuthCode); PushDataToHV(data, participant.HVPersonId.Value, participant.HVRecordId.Value); } } }
public static NestData GetData(string accessToken) { NestData data = new NestData(); var client = new HttpClient(); string url = String.Format("https://developer-api.nest.com/?auth={0}", accessToken); string responseString = client.GetStringAsync(url).Result; JObject response = JObject.Parse(responseString); if (response["devices"] == null) { return(data); } JObject devices = (JObject)response["devices"]; if (devices["thermostats"] != null) { JObject thermostats = (JObject)devices["thermostats"]; foreach (var thermostat in thermostats) { JObject id = (JObject)thermostat.Value; data.Temperature = (double)id["ambient_temperature_c"]; data.Humidity = (double)id["humidity"]; break; // ignore other devices } } if (devices["smoke_co_alarms"] != null) { JObject smokeAlarms = (JObject)devices["smoke_co_alarms"]; foreach (var smokeAlarm in smokeAlarms) { JObject id = (JObject)smokeAlarm.Value; data.CoState = (string)id["co_alarm_state"]; data.SmokeState = (string)id["smoke_alarm_state"]; break; // ignore other devices } } return(data); }
public static void PushDataToHV(NestData data, Guid personId, Guid recordId) { PushDataToHV(data, personId, recordId, DateTime.Now); }
public static void PushDataToHV(NestData data, Guid personId, Guid recordId, DateTime time) { if (data.Temperature.HasValue) { HV.AmbientTemperature temperatureObject = new HV.AmbientTemperature { Value = data.Temperature.Value, Time = time }; HV.Methods.PostCustomThing( temperatureObject, new Microsoft.Health.ItemTypes.HealthServiceDateTime(time), personId, recordId ); } if (data.Humidity.HasValue) { HV.Humidity humidityObject = new HV.Humidity { Value = data.Humidity.Value, Time = time }; HV.Methods.PostCustomThing( humidityObject, new Microsoft.Health.ItemTypes.HealthServiceDateTime(time), personId, recordId ); } if (data.CoState != null) { HV.CoState coStateObject = new HV.CoState { Value = data.CoState, Time = time }; HV.Methods.PostCustomThing( coStateObject, new Microsoft.Health.ItemTypes.HealthServiceDateTime(time), personId, recordId ); } if (data.SmokeState != null) { HV.SmokeState smokeStateObject = new HV.SmokeState { Value = data.SmokeState, Time = time }; HV.Methods.PostCustomThing( smokeStateObject, new Microsoft.Health.ItemTypes.HealthServiceDateTime(time), personId, recordId ); } }