/// <summary>
        /// Generate a callback that can be used to look up changes for a given entity.
        /// </summary>
        /// <param name="saveGraph">The save graph object that can be used to map from temporary IDs to real IDs.</param>
        /// <param name="entityChanges">Dictionary of changes for each entity. Where the keys may be temporary IDs.</param>
        /// <returns>A callback that will accept a real (saved) ID and return the entity changes associated with that entity id.</returns>
        private static Func <long, EntityChanges> CreateEntityChangesCallback(SaveGraph saveGraph, IDictionary <long, EntityChanges> entityChanges)
        {
            if (entityChanges == null || entityChanges.Count <= 0)
            {
                return(null);
            }

            return((savedEntityId) =>
            {
                // Map from the requested (real saved) ID to the original ID, which may be a temporary ID
                long possiblyTemporaryId;
                if (!saveGraph.Mapping.TryGetByValue(savedEntityId, out possiblyTemporaryId))
                {
                    possiblyTemporaryId = savedEntityId;
                }

                // Look up changes
                EntityChanges result;
                if (!entityChanges.TryGetValue(possiblyTemporaryId, out result))
                {
                    result = null;
                }
                return result;
            });
        }
 /// <summary>
 /// Sets the save graph.
 /// </summary>
 /// <param name="state">The state.</param>
 /// <param name="saveGraph">The save graph.</param>
 internal static void SetSaveGraph(IDictionary <string, object> state, SaveGraph saveGraph)
 {
     if (state != null)
     {
         state[SaveGraphKeyName] = saveGraph;
     }
 }
Пример #3
0
        private void save()
        {
            var dialog = new SaveFileDialog();

            dialog.Title  = "図形を保存";
            dialog.Filter = "XPSファイル|*.xps";
            if (dialog.ShowDialog() == true)
            {
                SaveGraph.Save(this, dialog.FileName);
            }
        }
        /// <summary>
        /// Called after saving of the specified enumeration of entities has taken place.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <param name="state">The state passed between the before save and after save callbacks.</param>
        public void OnAfterSave(IEnumerable <IEntity> entities, IDictionary <string, object> state)
        {
            object entry;
            IDictionary <long, EntityChanges> modifiedRelatedEntities;

            // Filter out certain entity changes (namely modifying softwarePlatformOpenIdProvider, which keeps invalidating our caches)
            IList <IEntity> entityList = FilterEntityChangeList(entities);

            if (entityList.Count == 0)
            {
                return;
            }

            // Get the SaveGraph, for mappings between TempIDs and real IDs.
            SaveGraph saveGraph = EventTargetStateHelper.GetSaveGraph(state);

            IList <EntityRef> relationshipTypes = null;
            IList <long>      fieldTypes        = null;

            foreach (ICacheInvalidator cacheInvalidator in Invalidators.ToList( ))
            {
                modifiedRelatedEntities = null;
                if (state.TryGetValue(cacheInvalidator.Name, out entry))
                {
                    modifiedRelatedEntities = entry as IDictionary <long, EntityChanges>;
                }

                Func <long, EntityChanges> entityChangeGetter = CreateEntityChangesCallback(saveGraph, modifiedRelatedEntities);

                cacheInvalidator.OnEntityChange(entityList, InvalidationCause.Save, entityChangeGetter);

                if (modifiedRelatedEntities != null)
                {
                    if (relationshipTypes == null)
                    {
                        relationshipTypes = modifiedRelatedEntities.Where(kvp => kvp.Value != null)
                                            .SelectMany(kvp => kvp.Value.RelationshipTypesToEntities.Select(rte => rte.RelationshipType))
                                            .ToList( );
                    }
                    cacheInvalidator.OnRelationshipChange(relationshipTypes);

                    if (fieldTypes == null)
                    {
                        fieldTypes = modifiedRelatedEntities.Where(kvp => kvp.Value != null)
                                     .SelectMany(kvp => kvp.Value.FieldTypes)
                                     .ToList( );
                    }
                    cacheInvalidator.OnFieldChange(fieldTypes);
                }

                // Invalidate if this is a field or relationship
                InvalidateFieldOrRelationshipIfEntityIsFieldOrRelationship(entityList, cacheInvalidator);
            }
        }
Пример #5
0
        /// <summary>
        /// Ensures the report is the default report for the type.
        /// </summary>
        private void EnsureIsDefaultReportForType(Report report, IDictionary <string, object> state)
        {
            IEntityFieldValues changedFields;
            IDictionary <long, IChangeTracker <IMutableIdKey> > changedFwdRelationships;
            IDictionary <long, IChangeTracker <IMutableIdKey> > changedRevRelationships;

            report.GetChanges(out changedFields, out changedFwdRelationships, out changedRevRelationships, false, false);

            if (changedRevRelationships == null || changedRevRelationships.Count == 0)
            {
                // No changes
                return;
            }

            SaveGraph saveGraph = EventTargetStateHelper.GetSaveGraph(state);

            ResourceEventTarget.EnsureIsOnlyRelationship(EntityType.DefaultPickerReport_Field.Id, true, report, changedRevRelationships, saveGraph);
            ResourceEventTarget.EnsureIsOnlyRelationship(EntityType.DefaultDisplayReport_Field.Id, true, report, changedRevRelationships, saveGraph);
        }
Пример #6
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (BatchSize != 0)
            {
                hash ^= BatchSize.GetHashCode();
            }
            if (NumVisualizations != 0)
            {
                hash ^= NumVisualizations.GetHashCode();
            }
            if (NumExamples != 0)
            {
                hash ^= NumExamples.GetHashCode();
            }
            if (EvalIntervalSecs != 0)
            {
                hash ^= EvalIntervalSecs.GetHashCode();
            }
            if (MaxEvals != 0)
            {
                hash ^= MaxEvals.GetHashCode();
            }
            if (SaveGraph != false)
            {
                hash ^= SaveGraph.GetHashCode();
            }
            if (VisualizationExportDir.Length != 0)
            {
                hash ^= VisualizationExportDir.GetHashCode();
            }
            if (EvalMaster.Length != 0)
            {
                hash ^= EvalMaster.GetHashCode();
            }
            hash ^= metricsSet_.GetHashCode();
            if (ExportPath.Length != 0)
            {
                hash ^= ExportPath.GetHashCode();
            }
            if (IgnoreGroundtruth != false)
            {
                hash ^= IgnoreGroundtruth.GetHashCode();
            }
            if (UseMovingAverages != false)
            {
                hash ^= UseMovingAverages.GetHashCode();
            }
            if (EvalInstanceMasks != false)
            {
                hash ^= EvalInstanceMasks.GetHashCode();
            }
            if (MinScoreThreshold != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(MinScoreThreshold);
            }
            if (MaxNumBoxesToVisualize != 0)
            {
                hash ^= MaxNumBoxesToVisualize.GetHashCode();
            }
            if (SkipScores != false)
            {
                hash ^= SkipScores.GetHashCode();
            }
            if (SkipLabels != false)
            {
                hash ^= SkipLabels.GetHashCode();
            }
            if (VisualizeGroundtruthBoxes != false)
            {
                hash ^= VisualizeGroundtruthBoxes.GetHashCode();
            }
            if (GroundtruthBoxVisualizationColor.Length != 0)
            {
                hash ^= GroundtruthBoxVisualizationColor.GetHashCode();
            }
            if (KeepImageIdForVisualizationExport != false)
            {
                hash ^= KeepImageIdForVisualizationExport.GetHashCode();
            }
            if (RetainOriginalImages != false)
            {
                hash ^= RetainOriginalImages.GetHashCode();
            }
            if (IncludeMetricsPerCategory != false)
            {
                hash ^= IncludeMetricsPerCategory.GetHashCode();
            }
            if (RecallLowerBound != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(RecallLowerBound);
            }
            if (RecallUpperBound != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(RecallUpperBound);
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #7
0
        public bool OnBeforeSave(IEnumerable <IEntity> entities, IDictionary <string, object> state)
        {
            foreach (Document document in from entity in entities where entity.Is <Document>() select entity.AsWritable <Document>())
            {
                // Populate the document revision
                DocumentRevision revision          = Entity.Create <DocumentRevision>();
                bool             createNewRevision = false;
                bool             initialRevision   = false;
                if (EntityTemporaryIdAllocator.IsAllocatedId(document.Id))
                {
                    // Populate the initial version string for the document
                    revision.VersionComments = @"Initial Version";
                    revision.Version         = @"1.0";
                    revision.Name            = revision.Version;
                    createNewRevision        = true;
                    initialRevision          = true;
                }
                else
                {
                    DocumentRevision currentRevision = document.CurrentDocumentRevision;

                    if (currentRevision?.FileDataHash != document.FileDataHash)
                    {
                        // Extract the version number and increment it
                        string newRevision = string.Format("{0}.0", Convert.ToInt32(currentRevision.Version.Split('.')[0]) + 1);
                        revision.VersionComments = document.Description;  // Need to modify the document entity to include a hidden field for comments ??
                        revision.Version         = newRevision;
                        revision.Name            = newRevision;
                        createNewRevision        = true;
                    }
                }

                if (createNewRevision)
                {
                    revision.FileExtension = document.FileExtension;
                    revision.ModifiedDate  = DateTime.UtcNow;
                    revision.Size          = document.Size;

                    // Get the entity that represents the user
                    UserAccount userAccount = Entity.Get <UserAccount>(RequestContext.GetContext().Identity.Id);

                    // Associate the revision to the account
                    revision.RevisionUpdatedBy = userAccount;
                    // Associate the file to this revision
                    revision.FileDataHash = document.FileDataHash;


                    SaveGraph saveGraph = EventTargetStateHelper.GetSaveGraph(state);
                    saveGraph.Entities[revision.Id] = revision;

                    document.CurrentDocumentRevision = revision;

                    // Associate the document to the revision (documentHasDocumentRevision - used for version history listing)
                    document.DocumentHasDocumentRevision.Add(revision);

                    // Associate the last created user to the document
                    if (initialRevision)
                    {
                        document.DocumentCreatedBy = userAccount;
                    }

                    // Associate the last modified user to the document
                    document.DocumentModifiedBy = userAccount;
                }

                document.DocumentHasDocumentType = document.DocumentFileType;

                if (document.InFolder == null)
                {
                    // Default document dumping ground if not specified
                    document.InFolder = Entity.Get <DocumentFolder>(new EntityRef("core", "documentsDocumentFolder"));
                }
            }
            return(false);
        }
 void MenuView_Save()
 {
     SaveGraph.InvokeSafe();
 }
Пример #9
0
        /// <summary>
        /// Ensures that when adding the specified relationship to the specified entity that any other existing relationships (for the specified relationship)
        /// are removed from the related entity.
        /// </summary>
        /// <param name="relationship">The relationship being added .</param>
        /// <param name="isReverse"></param>
        /// <param name="entity">The entity being saved.</param>
        /// <param name="changedRelationships">The changed relationships.</param>
        /// <param name="saveGraph">The save graph.</param>
        internal static void EnsureIsOnlyRelationship(EntityRef relationship, bool isReverse, IEntity entity, IDictionary <long, IChangeTracker <IMutableIdKey> > changedRelationships, SaveGraph saveGraph)
        {
            IChangeTracker <IMutableIdKey> relationshipChanges;

            if (!changedRelationships.TryGetValue(relationship.Id, out relationshipChanges))
            {
                return;
            }

            // Check for additions only
            if (relationshipChanges.Added == null || !relationshipChanges.Added.Any())
            {
                return;
            }

            foreach (var addedType in relationshipChanges.Added)
            {
                // Get the entity at the other end of the relationship
                var targetEntity         = Entity.Get(addedType.Key);
                var existingSourceEntity = targetEntity.GetRelationships(relationship, isReverse ? Direction.Forward : Direction.Reverse).FirstOrDefault();

                if (existingSourceEntity == null || existingSourceEntity.Id == entity.Id)
                {
                    continue;
                }

                // The targetEntity has another entity with the specified relationship
                // Delete the relationships to the other entities
                // Note: we are making changes to the source not the target as making changes to the target will
                // fail with security errors if the target is a type
                IEntity entitySaveGraph;

                var writeableExistingSource = saveGraph.Entities.TryGetValue(existingSourceEntity.Id, out entitySaveGraph)
                    ? entitySaveGraph.AsWritable()
                    : existingSourceEntity.AsWritable();

                writeableExistingSource.GetRelationships(relationship, isReverse ? Direction.Reverse : Direction.Forward).Entities.Remove(targetEntity);

                // Add to save graph so change happens efficiently
                saveGraph.Entities[existingSourceEntity.Id] = writeableExistingSource;
            }
        }