Beispiel #1
0
        /// <summary>
        /// Registers the files the specified path prefix.
        /// </summary>
        /// <param name="pathPrefix">The path prefix to be applied to all paths.</param>
        /// <param name="virtualPaths">The virtual path list.</param>
        public void Register(String pathPrefix, params string[] virtualPaths)
        {
            if (virtualPaths == null || virtualPaths.Length == 0)
            {
                virtualPaths = new[] { pathPrefix };
                pathPrefix   = "";
            }

            if (External)
            {
                package.AddFiles(virtualPaths.Select(vpath => DextopUtil.CombinePaths(pathPrefix, vpath)));
            }
            else
            {
                if (package.Module.Application.PreprocessingEnabled && !package.Module.Application.PreprocessorMode && Concate)
                {
                    return;
                }

                foreach (var vpath in virtualPaths)
                {
                    package.AddFiles(package.SearchServer(DextopUtil.CombinePaths(pathPrefix, vpath), ".js", true));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Register standard assembly preprocessors such as remoting, model, grid and forms preprocessors.
        /// </summary>
        /// <param name="generatedFilesPath"></param>
        /// <param name="preprocessors"></param>
        protected void RegisterStandardAssemblyPreprocessors(string generatedFilesPath, Dictionary <string, IDextopAssemblyPreprocessor> preprocessors)
        {
            preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "remote.js"), new DextopRemotingPreprocessor()
            {
                TypeFilter = PreprocessingTypeFilter
            });

            if (!Application.PreprocessingEnabled || Application.PreprocessorMode)
            {
                preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "model.js"), new DextopModelPreprocessor()
                {
                    TypeFilter = PreprocessingTypeFilter
                });
                preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "headers.js"), new DextopGridHeaderPreprocessor()
                {
                    TypeFilter = PreprocessingTypeFilter
                });
                preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "forms.js"), new DextopFormPreprocessor()
                {
                    TypeFilter = PreprocessingTypeFilter
                });
                preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "enums.js"), new DextopEnumPreprocessor()
                {
                    TypeFilter = PreprocessingTypeFilter
                });
            }
        }
Beispiel #3
0
 /// <summary>
 /// Registers the localization files.
 /// </summary>
 /// <param name="lanuage">The language code.</param>
 /// <param name="pathPrefix">The path prefix to be applied to all paths.</param>
 /// <param name="virtualPathFormats">The virtual path formats.</param>
 public void RegisterLocalization(string lanuage, String pathPrefix, params string[] virtualPathFormats)
 {
     foreach (var vpath in virtualPathFormats)
     {
         package.AddLocalization(lanuage, package.SearchServer(DextopUtil.CombinePaths(pathPrefix, String.Format(vpath, lanuage)), ".js", false));
     }
 }
Beispiel #4
0
 /// <summary>
 /// Registers standard data loaders
 /// </summary>
 /// <param name="generatedFilesPath">The generated files path.</param>
 /// <param name="loaders">The loaders.</param>
 protected void RegisterStandardFileLoaders(String generatedFilesPath, Dictionary <String, IDextopFileLoader> loaders)
 {
     if (Application.PreprocessingEnabled && !Application.PreprocessorMode)
     {
         loaders.Add(DextopUtil.CombinePaths(generatedFilesPath, "constructors.config"), new DextopRemotableConstructorLoader());
     }
 }
Beispiel #5
0
        /// <summary>
        /// Gets the direct config.
        /// </summary>
        /// <returns></returns>
        protected DextopConfig GetDirectConfig()
        {
            if (DextopApplication == null)
            {
                throw new DextopSessionNotInitializedException();
            }

            var urlFormat = DextopUtil.AbsolutePath(String.Format("{{0}}.ashx?sid={0}", SessionId));

            if (!String.IsNullOrEmpty(DextopApplication.AppKey))
            {
                urlFormat += "&app=" + DextopApplication.AppKey;
            }

            var res = new DextopConfig();

            res["remotingUrl"] = String.Format(urlFormat, "rpc");
            if (UseLongPolling)
            {
                res["longPollingUrl"] = String.Format(urlFormat, "lpoll");
            }
            else if (UsePolling)
            {
                res["pollingUrl"]      = String.Format(urlFormat, "poll");
                res["pollingInterval"] = PollingInterval;
            }
            return(res);
        }
 /// <summary>
 /// Registers the module.
 /// </summary>
 /// <param name="virtualPath">The virtual path.</param>
 /// <param name="module">The module.</param>
 protected void RegisterModule(String virtualPath, DextopModule module)
 {
     module.PhysicalPath = DextopUtil.MapPath(virtualPath);
     module.VirtualPath  = virtualPath;
     module.Application  = this;
     Modules.Add(module);
 }
Beispiel #7
0
 /// <summary>
 /// Register standard assembly preprocessors such as remoting, model, grid and forms preprocessors.
 /// </summary>
 /// <param name="generatedFilesPath"></param>
 /// <param name="preprocessors"></param>
 protected void RegisterStandardAssemblyPreprocessors(string generatedFilesPath, Dictionary <string, IDextopAssemblyPreprocessor> preprocessors)
 {
     preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "remote.js"), new DextopRemotingPreprocessor());
     preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "model.js"), new DextopModelPreprocessor());
     preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "headers.js"), new DextopGridHeaderPreprocessor());
     preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "forms.js"), new DextopFormPreprocessor());
     preprocessors.Add(DextopUtil.CombinePaths(generatedFilesPath, "enums.js"), new DextopEnumPreprocessor());
 }
Beispiel #8
0
 internal IEnumerable <string> PrefixVirtualPath(IEnumerable <string> list)
 {
     foreach (var a in list)
     {
         var colonHack = a.Replace(":/", "");
         yield return(DextopUtil.CombinePaths(VirtualPath, colonHack));
     }
 }
Beispiel #9
0
 /// <summary>
 /// Registers the files the specified path prefix.
 /// </summary>
 /// <param name="pathPrefix">The path prefix to be applied to all paths.</param>
 /// <param name="virtualPaths">The virtual path list.</param>
 public void Register(String pathPrefix, params string[] virtualPaths)
 {
     if (virtualPaths == null || virtualPaths.Length == 0)
     {
         virtualPaths = new[] { pathPrefix };
         pathPrefix   = "";
     }
     foreach (var vpath in virtualPaths)
     {
         package.AddFiles(package.SearchServer(DextopUtil.CombinePaths(pathPrefix, vpath), ".js", true));
     }
 }
        /// <summary>
        /// Optimizes the modules.
        /// </summary>
        /// <param name="outputVirtualPath">The output virtual path.</param>
        protected void OptimizeModules(String outputVirtualPath)
        {
            var outputModule = new DextopResourceOptimizationModule()
            {
                PhysicalPath = DextopUtil.MapPath(outputVirtualPath),
                VirtualPath  = outputVirtualPath
            };

            var context = new DextopResourceOptimizationContext
            {
                OptimizationOutputModule = outputModule
            };

            foreach (var m in Modules)
            {
                m.OptimizeResources(context);
            }
        }
Beispiel #11
0
 /// <summary>
 /// Registers the localization files.
 /// </summary>
 /// <param name="language">The language code.</param>
 /// <param name="pathPrefix">The path prefix to be applied to all paths.</param>
 /// <param name="virtualPathFormats">The virtual path formats.</param>
 public void RegisterLocalization(string language, String pathPrefix, params string[] virtualPathFormats)
 {
     foreach (var vpath in virtualPathFormats)
     {
         if (External)
         {
             if (vpath.EndsWith("/"))
             {
                 throw new DextopException("Folders are not allowed on external modules.");
             }
             package.AddLocalization(language, new[] { DextopUtil.CombinePaths(pathPrefix, String.Format(vpath, language)) });
         }
         else
         {
             package.AddLocalization(language, package.SearchServer(DextopUtil.CombinePaths(pathPrefix, String.Format(vpath, language)), ".js", false));
         }
     }
 }
Beispiel #12
0
        /// <summary>
        /// Decodes the JSON string to a value of given type.
        /// </summary>
        /// <param name="value">JSON text.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static object DecodeValue(String value, Type type)
        {
            if (type == typeof(String))
            {
                return(value);
            }

            if (String.IsNullOrEmpty(value))
            {
                return(type.IsValueType ? Activator.CreateInstance(type) : null);
            }

            value = value.Trim('"');
            if (type == typeof(DateTime))
            {
                return(DecodeDate(value));
            }
            if (type == typeof(DateTime?))
            {
                return((DateTime?)DecodeDate(value));
            }
            if (type == typeof(TimeSpan))
            {
                return(DecodeTime(value));
            }
            if (type == typeof(TimeSpan?))
            {
                return((TimeSpan?)DecodeTime(value));
            }
            if (type == typeof(Guid))
            {
                return(new Guid(value));
            }
            if (type == typeof(Guid?))
            {
                return((Guid?)(new Guid(value)));
            }
            if (type.IsValueType)
            {
                return(Codaxy.Common.Convert.ChangeTypeInvariant(value, type));
            }
            return(DextopUtil.Decode(value, type));
        }
Beispiel #13
0
        /// <summary>
        /// Try to cast property to given type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="property">The property name.</param>
        /// <param name="value">The value.</param>
        /// <returns>True if value is found and converted.</returns>
        public bool TryConvert(String property, out object value, Type type)
        {
            try
            {
                object v;
                if (TryGetValue(property, out v) && v != null)
                {
                    if (v is string)
                    {
                        value = DextopUtil.DecodeValue(v as string, type);
                    }
                    else
                    {
                        value = Codaxy.Common.Convert.ChangeType(v, type);
                    }
                    return(true);
                }
            }
            catch { }

            value = null;
            return(false);
        }
Beispiel #14
0
        /// <summary>
        /// Try to cast property to given type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="property">The property name.</param>
        /// <param name="value">The value.</param>
        /// <returns>True if value is found and converted.</returns>
        public bool TryGet <T>(String property, out T value)
        {
            try
            {
                object v;
                if (TryGetValue(property, out v) && v != null)
                {
                    if (v is string)
                    {
                        value = (T)DextopUtil.DecodeValue(v as string, typeof(T));
                    }
                    else
                    {
                        value = (T)Codaxy.Common.Convert.ChangeType(v, typeof(T));
                    }
                    return(true);
                }
            }
            catch {}

            value = default(T);
            return(false);
        }
        /// <summary>
        /// Searches the server for resource files.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <param name="extension">The extension.</param>
        /// <param name="throwIfNotFound">if set to <c>true</c> [throw if not found].</param>
        /// <returns></returns>
        public IList <string> SearchServer(String virtualPath, string extension, bool throwIfNotFound)
        {
            var files = new List <String>();

            if (virtualPath.EndsWith(extension, StringComparison.InvariantCultureIgnoreCase))
            {
                var fpath = Module.MapPath(virtualPath);
                if (File.Exists(fpath))
                {
                    files.Add(virtualPath);
                }
                else if (throwIfNotFound)
                {
                    throw new InvalidDextopPackagePathException(DextopUtil.CombinePaths(Module.VirtualPath, virtualPath));
                }
            }
            else if (virtualPath.EndsWith("/"))
            {
                bool recursive = virtualPath.EndsWith("/*/") || virtualPath.EndsWith("//");
                if (recursive)
                {
                    virtualPath = virtualPath.TrimEnd('/', '*');
                }
                String location = Module.MapPath(virtualPath);
                var    list     = Directory.GetFiles(location, "*" + extension, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                foreach (var f in list)
                {
                    var p = DextopUtil.CombinePaths(virtualPath, f.Substring(location.Length).Replace('\\', '/'));
                    files.Add(p);
                }
            }
            else
            {
                throw new InvalidDextopPackagePathException(DextopUtil.CombinePaths(Module.VirtualPath, virtualPath));
            }
            return(files);
        }
Beispiel #16
0
        internal IList <Response> HandleRemotingRequest(HttpContext context, Request[] requests)
        {
            if (Culture != null)
            {
                Thread.CurrentThread.CurrentCulture = Culture;
            }

            HttpContext = context;

            var responses = new List <Response>();

            foreach (var request in requests)
            {
                /* This part blocks out of order processing of direct transactions for 2 seconds.
                 * This is important as two sequential http request can come in different order than sent.
                 * Luckily Ext.direct has tid field.
                 */
                int waitCounter = 20;
                while (request.tid > lastTid + 1 && --waitCounter > 0)
                {
                    Thread.Sleep(100);
                }

                if (request.tid > lastTid)
                {
                    lastTid = request.tid;
                }

                var call = new DextopRemoteMethodCall
                {
                    FormSubmit = request.FormSubmit,
                    RemoteId   = request.data[0],
                    Arguments  = DextopUtil.Decode <String[]>(request.data[2]),
                    MethodName = request.data[1]
                };
                var response = new Response
                {
                    type   = "rpc",
                    method = request.method,
                    tid    = request.tid,
                    action = request.action
                };
                responses.Add(response);
                try
                {
                    response.result = ExecuteMethodCall(call);
                }
                catch (Exception ex)
                {
                    response.result = new DextopRemoteMethodCallResult
                    {
                        success = false,
                        result  = new DextopRemoteMethodCallException
                        {
                            type       = "rpc",
                            exception  = ex.Message,
                            stackTrace = ex.StackTrace
                        }
                    };
                }
            }

            HttpContext = null;

            return(responses);
        }
        internal DextopConfig Register(DextopRemote parent, IDextopRemotable remotable, String remoteId = null, bool subRemote = true)
        {
            if (remotable == null)
            {
                throw new ArgumentNullException("remotable");
            }

            bool isClientInitiated;

            if (remoteId == null)
            {
                remoteId          = Interlocked.Increment(ref nextRemoteId).ToString();
                isClientInitiated = parent != null && parent.IsClientInitiated;
            }
            else if (subRemote)
            {
                if (parent == null)
                {
                    throw new DextopInternalException();
                }
                remoteId          = parent.RemoteId + '.' + remoteId;
                isClientInitiated = parent.IsClientInitiated;
            }
            else
            {
                isClientInitiated = true;
            }

            var context = new RemotableContext
            {
                Remotable = remotable
            };

            var remote = new DextopRemote(Context, remoteId, isClientInitiated);

            var clientTypeName = DextopApplication.MapTypeName(remotable.GetType());

            try
            {
                var config = new DextopConfig();
                remotable.InitRemotable(remote, config);

                if (!remote.IsClientInitiated)
                {
                    DextopConfig remoteProxyConfig;
                    var          remoteTypeName = remote.RemoteHostType ?? clientTypeName;
                    if (remoteTypeName != null)
                    {
                        config.Add("alias", remoteTypeName);
                        remoteProxyConfig = new DextopConfig();
                        config.Add("remote", remoteProxyConfig);
                    }
                    else
                    {
                        remoteProxyConfig = config;
                    }
                    remoteProxyConfig.Add("remoteId", remoteId);
                    remoteProxyConfig.Add("alias", DextopUtil.GetRemotingProxyTypeName(clientTypeName));
                    if (remote.componentsConfig != null)
                    {
                        remoteProxyConfig.Add("components", remote.componentsConfig);

                        //config not needed anymore - free memory
                        remote.componentsConfig = null;
                    }
                }

                if (!remotables.TryAdd(remoteId, context))
                {
                    throw new DextopInternalException();
                }

                return(config);
            }
            catch
            {
                remote.Dispose();
                remotable.Dispose();
                throw;
            }
        }
        /// <summary>
        /// Gets the CSS files registered in all modules.
        /// </summary>
        /// <param name="culture">The culture.</param>
        /// <returns></returns>
        public string[] GetCssFiles(CultureInfo culture)
        {
            var lang = MapCultureToLanguageCode(culture);

            return(Modules.SelectMany(a => a.GetCssFiles(lang).Select(b => DextopUtil.AbsolutePath(b))).ToArray());
        }
Beispiel #19
0
 internal IEnumerable <string> PrefixVirtualPath(IEnumerable <string> list)
 {
     return(list.Select(a => DextopUtil.CombinePaths(VirtualPath, a)));
 }