コード例 #1
0
ファイル: FileSet.cs プロジェクト: kouweizhong/Sop
 /// <summary>
 /// Add a File object to the Set
 /// </summary>
 /// <param name="name">Name of File Object</param>
 /// <param name="filename"></param>
 /// <param name="profile">Contains configuration data for this File</param>
 /// <returns></returns>
 public IFile Add(string name, string filename = null, Profile profile = null)
 {
     if (this.Btree.File.Server.ReadOnly)
     {
         throw new InvalidOperationException("Object Server is in read only mode.");
     }
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("name");
     }
     if (string.IsNullOrEmpty(filename))
     {
         filename = string.Format("{0}{1}.{2}", this.Btree.File.Server.Path, name,
                                  ObjectServer.DefaultFileExtension);
     }
     return(Locker.Invoke(() =>
     {
         if (Btree.Contains(name))
         {
             throw new ArgumentException(string.Format("File object with Name '{0}' is already in FileSet", name));
         }
         IFile f = null;
         if (Btree.Transaction != null)
         {
             f = ((Transaction.TransactionBase)Btree.Transaction).CreateFile(Btree.File.Server, name, filename);
         }
         else
         {
             f = new File(Btree.File.Server, name, filename);
         }
         ((File)f).Profile = profile == null ? new Profile(Btree.File.Profile) : profile;
         return Add(f);
     }));
 }
コード例 #2
0
ファイル: FileSet.cs プロジェクト: kouweizhong/Sop
        /// <summary>
        /// Add a File object to the Set
        /// </summary>
        /// <param name="f"></param>
        /// <param name="f"> </param>
        /// <returns></returns>
        public IFile Add(IFile f)
        {
            if (this.Btree.File.Server.ReadOnly)
            {
                throw new InvalidOperationException("Object Server is in read only mode.");
            }
            if (f == null)
            {
                throw new ArgumentNullException("f");
            }

            return(Locker.Invoke(() =>
            {
                if (!Btree.Contains(f.Name))
                {
                    if (f.Server == null)
                    {
                        f.Server = this.Btree.File.Server;
                    }
                    if (!f.IsOpen)
                    {
                        f.Open();
                    }
                    if (f.IsDirty)
                    {
                        f.Flush();
                    }
                    Btree.Add(f.Name, f);
                    //Btree.Flush();
                    return f;
                }
                throw new ArgumentException(string.Format("File object with Name '{0}' is already in FileSet", f.Name));
            }));
        }
コード例 #3
0
ファイル: FileSet.cs プロジェクト: kouweizhong/Sop
 public bool Contains(string name)
 {
     return(Locker.Invoke(() => { return Btree.Contains(name); }));
 }
コード例 #4
0
ファイル: FileSet.cs プロジェクト: kouweizhong/Sop
 public bool Contains(string name)
 {
     return(Btree.Contains(name));
 }