Ejemplo n.º 1
0
        /// <summary>
        /// スレッドをhtml形式で保存
        /// </summary>
        /// <param name="cache">キャッシュ情報</param>
        /// <param name="header">保存するスレッド</param>
        /// <param name="filePath">保存先ファイルパス</param>
        public static void SaveHtml(Cache cache, ThreadHeader header, string filePath, ThreadSkinBase skin)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            // datの存在するパスを取得
            string fromPath = cache.GetDatPath(header);

            ThreadStorage reader = null;
            StreamWriter  writer = null;

            try {
                // 読み込みストリームを開く
                reader = new LocalThreadStorage(cache, header, StorageMode.Read);
                // 書き込みストリームを開く
                writer = new StreamWriter(filePath, false, TwinDll.DefaultEncoding);

                ResSetCollection items = new ResSetCollection();

                if (skin == null)
                {
                    skin = new HtmlSkin();
                }

                // ヘッダを書き込む
                writer.WriteLine(skin.GetHeader(header));

                // 本文を書き込む
                while (reader.Read(items) != 0)
                {
                    ;
                }
                writer.WriteLine(skin.Convert(items));

                // フッタを書き込む
                writer.WriteLine(skin.GetFooter(header));
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
        private IDbConnection GetConnection()
        {
            IDbConnection connection;

            if (ScopeIsActive)
            {
                var transaction = ThreadStorage.GetData <IDbTransaction>(TransactionScope.ScopeTransactionKey);

                if (transaction != null)
                {
                    connection = transaction.Connection;
                }
                else
                {
                    connection = this.GetDbConnection();

                    connection.Open();

                    transaction = connection.BeginTransaction();
                    ThreadStorage.SetData(TransactionScope.ScopeTransactionKey, transaction);
                }
            }
            else
            {
                connection = this.GetDbConnection();

                connection.Open();
            }

            return(connection);
        }
Ejemplo n.º 3
0
        public void Dispose()
        {
            var transaction = ThreadStorage.GetData <IDbTransaction>(ScopeTransactionKey);

            if (transaction == null || !ThreadStorage.GetData <bool>(ActiveScopeKey))
            {
                return;
            }

            var connection = transaction.Connection;

            if (_complete)
            {
                transaction.Commit();
            }
            else
            {
                transaction.Rollback();
            }

            if (connection != null && connection.State != ConnectionState.Closed)
            {
                connection.Dispose();
            }

            ThreadStorage.ClearData(ActiveScopeKey);
            ThreadStorage.ClearData(ScopeTransactionKey);
        }
Ejemplo n.º 4
0
        private void ReadCache(ResSetCollection buff)
        {
            // 新規に開く場合のみキャッシュを読み込む
            if (modeOpen)
            {
                if (ThreadIndexer.Exists(Cache, headerInfo))
                {
                    ThreadIndexer.Read(Cache, headerInfo);

                    try
                    {
                        storage            = new LocalThreadStorage(Cache, headerInfo, StorageMode.Read);
                        storage.BufferSize = bufferSize;

                        // すべてのレスを読み込み表示
                        while (storage.Read(buff) != 0)
                        {
                            ;
                        }
                    }
                    finally
                    {
                        if (storage != null)
                        {
                            storage.Close();
                            storage = null;
                        }
                    }

                    buff.IsNew = false;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// レスをあぼーん
        /// </summary>
        /// <param name="header">あぼーんするスレッド情報</param>
        /// <param name="indices">あぼーんするレス番号の配列</param>
        /// <param name="visible">透明あぼーんの場合はfalse、そうでない場合はtrue</param>
        public virtual void ResABone(ThreadHeader header, int[] indices, bool visible)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            if (indices == null)
            {
                throw new ArgumentNullException("indices");
            }

            ResSetCollection resSets = new ResSetCollection();
            ThreadStorage    storage = null;

            try {
                storage = new LocalThreadStorage(this);

                // スレッドを読み込む
                if (storage.Open(header, StorageMode.Read))
                {
                    while (storage.Read(resSets) != 0)
                    {
                        ;
                    }
                    storage.Close();
                }

                // レスの削除
                foreach (int index in indices)
                {
                    resSets.ABone(index, visible, visible ? ABoneType.Normal : ABoneType.Tomei, "");
                }

                // ログを一端削除
                string dat = GetDatPath(header);
                File.Delete(dat);

                // 書き込む
                if (storage.Open(header, StorageMode.Write))
                {
                    storage.Write(resSets);
                    storage.Close();
                }
                storage = null;
            }
            finally {
                if (storage != null)
                {
                    storage.Close();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// スレッドをdat形式で保存
        /// </summary>
        /// <param name="cache">キャッシュ情報</param>
        /// <param name="header">保存するスレッド</param>
        /// <param name="filePath">保存先ファイルパス</param>
        public static void SaveDat(Cache cache, ThreadHeader header, string filePath)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            // datの存在するパスを取得
            string fromPath = cache.GetDatPath(header);

            ThreadStorage reader = null;
            StreamWriter  writer = null;

            ResSetCollection    items     = new ResSetCollection();
            X2chThreadFormatter formatter = new X2chThreadFormatter();

            try {
                // 読み込みストリームを開く
                reader = new LocalThreadStorage(cache, header, StorageMode.Read);
                // 書き込みストリームを開く
                writer = new StreamWriter(filePath, false, Encoding.GetEncoding("Shift_Jis"));

                // すべて読み込む
                while (reader.Read(items) != 0)
                {
                    ;
                }
                writer.Write(formatter.Format(items));
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// スレッドをmonalog形式で保存
        /// </summary>
        /// <param name="cache">キャッシュ情報</param>
        /// <param name="header">保存するスレッド</param>
        /// <param name="filePath">保存先ファイルパス</param>
        public static void SaveMonalog(Cache cache, ThreadHeader header, string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            // datの存在するパスを取得
            string           fromPath = cache.GetDatPath(header);
            MonalogConverter conv     = new MonalogConverter();

            ThreadStorage    reader = null;
            ResSetCollection items  = new ResSetCollection();

            try {
                reader = new LocalThreadStorage(cache, header, StorageMode.Read);
                while (reader.Read(items) != 0)
                {
                    ;
                }
                conv.Write(filePath, header, items);
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
 internal ThreadPolicy(
     [Import(RequiredCreationPolicy = CreationPolicy.Shared)]
     ThreadStorage <T> storage)
     : base(storage)
 {
 }
Ejemplo n.º 9
0
 public TransactionScope()
 {
     ThreadStorage.SetData(ActiveScopeKey, true);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// データを読み込む&書き込む
        /// </summary>
        private void Reading()
        {
            ResSetCollection items = new ResSetCollection(),
                             buffer = new ResSetCollection();
            int read = -1, byteParsed, totalByteCount = 0;

            while (read != 0)
            {
                if (canceled)
                {
                    return;
                }

                read = reader.Read(buffer, out byteParsed);

                // あぼーんを検知した場合、処理を中止。
                if (read == -1)
                {
                    aboneDetected = true;
                    return;
                }

                totalByteCount += byteParsed;

                items.AddRange(buffer);

                // 逐次受信の場合はビューアに書き込む
                if (!isPackageReception)
                {
                    if (canceled)
                    {
                        return;
                    }

                    Invoke(new WriteResMethodInvoker(WriteInternal), new object[] { buffer });
                }
                buffer.Clear();

                OnReceive(new ReceiveEventArgs(
                              reader.Length, reader.Position, read));

                OnStatusTextChanged(
                    String.Format("{0} 受信中 ({1}/{2})",
                                  headerInfo.Subject, reader.Position, reader.Length));
            }

            // 一括受信の場合はここで一気にフラッシュ
            if (isPackageReception)
            {
                if (canceled)
                {
                    return;
                }

                Invoke(new WriteResMethodInvoker(WriteInternal), new object[] { items });
            }

            try
            {
                // スレッドのインデックス情報を保存
                storage            = new LocalThreadStorage(Cache, headerInfo, StorageMode.Write);
                storage.BufferSize = bufferSize;
                storage.Write(items);

                headerInfo.GotByteCount += totalByteCount;
                headerInfo.GotResCount  += items.Count;
                headerInfo.NewResCount   = items.Count;
                ThreadIndexer.Write(Cache, headerInfo);
            }
            catch (Exception ex)
            {
                TwinDll.Output(ex);
            }
            finally
            {
                storage.Close();
            }

            SaveThreadListIndices();
        }