Пример #1
0
        public IEnumerable <string> Keys(CacheProfile cacheProfile, string keyPrefix)
        {
            ArgumentValidation.NotNull(cacheProfile, "cacheProfile");
            var ret = Contents(cacheProfile, keyPrefix).Select(key => key.Split(new[] { CacheConstants.CacheItemKeyDelimiter }, StringSplitOptions.RemoveEmptyEntries)[1]);

            return(ret);
        }
Пример #2
0
        public static string ResolvePath(string relativePath)
        {
            ArgumentValidation.NotNull(relativePath);

            if (relativePath.StartsWith("$reproot"))
            {
                var hgRoot = FindParentDirectoryContainingDirectory(AppDomain.CurrentDomain.BaseDirectory, ".hg");

                if (hgRoot == null)
                {
                    throw new ErrorditeRepositoryRootNotFoundException(AppDomain.CurrentDomain.BaseDirectory);
                }

                relativePath = Path.Combine(hgRoot.FullName, relativePath.Replace(@"$reproot\", ""));

                return(relativePath);
            }

            if (Path.IsPathRooted(relativePath))
            {
                return(relativePath);
            }

            return(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath));
        }
Пример #3
0
        /// <summary>
        /// Removes an item from the cache
        /// </summary>
        /// <param name="key"></param>
        public void Remove(CacheKey key)
        {
            ArgumentValidation.NotNull(key, "key");
            var itemKey = CreateKey(key.Profile.ProfileName, key.Key);

            GetMemoryCache(key.Profile).Remove(itemKey);
        }
Пример #4
0
        public void Clear(CacheProfile cacheProfile, string keyPrefix = null)
        {
            ArgumentValidation.NotNull(cacheProfile, "cacheProfile");

            var cache = GetMemoryCache(cacheProfile);

            foreach (var key in Contents(cacheProfile, keyPrefix))
            {
                cache.Remove(key);
            }
        }
Пример #5
0
        /// <summary>
        /// Adds or replaces an item in the cache
        /// </summary>
        /// <param name="cacheItemInfo"></param>
        public void Put(CacheItemInfo cacheItemInfo)
        {
            ArgumentValidation.NotNull(cacheItemInfo, "entry");

            var itemKey = CreateKey(cacheItemInfo.Key.Profile.ProfileName, cacheItemInfo.Key.Key);
            var timeout = cacheItemInfo.Key.Profile.GetTimeout();
            var expiry  = timeout.HasValue ? DateTime.Now + timeout.Value : Cache.NoAbsoluteExpiration;

            GetMemoryCache(cacheItemInfo.Key.Profile).Set(
                itemKey,
                cacheItemInfo.Item,
                expiry);
        }
Пример #6
0
        /// <summary>
        /// Executes the specified action on a thread associated with object's dispatcher.
        /// This invokes a InvokeAsync on the Dispatcher, does not wait for the action
        /// to complete -- returns immediately.
        /// </summary>
        /// <param name="action">An action to execute.</param>
        /// <returns>A task that completes when action has completed.</returns>
        public async Task CheckAccessInvokeAsync(Action action)
        {
            ArgumentValidation.NotNull(action, "action");

            if (this.CheckAccess())
            {
                action();
            }
            else
            {
                await Dispatcher.InvokeAsync(action, DispatcherPriority.Normal);
            }
        }
Пример #7
0
        /// <summary>
        /// Executes the specified action on a thread associated with object's dispatcher.
        /// </summary>
        /// <param name="action">An action to execute.</param>
        public void CheckAccessInvoke(Action action)
        {
            ArgumentValidation.NotNull(action, "action");

            if (this.CheckAccess())
            {
                action();
            }
            else
            {
                Dispatcher.Invoke(action, DispatcherPriority.Normal);
            }
        }
Пример #8
0
        /// <summary>
        /// Executes the specified function on a thread associated with object's dispatcher.
        /// This invokes a InvokeAsync on the Dispatcher, does not wait for the action
        /// to complete -- returns immediately.
        /// </summary>
        /// <param name="func">The function to execute.</param>
        /// <returns>A task with the result of func when completed.</returns>
        public async Task <TResult> CheckAccessInvokeAsync <TResult>(Func <TResult> func)
        {
            ArgumentValidation.NotNull(func, "action");

            if (this.CheckAccess())
            {
                return(func());
            }
            else
            {
                return(await Dispatcher.InvokeAsync(func, DispatcherPriority.Normal));
            }
        }
Пример #9
0
        /// <summary>
        /// Removes an item from the cache
        /// </summary>
        /// <param name="key"></param>
        public void Remove(CacheKey key)
        {
            ArgumentValidation.NotNull(key, "key");

            if (!_session.EnsureConnectionIsOpen())
            {
                return;
            }

            var task = _session.Connection.Keys.Remove(key.Profile.CacheId, key.Key.ToLowerInvariant());

            _session.Connection.Wait(task);
        }
Пример #10
0
        /// <summary>
        /// Gets an item from the cache
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="entry"></param>
        /// <returns>false if the item was not found in the cache otherwise true</returns>
        public bool Get <T>(CacheKey key, out T entry)
        {
            ArgumentValidation.NotNull(key, "key");

            var itemKey = CreateKey(key.Profile.ProfileName, key.Key);
            var item    = GetMemoryCache(key.Profile)[itemKey];

            if (item == null)
            {
                entry = default(T);
                return(false);
            }

            entry = (T)item;
            return(true);
        }
Пример #11
0
        /// <summary>
        /// Gets an item from the cache
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="entry"></param>
        /// <returns>false if the item was not found in the cache otherwise true</returns>
        public bool Get <T>(CacheKey key, out T entry)
        {
            ArgumentValidation.NotNull(key, "key");

            if (!_session.EnsureConnectionIsOpen())
            {
                entry = default(T);
                return(false);
            }

            var task   = _session.Connection.Strings.Get(key.Profile.CacheId, key.Key.ToLowerInvariant());
            var result = _session.Connection.Wait(task);

            //GT: not 100% sure this is correct but added in the result.Length > 0 condition as without it were seeing
            //deserialising to all-null-property instances of T, which should not have been the case
            //In fact fairly sure this is wrong - just shouldn't have been caching this in the first place.. Trello added
            entry = (result != null && result.Length > 0) ? SerializationHelper.ProtobufDeserialize <T>(result) : default(T);
            return(result != null && result.Length > 0);
        }
Пример #12
0
        /// <summary>
        /// Adds or replaces an item in the cache
        /// </summary>
        /// <param name="cacheItemInfo"></param>
        public void Put(CacheItemInfo cacheItemInfo)
        {
            ArgumentValidation.NotNull(cacheItemInfo, "entry");

            if (!_session.EnsureConnectionIsOpen())
            {
                return;
            }

            try
            {
                var itemKey = cacheItemInfo.Key.Key.ToLowerInvariant();
                var timeout = cacheItemInfo.Key.Profile.GetTimeout();

                Task task;
                if (timeout.HasValue)
                {
                    task = _session.Connection.Strings.Set(cacheItemInfo.Key.Profile.CacheId,
                                                           itemKey,
                                                           SerializationHelper.ProtobufSerialize(cacheItemInfo.Item),
                                                           (long)timeout.Value.TotalSeconds);
                }
                else
                {
                    task = _session.Connection.Strings.Set(cacheItemInfo.Key.Profile.CacheId,
                                                           cacheItemInfo.Key.Key.ToLowerInvariant(),
                                                           SerializationHelper.ProtobufSerialize(cacheItemInfo.Item));
                }

                _session.Connection.Wait(task);
            }
            catch (SerializationException e)
            {
                throw new ErrorditeCacheException(
                          "Failed to serialize type:={0}, profile:={1}, key:={2}".FormatWith(cacheItemInfo.Item.GetType(), cacheItemInfo.Key.Profile.ProfileName, cacheItemInfo.Key.Key),
                          false,
                          e);
            }
        }
Пример #13
0
        private void MaybeSendGroupEmailNotification(SendNotificationRequest request)
        {
            if (request.Groups.Count == 0 && request.Users.Count == 0)
            {
                return;
            }

            ArgumentValidation.NotNull(request.OrganisationId, "request.OrganisationId");

            var allUsers = _getUsersQuery.Invoke(new GetUsersRequest
            {
                OrganisationId = request.OrganisationId,
                Paging         = new PageRequestWithSort(1, _configuration.MaxPageSize)
            }).Users;

            var usersToSendTo = (from userId in request.Users
                                 join userFromDb in allUsers.Items on userId equals userFromDb.Id
                                 select userFromDb)
                                .Union(
                from userFromDb2 in allUsers.Items
                from userGroup in userFromDb2.GroupIds
                join groupId in request.Groups on userGroup equals groupId
                select userFromDb2).Distinct().ToList();

            if (usersToSendTo.Count == 0)
            {
                return;
            }

            request.EmailInfo.To = usersToSendTo.Aggregate(string.Empty, (current, u) => current + (u.Email + ';')).TrimEnd(';');

            Session.AddCommitAction(new SendMessageCommitAction(request.EmailInfo,
                                                                _configuration.GetNotificationsQueueAddress(request.Organisation == null ?
                                                                                                            "1" :
                                                                                                            request.Organisation.RavenInstance.FriendlyId)));
        }
Пример #14
0
        public static System.Configuration.Configuration LoadConfiguration(ITypeDescriptorContext context)
        {
            ArgumentValidation.NotNull("context", context);
            IVsHierarchy hier     = VsHelper.GetCurrentHierarchy(context);
            Project      proj     = VsHelper.ToDteProject(hier);
            string       filename = proj.FileName;
            string       fullname = proj.FullName;
            ////EnvDTE.Project proj = GetProject(soln, "Test");
            //EnvDTE.Configuration config = proj.ConfigurationManager.ActiveConfiguration;
            //EnvDTE.Properties props = config.Properties;
            ////VSLangProj.VSProject vsPrj = (VSLangProj.VSProject)proj.Object;

            //proj.

            //this.textBox1.Clear();
            //this.textBox1.AppendText(string.Format("Filename: {0}{1}", filename, Environment.NewLine));
            //this.textBox1.AppendText(string.Format("Fullname: {0}{1}", fullname, Environment.NewLine));
            string webConfigPath = null;

            foreach (var item in proj.ProjectItems)
            {
                var pItem = ((ProjectItem)item);
                //this.textBox1.AppendText(string.Format("\t{0}:{1}", pItem.Name, Environment.NewLine));
                if (pItem.Name == "Web.config" /* || pItem.Name == "App.config"*/)
                {
                    for (short i = 0; i < pItem.FileCount; i++)
                    {
                        var ifilename = pItem.FileNames[i];
                        //this.textBox1.AppendText(string.Format("\t\t{0}{1}", ifilename, Environment.NewLine));
                        webConfigPath = ifilename;
                        break;
                    }
                }
                if (webConfigPath != null)
                {
                    break;
                }
            }

            try
            {
                if (webConfigPath != null)
                {
                    string root = webConfigPath.Substring(0, webConfigPath.LastIndexOf(Path.DirectorySeparatorChar));
                    WebConfigurationFileMap fileMap = CreateFileMap(root);
                    var config = System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/web.config");
                    return(config);
                }
                else
                {
                    MessageBox.Show("Web Config Not Found!");
                    return(null);
                }
            }
            catch (System.Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0}{1}", ex.Message, Environment.NewLine);
                sb.AppendFormat("{0}{1}", ex.StackTrace, Environment.NewLine);
                MessageBox.Show(sb.ToString(), ex.GetType().FullName);
                return(null);
            }
            throw new NotImplementedException();
        }
Пример #15
0
        public static void LoadConfiguration(this IConfiguration target, ConfigurationRequest request)
        {
            ArgumentValidation.NotNull("configuration", target);
            ArgumentValidation.NotNull("request", request);
            IVsHierarchy hier          = VsHelper.GetCurrentHierarchy(request.ServiceProvider);
            Project      proj          = VsHelper.ToDteProject(hier);
            string       filename      = proj.FileName;
            string       fullname      = proj.FullName;
            string       webConfigPath = null;

            foreach (var item in proj.ProjectItems)
            {
                var pItem = ((ProjectItem)item);
                if (pItem.Name == "Web.config" /* || pItem.Name == "App.config"*/)
                {
                    for (short i = 0; i < pItem.FileCount; i++)
                    {
                        var ifilename = pItem.FileNames[i];
                        webConfigPath = ifilename;
                        break;
                    }
                }
                if (webConfigPath != null)
                {
                    break;
                }
            }

            try
            {
                if (webConfigPath != null)
                {
                    string root = webConfigPath.Substring(0, webConfigPath.LastIndexOf(Path.DirectorySeparatorChar));
                    WebConfigurationFileMap fileMap = CreateFileMap(root);
                    var config = System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/web.config");

                    if ((target.Dependencies & ConfigurationDependency.ConnectionString) == ConfigurationDependency.ConnectionString)
                    {
                        var connectionString = config.ConnectionStrings.ConnectionStrings[request.ConnectionStringName];
                        if (connectionString != null)
                        {
                            target.ConnectionString = connectionString.ConnectionString;
                        }
                        else
                        {
                            MessageBox.Show($"Connection String not found {request.ConnectionStringName}");
                        }
                    }

                    if ((target.Dependencies & ConfigurationDependency.StyleSheets) == ConfigurationDependency.StyleSheets)
                    {
                        var section = (Configuration.WebSection)config.GetSection("webpx/web");
                        target.StyleSheets = WebResourceManagement.GetStyleSheets(section);
                    }
                }
                else
                {
                    MessageBox.Show("Web Config Not Found!");
                }
            }
            catch (System.Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0}{1}", ex.Message, Environment.NewLine);
                sb.AppendFormat("{0}{1}", ex.StackTrace, Environment.NewLine);
                MessageBox.Show(sb.ToString(), ex.GetType().FullName);
            }
        }