コード例 #1
0
ファイル: FileCacheStore.cs プロジェクト: rahulyhg/cms-cli
        long[] ICacheStore.AddRange(List <CacheDataTemplate> items)
        {
            if ((items != null) && (items.Count > 0))
            {
                long[] res = new long[items.Count];

                for (int i = 0; i < items.Count; i++)
                {
                    if ((items[i] == null) || ((items[i].Key == null) && !items[i].CIID.HasValue) || (items[i].Data == null))
                    {
                        res[i] = CacheStore.BadRecordID;
                        continue;
                    }

                    // creating a new record
                    FileCacheRecord rec = CreateRecord(items[i].DataBinary, items[i].CIID, items[i].Key, items[i].EntityType, items[i].Mode ?? CacheMode.Persistant);

                    data.Add(rec);

                    res[i] = rec.ID;
                }

                return(res);
            }

            return(new long[0]);
        }
コード例 #2
0
ファイル: FileCacheStore.cs プロジェクト: rahulyhg/cms-cli
        long ICacheStore.Add(byte[] newData, CacheItemID?ciid, byte[] key, CacheEntityType entityType, CacheMode cacheMode)
        {
            if (((key == null) && !ciid.HasValue) || (newData == null))
            {
                return(CacheStore.BadRecordID);
            }

            // creating a new record
            FileCacheRecord rec = CreateRecord(newData, ciid, key, entityType, cacheMode);

            data.Add(rec);

            return(rec.ID);
        }
コード例 #3
0
ファイル: FileCacheStore.cs プロジェクト: rahulyhg/cms-cli
        void ICacheStore.Load()
        {
            // preparing file storage
            files = IsolatedStorageFile.GetUserStoreForApplication();

            if (!files.DirectoryExists(CacheDirectory))
            {
                files.CreateDirectory(CacheDirectory);
            }

            // loading next record number
            object temp = Core.Settings[SettingKey.FileCacheIteration];

            if ((temp != null) && (temp is long))
            {
                nextRecordID = (long)temp;
            }
            else
            {
                nextRecordID = 1;
            }

            // loading index
            string indexFileName = String.Format(CacheStore.CacheFilePathNoExtFormat, CacheDirectory, CacheIndexFileName);

            if (files.FileExists(indexFileName))
            {
                using (IsolatedStorageFileStream str = new IsolatedStorageFileStream(indexFileName, FileMode.Open, files))
                {
                    if (str.ReadByte() == 0)
                    {
                        while (1 == 1)
                        {
                            FileCacheRecord rec = new FileCacheRecord();

                            if (rec.LoadFromStream(str))
                            {
                                data.Add(rec);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: FileCacheStore.cs プロジェクト: rahulyhg/cms-cli
        private FileCacheRecord CreateRecord(byte[] newData, CacheItemID?ciid, byte[] key, CacheEntityType entityType, CacheMode cacheMode)
        {
            FileCacheRecord rec = new FileCacheRecord();

            rec.ID = nextRecordID++;

            if (ciid.HasValue)
            {
                rec.CIID = ciid.Value;
            }
            else
            {
                rec.CIID = null;
            }

            rec.Key        = key;
            rec.EntityType = entityType;
            rec.CacheMode  = cacheMode;

            rec.SetDataFile(Guid.NewGuid().ToString());
            rec.Data = newData;

            return(rec);
        }