/// <summary> /// The SendRevitElementToCloud /// </summary> public void SendRevitElementToCloud() { RevitElementRoute route = new RevitElementRoute(ProjectProvider.Instance.CurrentProject._id); if (ProjectProvider.Instance.CurrentProject._id == null) { MessageBox.Show("Select a project please"); return; } RestRequest req = new RestRequest(route.url(), Method.POST); req.AddHeader("Content-Type", "application/json"); req.AddHeader("Authorization", "Bearer " + AuthProvider.Instance.token.token); string body = JsonConvert.SerializeObject(ModelProvider.Instance.DicRevitElements); req.RequestFormat = DataFormat.Json; req.AddJsonBody(body); IRestResponse res = Route.Client.Execute(req); }
/// <summary> /// The Refresh /// </summary> /// <param name="app">The app<see cref="UIApplication"/></param> private void Refresh(UIApplication app) { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; Selection selection = uidoc.Selection; ICollection <ElementId> selectedIds = uidoc.Selection.GetElementIds(); switch (selectedIds.Count) { case 0: MessageBox.Show("Please select an element"); break; case 1: RevitElementRoute route = new RevitElementRoute(ProjectProvider.Instance.CurrentProject._id); Element e = doc.GetElement(selectedIds.First()); if ((null != e.Category && 0 < e.Parameters.Size && (e.Category.HasMaterialQuantities)) == false) { MessageBox.Show("This element is NOT SUPPORTED by us. Sorry!"); return; } string guid = e.UniqueId; RestRequest req = new RestRequest(route.historyUrl(guid), Method.GET); req.AddHeader("Content-Type", "application/json"); req.AddHeader("Authorization", "Bearer " + AuthProvider.Instance.token.token); IRestResponse <Models.History> res = Route.Client.Execute <Models.History>(req); if (res.StatusCode == System.Net.HttpStatusCode.NotFound) { MessageBox.Show("Element is not synchronized on cloud yet."); return; } if (res.StatusCode == System.Net.HttpStatusCode.OK) { string format = "0000-12-31T23:50:39.000Z"; var dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = format, Culture = CultureInfo.InvariantCulture }; HistoryResParent revitElements = JsonConvert.DeserializeObject <HistoryResParent>(res.Content, dateTimeConverter); HistoryModel.Instance.HistoriesByTypeChange.Clear(); foreach (HistoryByTypeChange item in GetHistoryByType(revitElements.data.history)) { HistoryModel.Instance.HistoriesByTypeChange.Add(item); } } else { MessageBox.Show("Some error on getting element history."); } break; default: MessageBox.Show("Please select ONLY an element"); break; } }