private void LoginEvent() { if (Connected) { Cmd.ServerInterface.Logout(Data); Connected = false; ExportBtn.Enabled = false; } BimServerLoginForm form = new BimServerLoginForm(UIDoc, Data); if (DialogResult.OK != form.ShowDialog()) { return; } Data.CopyFrom(form.Data); Cmd.ShowResult("Successfully connected to the BIMserver" /*Data.Token*/); ExportBtn.Enabled = true; // if we have a connection we can enable the action buttons (upload) Connected = true; // mark as connected }
private void SimpleButton_Click(object sender, EventArgs e) { Button btn = sender as Button; if (null == btn) { return; } if (CancelBtn == btn) { // if we are still connected disconnect now if (Connected) { Cmd.ServerInterface.Logout(Data); Connected = false; } // then close the dialog normally DialogResult = DialogResult.OK; Close(); return; } if (LoginBtn == btn) { if (Connected) { Cmd.ServerInterface.Logout(Data); Connected = false; UploadBtn.Enabled = false; } BimServerLoginForm form = new BimServerLoginForm(UIDoc, Data, false); if (DialogResult.OK != form.ShowDialog()) { return; } Data.CopyFrom(form.Data); Cmd.ShowResult(Data.Token); Data.SaveToProperties(false); // save the settings in the properties so the next call will default with them UploadBtn.Enabled = true; // if we have a connection we can enable the action buttons (upload) Connected = true; // mark as connected return; } if (SaveBtn == btn) { string name = SelectedProjectName; if (string.IsNullOrEmpty(name)) { return; } Data.ProjectName = name; Cmd.BimServerExchange.SaveBimServerLink(name); // report to the user Cmd.BimServerExchange.ShowResultInForm($"This revit document is now linked to BIMserver project '{name}'"); return; } if (SaveIfcBtn == btn) { string path = Cmd.BimServerExchange.GetCurrentProjectPath(); if (string.IsNullOrEmpty(path) || !File.Exists(path)) { return; } path = Cmd.BimServerExchange.AskForIfcSavePath(path); if (string.IsNullOrEmpty(path)) { return; } Cmd.ShowResult(path); try { Cmd.BimServerExchange.ActivateButtons(false); Cmd.BimServerExchange.ExportProjectToIFC(path); IfcEdt.Text = path; Cmd.BimServerExchange.DoUpload(); } catch (IcnException iex) { iex.Display("Exception in Export to IFC"); } catch (Exception ex) { Cmd.ShowResult($"Export to IFC failed ({ex.Message})"); Cmd.ShowResult(ex.Message); } finally { Cmd.BimServerExchange.ActivateButtons(true); } return; } if (LoadIfcBtn == btn) { string path = Cmd.BimServerExchange.AskForIfcUploadPath(); if (string.IsNullOrEmpty(path) || !File.Exists(path)) { return; } IfcEdt.Text = path; Cmd.BimServerExchange.DoUpload(); return; } if (CopyProjectNameBtn == btn) { string name = UIDoc.Document.PathName; if (string.IsNullOrEmpty(name)) { return; } string fname = Path.GetFileNameWithoutExtension(name); if (string.IsNullOrEmpty(fname)) { return; } ProjectNameEdt.Text = fname; Cmd.BimServerExchange.SelectProjectInTree(fname); return; } if (ProjectAddBtn == btn) { if (string.IsNullOrEmpty(ProjectNameEdt.Text)) { Cmd.ShowResult("The revit project does not have a name (it must be saved before running this tool)"); return; } string ifcFormat = NewProjectData.IfcFormat; if (ifcFormat.StartsWith("ifc2x3", StringComparison.InvariantCultureIgnoreCase)) { ifcFormat = "ifc2x3tc1"; } else { ifcFormat = "ifc4"; } string fullname = Cmd.BimServerExchange.AddProject(SelectedProject, ProjectNameEdt.Text, ProjectDescEdt.Text, ifcFormat); if (string.IsNullOrEmpty(fullname)) { Cmd.ShowResult("Could not add a new project"); return; } UploadBtn.Enabled = true; // reset the projects list Projects.Clear(); Projects.AddRange(Cmd.ServerInterface.GetAllProjects(Data)); return; } if (UploadBtn == btn) { Cmd.BimServerExchange.DoUpload(); return; } if (CancelUploadBtn == btn) { Cmd.BimServerExchange.ActivateButtons(true); Cmd.ServerInterface.CancelDownload(); return; } // the exact structure of the IFC download request/response is currently undetermined, // we can't get the filename if (DownloadBtn == btn) { // see if there is a project up and running try { SProject proj = SelectedProject; if (null == proj) { throw new IcnException("No project selected", 10, "Download"); } SRevision file = SelectedRevision; if (null == file) { throw new IcnException("No IFC file selected", 10, "Download"); } string scheme = proj.schema; if (string.IsNullOrEmpty(scheme) || !scheme.StartsWith("Ifc", StringComparison.InvariantCultureIgnoreCase)) { Cmd.ShowResult($"Unknown IFC scheme '{scheme ?? string.Empty}'. Attemping to download with 'Ifc2x3tc1 (Streaming)'"); scheme = "Ifc2x3tc1 (Streaming)"; } SSerializer serialiser = Cmd.ServerInterface.GetSerialiser(Data, proj, scheme); //SSerializer serialiser = Cmd.ServerInterface.GetSerialiser(Data, proj, "json"); if (null == serialiser) { throw new IcnException($"Serializer '{scheme}' not found in project '{SelectedProjectName}'", 10, "Download"); } // construct a default pathname out of the current revit project location and the BIMserver project name string path = UIDoc.Document.PathName; if (!string.IsNullOrEmpty(path)) { path = Path.GetDirectoryName(path); } path = Cmd.BimServerExchange.AskForIfcDownloadFilename(path, proj.name + ".ifc"); if (string.IsNullOrEmpty(path)) { throw new IcnException($"No path supplied to download to", 10, "Download"); } if (File.Exists(path)) { string backup = Path.ChangeExtension(path, "bak"); if (File.Exists(backup)) { File.Delete(backup); } File.Move(path, backup); } // we may have linked files. And we likely will need additional controls (e.g. for the Project to upload to) and additional data to go with this Cmd.ServerInterface.DownloadFile(Data, path, file.oid, serialiser.oid); Cmd.ShowResult($"IFC file '{path}' is copied form the BIMsrver"); } catch (IcnException iex) { iex.Display(@"Exception in Download IFC file"); Cmd.ShowResult(iex.ToString()); } catch (Exception ex) { Cmd.ShowResult($"Download IFC file failed ({ex.Message})"); Cmd.ShowResult(ex.Message); } return; } throw new IcnException($"SimpleButton '{btn.Name}' activated that has no code", 20, "BimServerExchangeForm"); }