コード例 #1
0
        private void CopyStream(CobaltFile file, Stream stream)
        {
            var tries = 3;

            for (int i = 0; i < tries; i++)
            {
                try
                {
                    GenericFdaStream myCobaltStream = new GenericFda(file.CobaltEndpoint, null).GetContentStream();

                    myCobaltStream.CopyTo(stream);

                    break;
                }
                catch (Exception)
                {
                    //unable to read update - save failed
                    if (i == tries - 1)
                    {
                        throw;
                    }

                    //waiting for cobalt completion
                    Thread.Sleep(50);
                }
            }
        }
コード例 #2
0
ファイル: CobaltStore.cs プロジェクト: YHZX2013/exchange_diff
        private void LogBlobStoreMetrics(Action <Enum, string> logDetail, CobaltFile cobaltFile)
        {
            int   num  = 0;
            int   num2 = 0;
            ulong num3 = 0UL;
            ulong num4 = 0UL;
            long  num5 = 0L;
            long  num6 = 0L;

            foreach (HostBlobStore hostBlobStore in this.blobStores)
            {
                HostBlobStoreMetrics metrics = hostBlobStore.GetMetrics();
                if (metrics != null)
                {
                    num  += metrics.ReadBlobsFound + metrics.ReadBlobsNotFound;
                    num2 += metrics.WrittenBlobs;
                    num3 += metrics.ReadBlobBytes;
                    num4 += metrics.WrittenBlobBytes;
                    TemporaryHostBlobStoreMetrics tempHostBlobStoreMetrics = ((TemporaryHostBlobStore)hostBlobStore).TempHostBlobStoreMetrics;
                    num5 += (long)tempHostBlobStoreMetrics.NumberOfBlobsOnDisk;
                    num6 += tempHostBlobStoreMetrics.TotalSizeOfBlobsOnDisk;
                }
            }
            logDetail(WacRequestHandlerMetadata.CobaltReads, num.ToString());
            logDetail(WacRequestHandlerMetadata.CobaltWrites, num2.ToString());
            logDetail(WacRequestHandlerMetadata.CobaltBytesRead, num3.ToString());
            logDetail(WacRequestHandlerMetadata.CobaltBytesWritten, num4.ToString());
            logDetail(WacRequestHandlerMetadata.DiskBlobCount, num5.ToString());
            logDetail(WacRequestHandlerMetadata.DiskBlobSize, num6.ToString());
        }
コード例 #3
0
        private void CopyStream(CobaltFile file, Stream stream)
        {
            var tries = 3;

            for (int i = 0; i < tries; i++)
            {
                try
                {
                    GenericFdaStream myCobaltStream = new GenericFda(file.CobaltEndpoint, null).GetContentStream();

                    myCobaltStream.CopyTo(stream);

                    break;
                }
                catch (Exception)
                {
                    //unable to read update - save failed
                    if (i == tries - 1)
                    {
                        throw;
                    }

                    //waiting for cobalt completion
                    Thread.Sleep(50);
                }
            }
        }
コード例 #4
0
ファイル: CobaltSession.cs プロジェクト: katyaap/WopiHost
        public CobaltSession(string sessionId, string filePath, string login = "******", string name = "Anonymous", string email = "", bool isAnonymous = true)
            :base(sessionId, filePath, login, name, email, isAnonymous)
        {
            m_disposal = new DisposalEscrow(m_sessionId);

            CobaltFilePartitionConfig content = new CobaltFilePartitionConfig();
            content.IsNewFile = true;
            content.HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".Content");
            content.cellSchemaIsGenericFda = true;
            content.CellStorageConfig = new CellStorageConfig();
            content.Schema = CobaltFilePartition.Schema.ShreddedCobalt;
            content.PartitionId = FilePartitionId.Content;

            CobaltFilePartitionConfig coauth = new CobaltFilePartitionConfig();
            coauth.IsNewFile = true;
            coauth.HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".CoauthMetadata");
            coauth.cellSchemaIsGenericFda = false;
            coauth.CellStorageConfig = new CellStorageConfig();
            coauth.Schema = CobaltFilePartition.Schema.ShreddedCobalt;
            coauth.PartitionId = FilePartitionId.CoauthMetadata;

            CobaltFilePartitionConfig wacupdate = new CobaltFilePartitionConfig();
            wacupdate.IsNewFile = true;
            wacupdate.HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".WordWacUpdate");
            wacupdate.cellSchemaIsGenericFda = false;
            wacupdate.CellStorageConfig = new CellStorageConfig();
            wacupdate.Schema = CobaltFilePartition.Schema.ShreddedCobalt;
            wacupdate.PartitionId = FilePartitionId.WordWacUpdate;

            Dictionary<FilePartitionId, CobaltFilePartitionConfig> partitionConfs = new Dictionary<FilePartitionId, CobaltFilePartitionConfig>();
            partitionConfs.Add(FilePartitionId.Content, content);
            partitionConfs.Add(FilePartitionId.WordWacUpdate, wacupdate);
            partitionConfs.Add(FilePartitionId.CoauthMetadata, coauth);

            m_cobaltFile = new CobaltFile(m_disposal, partitionConfs, new CobaltHostLockingStore(this), null);

            if (m_fileinfo.Exists)
            {
                String appdata_path = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
                appdata_path = Path.Combine(appdata_path, @"WopiCobaltHost");
                if (!Directory.Exists(appdata_path))
                    Directory.CreateDirectory(appdata_path);
                String cache_file = Path.Combine(appdata_path, m_fileinfo.Name);
                if (File.Exists(cache_file))
                    File.Delete(cache_file);
                File.Copy(m_fileinfo.FullName, cache_file, true);
                var file_atom = FileAtom.FromExisting(cache_file, m_disposal);
                //if want to avoid temp file, you can use memory Atom below
                //MemoryStream ms = new MemoryStream();
                //using (FileStream fileStream = m_fileinfo.OpenRead())
                //{
                //    fileStream.CopyTo(ms);
                //}
                //var src_atom = new AtomFromByteArray(ms.ToArray());
                Cobalt.Metrics o1;
                m_cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, file_atom, out o1);
                m_cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();
            }
        }
コード例 #5
0
        public WopiSession(string accessId, string filePath, string login = "******", string name = "Anonymous", string email = "", bool isAnonymous = true)
        {
            _accessId    = accessId;
            _fileinfo    = new FileInfo(filePath);
            _name        = name;
            _login       = login;
            _email       = email;
            _isAnonymous = isAnonymous;
            _disposal    = new DisposalEscrow(_accessId);

            CobaltFilePartitionConfig content = new CobaltFilePartitionConfig();

            content.IsNewFile              = true;
            content.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), _disposal, _accessId + @".Content");
            content.cellSchemaIsGenericFda = true;
            content.CellStorageConfig      = new CellStorageConfig();
            content.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            content.PartitionId = FilePartitionId.Content;

            CobaltFilePartitionConfig coauth = new CobaltFilePartitionConfig();

            coauth.IsNewFile              = true;
            coauth.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), _disposal, _accessId + @".CoauthMetadata");
            coauth.cellSchemaIsGenericFda = false;
            coauth.CellStorageConfig      = new CellStorageConfig();
            coauth.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            coauth.PartitionId = FilePartitionId.CoauthMetadata;

            CobaltFilePartitionConfig wacupdate = new CobaltFilePartitionConfig();

            wacupdate.IsNewFile              = true;
            wacupdate.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), _disposal, _accessId + @".WordWacUpdate");
            wacupdate.cellSchemaIsGenericFda = false;
            wacupdate.CellStorageConfig      = new CellStorageConfig();
            wacupdate.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            wacupdate.PartitionId = FilePartitionId.WordWacUpdate;

            Dictionary <FilePartitionId, CobaltFilePartitionConfig> pd = new Dictionary <FilePartitionId, CobaltFilePartitionConfig>();

            pd.Add(FilePartitionId.Content, content);
            pd.Add(FilePartitionId.WordWacUpdate, wacupdate);
            pd.Add(FilePartitionId.CoauthMetadata, coauth);

            _cobaltFile = new CobaltFile(_disposal, pd, new WopiHostLockingStore(this), null);

            if (_fileinfo.Exists)
            {
                var            src = FileAtom.FromExisting(_fileinfo.FullName, _disposal);
                Cobalt.Metrics o1;
                _cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, src, out o1);
                _cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();
            }
        }
コード例 #6
0
ファイル: CobaltSession.cs プロジェクト: zz110/WopiHost-2
        private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal)
        {
            var disposal = new DisposalEscrow(file.Owner);
            CobaltFilePartitionConfig content = new CobaltFilePartitionConfig
            {
                IsNewFile              = true,
                HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, file.Identifier + @".Content"),
                cellSchemaIsGenericFda = true,
                CellStorageConfig      = new CellStorageConfig(),
                Schema      = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.Content
            };

            CobaltFilePartitionConfig coauth = new CobaltFilePartitionConfig
            {
                IsNewFile              = true,
                HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, file.Identifier + @".CoauthMetadata"),
                cellSchemaIsGenericFda = false,
                CellStorageConfig      = new CellStorageConfig(),
                Schema      = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.CoauthMetadata
            };

            CobaltFilePartitionConfig wacupdate = new CobaltFilePartitionConfig
            {
                IsNewFile              = true,
                HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, file.Identifier + @".WordWacUpdate"),
                cellSchemaIsGenericFda = false,
                CellStorageConfig      = new CellStorageConfig(),
                Schema      = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.WordWacUpdate
            };

            Dictionary <FilePartitionId, CobaltFilePartitionConfig> partitionConfigs = new Dictionary <FilePartitionId, CobaltFilePartitionConfig> {
                { FilePartitionId.Content, content }, { FilePartitionId.WordWacUpdate, wacupdate }, { FilePartitionId.CoauthMetadata, coauth }
            };


            var tempCobaltFile = new CobaltFile(disposal, partitionConfigs, new CobaltHostLockingStore(principal), null);

            if (file.Exists)
            {
                using (var stream = file.GetReadStream())
                {
                    var     srcAtom = new AtomFromStream(stream);
                    Metrics o1;
                    tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, srcAtom, out o1);
                    tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();
                }
            }
            return(tempCobaltFile);
        }
コード例 #7
0
        public WopiSession(string accessId, string filePath, string login = "******", string name = "Anonymous", string email = "", bool isAnonymous = true)
        {
            _accessId = accessId;
            _fileinfo = new FileInfo(filePath);
            _name = name;
            _login = login;
            _email = email;
            _isAnonymous = isAnonymous;
            _disposal = new DisposalEscrow(_accessId);

            CobaltFilePartitionConfig content = new CobaltFilePartitionConfig();
            content.IsNewFile = true;
            content.HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), _disposal, _accessId + @".Content");
            content.cellSchemaIsGenericFda = true;
            content.CellStorageConfig = new CellStorageConfig();
            content.Schema = CobaltFilePartition.Schema.ShreddedCobalt;
            content.PartitionId = FilePartitionId.Content;

            CobaltFilePartitionConfig coauth = new CobaltFilePartitionConfig();
            coauth.IsNewFile = true;
            coauth.HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), _disposal, _accessId + @".CoauthMetadata");
            coauth.cellSchemaIsGenericFda = false;
            coauth.CellStorageConfig = new CellStorageConfig();
            coauth.Schema = CobaltFilePartition.Schema.ShreddedCobalt;
            coauth.PartitionId = FilePartitionId.CoauthMetadata;

            CobaltFilePartitionConfig wacupdate = new CobaltFilePartitionConfig();
            wacupdate.IsNewFile = true;
            wacupdate.HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), _disposal, _accessId + @".WordWacUpdate");
            wacupdate.cellSchemaIsGenericFda = false;
            wacupdate.CellStorageConfig = new CellStorageConfig();
            wacupdate.Schema = CobaltFilePartition.Schema.ShreddedCobalt;
            wacupdate.PartitionId = FilePartitionId.WordWacUpdate;

            Dictionary<FilePartitionId, CobaltFilePartitionConfig> pd = new Dictionary<FilePartitionId, CobaltFilePartitionConfig>();
            pd.Add(FilePartitionId.Content, content);
            pd.Add(FilePartitionId.WordWacUpdate, wacupdate);
            pd.Add(FilePartitionId.CoauthMetadata, coauth);

            _cobaltFile = new CobaltFile(_disposal, pd, new WopiHostLockingStore(this), null);

            if (_fileinfo.Exists)
            {
                var src = FileAtom.FromExisting(_fileinfo.FullName, _disposal);
                Cobalt.Metrics o1;
                _cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, src, out o1);
                _cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();
            }
        }
コード例 #8
0
ファイル: CobaltStore.cs プロジェクト: YHZX2013/exchange_diff
 public void Save(Stream stream)
 {
     this.SaveDiagnosticStream(stream, "Original.bin");
     lock (this.synchronizationObject)
     {
         using (DisposalEscrow disposalEscrow = new DisposalEscrow("CobaltStore.Save"))
         {
             CobaltFile          cobaltFile          = this.CreateCobaltFile(disposalEscrow, true);
             CobaltFilePartition cobaltFilePartition = cobaltFile.GetCobaltFilePartition(FilePartitionId.Content);
             Metrics             metrics;
             cobaltFilePartition.SetStream(GenericFda.ContentStreamId, new BytesFromStream(stream), ref metrics);
             cobaltFilePartition.CommitChanges();
             this.SaveDiagnosticDocument(cobaltFile, "AfterSave.bin");
         }
     }
 }
コード例 #9
0
ファイル: CobaltStore.cs プロジェクト: YHZX2013/exchange_diff
        public Stream GetDocumentStream()
        {
            Stream result;

            lock (this.synchronizationObject)
            {
                using (DisposalEscrow disposalEscrow = new DisposalEscrow("CobaltStore.GetDocumentStream"))
                {
                    CobaltFile          cobaltFile          = this.CreateCobaltFile(disposalEscrow, false);
                    CobaltFilePartition cobaltFilePartition = cobaltFile.GetCobaltFilePartition(FilePartitionId.Content);
                    Bytes  stream  = cobaltFilePartition.GetStream(CobaltFilePartition.ContentStreamId);
                    Stream stream2 = new StreamFromBytes(stream, 0UL);
                    Stream stream3 = new StreamDisposalWrapper(stream2, disposalEscrow.Transfer("GetDocumentStream-StreamDisposalWrapper"));
                    result = stream3;
                }
            }
            return(result);
        }
コード例 #10
0
ファイル: CobaltStore.cs プロジェクト: YHZX2013/exchange_diff
        private void SaveDiagnosticDocument(CobaltFile cobaltFile, string fileName)
        {
            if (!this.diagnosticsEnabled)
            {
                return;
            }
            CobaltFilePartition cobaltFilePartition = cobaltFile.GetCobaltFilePartition(FilePartitionId.Content);
            Bytes  stream   = cobaltFilePartition.GetStream(CobaltFilePartition.ContentStreamId);
            string filePath = this.GetFilePath(fileName);

            using (StreamFromBytes streamFromBytes = new StreamFromBytes(stream, 0UL))
            {
                using (FileStream fileStream = File.Open(filePath, FileMode.Create, FileAccess.Write))
                {
                    streamFromBytes.CopyTo(fileStream);
                }
            }
        }
コード例 #11
0
        public CobaltFile Create(int accessTokenId)
        {
            var disposal = new DisposalEscrow(accessTokenId.ToString(CultureInfo.InvariantCulture));

            var content = new CobaltFilePartitionConfig
            {
                IsNewFile              = true,
                HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".Content"),
                cellSchemaIsGenericFda = true,
                CellStorageConfig      = new CellStorageConfig(),
                Schema      = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.Content
            };

            var coauth = new CobaltFilePartitionConfig
            {
                IsNewFile              = true,
                HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".CoauthMetadata"),
                cellSchemaIsGenericFda = false,
                CellStorageConfig      = new CellStorageConfig(),
                Schema      = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.CoauthMetadata
            };

            var wacupdate = new CobaltFilePartitionConfig
            {
                IsNewFile              = true,
                HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".WordWacUpdate"),
                cellSchemaIsGenericFda = false,
                CellStorageConfig      = new CellStorageConfig(),
                Schema      = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.WordWacUpdate
            };

            var partitionConfs = new Dictionary <FilePartitionId, CobaltFilePartitionConfig>
            {
                { FilePartitionId.Content, content },
                { FilePartitionId.WordWacUpdate, wacupdate },
                { FilePartitionId.CoauthMetadata, coauth }
            };

            var cobaltFile = new CobaltFile(disposal, partitionConfs, new CobaltHostLockingStore(), null);

            var token = _tokenManager.GetToken(accessTokenId);

            Atom atom;

            if (_webDavManager.FileExist(token.FilePath))
            {
                var fileBytes = _webDavManager.GetFileBytes(token.FilePath);

                atom = new AtomFromByteArray(fileBytes);
            }
            else
            {
                var filePath = HttpContext.Current.Server.MapPath(WebDavAppConfigManager.Instance.OfficeOnline.NewFilePath + Path.GetExtension(token.FilePath));

                atom = new AtomFromByteArray(File.ReadAllBytes(filePath));
            }

            Cobalt.Metrics o1;
            cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, atom, out o1);
            cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();

            Add(token.FilePath, cobaltFile);

            return(cobaltFile);
        }
コード例 #12
0
ファイル: CobaltStore.cs プロジェクト: YHZX2013/exchange_diff
 public void ProcessRequest(Stream requestStream, Stream responseStream, Action <Enum, string> logDetail)
 {
     if (this.permanentException != null)
     {
         throw new CobaltStore.OrphanedCobaltStoreException(string.Format("The attachment is no longer available for CobaltStore {0}.", this.correlationId), this.permanentException);
     }
     try
     {
         Stopwatch stopwatch = new Stopwatch();
         stopwatch.Start();
         if (!Monitor.TryEnter(this.synchronizationObject, TimeSpan.FromSeconds(15.0)))
         {
             throw new Exception("Unable to acquire CobaltStore lock.");
         }
         stopwatch.Stop();
         logDetail(WacRequestHandlerMetadata.LockWaitTime, stopwatch.ElapsedMilliseconds.ToString());
         using (DisposalEscrow disposalEscrow = new DisposalEscrow("CobaltStore.ProcessRequest"))
         {
             using (Stream stream = new MemoryStream(65536))
             {
                 requestStream.CopyTo(stream, 65536);
                 stream.Position = 0L;
                 logDetail(WacRequestHandlerMetadata.CobaltRequestLength, stream.Length.ToString());
                 CobaltFile cobaltFile = this.CreateCobaltFile(disposalEscrow, false);
                 this.SaveDiagnosticDocument(cobaltFile, "BeforeRoundTrip.bin");
                 this.SaveDiagnosticStream(requestStream, "Request.xml");
                 using (DisposableAtomFromStream disposableAtomFromStream = new DisposableAtomFromStream(stream))
                 {
                     Roundtrip roundtrip       = cobaltFile.CobaltEndpoint.CreateRoundtrip();
                     bool      exceptionThrown = false;
                     Atom      atom            = null;
                     Stopwatch stopwatch2      = new Stopwatch();
                     stopwatch2.Start();
                     try
                     {
                         object          obj;
                         ProtocolVersion protocolVersion;
                         roundtrip.DeserializeInputFromProtocol(disposableAtomFromStream, ref obj, ref protocolVersion);
                         roundtrip.Execute();
                         cobaltFile.CommitChanges();
                         atom = roundtrip.SerializeOutputToProtocol(1, obj, null);
                     }
                     catch (Exception)
                     {
                         exceptionThrown = true;
                         throw;
                     }
                     finally
                     {
                         stopwatch2.Stop();
                         logDetail(WacRequestHandlerMetadata.CobaltTime, stopwatch2.ElapsedMilliseconds.ToString());
                         this.LogBlobStoreMetrics(logDetail, cobaltFile);
                         this.LogRequestDetails(logDetail, roundtrip, exceptionThrown);
                     }
                     this.UpdateEditorCount(roundtrip.RequestBatch);
                     this.SaveDiagnosticDocument(cobaltFile, "AfterRoundTrip.bin");
                     atom.CopyTo(responseStream);
                     logDetail(WacRequestHandlerMetadata.CobaltResponseLength, atom.Length.ToString());
                     if (this.diagnosticsEnabled)
                     {
                         using (MemoryStream memoryStream = new MemoryStream())
                         {
                             atom.CopyTo(memoryStream);
                             this.SaveDiagnosticStream(memoryStream, "Response.xml");
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         if (Monitor.IsEntered(this.synchronizationObject))
         {
             Monitor.Exit(this.synchronizationObject);
         }
     }
 }
コード例 #13
0
        public CobaltSession(string sessionId, string filePath, string login = "******", string name = "Anonymous", string email = "", bool isAnonymous = true)
            : base(sessionId, filePath, login, name, email, isAnonymous)
        {
            m_disposal = new DisposalEscrow(m_sessionId);

            CobaltFilePartitionConfig content = new CobaltFilePartitionConfig();

            content.IsNewFile              = true;
            content.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".Content");
            content.cellSchemaIsGenericFda = true;
            content.CellStorageConfig      = new CellStorageConfig();
            content.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            content.PartitionId = FilePartitionId.Content;

            CobaltFilePartitionConfig coauth = new CobaltFilePartitionConfig();

            coauth.IsNewFile              = true;
            coauth.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".CoauthMetadata");
            coauth.cellSchemaIsGenericFda = false;
            coauth.CellStorageConfig      = new CellStorageConfig();
            coauth.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            coauth.PartitionId = FilePartitionId.CoauthMetadata;

            CobaltFilePartitionConfig wacupdate = new CobaltFilePartitionConfig();

            wacupdate.IsNewFile              = true;
            wacupdate.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".WordWacUpdate");
            wacupdate.cellSchemaIsGenericFda = false;
            wacupdate.CellStorageConfig      = new CellStorageConfig();
            wacupdate.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            wacupdate.PartitionId = FilePartitionId.WordWacUpdate;

            Dictionary <FilePartitionId, CobaltFilePartitionConfig> partitionConfs = new Dictionary <FilePartitionId, CobaltFilePartitionConfig>();

            partitionConfs.Add(FilePartitionId.Content, content);
            partitionConfs.Add(FilePartitionId.WordWacUpdate, wacupdate);
            partitionConfs.Add(FilePartitionId.CoauthMetadata, coauth);

            m_cobaltFile = new CobaltFile(m_disposal, partitionConfs, new CobaltHostLockingStore(this), null);

            if (m_fileinfo.Exists)
            {
                String appdata_path = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
                appdata_path = Path.Combine(appdata_path, @"WopiCobaltHost");

                if (!Directory.Exists(appdata_path))
                {
                    Directory.CreateDirectory(appdata_path);
                }
                String cache_file = Path.Combine(appdata_path, m_fileinfo.Name);
                if (File.Exists(cache_file))
                {
                    File.Delete(cache_file);
                }
                File.Copy(m_fileinfo.FullName, cache_file, true);
                var file_atom = FileAtom.FromExisting(cache_file, m_disposal);
                //if want to avoid temp file, you can use memory Atom below
                //MemoryStream ms = new MemoryStream();
                //using (FileStream fileStream = m_fileinfo.OpenRead())
                //{
                //    fileStream.CopyTo(ms);
                //}
                //var src_atom = new AtomFromByteArray(ms.ToArray());
                Cobalt.Metrics o1;
                m_cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, file_atom, out o1);
                m_cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();
            }
        }
コード例 #14
0
 public bool Add(string filePath, CobaltFile file)
 {
     return(_storage.Add(GetSessionKey(filePath), file));
 }
コード例 #15
0
 public bool Add(string filePath, CobaltFile file)
 {
     return _storage.Add(GetSessionKey(filePath), file);
 }
コード例 #16
0
        /// <summary>
        /// 查看Session
        /// </summary>
        /// <param name="sessionId">当前session Id</param>
        /// <param name="filePath">文件路径</param>
        /// <param name="login">当前登录用户</param>
        /// <param name="name">文件所属人(作者)</param>
        /// <param name="isAnonymous">是否匿名</param>
        public CobaltSession(string sessionId, string filePath, string login = "******", string name = "Anonymous", bool isAnonymous = true)
            : base(sessionId, filePath, login, name, isAnonymous)
        {
            m_disposal = new DisposalEscrow(m_sessionId);

            CobaltFilePartitionConfig content = new CobaltFilePartitionConfig();

            content.IsNewFile              = true;
            content.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".Content");
            content.cellSchemaIsGenericFda = true;
            content.CellStorageConfig      = new CellStorageConfig();
            content.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            content.PartitionId = FilePartitionId.Content;

            CobaltFilePartitionConfig coauth = new CobaltFilePartitionConfig();

            coauth.IsNewFile              = true;
            coauth.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".CoauthMetadata");
            coauth.cellSchemaIsGenericFda = false;
            coauth.CellStorageConfig      = new CellStorageConfig();
            coauth.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            coauth.PartitionId = FilePartitionId.CoauthMetadata;

            CobaltFilePartitionConfig wacupdate = new CobaltFilePartitionConfig();

            wacupdate.IsNewFile              = true;
            wacupdate.HostBlobStore          = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), m_disposal, m_sessionId + @".WordWacUpdate");
            wacupdate.cellSchemaIsGenericFda = false;
            wacupdate.CellStorageConfig      = new CellStorageConfig();
            wacupdate.Schema      = CobaltFilePartition.Schema.ShreddedCobalt;
            wacupdate.PartitionId = FilePartitionId.WordWacUpdate;

            Dictionary <FilePartitionId, CobaltFilePartitionConfig> partitionConfs = new Dictionary <FilePartitionId, CobaltFilePartitionConfig>();

            partitionConfs.Add(FilePartitionId.Content, content);
            partitionConfs.Add(FilePartitionId.WordWacUpdate, wacupdate);
            partitionConfs.Add(FilePartitionId.CoauthMetadata, coauth);

            m_cobaltFile = new CobaltFile(m_disposal, partitionConfs, new CobaltHostLockingStore(this), null);

            if (m_fileinfo.Exists)
            {
                //String appdata_path = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
                String appdata_path = @"C:\temp";
                appdata_path = Path.Combine(appdata_path, @"WopiCobaltHost");
                logger.Info($"临时文件家路径:{appdata_path}");
                if (!Directory.Exists(appdata_path))
                {
                    Directory.CreateDirectory(appdata_path);
                }
                String cache_file = Path.Combine(appdata_path, m_fileinfo.Name);
                if (File.Exists(cache_file))
                {
                    File.Delete(cache_file);
                }
                File.Copy(m_fileinfo.FullName, cache_file, true);
                var            file_atom = FileAtom.FromExisting(cache_file, m_disposal);
                Cobalt.Metrics o1;
                m_cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, file_atom, out o1);
                m_cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();
            }
        }
コード例 #17
0
        public CobaltFile Create(int accessTokenId)
        {
            var disposal = new DisposalEscrow(accessTokenId.ToString(CultureInfo.InvariantCulture));

            var content = new CobaltFilePartitionConfig
            {
                IsNewFile = true,
                HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".Content"),
                cellSchemaIsGenericFda = true,
                CellStorageConfig = new CellStorageConfig(),
                Schema = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.Content
            };

            var coauth = new CobaltFilePartitionConfig
            {
                IsNewFile = true,
                HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".CoauthMetadata"),
                cellSchemaIsGenericFda = false,
                CellStorageConfig = new CellStorageConfig(),
                Schema = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.CoauthMetadata
            };

            var wacupdate = new CobaltFilePartitionConfig
            {
                IsNewFile = true,
                HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".WordWacUpdate"),
                cellSchemaIsGenericFda = false,
                CellStorageConfig = new CellStorageConfig(),
                Schema = CobaltFilePartition.Schema.ShreddedCobalt,
                PartitionId = FilePartitionId.WordWacUpdate
            };

            var partitionConfs = new Dictionary<FilePartitionId, CobaltFilePartitionConfig>
            {
                {FilePartitionId.Content, content},
                {FilePartitionId.WordWacUpdate, wacupdate},
                {FilePartitionId.CoauthMetadata, coauth}
            };

            var cobaltFile = new CobaltFile(disposal, partitionConfs, new CobaltHostLockingStore(), null);

            var token = _tokenManager.GetToken(accessTokenId);

            Atom atom;

            if (_webDavManager.FileExist(token.FilePath))
            {
                var fileBytes = _webDavManager.GetFileBytes(token.FilePath);

                atom = new AtomFromByteArray(fileBytes);
            }
            else
            {
                var filePath = HttpContext.Current.Server.MapPath(WebDavAppConfigManager.Instance.OfficeOnline.NewFilePath + Path.GetExtension(token.FilePath));

                atom = new AtomFromByteArray(File.ReadAllBytes(filePath));
            }

            Cobalt.Metrics o1;
            cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, atom, out o1);
            cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();

            Add(token.FilePath, cobaltFile);

            return cobaltFile;
        }