コード例 #1
0
        public static StringProxy GetStringValue(this IValueProvider valueProvider, IResourceContext context,
                                                 bool setKey)
        {
            var proxy = new StringProxy();
            var value = valueProvider.ProvideValue(context);

            if (value is BindingBase binding)
            {
                BindingOperations.SetBinding(proxy, StringProxy.ValueProperty, binding);
                if (setKey)
                {
                    BindingOperations.SetBinding(proxy, StringProxy.KeyProperty, binding);
                }
            }
            else
            {
                proxy.Value = value?.ToString();
                if (setKey)
                {
                    proxy.Key = value;
                }
            }

            return(proxy);
        }
コード例 #2
0
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            Guid parentRequestId;
            var  parentRequestKey = context.Parameters.GetValueOrDefault(ParentRequestKey);

#if NET35
            if (!Glimpse.Core.Backport.Net35Backport.TryParseGuid(parentRequestKey, out parentRequestId))
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not parse ParentRequestKey '{0}' as GUID.", parentRequestKey)));
            }
#else
            if (!Guid.TryParse(parentRequestKey, out parentRequestId))
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not parse ParentRequestKey '{0}' as GUID.", parentRequestKey)));
            }
#endif

            var data = context.PersistenceStore.GetByRequestParentId(parentRequestId);

            if (data == null)
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not find requests with ParentRequestKey '{0}'.", parentRequestKey)));
            }

            return(new CacheControlDecorator(0, CacheSetting.NoCache, new JsonResourceResult(data.Where(r => r.RequestIsAjax), context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name))));
        }
コード例 #3
0
        public override Texture2D Process(Bitmap bitmap, IResourceContext context)
        {
            BitmapData       data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, Format);
            IGraphicsContext gc   = context.Locator.GetService <IGraphicsContext>();


            int id = gc.GenTexture();

            gc.BindTexture(TextureTarget.Texture2D, id);

            gc.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, false,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

            bitmap.UnlockBits(data);

            //gc.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);


            bitmap.Dispose();

            Console.WriteLine(GC.GetTotalMemory(true));

            return(new Texture2D(gc, id, data.Width, data.Height));
        }
コード例 #4
0
ファイル: RequestResource.cs プロジェクト: zanhaipeng/Glimpse
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            Guid requestId;
            var  request = context.Parameters.GetValueOrDefault(ResourceParameter.RequestId.Name);

#if NET35
            if (!Glimpse.Core.Backport.Net35Backport.TryParseGuid(request, out requestId))
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not parse RequestId '{0} as GUID.'", request)));
            }
#else
            if (!Guid.TryParse(request, out requestId))
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not parse RequestId '{0} as GUID.'", request)));
            }
#endif

            var data = context.PersistenceStore.GetByRequestId(requestId);

            if (data == null)
            {
                return(new StatusCodeResourceResult(404, string.Format("No data found for RequestId '{0}'.", request)));
            }

            return(new CacheControlDecorator(CacheDuration, CacheSetting.Private, new JsonResourceResult(data, context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name))));
        }
コード例 #5
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configuration">The configuration.</param>
        /// <returns>
        /// A <see cref="IResourceResult" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if either <paramref name="context"/> or <paramref name="configuration"/> are <c>null</c>.</exception>
        /// <remarks>
        /// Use of <see cref="IPrivilegedResource" /> is reserved.
        /// </remarks>
        public IResourceResult Execute(IResourceContext context, IGlimpseConfiguration configuration)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

            Guid requestId;
            var  request = context.Parameters.GetValueOrDefault(ResourceParameter.RequestId.Name);

#if NET35
            if (!Glimpse.Core.Backport.Net35Backport.TryParseGuid(request, out requestId))
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not parse RequestId of '{0}' as GUID.", request)));
            }
#else
            if (!Guid.TryParse(request, out requestId))
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not parse RequestId of '{0}' as GUID.", request)));
            }
#endif

            var requestStore       = configuration.FrameworkProvider.HttpRequestStore;
            var generateScriptTags = requestStore.Get <Func <Guid?, string> >(Constants.ClientScriptsStrategy);

            var scriptTags = generateScriptTags(requestId);
            var html       = string.Format("<!DOCTYPE html><html><head><meta charset='utf-8'><title>Glimpse Popup</title></head><body class='glimpse-popup'>{0}</body></html>", scriptTags);

            return(new HtmlResourceResult(html));
        }
コード例 #6
0
        public IResourceResult Execute(IResourceContext context)
        {
            var p = context.Parameters;

            string featureName;
            if (!p.TryGetValue("featurename", out featureName))
            {
                throw new ArgumentException("Missing name of the feature");
            }

            string value;
            if (!p.TryGetValue("val", out value))
            {
                throw new ArgumentException("Missing new value for the feature");
            }

            if (string.IsNullOrEmpty(featureName) || string.IsNullOrEmpty(value))
            {
                return GenerateResponse();
            }

            var newValue = Boolean.Parse(value);
            if (newValue)
            {
                FeatureContext.Enable(featureName);
            }
            else
            {
                FeatureContext.Disable(featureName);
            }

            return GenerateResponse();
        }
コード例 #7
0
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        public IResourceResult Execute(IResourceContext context)
        {
            var packages = NuGetPackage.GetRegisteredPackageVersions();

            var stamp    = context.Parameters.GetValueOrDefault(ResourceParameter.Timestamp.Name);
            var callback = context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name);

            var data = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(stamp))
            {
                data.Add("stamp", stamp);
            }

            if (!string.IsNullOrEmpty(callback))
            {
                data.Add("callback", callback);
            }

            if (packages.Count > 0)
            {
                data.Add("packages", packages);
            }

            var domain = ConfigurationManager.AppSettings["GlimpseVersionCheckAPIDomain"];

            if (string.IsNullOrEmpty(domain))
            {
                domain = "getGlimpse.com";
            }

            return(new CacheControlDecorator(OneDay, CacheSetting.Public, new RedirectResourceResult(@"//" + domain + "/Api/Version/Check{?packages*}{&stamp}{&callback}", data)));
        }
コード例 #8
0
        public DynamicForm()
        {
            IsTabStop            = false;
            ResourceContext      = new FormResourceContext(this);
            columns              = new double[0];
            currentElements      = new List <FrameworkElement>();
            DataFields           = new Dictionary <string, DataFormField>();
            DataBindingProviders = new Dictionary <string, IDataBindingProvider>();
            BindingOperations.SetBinding(this, ContextProperty, new Binding
            {
                Source = this,
                Path   = new PropertyPath(DataContextProperty),
                Mode   = BindingMode.OneWay
            });

            Loaded += (s, e) =>
            {
                ActiveForms.Add(this);
            };

            Unloaded += (s, e) =>
            {
                ActiveForms.Remove(this);
            };
        }
コード例 #9
0
 protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
 {
     return(new EmbeddedResourceInfo(
                this.GetType().Assembly,
                "Glimpse.TelerikDataAccess.Plugin.Resource.dataaccess.js",
                "application/x-javascript"));
 }
コード例 #10
0
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Throws an exception if <paramref name="context "/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var assembly = GetResourcesAssembly();

            if (assembly == null)
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not locate assembly for resource with ResourceName '{0}'.", ResourceName)));
            }

            using (var resourceStream = assembly.GetManifestResourceStream(ResourceName))
            {
                if (resourceStream != null)
                {
                    var content = new byte[resourceStream.Length];
                    resourceStream.Read(content, 0, content.Length);

                    return(new CacheControlDecorator(CacheDuration, CacheSetting.Public, new FileResourceResult(content, ResourceType)));
                }
            }

            return(new StatusCodeResourceResult(404, string.Format("Could not locate file with ResourceName '{0}'.", ResourceName)));
        }
コード例 #11
0
        public void ApplyChange(IResourceContext resource, ChangeEventArgs ev)
        {
            var book   = resource.RequireValue <Book>();
            var revert = new Dictionary <string, object>(ev.ChangedProperties.Count);

            if (ev.ChangedProperties.TryGetValue("title", out object titleObject))
            {
                string title = (string)titleObject;
                if (title == "")
                {
                    throw new ResException("Title must not be empty.");
                }
                if (title != book.Title)
                {
                    revert["title"] = book.Title;
                    book.Title      = title;
                }
            }

            if (ev.ChangedProperties.TryGetValue("author", out object authorObject))
            {
                string author = (string)authorObject;
                if (author == "")
                {
                    throw new ResException("Author must not be empty.");
                }
                if (author != book.Author)
                {
                    revert["author"] = book.Author;
                    book.Author      = author;
                }
            }

            ev.SetRevert(revert);
        }
コード例 #12
0
        protected internal override IBindingProvider CreateBindingProvider(IResourceContext context,
                                                                           IDictionary <string, IValueProvider> formResources)
        {
            var datePresenter = new DatePresenter(context, Resources, formResources);

            return(datePresenter);
        }
コード例 #13
0
 protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
 {
     return(new EmbeddedResourceInfo(
                this.GetType().Assembly,
                "Glimpse.Test.Core.Resource.FileResourceTester.js",
                "application/x-javascript"));
 }
コード例 #14
0
        public BindingBase ProvideBinding(IResourceContext context)
        {
            if (Resources == null || Resources.Count == 0)
            {
                return(new LiteralValue(StringFormat).ProvideBinding(context));
            }

            if (Resources.Count == 1)
            {
                var resource = Resources[0];
                var binding  = resource.ProvideBinding(context);
                if (StringFormat != null)
                {
                    binding.StringFormat = StringFormat;
                }

                return(binding);
            }

            var multiBinding = new MultiBinding
            {
                StringFormat = StringFormat
            };

            foreach (var binding in Resources.Select(resource => resource.ProvideBinding(context)))
            {
                multiBinding.Bindings.Add(binding);
            }

            return(multiBinding);
        }
コード例 #15
0
 protected internal override IBindingProvider CreateBindingProvider(IResourceContext context,
                                                                    IDictionary <string, IValueProvider> formResources)
 {
     return(!IsPassword
         ? (IBindingProvider) new StringPresenter(context, Resources, formResources)
         : new PasswordPresenter(context, Resources, formResources));
 }
コード例 #16
0
ファイル: FileResource.cs プロジェクト: zanhaipeng/Glimpse
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Throws an exception if <paramref name="context "/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var embeddedResourceInfo = this.GetEmbeddedResourceInfo(context);

            if (embeddedResourceInfo == null)
            {
                return(new StatusCodeResourceResult(404, string.Format("Could not get embedded resource information.")));
            }

            using (var resourceStream = embeddedResourceInfo.Assembly.GetManifestResourceStream(embeddedResourceInfo.Name))
            {
                if (resourceStream != null)
                {
                    var content = new byte[resourceStream.Length];
                    resourceStream.Read(content, 0, content.Length);

                    return(new CacheControlDecorator(CacheDuration, CacheSetting.Public, new FileResourceResult(content, embeddedResourceInfo.ContentType)));
                }
            }

            return(new StatusCodeResourceResult(404, string.Format("Could not locate embedded resource with name '{0}' inside assembly '{1}'.", embeddedResourceInfo.Name, embeddedResourceInfo.Assembly.FullName)));
        }
コード例 #17
0
 internal CompiledRegexReplacement Compile(IResourceContext context)
 {
     return(new CompiledRegexReplacement(
                Pattern.GetStringValue(context),
                Replacement.GetStringValue(context),
                Replacement.GetValue(context)));
 }
コード例 #18
0
ファイル: AjaxResource.cs プロジェクト: shiftkey/Glimpse
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            Guid parentRequestId;
            var parentRequestKey = context.Parameters.GetValueOrDefault(ParentRequestKey);

            #if NET35
            if (!Glimpse.Core.Backport.Net35Backport.TryParseGuid(parentRequestKey, out parentRequestId))
            {
                return new StatusCodeResourceResult(404, string.Format("Could not parse ParentRequestKey '{0}' as GUID.", parentRequestKey));
            }
            #else
            if (!Guid.TryParse(parentRequestKey, out parentRequestId))
            {
                return new StatusCodeResourceResult(404, string.Format("Could not parse ParentRequestKey '{0}' as GUID.", parentRequestKey));
            }
            #endif

            var data = context.PersistenceStore.GetByRequestParentId(parentRequestId);

            if (data == null)
            {
                return new StatusCodeResourceResult(404, string.Format("Could not find requests with ParentRequestKey '{0}'.", parentRequestKey));
            }

            return new JsonResourceResult(data.Where(r => r.RequestIsAjax), context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name));
        }
コード例 #19
0
        public void AccessProtectedResource(IResourceContext context)
        {
            IEnumerable <ContextProcessor <IResourceContext> > processors = ServiceLocator.Current.GetAllInstances <ContextProcessor <IResourceContext> >();

            bool handled = false;

            foreach (ContextProcessor <IResourceContext> processor in processors)
            {
                if (!processor.IsSatisfiedBy(context))
                {
                    continue;
                }
                processor.Process(context);
                handled = true;
                break;
            }

            if (!handled)
            {
                Log.Info(m => m("Failed to find a processor for the context: {0}", context.ToString()));
                throw new OAuthFatalException(ResourceEndpointResources.UnsupportedTokenType);
            }
            if (context.Token == null)
            {
                throw Errors.InvalidToken(context);
            }

            if (context.Token.ExpiresIn > 0 && (SharpOAuth2.Provider.Utility.Epoch.FromEpoch(((IAccessToken)context.Token).IssuedOn).AddSeconds(context.Token.ExpiresIn) < DateTime.Now))
            {
                throw Errors.InvalidToken(context);
            }
        }
コード例 #20
0
        public ActionElementCommand(IResourceContext context, IValueProvider action, IValueProvider actionParameter, IValueProvider isEnabled, IValueProvider validates, IValueProvider closesDialog, IValueProvider isReset)
        {
            this.context = context;
            this.action  = action?.GetBestMatchingProxy(context) ?? new PlainObject(null);

            switch (isEnabled)
            {
            case LiteralValue v when v.Value is bool b:
                canExecute = new PlainBool(b);
                break;

            case null:
                canExecute = new PlainBool(true);
                break;

            default:
                var proxy = isEnabled.GetBoolValue(context);
                proxy.ValueChanged = () => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
                canExecute         = proxy;
                break;
            }

            this.validates       = validates != null ? (IBoolProxy)validates.GetBoolValue(context) : new PlainBool(false);
            this.closesDialog    = closesDialog != null ? (IBoolProxy)closesDialog.GetBoolValue(context) : new PlainBool(true);
            resets               = isReset != null ? (IBoolProxy)isReset.GetBoolValue(context) : new PlainBool(false);
            this.actionParameter = actionParameter?.GetBestMatchingProxy(context) ?? new PlainObject(null);
        }
コード例 #21
0
ファイル: PopupResource.cs プロジェクト: GProulx/Glimpse
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configuration">The configuration.</param>
        /// <returns>
        /// A <see cref="IResourceResult" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if either <paramref name="context"/> or <paramref name="configuration"/> are <c>null</c>.</exception>
        /// <remarks>
        /// Use of <see cref="IPrivilegedResource" /> is reserved.
        /// </remarks>
        public IResourceResult Execute(IResourceContext context, IGlimpseConfiguration configuration)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

            Guid requestId;
            var request = context.Parameters.GetValueOrDefault(ResourceParameter.RequestId.Name);

#if NET35
            if (!Glimpse.Core.Backport.Net35Backport.TryParseGuid(request, out requestId))
            {
                return new StatusCodeResourceResult(404, string.Format("Could not parse RequestId of '{0}' as GUID.", request));
            }
#else
            if (!Guid.TryParse(request, out requestId))
            {
                return new StatusCodeResourceResult(404, string.Format("Could not parse RequestId of '{0}' as GUID.", request));
            }
#endif

            var requestStore = configuration.FrameworkProvider.HttpRequestStore;
            var generateScriptTags = requestStore.Get<Func<Guid?, string>>(Constants.ClientScriptsStrategy);

            var scriptTags = generateScriptTags(requestId); 
            var html = string.Format("<!DOCTYPE html><html><head><meta charset='utf-8'><title>Glimpse Popup</title></head><body class='glimpse-popup'>{0}</body></html>", scriptTags);

            return new HtmlResourceResult(html);
        }
コード例 #22
0
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        public IResourceResult Execute(IResourceContext context)
        {
            var packages = NuGetPackage.GetRegisteredPackageVersions();

            var stamp = context.Parameters.GetValueOrDefault(ResourceParameter.Timestamp.Name);
            var callback = context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name);

            var data = new Dictionary<string, object>();

            if (!string.IsNullOrEmpty(stamp))
            {
                data.Add("stamp", stamp);
            }

            if (!string.IsNullOrEmpty(callback))
            {
                data.Add("callback", callback);
            }

            if (packages.Count > 0)
            {
                data.Add("packages", packages);
            }

            var domain = ConfigurationManager.AppSettings["GlimpseVersionCheckAPIDomain"];
            
            if (string.IsNullOrEmpty(domain))
            {
                domain = "getGlimpse.com";
            }

            return new CacheControlDecorator(OneDay, CacheSetting.Public, new RedirectResourceResult(@"//" + domain + "/Api/Version/Check{?packages*}{&stamp}{&callback}", data));
        }
コード例 #23
0
        public BindingBase ProvideBinding(IResourceContext context)
        {
            var binding = context.CreateModelBinding(PropertyPath);

            if (OneWay)
            {
                binding.Mode = BindingMode.OneWay;
            }

            BindingOptions.Apply(binding);
            var deserializer = ReplacementPipe.CreateDeserializer(context);

            binding.Converter = new StringTypeConverter(deserializer);
            binding.ValidationRules.Add(new ConversionValidator(deserializer, ConversionErrorStringProvider(context),
                                                                binding.ConverterCulture));
            var pipe = new ValidationPipe();

            foreach (var validatorProvider in ValidationRules)
            {
                binding.ValidationRules.Add(validatorProvider.GetValidator(context, pipe));
            }

            binding.ValidationRules.Add(pipe);
            return(binding);
        }
コード例 #24
0
        protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
        {
            var sub = context.Parameters.ContainsKey("sub") ? context.Parameters["sub"] : "help";

            if ("store".Equals(sub) && context.Parameters.ContainsKey("name"))
            {
                var data       = context.PersistenceStore.GetByRequestIdAndTabKey(Guid.Parse(context.Parameters["requestId"]), "glimpse_dataaccess");
                var serializer = new JsonNetSerializer(context.Logger);
                var jsonData   = serializer.Serialize(data);
                File.WriteAllText(context.Parameters["name"], jsonData, Encoding.UTF8);

                return(new EmbeddedResourceInfo(
                           this.GetType().Assembly,
                           "Glimpse.TelerikDataAccess.Plugin.Resource.store.html",
                           "text/html"));
            }
            if ("glimpse1.png".Equals(sub))
            {
                return(new EmbeddedResourceInfo(
                           this.GetType().Assembly,
                           "Glimpse.TelerikDataAccess.Plugin.Resource.glimpse1.png",
                           "text/html"));
            }
            if ("glimpse2.png".Equals(sub))
            {
                return(new EmbeddedResourceInfo(
                           this.GetType().Assembly,
                           "Glimpse.TelerikDataAccess.Plugin.Resource.glimpse2.png",
                           "text/html"));
            }
            return(new EmbeddedResourceInfo(
                       this.GetType().Assembly,
                       "Glimpse.TelerikDataAccess.Plugin.Resource.help.html",
                       "text/html"));
        }
コード例 #25
0
ファイル: FileResource.cs プロジェクト: GProulx/Glimpse
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Throws an exception if <paramref name="context "/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var embeddedResourceInfo = this.GetEmbeddedResourceInfo(context);
            if (embeddedResourceInfo == null)
            {
                return new StatusCodeResourceResult(404, string.Format("Could not get embedded resource information."));
            }

            using (var resourceStream = embeddedResourceInfo.Assembly.GetManifestResourceStream(embeddedResourceInfo.Name))
            {
                if (resourceStream != null)
                {
                    var content = new byte[resourceStream.Length];
                    resourceStream.Read(content, 0, content.Length);

                    return new CacheControlDecorator(CacheDuration, CacheSetting.Public, new FileResourceResult(content, embeddedResourceInfo.ContentType));
                }
            }

            return new StatusCodeResourceResult(404, string.Format("Could not locate embedded resource with name '{0}' inside assembly '{1}'.", embeddedResourceInfo.Name, embeddedResourceInfo.Assembly.FullName));
        }
コード例 #26
0
        public object CreateInstance(IResourceContext context)
        {
            if (ModelType != null)
            {
                return(Activator.CreateInstance(ModelType));
            }

            if (!frozen)
            {
                throw new InvalidOperationException("Cannot create dynamic models without freezing this object.");
            }

            var expando = new ExpandoObject();
            IDictionary <string, object> dictionary = expando;

            foreach (var field in FormRows
                     .SelectMany(row => row.Elements
                                 .SelectMany(c => c.Elements)))
            {
                if (field is DataFormField dataField && dataField.Key != null && !dataField.IsDirectBinding)
                {
                    dictionary[dataField.Key] = dataField.GetDefaultValue(context);
                }
            }

            return(expando);
        }
コード例 #27
0
        public BindingBase ProvideBinding(IResourceContext context)
        {
            var binding = innerProvider.ProvideBinding(context);

            binding.FallbackValue = defaultValue;
            return(binding);
        }
コード例 #28
0
        private Texture2D LoadTexture(string fileName, IResourceContext context)
        {
            string path = Path.Combine(Path.GetDirectoryName(this.ResourcePath), fileName);

            return(context.LoadAsset <Texture2D>(path, processor: new TextureProcessor(System.Drawing.Imaging.PixelFormat.Format32bppPArgb,
                                                                                       OpenTK.Graphics.OpenGL.PixelInternalFormat.CompressedRedRgtc1)));
        }
コード例 #29
0
ファイル: QueryRequest.cs プロジェクト: boekfors/csharp-res
 public QueryRequest(IResourceContext resource, Msg msg)
     : base(resource)
 {
     this.msg = msg;
     Replied  = false;
     Events   = new List <EventDto>();
 }
コード例 #30
0
        public override Font Process(FontFile input, IResourceContext context)
        {
            if (input.Pages.Count > 1)
            {
                throw new ArgumentException("The font system can only handle fonts that are in a single page!" +
                                            string.Format(" The file {0} contains {1} pages!", this.ResourcePath, input.Pages.Count));
            }

            string face    = input.Info.Face + "-" + input.Info.Size + "-" + (input.Info.Bold == 1 ? "b" : "") + (input.Info.Italic == 1 ? "i" : "");
            var    texture = LoadTexture(input.Pages[0].File, context);

            int largest = input.Chars.Max((x) => x.ID);

            var charMap = new CharInfo[largest + 1];

            for (int i = 0; i < input.Chars.Count; i++)
            {
                FontChar c = input.Chars[i];


                var info =
                    new CharInfo(texture, new Rect(c.X - 1f, c.Y - 1f, c.Width + 1f, c.Height + 1f),
                                 new Vector2(c.XOffset, c.YOffset),
                                 c.XAdvance);

                charMap[c.ID] = info;
            }


            return(new Font(face, input.Info.Size, input.Common.LineHeight, texture, charMap));
        }
コード例 #31
0
 protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
 {
     return new EmbeddedResourceInfo(
         this.GetType().Assembly, 
         "Glimpse.Test.Core.Resource.FileResourceTester.js", 
         "application/x-javascript");
 }
コード例 #32
0
ファイル: RequestResource.cs プロジェクト: GProulx/Glimpse
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            Guid requestId;
            var request = context.Parameters.GetValueOrDefault(ResourceParameter.RequestId.Name);

#if NET35
            if (!Glimpse.Core.Backport.Net35Backport.TryParseGuid(request, out requestId))
            {
                return new StatusCodeResourceResult(404, string.Format("Could not parse RequestId '{0} as GUID.'", request));
            }
#else
            if (!Guid.TryParse(request, out requestId))
            {
                return new StatusCodeResourceResult(404, string.Format("Could not parse RequestId '{0} as GUID.'", request));
            }
#endif

            var data = context.PersistenceStore.GetByRequestId(requestId);

            if (data == null)
            {
                return new StatusCodeResourceResult(404, string.Format("No data found for RequestId '{0}'.", request));
            }

            return new CacheControlDecorator(CacheDuration, CacheSetting.Private, new JsonResourceResult(data, context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name)));
        }
コード例 #33
0
        public IResourceResult Execute(IResourceContext context)
        {
            var queryValue = int.Parse(context.Parameters.GetValueOrDefault(AlbumIdKey));

            var data = InventoryManager.GetInventory(queryValue);

            return new CacheControlDecorator(0, CacheSetting.NoCache, new JsonResourceResult(data, null)); ;
        }
コード例 #34
0
 public EventContext(object model, IFormDefinition formDefinition, object formDefinitionSource, object context, IResourceContext resourceContext)
 {
     Model                = model;
     FormDefinition       = formDefinition;
     FormDefinitionSource = formDefinitionSource;
     Context              = context;
     ResourceContext      = resourceContext;
 }
コード例 #35
0
 public BindingBase ProvideBinding(IResourceContext context)
 {
     return(new Binding
     {
         Source = ProvideValue(context),
         Mode = BindingMode.OneTime
     });
 }
コード例 #36
0
 /// <summary>
 /// Calls the callback on the resource's worker thread.
 /// </summary>
 /// <param name="resource">Resource context.</param>
 /// <param name="callback">Callback to be called on the resource's worker thread.</param>
 public void With(IResourceContext resource, Action <IResourceContext> callback)
 {
     runWith(resource.Group, () =>
     {
         callback(resource);
         return(completedTask);
     });
 }
コード例 #37
0
        public override BindingBase ProvideBinding(IResourceContext context)
        {
            var binding = context.CreateModelBinding(PropertyPath);

            binding.Converter = GetValueConverter(context);
            binding.Mode      = OneTimeBinding ? BindingMode.OneTime : BindingMode.OneWay;
            return(binding);
        }
コード例 #38
0
        public object ProvideValue(IResourceContext context)
        {
            if (Resources == null || Resources.Count == 0)
            {
                return(UnescapedStringFormat());
            }

            return(ProvideBinding(context));
        }
コード例 #39
0
        public object ProcessContent(string filePath, object content, IResourceContext context, IProcessor processor = null)
        {
            if (processor == null)
                processor = GetDefaultProcessor(content.GetType());

            processor.ResourcePath = filePath;

            return processor.Process(content, context);
        }
コード例 #40
0
        public void Setup()
        {
            var readerFactory = new TypeReaderFactory();
            var writerFactory = new TypeWriterFactory();
            var loader = new ResourceLoader();
            loader.AddImportersAndProcessors(typeof(IImporter).Assembly);

            manager = new ResourceContext(null, readerFactory, writerFactory, loader, Environment.CurrentDirectory + "\\Assets", Environment.CurrentDirectory);
        }
コード例 #41
0
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            var getInvocationsHandler = new GetInvocationsHandler();
            var getInvocationsRequest = new GetInvocationsRequest();
            var getInvocationsResult = getInvocationsHandler.Handle(getInvocationsRequest);
            var data = FormatInvocations(getInvocationsResult.Invocations);
            return new CacheControlDecorator(0, CacheSetting.NoCache, new JsonResourceResult(data, context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name)));
        }
コード例 #42
0
        public IResourceResult Execute(IResourceContext context)
        {
            var queryValue = context.Parameters.GetValueOrDefault(QueryKey);

            using (var connection = SqlMapper.CreateConnection())
            {
                var data = connection.Query(queryValue).ToList();

                return new CacheControlDecorator(0, CacheSetting.NoCache, new JsonResourceResult(data, null));
            } 
        }
コード例 #43
0
ファイル: MetadataResource.cs プロジェクト: shiftkey/Glimpse
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        public IResourceResult Execute(IResourceContext context)
        {
            var metadata = context.PersistenceStore.GetMetadata();

            if (metadata == null)
            {
                return new StatusCodeResourceResult(404, "Metadata not found.");
            }

            return new CacheControlDecorator(CacheDuration, CacheSetting.Public, new JsonResourceResult(metadata, context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name)));
        }
コード例 #44
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configuration">The configuration.</param>
        /// <returns>
        /// A <see cref="IResourceResult" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if either <paramref name="context"/> or <paramref name="configuration"/> are <c>null</c>.</exception>
        /// <remarks>
        /// Use of <see cref="IPrivilegedResource" /> is reserved.
        /// </remarks>
        public IResourceResult Execute(IResourceContext context, IGlimpseConfiguration configuration)
        {
            //TODO: Can't assume this is here 
            var request = context.PersistenceStore.GetTop(1).FirstOrDefault(); 
            if (request == null)
                return new HtmlResourceResult("<html><body><h1>Sorry no requests are currently available</h1>This is a current limitation of this feature. For Glimpse client to work, Glimpse has to detect at least one requesting for which it is enabled.<br /><br />If you are using this feature and it is causing you issues, please let us know.</body></html>");

            var popupResource = configuration.Resources.FirstOrDefault(r => r.Name.Equals("glimpse_popup", StringComparison.InvariantCultureIgnoreCase));
            var popupUriTemplate = configuration.ResourceEndpoint.GenerateUriTemplate(popupResource, configuration.EndpointBaseUri, configuration.Logger);

            return new CacheControlDecorator(0, CacheSetting.NoCache, new RedirectResourceResult(popupUriTemplate, new Dictionary<string, object> { { ResourceParameter.RequestId.Name, request.RequestId.ToString() } }));
        }
コード例 #45
0
        public IResourceResult Execute(IResourceContext context)
        {
            var clientParameter = context.Parameters[ParamIdKey];

            var data = new
                           {
                               A = "A " + clientParameter,
                               B = "B " + clientParameter,
                           };

            return new CacheControlDecorator(0, CacheSetting.NoCache, new JsonResourceResult(data, null)); ;
        }
コード例 #46
0
ファイル: LogosResource.cs プロジェクト: GProulx/Glimpse
        /// <summary>
        /// Returns, based on the resource context, the embedded resource that represents a logo and will be returned during the execution of the <see cref="FileResource"/>
        /// </summary>
        /// <param name="context">The resource context</param>
        /// <returns>Information about the embedded resource that represents a logo</returns>
        protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
        {
            var logoname = context.Parameters.GetValueOrDefault(ResourceParameter.LogoName.Name);

            EmbeddedResourceInfo embeddedResourceInfo;
            if (!string.IsNullOrEmpty(logoname) && embeddedResourceInfos.TryGetValue(logoname, out embeddedResourceInfo))
            {
                return embeddedResourceInfo;
            }

            return null;
        }
コード例 #47
0
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        public IResourceResult Execute(IResourceContext context)
        {
            var packages = new Dictionary<string, string>();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                var nugetPackage = assembly.GetCustomAttributes(typeof(NuGetPackageAttribute), false).Cast<NuGetPackageAttribute>().SingleOrDefault();
                if (nugetPackage == null)
                {
                    continue;
                }

                var version = nugetPackage.GetVersion(assembly);
                var id = nugetPackage.GetId(assembly);

                packages[id] = version;
            }

            var stamp = context.Parameters.GetValueOrDefault(ResourceParameter.Timestamp.Name);
            var callback = context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name);

            var data = new Dictionary<string, object>();

            if (!string.IsNullOrEmpty(stamp))
            {
                data.Add("stamp", stamp);
            }

            if (!string.IsNullOrEmpty(callback))
            {
                data.Add("callback", callback);
            }

            if (packages.Count > 0)
            {
                data.Add("packages", packages);
            }

            var domain = ConfigurationManager.AppSettings["GlimpseVersionCheckAPIDomain"];

            if (string.IsNullOrEmpty(domain))
            {
                domain = "getGlimpse.com";
            }

            return new CacheControlDecorator(OneDay, CacheSetting.Public, new RedirectResourceResult(@"//" + domain + "/Api/Version/Check{?packages*}{&stamp}{&callback}", data));
        }
コード例 #48
0
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        public IResourceResult Execute(IResourceContext context)
        {
            var content = new StringBuilder();
            content.Append("<!DOCTYPE html><html><head><link rel=\"shortcut icon\" href=\"http://getglimpse.com/favicon.ico\" />");
            content.Append("<style>body { margin: 0px; text-align:center; font-family:\"avante garde\", \"Century Gothic\", Serif; font-size:0.8em; line-height:1.4em; } .important { font-size:1.4em; } .content { position:absolute; left:50%; margin-left:-450px; text-align:left; width:900px; } h1, h2, h3, h4 { line-height:1.2em; font-weight:normal; } h1 { font-size:4em; } h2 { font-size:2.5em; } h3 { font-size:2em; } .logo { font-family: \"TitilliumMaps\", helvetica, sans-serif; margin:0 0 40px; position:relative; background: url(http://getglimpse.com/content/glimpseLogo.png?version=" + GlimpseRuntime.Version + ") -10px -15px no-repeat; padding: 0 0 0 140px; } .logo h1 { color:transparent; } .logo div { font-size:1.5em; margin: 25px 0 0 -10px; } .logo blockquote { width:350px; position:absolute; right:0; top:10px; } blockquote { font: 1.2em/1.6em \"avante garde\", \"Century Gothic\", Serif; width: 400px; background: url(http://getglimpse.com/Content/close-quote.gif?version=" + GlimpseRuntime.Version + ") no-repeat right bottom; padding-left: 18px; text-indent: -18px; } .footer { text-align:center; margin-bottom:30px; } blockquote:first-letter { background: url(http://getglimpse.com/Content/open-quote.gif?version=" + GlimpseRuntime.Version + ") no-repeat left top; padding-left: 18px; font: italic 1.4em \"avante garde\", \"Century Gothic\", Serif; } .myButton{width:175px; line-height: 1.2em; margin:0.25em 0; text-align:center; -moz-box-shadow:inset 0 1px 0 0 #fff;-webkit-box-shadow:inset 0 1px 0 0 #fff;box-shadow:inset 0 1px 0 0 #fff;background:-webkit-gradient(linear,left top,left bottom,color-stop(0.05,#ededed),color-stop(1,#dfdfdf));background:-moz-linear-gradient(center top,#ededed 5%,#dfdfdf 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed',endColorstr='#dfdfdf');background-color:#ededed;-moz-border-radius:6px;-webkit-border-radius:6px;border-radius:6px;border:1px solid #dcdcdc;display:inline-block;color:#777;font-family:arial;font-size:24px;padding:10px 41px;text-decoration:none;text-shadow:1px 1px 0 #fff}.myButton:hover{background:-webkit-gradient(linear,left top,left bottom,color-stop(0.05,#dfdfdf),color-stop(1,#ededed));background:-moz-linear-gradient(center top,#dfdfdf 5%,#ededed 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf',endColorstr='#ededed');background-color:#dfdfdf}.myButton:active{position:relative;top:1px}</style>");
            content.Append("<title>Glimpse Config</title>");
            content.Append("<script>function toggleCookie(){var mode = document.getElementById('glimpseState'); if (mode.innerHTML==='On'){mode.innerHTML='Off';document.cookie='glimpsePolicy=Off; path=/;';}else{mode.innerHTML='On';document.cookie='glimpsePolicy=On; path=/;';}}</script>");
            content.Append("<head><body>");
            content.Append("<div class=\"content\"><div class=\"logo\"><blockquote>What Firebug is for the client, Glimpse does for the server... in other words, a client side Glimpse into what's going on in your server.</blockquote><h1>Glimpse</h1><div>A client side Glimpse to your server</div></div>");
            content.Append("<table width=\"100%\"><tr align=\"center\"><td width=\"33%\"><a class=\"myButton\" href=\"javascript:(function(){document.cookie='glimpsePolicy=On; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Turn Glimpse On</a></td><td width=\"34%\"><a class=\"myButton\" href=\"javascript:(function(){document.cookie='glimpsePolicy=; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Turn Glimpse Off</a></td><td><a class=\"myButton\" href=\"javascript:(function(){document.cookie='glimpseId='+ prompt('Client Name?') +'; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Set Glimpse Session Name</a></td></tr></table>");
            content.Append("<p style=\"text-align:center\">Drag the above button to your favorites bar for quick and easy access to Glimpse.</p>");
            content.Append("<h2>More Info:</h2>");
            content.Append("<div class=\"footer\"><span class=\"important\">For more info see <a href=\"http://getGlimpse.com\" />getGlimpse.com</a></span><br /><br /><img src=\"http://getglimpse.com/content/uservoice-icon.png\" width=\"16\" /> Have a <em>feature</em> request? <a href=\"http://getglimpse.uservoice.com\">Submit the idea</a>. &nbsp; &nbsp; <img src=\"http://getglimpse.com/content/github.gif\" /> Found an <em>error</em>? <a href=\"https://github.com/glimpse/glimpse/issues\">Help us improve</a>. &nbsp; &nbsp;<img src=\"http://getglimpse.com/content/twitter.png\" /> Have a <em>question</em>? <a href=\"http://twitter.com/#search?q=%23glimpse\">Tweet us using #glimpse</a>.</div>");
            content.Append("</body></html>");

            return new HtmlResourceResult(content.ToString());
        }
コード例 #49
0
ファイル: HistoryResource.cs プロジェクト: shiftkey/Glimpse
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Exception thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            int top;
            int.TryParse(context.Parameters.GetValueOrDefault(TopKey, ifNotFound: "50"), out top);

            var data = context.PersistenceStore.GetTop(top);

            if (data == null)
            {
                return new StatusCodeResourceResult(404, string.Format("No data found in top {0}.", top));
            }

            var requests = data.GroupBy(d => d.ClientId).ToDictionary(group => group.Key, group => group.Select(g => new GlimpseRequestHeaders(g)));
            return new JsonResourceResult(requests, context.Parameters.GetValueOrDefault(ResourceParameter.Callback.Name));
        }
コード例 #50
0
ファイル: HtmlResource.cs プロジェクト: NLog/Glimpse.NLog
 protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
 {
     return new EmbeddedResourceInfo(this.GetType().Assembly, "Glimpse.NLog.Resource.glimpse.nlog.html", @"text/html");
 }
コード例 #51
0
ファイル: ScriptResource.cs プロジェクト: ericziko/navigation
		protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
		{
			return GlimpseClientEmbeddedResourceInfo;
		}
コード例 #52
0
ファイル: FileResource.cs プロジェクト: GProulx/Glimpse
 /// <summary>
 /// Returns, based on the resource context, the embedded resource that will be returned during the execution of the <see cref="FileResource"/>
 /// </summary>
 /// <param name="context">The resource context</param>
 /// <returns>Information about the embedded resource</returns>
 protected abstract EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context);
コード例 #53
0
ファイル: FileResource.cs プロジェクト: rroman81/Glimpse
        /// <summary>
        /// Executes the specified resource with the specific context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Throws an exception if <paramref name="context "/> is <c>null</c>.</exception>
        public IResourceResult Execute(IResourceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var assembly = GetResourcesAssembly();
            if (assembly == null) {
                return new StatusCodeResourceResult(404, string.Format("Could not locate assembly for resource with ResourceName '{0}'.", ResourceName));
            }

            using (var resourceStream = assembly.GetManifestResourceStream(ResourceName))
            {
                if (resourceStream != null)
                {
                    var content = new byte[resourceStream.Length];
                    resourceStream.Read(content, 0, content.Length);

                    return new CacheControlDecorator(CacheDuration, CacheSetting.Public, new FileResourceResult(content, ResourceType));
                }
            }

            return new StatusCodeResourceResult(404, string.Format("Could not locate file with ResourceName '{0}'.", ResourceName));
        }
コード例 #54
0
ファイル: SpriteResource.cs プロジェクト: GitObjects/Glimpse
 protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
 {
     return new EmbeddedResourceInfo(this.GetType().Assembly, "Glimpse.Core.EmbeddedResources.sprite.png", "image/png");
 }
コード例 #55
0
ファイル: ClientShould.cs プロジェクト: GProulx/Glimpse
 protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
 {
     return new EmbeddedResourceInfo(this.GetType().Assembly, "wrong", "Doesn't Matter");
 }
コード例 #56
0
 public IResourceResult Execute(IResourceContext context)
 {
     return null; // should not be executed during tests
 }
コード例 #57
0
 /// <summary>
 /// Returns the embedded resource that represents the Glimpse Configuration Script which will be returned during the execution of the <see cref="FileResource"/>
 /// </summary>
 /// <param name="context">The resource context</param>
 /// <returns>Information about the embedded Glimpse Configuration Script</returns>
 protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
 {
     return new EmbeddedResourceInfo(this.GetType().Assembly, "Glimpse.Core.EmbeddedResources.glimpse_config.js", "text/javascript");
 }
コード例 #58
0
ファイル: PopupResource.cs プロジェクト: GProulx/Glimpse
 /// <summary>
 /// Executes the specified resource with the specific context.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>
 ///   <see cref="IResourceResult" /> that can be executed when the Http response is ready to be returned.
 /// </returns>
 /// <exception cref="System.NotSupportedException">Throws a <see cref="NotSupportedException"/> since this is a <see cref="IPrivilegedResource"/>.</exception>
 public IResourceResult Execute(IResourceContext context)
 {
     throw new NotSupportedException(string.Format(Resources.PrivilegedResourceExecuteNotSupported, GetType().Name));
 }
コード例 #59
0
        public MessagingModule(Config cfg, IBus bus, IQueryJSonBus reader, IStore store, IResourceContext ctx, IExceptionLoggerService exceptionLoggerService)
        {
            Get["/query/{name}"] = _ =>
            {
                long exId = 0;
                try
                {
                    var t = store.ResolveMessageType(_["name"]);
                    if (t == null) throw new Exception("Query not found : " + _["name"]);
                    var q = (IQuery)Activator.CreateInstance(t);
                    NevaUtils.ObjectHelper.FillFromString(q, n => Request.Query[n]);

                    MethodInfo method = typeof(IQueryJSonBus).GetMethod("Read");
                    MethodInfo generic = method.MakeGenericMethod(t);
                    var json = (string)generic.Invoke(reader, new object[] { q });

                    return Response.AsText(json, "application/json");
                }
                catch (Exception ex)
                {
                    exId = exceptionLoggerService.Log(new Exception("Unable to read query : " + _["name"], ex));
                }
                return Response.AsJson(new { ExceptionId = exId.ToString(CultureInfo.InvariantCulture) });
            };

            Post["/command/{name}"] = _ =>
            {
                long exId = 0;
                string cmdId = null;
                try
                {
                    var t = store.ResolveMessageType(_.name);
                    if (t == null) throw new Exception("Command not found : " + _["name"]);
                    var c = (ICommand)Activator.CreateInstance(t);

                    //var ci = ctx.CurrentCultureId == 12
                    //    ? new System.Globalization.CultureInfo("fr-FR")
                    //    : new System.Globalization.CultureInfo("en-GB");
                    var ci = CultureInfo.InvariantCulture;
                    NevaUtils.ObjectHelper.FillFromString(c, n => Request.Form[n], ci);

                    var eWrapper = new EventDispatcherWrapper(bus);

                    MethodInfo method =
                        typeof(IBus).GetMethods().SingleOrDefault(m => m.Name == "Send" && m.GetParameters().Count() == 2);
                    System.Diagnostics.Debug.Assert(method != null, "IBus should contains Send methode with 2 parameters");
                    MethodInfo generic = method.MakeGenericMethod(t);
                    var r = (CommandResult)generic.Invoke(bus, new object[] { c, eWrapper });

                    cmdId = r.CommandId;
                    return Response.AsJson(new
                    {
                        ExceptionId = 0,
                        r.CommandId,
                        r.CommandValidationErrors,
                        Events = eWrapper.Events.Select(e => new { Name = e.GetType().FullName, Payload = e }).ToArray()
                    });
                }
                catch (Exception ex)
                {
                    if (ex.InnerException is UnauthorizedAccessException)
                        return new HtmlResponse(HttpStatusCode.Forbidden);
                    exId = exceptionLoggerService.Log(new Exception("Unable to execute command : " + _["name"], ex));
                }

                return Response.AsJson(new { cmdId, ExceptionId = exId.ToString(CultureInfo.InvariantCulture) });
            };
        }
コード例 #60
0
ファイル: JsResource.cs プロジェクト: NLog/Glimpse.NLog
 protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
 {
     return new EmbeddedResourceInfo(this.GetType().Assembly, "Glimpse.NLog.Resource.glimpse.nlog.js", @"application/x-javascript");
 }