public static EditingContext GetEditingContext(this EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "artifact != null");

            var service = new EFArtifactService(artifact);
            var editingContext = new EditingContext();
            editingContext.SetEFArtifactService(service);
            return editingContext;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Disposes this editing context.
        /// </summary>
        /// <param name="disposing">True if this object is being disposed, or false if it is finalizing.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Let any interested parties know the context is being disposed
                if (Disposing != null)
                {
                    Disposing(this, EventArgs.Empty);
                }

                if (_contextItems != null)
                {
                    foreach (var contextItem in _contextItems)
                    {
                        var d = contextItem as IDisposable;
                        if (d != null)
                        {
                            d.Dispose();
                        }
                    }
                }

                _efArtifactService = null;
                _contextItems = null;
            }
        }
Ejemplo n.º 3
0
 internal void SetEFArtifactService(EFArtifactService artifactService)
 {
     _efArtifactService = artifactService;
 }
        internal EditingContext GetNewOrExistingContext(Uri itemUri)
        {
            EditingContext itemContext = null;

            // creating a new context is an expensive operation, so optimize for the case where it exists
            var item = _package.ModelManager.GetArtifact(itemUri);
            if (item != null)
            {
                _mapArtifactToEditingContext.TryGetValue(item, out itemContext);
            }

            // there isn't one, so call the path that will create it
            if (itemContext == null)
            {
                item = GetNewOrExistingArtifact(itemUri);
                if (itemUri != null
                    && item != null
                    && !_mapArtifactToEditingContext.TryGetValue(item, out itemContext))
                {
                    var service = new EFArtifactService(item);

                    var editingContext = new EditingContext();
                    editingContext.SetEFArtifactService(service);
                    itemContext = editingContext;
                    _mapArtifactToEditingContext[item] = itemContext;
                }
            }

            return itemContext;
        }