/// <summary> /// PUT JSON document data into /// the specified mongoDB collection. /// </summary> public static string Put( string collection_name_and_id, DoorData doorData ) { var client = new RestClient( RestApiBaseUrl ); var request = new RestRequest( _api_version + "/" + collection_name_and_id, Method.PUT ); request.RequestFormat = DataFormat.Json; request.AddBody( doorData ); // uses JsonSerializer IRestResponse response = client.Execute( request ); var content = response.Content; // raw content as string return content; }
public static Result ExportOneByOne( FilteredElementCollector doors, Guid paramGuid, string project_id, uint timestamp, ref string message ) { #region Project #if NEED_PROJECT_DOCUMENT // Post project data. string project_id = string.Empty; object obj; Hashtable d; // curl -i -X POST -H 'Content-Type: application/json' -d '{ // "projectinfo_uid": "8764c510-57b7-44c3-bddf-266d86c26380-0000c160", // "versionguid": "f498e8b1-7311-4409-a669-2fd290356bb4", // "numberofsaves": 271, // "title": "rac_basic_sample_project.rvt", // "centralserverpath": "", // "path": "C:/Program Files/Autodesk/Revit 2016/Samples/rac_basic_sample_project.rvt", // "computername": "JEREMYTAMMIB1D2" }' // http://localhost:3001/api/v1/projects string json = GetProjectDataJson( doc ); Debug.Print( json ); string jsonResponse = string.Empty; try { jsonResponse = Util.QueryOrUpsert( "projects/jid/" + jid, string.Empty, "GET" ); } catch( System.Net.WebException ex ) { } if( 0 == jsonResponse.Length ) { jsonResponse = Util.QueryOrUpsert( "projects", json, "POST" ); } else { jsonResponse = Util.QueryOrUpsert( "projects/" + project_id, json, "PUT" ); } Debug.Print( jsonResponse ); obj = JsonParser.JsonDecode( jsonResponse ); if( null != obj ) { d = obj as Hashtable; project_id = d["_id"] as string; } //if( null != project_id ) //{ // jsonResponse = Util.QueryOrUpsert( // "projects/" + project_id, json, "PUT" ); // Debug.Assert( // jsonResponse.Equals( "Accepted" ), // "expected successful db update response" ); // if( !jsonResponse.Equals( "Accepted" ) ) // { // project_id = null; // } //} //else //{ // jsonResponse = Util.QueryOrUpsert( // "projects", json, "POST" ); // Debug.Print( jsonResponse ); // obj = JsonParser.JsonDecode( jsonResponse ); // if( null != obj ) // { // d = obj as Hashtable; // project_id = d["_id"] as string; // } //} if( !string.IsNullOrEmpty( project_id ) ) { #endif // NEED_PROJECT_DOCUMENT #endregion // Project // Loop through the selected doors and export // their shared parameter value one by one. DoorData doorData; HttpStatusCode sc; string jsonResponse, errorMessage; Result rc = Result.Succeeded; //collector.Select<Element, string>( // d => Util.Put( "doors/" + d.UniqueId, // new DoorData( d, project_id, paramGuid ) ) ); foreach( Element e in doors ) { //Debug.Print( e.Id.IntegerValue.ToString() ); doorData = new DoorData( e, project_id, paramGuid, timestamp ); sc = Util.Put( out jsonResponse, out errorMessage, "doors/" + e.UniqueId, doorData ); if( 0 == (int) sc ) { message = errorMessage; rc = Result.Failed; break; } //Util.Log( jsonResponse ); } return rc; }
public static Result ExportOneByOne( FilteredElementCollector doors, Guid paramGuid, string project_id, uint timestamp, ref string message) { #region Project #if NEED_PROJECT_DOCUMENT // Post project data. string project_id = string.Empty; object obj; Hashtable d; // curl -i -X POST -H 'Content-Type: application/json' -d '{ // "projectinfo_uid": "8764c510-57b7-44c3-bddf-266d86c26380-0000c160", // "versionguid": "f498e8b1-7311-4409-a669-2fd290356bb4", // "numberofsaves": 271, // "title": "rac_basic_sample_project.rvt", // "centralserverpath": "", // "path": "C:/Program Files/Autodesk/Revit 2016/Samples/rac_basic_sample_project.rvt", // "computername": "JEREMYTAMMIB1D2" }' // http://localhost:3001/api/v1/projects string json = GetProjectDataJson(doc); Debug.Print(json); string jsonResponse = string.Empty; try { jsonResponse = Util.QueryOrUpsert( "projects/jid/" + jid, string.Empty, "GET"); } catch (System.Net.WebException ex) { } if (0 == jsonResponse.Length) { jsonResponse = Util.QueryOrUpsert( "projects", json, "POST"); } else { jsonResponse = Util.QueryOrUpsert( "projects/" + project_id, json, "PUT"); } Debug.Print(jsonResponse); obj = JsonParser.JsonDecode(jsonResponse); if (null != obj) { d = obj as Hashtable; project_id = d["_id"] as string; } //if( null != project_id ) //{ // jsonResponse = Util.QueryOrUpsert( // "projects/" + project_id, json, "PUT" ); // Debug.Assert( // jsonResponse.Equals( "Accepted" ), // "expected successful db update response" ); // if( !jsonResponse.Equals( "Accepted" ) ) // { // project_id = null; // } //} //else //{ // jsonResponse = Util.QueryOrUpsert( // "projects", json, "POST" ); // Debug.Print( jsonResponse ); // obj = JsonParser.JsonDecode( jsonResponse ); // if( null != obj ) // { // d = obj as Hashtable; // project_id = d["_id"] as string; // } //} if (!string.IsNullOrEmpty(project_id)) { #endif // NEED_PROJECT_DOCUMENT #endregion // Project // Loop through the selected doors and export // their shared parameter value one by one. DoorData doorData; HttpStatusCode sc; string jsonResponse, errorMessage; Result rc = Result.Succeeded; //collector.Select<Element, string>( // d => Util.Put( "doors/" + d.UniqueId, // new DoorData( d, project_id, paramGuid ) ) ); foreach (Element e in doors) { //Debug.Print( e.Id.IntegerValue.ToString() ); doorData = new DoorData(e, project_id, paramGuid, timestamp); sc = Util.Put(out jsonResponse, out errorMessage, "doors/" + e.UniqueId, doorData); if (0 == (int)sc) { message = errorMessage; rc = Result.Failed; break; } //Util.Log( jsonResponse ); } return(rc); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) { UIApplication uiapp = commandData.Application; Application app = uiapp.Application; Document doc = uiapp.ActiveUIDocument.Document; // Get shared parameter GUID. Guid paramGuid; if( !Util.GetSharedParamGuid( app, out paramGuid ) ) { message = "Shared parameter GUID not found."; return Result.Failed; } // Determine custom project identifier. string project_id = Util.GetProjectIdentifier( doc ); #region Project #if NEED_PROJECT_DOCUMENT // Post project data. string project_id = string.Empty; object obj; Hashtable d; // curl -i -X POST -H 'Content-Type: application/json' -d '{ // "projectinfo_uid": "8764c510-57b7-44c3-bddf-266d86c26380-0000c160", // "versionguid": "f498e8b1-7311-4409-a669-2fd290356bb4", // "numberofsaves": 271, // "title": "rac_basic_sample_project.rvt", // "centralserverpath": "", // "path": "C:/Program Files/Autodesk/Revit 2016/Samples/rac_basic_sample_project.rvt", // "computername": "JEREMYTAMMIB1D2" }' // http://localhost:3001/api/v1/projects string json = GetProjectDataJson( doc ); Debug.Print( json ); string jsonResponse = string.Empty; try { jsonResponse = Util.QueryOrUpsert( "projects/jid/" + jid, string.Empty, "GET" ); } catch( System.Net.WebException ex ) { } if( 0 == jsonResponse.Length ) { jsonResponse = Util.QueryOrUpsert( "projects", json, "POST" ); } else { jsonResponse = Util.QueryOrUpsert( "projects/" + project_id, json, "PUT" ); } Debug.Print( jsonResponse ); obj = JsonParser.JsonDecode( jsonResponse ); if( null != obj ) { d = obj as Hashtable; project_id = d["_id"] as string; } //if( null != project_id ) //{ // jsonResponse = Util.QueryOrUpsert( // "projects/" + project_id, json, "PUT" ); // Debug.Assert( // jsonResponse.Equals( "Accepted" ), // "expected successful db update response" ); // if( !jsonResponse.Equals( "Accepted" ) ) // { // project_id = null; // } //} //else //{ // jsonResponse = Util.QueryOrUpsert( // "projects", json, "POST" ); // Debug.Print( jsonResponse ); // obj = JsonParser.JsonDecode( jsonResponse ); // if( null != obj ) // { // d = obj as Hashtable; // project_id = d["_id"] as string; // } //} if( !string.IsNullOrEmpty( project_id ) ) { #endif // NEED_PROJECT_DOCUMENT #endregion // Project // Loop through all elements of the given target // category and export the shared parameter value // specified by paramGuid for each. FilteredElementCollector collector = Util.GetTargetInstances( doc, Cmd_1_CreateAndBindSharedParameter.Target ); int n = collector.Count<Element>(); DoorData doorData; string jsonResponse; foreach( Element e in collector ) { Debug.Print( e.Id.IntegerValue.ToString() ); doorData = new DoorData( e, project_id, paramGuid ); jsonResponse = Util.Put( "doors/" + e.UniqueId, doorData ); Debug.Print( jsonResponse ); } return Result.Succeeded; } }