private object Store(Type type, Dictionary <string, object> Parameters)
        {
            var obj = Configuration.Container.Build(type, Parameters);

            string inJson = obj.Serialize();

            if (Settings.CompressionFunction != null && Settings.DecompressionFunction != null)
            {
                inJson = Settings.CompressionFunction(inJson);
            }
            if (Settings.EncryptionFunction != null && Settings.DecryptionFunction != null)
            {
                inJson = Settings.EncryptionFunction(inJson);
            }

            ViewJson view = new ViewJson
            {
                Id       = Parameters.Hash(type),
                TypeHash = type.GetHashCode(),
                Json     = inJson
            };

            using (var session = OpenSession())
            {
                session.Store(view);
                session.SaveChanges();
            }

            return(obj);
        }
Пример #2
0
 public View(ViewJson vj)
 {
     name        = vj.name;
     orientation = new Quaternion((float)vj.orientation[0], (float)vj.orientation[1], (float)vj.orientation[2], (float)vj.orientation[3]);
     scale       = new Vector3((float)vj.scale[0], (float)vj.scale[1], (float)vj.scale[2]);
     opacities   = new Dictionary <string, double>();
     if (vj.opacityKeys.Count == vj.opacityValues.Count)
     {
         int numEntries = vj.opacityKeys.Count;
         for (int i = 0; i < numEntries; i++)
         {
             string meshName = vj.opacityKeys [i];
             // Remove a possible "ME" at the beginning of the mesh name (for backward compatibility):
             if (meshName.Substring(0, 2) == "ME")
             {
                 meshName = meshName.Substring(2, meshName.Length - 2);
             }
             opacities.Add(meshName, vj.opacityValues[i]);
         }
     }
     else
     {
         throw new System.Exception("Number of opacity values incorrect. Number of opacity keys and number of opacities must match!");
     }
 }
Пример #3
0
    public void saveViews()
    {
        Patient p = Patient.getLoadedPatient();
        string path = p.path + "/views.json";

        //Create file if it not exists
        if (!File.Exists(path))
        {
            using (StreamWriter outputFile = new StreamWriter(path,true))
            {
                outputFile.Close();
            }
        }

        //Write annotations in file
        using (StreamWriter outputFile = new StreamWriter(path))
        {
            foreach(View view in mViews)
            {
                ViewJson vj = new ViewJson(view);
                outputFile.WriteLine(JsonMapper.ToJson(vj));
            }
            outputFile.Close();
        }
        return;
    }
Пример #4
0
 public View(ViewJson vj)
 {
     name        = vj.name;
     orientation = new Quaternion((float)vj.orientation[0], (float)vj.orientation[1], (float)vj.orientation[2], (float)vj.orientation[3]);
     scale       = new Vector3((float)vj.scale[0], (float)vj.scale[1], (float)vj.scale[2]);
     opacities   = new Dictionary <string, double>();
     if (vj.opacityKeys.Count == vj.opacityValues.Count)
     {
         int numEntries = vj.opacityKeys.Count;
         for (int i = 0; i < numEntries; i++)
         {
             opacities.Add(vj.opacityKeys[i], vj.opacityValues[i]);
         }
     }
     else
     {
         throw new System.Exception("Number of opacity values incorrect. Number of opacity keys and number of opacities must match!");
     }
 }
Пример #5
0
 private void readViews()
 {
     // Find any views in a seperate view file, if given:
     string viewsFile = Path.Combine (base.path, "views.json");		// TODO: Read from base path?
     mViews.Clear ();
     //Debug.Log ("Loading Views: " + viewsFile);
     if (File.Exists (viewsFile)) {
         try {
             // Read the file
             string line;
             System.IO.StreamReader file = new System.IO.StreamReader (viewsFile);
             while ((line = file.ReadLine ()) != null) {
                 ViewJson vj = JsonMapper.ToObject<ViewJson> (line);
                 View view = new View (vj);
                 mViews.Add (view);
             }
             file.Close ();
         } catch {
             mViews.Clear ();
         }
     }
     Debug.Log ("Loaded: " + mViews.Count + " views.");
 }