public void NestedInNestedDictionary() { var db = DatabaseGenerator.Get(); Product product = new Product() { Category = new Category { Seller = new Seller { ProductSells = new Dictionary <string, int>() { { "Pen", 1 } } } } }; var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Category.Seller.ProductSells.Add("Pencil", 3); var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Category':{'Seller':{'ProductSells':{'Pencil':3}}}}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
/// <summary> /// Called by ProjectDocumentTracker when a scc-capable project is opened /// </summary> /// <param name="project">The loaded project</param> /// <param name="added">The project was added after opening</param> protected override void OnProjectOpened(SccProjectData data, bool added) { if (data.IsStoredInSolution) { if (IsSolutionManaged) { // We let them follow the solution settings (See OnSolutionOpen() for the not added case if (added && data.IsSolutionInfrastructure) { data.SetManaged(true); } } // Solution folders are projects without Scc state data.NotifyGlyphsChanged(); } data.OnOpened(); _syncMap = true; // Don't take the focus from naming the folder. The rename will perform the .Load() // and dirty check if (added && data.IsSolutionInfrastructure) { return; } if (added && !string.IsNullOrEmpty(SolutionFilename)) { DocumentTracker.CheckDirty(SolutionFilename); } RegisterForSccCleanup(); }
public void NestedInNestedOneProperty() { var db = DatabaseGenerator.Get(); Product product = new Product() { Category = new Category { Seller = new Seller { TotalSells = 5000 } } }; var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Category.Seller.TotalSells = 11000; var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Category':{'Seller':{'TotalSells':11000}}}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
/// <summary> /// Schedules a dirty check for the specified document /// </summary> /// <param name="item">The item.</param> public void ScheduleDirtyCheck(SvnItem item) { if (item == null) { throw new ArgumentNullException("path"); } if (!item.IsVersioned || item.IsModified || DocumentTracker.NoDirtyCheck(item)) { return; // Not needed } lock (_lock) { if (_dirtyCheck == null) { _dirtyCheck = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); } if (!_dirtyCheck.Contains(item.FullPath)) { _dirtyCheck.Add(item.FullPath); } PostIdle(); } }
/// <summary> /// Move 5 percent of the (no less than 1) documents from child to parentFolder level (Shows Re-Filing Documents) /// </summary> /// <param name="tracker"></param> protected void MoveChildFolderDocumentsToParent() { List <DocumentTracker> newList = new List <DocumentTracker>(Tracker); double moveCount = Math.Ceiling(newList.Count * .30); for (int a = 0; a < moveCount; a++) { DocumentTracker aDoc = ObjectUtil.getRandomObjectFromList <DocumentTracker>(newList); // Make sure we do not use this again newList.Remove(aDoc); String currentPath = ProcessBasePath + aDoc.getPath(); Document docToMove = CurrentRepository.GetSysObjectById <Document>(aDoc.DocumentId); List <String> childPathAndFolder = ObjectUtil.getPathAndFolderNameFromPath(currentPath); String parentFolderPath = childPathAndFolder[0]; String childFolderName = childPathAndFolder[1]; Folder childFolder = CurrentRepository.GetFolderByQualification( String.Format("dm_folder where r_object_id = '{0}'", docToMove.GetRepeatingValue("i_folder_id", 0)), new FeedGetOptions { Inline = true, Links = true }); List <String> parentPathAndFolder = ObjectUtil.getPathAndFolderNameFromPath(parentFolderPath); String folderPath = parentPathAndFolder[0]; String parentFolderName = parentPathAndFolder[1]; Folder parentFolder = CurrentRepository.GetFolderByQualification( String.Format("dm_folder where folder('{0}') and object_name='{1}'", folderPath, parentFolderName), new FeedGetOptions { Inline = true, Links = true }); CurrentRepository.MoveDocument(docToMove, childFolder, parentFolder); WriteOutput("\t\t[MoveDocument] - RestDocument removed from " + currentPath + " to " + parentFolderPath); } }
protected void GetDocumentHistory() { List <DocumentTracker> newList = new List <DocumentTracker>(Tracker); double moveCount = Math.Ceiling(newList.Count * .10); for (int a = 0; a < moveCount; a++) { DocumentTracker aDoc = ObjectUtil.getRandomObjectFromList <DocumentTracker>(newList); // Make sure we do not use this again newList.Remove(aDoc); Document doc = CurrentRepository.GetSysObjectById <Document>(aDoc.DocumentId); //CurrentRepository.getDocumentByQualification( //String.Format("dm_document(all) where r_object_id = '{0}'",aDoc.DocumentId), null); WriteOutput("\t" + aDoc.DocumentId + ":" + doc.GetPropertyValue("object_name").ToString() + " - RestDocument History:"); Feed <AuditEntry> auditInfo = CurrentRepository.GetAuditHistory(HistoryType.THISDOCUMENTONLY, doc); List <AuditEntry> entries = ObjectUtil.getFeedAsList(auditInfo, true); //List<Entry<AuditEntry>> entries = (List<Entry<AuditEntry>>)auditInfo.Entries; foreach (AuditEntry history in entries) { WriteOutput("\t\tEvent:" + history.getEventName() + " Description:" + history.getEventDescription() + " ObjectName:" + history.getObjectName() + " Time:" + history.getTimeStamp()); } WriteOutput("\t\t[AuditHistory] - RestDocument history pulled from the Audit tables"); } }
public void ViewDocument(String path, DocumentTracker tracker, bool openDocument) { Document doc = CurrentRepository.GetSysObjectById <Document>(tracker.DocumentId); ContentMeta contentMeta = doc.GetPrimaryContent(new SingleGetOptions { View = ":all" }); if (contentMeta == null) { WriteOutput("!!!!!!!!!!!!!!!!VIEW TEST FAILURE!!!!!!!!!!!!!!!!!!!!"); return; } FileInfo downloadedContentFile = contentMeta.DownloadContentMediaFile(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } downloadedContentFile.MoveTo(path + Path.DirectorySeparatorChar + tracker.ChildId + "-" + downloadedContentFile.Name); WriteOutput("\t\t[GetFileForView] - RestDocument file is located: " + downloadedContentFile.FullName); if (openDocument) { System.Diagnostics.Process.Start(downloadedContentFile.FullName); } }
public void NestedList() { var db = DatabaseGenerator.Get(); Product product = new Product() { Category = new Category() { Tags = new List <string>() { "Soft" } } }; var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Category.Tags.Add("Hard"); var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Category':{'Tags':['Soft','Hard']}}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
public ArangoDatabase() { SharedSetting = FindSetting("default"); Setting = new DatabaseSetting(SharedSetting); Connection = new HttpConnection(this); ChangeTracker = new DocumentTracker(this); Advanced = new AdvancedOperation(this); }
public void WithoutIdentifier() { var db = DatabaseGenerator.Get(); Person person = new Person(); var tracker = new DocumentTracker(db); tracker.TrackChanges(person, ObjectUtility.CreateJObject(person, db)); Assert.Throws <KeyNotFoundException>(() => tracker.GetChanges(person)); }
/// <summary> /// Called by ProjectDocumentTracker when a scc-capable project is closed /// </summary> /// <param name="project">The project.</param> /// <param name="removed">if set to <c>true</c> the project is being removed or unloaded from the solution.</param> protected override void OnProjectClosed(SccProjectData data, bool removed) { base.OnProjectClosed(data, removed); if (removed) { if (!string.IsNullOrEmpty(SolutionFilename)) { DocumentTracker.CheckDirty(SolutionFilename); } } }
public void None() { var db = DatabaseGenerator.Get(); Product product = new Product(); var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); var changed = tracker.GetChanges(product); Assert.Empty(changed); }
public void IgnoreKey() { var db = DatabaseGenerator.Get(); Product product = new Product(); var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Key = "999"; var changed = tracker.GetChanges(product); Assert.Equal(changed.Count, 0); }
protected void CreateRendition(int page, bool isPrimary) { List <string> idsWithRenditions = new List <string>(); List <DocumentTracker> newList = new List <DocumentTracker>(Tracker); double moveCount = Math.Ceiling(newList.Count * .30); for (int a = 0; a < moveCount; a++) { DocumentTracker aDoc = ObjectUtil.getRandomObjectFromList <DocumentTracker>(newList); // Make sure we do not use this again newList.Remove(aDoc); String objectId = aDoc.DocumentId; Document doc = CurrentRepository.GetSysObjectById <Document>(objectId); //getDocumentByQualification( //String.Format("dm_document where r_object_id = '{0}'", objectId), null); FileInfo file = ObjectUtil.getRandomFileFromDirectory(importFilesDirectory); String mimeType = ObjectUtil.getMimeTypeFromFileName(file.Name); // Upload the content as a new rendition GenericOptions rendOptions = new GenericOptions(); String format = ObjectUtil.getDocumentumFormatForFile(file.Extension); rendOptions.SetQuery("format", format); rendOptions.SetQuery("page", page); // If you want to allow multiple renditions of the same format, the modifier must be set, this makes the rendition unique in the list // the "modifier" is more like a label/tag for the rendition in the list. rendOptions.SetQuery("modifier", "Test"); // With primary false, will be added as a rendition rendOptions.SetQuery("primary", isPrimary); ContentMeta renditionMeta = doc.CreateContent(file.OpenRead(), mimeType, rendOptions); Feed <ContentMeta> contents = doc.GetContents <ContentMeta>(new FeedGetOptions { Inline = true }); List <Entry <ContentMeta> > entries = (List <Entry <ContentMeta> >)contents.Entries; WriteOutput("\t\t[AddRendition] - Rendition Added for RestDocument ID: " + doc.GetPropertyValue("r_object_id") + ":" + doc.GetPropertyValue("object_name")); foreach (Entry <ContentMeta> entry in entries) { ContentMeta rendition = entry.Content; WriteOutput("\t\t\tRendition Format: " + rendition.GetPropertyValue("full_format") + " Modifier: " + rendition.GetRepeatingString("page_modifier", 0)); //((Object[])rendition.getAttributeValue("page_modifier"))[0].ToString()); } idsWithRenditions.Add(objectId); } IDsWithRenditions = idsWithRenditions; }
public DocumentCollectionTracker(YellowstonePathology.Business.ReportDistribution.Model.ReportDistributionLogEntryCollection collection, YellowstonePathology.Business.Mongo.Server mongoServer) { this.m_MongoServer = mongoServer; this.m_DocumentTrackerList = new List<DocumentTracker>(); foreach (INotifyPropertyChanged o in collection) { DocumentTracker documentTracker = new DocumentTracker(this.m_MongoServer); documentTracker.Register(o); this.m_DocumentTrackerList.Add(documentTracker); } collection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(CollectionChanged); }
protected override void OnProjectRenamed(SccProjectData data) { if (string.IsNullOrEmpty(SolutionFilename)) { return; } // Mark the sln file edited, so it shows up in Pending Changes/Commit if (!string.IsNullOrEmpty(SolutionFilename)) { DocumentTracker.CheckDirty(SolutionFilename); } base.OnProjectRenamed(data); }
public void OneProperty() { var db = DatabaseGenerator.Get(); Product product = new Product(); var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Quantity = 5; var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Quantity':5}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
public void Delete(params T[] items) { lock (sessionLock) { foreach (var item in items) { additions.Remove(item); var key = mapper.ToKey(item); if (key.Empty) { throw new InvalidOperationException("The type " + typeof(T) + " does not specify any key fields."); } deleteKeys.Add(key); DocumentTracker.MarkForDeletion(key); } } }
public void OnePropertyToNull() { var db = DatabaseGenerator.Get(); Product product = new Product() { Title = "Pen" }; var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Title = null; var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Title':null}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
public void ListFromNull() { var db = DatabaseGenerator.Get(); Product product = new Product(); var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Tags = new List <string>() { "Soft" }; var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Tags':['Soft']}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
public void NestedFromNull() { var db = DatabaseGenerator.Get(); Product product = new Product(); var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Category = new Category() { Title = "Featured" }; var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Category':{'Title':'Featured','Tags':null,'Seller':null}}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
public void DictionaryFromNull() { var db = DatabaseGenerator.Get(); Product product = new Product(); var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.TypeQuantities = new Dictionary <string, int>() { { "Soft", 1 } }; var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'TypeQuantities':{'Soft':1}}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
public void NestedOneProperty() { var db = DatabaseGenerator.Get(); Product product = new Product() { Category = new Category() { Title = "Featured" } }; var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Category.Title = "Stock"; var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Category':{'Title':'Stock'}}"); Assert.True(JObject.DeepEquals(expectedJson, changed)); }
public void NestedToNull() { var db = DatabaseGenerator.Get(); Product product = new Product() { Category = new Category() { Title = "Featured" } }; var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.Category = null; var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'Category':null}"); Assert.Equal(JObject.DeepEquals(expectedJson, changed), true); }
protected void CreateFromTemplate() { Random rnd = new Random(); //get list of templates Feed <Document> results = CurrentRepository.ExecuteDQL <Document>(String.Format("select * from dm_document where FOLDER('/Templates') "), new FeedGetOptions { Inline = true, Links = true }); List <Document> docs = ObjectUtil.getFeedAsList <Document>(results, true); int resultSamples = docs.Count; WriteOutput(String.Format("\t[TemplateList] Returning list of templates...")); foreach (Document doc in docs) { WriteOutput(String.Format("\t\t\tTemplate Name: {0} ID: {1}", doc.GetPropertyValue("object_name").ToString(), doc.GetPropertyValue("r_object_id").ToString())); } List <string> req = childList; for (int i = 0; i < 10; i++) { DocumentTracker trackerDoc = Tracker[rnd.Next(0, Tracker.Count)]; string movePath = trackerDoc.getPath(); string childId = trackerDoc.ChildId; //select one of the documents Document template = docs[rnd.Next(0, resultSamples)]; Document newDoc = CurrentRepository.CopyDocument(template.GetPropertyValue("r_object_id").ToString(), ProcessBasePath + movePath); newDoc.SetPropertyValue("subject", "Created From Template: " + template.GetPropertyValue("object_name")); string documentName = ObjectUtil.NewRandomDocumentName("FROMTEMPLATE"); newDoc.SetPropertyValue("object_name", documentName); newDoc.Save(); string objectId = newDoc.GetPropertyValue("r_object_id").ToString(); //String childId = parentFolderId + " CHILD-" + new Random().Next(0, 5); Tracker.Add(new DocumentTracker(objectId, parentFolderId, childId)); WriteOutput("\t[CreateDocumentFromTemplate] Created document " + documentName + " from template " + template.GetPropertyValue("object_name").ToString()); } }
public void ExternallyChanged(string path, out bool isDirty) { if (path == null) { throw new ArgumentNullException("path"); } isDirty = false; if (DocumentTracker.NoReloadNecessary(path)) { return; } lock (_externallyChanged) { if (DocumentTracker.IsDocumentOpenInTextEditor(path)) { if (!DocumentTracker.IsDocumentDirty(path, true)) { if (!_externallyChanged.ContainsKey(path)) { _externallyChanged[path] = DocumentTracker.LockDocument(path, DocumentLockType.ReadOnly); } } else { DocumentLock dl; if (_externallyChanged.TryGetValue(path, out dl)) { _externallyChanged.Remove(path); dl.Dispose(); } isDirty = true; // Unhook external change handling: Make VS ask user } } } }
public void DictionaryTwoProperty() { var db = DatabaseGenerator.Get(); Product product = new Product() { TypeQuantities = new Dictionary <string, int>() { { "Soft", 1 } } }; var tracker = new DocumentTracker(db); tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db)); product.TypeQuantities["Soft"] = 5; product.TypeQuantities.Add("Hard", 2); var changed = tracker.GetChanges(product); var expectedJson = JObject.Parse("{'TypeQuantities':{'Hard':2,'Soft':5}}"); Assert.Equal(JObject.DeepEquals(expectedJson, changed), true); }
protected void ImportAsNewVersion() { List <DocumentTracker> myList = new List <DocumentTracker>(Tracker); WriteOutput(("\t[ImportAsNewVersion] Importing new Content to existing objects as New Versions")); for (int i = 0; i < (Math.Ceiling(myList.Count * .20)); i++) { DocumentTracker aDoc = myList[i]; myList.Remove(aDoc); Document doc = CurrentRepository.GetSysObjectById <Document>(myList[i].DocumentId); //RestDocument doc = CurrentRepository.getDocumentByQualification(String.Format("dm_document where r_object_id = '{0}'", // myList[i].DocumentId), new FeedGetOptions { Inline = true, Links = true }); Feed <OutlineAtomContent> versions = doc.GetAllVersions <OutlineAtomContent>(null); List <Entry <OutlineAtomContent> > entries = versions.Entries; WriteOutput("\t\tCurrentDocumentVersion: " + doc.GetRepeatingValuesAsString("r_version_label", ",") + " ID: " + doc.GetPropertyValue("r_object_id").ToString()); WriteOutput("\t\tVersion Count Prior to Importing New Version:" + entries.Count); if (!doc.IsCheckedOut()) { doc = doc.Checkout(); // Handles when you unwind during debugging and doc was checked out before. } if (doc.IsCheckedOut()) { WriteOutput("\t\t[CheckOut] - Checked out document..."); doc = doc.CancelCheckout(); if (!doc.IsCheckedOut()) { WriteOutput("\t\t[CancelCheckOut] - Canceled Checkout...."); doc = doc.Checkout(); if (doc.IsCheckedOut()) { WriteOutput("\t\t[CheckOut] - Checked out document after cancel checkout..., document is checked out by: " + doc.GetCheckedOutBy()); } else { WriteOutput("\t\t[CheckOut] - #####FAILED##### CHECK OUT DOCUMENT"); } } } else { WriteOutput("\t\t[CheckOut] - #####FAILED##### CHECK OUT DOCUMENT"); } FileInfo file = ObjectUtil.getRandomFileFromDirectory(importFilesDirectory); doc = CurrentRepository.ImportDocumentAsNewVersion(doc, file); WriteOutput("\t [ImportAsNewVersion] Import RestDocument as New Version"); if (doc.IsCheckedOut()) { WriteOutput("\t\t[CheckIn] - #####FAILED##### CHECK IN DOCUMENT"); } else { WriteOutput("\t\t[CheckIn] - RestDocument Checked IN..."); } Feed <OutlineAtomContent> newVersions = doc.GetAllVersions <OutlineAtomContent>(null); List <Entry <OutlineAtomContent> > newEntries = newVersions.Entries; WriteOutput("\t\tNew Version Count: " + newEntries.Count); WriteOutput("\t\tNewDocumentVersion: " + doc.GetRepeatingValuesAsString("r_version_label", ",") + " ID: " + doc.GetPropertyValue("r_object_id").ToString()); WriteOutput("\t\t[ListVersions] - List of document versions:"); WriteOutput("Versions:"); Feed <Document> allVersions = doc.GetAllVersions <Document>(new FeedGetOptions { Inline = true, View = ":all" }); foreach (Entry <Document> vDoc in allVersions.Entries) { WriteOutput(String.Format("\t\t\t ChronicleID: {0} ObjectID: {1} VersionLabel: {2}", doc.GetPropertyValue("i_chronicle_id").ToString(), vDoc.Content.GetPropertyValue("r_object_id").ToString(), vDoc.Content.GetRepeatingValuesAsString("r_version_label", ","))); } } }
private void HandleNewItems(IList newItems) { foreach (object o in newItems) { DocumentTracker documentTracker = new DocumentTracker(this.m_MongoServer); documentTracker.Register(o); documentTracker.Status = DocumentStatusEnum.Inserted; this.m_DocumentTrackerList.Add(documentTracker); } }
internal void HandleEvent(AnkhCommand command) { List <SccProject> dirtyProjects; HybridCollection <string> dirtyCheck; HybridCollection <string> maybeAdd; SvnSccProvider provider = GetService <SvnSccProvider>(); lock (_lock) { _posted = false; _onIdle = false; if (provider == null) { return; } dirtyProjects = _dirtyProjects; dirtyCheck = _dirtyCheck; maybeAdd = _maybeAdd; _dirtyProjects = null; _dirtyCheck = null; _maybeAdd = null; } if (dirtyCheck != null) { foreach (string file in dirtyCheck) { DocumentTracker.CheckDirty(file); } } if (dirtyProjects != null) { foreach (SccProject project in dirtyProjects) { if (project.IsSolution) { provider.UpdateSolutionGlyph(); } else { project.NotifyGlyphChanged(); } } } if (maybeAdd != null) { using (SvnClient cl = GetService <ISvnClientPool>().GetNoUIClient()) { foreach (string file in maybeAdd) { SvnItem item = SvnCache[file]; // Only add // * files // * that are unversioned // * that are addable // * that are not ignored // * and just to be sure: that are still part of the solution if (item.IsFile && !item.IsVersioned && item.IsVersionable && !item.IsIgnored && item.InSolution && !item.IsSccExcluded) { SvnAddArgs aa = new SvnAddArgs(); aa.ThrowOnError = false; // Just ignore errors here; make the user add them themselves aa.AddParents = true; if (cl.Add(item.FullPath, aa)) { item.MarkDirty(); // Detect if we have a file that Subversion might detect as binary if (item.IsVersioned && !item.IsTextFile) { // Only check small files, avoid checking big binary files FileInfo fi = new FileInfo(item.FullPath); if (fi.Length < 10) { // We're sure it's at most 10 bytes here, so just read all byte[] fileBytes = File.ReadAllBytes(item.FullPath); // If the file starts with a UTF8 BOM, we're sure enough it's a text file, keep UTF16 & 32 binary if (StartsWith(fileBytes, new byte[] { 0xEF, 0xBB, 0xBF })) { // Delete the mime type property, so it's detected as a text file again SvnSetPropertyArgs pa = new SvnSetPropertyArgs(); pa.ThrowOnError = false; cl.DeleteProperty(item.FullPath, SvnPropertyNames.SvnMimeType, pa); } } } } } } } } }