Пример #1
0
        public string GetQueryString(string url)
        {
            var haveFirstSlash = url.StartsWith("/");
            var haveLastSlash  = url.EndsWith('/');
            var fixedURL       = url;

            if (!haveFirstSlash)
            {
                fixedURL = $"/{fixedURL}";
            }
            if (!haveLastSlash)
            {
                fixedURL = $"{fixedURL}/";
            }
            string path = $"{(!string.IsNullOrEmpty(Prefix) ? Prefix + (Prefix.EndsWith("/") ? "" : "/") : "/")}{GetControllerName()}/{GetActionName()}/";

            if (fixedURL.StartsWith(path, StringComparison.OrdinalIgnoreCase))
            {
                return(url.Substring(path.Length - (!haveFirstSlash ? 1 : 0) - (!haveLastSlash ? 1 : 0)));
            }
            else
            {
                return(url);
            }
        }
Пример #2
0
        private string GetCrmPath(string localfile)
        {
            if (!localfile.StartsWith(RootFolder, StringComparison.OrdinalIgnoreCase))
            {
                throw new FileLoadException("File not under root folder", localfile);
            }

            var crmpath = Prefix + (Prefix.EndsWith("_") ? "" : "_") + "/";

            crmpath += localfile.Replace(RootFolder.EndsWith("\\") ? RootFolder : RootFolder + "\\", "").Replace("\\", "/");
            return(crmpath);
        }
Пример #3
0
        public virtual void Start()
        {
            try
            {
                Debug.Assert(string.IsNullOrEmpty(Prefix) || Prefix.EndsWith("/"));

                _listener = new HttpListener();
                _listener.IgnoreWriteExceptions = true;
#if DEBUG
                _listener.Prefixes.Add(string.Format("http://localhost:{0}/{1}", Port, Prefix));
#else
                _listener.Prefixes.Add(string.Format("http://+:{0}/{1}", Port, Prefix));
#endif

                _listener.Start();
                _listener.BeginGetContext(this.Listener_Request, _listener);
            }
            catch (Exception ex) { TraceLog.WriteException(ex); throw; }
        }
Пример #4
0
        protected override void ExecuteInternal(string filePath, OrganizationServiceContext ctx)
        {
            _trace.WriteLine("Searching for webresources in '{0}'", filePath);

            ConfigFile config = null;

            try
            {
                var configs = ServiceLocator.ConfigFileFactory.FindConfig(filePath);
                config = configs[0];
            }
            catch
            {
                config = new ConfigFile()
                {
                    filePath = filePath,
                };
            }

            if (config.webresources == null || config.webresources.Count == 0)
            {
                // Add a webresource seciton
                config.webresources = new List <WebresourceDeployConfig> {
                    new WebresourceDeployConfig
                    {
                        files = new List <WebResourceFile>()
                    }
                };
            }

            var newWebResources = new List <WebResourceFile>();

            var files = config.webresources.Where(a => a.files != null).SelectMany(a => a.files);
            Dictionary <string, WebResourceFile> existingWebResources = new Dictionary <string, WebResourceFile>();

            foreach (var file in files)
            {
                string key = file.uniquename.ToLower();
                if (!existingWebResources.ContainsKey(key))
                {
                    existingWebResources[key] = file;
                }
                else
                {
                    var duplicate = new SparkleTaskException(SparkleTaskException.ExceptionTypes.DUPLICATE_FILE, String.Format("Duplicate file in webresource config '{0}'. Config at '{1}'", file.file, filePath));
                    throw duplicate;
                }
            }

            var webresources = ServiceLocator.DirectoryService.Search(filePath, "*.js|*.htm|*.css|*.xap|*.png|*.jpeg|*.jpg|*.gif|*.ico|*.xml");

            if (webresources == null)
            {
                throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.NO_WEBRESOURCES_FOUND, $"No webresources found in the folder '{filePath}'");
            }

            // check there is a prefix supplied
            if (string.IsNullOrWhiteSpace(Prefix))
            {
                throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.MISSING_PREFIX, "Please supply the prefix for your webresources e.g. /p:new");
            }
            // Get a list of all webresources!
            var matchList = ServiceLocator.Queries.GetWebresources(ctx).ToDictionary(w => w.Name.ToLower().Replace(Prefix + (Prefix.EndsWith("_") ? "" : "_"), ""));

            var webresourceConfig = config.GetWebresourceConfig(this.Profile).FirstOrDefault();

            if (webresourceConfig == null)
            {
                throw new Exception("Cannot find webresource section in spkl.json");
            }

            string rootPath = Path.Combine(config.filePath, webresourceConfig.root != null ? webresourceConfig.root : "");

            foreach (var filename in webresources)
            {
                _trace.WriteLine("Found '{0}'", filename);
                var file = filename.Replace("\\", "/").ToLower();

                // Find if there are any matches
                var match = matchList.Keys.Where(w => file.Contains(w)).FirstOrDefault();

                if (match != null)
                {
                    _trace.WriteLine(String.Format("Found webresource {0}", match));
                    var webresource     = matchList[match];
                    var webresourcePath = filename.Replace(rootPath, "").TrimStart('\\').TrimStart('/');

                    // is it already in the config file
                    var existingMatch = existingWebResources.Keys.Where(w => webresource.Name.Contains(w)).FirstOrDefault();
                    if (existingMatch != null)
                    {
                        continue;
                    }

                    var webresourceFile = new WebResourceFile
                    {
                        uniquename  = webresource.Name,
                        file        = webresourcePath,
                        displayname = "" + webresource.DisplayName,
                        description = "" + webresource.Description
                    };
                    // If the displayname is the same as the uniquename then we only need the unique name
                    if (webresourceFile.displayname == webresourceFile.uniquename)
                    {
                        webresourceFile.displayname = null;
                    }
                    newWebResources.Add(webresourceFile);
                }
            }


            if (webresourceConfig.files == null)
            {
                webresourceConfig.files = new List <WebResourceFile>();
            }
            webresourceConfig.files.AddRange(newWebResources);
            config.Save();
        }