当前位置: 首页>>代码示例>>C#>>正文


C# Plug.At方法代码示例

本文整理汇总了C#中MindTouch.Dream.Plug.At方法的典型用法代码示例。如果您正苦于以下问题:C# Plug.At方法的具体用法?C# Plug.At怎么用?C# Plug.At使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MindTouch.Dream.Plug的用法示例。


在下文中一共展示了Plug.At方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetServiceIDBySID

 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;
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:8,代码来源:XmlAuthTests.cs

示例2: GlobalInit

 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);
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:13,代码来源:DekiChangeSubscriptionExtTests.cs

示例3: ConnectToDeki

        public void ConnectToDeki(string dreamAPI, string dekiUserName, string dekiUserPassword)
        {
            this._dreamAPI = dreamAPI;
            this._dekiPlug = Plug.New(_dreamAPI).WithCredentials(dekiUserName, dekiUserPassword);

            DreamMessage authResponse = _dekiPlug.At("users", "authenticate").GetAsync().Wait();
            if(!authResponse.IsSuccessful) {
                Log.FatalFormat("Could not connect to MT API '{0}' username: '{1}' password: '{2}' Error:", _dekiPlug.ToString(), dekiUserName, dekiUserPassword, authResponse.ToString());
                throw new DreamAbortException(authResponse);
            }

            //Check that user have admin rights
            DreamMessage userResponse = _dekiPlug.At("users", "=" + Utils.DoubleUrlEncode(dekiUserName)).Get();
            XDoc resDoc = userResponse.AsDocument();
            string roleName = resDoc["permissions.user/role"].AsText;
            if ((roleName == null) || (roleName.ToLower() != "admin"))
            {
                WriteLineToConsole("User " + dekiUserName + " should have Admin role in Deki.");
                return;
            }

            _connectedToDeki = true;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:23,代码来源:ACConverter.Connections.cs

示例4: AddNewUserToXml

        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);
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:17,代码来源:XmlAuthTests.cs

示例5: AwsS3Client

 //--- 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;
 }
开发者ID:bjorg,项目名称:DReAM,代码行数:23,代码来源:AwsS3Client.cs

示例6: CreateDekiPage

        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;
        }       
开发者ID:heran,项目名称:DekiWiki,代码行数:45,代码来源:ACConverter.DekiWrapper.cs

示例7: CreateUser

        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;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:19,代码来源:UserUtils.cs

示例8: CreateDekiPageHistory

        private int CreateDekiPageHistory(Plug p, string pagePath, string pageTitle, DateTime? modified, string content,
           out string dekiPageUrl)
        {

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

            Plug pagePlug = p.At("pages", "=" + pagePath, "revision");
            pagePlug = pagePlug.With("abort", "never");
            modified = modified ?? DateTime.Now;
            string editTime = Utils.FormatPageDate(modified.Value.ToUniversalTime());
            pagePlug = pagePlug.With("edittime", editTime);
            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);
                Log.WarnFormat("Error converting page: '{0}'. Request: {0}    \nResponse: {1}", msg.ToString(), res.ToString());
            }
            else
            {
                XDoc createdPage = res.AsDocument();
                int pageId = createdPage["page/@id"].AsInt.Value;
                dekiPageUrl = createdPage["page/path"].AsText;

                return pageId;
            }
            dekiPageUrl = null;
            return -1;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:38,代码来源:ACConverter.PageHistory.cs

示例9: SetMembersForGroup

        public static DreamMessage SetMembersForGroup(Plug p, string groupid, string[] memberUserIds)
        {
            XDoc usersDoc = new XDoc("users");
            foreach (string  userid in memberUserIds)
	        {
                usersDoc.Start("user")
                    .Attr("id", userid)
                .End();
	        }
            DreamMessage msg = p.At("groups", groupid, "users").Put(usersDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            return msg;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:14,代码来源:UserUtils.cs

示例10: CreateGroup

        public static DreamMessage CreateGroup(Plug p, string role, string[] memberUserIds, out string id, string name)
        {
            XDoc groupDoc = new XDoc("group")
                .Elem("groupname", name)
                .Start("permissions.group")
                    .Elem("role", role)
                .End();

            if (memberUserIds != null && memberUserIds.Length > 0)
            {
                groupDoc.Start("users");
                foreach (string userid in memberUserIds)
                    groupDoc.Start("user").Attr("id", userid).End();
                groupDoc.End();
            }

            DreamMessage msg = p.At("groups").Post(groupDoc);
            id = msg.ToDocument()["@id"].AsText;
            return msg;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:20,代码来源:UserUtils.cs

示例11: SavePage

        public static DreamMessage SavePage(Plug p, 
            string parentPath, 
            string pageTitle, 
            string content, 
            string edittime, 
            out string id,
            out string path)
        {
            string title = pageTitle;
            if (parentPath != string.Empty)
                title = parentPath + pageTitle;

            title = "=" + XUri.DoubleEncode(title);

            p = p.At("pages", title, "contents");
            if (!string.IsNullOrEmpty(edittime))
                p = p.With("edittime", edittime);

            DreamMessage msg = p.PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, content)).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page creation failed!");
            id = msg.ToDocument()["page/@id"].AsText;
            path = msg.ToDocument()["page/path"].AsText;
            Assert.IsTrue(!string.IsNullOrEmpty(path), "Page path is null!");
            Assert.IsTrue(!string.IsNullOrEmpty(id), "Page ID is null!");

            return msg;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:27,代码来源:PageUtils.cs

示例12: DeleteWithSubPage

        private void DeleteWithSubPage(Plug p, string suffix)
        {
            string path = PageUtils.GenerateUniquePageName() + suffix;
            DreamMessage msg = PageUtils.CreateRandomPage(p, path);
            string id = msg.ToDocument()["page/@id"].AsText;

            msg = PageUtils.CreateRandomPage(p, path + "/" + Utils.GenerateUniqueName());
            string subid = msg.ToDocument()["page/@id"].AsText;
            string subpath = msg.ToDocument()["page/path"].AsText;

            msg = PageUtils.DeletePageByID(p, id, false);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("pages", "=" + XUri.DoubleEncode(subpath)).GetAsync().Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            //Assert.IsFalse(msg.ToDocument()[string.Format("page/subpages//page/subpages/page[@id=\"{0}\"]", subid)].IsEmpty);
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:18,代码来源:DeleteTests.cs

示例13: DreamHost

        /// <summary>
        /// Create a new host with provided configuration and an Inversion of Control container.
        /// </summary>
        /// <remarks>
        /// The IoC container is also injected into default activator, so that <see cref="IDreamService"/> instances
        /// can be resolved from the container. The host configuration is provided to the container as a typed parameter.
        /// </remarks>
        /// <param name="config">Host configuration.</param>
        /// <param name="container">IoC Container.</param>
        public DreamHost(XDoc config, IContainer container) {
            if(config == null) {
                throw new ArgumentNullException("config");
            }

            // read host settings
            string appDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
            int limit = config["connect-limit"].AsInt ?? 0;
            int httpPort = config["http-port"].AsInt ?? DEFAULT_PORT;
            AuthenticationSchemes authenticationScheme = AuthenticationSchemes.Anonymous;
            string authShemes = config["authentication-shemes"].AsText;
            if(!String.IsNullOrEmpty(authShemes)) {
                try {
                    authenticationScheme = (AuthenticationSchemes)Enum.Parse(typeof(AuthenticationSchemes), authShemes, true);
                } catch(Exception e) {
                    _log.Warn(String.Format("invalid authetication scheme specified :{0}", authShemes), e);
                }
            }

            // get the authtoken for whitelisting dream.in.* query args
            _dreamInParamAuthtoken = config["dream.in.authtoken"].AsText;
            if(!string.IsNullOrEmpty(_dreamInParamAuthtoken)) {
                _log.Debug("Host is configured in dream.in param authorizing mode");
            }

            // read ip-addresses
            var addresses = new List<string>();
            foreach(XDoc ip in config["host|ip"]) {
                addresses.Add(ip.AsText);
            }
            if(addresses.Count == 0) {

                // if no addresses were supplied listen to all
                addresses.Add("*:" + httpPort);
            }

            // use default servername
            XUri publicUri = config["uri.public"].AsUri;
            if(publicUri == null) {

                // backwards compatibility
                publicUri = config["server-name"].AsUri;
                if(publicUri == null) {
                    foreach(IPAddress addr in Dns.GetHostAddresses(Dns.GetHostName())) {
                        if(addr.AddressFamily == AddressFamily.InterNetwork) {
                            XUri.TryParse("http://" + addr, out publicUri);
                        }
                    }
                    if(publicUri == null) {
                        // failed to get an address out of dns, fall back to localhost
                        XUri.TryParse("http://localhost", out publicUri);
                    }
                }
                publicUri = publicUri.AtPath(config["server-path"].AsText ?? config["path-prefix"].AsText ?? string.Empty);
            }

            // create environment and initialize it
            _env = new DreamHostService(container);
            try {

                // initialize environment
                string apikey = config["apikey"].AsText ?? StringUtil.CreateAlphaNumericKey(32);
                XDoc serviceConfig = new XDoc("config");
                var storageType = config["storage/@type"].AsText ?? "local";
                if("s3".EqualsInvariant(storageType)) {
                    serviceConfig.Add(config["storage"]);
                } else {
                    serviceConfig.Elem("storage-dir", config["storage-dir"].AsText ?? config["service-dir"].AsText ?? appDirectory);
                }
                serviceConfig.Elem("apikey", apikey);
                serviceConfig.Elem("uri.public", publicUri);
                serviceConfig.Elem("connect-limit", limit);
                serviceConfig.Elem("guid", config["guid"].AsText);
                serviceConfig.AddAll(config["components"]);
                var memorize = config["memorize-aliases"];
                if(!memorize.IsEmpty) {
                    serviceConfig.Elem("memorize-aliases", memorize.AsBool);
                }
                _env.Initialize(serviceConfig);

                // initialize host plug
                _host = _env.Self.With("apikey", apikey);

                // load assemblies in 'services' folder
                string servicesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "services");
                if(Directory.Exists(servicesFolder)) {

                    // Note (arnec): Deprecated, but the suggested alternative really doesn't apply since we don't want to
                    // load services into a separate appdomain.
#pragma warning disable 618,612
                    AppDomain.CurrentDomain.AppendPrivatePath("services");
//.........这里部分代码省略.........
开发者ID:nataren,项目名称:DReAM,代码行数:101,代码来源:DreamHost.cs

示例14: TagPage

 public static DreamMessage TagPage(Plug p, string pageId, string[] tags) {
     var doc = new XDoc("tags");
     doc = tags.Aggregate(doc, (current, tag) => current.Start("tag").Attr("value", tag).End());
     return p.At("pages", pageId, "tags").Put(doc);
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:5,代码来源:PageUtils.cs

示例15: RetrieveConfig

 public static DreamMessage RetrieveConfig(Plug p)
 {
     DreamMessage msg = p.At("site", "settings").Get(new Result<DreamMessage>()).Wait();
     Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve site settings");
     return msg;
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:6,代码来源:SiteUtils.cs


注:本文中的MindTouch.Dream.Plug.At方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。