module File; from EclassDB import all; export all; object FileSpace is File* components: ; description: (* A File Space is a representation of where File(s) are present in the E-Class operating environment. *); end; object File is components: name:FileName and file_type:FileType and approval:FileApproval and data:FileData; description: (* The File object is a representation of a file stored in a file space. It has a file name and a file type. *); end File; object FileName is string components: ; description: (* This is a string reprepresentation of the name of the file. *); end; object FileType is html_type:HtmlType or other_type:OtherType or eclass_type:EclassType components: ; description: (* The type of data is either Html or another type of data. *); end; object HtmlType components: ; description: (* File data typing tag indicating that the file contains html data. *); end HtmlType; object EclassType components: ; description: (* File data typing tag indicating that the file contains Eclass data. *); end EclassType; object OtherType components: ; description: (* File data typing tag indicating that the file conatins data different from html data. *); end OtherType; object FileApproval is writable:FileWritable and readable:FileReadable description: (* Indicates whether a file is readable and/or writable. *); end; object FileReadable is boolean components: ; description: (* Flag indicating whether the file can be read by the FileOpen operation. Flag has to be true by the FileOpen operation. *); end; object FileWritable is boolean components: ; description: (* Flag indicating whether the file can be saved by the FileSave operation. Flag has to be true by the FileSave operation. *); end; object Server is users:Users and db:Database description: (* The server has a list of users that can access and a database. *); end; object Users is UserRecord* description: (* Users is a part of the user record that has a user id and password. *); end; object UserRecord is id:UserID and pwd:Password description: (* A user record consists of a user id and password. *); end; object UserID is string description: (* The ID of a user is in the form of a string. *); end; object Password is string description: (* The password of a user is in the form of a string. *); end; object Database is string description: (* The database of servers on the network. *); end; object FileData is UserLecture description: (* Data type of file is UserLecture. *); end; object ServerUp is boolean description: (* Indicates whether the server is connected. *); end; operation LogOn is inputs: server:Server, id:UserID, pwd:Password, url:URL, cn:CourseNumber, sec:Section; outputs: db:Database, connect:ServerUp; precondition: exists (u in server.users) (u.id = id) and (u.pwd = pwd) and (url != nil) and (cn != nil) and (sec != nil); postcondition: db = server.db and connect = true; description: (* Operation that takes in the inputs and make sure that they are not empty and also makes sure that user exists in server. Has post conditions for makeing sure that the server is connected. *); end; operation LogOut is inputs: server:Server, db:Database, connect:ServerUp; outputs: db':Database, connect':ServerUp; precondition: db = server.db and connect = true; postcondition: db' != server.db and connect = false; description: (* Terminates the server. *); end; operation FileOpen is inputs: fs:FileSpace, fn:FileName, ews:EclassWorkSpace; outputs: ews':EclassWorkSpace; precondition: exists (file in fs) (file.name= fn) and file.approval.readable and (file.file_type?html_type or file.file_type?eclass_type); postcondition: (exists (ul:UserLecture) (ul = ews'.lectures[1]) and (ul.id = ews.id) and (exists (file in fs) (file.name = fn) and (ul = file.data)) and (not ul.nts) and (#ews'.lectures) = #(ews.lectures) +1) and (forall (i:integer | (i >= 2) and (i <= #(ews.lectures))) ews'.lectures[i+1] = ews.lectures[i+1] ); description: (* Opening an existing html or other file. *); end; operation FileSave is inputs: fs:FileSpace, ews:EclassWorkSpace; outputs: fs':FileSpace, ews':EclassWorkSpace; precondition: (ews.lectures[1].nts) and (exists (file in fs) (file.name = ews.lectures[1].file.name) and (file.approval.writable)); postcondition: (exists (file in fs') (file.name = ews'.lectures[1].file.name) and (file.data = ews'.lectures[1]) and (file.approval.writable) and (file.file_type?html_type or file.file_type?eclass_type) and (not ews'.lectures[1].nts) ); description: (* Saves work done in the lecture in a html or eclass format. *); end; operation FileSaveAs is inputs: fs:FileSpace, ews:EclassWorkSpace; outputs: fs':FileSpace, ews':EclassWorkSpace; precondition: (ews.lectures[1].nts) and (exists (file in fs) (file.name = ews.lectures[1].file.name) and (file.approval.writable)); postcondition: (exists (file in fs') (file.name = ews'.lectures[1].file.name) and (file.data = ews'.lectures[1]) and (file.approval.writable) and (file.file_type?html_type or file.file_type?eclass_type) and (not ews'.lectures[1].nts)); description: (* Saves work from a previously saved to a html or eclass format. *); end; operation FileSaveAll is inputs: fs:FileSpace, ews:EclassWorkSpace; outputs: fs':FileSpace, ews':EclassWorkSpace; precondition: (forall (i:integer | (i >= 1) and (i <= #(ews.lectures))) (ews.lectures[i].nts)) and (forall (i:integer | (i >= 1) and (i <= #(ews.lectures))) (exists (file in fs) (file.name = ews.lectures[i].file.name) and (file.approval.writable))); postcondition: (forall (i:integer | (i >= 1) and (i <= #(ews.lectures))) (exists (file in fs') (file.name = ews'.lectures[i].file.name) and (file.data = ews'.lectures[i]) and (file.approval.writable) and (file.file_type?html_type or file.file_type?eclass_type) and (not ews'.lectures[i].nts) )); description: (* Saves all the lecture opened to a html or eclass format. *); end; operation FileExit is inputs: fs:FileSpace, ews:EclassWorkSpace; outputs: ews':EclassWorkSpace; precondition: (forall (i:integer | (i>=1) and (i < #(ews.lectures))) not(ews.lectures[1].nts)); postcondition: ; description: (* Exits from the program and makes sure that the files don't need to be saved. *); end; object UserName is string description: (* The UserName is in the form of a string. *); end; object IsAnonymous is boolean description: (* Indicates whether the user is anonymous or not. *); end; object URL is string description: (* The URL of the server is in the form of a string. *); end; object CourseNumber is integer description: (* The course number of class logging onto is in the form of an integer. *); end; object Section is integer description: (* The section of the class logging onto is in the form of an integer. *); end; object IsConnected is boolean description: (* Indicates whether the user is connected to the server. *); end; operation ConnectToLecture inputs: un:UserName, anon:IsAnonymous, url:URL, cn:CourseNumber, sec:Section; outputs: connect:IsConnected; precondition: (* The UserName, URL, CourseNumber, and Section must not be null. *) un != nil and url != nil and cn != nil and sec != nil; postcondition: (* The user successfully connected to the lecture. *) connect = true; description: (* Connects user to an active lecture *); end ConnectToLecture; end File;