Пример #1
0
    internal static LogInState LogIn(string playerName, string password)
    {
        string            filePath = Settings.GeneratePath("Players.xml");
        XmlReaderSettings settings = new XmlReaderSettings
        {
            IgnoreComments = true
        };
        XmlDataDocument playerDocument = new XmlDataDocument();

        playerDocument.Load(XmlReader.Create(filePath, settings));
        XmlNodeList playerList = playerDocument.SelectSingleNode("Players").ChildNodes;
        bool        found      = false;

        foreach (XmlNode player in playerList)
        {
            if (((XmlElement)player).GetAttribute("name") == playerName)
            {
                found = true;
                if (((XmlElement)player).GetAttribute("password") == password)
                {
                    currentPlayer = new Player
                    {
                        playerName   = playerName,
                        selectedPerk = Perk.GetPerkName(((XmlElement)player).GetAttribute("selectedPerk")),
                        perkInfo     = new PerkInfo[4]
                    };
                    for (int i = 0; i < 4; i++)
                    {
                        XmlElement perkElement = (XmlElement)player.ChildNodes.Item(i);
                        currentPlayer.perkInfo[i] = new PerkInfo
                        {
                            currentLevel      = Int32.Parse(perkElement.GetAttribute("level")),
                            currentExp        = Int32.Parse(perkElement.GetAttribute("exp")),
                            abilitiesSelected = new PerkInfo.PerkChosenState[5]
                            {
                                (PerkInfo.PerkChosenState)Int32.Parse(((XmlElement)perkElement.ChildNodes.Item(0)).GetAttribute("chosen")),
                                (PerkInfo.PerkChosenState)Int32.Parse(((XmlElement)perkElement.ChildNodes.Item(1)).GetAttribute("chosen")),
                                (PerkInfo.PerkChosenState)Int32.Parse(((XmlElement)perkElement.ChildNodes.Item(2)).GetAttribute("chosen")),
                                (PerkInfo.PerkChosenState)Int32.Parse(((XmlElement)perkElement.ChildNodes.Item(3)).GetAttribute("chosen")),
                                (PerkInfo.PerkChosenState)Int32.Parse(((XmlElement)perkElement.ChildNodes.Item(4)).GetAttribute("chosen"))
                            }
                        };
                    }
                }
                else
                {
                    return(LogInState.wrongPassword);
                }
            }
            if (found)
            {
                break;
            }
        }
        if (found == true)
        {
            return(LogInState.success);
        }
        else
        {
            return(LogInState.doesNotExist);
        }
    }
Пример #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            int             gradesum = 0;
            XmlDataDocument xmlDoc   = new XmlDataDocument();

            xmlDoc.Load("rubric.xml");
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("UIC").ChildNodes;
            int         count    = 0;

            foreach (XmlNode xn in nodeList)
            {
                XmlElement xe = (XmlElement)xn;

                if (xe.GetAttribute("name") == name)
                {
                    XmlNodeList nls = xe.ChildNodes;
                    foreach (XmlNode xn1 in nls)
                    {
                        gradesum = gradesum + Convert.ToInt32(xn1.Attributes[2].Value);
                    }
                }
            }

            if (gradesum == 100)
            {
                Form1 f1 = new Form1();
                f1.Show();
                this.Hide();
            }
            else
            {
                countmodify = false;
                string      xmlpath = @"rubric.xml";
                XmlDocument xmlDoc1 = new XmlDocument();
                xmlDoc1.Load(xmlpath);
                XmlNode     root   = xmlDoc1.SelectSingleNode("UIC");
                XmlNodeList xnList = root.ChildNodes;
                foreach (XmlNode xn in xnList)
                {
                    if (xn.Attributes[1].Value.ToString() == name)
                    {
                        root.RemoveChild(xn);
                    }
                }
                xmlDoc1.Save(xmlpath);
                MessageBox.Show("Total percentage should be 100, please enter rubric again");
            }


            XElement student           = XElement.Load("rubric.xml");
            IEnumerable <XElement> stu = from st in student.Elements("courses")
                                         where (string)st.Attribute("name") == name
                                         select st;
            var query1 = from n in stu.Elements()
                         select new
            {
                row        = n.Attribute("row").Value,
                Item       = n.Attribute("Item").Value,
                Percentage = n.Attribute("Percentage").Value,
                A          = n.Attribute("A").Value,
                B          = n.Attribute("B").Value,
                C          = n.Attribute("C").Value,
                D          = n.Attribute("D").Value,
                F          = n.Attribute("F").Value
            };

            dataGridView1.DataSource = query1.ToList();
        }
Пример #3
0
 public NavigationSearchData(string xmltag)
 {
     Id          = "";
     FieldId     = "";
     Action      = "";
     SqlOperator = "";
     SearchFrom  = "";
     SearchTo    = "";
     SqlType     = "";
     SearchField = "";
     SqlField    = "";
     ControlType = "";
     Static      = "";
     Dependency  = "";
     if (xmltag.Trim().StartsWith("<tag"))
     {
         var xdoc = new XmlDataDocument();
         xdoc.LoadXml(xmltag);
         var nodtag = xdoc.SelectSingleNode("tag");
         if (nodtag != null)
         {
             if (nodtag.Attributes["search"] != null)
             {
                 SearchField = nodtag.Attributes["search"].Value;
                 var s = SearchField.Split('/');
                 FieldId     = s[s.Count() - 1];
                 ControlType = s[s.Count() - 2];
             }
             if (nodtag.Attributes["id"] != null)
             {
                 Id = nodtag.Attributes["id"].Value;
             }
             if (nodtag.Attributes["action"] != null)
             {
                 Action = nodtag.Attributes["action"].Value;
             }
             if (nodtag.Attributes["sqloperator"] != null)
             {
                 SqlOperator = nodtag.Attributes["sqloperator"].Value;
             }
             if (nodtag.Attributes["searchfrom"] != null)
             {
                 SearchFrom = nodtag.Attributes["searchfrom"].Value;
             }
             if (nodtag.Attributes["searchto"] != null)
             {
                 SearchTo = nodtag.Attributes["searchto"].Value;
             }
             if (nodtag.Attributes["sqltype"] != null)
             {
                 SqlType = nodtag.Attributes["sqltype"].Value;
             }
             if (nodtag.Attributes["sqlfield"] != null)
             {
                 SqlField = nodtag.Attributes["sqlfield"].Value;
             }
             if (nodtag.Attributes["static"] != null)
             {
                 Static = nodtag.Attributes["static"].Value;
             }
             if (nodtag.Attributes["dependency"] != null)
             {
                 Dependency = nodtag.Attributes["dependency"].Value;
             }
         }
     }
 }
Пример #4
0
        private static string GetAdfsAssertion()
        {
            string tokenToSubmit;

            try
            {
                Guid messageId       = Guid.NewGuid();
                Guid usernameTokenId = Guid.NewGuid();

                var strmessageid       = "urn:uuid:" + messageId.ToString();
                var strusernameTokenId = "uuid-" + usernameTokenId.ToString() + "-1";

                var tokenEnvelopeXml = File.ReadAllText("../../Data/SecurityTokenFormat.xml");
                var requestBody      =
                    tokenEnvelopeXml.Replace("$$MessageGUID$$", strmessageid)
                    .Replace("$$UsernameTokenGUID$$", strusernameTokenId)
                    .Replace("*****@*****.**", AppSettings.Username)
                    .Replace("*******", AppSettings.Password)
                    .Replace("$$ADFSEndPoint$$", AppSettings.AdfsEndpoint)
                    .Replace("$$Realm$$", AppSettings.Realm);

                var securityTokenRequest = (HttpWebRequest)WebRequest.Create(AppSettings.AdfsEndpoint);
                var requestBodyData      = Encoding.ASCII.GetBytes(requestBody);
                securityTokenRequest.Method        = "POST";
                securityTokenRequest.ContentType   = "application/soap+xml; charset=utf-8";
                securityTokenRequest.ContentLength = requestBodyData.Length;

                using (var securityTokenStream = securityTokenRequest.GetRequestStream())
                {
                    securityTokenStream.Write(requestBodyData, 0, requestBodyData.Length);

                    using (var securityTokenResponse = (HttpWebResponse)securityTokenRequest.GetResponse())
                    {
                        using (var securityTokenResponseStream = securityTokenResponse.GetResponseStream())
                        {
                            if (securityTokenResponseStream == null)
                            {
                                throw new ArgumentNullException(nameof(securityTokenResponseStream));
                            }

                            var securityTokenResponseXml = new StreamReader(securityTokenResponseStream).ReadToEnd();

                            XmlDataDocument doc = new XmlDataDocument();
                            doc.LoadXml(securityTokenResponseXml);
                            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                            nsmgr.AddNamespace("t", "http://schemas.xmlsoap.org/ws/2005/02/trust");
                            nsmgr.AddNamespace("s", "http://www.w3.org/2003/05/soap-envelope");

                            var element = doc.SelectSingleNode("//s:Envelope/s:Body/t:RequestSecurityTokenResponse", nsmgr);
                            tokenToSubmit = element.OuterXml;
                        }
                    }
                }

                return(tokenToSubmit);
            }
            catch (Exception ex)
            {
                throw new Exception(
                          $"An error occurred when getting the security token:{ex.Message}{ex.StackTrace}");
            }
        }
Пример #5
0
        private long ReadLong(string xPath)
        {
            XmlNode node = dataDocument.SelectSingleNode(xPath);

            return(long.Parse(node.Value));
        }
Пример #6
0
        //变换条件
        private void cmbCondition_SelectedIndexChanged(System.Object sender, System.EventArgs e)         //Handles cmbCondition.SelectedIndexChanged
        {
            if (first == true)
            {
                return;
            }
            try
            {
                string s = "设置/系统设置[@名称=\"" + this.cmbCondition.Text + "\"]";
                node = doc.SelectSingleNode(s);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            short i, j;

            try
            {
                type = node.Attributes[1].Value;
            }
            catch
            {
                type = "";
            }
            short k = 0;

            for (j = 0; j < alControls.Count; ++j)
            {
                Control control = alControls[j] as Control;
                control.Visible = false;
            }
            for (i = 0; i < node.ChildNodes[0].Attributes.Count; ++i)
            {
                if (node.ChildNodes[0].Attributes[i].Name.Substring(node.ChildNodes[0].Attributes[i].Name.Length - 2) != "数值")
                {
                    for (j = 0; j < alControls.Count; ++j)
                    {
                        Control control = alControls[j] as Control;

                        if (control.Name == "lblRefer" + (k + 1).ToString())
                        {
                            control.Text    = node.ChildNodes[0].Attributes[i].Name;
                            control.Visible = true;
                        }
                        if (control.Name == "txtRefer" + (k + 1).ToString())
                        {
                            control.Tag     = node.ChildNodes[0].Attributes[i].Value;
                            control.Visible = true;
                            ((ComboBox)control).Items.Clear();
                            //找到 value
                            try
                            {
                                if (node.ChildNodes[0].Attributes[i + 1].Name.Substring(node.ChildNodes[0].Attributes[i + 1].Name.Length - 2) == "数值")
                                {
                                    f_fillCombo(control, node.ChildNodes[0].Attributes[i + 1].Value);
                                }
                            }
                            catch {}
                        }
                    }
                    k += 1;
                }
            }

            this.cmbCondition.Tag = node.InnerText;
            //*****显示必须控件*******************************
            this.cmbCondition.Visible = true;
//			this.Button1.Visible = true;
//			this.Label1.Visible = true;
//			this.btnQuery.Visible = true;
//			this.DataGrid.Visible = true;
//			this.chkSealed.Visible = true;
//			this.GroupBox1.Visible = true;
//			this.Panel1.Visible = true;
//			this.Panel2.Visible = true;
//			this.CheckBox1.Visible = true;
//			if (GetPermission[11] == "1")
//				this.Button2.Visible = true;
        }