コード例 #1
0
        public bool UnpersistUnitSystemCatalog(string fileName)
        {
            bool ok = true;

            try {
                if (!File.Exists(fileName))
                {
                    fileName = GetBackupFileName(fileName);
                }

                if (File.Exists(fileName))
                {
                    ArrayList customUnitList = (ArrayList)UnpersistFile(fileName);

                    UnitSystemCatalog unitSystemCatalog = UnitSystemService.GetInstance().GetUnitSystemCatalog();

                    foreach (UnitSystem us in customUnitList)
                    {
                        us.SetObjectData();
                        unitSystemCatalog.Add(us);
                    }
                }
            }
            catch (Exception e) {
                ok = false;
                string message = e.ToString();
                MessageBox.Show(message, "Error Retrieving Unit System Catalog", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(ok);
        }
コード例 #2
0
        public bool UnpersistUnitSystemCatalog(string fileName)
        {
            bool ok = true;

            //Stream stream = null;
            try {
                if (!File.Exists(fileName))
                {
                    fileName = GetBackupFileName(fileName);
                }

                if (File.Exists(fileName))
                {
                    //if (File.Exists(fileName) || File.Exists(bakFileName)) {
                    //if (File.Exists(fileName)) {
                    //   stream = new FileStream(fileName, FileMode.Open);
                    //}
                    //else if (File.Exists(bakFileName)) {
                    //   stream = new FileStream(bakFileName, FileMode.Open);
                    //}
                    //SoapFormatter serializer = new SoapFormatter();
                    //BinaryFormatter serializer = new BinaryFormatter();
                    //serializer.AssemblyFormat = FormatterAssemblyStyle.Simple;


                    //IFormatter serializer = GetPersistenceSerializer();
                    //ArrayList customUnitList = (ArrayList)serializer.Deserialize(stream);
                    ArrayList customUnitList = (ArrayList)UnpersistFile(fileName);

                    //IEnumerator e = customUnitSystems.GetEnumerator();
                    //while (e.MoveNext()) {
                    //   UnitSystem us = (UnitSystem)e.Current;
                    //   us.SetObjectData(us.SerializationInfo, us.StreamingContext);

                    UnitSystemCatalog unitSystemCatalog = UnitSystemService.GetInstance().GetUnitSystemCatalog();

                    foreach (UnitSystem us in customUnitList)
                    {
                        us.SetObjectData();
                        unitSystemCatalog.Add(us);
                    }
                }
            }
            catch (Exception e) {
                ok = false;
                string message = e.ToString();
                MessageBox.Show(message, "Error Retrieving Unit System Catalog", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //finally {
            //   if (stream != null)
            //      stream.Close();
            //}
            return(ok);
        }
コード例 #3
0
        public bool UnpersistUnitSystemCatalog(string fileName, string bakFileName)
        {
            bool   ok     = true;
            Stream stream = null;

            try
            {
                if (File.Exists(fileName) || File.Exists(bakFileName))
                {
                    if (File.Exists(fileName))
                    {
                        stream = new FileStream(fileName, FileMode.Open);
                    }
                    else if (File.Exists(bakFileName))
                    {
                        stream = new FileStream(bakFileName, FileMode.Open);
                    }
                    SoapFormatter serializer = new SoapFormatter();
                    serializer.AssemblyFormat = FormatterAssemblyStyle.Simple;
                    UnitSystemCatalog unitSystemCatalog = UnitSystemService.GetInstance().GetUnitSystemCatalog();
                    ArrayList         customUnitSystems = (ArrayList)serializer.Deserialize(stream);
                    IEnumerator       e = customUnitSystems.GetEnumerator();
                    while (e.MoveNext())
                    {
                        UnitSystem us = (UnitSystem)e.Current;
                        us.SetObjectData(us.SerializationInfo, us.StreamingContext);
                        unitSystemCatalog.Add(us);
                    }
                }
            }
            catch (Exception e)
            {
                ok = false;
                string message = e.ToString();
                MessageBox.Show(message, "Error Retrieving Unit System Catalog", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
            return(ok);
        }