Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpssDataDocument"/> class
        /// and opens an existing SPSS file, or creates a new one.
        /// </summary>
        /// <param name="filename">The path of the file to open/create.</param>
        /// <param name="access">The desired file access.</param>
        protected SpssDataDocument(string filename, SpssFileAccess access)
        {
            this.Filename = filename;
            this.AccessMode = access;
            int handle;
            switch (access)
            {
                case SpssFileAccess.Read:
                    SpssException.ThrowOnFailure(SpssSafeWrapper.spssOpenRead(filename, out handle), "spssOpenRead");
                    break;
                case SpssFileAccess.Append:
                    SpssException.ThrowOnFailure(SpssSafeWrapper.spssOpenAppend(filename, out handle), "spssOpenAppend");
                    break;
                case SpssFileAccess.Create:
                    SpssException.ThrowOnFailure(SpssSafeWrapper.spssOpenWrite(filename, out handle), "spssOpenWrite");
                    break;
                default:
                    throw new ApplicationException("Unrecognized access level: " + access);
            }

            this.Handle = new SpssSafeHandle(handle, access);
            if (access == SpssFileAccess.Create)
            {
                this.IsCompressed = true;
            }
            this.IsAuthoringDictionary = true;
            this.Variables = new SpssVariablesCollection(this);
            this.Cases = new SpssCasesCollection(this);
            this.IsAuthoringDictionary = access == SpssFileAccess.Create;
        }
Beispiel #2
0
 /// <summary>
 /// Opens an SPSS data document for reading or appending.
 /// </summary>
 /// <param name="filename">
 /// The filename of the existing document to open.
 /// </param>
 /// <param name="access">
 /// <see cref="FileAccess.Read"/> for read only access, or 
 /// <see cref="FileAccess.Write"/> for append access.
 /// </param>
 /// <returns>
 /// The newly opened <see cref="SpssDataDocument">SPSS data document</see>.
 /// </returns>
 /// <remarks>
 /// This method is only for opening existing data documents.
 /// To create a new document, use the <see cref="Create(string)"/> method.
 /// </remarks>
 public static SpssDataDocument Open(string filename, SpssFileAccess access)
 {
     if (access == SpssFileAccess.Create)
     {
         throw new ArgumentOutOfRangeException("access", access, "Use Create method to create a new file.");
     }
     return new SpssDataDocument(filename, access);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SpssSafeHandle"/> class.
 /// </summary>
 /// <param name="handle">The SPSS handle.</param>
 /// <param name="accessMode">The access mode the handle was opened with.</param>
 public SpssSafeHandle(int handle, SpssFileAccess accessMode)
     : base(true)
 {
     this.accessMode = accessMode;
     this.SetHandle(new IntPtr(handle));
 }