This project has moved and is read-only. For the latest updates, please go here.

Saving a new Project

Nov 13, 2014 at 11:35 AM
Edited Nov 13, 2014 at 11:40 AM
Hi,

I am very new to NShape.

Currently I load a project and display a diagram:
xmlStore1.DirectoryName = @"C:\Users\Public\Documents\NShape\Demo Projects";
xmlStore1.FileExtension = "nspj";
project1.LibrarySearchPaths.Add(@"C:\Users\Public\Documents\NShape\bin\Debug");
project1.AutoLoadLibraries = true;
project1.Open();
display1.LoadDiagram("Diagram 1");
display1.ActiveTool = new SelectionTool();

Works fine.

after a while I want to create a new Project, and work (well O.K. currently i do nothing with the new project) with it:
project1.Close();
project1.Name = "NewProject";
project1.Repository.Create();
Diagram diagram = new Diagram("D1");
project1.Repository.InsertAll(diagram);
display1.LoadDiagram("D1");
display1.ActiveTool = new SelectionTool();

Works fine. (Meaning I am shown an empty new diagram)

Then I want to save it:
project1.Repository.SaveChanges();

I do not understand the following exception. Do I have ti intialice the Project in another way to be able to save it?

Dataweb.NShape.NShapeException wurde nicht behandelt.
HResult=-2146233088
Message=Entity type 'Core.Project' does not exist in the repository.
Source=Dataweb.NShape
StackTrace:
   bei Dataweb.NShape.Advanced.CachedRepository.FindEntityType(String entityTypeName, Boolean mustExist)
   bei Dataweb.NShape.Advanced.CachedRepository.Dataweb.NShape.Advanced.IStoreCache.FindEntityTypeByName(String name)
   bei Dataweb.NShape.XmlStore.WriteProjectSettings(IStoreCache cache)
   bei Dataweb.NShape.XmlStore.WriteProject(IStoreCache cache)
   bei Dataweb.NShape.XmlStore.DoSaveChanges(IStoreCache cache, String filePath)
   bei Dataweb.NShape.XmlStore.SaveChangesToFile(IStoreCache cache)
   bei Dataweb.NShape.XmlStore.SaveChanges(IStoreCache cache)
   bei Dataweb.NShape.Advanced.CachedRepository.SaveChanges()
   bei Dia_2.Form1.newToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\SeilerM\documents\visual studio 2010\Projects\Dia_2\Dia_2\Form1.cs:Zeile 47.
   bei System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   bei System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   bei System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   bei System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   bei System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   bei System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   bei System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   bei System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   bei System.Windows.Forms.ToolStrip.WndProc(Message& m)
   bei System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.Run(Form mainForm)
   bei Dia_2.Program.Main() in C:\Users\SeilerM\documents\visual studio 2010\Projects\Dia_2\Dia_2\Program.cs:Zeile 18.
   bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()
InnerException:


Thank you for any helpful answer or hint what I have missed in the documentation.

Martin
Nov 13, 2014 at 2:13 PM
After taking a quick look, I would say you have to add the shape libraries to the project (before creating it):
project1.AddLibrary(typeof(Ellipse).Assembly, false);
Please refer to the following chapters of the documentation for details on adding libraries:
  • "Basic Tutorial > Libraries"
  • "Class Reference > Namespace Dataweb.NShape > Project Class > AddLibrary Method"
Nov 13, 2014 at 5:09 PM
Edited Nov 13, 2014 at 5:11 PM
Hi KurtHolzinger,

Thank your for your quick response.
Either I did nor understand or it was not the solution:
I simplyfied the code to see what is wrong:

// Menue: New Project
private void newToolStripMenuItem_Click(object sender, EventArgs e)
   {
        xmlStore1.DirectoryName = @"C:\Users\Public\Documents\NShape\Demo Projects";
        xmlStore1.FileExtension = "nspj";

        project1.Name = "NewProject";
        project1.LibrarySearchPaths.Add(@"C:\Users\Public\Documents\NShape\bin\Debug");

        project1.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Ellipse).Assembly, false);
        project1.Repository.Create();

        Diagram diagram = new Diagram("D1");
        project1.Repository.InsertAll(diagram);
        display1.LoadDiagram("D1");  
    }
// Menue: Save Changes
    private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {
        project1.Repository.SaveChanges();
    }
Still leaves me with the exception: "Entity type 'Core.Project' does not exist in the repository." if I try to save the project.

If I have a look at the "New Project" function I see, that I have created and assigned a diagram (which is shown), but no shapes on it.
Can I save an shape-empty Project?

Have a nice evening
Martin
Nov 14, 2014 at 8:21 AM
Yes, of course you can save an empty diagram.

After a closer look I finally spotted the problem:
Call
project1.Create();
instead of
project1.Repository.Create();
because the latter only creates the repository (the XML file in this case) whereas the first one creates a new project.
Marked as answer by MatinSeiler on 11/14/2014 at 2:31 AM