Exemplo n.º 1
0
        public Yield ExpandFolder(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            if (_directoryInfo == null)
            {
                throw new DreamBadRequestException("folder is misconfigured");
            }

            // Extract the folder to expand
            string foldername = context.GetParam("foldername", String.Empty);

            foldername = XUri.Decode(foldername);
            if (foldername.Contains(".."))
            {
                response.Return(DreamMessage.Forbidden("Relative paths are not allowed"));
                yield break;
            }

            // Extract the search pattern
            string pattern = context.GetParam("pattern", null);

            DirectoryInfo currentDirectory = new DirectoryInfo(_directoryInfo.FullName + Path.DirectorySeparatorChar + foldername);
            XDoc          result           = new XDoc("results");

            // If specified, retrieve all the directories under the current directory
            bool topDirectoryOnly = context.GetParam("topDirectoryOnly", false);

            if (!topDirectoryOnly)
            {
                foreach (DirectoryInfo directory in currentDirectory.GetDirectories())
                {
                    string encodedDirectoryName = XUri.DoubleEncodeSegment((foldername + Path.DirectorySeparatorChar + directory.Name).Replace("+", "%2b"));
                    XUri   dynamicExpandUri     = DreamContext.Current.AsPublicUri(Self.At("expand", encodedDirectoryName)).With("dream.out.format", "json");
                    if (null != pattern)
                    {
                        dynamicExpandUri = dynamicExpandUri.With("pattern", pattern);
                    }
                    result.Start("result").Elem("name", directory.Name).Elem("dynamicexpanduri", dynamicExpandUri.ToString()).End();
                }
            }

            // Retrieve files according to the search pattern
            FileInfo[] files;
            if (null != pattern)
            {
                files = currentDirectory.GetFiles(pattern, SearchOption.TopDirectoryOnly);
            }
            else
            {
                files = currentDirectory.GetFiles();
            }
            foreach (FileInfo file in files)
            {
                string encodedFileName = XUri.DoubleEncodeSegment((foldername + Path.DirectorySeparatorChar + file.Name).Replace("+", "%2b"));
                XUri   href            = DreamContext.Current.AsPublicUri(Self.At("doc", encodedFileName));
                result.Start("result").Elem("name", file.Name).Elem("href", href.ToString()).Elem("labelstyle", "iconitext-16 ext-" + file.Extension.TrimStart('.').ToLowerInvariant()).End();
            }

            response.Return(DreamMessage.Ok(result));
            yield break;
        }
Exemplo n.º 2
0
 public XUri PropertyUri(XUri parentUri)
 {
     if (ResourceType != Type.PROPERTY)
     {
         throw new InvalidOperationException("invalid operation for resource type");
     }
     return(parentUri.At("properties", XUri.DoubleEncodeSegment(Name)));
 }
Exemplo n.º 3
0
        private static void Publish(XUri uri, String login, String password, List <DreamCookie> cookies, string destination, XDoc overviewDoc, XDoc additionalInfoDoc)
        {
            string encodedPageName = XUri.DoubleEncodeSegment(destination);
            string plugPath        = "pages/=" + encodedPageName + "/contents?edittime=" + DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss");
            XDoc   pageContents    = null;

            // attempt to retrieve the page to determine if it already exists
            Plug         p   = Plug.New(uri).AtPath(plugPath);
            DreamMessage msg = DreamMessage.Ok();

            msg.Cookies.AddRange(cookies);
            msg = p.Get(msg, new Result <DreamMessage>()).Wait();

            switch (msg.Status)
            {
            case DreamStatus.Ok:

                // the page exists - update the auto-generated overview section
                plugPath    += "&section=1";
                pageContents = overviewDoc;
                break;

            case DreamStatus.NotFound:

                // the page does not yet exist - create it
                pageContents = overviewDoc;
                pageContents.AddNodes(additionalInfoDoc);
                break;

            default:
                throw new Exception("An error occurred during publishing:  " + msg.Status);
            }

            // save the page contents
            p   = Plug.New(uri).With("redirects", "0").AtPath(plugPath).WithCredentials(login, password);
            msg = DreamMessage.Ok(MimeType.TEXT, pageContents.ToInnerXHtml());
            msg.Cookies.AddRange(cookies);
            msg = p.Post(msg, new Result <DreamMessage>()).Wait();
            if (DreamStatus.Ok != msg.Status)
            {
                throw new Exception("An error occurred during publishing:  " + msg.Status);
            }
        }
Exemplo n.º 4
0
        public void ServiceTest()
        {
            string sid      = "http://services.mindtouch.com/dream/test/2007/03/sample";
            string sidInner = "http://services.mindtouch.com/dream/test/2007/03/sample-inner";

            _host.At("blueprints").Post(new XDoc("blueprint").Elem("assembly", "test.mindtouch.dream").Elem("class", "MindTouch.Dream.Test.SampleService"));
            _host.At("blueprints").Post(new XDoc("blueprint").Elem("assembly", "test.mindtouch.dream").Elem("class", "MindTouch.Dream.Test.SampleInnerService"));
            DreamServiceInfo info = DreamTestHelper.CreateService(_hostinfo,
                                                                  new XDoc("config")
                                                                  .Elem("path", "sample")
                                                                  .Elem("sid", sid)
                                                                  .Start("prologue")
                                                                  .Attr("name", "dummy")
                                                                  .Value("p0")
                                                                  .End()
                                                                  .Start("epilogue")
                                                                  .Attr("name", "dummy")
                                                                  .Value("e0")
                                                                  .End()
                                                                  .Elem("apikey", "xyz"));
            Plug service = info.AtLocalHost.With("apikey", "xyz");

            // TODO (steveb):
            //  1) check that http://localhost:8081/host/services contains the newly started service
            //  2) check that http://localhost:8081/host/services contains the inner service of the newly started service
            //  3) check that http://localhost:8081/host/sample has the expected prologues/epilogues
            //  4) check that http://localhost:8081/host/sample/inner has the 'sample' as owner
            //  5) check that http://localhost:8081/host/sample/inner has the expected prologues/epilogues

            service.Delete();

            //  6) check that http://localhost:8081/host/services does not contain the started service
            //  7) check that http://localhost:8081/host/services does not contain the inner service

            _host.At("blueprints", XUri.DoubleEncodeSegment(sid)).Delete();
            _host.At("blueprints", XUri.DoubleEncodeSegment(sidInner)).Delete();
        }
Exemplo n.º 5
0
        public XDoc Tree(
            [DekiExtParam("The top directory (default: root)", true)] string folder,
            [DekiExtParam("Specifies whether to include all directories or only the top directory (default: false)", true)] bool?topDirectoryOnly,
            [DekiExtParam("Search pattern (default: nil)", true)] string pattern
            )
        {
            if (_directoryInfo == null)
            {
                throw new DreamBadRequestException("folder is misconfigured");
            }

            string id = StringUtil.CreateAlphaNumericKey(8);

            if (null != folder && folder.Contains(".."))
            {
                throw new ArgumentException("Relative paths are not allowed", "folder");
            }

            // Construct the uri used to expand the root node
            XUri dynamicExpandUri = DreamContext.Current.AsPublicUri(null == folder ? Self.At("expand") : Self.At("expand", XUri.DoubleEncodeSegment(folder.Replace("+", "%2b")))).With("dream.out.format", "json");

            dynamicExpandUri = dynamicExpandUri.With("topDirectoryOnly", topDirectoryOnly.GetValueOrDefault(false).ToString());
            if (null != pattern)
            {
                dynamicExpandUri = dynamicExpandUri.With("pattern", pattern);
            }
            string yahooTreeScript =
                @"(function() {
     var tree;
     function treeInit() {
       tree = new YAHOO.widget.TreeView({id});
       tree.setDynamicLoad(loadNodeData);
       var root = tree.getRoot();
       var rootNode = new YAHOO.widget.TextNode({name}, root, true);
       rootNode.dynamicexpanduri = {dynamicexpanduri};
       tree.draw();
     }
     
     function makeChildNode(node, result) {
       var currentNode = new YAHOO.widget.TextNode(result.name, node, false);
       if (result.dynamicexpanduri != undefined) {
         currentNode.dynamicexpanduri = result.dynamicexpanduri;
       } else {
         currentNode.href = result.href;
         currentNode.labelStyle = result.labelstyle;
         currentNode.isLeaf = true; 
       }
     }

     function loadNodeData(node, fnLoadComplete) {
       if(node.dynamicexpanduri){
         $.get(node.dynamicexpanduri, null, function(r) {
           var response = (typeof r == 'string') ? eval('(' + (r || 0) +  ')') : r;
           if(response.result != undefined) {
             if(response.result.name != undefined) {
               makeChildNode(node, response.result);
             } else {
               for(var key in response.result) {
                 var entry = response.result[key];
                 if (entry.name != undefined) {
                   makeChildNode(node, entry);
                 }
               }
             }
           }
           fnLoadComplete();           
         });
       } else {
         fnLoadComplete();           
       }
     }
     YAHOO.util.Event.onDOMReady(treeInit);
   })();"
                .Replace("{id}", StringUtil.QuoteString(id))
                .Replace("{name}", StringUtil.QuoteString(null == folder ? _directoryInfo.FullName : (new DirectoryInfo(_directoryInfo.FullName + Path.DirectorySeparatorChar + folder).FullName)))
                .Replace("{dynamicexpanduri}", StringUtil.QuoteString(dynamicExpandUri.ToString()));

            // Load in the necessary yahoo resources and create a script element with the javascript for this control
            return(new XDoc("html").Start("head")
                   .Start("script").Attr("type", "text/javascript").Value(yahooTreeScript).End()
                   .Start("script").Attr("src", "http://yui.yahooapis.com/2.5.1/build/treeview/treeview-min.js").End()
                   .Start("link").Attr("type", "text/css").Attr("rel", "stylesheet").Attr("href", "http://yui.yahooapis.com/2.5.1/build/treeview/assets/skins/sam/treeview.css").End()
                   .End()
                   .Start("body").Start("div").Attr("id", id).End().End());
        }
Exemplo n.º 6
0
 public static string DoubleUrlEncode(string url)
 {
     return(XUri.DoubleEncodeSegment(url));
 }