public override void Load(OpenedFile file, Stream stream)
        {
            Debug.Assert(file == this.PrimaryFile);

            EDMDesignerChangeWatcher.Init = true;

            // Load EDMX from stream
            XElement          edmxElement    = null;
            Action <XElement> readMoreAction = edmxElt => edmxElement = edmxElt;

            _edmView = new EDMView(stream, readMoreAction);

            // If EDMX is empty run EDM Wizard
            if (_edmView.EDM.IsEmpty)
            {
                edmxElement = null;
                EDMWizardWindow wizard = RunWizard(file, ProjectService.CurrentProject.RootNamespace);

                if (wizard.DialogResult == true)
                {
                    _edmView = new EDMView(wizard.EDMXDocument, readMoreAction);
                }
                else
                {
                    throw new WizardCancelledException();
                }
            }

            // Load or generate DesignerView and EntityTypeDesigners
            EntityTypeDesigner.Init = true;

            XElement designerViewsElement = null;

            if (edmxElement == null || (designerViewsElement = EDMXIO.ReadSection(edmxElement, EDMXIO.EDMXSection.DesignerViews)) == null)
            {
                designerViewsElement = DesignerIO.GenerateNewDesignerViewsFromCSDLView(_edmView);
            }

            if (edmxElement != null && designerViewsElement != null)
            {
                DesignerIO.Read(_edmView, designerViewsElement, entityType => new EntityTypeDesigner(entityType), complexType => new ComplexTypeDesigner(complexType));
            }

            EntityTypeDesigner.Init = false;

            // Call DoEvents, otherwise drawing associations can fail
            VisualHelper.DoEvents();

            // Gets the designer canvas
            _designerCanvas       = DesignerCanvas.GetDesignerCanvas(this, _edmView, _edmView.DesignerViews.FirstOrDefault());
            _scrollViewer.Content = _designerCanvas;

            // Register CSDL of EDMX in CSDL DatabaseTreeView
            CSDLDatabaseTreeViewAdditionalNode.Instance.CSDLViews.Add(_edmView.CSDL);

            EDMDesignerChangeWatcher.Init = false;
        }
예제 #2
0
        public static XDocument CreateEDMXFromIDatabase(IDatabase database, string modelNamespace, string objectContextNamespace, string objectContextName)
        {
            XDocument ssdlXDocument = GetSSDLXML(database, modelNamespace);

            string ssdlTempFilename = IO.IO.GetTempFilenameWithExtension("ssdl");

            ssdlXDocument.Save(ssdlTempFilename);

            FileInfo fileInfo     = new FileInfo(ssdlTempFilename);
            string   filenameRump = Path.GetTempPath() + fileInfo.Name.Replace(fileInfo.Extension, string.Empty);

            string edmGenPath = RuntimeEnvironment.GetRuntimeDirectory() + "\\EdmGen.exe";

            Process          process          = new Process();
            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.WorkingDirectory = Path.GetTempPath();
            processStartInfo.FileName         = edmGenPath;
            processStartInfo.Arguments        = string.Format(@"/mode:FromSSDLGeneration /inssdl:""{0}.ssdl"" /outcsdl:""{0}.csdl"" /outmsl:""{0}.msl"" /outobjectlayer:""{1}.Designer.cs"" /outviews:""{1}.Views.cs"" /Namespace:{2} /EntityContainer:{1}",
                                                              filenameRump, objectContextName, objectContextNamespace);
            processStartInfo.UseShellExecute        = false;
            processStartInfo.ErrorDialog            = false;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardError  = true;
            process.StartInfo = processStartInfo;
            process.Start();
            string outputMessage = process.StandardOutput.ReadToEnd();

            process.WaitForExit();

            if (process.ExitCode != 0)
            {
                throw new ObjectModelConverterException(string.Format("An error occured during generating the EDMX file from \"{0}.ssdl\".", filenameRump),
                                                        outputMessage, ObjectModelConverterExceptionEnum.EDM);
            }

            XDocument csdlXDocument = XDocument.Load(filenameRump + ".csdl");
            XDocument mslXDocument  = XDocument.Load(filenameRump + ".msl");

            mslXDocument = MSLIO.GenerateTypeMapping(mslXDocument);

            return(EDMXIO.WriteXDocument(ssdlXDocument, csdlXDocument, mslXDocument));
        }
 public override void Save(OpenedFile file, Stream stream)
 {
     EDMXIO.WriteXDocument(_edmView).Save(stream);
 }
        public override void Load(OpenedFile file, Stream stream)
        {
            Debug.Assert(file == this.PrimaryFile);

            EDMDesignerChangeWatcher.Init = true;

            // Load EDMX from stream
            XElement          edmxElement    = null;
            Action <XElement> readMoreAction = edmxElt => edmxElement = edmxElt;

            _edmView = new EDMView(stream, readMoreAction);

            // If EDMX is empty run EDM Wizard
            if (_edmView.EDM.IsEmpty)
            {
                edmxElement = null;

                string ns = String.Empty;
                if (ProjectService.CurrentProject == null)
                {
                    ns = ICSharpCode.Core.MessageService.ShowInputBox("EDMDesigner", "Enter NameSpace", "DefaultNamespace");
                }
                else
                {
                    ns = ProjectService.CurrentProject.RootNamespace;
                }

                EDMWizardWindow wizard = RunWizard(file, ns);

                if (wizard.DialogResult == true)
                {
                    _edmView = new EDMView(wizard.EDMXDocument, readMoreAction);
                }
                else
                {
                    throw new WizardCancelledException();
                }
            }

            // Load or generate DesignerView and EntityTypeDesigners
            EntityTypeDesigner.Init = true;

            XElement designerViewsElement = null;

            if (edmxElement == null || (designerViewsElement = EDMXIO.ReadSection(edmxElement, EDMXIO.EDMXSection.DesignerViews)) == null)
            {
                designerViewsElement = DesignerIO.GenerateNewDesignerViewsFromCSDLView(_edmView);
            }

            if (edmxElement != null && designerViewsElement != null)
            {
                DesignerIO.Read(_edmView, designerViewsElement, entityType => new EntityTypeDesigner(entityType), complexType => new ComplexTypeDesigner(complexType));
            }

            EntityTypeDesigner.Init = false;

            // Gets the designer canvas
            _designerCanvas       = DesignerCanvas.GetDesignerCanvas(this, _edmView, _edmView.DesignerViews.FirstOrDefault());
            _scrollViewer.Content = _designerCanvas;

            // Register CSDL of EDMX in CSDL DatabaseTreeView
            CSDLViews.Add(_edmView.CSDL);

            EDMDesignerChangeWatcher.Init = false;
        }
예제 #5
0
 public EDMView(XDocument edmxDocument, Action <XElement> readMoreAction)
 {
     EDM = EDMXIO.Read(edmxDocument, readMoreAction);
 }
예제 #6
0
 public EDMView(Stream stream, Action <XElement> readMoreAction)
 {
     EDM = EDMXIO.Read(stream, readMoreAction);
 }
예제 #7
0
 public EDMView(string edmxPath, Action <XElement> readMoreAction)
 {
     EDM = EDMXIO.Read(edmxPath, readMoreAction);
 }