示例#1
0
        private dao.Index ReadIndex(ImportObject import)
        {
            dao.Index idx = tableDef.CreateIndex();
            Dictionary <string, object> props = import.ReadProperties();

            idx.Name        = Convert.ToString(props["Name"]);
            idx.Primary     = Convert.ToBoolean(props["Primary"]);
            idx.Unique      = Convert.ToBoolean(props["Unique"]);
            idx.IgnoreNulls = Convert.ToBoolean(props["IgnoreNulls"]);
            idx.Required    = Convert.ToBoolean(props["Required"]);

            import.ReadLine(); //Read the 'Begin Fields' line
            while (!import.IsEnd)
            {
                dao.Field fld = idx.CreateField();
                import.ReadLine();
                fld.Name = import.PropertyValue();
                import.ReadLine();
                fld.Attributes = Convert.ToInt32(import.PropertyValue());
                ((dao.IndexFields)idx.Fields).Append(fld);
                import.ReadLine(2);  //Skip the 'End Field' line and read the next 'Begin Field' line (or 'End Fields' if there aren't more fields)
            }
            import.ReadLine(2);      //Read the 'End Index' line and the 'Begin Index' or 'End Indexes'
            return(idx);
        }
示例#2
0
        /// <summary>
        /// Ovewrite the current references with the references from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">Name of the file with the references to load into the database</param>
        public override void Load(string fileName)
        {
            using (StreamReader sr = new StreamReader(fileName)) {
                ImportObject import = new ImportObject(sr);

                //Remove any previous reference
                Access.Reference[] referencesList = new Access.Reference[App.Application.References.Count];
                int i = 0;
                foreach (Access.Reference reference in App.Application.References)
                {
                    if (!reference.BuiltIn && !reference.IsBroken)
                    {
                        referencesList[i++] = reference;
                    }
                }
                for (int j = 0; j < i; j++)
                {
                    App.Application.References.Remove(referencesList[j]);
                }

                //Add new references from file
                //if reference is dll or typelib, it will have guid and version
                //if reference is an access file (mde,mdb,mda,adp,...) we need add the reference by filename
                import.ReadLine();
                import.ReadLine();  //Read the Begin Reference (or End References if there is no references)
                while (!import.IsEnd)
                {
                    import.ReadLine();  //Read FullPath
                    string fullPath = import.PropertyValue();
                    import.ReadLine();  //Read Gui or End Reference
                    if (import.IsEnd)
                    {
                        fullPath = ResolveFileName(fullPath);
                        App.Application.References.AddFromFile(fullPath);
                    }
                    else
                    {
                        string guid = import.PropertyValue();
                        import.ReadLine();  //Read Major
                        int major = Convert.ToInt32(import.PropertyValue());
                        import.ReadLine();  //Read Minor
                        int minor = Convert.ToInt32(import.PropertyValue());
                        import.ReadLine();  //Read End Reference
                        App.Application.References.AddFromGuid(guid, major, minor);
                        import.ReadLine();  //Read the next Begin Reference or End References
                    }
                }
            }
        }
示例#3
0
        public override void Load(string fileName)
        {
            //Delete first the existent relations
            dao.Database  db        = App.Application.CurrentDb();
            dao.Relations relations = db.Relations;
            foreach (dao.Relation item in relations)
            {
                relations.Delete(item.Name);
            }
            relations.Refresh();

            using (StreamReader sr = new StreamReader(fileName)) {
                ImportObject import = new ImportObject(sr);
                import.ReadLine(2);      //Read 'Begin Relations' and 'Begin Relation' lines

                do
                {
                    string relationName = import.PeekObjectName();
                    Dictionary <string, object> relationProperties = import.ReadProperties();

                    dao.Relation relation = db.CreateRelation(relationName);
                    relation.Attributes   = Convert.ToInt32(relationProperties["Attributes"]);
                    relation.ForeignTable = Convert.ToString(relationProperties["ForeignTable"]);
                    relation.Table        = Convert.ToString(relationProperties["Table"]);
                    //try { relation.PartialReplica = Convert.ToBoolean(relationProperties["PartialReplica"]); } catch { }  //Accessing this property causes an exception ¿?

                    import.ReadLine(2);         //Read 'Begin Fields' and 'Begin Field' lines
                    while (!import.IsEnd)
                    {
                        dao.Field field = relation.CreateField();
                        field.Name = import.PropertyValue();
                        import.ReadLine();
                        field.ForeignName = import.PropertyValue();
                        import.ReadLine(2);     //Read 'End Field' and ('Begin Field' or 'End Fields'

                        relation.Fields.Append(field);
                    }

                    import.ReadLine(2);         //Read 'End Relation' and ('Begin Relation or 'End Relations')
                    relations.Append(relation);
                } while (!import.IsEnd);
            }
        }