当前位置: 首页>>代码示例>>C#>>正文


C# Index.Export方法代码示例

本文整理汇总了C#中Index.Export方法的典型用法代码示例。如果您正苦于以下问题:C# Index.Export方法的具体用法?C# Index.Export怎么用?C# Index.Export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Index的用法示例。


在下文中一共展示了Index.Export方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EncodeThread


//.........这里部分代码省略.........
                                var task = _cacheManager.ParityEncoding(keys, item.HashAlgorithm, item.BlockLength, item.CorrectionAlgorithm, tokenSource.Token);

                                while (!task.IsCompleted)
                                {
                                    if (this.State == ManagerState.Stop || !_settings.UploadItems.Contains(item)) tokenSource.Cancel();

                                    Thread.Sleep(1000);
                                }

                                group = task.Result;
                            }
                        }
                        catch (Exception)
                        {
                            continue;
                        }

                        lock (_thisLock)
                        {
                            if (!_settings.UploadItems.Contains(item))
                            {
                                foreach (var key in group.Keys.Skip(group.InformationLength))
                                {
                                    _cacheManager.Unlock(key);
                                }

                                continue;
                            }

                            foreach (var key in group.Keys.Skip(group.InformationLength))
                            {
                                item.UploadKeys.Add(key);
                                item.LockedKeys.Add(key);
                            }

                            item.Groups.Add(group);

                            item.Keys.RemoveRange(0, length);
                        }
                    }
                    else if (item.Groups.Count > 0 && item.Keys.Count == 0)
                    {
                        var index = new Index();
                        index.Groups.AddRange(item.Groups);

                        KeyCollection keys = null;

                        try
                        {
                            using (var stream = index.Export(_bufferManager))
                            using (ProgressStream encodingProgressStream = new ProgressStream(stream, (object sender, long readSize, long writeSize, out bool isStop) =>
                            {
                                isStop = (this.State == ManagerState.Stop || !_settings.UploadItems.Contains(item));
                            }, 1024 * 1024, true))
                            {
                                encodingProgressStream.Seek(0, SeekOrigin.Begin);

                                item.State = BackgroundUploadState.Encoding;
                                keys = _cacheManager.Encoding(encodingProgressStream, CompressionAlgorithm.None, CryptoAlgorithm.None, null, item.BlockLength, item.HashAlgorithm);
                            }
                        }
                        catch (StopIoException)
                        {
                            continue;
                        }

                        lock (_thisLock)
                        {
                            if (!_settings.UploadItems.Contains(item))
                            {
                                foreach (var key in keys)
                                {
                                    _cacheManager.Unlock(key);
                                }

                                continue;
                            }

                            foreach (var key in keys)
                            {
                                item.UploadKeys.Add(key);
                                item.LockedKeys.Add(key);
                            }

                            item.Keys.AddRange(keys);
                            item.Depth++;
                            item.Groups.Clear();
                        }
                    }
                }
                catch (Exception e)
                {
                    item.State = BackgroundUploadState.Error;

                    Log.Error(e);

                    this.Remove(item);
                }
            }
        }
开发者ID:Alliance-Network,项目名称:Library,代码行数:101,代码来源:BackgroundUploadManager.cs

示例2: EncodeThread


//.........这里部分代码省略.........
                    else if (item.Groups.Count > 0 && item.Keys.Count == 0)
                    {
                        item.State = UploadState.Encoding;

                        var index = new Index();

                        if (item.Type == UploadType.Upload)
                        {
                            index.Groups.AddRange(item.Groups);

                            index.CompressionAlgorithm = item.CompressionAlgorithm;

                            index.CryptoAlgorithm = item.CryptoAlgorithm;
                            index.CryptoKey = item.CryptoKey;
                        }
                        else if (item.Type == UploadType.Share)
                        {
                            index.Groups.AddRange(item.Groups);

                            if (item.Depth != 1)
                            {
                                index.CompressionAlgorithm = item.CompressionAlgorithm;

                                index.CryptoAlgorithm = item.CryptoAlgorithm;
                                index.CryptoKey = item.CryptoKey;
                            }
                        }

                        byte[] cryptoKey = null;
                        KeyCollection keys = null;

                        try
                        {
                            using (var stream = index.Export(_bufferManager))
                            using (ProgressStream hashProgressStream = new ProgressStream(stream, (object sender, long readSize, long writeSize, out bool isStop) =>
                            {
                                isStop = (this.EncodeState == ManagerState.Stop || !_settings.UploadItems.Contains(item));

                                item.EncodeOffset = Math.Min(readSize, stream.Length);
                            }, 1024 * 1024, true))
                            using (ProgressStream encodingProgressStream = new ProgressStream(stream, (object sender, long readSize, long writeSize, out bool isStop) =>
                            {
                                isStop = (this.EncodeState == ManagerState.Stop || !_settings.UploadItems.Contains(item));

                                item.EncodeOffset = Math.Min(readSize, stream.Length);
                            }, 1024 * 1024, true))
                            {
                                item.EncodeLength = stream.Length;

                                item.State = UploadState.ComputeHash;

                                if (item.HashAlgorithm == HashAlgorithm.Sha256)
                                {
                                    cryptoKey = Sha256.ComputeHash(hashProgressStream);
                                }

                                stream.Seek(0, SeekOrigin.Begin);
                                item.EncodeOffset = 0;

                                item.State = UploadState.Encoding;
                                keys = _cacheManager.Encoding(encodingProgressStream, item.CompressionAlgorithm, item.CryptoAlgorithm, cryptoKey, item.BlockLength, item.HashAlgorithm);
                            }
                        }
                        catch (StopIoException)
                        {
                            continue;
开发者ID:Alliance-Network,项目名称:Library,代码行数:67,代码来源:UploadManager.cs

示例3: UploadManagerThread

        private void UploadManagerThread()
        {
            for (; ; )
            {
                Thread.Sleep(1000 * 1);
                if (this.State == ManagerState.Stop) return;

                BackgroundUploadItem item = null;

                try
                {
                    lock (this.ThisLock)
                    {
                        if (_settings.BackgroundUploadItems.Count > 0)
                        {
                            item = _settings.BackgroundUploadItems
                                .Where(n => n.State == BackgroundUploadState.Encoding)
                                .FirstOrDefault();
                        }
                    }
                }
                catch (Exception)
                {
                    return;
                }

                if (item == null) continue;

                try
                {
                    if (item.Groups.Count == 0 && item.Keys.Count == 0)
                    {
                        Stream stream = null;

                        try
                        {
                            if (item.Type == BackgroundItemType.Link)
                            {
                                var link = item.Value as Link;
                                if (link == null) throw new FormatException();

                                stream = link.Export(_bufferManager);
                            }
                            else if (item.Type == BackgroundItemType.Store)
                            {
                                var store = item.Value as Store;
                                if (store == null) throw new FormatException();

                                stream = store.Export(_bufferManager);
                            }
                            else
                            {
                                throw new FormatException();
                            }

                            if (stream.Length == 0)
                            {
                                lock (this.ThisLock)
                                {
                                    item.Seed.Rank = 0;

                                    if (item.DigitalSignature != null)
                                    {
                                        item.Seed.CreateCertificate(item.DigitalSignature);
                                    }

                                    _connectionsManager.Upload(item.Seed);

                                    item.State = BackgroundUploadState.Completed;
                                }
                            }
                            else
                            {
                                KeyCollection keys = null;
                                byte[] cryptoKey = null;

                                try
                                {
                                    using (ProgressStream encodingProgressStream = new ProgressStream(stream, (object sender, long readSize, long writeSize, out bool isStop) =>
                                    {
                                        isStop = (this.State == ManagerState.Stop || !_settings.BackgroundUploadItems.Contains(item));
                                    }, 1024 * 1024, true))
                                    {
                                        item.Seed.Length = stream.Length;

                                        if (item.Seed.Length == 0) throw new InvalidOperationException("Stream Length");

                                        if (item.HashAlgorithm == HashAlgorithm.Sha256)
                                        {
                                            cryptoKey = Sha256.ComputeHash(encodingProgressStream);
                                        }

                                        encodingProgressStream.Seek(0, SeekOrigin.Begin);

                                        item.State = BackgroundUploadState.Encoding;
                                        keys = _cacheManager.Encoding(encodingProgressStream, item.CompressionAlgorithm, item.CryptoAlgorithm, cryptoKey, item.BlockLength, item.HashAlgorithm);
                                    }
                                }
                                catch (StopIoException)
                                {
//.........这里部分代码省略.........
开发者ID:networkelements,项目名称:Library,代码行数:101,代码来源:BackgroundUploadManager.cs


注:本文中的Index.Export方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。