Esempio n. 1
0
        public static List <ExternalContent> GetContentByDate(string username, string password, string userJournal, DateTime date)
        {
            //auth_method=challenge&auth_challenge={0}&auth_response={1}
            var key       = GetChalenge();
            var query     = new XmlDocument();
            var structure = PrepareXMLRPCDocument("getevents", query);

            structure.AppendChild(AddStringParam("username", username, query));
            structure.AppendChild(AddStringParam("auth_method", "challenge", query));
            structure.AppendChild(AddStringParam("auth_challenge", key, query));
            structure.AppendChild(AddStringParam("auth_response", EncodePassword(password, key), query));
            structure.AppendChild(AddStringParam("lineendings", "pc", query));
            structure.AppendChild(AddStringParam("selecttype", "day", query));
            structure.AppendChild(AddIntParam("year", date.Year, query));
            structure.AppendChild(AddIntParam("month", date.Month, query));
            structure.AppendChild(AddIntParam("day", date.Day, query));


            structure.AppendChild(AddIntParam("ver", 1, query));

            structure.AppendChild(AddStringParam("usejournal", userJournal, query));

            var response = SendXMLCode(query);

            var dataStream = response.GetResponseStream();

            XmlDocument doc = new XmlDocument();

            doc.Load(dataStream);
            List <ExternalContent> resultList = new List <ExternalContent>();
            var namenodes = doc.GetElementsByTagName("data");

            foreach (XmlNode node in namenodes)
            {
                foreach (XmlNode element in node.ChildNodes)
                {
                    if (element.Name == "value")
                    {
                        ExternalContent newElement = new ExternalContent();

                        if (element.FirstChild != null && element.FirstChild.Name == "struct")
                        {
                            var parentDataNode = node.FirstChild.FirstChild;

                            foreach (XmlNode valueNode in parentDataNode.ChildNodes)
                            {
                                if (valueNode.Name == "member" && valueNode.ChildNodes.Count == 2)
                                {
                                    string name  = null;
                                    string value = null;

                                    if (valueNode.ChildNodes[0].Name == "name")
                                    {
                                        name = valueNode.ChildNodes[0].InnerText;

                                        if (valueNode.ChildNodes[1].Name == "value" && valueNode.ChildNodes[1].FirstChild != null)
                                        {
                                            if (valueNode.ChildNodes[1].FirstChild.ChildNodes.Count == 1)
                                            {
                                                value = valueNode.ChildNodes[1].FirstChild.InnerText;
                                                newElement.ComposeProperty(name, value);
                                                //Console.WriteLine(name + ": " + value);
                                            }
                                            else if (valueNode.ChildNodes[1].FirstChild.ChildNodes.Count > 1)
                                            {
                                                foreach (XmlNode innerprop in valueNode.ChildNodes[1].FirstChild.ChildNodes)
                                                {
                                                    if (innerprop.ChildNodes[0].Name == "name")
                                                    {
                                                        name = innerprop.ChildNodes[0].InnerText;

                                                        if (innerprop.ChildNodes[1].Name == "value" && innerprop.ChildNodes[1].FirstChild != null)
                                                        {
                                                            value = innerprop.ChildNodes[1].FirstChild.InnerText;
                                                            newElement.ComposeProperty(name, value);
                                                            //Console.WriteLine(name + ": " + value);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        resultList.Add(newElement);
                    }
                }
            }


            dataStream.Close();
            response.Close();

            //TODO: Анализировать ответ и возвращать

            return(resultList);
        }
Esempio n. 2
0
        public static List<ExternalContent> GetContentByDate(string username, string password, string userJournal, DateTime date)
        {
            //auth_method=challenge&auth_challenge={0}&auth_response={1}
            var key = GetChalenge();
            var query = new XmlDocument();
            var structure = PrepareXMLRPCDocument("getevents", query);

            structure.AppendChild(AddStringParam("username", username, query));
            structure.AppendChild(AddStringParam("auth_method", "challenge", query));
            structure.AppendChild(AddStringParam("auth_challenge", key, query));
            structure.AppendChild(AddStringParam("auth_response", EncodePassword(password, key), query));
            structure.AppendChild(AddStringParam("lineendings", "pc", query));
            structure.AppendChild(AddStringParam("selecttype", "day", query));
            structure.AppendChild(AddIntParam("year", date.Year, query));
            structure.AppendChild(AddIntParam("month", date.Month, query));
            structure.AppendChild(AddIntParam("day", date.Day, query));

            structure.AppendChild(AddIntParam("ver", 1, query));

            structure.AppendChild(AddStringParam("usejournal", userJournal, query));

            var response = SendXMLCode(query);

            var dataStream = response.GetResponseStream();

            XmlDocument doc = new XmlDocument();
            doc.Load(dataStream);
            List<ExternalContent> resultList = new List<ExternalContent>();
            var namenodes = doc.GetElementsByTagName("data");
            foreach (XmlNode node in namenodes)
            {
                foreach (XmlNode element in node.ChildNodes)
                {
                    if (element.Name == "value")
                    {
                        ExternalContent newElement = new ExternalContent();

                        if (element.FirstChild != null && element.FirstChild.Name == "struct")
                        {
                            var parentDataNode = node.FirstChild.FirstChild;

                            foreach (XmlNode valueNode in parentDataNode.ChildNodes)
                            {
                                if (valueNode.Name == "member" && valueNode.ChildNodes.Count == 2)
                                {
                                    string name = null;
                                    string value = null;

                                    if (valueNode.ChildNodes[0].Name == "name")
                                    {
                                        name = valueNode.ChildNodes[0].InnerText;

                                        if (valueNode.ChildNodes[1].Name == "value" && valueNode.ChildNodes[1].FirstChild != null)
                                        {
                                            if (valueNode.ChildNodes[1].FirstChild.ChildNodes.Count == 1)
                                            {
                                                value = valueNode.ChildNodes[1].FirstChild.InnerText;
                                                newElement.ComposeProperty(name, value);
                                                //Console.WriteLine(name + ": " + value);
                                            }
                                            else if (valueNode.ChildNodes[1].FirstChild.ChildNodes.Count > 1)
                                            {
                                                foreach (XmlNode innerprop in valueNode.ChildNodes[1].FirstChild.ChildNodes)
                                                {
                                                    if (innerprop.ChildNodes[0].Name == "name")
                                                    {
                                                        name = innerprop.ChildNodes[0].InnerText;

                                                        if (innerprop.ChildNodes[1].Name == "value" && innerprop.ChildNodes[1].FirstChild != null)
                                                        {
                                                            value = innerprop.ChildNodes[1].FirstChild.InnerText;
                                                            newElement.ComposeProperty(name, value);
                                                            //Console.WriteLine(name + ": " + value);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        resultList.Add(newElement);
                    }
                }
            }

            dataStream.Close();
            response.Close();

            //TODO: Анализировать ответ и возвращать

            return resultList;
        }