示例#1
0
    // Adds item to cache, returns a guid for obtaining that item from the cache
    public static string AddItem(Item item)
    {
        string guid = Guid.NewGuid().ToString();

        cache.Add(guid, item);
        return(guid);
    }
示例#2
0
        public static Item GetInstance(ItemType type)
        {
            Item result;

            if (!ItemCache.TryGetValue(type, out result))
            {
                result      = Resources.Load <Item>(ITEMS_FOLDER_PATH + type.ToString());
                result.Type = type;
                ItemCache.Add(type, result);
            }
            return(result);
        }
示例#3
0
        ///// <summary>
        ///// Проверка доступности ссылки
        ///// </summary>
        ///// <param name="link"></param>
        ///// <returns></returns>
        //private bool IsLinkAlive(ItemLink link)
        //{
        //    string path = WebDavPath.Combine(link.MapTo, link.Name);
        //    try
        //    {
        //        var entry = _cloud.GetItem(path).Result;
        //        return entry != null;
        //    }
        //    catch (AggregateException e)
        //    when (  // let's check if there really no file or just other network error
        //            e.InnerException is WebException we &&
        //            (we.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound
        //         )
        //    {
        //        return false;
        //    }
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="doResolveType">Resolving file/folder type requires addition request to cloud</param>
        /// <returns></returns>
        public async Task <Link> GetItemLink(string path, bool doResolveType = true)
        {
            var cached = _itemCache.Get(path);

            if (null != cached)
            {
                return((Link)cached);
            }

            //TODO: subject to refact
            string   parent = path;
            ItemLink wp;
            string   right = string.Empty;

            do
            {
                string name = WebDavPath.Name(parent);
                parent = WebDavPath.Parent(parent);
                wp     = _itemList.Items.FirstOrDefault(ip => parent == ip.MapTo && name == ip.Name);
                if (null == wp)
                {
                    right = WebDavPath.Combine(name, right);
                }
            } while (parent != WebDavPath.Root && null == wp);

            if (null == wp)
            {
                return(null);
            }

            string addhref = string.IsNullOrEmpty(right)
                ? string.Empty
                : '/' + Uri.EscapeDataString(right.TrimStart('/'));
            var link = new Link(wp, path, wp.Href + addhref);

            //resolve additional link properties, e.g. OriginalName, ItemType, Size
            if (doResolveType)
            {
                await ResolveLink(link);
            }

            _itemCache.Add(link.FullPath, link);
            return(link);
        }
示例#4
0
    public override void AddItem(Item item)
    {
        DemoItem demoItem = new DemoItem(this)
        {
            Name           = item.Name,
            IsFolder       = item.IsFolder,
            Owner          = item.Owner,
            OwnerId        = item.Owner == null ? (long?)null : item.Owner.Id,
            ParentItem     = item.ParentItem,
            ParentItemId   = item.ParentItem == null ? (long?)null : item.ParentItem.Id,
            Content        = item.Content,
            ContentId      = item.Content == null ? (long?)null : item.Content.Id,
            CreationTime   = item.CreationTime,
            LastAccessTime = item.LastAccessTime,
            LastWriteTime  = item.LastWriteTime
        };

        lock (this.itemCacheLocker) {
            MaxItemId++;
            demoItem.Id = MaxItemId;
            ItemCache.Add(demoItem.Id, demoItem);
        }
        item.Id = demoItem.Id;
    }
示例#5
0
        private void FetchItems(bool bBypassItems)
        {
            List <Document> oDocuments;
            List <Document> oSearchDocuments;
            Field           oIdField;
            string          sItemId;
            bool            bPermitted = true;

            //create a list of result objects
            oDocuments = new List <Document>();

            //do we have any query attributes?
            if (oQueries.Count > 0)
            {
                if (oQueries.ContainsKey(Constants.Investments.Indexes.Fields.Title))
                {
                    oQuery = oQueries[Constants.Investments.Indexes.Fields.Title];
                    oQueries.Remove(Constants.Investments.Indexes.Fields.Title);
                }
                else
                {
                    oQuery = SearchHelper.CreateBooleanQuery(Occur.MUST, oQueries.Values.ToArray());
                }
                if (oDefaultQuery != null)
                {
                    oQuery = SearchHelper.CreateBooleanQuery(Occur.MUST, oQuery, oDefaultQuery);
                }
                //get documents from search
                oSearchDocuments = SearchHelper.SearchLuceneIndex(oQuery, Constants.Investments.Indexes.InvestmentsResearchIndex);
            }
            else
            {
                //get all documents
                oSearchDocuments = SearchHelper.SearchLuceneIndex(ALL_ITEMS_QUERY, Constants.Investments.Indexes.InvestmentsResearchIndex);
            }

            if (!bBypassItems)
            {
                //do we have documents?
                if (oSearchDocuments != null)
                {
                    //loop over the documents
                    foreach (Document oDocument in oSearchDocuments)
                    {
                        //get the id field
                        if ((oIdField = oDocument.GetField(Genworth.SitecoreExt.Constants.Investments.Indexes.Fields.Id)) != null && !string.IsNullOrEmpty(sItemId = oIdField.StringValue))
                        {
                            //lock on the item cache
                            lock (oItemCache)
                            {
                                //is this item in the item cache already?
                                if (oItemCache.ContainsKey(sItemId))
                                {
                                    //get the item
                                    bPermitted = oItemCache[sItemId];
                                }
                                else
                                {
                                    //get the item from Sitecore
                                    bPermitted = ContextExtension.CurrentDatabase.GetItem(ItemPointer.Parse(sItemId).ItemID) != null;

                                    //add to the list
                                    oItemCache.Add(sItemId, bPermitted);
                                }
                            }

                            //we only want to use this item if it is non-null
                            if (bPermitted)
                            {
                                //add teh document to hte list
                                oDocuments.Add(oDocument);
                            }
                        }
                    }
                }

                //store the results
                oResultDocuments = oDocuments.ToArray();
            }
            else
            {
                oResultDocuments = oSearchDocuments.ToArray();
            }
            //turn off dirty flag
            bIsDirty = false;
        }
示例#6
0
        ///// <summary>
        ///// Get list of files and folders from account.
        ///// </summary>
        ///// <param name="path">Path in the cloud to return the list of the items.</param>
        ///// <param  name="itemType">Unknown, File/Folder if you know for sure</param>
        ///// <param name="resolveLinks">True if you know for sure that's not a linked item</param>
        ///// <returns>List of the items.</returns>
        public virtual async Task <IEntry> GetItemAsync(string path, ItemType itemType = ItemType.Unknown, bool resolveLinks = true)
        {
            //TODO: вообще, всё плохо стало, всё запуталось, всё надо переписать
            var uriMatch = Regex.Match(path, @"\A/(?<uri>https://cloud\.mail\.\w+/public/\S+/\S+(/.*)?)\Z");

            if (uriMatch.Success)
            {
                return(await GetPublicItemAsync(new Uri(uriMatch.Groups["uri"].Value, UriKind.Absolute), itemType));
            }

            if (Account.IsAnonymous)
            {
                return(null);
            }

            path = WebDavPath.Clean(path);

            if (_settings.CacheListingSec > 0)
            {
                var cached = CacheGetEntry(path);
                if (cached != null)
                {
                    return(cached);
                }
            }

            //TODO: subject to refact!!!
            var ulink = resolveLinks ? await _linkManager.GetItemLink(path) : null;

            // bad link detected, just return stub
            // cause client cannot, for example, delete it if we return NotFound for this item
            if (ulink != null && ulink.IsBad)
            {
                var res = ulink.ToBadEntry();
                _itemCache.Add(res.FullPath, res);
                return(res);
            }

            if (itemType == ItemType.Unknown && ulink != null)
            {
                itemType = ulink.ItemType;
            }

            // TODO: cache (parent) folder for file
            //if (itemType == ItemType.File)
            //{
            //    var cachefolder = datares.ToFolder(path, ulink);
            //    _itemCache.Add(cachefolder.FullPath, cachefolder);
            //    //_itemCache.Add(cachefolder.Files);
            //}

            var rp = null == ulink?RemotePath.Get(path) : RemotePath.Get(ulink);

            var entry = await Account.RequestRepo.FolderInfo(rp, depth : Settings.ListDepth);

            if (null == entry)
            {
                return(null);
            }

            if (itemType == ItemType.Unknown)
            {
                itemType = entry is Folder
                    ? ItemType.Folder
                    : ItemType.File;
            }

            if (itemType == ItemType.Folder && entry is Folder folder) // fill folder with links if any
            {
                FillWithULinks(folder);
            }

            if (_settings.CacheListingSec > 0)
            {
                CacheAddEntry(entry);
            }

            return(entry);
        }
示例#7
0
        ///// <summary>
        ///// Get list of files and folders from account.
        ///// </summary>
        ///// <param name="path">Path in the cloud to return the list of the items.</param>
        ///// <param  name="itemType">Unknown, File/Folder if you know for sure</param>
        ///// <param name="resolveLinks">True if you know for sure that's not a linked item</param>
        ///// <returns>List of the items.</returns>
        public virtual async Task <IEntry> GetItemAsync(string path, ItemType itemType = ItemType.Unknown, bool resolveLinks = true)
        {
            //TODO: вообще, всё плохо стало, всё запуталось, всё надо переписать
            var uriMatch = Regex.Match(path, @"\A/https://cloud\.mail\.\w+/public(?<uri>/\S+/\S+(/.*)?)\Z");

            if (uriMatch.Success)
            {
                return(await GetPublicItemAsync(uriMatch.Groups["uri"].Value, itemType));
            }

            if (Account.IsAnonymous)
            {
                return(null);
            }

            path = WebDavPath.Clean(path);

            if (_settings.CacheListingSec > 0)
            {
                var cached = CacheGetEntry(path, _settings.ListDepth);
                if (cached != null)
                {
                    return(cached);
                }
            }

            //TODO: subject to refact!!!
            var ulink = resolveLinks ? await _linkManager.GetItemLink(path) : null;

            // bad link detected, just return stub
            // cause client cannot, for example, delete it if we return NotFound for this item
            if (ulink != null && ulink.IsBad)
            {
                var res = ulink.ToBadEntry();
                _itemCache.Add(res.FullPath, res);
                return(res);
            }

            if (itemType == ItemType.Unknown && ulink != null)
            {
                itemType = ulink.ItemType;
            }

            // TODO: cache (parent) folder for file
            //if (itemType == ItemType.File)
            //{
            //    var cachefolder = datares.ToFolder(path, ulink);
            //    _itemCache.Add(cachefolder.FullPath, cachefolder);
            //    //_itemCache.Add(cachefolder.Files);
            //}

            var entry = await Account.RequestRepo.FolderInfo(path, ulink);

            if (null == entry)
            {
                return(null);
            }

            if (itemType == ItemType.Unknown)
            {
                itemType = entry is Folder
                    ? ItemType.Folder
                    : ItemType.File;
            }

            // fill folder with links if any
            if (itemType == ItemType.Folder && entry is Folder folder)
            {
                var flinks = _linkManager.GetItems(folder.FullPath);
                if (flinks.Any())
                {
                    //var z = flinks.Where(f => f.IsFile).Skip(1).ToList(); //  Take(15).ToList();
                    foreach (var flink in flinks)
                    {
                        string linkpath = WebDavPath.Combine(folder.FullPath, flink.Name);

                        if (!flink.IsFile)
                        {
                            folder.Folders.Add(new Folder(0, linkpath)
                            {
                                CreationTimeUtc = flink.CreationDate ?? DateTime.MinValue
                            });
                        }
                        else
                        {
                            if (folder.Files.All(inf => inf.FullPath != linkpath))
                            {
                                var newfile = new File(linkpath, flink.Size)
                                {
                                    PublicLink = flink.Href,
                                };
                                if (flink.CreationDate != null)
                                {
                                    newfile.LastWriteTimeUtc = flink.CreationDate.Value;
                                }
                                folder.Files.Add(newfile);
                            }
                        }
                    }
                }
            }

            if (_settings.CacheListingSec > 0)
            {
                CacheAddEntry(entry);
            }

            return(entry);
        }
示例#8
0
            private void FetchItems(bool bBypassItems)
            {
                List <Document> oDocuments;
                List <Document> oSearchDocuments;
                Field           oIdField;
                string          sItemId;
                bool            bPermitted;

                //create a list of result objects
                oDocuments = new List <Document>();

                //get documents from search
                oSearchDocuments = SearchHelper.SearchLuceneIndex(oQuery, Constants.Investments.Indexes.InvestmentManagerStrategiesIndex);

                if (!bBypassItems)
                {
                    //do we have documents?
                    if (oSearchDocuments != null)
                    {
                        //loop over the documents
                        foreach (Document oDocument in oSearchDocuments)
                        {
                            //get the id field
                            if ((oIdField = oDocument.GetField(Genworth.SitecoreExt.Constants.Investments.Indexes.Fields.Id)) != null && !string.IsNullOrEmpty(sItemId = oIdField.StringValue))
                            {
                                //lock on the item cache
                                lock (oItemCache)
                                {
                                    //is this item in the item cache already?
                                    if (oItemCache.ContainsKey(sItemId))
                                    {
                                        //get the item
                                        bPermitted = oItemCache[sItemId];
                                    }
                                    else
                                    {
                                        //get the item from Sitecore
                                        bPermitted = ContextExtension.CurrentDatabase.GetItem(ItemPointer.Parse(sItemId).ItemID) != null;

                                        //add to the list
                                        oItemCache.Add(sItemId, bPermitted);
                                    }
                                }

                                //we only want to use this item if it is non-null
                                if (bPermitted)
                                {
                                    //add teh document to hte list
                                    oDocuments.Add(oDocument);
                                }
                            }
                        }
                    }

                    //store the results
                    oResultDocuments = oDocuments.ToArray();

                    //turn off dirty flag
                    bIsDirty = false;
                }
                else
                {
                    oResultDocuments = oSearchDocuments.ToArray();
                }
            }
示例#9
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            personCity = new Dictionary<int, City>();
            IList<City> allcity = new List<City>();
          
            cache = new ItemCache<Certificate>();

            using (RepositoryBase repository = new RepositoryBase())
            {
                try
                {
                    var city = repository.GetCity();
                    int i = 0;
                    foreach (City c in city)
                    {

                        comboBoxEdit1.Properties.Items.Add(c.Name);
                        personCity.Add(i, c);
                        i++;
                    }

                    var certificate = repository.GetCertificates();

                    foreach (Certificate c in certificate)
                    {
                        cache.Add(listBoxControl1.Items.Add(c.Name), c.Id, c);
                        
                    }

                }
                catch (Exception)
                {
                    repository.RollbackTransaction();
                }
            }

            listBoxControl1.SelectedIndex = -1;
        }
示例#10
0
        ///// <summary>
        ///// Get list of files and folders from account.
        ///// </summary>
        ///// <param name="path">Path in the cloud to return the list of the items.</param>
        ///// <param  name="itemType">Unknown, File/Folder if you know for sure</param>
        ///// <param name="resolveLinks">True if you know for sure that's not a linked item</param>
        ///// <returns>List of the items.</returns>
        public virtual async Task <IEntry> GetItemAsync(string path, ItemType itemType = ItemType.Unknown, bool resolveLinks = true)
        {
            path = WebDavPath.Clean(path);

            var cached = _itemCache.Get(path);

            if (null != cached)
            {
                return(cached);
            }

            //TODO: subject to refact!!!
            var ulink = resolveLinks ? await _linkManager.GetItemLink(path) : null;

            // bad link detected, just return stub
            // cause client cannot, for example, delete it if we return NotFound for this item
            if (ulink != null && ulink.IsBad)
            {
                var res = ulink.ToBadEntry();
                _itemCache.Add(res.FullPath, res);
                return(res);
            }

            if (itemType == ItemType.Unknown && ulink != null)
            {
                itemType = ulink.ItemType;
            }

            // TODO: cache (parent) folder for file
            //if (itemType == ItemType.File)
            //{
            //    var cachefolder = datares.ToFolder(path, ulink);
            //    _itemCache.Add(cachefolder.FullPath, cachefolder);
            //    //_itemCache.Add(cachefolder.Files);
            //}

            var entry = await Account.RequestRepo.FolderInfo(path, ulink);

            if (null == entry)
            {
                return(null);
            }

            if (itemType == ItemType.Unknown)
            {
                itemType = entry is Folder
                    ? ItemType.Folder
                    : ItemType.File;
            }

            // fill folder with links if any
            if (itemType == ItemType.Folder && entry is Folder folder)
            {
                var flinks = _linkManager.GetItems(folder.FullPath);
                if (flinks.Any())
                {
                    //var z = flinks.Where(f => f.IsFile).Skip(1).ToList(); //  Take(15).ToList();
                    foreach (var flink in flinks)
                    {
                        string linkpath = WebDavPath.Combine(folder.FullPath, flink.Name);

                        if (!flink.IsFile)
                        {
                            folder.Folders.Add(new Folder(0, linkpath)
                            {
                                CreationTimeUtc = flink.CreationDate ?? DateTime.MinValue
                            });
                        }
                        else
                        {
                            if (folder.Files.All(inf => inf.FullPath != linkpath))
                            {
                                var newfile = new File(linkpath, flink.Size)
                                {
                                    PublicLink = flink.Href,
                                };
                                if (flink.CreationDate != null)
                                {
                                    newfile.LastWriteTimeUtc = flink.CreationDate.Value;
                                }
                                folder.Files.Add(newfile);
                            }
                        }
                    }
                }
            }

            _itemCache.Add(entry.FullPath, entry);
            if (entry is Folder cfolder)
            {
                _itemCache.Add(cfolder.Files.Select(f => new KeyValuePair <string, IEntry>(f.FullPath, f)));
            }
            return(entry);
        }