/// <summary>
 /// Saves the integrator.
 /// </summary>
 /// <param name="toSave">The integrator to save</param>
 /// <remarks></remarks>
 public virtual void save(Integrator toSave)
 {
     if (!object.ReferenceEquals(null, toSave))
     {
         var tps   = toSave.blockTypes;
         var lstts = new List <List <List <Byte[]> > >();
         for (int i = 0; i < toSave.rowCount; i++)
         {
             var lsti = new List <List <Byte[]> >();
             for (int j = 0; j < toSave.blockCount; j++)
             {
                 var lstj = new List <Byte[]>();
                 for (int k = 0; k < toSave.blockTypes.Length; k++)
                 {
                     Byte[] btsk = null;
                     var    ce   = toSave.get_element(j, i, k);
                     if (!object.ReferenceEquals(null, ce))
                     {
                         var cons = ce.GetType().GetConstructor(Type.EmptyTypes);
                         if (object.ReferenceEquals(null, cons))
                         {
                             btsk = Serializer.serialize(ce);
                         }
                         else
                         {
                             if (ce.CanBeConvertedToFromByteArray)
                             {
                                 btsk = ce.getElementAsByteArray();
                             }
                             else
                             {
                                 btsk = Serializer.serialize(ce);
                             }
                         }
                     }
                     else
                     {
                         btsk = Serializer.serialize(new NullElement());
                     }
                     lstj.Add(btsk);
                 }
                 lsti.Add(lstj);
             }
             lstts.Add(lsti);
         }
         var ndat = new Tuple <Type[], List <List <List <Byte[]> > > >(tps, lstts);
         _data = Serializer.serialize(ndat);
     }
     else
     {
         throw new ArgumentNullException("toSave");
     }
 }
 /// <summary>
 /// Loads integration data from the specified loader into the integrator.
 /// </summary>
 /// <param name="loader">The loader to use</param>
 /// <remarks></remarks>
 public void load(ILoader loader)
 {
     if (object.ReferenceEquals(null, loader))
     {
         throw new ArgumentNullException("loader");
     }
     lock (slockop) {
         Integrator me = loader.load();
         if (!object.ReferenceEquals(null, me))
         {
             _blocktypes = me._blocktypes;
             data        = me.data;
             _blocks     = me._blocks;
             _rows       = me._rows;
         }
     }
 }
 public XMLIntegration(Integrator iIn)
 {
     rowCount   = iIn.rowCount;
     blockCount = iIn.blockCount;
     indexCount = iIn.blockTypes.Length;
     types      = System.Convert.ToBase64String(Serializer.serialize(iIn.blockTypes));
     rows       = new XRow[iIn.rowCount];
     for (int i = 0; i < iIn.rowCount; i++)
     {
         var tr = new List <List <IElement> >();
         for (int j = 0; j < iIn.blockCount; j++)
         {
             tr.Add(new List <IElement>(iIn.get_block(j, i)));
         }
         rows[i] = new XRow(tr);
     }
 }
            public Integrator toIntegrator()
            {
                var tps   = Serializer.deSerialize(System.Convert.FromBase64String(types)) as Type[];
                var toret = new Integrator(tps, blockCount, rowCount);
                var lstm  = new List <List <List <IElement> > >();

                for (int i = 0; i < rows.Length; i++)
                {
                    lstm.Add(rows[i].toRow(tps));
                }
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < blockCount; j++)
                    {
                        for (int k = 0; k < tps.Length; k++)
                        {
                            toret.set_element(j, i, k, lstm[i][j][k]);
                        }
                    }
                }
                return(toret);
            }
 /// <summary>
 /// Saves the integrator.
 /// </summary>
 /// <param name="toSave">The integrator to save</param>
 /// <remarks></remarks>
 public virtual void save(Integrator toSave)
 {
     if (!object.ReferenceEquals(null, toSave))
     {
         var ndat = "";
         var xf   = new XmlSerializer(typeof(XMLIntegration));
         var ms   = new MemoryStream();
         var sr   = new StreamReader(ms);
         var sw   = new StreamWriter(ms);
         try {
             var xtodo = new XMLIntegration(toSave);
             xf.Serialize(sw, xtodo);
             ms.Position = 0;
             ndat        = sr.ReadToEnd();
         } catch (ObjectDisposedException e) {
             ndat = "";
             sr.Dispose();
             sr = null;
             sw.Dispose();
             sw = null;
             ms.Dispose();
             ms = null;
             xf = null;
             throw e;
         } catch (IOException e) {
             ndat = "";
             sr.Dispose();
             sr = null;
             sw.Dispose();
             sw = null;
             ms.Dispose();
             ms = null;
             xf = null;
             throw e;
         } catch (OutOfMemoryException e) {
             ndat = "";
             sr.Dispose();
             sr = null;
             sw.Dispose();
             sw = null;
             ms.Dispose();
             ms = null;
             xf = null;
             throw e;
         } finally {
             if (!object.ReferenceEquals(null, sr))
             {
                 sr.Dispose(); sr = null;
             }
             if (!object.ReferenceEquals(null, sw))
             {
                 sw.Dispose(); sw = null;
             }
             if (!object.ReferenceEquals(null, ms))
             {
                 ms.Dispose(); ms = null;
             }
             xf = null;
         }
         _data = ndat;
     }
     else
     {
         throw new ArgumentNullException("toSave");
     }
 }
        /// <summary>
        /// Loads the integrator.
        /// </summary>
        /// <returns>Integrator</returns>
        /// <remarks></remarks>
        public virtual Integrator load()
        {
            if (object.ReferenceEquals(null, _data))
            {
                throw new NullReferenceException("_data");
            }
            Integrator toret = null;
            var        xf    = new XmlSerializer(typeof(XMLIntegration));
            var        ms    = new MemoryStream();
            var        sw    = new StreamWriter(ms);

            try {
                XMLIntegration xtoret = null;
                sw.AutoFlush = true;
                for (int i = 0; i < _data.Length; i++)
                {
                    sw.Write(_data[i]);
                }
                if (!sw.AutoFlush)
                {
                    sw.Flush();
                }
                sw.AutoFlush = false;
                ms.Position  = 0;
                xtoret       = xf.Deserialize(ms) as XMLIntegration;
                toret        = !object.ReferenceEquals(null, xtoret) ? xtoret.toIntegrator() : null;
            } catch (System.Text.EncoderFallbackException e) {
                toret = null;
                sw.Dispose();
                sw = null;
                ms.Dispose();
                ms = null;
                xf = null;
                throw e;
            } catch (ObjectDisposedException e) {
                toret = null;
                sw.Dispose();
                sw = null;
                ms.Dispose();
                ms = null;
                xf = null;
                throw e;
            } catch (IOException e) {
                toret = null;
                sw.Dispose();
                sw = null;
                ms.Dispose();
                ms = null;
                xf = null;
                throw e;
            } catch (NotSupportedException e) {
                toret = null;
                sw.Dispose();
                sw = null;
                ms.Dispose();
                ms = null;
                xf = null;
                throw e;
            } finally {
                if (!object.ReferenceEquals(null, sw))
                {
                    sw.Dispose(); sw = null;
                }
                if (!object.ReferenceEquals(null, ms))
                {
                    ms.Dispose(); ms = null;
                }
                xf = null;
            }
            return(toret);
        }
        /// <summary>
        /// Loads the integrator.
        /// </summary>
        /// <returns>Integrator</returns>
        /// <remarks></remarks>
        public virtual Integrator load()
        {
            if (object.ReferenceEquals(null, _data))
            {
                throw new NullReferenceException("_data");
            }
            var dst = Serializer.deSerialize(_data) as Tuple <Type[], List <List <List <Byte[]> > > >;

            if (!object.ReferenceEquals(null, dst))
            {
                var rows   = dst.Item2.Count;
                var blocks = 0;
                if (rows < 1)
                {
                    blocks = 0;
                }
                else
                {
                    blocks = dst.Item2[0].Count;
                }
                var blockSize = dst.Item1.Length;
                var toret     = new Integrator(dst.Item1, blocks, rows);
                for (int i = 0; i < blocks; i++)
                {
                    for (int j = 0; j < rows; j++)
                    {
                        for (int k = 0; k < blockSize; k++)
                        {
                            var      ctype   = dst.Item1[k];
                            var      cons    = ctype.GetConstructor(Type.EmptyTypes);
                            IElement element = null;
                            if (!object.ReferenceEquals(null, cons))
                            {
                                element = cons.Invoke(null) as IElement;
                                if (element.CanBeConvertedToFromByteArray)
                                {
                                    element.setElementAsByteArray(dst.Item2[j][i][k]);
                                }
                                else
                                {
                                    element = Serializer.deSerialize(dst.Item2[j][i][k]) as IElement;
                                }
                            }
                            else
                            {
                                element = Serializer.deSerialize(dst.Item2[j][i][k]) as IElement;
                            }
                            if (element.GetType().Equals(typeof(NullElement)))
                            {
                                toret.set_element(i, j, k, null);
                            }
                            else
                            {
                                toret.set_element(i, j, k, element);
                            }
                        }
                    }
                }
                return(toret);
            }
            else
            {
                return(null);
            }
        }