private SP.ListItemCollection GetItemsFromSharepointList(string listName, string viewName) { try { // get the list from context SP.List readList = SharepointMethods.GetListFromWeb( _context, listName); // get view from list by view name SP.View readView = SharepointMethods.GetViewFromList( _context, readList, viewName); // get items from list by view SP.ListItemCollection readListItems = SharepointMethods.GetViewItemsFromList( _context, readList, readView); return(readListItems); } catch (Exception e) { MessageBox.Show(e.ToString()); return(null); } }
private void loginButton_Click(object sender, EventArgs e) { // grab the username from the text box string username = this.textBox1.Text; // grab the password from the text box and convert it to a secure string SecureString password = new NetworkCredential("", this.textBox2.Text).SecurePassword; // validate the format of the credentials _isValidated = SharepointMethods.ValidateCredentials(_context, username, password); if (_isValidated == false) { MessageBox.Show("Error, invalid username or password format. Please try again."); } else { // test the validated credentials _isLoggedIn = SharepointMethods.TestCredentials(_context, username, password); if (_isLoggedIn == false) { MessageBox.Show("Error, username or password is incorrect. Please try again."); } else { // store the validated and tested credentials in the cache SharepointConstants.Cache.username = this.textBox1.Text; SharepointConstants.Cache.password = new NetworkCredential("", this.textBox2.Text).SecurePassword; MessageBox.Show("Successfully logged in."); Close(); } } }
private SP.ListItem LogTransaction(SP.ListItem project, string transactionTypeId) { Dictionary <string, string> transactionInfo = ParseTransactionInfo(project, "19"); SP.List transactionsList = SharepointMethods.GetListFromWeb( _context, SharepointConstants.Links.transactionsList); SP.ListItem transaction = SharepointMethods.AddItemToList( _context, transactionsList, transactionInfo ); return(transaction); }
private SP.ListItem LogProject(SP.ListItem selectedProject, SP.ListItem transaction) { // parse the project info Dictionary <string, string> projectInfo = ParseProjectInfo(selectedProject, transaction); // get write list SP.List linkedProjectsList = SharepointMethods.GetListFromWeb( _context, SharepointConstants.Links.linkedProjectList); // write the project info to sharepoint SP.ListItem loggedProject = SharepointMethods.AddItemToList( _context, linkedProjectsList, projectInfo ); return(loggedProject); }
private SP.ListItem GetLinkedProject() { // get all linked projects SP.ListItemCollection linkedProjects = GetItemsFromSharepointList( SharepointConstants.Links.linkedProjectList, SharepointConstants.Views.allItems ); if (linkedProjects.Count == 0) { //return null; } // see if the current project is linked SP.ListItem linkedProject = SharepointMethods.GetItem( linkedProjects, SharepointConstants.ColumnHeaders.Title, _doc.Title ); return(linkedProject); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { // intialize context variables to pass on to user interface form Document doc = commandData.Application.ActiveUIDocument.Document; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; SP.ClientContext context = SharepointMethods.GetContext(SharepointConstants.Links.siteUrl); // inject the context variables via arguments Forms.UDPInterface wf = new Forms.UDPInterface(doc, app, context); wf.ShowDialog(); return(Result.Succeeded); } catch (Exception e) { TaskDialog.Show("Error", e.ToString()); return(Result.Failed); } }
private List <Dictionary <string, string> > HandleUpload() { using (ProgressDialog pd = new ProgressDialog("Upload", 5)) { pd.Show(); // collect rooms from the model, return false if there are none pd.StartTask("Collecting placed rooms"); IList <SpatialElement> placedRooms = RevitMethods.GetPlacedRooms(_doc); if (placedRooms == null) { pd.Close(); return(null); } pd.Increment(); // check if the custom room parameters exist pd.StartTask("Checking room parameters"); bool roomParametersCheck = RevitMethods.CheckParametersExist( placedRooms, SharepointConstants.Dictionaries.newRevitRoomParameters); if (roomParametersCheck == false) { pd.Close(); return(null); } pd.Increment(); // collect the room info for writing to sharepoint pd.StartTask("Parsing room data"); List <Dictionary <string, string> > placedRoomsData = RevitMethods.ParseRoomData( placedRooms, SharepointConstants.Dictionaries.newRevitRoomParameters); if (placedRoomsData == null) { pd.Close(); return(null); } pd.Increment(); // retrieve write list from sharepoint pd.StartTask("Connecting to Sharepoint"); SP.List SPWriteList = SharepointMethods.GetListFromWeb( _context, SharepointConstants.Links.spWriteList); if (SPWriteList == null) { pd.Close(); return(null); } pd.Increment(); // write the room data to the write list pd.StartTask("Writing data to Sharepoint"); bool roomsUploaded = SharepointMethods.AddItemsToList( _context, SPWriteList, placedRoomsData); if (roomsUploaded == false) { pd.Close(); return(null); } pd.Increment(); // if we get to the end then return the written data return(placedRoomsData); } }
private List <Room> HandleSync() { using (ProgressDialog pd = new ProgressDialog("Sync", 6)) { pd.Show(); List <Room> syncedRooms = new List <Room>(); // get current revit rooms pd.StartTask("Collecting Revit rooms"); IList <Element> collectedRooms = RevitMethods.GetElements( _doc, BuiltInCategory.OST_Rooms); if (collectedRooms == null) { pd.Close(); return(null); } pd.Increment(); // get items from SP list pd.StartTask("Fetching Sharepoint data"); SP.ListItemCollection allSpRooms = GetItemsFromSharepointList( SharepointConstants.Links.spReadList, SharepointConstants.Views.allItems); if (allSpRooms == null) { pd.Close(); return(null); } pd.Increment(); // filter by current project pd.StartTask("Retrieving rooms from current project"); IEnumerable <SP.ListItem> spRooms = SharepointMethods.GetItems( allSpRooms, SharepointConstants.ColumnHeaders.project_id, _project[SharepointConstants.ColumnHeaders.ID].ToString()); if (spRooms == null) { pd.Close(); return(null); } pd.Increment(); // get the latest phase pd.StartTask("Getting latest Revit phase"); Phase latestPhase = RevitMethods.GetLatestPhase(_doc); if (latestPhase == null) { pd.Close(); return(null); } pd.Increment(); // check if room parameters exist pd.StartTask("Checking Revit parameters"); bool roomParamsExist = RevitMethods.CheckParametersExist( collectedRooms, SharepointConstants.Dictionaries.newRevitRoomParameters); pd.Increment(); // if they don't exist if (!roomParamsExist) { // make new parameters Dictionary <string, ExternalDefinition> roomParametersCreated = RevitMethods.CreateSharedParameters( _doc, _app, SharepointConstants.Dictionaries.newRevitRoomParameters, BuiltInCategory.OST_Rooms, BuiltInParameterGroup.PG_REFERENCE); if (roomParametersCreated == null) { pd.Close(); return(null); } // generate the rooms pd.StartTask("Creating revit rooms"); syncedRooms = RevitMethods.CreateRooms( _doc, latestPhase, spRooms, roomParametersCreated); pd.Increment(); } else { // sync the existing rooms pd.StartTask("Syncing revit rooms"); syncedRooms = RevitMethods.UpdateRooms( _doc, latestPhase, collectedRooms, spRooms, SharepointConstants.Dictionaries.newRevitRoomParameters); pd.Increment(); } return(syncedRooms); } }
private void HandleState() { // check user credentials CheckLogin(); if (_isLoggedIn) { using (ProgressDialog pd = new ProgressDialog("Loading data.", 4)) { pd.Show(); // get current user from sharepoint pd.StartTask("Looking up user."); SP.ListItem user = GetCurrentUser(); if (user == null) { // disable the form if the user doesn't exist SharepointConstants.Cache.user = null; DisableForm(); pd.Close(); return; } SharepointConstants.Cache.user = user; // CheckUser(); pd.Increment(); // get all available projects from sharepoint pd.StartTask("Fetching sharepoint projects."); SP.ListItemCollection projects = GetProjects(); if (projects == null) { SharepointConstants.Cache.projects = null; pd.Close(); return; } SharepointConstants.Cache.projects = projects; pd.Increment(); // check if the project is linked pd.StartTask("Checking Revit model link status."); SP.ListItem linkedProject = GetLinkedProject(); if (linkedProject == null) { // display the available projects in the dropdown box SharepointConstants.Cache.project = null; DisplayProjects(projects); ReloadForm(); pd.Close(); return; } pd.Increment(); // get the sharepoint project associated with the linked project pd.StartTask("Establishing Revit model to Sharepoint link."); SP.ListItem spProject = SharepointMethods.GetItem( projects, SharepointConstants.ColumnHeaders.ID, linkedProject[SharepointConstants.ColumnHeaders.project_id].ToString() ); SharepointConstants.Cache.project = spProject; pd.Increment(); } } // refresh the form ReloadForm(); }