Esempio n. 1
0
        private void _OnContentChangeWatch(object source, FileSystemEventArgs ev)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    Dictionary <string, stWebContentWatcher> dict = this._contentwatcher
                                                                    .Where(o => (o.Key.Contains(ev.FullPath)) && (!o.Value.Busy))
                                                                    .ToDictionary(o => o.Key, o => o.Value);

                    if (dict != null)
                    {
                        this._iLog.LogInfo(
                            string.Format(
                                Properties.Resources.httpMinifyChanged,
                                ev.ChangeType,
                                ev.Name
                                )
                            );
                        foreach (KeyValuePair <string, stWebContentWatcher> watch in dict)
                        {
                            watch.Value.Busy   = true;
                            stBootStrap minify = new stBootStrap(this._isConcat, this._isMinify, this._iLog);
                            minify.Minify(Path.GetDirectoryName(watch.Key), null);
                            watch.Value.Busy = false;
                        }
                    }
                }
                catch (Exception e)
                {
                    this._iLog.LogError(e.Message);
                }
            });
        }
Esempio n. 2
0
        private void _AddHandler(WebHandleTypes ht, Action <string, object, object> httpRequestHandler, stIPFilter ipFilter, string path, string dir)
        {
            this._Check();

            if (httpRequestHandler == null)
            {
                throw new ArgumentNullException(Properties.Resources.httpCallbackNull);
            }
            if (string.IsNullOrWhiteSpace(path))
            {
                path = httpRequestHandler.ToString();
            }

            path = ((!path.StartsWith("/")) ? "/" + path : path);
            path = ((!path.EndsWith("/")) ? path + "/" : path);

            stWebResourceLocator resLocator = new stWebResourceLocator()
            {
                IPFilter    = ((ipFilter == null) ? new stIPFilter() : ipFilter),
                ReqCallBack = httpRequestHandler,
                HandleTypes = ht
            };

            if (!this._ResourceLocator.ContainsKey(path))
            {
                this._ResourceLocator.Add(path, resLocator);
            }
            else
            {
                this._ResourceLocator[path] = resLocator;
            }
            if (!this._listener.Prefixes.Contains(path))
            {
                try
                {
                    this._listener.Prefixes.Add(
                        string.Format(
                            @"{0}{1}",
                            this._SrvUri,
                            path
                            )
                        );
                }
                catch (Exception e)
                {
                    throw new ArgumentException(
                              string.Format(
                                  Properties.Resources.httpListenerExceptionAddResource,
                                  e.Message
                                  )
                              );
                }
            }
            if (
                ((this._isConcat) || (this._isMinify)) &&
                (!string.IsNullOrWhiteSpace(dir))
                )
            {
                path = path.Substring(1, (path.Length - 2));
                path = Path.Combine(dir, path);

                if (Directory.Exists(path))
                {
                    stBootStrap minify = null;

                    try
                    {
                        minify = new stBootStrap(this._isConcat, this._isMinify, this._iLog);
                        if (this._WatchChange)
                        {
                            minify.Minify(path, this._AddContentChangeWatch);
                        }
                        else
                        {
                            minify.Minify(path, null);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new ArgumentException(e.Message);
                    }
                    finally
                    {
                        if (minify != null)
                        {
                            minify.Dispose();
                        }
                    }
                }
            }
        }