public static ProjectReplicatorSettings ReadSettings(Document doc) { ProjectReplicatorSettings settings = new ProjectReplicatorSettings(); try { if (null == m_schema) { m_schema = CreateSchema(); } if (null != m_schema) { IList <DataStorage> savedStorages = GetDataStorage(doc, m_schema); if (savedStorages.Count > 0) { DataStorage savedStorage = savedStorages.First(); Entity entity = savedStorage.GetEntity(m_schema); settings.RevitDocumentId = entity.Get <string>(m_schema.GetField(s_RevitDocId)); settings.GoogleSheetId = entity.Get <string>(m_schema.GetField(s_GoogleSheetId)); } } } catch (Exception ex) { MessageBox.Show("Failed to read google sheet Id.\n" + ex.Message, "Read Google Sheet Id", MessageBoxButton.OK, MessageBoxImage.Warning); } return(settings); }
public static string GetGoogleSheetId(ModelInfo modelInfo) { string sheetId = ""; try { ProjectReplicatorSettings settings = DataStorageUtil.ReadSettings(modelInfo.Doc); /* * sheetId = settings.GoogleSheetId; * if (!string.IsNullOrEmpty(sheetId)) * { * FilesResource.GetRequest getRequest = service.Files.Get(sheetId); * File sheetFile = getRequest.Execute(); * if (null != sheetFile) * { * if (null == sheetFile.ExplicitlyTrashed) * { * return sheetFile.Id; * } * } * } */ sheetId = FindGoogleSheetId(modelInfo); settings.GoogleSheetId = sheetId; bool updated = DataStorageUtil.UpdateSettings(modelInfo.Doc, settings); } catch (Exception ex) { MessageBox.Show("Failed to get google sheet Id\n" + ex.Message, "Google Drive : File ID", MessageBoxButton.OK, MessageBoxImage.Warning); } return(sheetId); }
public ModelInfo(Document doc) { m_doc = doc; docTitle = doc.Title; prefixes.Add("E-CAD", "E-CAD"); prefixes.Add("E-BIM", "E-BIM"); prefixes.Add("REVIT", "REVIT"); docCentralPath = GetCentralPath(); GetProjectInfo(); GetFileLocation(); GetUserLocation(); if (string.IsNullOrEmpty(fileLocation) && userLocation == "UNKNOWN") { hokStandard = false; string regValue = RegistryUtil.GetRegistryKey("CompanyName"); if (!string.IsNullOrEmpty(regValue)) { companyName = regValue; } } else { hokStandard = true; } ProjectReplicatorSettings settings = DataStorageUtil.ReadSettings(doc); revitDocumentId = settings.RevitDocumentId; if (string.IsNullOrEmpty(revitDocumentId)) { revitDocumentId = Guid.NewGuid().ToString(); settings.RevitDocumentId = revitDocumentId; DataStorageUtil.UpdateSettings(doc, settings); } }
public static bool UpdateSettings(Document doc, ProjectReplicatorSettings settings) { bool updated = false; try { if (null == m_schema) { m_schema = CreateSchema(); } if (null != m_schema) { IList <DataStorage> storages = GetDataStorage(doc, m_schema); if (storages.Count > 0) { DataStorage savedStorage = storages.First(); using (Transaction trans = new Transaction(doc)) { trans.Start("Delete DataStorage"); try { doc.Delete(savedStorage.Id); trans.Commit(); } catch { trans.RollBack(); } } } //create new data storage using (Transaction trans = new Transaction(doc)) { trans.Start("Create Data Storage"); try { DataStorage storage = DataStorage.Create(doc); Entity entity = new Entity(schemaId); entity.Set <string>(s_RevitDocId, settings.RevitDocumentId); entity.Set <string>(s_GoogleSheetId, settings.GoogleSheetId); storage.SetEntity(entity); trans.Commit(); updated = true; } catch (Exception ex) { string message = ex.Message; trans.RollBack(); } } } } catch (Exception ex) { MessageBox.Show("Failed to update File Id.\n" + ex.Message, "Update Google Sheet Id", MessageBoxButton.OK, MessageBoxImage.Warning); } return(updated); }