Esempio n. 1
0
        public override BaseActionResult Execute(Context context)
        {
            LoginSettingsActionResult result = new LoginSettingsActionResult();

            result.Model = context.Model as LoginSettingsModel;
            if (result.Model == null)
            {
                result.Model = new LoginSettingsModel();
            }
            string actionName = CommonGlobalSettings.Utilities.GetParameter("actionName", context.Parameters);
            string site       = CommonGlobalSettings.Utilities.GetParameter("site", context.Parameters);

            if (actionName == null || actionName.Equals(""))
            {
                actionName = "LoginInfo";
            }

            try
            {
                switch (actionName)
                {
                case "LoginInfo":
                    LoginSettingsService.GetLoginInfo(result);
                    break;

                case "Upload":
                    LoginSettingsService.WriteXML(result, site);
                    break;

                case "Download":
                    LoginSettingsService.ReadXML(result, site);
                    break;

                default:
                    LoginSettingsService.GetLoginInfo(result);
                    break;
                }
                result.Result = true;
            }
            catch (Exception ex)
            {
                result.ReturnMessage = ex.Message;
                result.Result        = false;
                result.recode        = -1;
            }


            return(result);
        }
Esempio n. 2
0
        public void ReadXML(LoginSettingsActionResult result, string site)
        {
            XmlDocument root = loadXml(site, true);
            XmlNode     myNode;
            XmlNode     pictures = root.SelectSingleNode("//pictures");

            if (pictures != null)
            {
                result.Model.defaultPicture = pictures.Attributes["default"].Value;
            }
            List <string> mylist = new List <string>();

            foreach (XmlNode node in pictures.ChildNodes)
            {
                mylist.Add(node.InnerText);
            }
            result.Model.pictures = mylist.ToArray();

            myNode = root.SelectSingleNode("//title");
            if (myNode != null)
            {
                result.Model.title = myNode.InnerText;
            }
            myNode = root.SelectSingleNode("//font");
            if (myNode != null)
            {
                result.Model.font = myNode.InnerText;
            }
            myNode = root.SelectSingleNode("//fontStyle");
            if (myNode != null)
            {
                result.Model.fontStyle = Convert.ToInt32(myNode.InnerText);
            }
            myNode = root.SelectSingleNode("//color");
            if (myNode != null)
            {
                result.Model.color = myNode.InnerText;
            }
            myNode = root.SelectSingleNode("//logo");
            if (myNode != null)
            {
                result.Model.logo = myNode.InnerText;
            }
            myNode = root.SelectSingleNode("//isRegular");
            if (myNode != null)
            {
                result.Model.isRegular = myNode.InnerText;
            }
            myNode = root.SelectSingleNode("//regularNum");
            if (myNode != null)
            {
                result.Model.regularNum = myNode.InnerText;
            }
            myNode = root.SelectSingleNode("//regularUnit");
            if (myNode != null)
            {
                result.Model.regularUnit = myNode.InnerText;
            }
            myNode = root.SelectSingleNode("//random");
            if (myNode != null)
            {
                result.Model.random = myNode.InnerText;
            }
        }
Esempio n. 3
0
        public void GetLoginInfo(LoginSettingsActionResult result)
        {
            List <string> myList = new List <string>();

            string[] arr  = new string[] { };
            string   site = "";

            result.useLoginSettings = LoginDAO.FullShowLoginBackground(ref site);
            lock (LoginDAOForLock)
            {
                XmlDocument root     = loadXml(site);
                XmlNode     pictures = root.SelectSingleNode("//pictures");
                if (pictures.Attributes["previous"] == null)
                {
                    XmlAttribute attribute = root.CreateAttribute("previous");
                    pictures.Attributes.Append(attribute);
                }
                if (pictures.Attributes["current"] == null)
                {
                    XmlAttribute attribute = root.CreateAttribute("current");
                    pictures.Attributes.Append(attribute);
                }
                if (pictures.Attributes["next"] == null)
                {
                    XmlAttribute attribute = root.CreateAttribute("next");
                    pictures.Attributes.Append(attribute);
                }

                XmlNode  myNode     = root.SelectSingleNode("//updateDateTime");
                DateTime updateDate = (myNode == null) ? DateTime.Now.Date : Convert.ToDateTime(myNode.InnerText);
                myNode = root.SelectSingleNode("//regularNum");
                int regularNum = (myNode == null) ? 1 : Convert.ToInt32(myNode.InnerText);

                myNode = root.SelectSingleNode("//title");
                if (myNode != null)
                {
                    result.Model.title = myNode.InnerText;
                }
                myNode = root.SelectSingleNode("//font");
                if (myNode != null)
                {
                    result.Model.font = myNode.InnerText;
                }
                myNode = root.SelectSingleNode("//fontStyle");
                if (myNode != null)
                {
                    result.Model.fontStyle = Convert.ToInt32(myNode.InnerText);
                }
                myNode = root.SelectSingleNode("//color");
                if (myNode != null)
                {
                    result.Model.color = myNode.InnerText;
                }
                myNode = root.SelectSingleNode("//logo");
                if (myNode != null)
                {
                    result.Model.logo = myNode.InnerText;
                }

                bool IsRandom = false;
                myNode = root.SelectSingleNode("//random");
                if (myNode != null)
                {
                    if (myNode.InnerText == "1")
                    {
                        IsRandom = true;
                    }
                }

                myNode = root.SelectSingleNode("//isRegular");
                if (myNode != null && myNode.InnerText == "0")
                {
                    myNode = root.SelectSingleNode("//IsNew");
                    if (myNode != null)
                    {
                        if (myNode.InnerText == "1")
                        {
                            pictures.Attributes["previous"].Value = pictures.Attributes["current"].Value;
                            pictures.Attributes["current"].Value  = pictures.Attributes["default"].Value;
                            myNode.InnerText = "0";
                            LoginDAOForLock.WriteXML(site, root.InnerXml);
                            //root.Save(AppDomain.CurrentDomain.BaseDirectory + "Login_UI_Setting.xml");
                        }
                    }

                    myList.Add(pictures.Attributes["previous"].Value);
                    myList.Add(pictures.Attributes["default"].Value);
                    myList.Add(pictures.Attributes["default"].Value);
                }
                else
                {
                    myNode = root.SelectSingleNode("//regularUnit");
                    if (myNode != null)
                    {
                        string regularUnit   = myNode.InnerText;
                        int    startPosition = 1;
                        for (int i = 0; i < pictures.ChildNodes.Count; i++)
                        {
                            if (pictures.ChildNodes[i].InnerText == pictures.Attributes["default"].Value)
                            {
                                startPosition = i + 1;
                                break;
                            }
                        }

                        myNode = root.SelectSingleNode("//IsNew");
                        if (myNode != null)
                        {
                            Int32 times = GetTimes(regularNum, regularUnit, updateDate);

                            //lock (pictures)
                            //{
                            if (myNode.InnerText == "1" || pictures.Attributes["times"].Value.ToString() != times.ToString())
                            {
                                if (pictures.ChildNodes.Count == 0)
                                {
                                    pictures.Attributes["previous"].Value = pictures.Attributes["current"].Value;
                                    pictures.Attributes["current"].Value  = "";
                                    pictures.Attributes["next"].Value     = "";
                                }
                                else
                                {
                                    if (IsRandom)
                                    {
                                        Random rm = new Random();
                                        pictures.Attributes["previous"].Value = pictures.Attributes["current"].Value;
                                        if (string.IsNullOrWhiteSpace(pictures.Attributes["next"].Value))
                                        {
                                            pictures.Attributes["current"].Value = pictures.ChildNodes[rm.Next(0, (pictures.ChildNodes.Count - 1))].InnerText;
                                        }
                                        else
                                        {
                                            pictures.Attributes["current"].Value = pictures.Attributes["next"].Value;
                                        }
                                        pictures.Attributes["next"].Value = pictures.ChildNodes[rm.Next(0, (pictures.ChildNodes.Count - 1))].InnerText;
                                    }
                                    else
                                    {
                                        XmlNode currentNode = GetCurrentPicture(times, startPosition, pictures);
                                        pictures.Attributes["previous"].Value = pictures.Attributes["current"].Value;
                                        pictures.Attributes["current"].Value  = currentNode.InnerText;
                                        if (currentNode.NextSibling == null)
                                        {
                                            pictures.Attributes["next"].Value = pictures.FirstChild.InnerText;
                                        }
                                        else
                                        {
                                            pictures.Attributes["next"].Value = currentNode.NextSibling.InnerText;
                                        }
                                    }
                                }
                                myNode.InnerText = "0";
                                pictures.Attributes["times"].Value = times.ToString();
                                LoginDAOForLock.WriteXML(site, root.InnerXml);
                                //root.Save(AppDomain.CurrentDomain.BaseDirectory + "Login_UI_Setting.xml");
                            }
                            //}


                            myList.Add(pictures.Attributes["previous"].Value);
                            myList.Add(pictures.Attributes["current"].Value);
                            myList.Add(pictures.Attributes["next"].Value);
                        }
                    }
                }
                if (myList.Count == 0)
                {
                    myList.Add("");
                    myList.Add("");
                    myList.Add("");
                }

                result.ArrData = myList.ToArray();
            }
        }
Esempio n. 4
0
        public void WriteXML(LoginSettingsActionResult result, string site)
        {
            XmlDocument root = loadXml(site);
            XmlElement  element;
            XmlNode     myNode;
            XmlNode     pictures = root.SelectSingleNode("//pictures");

            if (pictures != null)
            {
                element = pictures as XmlElement;
                element.Attributes["default"].Value = result.Model.defaultPicture;
            }
            foreach (XmlNode node in pictures.ChildNodes)
            {
                pictures.RemoveChild(node);
            }
            while (pictures.ChildNodes.Count > 0)
            {
                pictures.RemoveChild(pictures.ChildNodes[0]);
            }
            foreach (string picture in result.Model.pictures)
            {
                element           = root.CreateElement("picture");
                element.InnerText = picture;
                pictures.AppendChild(element);
            }

            myNode = root.SelectSingleNode("//title");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.title;
            }
            myNode = root.SelectSingleNode("//font");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.font;
            }
            myNode = root.SelectSingleNode("//fontStyle");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.fontStyle.ToString();
            }
            myNode = root.SelectSingleNode("//color");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.color;
            }
            myNode = root.SelectSingleNode("//logo");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.logo;
            }
            myNode = root.SelectSingleNode("//isRegular");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.isRegular;
            }
            myNode = root.SelectSingleNode("//regularNum");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.regularNum;
            }
            myNode = root.SelectSingleNode("//regularUnit");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.regularUnit;
            }
            myNode = root.SelectSingleNode("//random");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = result.Model.random;
            }
            myNode = root.SelectSingleNode("//updateDateTime");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = DateTime.Now.Date.ToShortDateString();
            }
            myNode = root.SelectSingleNode("//IsNew");
            if (myNode != null)
            {
                element           = myNode as XmlElement;
                element.InnerText = "1";
            }
            lock (LoginDAOForLock)
            {
                LoginDAOForLock.WriteXML(site, root.InnerXml);
                //root.Save(AppDomain.CurrentDomain.BaseDirectory + "Login_UI_Setting.xml");
            }
        }