示例#1
0
        public Yield Invoke(Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response)
        {
            // NOTE (steveb): we convert 'xri://@name/path?params' into 'http://xri.net/@name/path?params'

            // prepend segments with authority
            List<string> segments = new List<string>();
            segments.Add(uri.Authority);
            if(uri.Segments != null) {
                segments.AddRange(uri.Segments);
            }

            // build new plug
            List<PlugHandler> preHandlers = (plug.PreHandlers != null) ? new List<PlugHandler>(plug.PreHandlers) : null;
            List<PlugHandler> postHandlers = (plug.PostHandlers != null) ? new List<PlugHandler>(plug.PostHandlers) : null;
            Plug xri = new Plug(new XUri("http", null, null, "xri.net", 80, segments.ToArray(), uri.TrailingSlash, uri.Params, uri.Fragment), plug.Timeout, request.Headers, preHandlers, postHandlers, plug.Credentials, plug.CookieJar, plug.MaxAutoRedirects);

            // add 'Accept' header for 'application/xrds+xml' mime-type
            if((xri.Headers == null) || (xri.Headers.Accept == null)) {
                xri = xri.WithHeader(DreamHeaders.ACCEPT, MimeType.RenderAcceptHeader(MimeType.XRDS));
            }

            // BUGBUGBUG (steveb): this will probably fail in some cases since we may exit this coroutine before the call has completed!

            xri.InvokeEx(verb, request, response);
            yield break;
        }
示例#2
0
        protected CouchBase(XUri aBaseUri, string aUserName = null, string aPassword = null)
        {
            if (aBaseUri == null)
                throw new ArgumentNullException("aBaseUri");

            BasePlug = Plug.New(aBaseUri).WithCredentials(aUserName, aPassword);
        }
        // --- Constructors ---
        public RemoteInstanceManager(DekiWikiService dekiService, XUri directoryUri) : base(dekiService) {
            _directory = Plug.New(directoryUri);

            DreamMessage testMsg = _directory.GetAsync().Wait();
            if (!testMsg.IsSuccessful)
                throw new DreamInternalErrorException(string.Format("Error validating remote deki portal service at '{0}'", directoryUri.ToString()));
        }
示例#4
0
 //--- Methods ---
 private void CallbackHandler(Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response) {
     if(uri.Segments.Length == 0) {
         response.Return(DreamMessage.Ok());
         return;
     }
     var segments = uri.Segments;
     var wikiId = segments[0];
     if(wikiId.StartsWith("=")) {
         var id = (HostLookupOverride == null) ? DefaultWikiId : HostLookupOverride(wikiId.Substring(1));
         response.Return(DreamMessage.Ok(new XDoc("wiki").Attr("id", id)));
         return;
     }
     if(segments.Length == 2 && segments[1] == "license") {
         XDoc license;
         if(LicenseOverride == null) {
             _log.Debug("returning license from disk");
             license = XDocFactory.LoadFrom(Utils.Settings.LicensePath, MimeType.TEXT_XML);
         } else {
             _log.Debug("returning license from override callback");
             license = LicenseOverride(wikiId);
         }
         response.Return(DreamMessage.Ok(license));
         return;
     }
     var config = (ConfigOverride == null) ? DefaultConfig : ConfigOverride(wikiId);
     response.Return(DreamMessage.Ok(config));
 }
示例#5
0
        //--- Methods ---
        public override void Start(XDoc config) {
            base.Start(config);

            // create helper services
            _global = CreateService("$global", "http://services.mindtouch.com/dream/stable/2007/03/events");
            _users = CreateService("$users", "http://services.mindtouch.com/dream/stable/2007/03/directory");
        }
示例#6
0
        public static DreamMessage CreateRandomPage(Plug p, out string id)
        {
            string path = null;
            string title = GenerateUniquePageName();

            return PageUtils.SavePage(p, string.Empty, title, Utils.GetSmallRandomText(), out id, out path);
        }
示例#7
0
 //--- Constructors ---
 public LuceneResultFilter(Plug authPlug, int maxAuthItems, int minAuthItems) {
     if(authPlug == null) {
         throw new ArgumentNullException("authPlug");
     }
     _authPlug = authPlug;
     _maxAuthItems = maxAuthItems;
     _minAuthItems = minAuthItems;
 }
示例#8
0
 //--- Constructors ---
 private DreamApplication(DreamApplicationConfiguration appConfig)
 {
     _appConfig = appConfig;
     _env = new DreamHostService();
     Initialize();
     RegisterDefaultRoute();
     _self = Plug.New(_env.Self.Uri.AtAbsolutePath("/"));
 }
示例#9
0
        protected CouchBase(XUri baseUri, string username = null, 
      string password = null)
        {
            if (baseUri == null)
            throw new ArgumentNullException("baseUri");

              BasePlug = Plug.New(baseUri).WithCredentials(username, password);
        }
示例#10
0
 private string GetServiceIDBySID(Plug p, string sid) {
     DreamMessage msg = p.At("site", "services").With("limit","all").Get();
     foreach(XDoc service in msg.ToDocument()["service"]) {
         if(service["sid"].AsText == sid)
             return service["@id"].AsText;
     }
     return null;
 }
示例#11
0
        public static DreamMessage UploadRandomFile(Plug p, string pageid, byte[] content, string description, out string fileid, out string filename)
        {
            filename = FileUtils.CreateRamdomFile(content);
            DreamMessage msg = UploadFile(p, pageid, description, out fileid, filename);
            filename = msg.ToDocument()["filename"].AsText;
            Assert.IsFalse(string.IsNullOrEmpty(filename));

            return msg;
        }
示例#12
0
 //--- Constructors ---
 public DekiDispatcher(DispatcherConfig config, IPubSubDispatchQueueRepository repository)
     : base(config, repository) {
     _authtoken = config.ServiceConfig["authtoken"].AsText;
     var dekiUri = config.ServiceConfig["uri.deki"].AsUri;
     if(config.ServiceCookies != null) {
         _cookieJar.Update(config.ServiceCookies.Fetch(dekiUri), null);
     }
     _deki = Plug.New(dekiUri).WithCookieJar(_cookieJar);
 }
示例#13
0
 private static Yield Create_Helper(Plug dekiApi, XDoc exports, int relto, string reltopath, IPackageWriter packager, Result<ExportManager> result) {
     Result<Exporter> exporterResult;
     if(string.IsNullOrEmpty(reltopath)) {
         yield return exporterResult = Exporter.CreateAsync(dekiApi, exports, relto, new Result<Exporter>());
     } else {
         yield return exporterResult = Exporter.CreateAsync(dekiApi, exports, reltopath, new Result<Exporter>());
     }
     result.Return(new ExportManager(exporterResult.Value, packager));
     yield break;
 }
 public PageChangeCache(Plug deki, Action<string, Action> cacheItemCallback) {
     if(deki == null) {
         throw new ArgumentNullException("deki");
     }
     if(cacheItemCallback == null) {
         throw new ArgumentNullException("cacheItemCallback");
     }
    _cacheItemCallback = cacheItemCallback;
     _deki = deki;
 }
 public void FixtureSetup() {
     var builder = new ContainerBuilder();
     builder.Register(c => _searchBLFactory()).As<ISearchBL>().RequestScoped();
     _hostInfo = DreamTestHelper.CreateRandomPortHost(new XDoc("config").Elem("apikey", Utils.Settings.ApiKey), builder.Build());
     _hostInfo.Host.Self.At("load").With("name", "mindtouch.deki").Post(DreamMessage.Ok());
     _hostInfo.Host.Self.At("load").With("name", "mindtouch.deki.services").Post(DreamMessage.Ok());
     _hostInfo.Host.Self.At("load").With("name", "mindtouch.indexservice").Post(DreamMessage.Ok());
     _deki = DreamTestHelper.CreateService(_hostInfo, Utils.Settings.DekiConfig);
     _search = _deki.AtLocalHost.At("site", "query");
 }
示例#16
0
 protected override Yield Start(XDoc config, Result result) {
     Result res;
     yield return res = Coroutine.Invoke(base.Start, config, new Result());
     res.Confirm();
     var fs = new Result<Plug>();
     CreateService("mount", "http://services.mindtouch.com/dream/draft/2006/11/mount", 
         new XDoc("config").Start("mount").Attr("to", "files").Value("%DreamHost%").End(), fs);
     joinMeTL();
     _fs = fs.Value;
     result.Return();
 }
示例#17
0
        protected CouchBase(string connectionStringName)
        {
            ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings[connectionStringName];
            if(connectionString == null)
                throw new ArgumentException("Invalid connection string name");

            CouchDbConnectionStringBuilder cs = new CouchDbConnectionStringBuilder(connectionString.ConnectionString);

            BasePlug = Plug.New(String.Format("{0}://{1}:{2}",cs.SslEnabled ? "https" : "http", cs.Host, cs.Port))
                .WithCredentials(cs.UserName,cs.Password);
        }
 private static Yield Create_Helper(Plug dekiApi, int relto, string reltopath, IPackageReader packager, Result<ImportManager> result) {
     Result<XDoc> manifestResult;
     yield return manifestResult = packager.ReadManifest(new Result<XDoc>());
     Result<Importer> importerResult;
     if(string.IsNullOrEmpty(reltopath)) {
         yield return importerResult = Importer.CreateAsync(dekiApi, manifestResult.Value, relto, new Result<Importer>());
     } else {
         yield return importerResult = Importer.CreateAsync(dekiApi, manifestResult.Value, reltopath, new Result<Importer>());
     }
     result.Return(new ImportManager(importerResult.Value, packager));
     yield break;
 }
 public void GlobalInit() {
     _adminPlug = Utils.BuildPlugForAdmin();
     _log.DebugFormat("admin plug: {0}", _adminPlug.Uri.ToString());
     _userId = null;
     string subscriber = null;
     UserUtils.CreateRandomContributor(_adminPlug, out _userId, out subscriber);
     _log.DebugFormat("created contributor {0} ({1})", subscriber, _userId);
     _pageSubscriberPlug = Utils.BuildPlugForUser(subscriber);
     _log.DebugFormat("subscriber plug: {0}", _pageSubscriberPlug.Uri.ToString());
     _pageSub = _pageSubscriberPlug.At("pagesubservice");
     DreamMessage response = PageUtils.CreateRandomPage(_adminPlug);
     Assert.IsTrue(response.IsSuccessful);
 }
示例#20
0
        internal static XDoc ExecuteScript(Plug env, DreamHeaders headers, XDoc script) {

            // execute script commands
            XDoc reply = new XDoc("results");
            string ID = script["@ID"].Contents;
            if(!string.IsNullOrEmpty(ID)) {
                reply.Attr("ID", ID);
            }
            foreach(XDoc cmd in script.Elements) {
                reply.Add(ExecuteCommand(env, headers, cmd));
            }
            return reply;
        }
示例#21
0
        public static DreamMessage UploadFile(Plug p, string pageid, string description, out string fileid, string filename)
        {
            DreamMessage msg = DreamMessage.FromFile(filename);
            filename = XUri.DoubleEncode(System.IO.Path.GetFileName(filename));
            if (string.IsNullOrEmpty(description))
                msg = p.At("pages", pageid, "files", "=" + filename).Put(msg);
            else
                msg = p.At("pages", pageid, "files", "=" + filename).With("description", description).Put(msg);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            fileid = msg.ToDocument()["@id"].AsText;
            Assert.IsFalse(string.IsNullOrEmpty(fileid));

            return msg;
        }
示例#22
0
        //--- Constructors ---
        public RemoteInstanceManager(DekiWikiService dekiService, TaskTimerFactory timerFactory, XUri directoryUri, string tempPath) : base(dekiService, timerFactory) {

            // validate temp folder
            _tempPath = tempPath;
            if(!Directory.Exists(_tempPath)) {
                throw new ArgumentException("temp folder does not exist", "tempPath");
            }

            // check remote directory
            _directory = Plug.New(directoryUri);
            var testMsg = _directory.GetAsync().Wait();
            if(!testMsg.IsSuccessful) {
                _log.WarnFormat("Error validating remote deki portal service at '{0}'", directoryUri);
            }
        }
        //--- Methods ---
        protected override Yield Start(XDoc config, Result result) {
            yield return Coroutine.Invoke(base.Start, config, new Result());
            _varnish = Plug.New(Config["uri.varnish"].AsUri);
            _deki = Plug.New(Config["uri.deki"].AsUri);
            _apikey = Config["apikey"].AsText;
            _delayPurgeTimespan = TimeSpan.FromSeconds(config["varnish-purge-delay"].AsInt ?? 10);
            var dispatcher = new UpdateRecordDispatcher(OnQueueExpire);
            _updateDelayQueue = new UpdateDelayQueue(_delayPurgeTimespan, dispatcher);

            // set up subscription for pubsub
            XDoc subscriptionSet = new XDoc("subscription-set")
                .Elem("uri.owner", Self.Uri)
                .Start("subscription")
                    .Add(DreamCookie.NewSetCookie("service-key", InternalAccessKey, Self.Uri).AsSetCookieDocument)
                    .Elem("channel", "event://*/deki/pages/create")
                    .Elem("channel", "event://*/deki/pages/move")
                    .Elem("channel", "event://*/deki/pages/update")
                    .Elem("channel", "event://*/deki/pages/delete")
                    .Elem("channel", "event://*/deki/pages/revert")
                    .Elem("channel", "event://*/deki/pages/createalias")
                    .Elem("channel", "event://*/deki/pages/tags/update")
                    .Elem("channel", "event://*/deki/pages/dependentschanged/comments/create")
                    .Elem("channel", "event://*/deki/pages/dependentschanged/comments/update")
                    .Elem("channel", "event://*/deki/pages/dependentschanged/comments/delete")
                    .Elem("channel", "event://*/deki/pages/dependentschanged/files/create")
                    .Elem("channel", "event://*/deki/pages/dependentschanged/files/update")
                    .Elem("channel", "event://*/deki/pages/dependentschanged/files/delete")
                    .Elem("channel", "event://*/deki/pages/dependentschanged/files/move")
                    .Elem("channel", "event://*/deki/pages/dependentschanged/files/restore")
                    .Elem("channel", "event://*/deki/files/create")
                    .Elem("channel", "event://*/deki/files/update")
                    .Elem("channel", "event://*/deki/files/delete")
                    .Elem("channel", "event://*/deki/files/move")
                    .Elem("channel", "event://*/deki/files/restore")
                    .Start("recipient")
                        .Attr("authtoken", _apikey)
                        .Elem("uri", Self.Uri.At("queue"))
                    .End()
                .End();
            Result<DreamMessage> subscriptionResult;
            yield return subscriptionResult = PubSub.At("subscribers").PostAsync(subscriptionSet);
            string accessKey = subscriptionResult.Value.ToDocument()["access-key"].AsText;
            XUri location = subscriptionResult.Value.Headers.Location;
            Cookies.Update(DreamCookie.NewSetCookie("access-key", accessKey, location), null);
            _subscriptionLocation = location.AsLocalUri().WithoutQuery();
            _log.DebugFormat("subscribed VarnishPurgeService for events at {0}", _subscriptionLocation);
            result.Return();
        }
示例#24
0
 private static Yield Create_Helper(Plug dekiApi, XDoc exports, int exportRelto, string exportReltoPath, int importRelto, string importReltoPath, bool forceOverwrite, Result<BulkCopy> result) {
     Result<Exporter> exporterResult;
     if(string.IsNullOrEmpty(exportReltoPath)) {
         yield return exporterResult = Exporter.CreateAsync(dekiApi, exports, exportRelto, new Result<Exporter>());
     } else {
         yield return exporterResult = Exporter.CreateAsync(dekiApi, exports, exportReltoPath, new Result<Exporter>());
     }
     Exporter exporter = exporterResult.Value;
     Result<Importer> importerResult;
     if(string.IsNullOrEmpty(importReltoPath)) {
         yield return importerResult = Importer.CreateAsync(dekiApi, exporter.Manifest, importRelto, forceOverwrite, new Result<Importer>());
     } else {
         yield return importerResult = Importer.CreateAsync(dekiApi, exporter.Manifest, importReltoPath, forceOverwrite, new Result<Importer>());
     }
     BulkCopy bulkCopy = new BulkCopy(exporter, importerResult.Value);
     result.Return(bulkCopy);
 }
示例#25
0
        private void AddNewUserToXml(Plug p, string serviceid, string username, string password) {
            DreamMessage msg = p.At("site", "services", serviceid).Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            string filename = msg.ToDocument()["config/value[@key='xmlauth-path']"].AsText;

            XDoc xdoc = XDocFactory.LoadFrom(filename, MimeType.XML);
            xdoc["users"]
                    .Start("user").Attr("name", username)
                        .Start("password").Attr("type", "plain").Value(password).End()
                        .Elem("email", username + "@somewhere.com")
                        .Elem("fullname", username)
                        .Elem("status", "enabled")
                    .End();

            xdoc.Save(filename);
        }
示例#26
0
 //--- Constructors ---
 /// <summary>
 /// Create new client instance 
 /// </summary>
 /// <param name="config">Client configuration.</param>
 /// <param name="timerFactory">Timer factory.</param>
 public AwsS3Client(AwsS3ClientConfig config, TaskTimerFactory timerFactory)
 {
     _config = config;
     _bucketPlug = Plug.New(_config.Endpoint.S3Uri)
         .WithS3Authentication(_config.PrivateKey, _config.PublicKey)
         .WithTimeout(_config.Timeout)
         .At(_config.Bucket);
     _rootPlug = _bucketPlug;
     if(!string.IsNullOrEmpty(_config.RootPath)) {
         _keyRootParts = _config.RootPath.Split(new[] { config.Delimiter }, StringSplitOptions.RemoveEmptyEntries);
         if(_keyRootParts.Any()) {
             _rootPlug = _rootPlug.At(_keyRootParts);
         }
     }
     _expirationEntries = new ExpiringHashSet<string>(timerFactory);
     _expirationEntries.EntryExpired += OnDelete;
 }
示例#27
0
        public static DreamMessage SavePage(Plug p, 
            string parentPath, 
            string pageTitle, 
            string content,
            out string id,
            out string path)
        {
            string sEditTime = null;
            DreamMessage msg = PageUtils.GetPage(p, parentPath + pageTitle);
            if (msg.Status == DreamStatus.Ok)
            {
                DateTime edittime = msg.ToDocument()["/page/date.edited"].AsDate ?? DateTime.MinValue;
                sEditTime = Utils.DateToString(edittime);
            }

            return SavePage(p, parentPath, pageTitle, content, sEditTime, out id, out path);
        }
示例#28
0
        private int CreateDekiPage(Plug p, string pagePath, string pageTitle, DateTime? modified, string content,
            out string dekiPageUrl)
        {

            Log.DebugFormat("Creating page: '{0}' Content? {1}", XUri.DoubleDecode(pagePath), !string.IsNullOrEmpty(content));

            Plug pagePlug = p.At("pages", "=" + pagePath, "contents");
            pagePlug = pagePlug.With("abort", "never");
            modified = modified ?? DateTime.Now;
            string editTime = Utils.FormatPageDate(modified.Value.ToUniversalTime());
            pagePlug = pagePlug.With("edittime", editTime);
            pagePlug = pagePlug.With("comment", "Created at " + modified.Value.ToShortDateString() + " " + modified.Value.ToShortTimeString());
            if (pageTitle != null)
            {
                pagePlug = pagePlug.With("title", pageTitle);
            }
            DreamMessage msg = DreamMessage.Ok(MimeType.TEXT_UTF8, content);

            DreamMessage res = pagePlug.PostAsync(msg).Wait();
            if (res.Status != DreamStatus.Ok)
            {
                WriteLineToConsole("Error converting page \"" + XUri.DoubleDecode(pagePath) + "\"");
                WriteLineToLog("Edit time: " + editTime);
                WriteLineToLog("Page title: " + pageTitle);
                WriteErrorResponse(res);
                WriteErrorRequest(msg);
            }
            else
            {
                XDoc createdPage = res.AsDocument();
                int pageId = createdPage["page/@id"].AsInt.Value;

                //dekiPageUrl = createdPage["page/path"].AsText;
                
                //Using the uri.ui instead of path to not worry about encodings for links
                //But this makes the values (mt urls) in the link mapping table unsuitable for page paths 
                //(such as those used in dekiscript for macros). Those need to be converted to paths 
                // via Utils.ConvertPageUriToPath
                dekiPageUrl = createdPage["page/uri.ui"].AsText;

                return pageId;
            }
            dekiPageUrl = null;
            return -1;
        }       
示例#29
0
 //--- Methods ---
 internal static XDoc ExecuteCommand(Plug env, DreamHeaders headers, XDoc cmd) {
     try {
         switch(cmd.Name.ToLowerInvariant()) {
         case "script":
             return ExecuteScript(env, headers, cmd);
         case "fork":
             return ExecuteFork(env, headers, cmd);
         case "action":
             return ExecuteAction(env, headers, cmd);
         case "pipe":
             return ExecutePipe(env, headers, cmd);
         default:
             throw new DreamException(string.Format("unregonized script command: " + cmd.Name.ToString()));
         }
     } catch(Exception e) {
         return new XException(e);
     }
 }
示例#30
0
        public static DreamMessage CreateUser(Plug p, string role, string password, out string id, string name, string email)
        {
            XDoc usersDoc = new XDoc("user")
                .Elem("username", name)
                .Elem("email", email)
                .Elem("fullname", name + "'s full name")
                .Start("permissions.user")
                    .Elem("role", role)
                .End();

            DreamMessage msg = p.At("users").With("accountpassword", password).PostAsync(usersDoc).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "POST: users with password returned non 200 status: "+msg.ToString());
            name = msg.ToDocument()["username"].AsText;
            Assert.IsTrue(!string.IsNullOrEmpty(name));
            id = msg.ToDocument()["@id"].AsText;
            Assert.IsTrue(!string.IsNullOrEmpty(id));

            return msg;
        }
示例#31
0
        public DreamMessage PostPasteHandler(DreamContext context, DreamMessage message)
        {
            XDoc xhtml = message.ContentType.Contains("/html")
                ? XDoc.FromHtml(new StreamReader(message.Stream, message.ContentEncoding))
                : message.Document;

            if (xhtml == null || xhtml.IsEmpty)
            {
                LogUtils.LogWarning(_log, "PostEditHandler: null/empty input document");
                throw new DreamAbortException(DreamMessage.BadRequest("null/empty input document"));
            }
            string baseHref = context.Uri.GetParam("baseHref", 0, "http://mos/");
            string pageID   = context.Uri.GetParam("context", "");

            XHTMLConverter.Convert(xhtml, baseHref, pageID, true);

            MindTouch.Dream.Plug plug = MindTouch.Dream.Plug.New(Env.RootUri);
            foreach (XDoc nodeWithClass in xhtml["//*[@class='vcard']"])
            {
                XDoc replacement = plug.At("wiki-data", "dekibizcard", "hcardtoedit").Post(nodeWithClass).Document;
                if (replacement != null && !replacement.IsEmpty)
                {
                    nodeWithClass.Replace(replacement);
                }
            }

            bool insertMagic = context.Uri.GetParam <bool>("insertMagic", false);

            if (insertMagic)
            {
                Plug widgetStorage = Plug.New(Env.RootUri).At("mount", "deki-widgets");
                Plug widgetToEdit  = Plug.New(Env.RootUri.At("wiki-data", "dekibizcard", "edit"));
                XDoc files         = widgetStorage.With("pattern", "*.vcf").Get().Document;
                foreach (XDoc fileName in files["file/name"])
                {
                    XDoc vcard       = XDoc.FromVersit(widgetStorage.At(fileName.Contents).Get().Text, "dekibizcard");
                    XDoc widgetXhtml = widgetToEdit.Post(vcard).Document;
                    xhtml["//body"].Add(widgetXhtml);
                }
            }
            return(DreamMessage.Ok(MimeType.HTML, xhtml.ToString()));
        }