コード例 #1
0
ファイル: RestoreUtils.cs プロジェクト: amasasi/DotNetRosa
        public static void  importRMS(FormInstance dm, IStorageUtility storage, System.Type type, System.String path)
        {
            if (!typeof(Externalizable).IsAssignableFrom(type) || !typeof(Restorable).IsAssignableFrom(type))
            {
                return;
            }

            bool idMatters = typeof(Persistable).IsAssignableFrom(type);

            System.String childName = ((Restorable)PrototypeFactory.getInstance(type)).RestorableType;
            TreeElement   e         = dm.resolveReference(absRef(path, dm));

            System.Collections.ArrayList children = e.getChildrenWithName(childName);

            for (int i = 0; i < children.Count; i++)
            {
                FormInstance child = subDataModel((TreeElement)children[i]);

                Restorable inst = (Restorable)PrototypeFactory.getInstance(type);

                //restore record id first so 'importData' has access to it
                int recID = -1;
                if (idMatters)
                {
                    recID = ((System.Int32)getValue(RECORD_ID_TAG, child));
                    ((Persistable)inst).ID = recID;
                }

                inst.importData(child);

                try
                {
                    if (idMatters)
                    {
                        storage.write((Persistable)inst);
                    }
                    else
                    {
                        storage.add((Externalizable)inst);
                    }
                }
                catch (System.Exception ex)
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    throw new System.SystemException("Error importing RMS during restore! [" + type.FullName + ":" + recID + "]; " + ex.Message);
                }
            }
        }