/// <summary> /// Interpreta un nodo XML con un mensaje /// </summary> private static DirectMessage Parse(MLNode objMLMessage) { DirectMessage objMessage = new DirectMessage(); // Obtiene los datos del mensaje objMessage.ID = objMLMessage.Nodes[cnstStrTagID].GetValue(0); objMessage.SenderID = objMLMessage.Nodes[cnstStrTagSenderID].GetValue(0); objMessage.Text = objMLMessage.Nodes[cnstStrTagText].Value; objMessage.RecipientID = objMLMessage.Nodes[cnstStrTagRecipientID].GetValue(0); objMessage.CreatedAt = objMLMessage.Nodes[cnstStrTagCreatedAt].Value; objMessage.SenderScreenName = objMLMessage.Nodes[cnstStrTagSenderScreenName].Value; objMessage.RecipientScreenName = objMLMessage.Nodes[cnstStrTagRecipientScreenName].Value; // Obtiene el emisor y el receptor if (!string.IsNullOrEmpty(objMLMessage.Nodes[cnstStrTagSender].Name)) objMessage.Sender = UserParser.Parse(objMLMessage.Nodes[cnstStrTagSender]); if (!string.IsNullOrEmpty(objMLMessage.Nodes[cnstStrTagRecipient].Name)) objMessage.Recipient = UserParser.Parse(objMLMessage.Nodes[cnstStrTagRecipient]); // Devuelve el mensaje return objMessage; }
/// <summary> /// Interpreta un nodo con un estado /// </summary> internal static Status Parse(MLNode objMLStatus) { Status objStatus = new Status(); // Asigna las propiedades objStatus.CreatedAt = objMLStatus.Attributes[cnstStrTagCreatedAt].Value; objStatus.ID = objMLStatus.Attributes[cnstStrTagID].GetValue((long) 0); objStatus.Text = objMLStatus.Attributes[cnstStrTagText].Value; objStatus.Source = objMLStatus.Attributes[cnstStrTagSource].Value; objStatus.Truncated = objMLStatus.Attributes[cnstStrTagTruncated].GetValue(false); objStatus.InReplyToStatusID = objMLStatus.Attributes[cnstStrTagInReplyToStatusID].GetValue(0); objStatus.InReplyToUserID = objMLStatus.Attributes[cnstStrTagInReplyToUserID].GetValue(0); objStatus.Favorited = objMLStatus.Attributes[cnstStrTagFavorited].GetValue(false); objStatus.InReplyToUserID = objMLStatus.Attributes[cnstStrTagInReplyToScreenName].GetValue(0); // Carga los datos del usuario if (!string.IsNullOrEmpty(objMLStatus.Nodes[UserParser.cnstStrTagUser].Name)) objStatus.User = UserParser.Parse(objMLStatus.Nodes[UserParser.cnstStrTagUser]); // Devuelve el estado return objStatus; }
/// <summary> /// Interpreta un nodo XML con un usuario /// </summary> internal static User Parse(MLNode objMLUser) { User objUser = new User(); // Obtiene los datos del usuario objUser.ID = objMLUser.Attributes[cnstStrTagID].GetValue(0); objUser.Name = objMLUser.Attributes[cnstStrTagName].Value; objUser.ScreenName = objMLUser.Attributes[cnstStrTagScreenName].Value; objUser.Location = objMLUser.Attributes[cnstStrTagLocation].Value; objUser.Description = objMLUser.Attributes[cnstStrTagDescription].Value; objUser.ProfileImage = objMLUser.Attributes[cnstStrTagProfileImageUrl].Value; objUser.Url = objMLUser.Attributes[cnstStrTagUrl].Value; objUser.IsProtected = objMLUser.Attributes[cnstStrTagProtected].GetValue(false); objUser.FollowersCount = objMLUser.Attributes[cnstStrTagFollowersCount].GetValue(0); objUser.ProfileBackgroundColor = objMLUser.Attributes[cnstStrTagProfileBackgroundColor].Value; objUser.ProfileTextColor = objMLUser.Attributes[cnstStrTagProfileTextColor].Value; objUser.ProfileLinkColor = objMLUser.Attributes[cnstStrTagProfileLinkColor].Value; objUser.ProfileSidebarFillColor = objMLUser.Attributes[cnstStrTagProfileSidebarFillColor].Value; objUser.ProfileSidebarBordeColor = objMLUser.Attributes[cnstStrTagProfileSidebarBorderColor].Value; objUser.FriendsCount = objMLUser.Attributes[cnstStrTagFriendsCount].GetValue(0); objUser.CreatedAt = objMLUser.Attributes[cnstStrTagCreatedAt].Value; objUser.FavoritesCount = objMLUser.Attributes[cnstStrTagFavoritesCount].GetValue(0); objUser.UtcOffset = objMLUser.Attributes[cnstStrTagUtcOfsset].GetValue(0); objUser.TimeZone = objMLUser.Attributes[cnstStrTagTimeZone].Value; objUser.ProfileBackgroundImageUrl = objMLUser.Attributes[cnstStrTagProfileBackgroundImageUrl].Value; objUser.ProfileBackgroundTitle = objMLUser.Attributes[cnstStrTagProfileBackgroundTitle].Value; objUser.Notifications = objMLUser.Attributes[cnstStrTagNotifications].Value; objUser.GeoEnabled = objMLUser.Attributes[cnstStrTagGeoEnabled].GetValue(false); objUser.Verified = objMLUser.Attributes[cnstStrTagVerified].GetValue(false); objUser.Following = objMLUser.Attributes[cnstStrTagFolloging].GetValue(false); objUser.StatusCount = objMLUser.Attributes[cnstStrTagStatusesCount].GetValue(0); objUser.Language = objMLUser.Attributes[cnstStrTagLang].Value; objUser.ContributorsEnabled = objMLUser.Attributes[cnstStrTagContributorsEnabled].GetValue(false); // Obtiene el estado if (!string.IsNullOrEmpty(objMLUser.Nodes[StatusParser.cnstStrTagStatus].Name)) objUser.Status = StatusParser.Parse(objMLUser.Nodes[StatusParser.cnstStrTagStatus]); // Devuelve el usuario return objUser; }
/// <summary> /// Interpreta un nodo XML con un usuario /// </summary> private static Trend Parse(MLNode objMLNode) { Trend objTrend = new Trend(); // Obtiene los datos del usuario objTrend.Name = objMLNode.Nodes[cnstStrTagName].Value; objTrend.URL = objMLNode.Nodes[cnstStrTagUrl].Value; // Devuelve la tendencia return objTrend; }
/// <summary> /// Carga los datos de una instrucción /// </summary> private Instruction LoadInstruction(MLNode objMLNode) { Instruction objInstruction = new Instruction(); // Obtiene los datos de la instrucción objInstruction.Name = objMLNode.Nodes[cnstStrTagMessageName].Value; objInstruction.Request.Method = (RequestMessage.MethodType) objMLNode.Nodes[cnstStrTagMessageMethod].GetValue((int) RequestMessage.MethodType.Post); objInstruction.Request.URL = objMLNode.Nodes[cnstStrTagMessageURL].Value; objInstruction.Request.ContentType = objMLNode.Nodes[cnstStrTagMessageContentType].Value; // Obtiene los parámetros y nombres de archivos foreach (MLNode objMLChild in objMLNode.Nodes) switch (objMLChild.Name) { case cnstStrTagMessageQueryParameter: objInstruction.Request.QueryParameters.Add(objMLChild.Attributes[cnstStrTagMessageAttrName].Value, objMLChild.Attributes[cnstStrTagMessageAttrValue].Value); break; case cnstStrTagMessageHeader: objInstruction.Request.Headers.Add(objMLChild.Attributes[cnstStrTagMessageAttrName].Value, objMLChild.Attributes[cnstStrTagMessageAttrValue].Value); break; case cnstStrTagMessageFileName: objInstruction.Request.Attachments.Add(objMLChild.Value); break; } // Devuelve la instrucción return objInstruction; }
/// <summary> /// Carga los datos de contexto /// </summary> private RestController LoadContext(MLNode objMLNode) { RestController objContext = new RestController("Agent"); // Carga los datos objContext.UserAgent = objMLNode.Nodes[cnstStrTagContextUserAgent].Value; objContext.TimeOut = objMLNode.Nodes[cnstStrTagContextTimeOut].GetValue(20000); objContext.Proxy.Enabled = objMLNode.Nodes[cnstStrTagContextProxyEnabled].Value.GetBool(); objContext.Proxy.Address = objMLNode.Nodes[cnstStrTagContextProxyAddress].Value; objContext.Proxy.Port = objMLNode.Nodes[cnstStrTagContextProxyPort].Value.GetInt(0); objContext.Proxy.User = objMLNode.Nodes[cnstStrTagContextProxyUser].Value; objContext.Proxy.Password = objMLNode.Nodes[cnstStrTagContextProxyPassword].Value; objContext.Proxy.MustBypassLocal = objMLNode.Nodes[cnstStrTagContextProxyByPassLocal].GetValue(false); // Devuelve los datos de contexto return objContext; }
/// <summary> /// Carga los datos de autentificación plano /// </summary> private IAuthenticator LoadAuthenticationPlain(MLNode objMLChild) { return new PlainAuthenticator(objMLChild.Nodes[cnstStrTagAuthPlainUser].Value, objMLChild.Nodes[cnstStrTagAuthPlainPassword].Value); }
/// <summary> /// Carga los datos de autentificación plano /// </summary> private IAuthenticator LoadAuthenticationOAuth(MLNode objMLChild) { oAuthAuthenticator objAuthenticator = new oAuthAuthenticator(); // Asigna los datos objAuthenticator.ConsumerKey = objMLChild.Nodes[cnstStrTagAuthOAuthConsumerKey].Value; objAuthenticator.ConsumerSecret = objMLChild.Nodes[cnstStrTagAuthOAuthConsumerSecret].Value; objAuthenticator.AccessToken = objMLChild.Nodes[cnstStrTagAuthOAuthAccessToken].Value; objAuthenticator.AccessTokenSecret = objMLChild.Nodes[cnstStrTagAuthOAuthAccessTokenSecret].Value; // Devuelve el autentificador return objAuthenticator; }
/// <summary> /// Obtiene un nodo para parámetros o cabeceras /// </summary> private MLNode GetNodeKey(string strHeader, string strKey, string strValue) { MLNode objMLNode = new MLNode(strHeader); // Añade los atributos objMLNode.Attributes.Add(cnstStrTagMessageAttrName, strKey); objMLNode.Attributes.Add(cnstStrTagMessageAttrValue, strValue); // Devuelve el nodo return objMLNode; }
/// <summary> /// Añade los nodos de la instrucción /// </summary> private void AddNodesMessage(MLNode objMLNode, Instruction objInstruction) { MLNode objMLChild = objMLNode.Nodes.Add(cnstStrTagMessage); // Obtiene los datos de la instrucción objMLChild.Nodes.Add(cnstStrTagMessageName, objInstruction.Name); objMLChild.Nodes.Add(cnstStrTagMessageMethod, (int) objInstruction.Request.Method); objMLChild.Nodes.Add(cnstStrTagMessageURL, objInstruction.Request.URL); objMLChild.Nodes.Add(cnstStrTagMessageContentType, objInstruction.Request.ContentType); // Añade los parámetros, cabeceras y nombres de archivos foreach (ParameterData objQueryParameter in objInstruction.Request.QueryParameters) objMLChild.Nodes.Add(GetNodeKey(cnstStrTagMessageQueryParameter, objQueryParameter.Key, objQueryParameter.Value)); foreach (Header objHeader in objInstruction.Request.Headers) objMLChild.Nodes.Add(GetNodeKey(cnstStrTagMessageHeader, objHeader.Key, objHeader.Value)); foreach (Attachment objAttachment in objInstruction.Request.Attachments) objMLChild.Nodes.Add(cnstStrTagMessageFileName, objAttachment.FileName); }
/// <summary> /// Añade los nodos de contexto /// </summary> private void AddNodesContext(MLNode objMLNode, RestController objContext) { MLNode objMLChild = objMLNode.Nodes.Add(cnstStrTagContext); // Añade los nodos de contexto objMLChild.Nodes.Add(cnstStrTagContextUserAgent, objContext.UserAgent); objMLChild.Nodes.Add(cnstStrTagContextTimeOut, objContext.TimeOut); objMLChild.Nodes.Add(cnstStrTagContextProxyEnabled, objContext.Proxy.Enabled); objMLChild.Nodes.Add(cnstStrTagContextProxyAddress, objContext.Proxy.Address); objMLChild.Nodes.Add(cnstStrTagContextProxyPort, objContext.Proxy.Port); objMLChild.Nodes.Add(cnstStrTagContextProxyUser, objContext.Proxy.User); objMLChild.Nodes.Add(cnstStrTagContextProxyPassword, objContext.Proxy.Password); objMLChild.Nodes.Add(cnstStrTagContextProxyByPassLocal, objContext.Proxy.MustBypassLocal); }
/// <summary> /// Añade los nodos de autentificación plano /// </summary> private void AddNodesAuthentificationPlain(MLNode objMLNode, PlainAuthenticator objAuthenticator) { MLNode objMLAuth = objMLNode.Nodes.Add(cnstStrTagAuthPlain); objMLAuth.Nodes.Add(cnstStrTagAuthPlainUser, objAuthenticator.User); objMLAuth.Nodes.Add(cnstStrTagAuthPlainPassword, objAuthenticator.Password); }
/// <summary> /// Añade los nodos de autentificación oAuth /// </summary> private void AddNodesAuthentificationOAuht(MLNode objMLNode, oAuthAuthenticator objAuthenticator) { MLNode objMLAuth = objMLNode.Nodes.Add(cnstStrTagAuthOAuth); objMLAuth.Nodes.Add(cnstStrTagAuthOAuthConsumerKey, objAuthenticator.ConsumerKey); objMLAuth.Nodes.Add(cnstStrTagAuthOAuthConsumerSecret, objAuthenticator.ConsumerSecret); objMLAuth.Nodes.Add(cnstStrTagAuthOAuthAccessToken, objAuthenticator.AccessToken); objMLAuth.Nodes.Add(cnstStrTagAuthOAuthAccessTokenSecret, objAuthenticator.AccessTokenSecret); }
/// <summary> /// Añade los nodos de autentificación /// </summary> private void AddNodesAuthentification(MLNode objMLNode, IAuthenticator objAuthenticator) { if (objAuthenticator != null) { if (objAuthenticator is PlainAuthenticator) AddNodesAuthentificationPlain(objMLNode, objAuthenticator as PlainAuthenticator); else if (objAuthenticator is oAuthAuthenticator) AddNodesAuthentificationOAuht(objMLNode, objAuthenticator as oAuthAuthenticator); } }