Пример #1
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public override void ProcessRequest(HttpContext context)
        {
            PollingResult result;

            try
            {
                var session = GetSession(context);
                result = session.HandlePollingRequest(context);
            }
            catch (Exception ex)
            {
                //Application should handle the request and give a valid result.
                //Any exception is a sign that session is not valid anymore.
                result = new LongPollingResult
                {
                    type    = "rpc",
                    name    = "message",
                    success = false,
                    data    = new DextopRemoteMethodCallException
                    {
                        exception = ex.Message,
                        type      = "session"
                    }
                };
            }

            context.Response.ContentType = "application/json";
            DextopUtil.Encode(result, context.Response.Output);
        }
        void IHttpAsyncHandler.EndProcessRequest(IAsyncResult asyncResult)
        {
            if (errorHandler != null)
            {
                errorHandler.EndInvoke(asyncResult);
            }
            else
            {
                LongPollingResult result;
                try
                {
                    result = session.EndHandlingLongPollingRequest(asyncResult, start);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Long polling exception.", ex);
                    //Application should handle the request and give a valid result.
                    //Any exception is a sign that session is not valid anymore.
                    result = new LongPollingResult
                    {
                        type    = "rpc",
                        name    = "message",
                        success = false,
                        data    = new DextopRemoteMethodCallException
                        {
                            exception = ex.Message,
                            type      = "session"
                        }
                    };
                }

                context.Response.ContentType = "application/json";
                DextopUtil.Encode(result, context.Response.Output);
            }
        }
Пример #3
0
 private string Serialize(IList <object> data)
 {
     if (data == null)
     {
         return(null);
     }
     return(DextopUtil.Encode(serializer.Serialize(data)));
 }
Пример #4
0
 /// <summary>
 /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios.
 /// </summary>
 /// <param name="jw">The writer.</param>
 protected override void WriteProperties(DextopJsWriter jw)
 {
     jw.AddProperty("field", field);
     jw.AddProperty("type", type);
     jw.DefaultProperty("min", min);
     jw.DefaultProperty("max", max);
     if (list != null)
     {
         jw.AddRawProperty("list", DextopUtil.Encode(list));
     }
     jw.DefaultProperty("matcher", matcher);
     base.WriteProperties(jw);
 }
Пример #5
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var app     = DextopApplication.GetApplication();
            var session = new ShowcaseSession();
            var config  = app.AddSession(session);

            return(View(new Models.DextopAppConfig
            {
                CssFiles = app.GetCssFiles(session.Culture),
                JsFiles = app.GetJsFiles(session.Culture),
                SessionConfig = new HtmlString(DextopUtil.Encode(config))
            }));
        }
Пример #6
0
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream output)
        {
            BaseSrcPath = DextopUtil.MapPath("~/guides/articles/");
            OutputPath  = DextopUtil.MapPath("~/guides/html/");

            var articles = ProcessDirectory(BaseSrcPath);

            using (var tw = new StreamWriter(output))
            {
                tw.WriteLine("Ext.ns('Showcase');");
                tw.Write("Showcase.Guides = ");
                tw.Write(DextopUtil.Encode(articles.ToArray()));
                tw.WriteLine(";");
            }
        }
Пример #7
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var app     = DextopApplication.GetApplication();
            var session = new App.Session();
            var config  = app.AddSession(session);

            var model = new Models.AppConfig
            {
                CssFiles      = app.GetCssFiles(session.Culture),
                JsFiles       = app.GetJsFiles(session.Culture),
                SessionConfig = DextopUtil.Encode(config)
            };

            return(View(model));
        }
 void ArraySerializationTest(int n)
 {
     using (var app = new DextopTestApplication())
     {
         var arraySerializer = new DextopModelArraySerializer(app.ModelManager.GetModelMeta(typeof(Model)));
         var list            = new List <object>();
         for (var i = 0; i < n; i++)
         {
             list.Add(new Model {
                 Id = 1, Name = "Name", Bool = true
             });
         }
         var data = arraySerializer.Serialize(list);
         var str  = DextopUtil.Encode(data);
     }
 }
Пример #9
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var app     = DextopApplication.GetApplication();
            var session = new ShowcaseSession();
            var config  = app.AddSession(session);

            if (!String.IsNullOrEmpty(Request.QueryString["culture"]))
            {
                session.Culture = new System.Globalization.CultureInfo(Request.QueryString["culture"]);
            }

            return(View(new Models.DextopAppConfig
            {
                CssFiles = app.GetCssFiles(session.Culture),
                JsFiles = app.GetJsFiles(session.Culture),
                SessionConfig = new HtmlString(DextopUtil.Encode(config))
            }));
        }
        void WriteException(HttpContext context, Exception ex)
        {
            //Application should handle the request and give a valid result.
            //Any exception is a sign that session is not valid anymore.
            var result = new LongPollingResult
            {
                type    = "rpc",
                name    = "message",
                success = false,
                data    = new DextopRemoteMethodCallException
                {
                    exception = ex.Message,
                    type      = "session"
                }
            };

            context.Response.ContentType = "application/json";
            DextopUtil.Encode(result, context.Response.Output);
        }
Пример #11
0
        public void ProcessRequest(HttpContext context)
        {
            var ajaxRequest = context.Request.QueryString["ajax"] == "1";

            if (ajaxRequest)
            {
                ProcessAjaxRequest(context);
                return;
            }

            var formSubmit = context.Request.QueryString["formSubmit"] == "1";
            var upload     = formSubmit && context.Request.Form["extUpload"] == "true";

            var requests = upload ? GetUploadRequest(context) : GetActionRequest(context);

            var responses = new List <Response>();

            foreach (var request in requests)
            {
                DextopApiInvocationResult result;
                try
                {
                    using (var apiContext = DextopApi.Resolve <DextopApiContext>())
                    {
                        var controllerType = Type.GetType(request.data[0]);
                        apiContext.Scope       = DextopUtil.Decode <DextopConfig>(request.data[1]);
                        apiContext.HttpContext = new HttpContextWrapper(context);
                        var controller = apiContext.ResolveController(controllerType);
                        controller.OnInitialize();

                        try
                        {
                            controller.OnExecuting();
                            result = controller.Invoke(request.data[2], request.FormSubmit, DextopUtil.Decode <string[]>(request.data[3]));
                            controller.OnExecuted();
                        }
                        catch (Exception ex)
                        {
                            controller.OnError(ex);
                            throw;
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = DextopApiInvocationResult.Exception(ex);
                }

                var response = new Response
                {
                    action = request.action,
                    method = request.method,
                    type   = request.type,
                    tid    = request.tid,
                    result = result
                };

                responses.Add(response);
            }

            DextopUtil.Encode(responses, context.Response.Output);
        }
Пример #12
0
 public RemoteInstantiationWindow(DextopConfig dc)
 {
     title = DextopUtil.Encode(dc);
 }
Пример #13
0
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream output)
        {
            using (var tw = new StreamWriter(output))
            {
                DextopJsWriter jw       = new DextopJsWriter(tw);
                var            assembly = this.GetType().Assembly;
                var            data     = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DemoAttribute>(assembly, false);
                jw.ExtNamespace("Showcase");
                jw.Write("Showcase.Demos = [");
                bool first = true;

                HashSet <String> levels     = new HashSet <string>();
                HashSet <String> categories = new HashSet <string>();
                HashSet <String> topics     = new HashSet <string>();

                foreach (var entry in data)
                {
                    var att = entry.Value;
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        jw.Write(", ");
                    }
                    jw.StartBlock();
                    jw.AddProperty("id", att.Id);
                    jw.DefaultProperty("title", att.Title);
                    jw.DefaultProperty("description", att.Description);
                    jw.AddProperty("clientLauncher", att.ClientLauncher);
                    LevelAttribute level;
                    if (AttributeHelper.TryGetAttribute <LevelAttribute>(entry.Key, out level, false))
                    {
                        jw.AddProperty("level", level.Name);
                    }
                    TopicAttribute topic;
                    if (AttributeHelper.TryGetAttribute <TopicAttribute>(entry.Key, out topic, false))
                    {
                        jw.AddProperty("topic", topic.Name);
                    }
                    CategoryAttribute cat;
                    if (AttributeHelper.TryGetAttribute <CategoryAttribute>(entry.Key, out cat, false))
                    {
                        jw.AddProperty("category", cat.Name);
                    }

                    jw.AddProperty("sourceUrlBase", DextopUtil.AbsolutePath(String.Format("source/{0}", att.Id)));
                    jw.AddProperty("cacheBuster", GetCacheBuster(att));

                    jw.CloseBlock();
                    ((ShowcaseApplication)application).RegisterDemo(att.Id, entry.Key);

                    if (!levels.Contains(level.Name))
                    {
                        levels.Add(level.Name);
                    }

                    if (!topics.Contains(topic.Name))
                    {
                        topics.Add(topic.Name);
                    }

                    if (!categories.Contains(cat.Name))
                    {
                        categories.Add(cat.Name);
                    }
                }
                jw.WriteLine("];");
                jw.WriteLine();
                jw.Write("Showcase.Topics = ");
                jw.Write(DextopUtil.Encode(topics.ToArray()));
                jw.WriteLine(";");
                jw.WriteLine();
                jw.Write("Showcase.Levels = ");
                jw.Write(DextopUtil.Encode(levels.ToArray()));
                jw.WriteLine(";");
                jw.WriteLine();
                jw.Write("Showcase.Categories = ");
                jw.Write(DextopUtil.Encode(categories.ToArray()));
                jw.WriteLine(";");
            }
        }
Пример #14
0
 void Send(Form form)
 {
     throw new DextopInfoMessageException(DextopUtil.Encode(form));
 }
Пример #15
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            var ajax = context.Request.QueryString["ajax"] == "1";

            if (ajax)
            {
                try
                {
                    var session = GetSession(context);
                    session.HandleAjaxRequest(context);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }

                return;
            }

            try
            {
                var formSubmit = context.Request.QueryString["formSubmit"] == "1";
                var upload     = formSubmit && context.Request.Form["extUpload"] == "true";

                var requests = upload ? GetUploadRequest(context) : GetActionRequest(context);

                IList <Response> result;
                try
                {
                    var session = GetSession(context);
                    result = session.HandleRemotingRequest(context, requests);
                }
                catch (Exception ex)
                {
                    //Application should handle the request and give a valid result.
                    //Any exception is a sign that session is not valid anymore.
                    result = requests.Select(a => new Response
                    {
                        action = a.action,
                        method = a.method,
                        tid    = a.tid,
                        type   = a.type,
                        result = new DextopRemoteMethodCallResult
                        {
                            success = false,
                            result  = new DextopRemoteMethodCallException
                            {
                                exception = ex.Message,
                                type      = "session"
                            }
                        }
                    }).ToArray();
                }

                context.Response.ContentType = upload ? "text/html" : "application/json";
                DextopUtil.Encode(result, context.Response.Output);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                DextopUtil.Encode(new DextopRemoteMethodCallResult
                {
                    success = false,
                    result  = new DextopRemoteMethodCallException
                    {
                        exception = ex.Message
                    }
                }, context.Response.Output);
            }
        }
        DextopRemoteMethodInvokeResult Instantiate(IDextopRemotable target, String[] arguments)
        {
            try
            {
                if (arguments.Length < 1)
                {
                    throw new InvalidDextopRemoteMethodCallException();
                }
                InstantiateOptions options;
                if (arguments[0] != null && arguments[0].StartsWith("{"))
                {
                    options = DextopUtil.Decode <InstantiateOptions>(arguments[0]);
                }
                else
                {
                    options = new InstantiateOptions
                    {
                        subRemote = true,
                        type      = arguments[0]
                    }
                };

                if (options.type == null)
                {
                    throw new InvalidDextopRemoteMethodCallException();
                }

                String config = null;
                if (arguments.Length > 1)
                {
                    config = arguments[1];
                }

                if (options.type == null)
                {
                    throw new InvalidDextopRemoteMethodCallException();
                }

                List <RemotableConstructor> constructors;

                if (!constructorCache.TryGetValue(options.type, out constructors))
                {
                    String       typeName;
                    DextopConfig routeParams;
                    if (MatchRoutes(options.type, out typeName, out routeParams))
                    {
                        return(Instantiate(target, new[] { typeName, DextopUtil.Encode(routeParams) }));
                    }

                    if (constructors == null || constructors.Count == 0)
                    {
                        constructors = LoadRemotableConstructors(options.type);
                    }
                }

                if (constructors == null || constructors.Count == 0)
                {
                    throw new InvalidDextopRemoteMethodCallException();
                }

                object[]             args;
                RemotableConstructor c;

                if (config == null)
                {
                    args = new object[0];
                    c    = constructors.FirstOrDefault(a => a.ArgumentsType == ConstructorArgments.Default);
                    if (c == null)
                    {
                        c    = constructors.FirstOrDefault(a => a.ArgumentsType == ConstructorArgments.Hash);
                        args = new object[1];
                    }
                }
                else if (config.StartsWith("["))
                {
                    var argss = DextopUtil.Decode <String[]>(config);
                    c = constructors.Where(a => a.ArgumentsType == ConstructorArgments.Array && a.Args.Length >= argss.Length).OrderBy(a => a.Args.Length).FirstOrDefault();
                    if (c == null)
                    {
                        c = constructors.Where(a => a.ArgumentsType == ConstructorArgments.Array).OrderByDescending(a => a.Args.Length).FirstOrDefault();
                    }
                    if (c == null)
                    {
                        c = constructors.FirstOrDefault(a => a.ArgumentsType == ConstructorArgments.Hash);
                    }
                    if (c == null)
                    {
                        c = constructors.FirstOrDefault(a => a.ArgumentsType == ConstructorArgments.Default);
                    }

                    if (c == null)
                    {
                        throw new InvalidDextopRemoteMethodCallException();
                    }

                    args = new object[c.Args.Length];
                    for (var i = 0; i < c.Args.Length && i < argss.Length; i++)
                    {
                        args[i] = DextopUtil.DecodeValue(argss[i], c.Args[i].ParameterType);
                    }
                }
                else if (config.StartsWith("{"))
                {
                    c = constructors.FirstOrDefault(a => a.ArgumentsType == ConstructorArgments.Hash);
                    if (c != null)
                    {
                        args = new object[1] {
                            DextopUtil.Decode(config, c.Args[0].ParameterType)
                        };
                    }
                    else
                    {
                        var configs    = DextopUtil.Decode <Dictionary <String, String> >(config) ?? new Dictionary <String, String>();
                        var candidates = constructors.Select(a => new
                        {
                            Constructor   = a,
                            ArgumentMatch = a.Args.Count(b => configs.ContainsKey(b.Name))
                        }).OrderByDescending(x => x.ArgumentMatch).ToArray();

                        c = null;
                        foreach (var cand in candidates)
                        {
                            if (cand.ArgumentMatch == configs.Count && cand.Constructor.Args.Length == cand.ArgumentMatch)
                            {
                                c = cand.Constructor;
                                break;
                            }
                        }

                        if (c == null) // if we still don't have a match take the candidate with the biggest number of matching arguments, and prefer parameterless constructor if zero
                        {
                            c = candidates.OrderByDescending(a => a.ArgumentMatch).ThenBy(a => (int)a.Constructor.ArgumentsType).First().Constructor;
                        }

                        args = new object[c.Args.Length];
                        for (var i = 0; i < c.Args.Length; i++)
                        {
                            String argString;
                            if (configs.TryGetValue(c.Args[i].Name, out argString))
                            {
                                args[i] = DextopUtil.DecodeValue(argString, c.Args[i].ParameterType);
                            }
                        }
                    }
                }
                else
                {
                    c = constructors.Where(a => a.ArgumentsType == ConstructorArgments.Array && a.Args.Length >= 1).OrderBy(a => a.Args.Length).FirstOrDefault();
                    if (c == null)
                    {
                        throw new InvalidDextopRemoteMethodCallException();
                    }
                    args    = new object[c.Args.Length];
                    args[0] = DextopUtil.DecodeValue(config, c.Args[0].ParameterType);
                }

                var remotable = (IDextopRemotable)c.ConstructorInfo.Invoke(args);

                try
                {
                    return(new DextopRemoteMethodInvokeResult
                    {
                        Success = true,
                        Result = target.Remote.TrackRemotableComponent(remotable,
                                                                       remoteId: options.remoteId,
                                                                       subRemote: options.subRemote ?? true,
                                                                       own: options.own ?? true
                                                                       )
                    });
                }
                catch
                {
                    remotable.Dispose();
                    throw;
                }
            }
            catch (TargetInvocationException tix)
            {
                return(new DextopRemoteMethodInvokeResult
                {
                    Success = false,
                    Exception = tix.InnerException ?? tix
                });
            }
            catch (Exception ex)
            {
                return(new DextopRemoteMethodInvokeResult
                {
                    Success = false,
                    Exception = ex
                });
            }
        }
Пример #17
0
        DextopFormField ToField(string memberName, Type memberType, int index)
        {
            DextopFormField field = base.ToField(memberName, memberType);

            field.NameSuffix = "_" + index.ToString() + "_";
            if (inputValues != null && index < inputValues.Length)
            {
                field["inputValue"] = inputValues[index];
            }
            else
            {
                field["inputValue"] = index;
            }

            field.fieldLabel = field.boxLabel = null;
            field.Properties.Remove("fieldLabel");
            field.Properties.Remove("boxLabel");

            field["checked"] = new DextopRawJs("options.data['{0}'] === {1}", field.name, DextopUtil.Encode(field["inputValue"]));

            if (fieldLabels != null && index < fieldLabels.Length)
            {
                field.fieldLabel = fieldLabels[index];
            }

            if (boxLabels != null)
            {
                field.boxLabel = boxLabels[index];
            }

            return(field);
        }