/// <summary>
        /// Constructs the exchanger - allowing passing in of COBie settings rather than looking for a file relative
        /// to an Executable
        /// </summary>
        /// <param name="facility"></param>
        /// <param name="repository"></param>
        /// <param name="configFilePath"></param>
        public CoBieLiteToIfcExchanger(FacilityType facility, XbimModel repository, string configFilePath)
            : this(facility, repository)
        {
            CobieToIfcPropertyMap = new Dictionary <string, NamedProperty>();

            System.Xml.XmlDocument settings = new System.Xml.XmlDocument();
            settings.Load(configFilePath);

            var settingsElement = settings.DocumentElement.SelectSingleNode("COBiePropertyMaps");

            foreach (var element in settingsElement.ChildNodes)
            {
                System.Xml.XmlElement el = element as System.Xml.XmlElement;

                if (el == null)
                {
                    continue;
                }

                var values   = el.GetAttribute("value").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                var selected = values.FirstOrDefault();
                if (selected != null)
                {
                    var names = selected.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                    if (names.Length == 2 && !CobieToIfcPropertyMap.ContainsKey(el.GetAttribute("key")))
                    {
                        CobieToIfcPropertyMap.Add(el.GetAttribute("key"), new NamedProperty(names[0], names[1]));
                    }
                }
            }
        }
        private anmar.SharpWebMail.ServerSelector ParseConfigServers(System.Xml.XmlNodeList list)
        {
            anmar.SharpWebMail.ServerSelector selector = new anmar.SharpWebMail.ServerSelector();
            foreach (System.Xml.XmlNode item in list)
            {
                if (item.NodeType.Equals(System.Xml.XmlNodeType.Element) && (item.LocalName.Equals("server") || item.LocalName.Equals("add")))
                {
                    System.Xml.XmlElement element = (System.Xml.XmlElement)item;
                    if (element.HasAttribute("key") && element.HasAttribute("value"))                       // Old format
                    {
                        selector.Add(element.GetAttribute("key"), element.GetAttribute("value"));
                    }
                    else if (element.HasAttribute("protocol") && element.HasAttribute("host") && element.HasAttribute("port"))                         // New format
                    {
                        anmar.SharpWebMail.EmailServerInfo server = new anmar.SharpWebMail.EmailServerInfo(element.GetAttribute("protocol"), element.GetAttribute("host"), element.GetAttribute("port"));
                        if (element.HasAttribute("regexp"))
                        {
                            server.SetCondition(element.GetAttribute("regexp"));
                        }
                        if (element.HasAttribute("name"))
                        {
                            server.Name = element.GetAttribute("name");
                        }

                        if (server.IsValid())
                        {
                            selector.Add(server);
                        }
                    }
                }
            }
            return(selector);
        }
Exemple #3
0
        public override bool FromXML(System.Xml.XmlElement myElement)
        {
            if (myElement != null)
            {
                this.Type = StringCommon.GetTypeByName(myElement.GetAttribute("type"));
                this.Name = myElement.GetAttribute("name");
                this.Code = myElement.GetAttribute("code");

                //Add by wwj 2013-08-01
                if (myElement.HasAttribute("candelete"))
                {
                    this.CanDelete = bool.Parse(myElement.GetAttribute("candelete"));
                }

                //Add by wwj 2013-08-01
                if (myElement.HasAttribute("direction"))
                {
                    this.Direction = (ZYFlagDirection)Enum.Parse(typeof(ZYFlagDirection), myElement.GetAttribute("direction"));
                }

                //Add by wwj 2013-08-01
                if (myElement.HasAttribute("isholdspacewhenprint"))
                {
                    this.IsHoldSpaceWhenPrint = bool.Parse(myElement.GetAttribute("isholdspacewhenprint"));
                }

                return(true);
            }
            return(false);
        }
Exemple #4
0
            public static ItemArchetype CreateFromXml(System.Xml.XmlElement n, Roar.DataConversion.IXCRMParser ixcrm_parser)
            {
                DomainObjects.ItemArchetype retval = new DomainObjects.ItemArchetype();
                retval.id          = n.GetAttributeOrDefault("id", null);
                retval.ikey        = n.GetAttributeOrDefault("ikey", null);
                retval.type        = n.GetAttributeOrDefault("type", null);
                retval.label       = n.GetAttributeOrDefault("label", null);
                retval.description = n.GetAttributeOrDefault("description", null);

                if (n.HasAttribute("consumable"))
                {
                    retval.consumable = n.GetAttribute("consumable").ToLower() == "true";
                }
                if (n.HasAttribute("sellable"))
                {
                    retval.sellable = n.GetAttribute("sellable").ToLower() == "true";
                }
                retval.stats = ixcrm_parser.ParseItemStatList(n.SelectSingleNode("./stats") as System.Xml.XmlElement);
                retval.price = ixcrm_parser.ParseModifierList(n.SelectSingleNode("./price") as System.Xml.XmlElement);
                retval.tags  = ixcrm_parser.ParseTagList(n.SelectSingleNode("./tags") as System.Xml.XmlElement);
                System.Xml.XmlNodeList property_nodes = n.SelectNodes("./properties/property");
                foreach (System.Xml.XmlElement property_node in property_nodes)
                {
                    Roar.DomainObjects.ItemArchetypeProperty property = new Roar.DomainObjects.ItemArchetypeProperty();
                    property.ikey  = property_node.GetAttribute("ikey");
                    property.value = property_node.GetAttribute("value");
                    retval.properties.Add(property);
                }
                return(retval);
            }
Exemple #5
0
        public static void SetValue(string AppKey, string AppValue)
        {
            System.Xml.XmlDataDocument xDoc = new System.Xml.XmlDataDocument();
            // xDoc.Load("../../App.config");
            string filePath = System.Windows.Forms.Application.ExecutablePath + ".config";

            xDoc.Load(filePath);//

            System.Xml.XmlNodeList nodeList = null;
            nodeList = xDoc.SelectSingleNode("//configuration//appSettings").ChildNodes;
            if (nodeList != null)
            {
                foreach (System.Xml.XmlNode xn in nodeList)
                {
                    System.Xml.XmlElement xe = xn as System.Xml.XmlElement;
                    if (xe != null)
                    {
                        if (xe.Name == "add")
                        {
                            string s = xe.GetAttribute("key");
                            string p = xe.GetAttribute("value");
                            if (s == AppKey)
                            {
                                xe.SetAttribute("value", AppValue);
                            }
                        }
                    }
                }
            }
            xDoc.Save(filePath);
        }
Exemple #6
0
            public static ChromeWebStoreEvent CreateFromXml(System.Xml.XmlElement n)
            {
                ChromeWebStoreEvent e = new ChromeWebStoreEvent();

                e.costsList      = new List <string>();
                e.modifierList   = new List <string>();
                e.ikey           = n.GetAttribute("ikey");
                e.transaction_id = n.GetAttribute("transaction_id");

                System.Xml.XmlNode costsNode = n.SelectSingleNode("./costs");

                foreach (System.Xml.XmlNode nn in costsNode)
                {
                    e.costsList.Add(nn.InnerText);
                }

                System.Xml.XmlNode attributesNode = n.SelectSingleNode("./modifiers");

                foreach (System.Xml.XmlNode nn in attributesNode)
                {
                    e.modifierList.Add(nn.InnerText);
                }

                return(e);
            }
Exemple #7
0
        private static ICSSoft.STORMNET.FunctionalLanguage.Function FromXMLElements(System.Xml.XmlElement elem, ICSSoft.STORMNET.FunctionalLanguage.FunctionalLanguageDef lang, ICSSoft.STORMNET.FunctionalLanguage.VariableDef[] vars)
        {
            string funcname = elem.GetAttribute("Name");

            object[] parameters = new object[elem.ChildNodes.Count];
            for (int i = 0; i < elem.ChildNodes.Count; i++)
            {
                System.Xml.XmlElement subel = (System.Xml.XmlElement)elem.ChildNodes[i];
                switch (subel.Name)
                {
                case "Function":
                    parameters[i] = FromXMLElements(subel, lang, vars);
                    break;

                case "Variable":
                    string varName = subel.GetAttribute("Value");
                    foreach (ICSSoft.STORMNET.FunctionalLanguage.VariableDef vd in vars)
                    {
                        if (vd.StringedView == varName)
                        {
                            parameters[i] = vd;
                            break;
                        }
                    }
                    break;

                case "Value":
                {
                    string typename = subel.GetAttribute("ConstType");
                    parameters[i] = null;
                    foreach (ICSSoft.STORMNET.FunctionalLanguage.ObjectType ot in lang.Types)
                    {
                        if (ot.StringedView == typename)
                        {
                            try
                            {
                                parameters[i] = Convert.ChangeType(subel.GetAttribute("Value"), ot.NetCompatibilityType);
                                break;
                            }
                            catch { }
                        }
                    }
                    if (parameters[i] == null)
                    {
                        parameters[i] = subel.GetAttribute("Value");
                    }
                    break;
                }
                }
                ;
            }
            if (funcname == null || funcname == "")
            {
                return(null);
            }
            else
            {
                return(lang.GetFunction(funcname, parameters));
            }
        }
Exemple #8
0
 /// <summary>
 /// 初始化主线副本经验表集合
 /// </summary>
 public void InitExpTable()
 {
     _expTable = new ObservableCollection <ExpTable>();
     if (File.Exists("stages.xml"))
     {
         try
         {
             System.Xml.XmlDocument file = new System.Xml.XmlDocument();
             file.Load("stages.xml");
             System.Xml.XmlNode     ixn  = file.SelectSingleNode("stageList");
             System.Xml.XmlNodeList ixnl = ixn.ChildNodes;
             foreach (System.Xml.XmlNode inxf in ixnl)
             {
                 System.Xml.XmlElement ixe = inxf as System.Xml.XmlElement;
                 if (ixe.Name == "stage" && ixe.GetAttribute("name") != null && ixe.GetAttribute("name") != "")
                 {
                     _expTable.Add(new ExpTable()
                     {
                         stage  = ixe.GetAttribute("name"),
                         ap     = int.Parse(ixe.GetAttribute("ap")),
                         exp    = int.Parse(ixe.GetAttribute("exp")),
                         effect = (float.Parse(ixe.GetAttribute("exp")) / float.Parse(ixe.GetAttribute("ap"))).ToString("#0.00")
                     });
                 }
             }
         }
         catch
         {
             MiscHelper.AddLog("关卡经验信息加载出错,请检查stages.xml文件是否损坏!", MiscHelper.LogType.System);
         }
     }
 }
        public static List <RecordLine> ReadFromXmlFile(String _XmlFilename)
        {
            List <RecordLine> result = new List <RecordLine>();

            if (!String.IsNullOrEmpty(_XmlFilename))
            {
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.Load(_XmlFilename);

                System.Xml.XmlNodeList lines = doc.GetElementsByTagName("RecordLine");
                foreach (System.Xml.XmlNode line in lines)
                {
                    System.Xml.XmlElement lineEle = line as System.Xml.XmlElement;
                    String palletizer             = lineEle.GetAttribute("PalletizerName");
                    String readMarkDevice         = lineEle.GetAttribute("ReadMarkDevice");
                    String plateCodeDevice        = lineEle.GetAttribute("PlateCodeDevice");

                    System.Xml.XmlNodeList records = lineEle.GetElementsByTagName("Record");
                    if (records.Count > 0)
                    {
                        RecordLine recordLine = new RecordLine(palletizer, readMarkDevice, plateCodeDevice);
                        foreach (System.Xml.XmlNode record in records)
                        {
                            System.Xml.XmlElement recordEle = record as System.Xml.XmlElement;
                            String boxCodeDevice            = recordEle.GetAttribute("BoxCodeDevice");
                            String amountDevice             = recordEle.GetAttribute("AmountDevice");
                            recordLine.AddRecord(new Record(boxCodeDevice, amountDevice));
                        }
                        result.Add(recordLine);
                    }
                }
            }

            return(result);
        }
Exemple #10
0
        protected virtual DataSet LoadFromFile()
        {
            if (m_FileName == null)
            {
                throw new ApplicationException("FileName is null");
            }

            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
            xmlDoc.Load(m_FileName);

            System.Xml.XmlNamespaceManager namespaceMan = new System.Xml.XmlNamespaceManager(xmlDoc.NameTable);
            namespaceMan.AddNamespace("fileds", c_DataNamespace);

            System.Xml.XmlNode tmp = xmlDoc.DocumentElement.SelectSingleNode("fileds:header", namespaceMan);
            if (tmp == null)
            {
                throw new ApplicationException("File header not found");
            }
            System.Xml.XmlElement header = (System.Xml.XmlElement)tmp;

            //File Version
            string strFileVersion = header.GetAttribute(c_FileVersion);
            int    fileVersion    = int.Parse(strFileVersion);

            if (fileVersion == c_FileVersionNumber)
            {
                string strDataFormat = header.GetAttribute(c_DataFormat);
                mFileDataFormat = (StreamDataSetFormat)int.Parse(strDataFormat);
            }
            else if (fileVersion == 0)
            {
                mFileDataFormat = StreamDataSetFormat.XML;
            }
            else if (fileVersion > c_FileVersionNumber)
            {
                throw new ApplicationException("File Version not supported, expected: " + c_FileVersionNumber.ToString());
            }

            //Data Version
            string  strDataVersion = header.GetAttribute(c_DataVersion);
            int     dataVersion    = int.Parse(strDataVersion);
            DataSet dataSet        = CreateData(dataVersion);

            //Data
            tmp = xmlDoc.DocumentElement.SelectSingleNode("fileds:data", namespaceMan);
            if (tmp == null)
            {
                throw new ApplicationException("File data not found");
            }
            System.Xml.XmlElement xmlDataNode = (System.Xml.XmlElement)tmp;

            byte[] xmlBuffer = System.Convert.FromBase64String(xmlDataNode.InnerText);
            using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(xmlBuffer))
            {
                StreamDataSet.Read(memStream, dataSet, mFileDataFormat, MergeReadedSchema);
                //dataSet.ReadXml(memStream);
            }

            return(dataSet);
        }
Exemple #11
0
 /// <summary>
 /// 加载角色信息文件到数组
 /// </summary>
 private void _LoadCards()
 {
     if (File.Exists("cards.xml"))
     {
         try
         {
             _cardsList = new List <Cards>();
             System.Xml.XmlDocument file = new System.Xml.XmlDocument();
             file.Load("cards.xml");
             System.Xml.XmlNode     ixn  = file.SelectSingleNode("cardList");
             System.Xml.XmlNodeList ixnl = ixn.ChildNodes;
             foreach (System.Xml.XmlNode inxf in ixnl)
             {
                 System.Xml.XmlElement ixe = inxf as System.Xml.XmlElement;
                 if (ixe.Name == "card")
                 {
                     Cards info = new Cards();
                     info.id   = int.Parse(ixe.GetAttribute("id"));
                     info.name = ixe.GetAttribute("name");
                     info.rare = short.Parse(ixe.GetAttribute("rare"));
                     info.type = ixe.GetAttribute("type");
                     info.rank = (info.rare >= 5 && ixe.GetAttribute("rank") != "") ? float.Parse(ixe.GetAttribute("rank")) : -1F;
                     _cardsList.Add(info);
                 }
             }
         }
         catch
         {
             MiscHelper.AddLog("角色信息加载出错,请检查cards.xml文件是否损坏!", MiscHelper.LogType.System);
         }
     }
 }
Exemple #12
0
            public static ItemAddEvent CreateFromXml(System.Xml.XmlElement n)
            {
                Events.ItemAddEvent e = new Events.ItemAddEvent();

                e.item_id   = n.GetAttribute("item_id");
                e.item_ikey = n.GetAttribute("item_ikey");
                return(e);
            }
Exemple #13
0
 public HLAInteractionParameter(System.Xml.XmlElement parameterElement)
     : base(parameterElement)
 {
     this.DataType       = parameterElement.GetAttribute("dataType");
     this.DataTypeNotes  = parameterElement.GetAttribute("dataTypeNotes");
     this.Semantics      = ReplaceNewLines(parameterElement.GetAttribute("semantics"));
     this.SemanticsNotes = parameterElement.GetAttribute("semanticsNotes");
 }
        public void LoadFromXmlSchema(System.Xml.XmlElement xmlEl)         //, SchemaMembers siblings)
        {
            base.LoadFromXml(xmlEl);
            this._isOpen        = (xmlEl.GetAttribute("O") == "1"?true:false);
            this._isPlaceholder = (xmlEl.GetAttribute("PH") == "1"?true:false);
//			this.OnAddToSchemaMembers(siblings);
            LoadChildrenFromXmlSchema(xmlEl);
        }
Exemple #15
0
            public static RegenEvent CreateFromXml(System.Xml.XmlElement n)
            {
                Events.RegenEvent e = new Events.RegenEvent();

                e.name = n.GetAttribute("name");
                e.next = n.GetAttribute("next");
                return(e);
            }
Exemple #16
0
 public HLARecordField(System.Xml.XmlElement recordFieldElement)
     : base(recordFieldElement)
 {
     DataType       = recordFieldElement.GetAttribute("dataType");
     DataTypeNotes  = recordFieldElement.GetAttribute("dataTypeNotes");
     Semantics      = ReplaceNewLines(recordFieldElement.GetAttribute("semantics"));
     SemanticsNotes = recordFieldElement.GetAttribute("semanticsNotes");
 }
Exemple #17
0
            public static AppstoreShopEntry CreateFromXml(System.Xml.XmlElement n, Roar.DataConversion.IXCRMParser ixcrm_parser)
            {
                AppstoreShopEntry retval = new AppstoreShopEntry();

                retval.product_identifier = n.GetAttribute("product_identifier");
                retval.label     = n.GetAttribute("label");
                retval.modifiers = ixcrm_parser.ParseModifierList(n.SelectSingleNode("modifiers") as System.Xml.XmlElement);
                return(retval);
            }
Exemple #18
0
            public static ScriptEvent CreateFromXml(System.Xml.XmlElement n)
            {
                ScriptEvent e = new ScriptEvent();

                e.key = n.GetAttribute("key");
                e.val = n.GetAttribute("value");

                return(e);
            }
Exemple #19
0
            public static MailInEvent CreateFromXml(System.Xml.XmlElement n)
            {
                MailInEvent e = new MailInEvent();

                e.sender_id   = n.GetAttribute("sender_id");
                e.sender_name = n.GetAttribute("sender_name");

                return(e);
            }
Exemple #20
0
        /// <summary>
        /// 已重载:从XML节点加载对象数据
        /// </summary>
        /// <param name="myElement">XML节点</param>
        /// <returns>操作是否成功</returns>
        public override bool FromXML(System.Xml.XmlElement myElement)
        {
            if (base.FromXML(myElement))
            {
                this.Width  = 30;
                this.Height = 30;
                if (myImage != null)
                {
                    myImage.Dispose();
                    myImage      = null;
                    imagecontent = string.Empty;
                }
                if (this.SaveInFile)
                {
                    try
                    {
                        myImage = StringCommon.ImageFromBase64String(myElement.InnerText);
                    }
                    catch
                    {
                        //如果不能加载出图片,则说明是该图片已经被修改过了
                        //需要使用图片编辑器
                        myImage = null;
                    }
                    if (myImage == null)
                    {
                        imagecontent = myElement.InnerText;
                        MemoryStream ms = new MemoryStream(Convert.FromBase64String(imagecontent));
                        m_temppanel.LoadImage(ms);
                        myImage = m_temppanel.CurrentImage;
                    }
                }
                else
                {
                    myImage = ZYTextConst.ImageFromURL(this.Src);
                    //todo
                }

                if (myImage != null)
                {
                    this.Width  = myImage.Size.Width;
                    this.Height = myImage.Size.Height;
                }
                if (myElement.HasAttribute(ZYTextConst.c_Width))
                {
                    this.Width = StringCommon.ToInt32Value(myElement.GetAttribute(ZYTextConst.c_Width), intWidth);
                }
                if (myElement.HasAttribute(ZYTextConst.c_Height))
                {
                    this.Height = StringCommon.ToInt32Value(myElement.GetAttribute(ZYTextConst.c_Height), intHeight);
                }
                myAttributes.SetValue(ZYTextConst.c_Width, intWidth.ToString());
                myAttributes.SetValue(ZYTextConst.c_Height, intHeight.ToString());
                return(true);
            }
            return(false);
        }
Exemple #21
0
            public static CollectChangedEvent CreateFromXml(System.Xml.XmlElement n)
            {
                CollectChangedEvent e = new CollectChangedEvent();

                e.ikey = n.GetAttribute("ikey");
                e.next = n.GetAttribute("next");

                return(e);
            }
Exemple #22
0
            public static TransactionEvent CreateFromXml(System.Xml.XmlElement n)
            {
                TransactionEvent e = new TransactionEvent();

                e.ikey = n.GetAttribute("ikey");
                e.val  = n.GetAttribute("value");

                return(e);
            }
Exemple #23
0
 void ReadHeader(System.Xml.XmlElement node)
 {
     size           = System.Convert.ToUInt32(node.GetAttribute("Size"));
     compressedsize = System.Convert.ToUInt32(node.GetAttribute("CompressedSize"));
     adler32        = System.Convert.ToUInt32(node.GetAttribute("Checksum"), 16);
     filetime       = System.Convert.ToUInt32(node.GetAttribute("FileTime"), 16);
     algorithm      = (AlgorithmType)System.Convert.ToUInt32(node.GetAttribute("Algorithm"));
     oldalgorithm   = algorithm;
 }
Exemple #24
0
 public override bool FromXML(System.Xml.XmlElement myElement)
 {
     base.FromXML(myElement);
     strUserName = myElement.GetAttribute("user");
     //dtmDateTime = ZYCommon.StringCommon.ConvertToDateTime( myElement.GetAttribute("time"),null,System.DateTime.Now);
     dtmDateTime = StringCommon.ConvertToDateTime(myElement.GetAttribute("time"), null, ZYTime.GetServerTime());
     intLevel    = StringCommon.ToInt32Value(myElement.GetAttribute("level"), intLevel);
     return(true);
 }
Exemple #25
0
            public static InviteAcceptedEvent CreateFromXml(System.Xml.XmlElement n)
            {
                InviteAcceptedEvent e = new InviteAcceptedEvent();

                e.name      = n.GetAttribute("name");
                e.player_id = n.GetAttribute("player_id");
                e.level     = n.GetAttribute("level");

                return(e);
            }
Exemple #26
0
 public override bool FromXML(System.Xml.XmlElement myElement)
 {
     if (myElement != null)
     {
         this.Type = StringCommon.GetTypeByName(myElement.GetAttribute("type"));
         this.Name = myElement.GetAttribute("name");
         return(true);
     }
     return(false);
 }
Exemple #27
0
            public static LeaderboardInfo CreateFromXml(System.Xml.XmlElement n)
            {
                LeaderboardInfo retval = new LeaderboardInfo();

                retval.ikey        = n.GetAttribute("ikey");
                retval.board_id    = n.GetAttribute("board_id");
                retval.label       = n.GetAttribute("label");
                retval.resource_id = n.GetAttribute("resource_id");
                return(retval);
            }
Exemple #28
0
            public static UpdateEvent CreateFromXml(System.Xml.XmlElement n)
            {
                Events.UpdateEvent e = new Events.UpdateEvent();

                e.type = n.GetAttribute("type");
                e.ikey = n.GetAttribute("ikey");
                e.val  = n.GetAttribute("value");

                return(e);
            }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public HLAinteractionClass(System.Xml.XmlElement interactionElement)
     : base(interactionElement)
 {
     Semantics      = ReplaceNewLines(interactionElement.GetAttribute("semantics"));
     SemanticsNotes = interactionElement.GetAttribute("semanticsNotes");
     if (string.IsNullOrEmpty(interactionElement.GetAttribute("sharing")))
     {
         Sharing = HLAsharingType.Neither;
     }
     else
     {
         Sharing = (HLAsharingType)Enum.Parse(typeof(HLAsharingType), interactionElement.GetAttribute("sharing"));
     }
     SharingNotes   = interactionElement.GetAttribute("sharingNotes");
     dimensions     = interactionElement.GetAttribute("dimensions");
     transportation = interactionElement.GetAttribute("transportation");
     if (string.IsNullOrEmpty(interactionElement.GetAttribute("order")))
     {
         Order = HLAorderType.Receive;
     }
     else
     {
         Order = (HLAorderType)Enum.Parse(typeof(HLAorderType), interactionElement.GetAttribute("order"));
     }
 }
Exemple #30
0
        public DomainObjects.Cost ParseACost(System.Xml.XmlElement n)
        {
            DomainObjects.Cost retval;
            //TODO: Implement the rest!
            switch (n.Name)
            {
            case "stat_cost":
            {
                DomainObjects.Costs.Stat stat = new DomainObjects.Costs.Stat();
                stat.ikey = n.GetAttribute("ikey");
                stat.type = n.GetAttribute("type");
                if (!System.Int32.TryParse(n.GetAttribute("value"), out stat.value))
                {
                    throw new InvalidXMLElementException("Unable to parse value to integer.");
                }
                retval = stat;
            }
            break;

            case "stat_change":
            {
                DomainObjects.Costs.Stat stat = new DomainObjects.Costs.Stat();
                stat.ikey = n.GetAttribute("ikey");
                stat.type = n.GetAttribute("type");
                if (!System.Int32.TryParse(n.GetAttribute("value"), out stat.value))
                {
                    throw new InvalidXMLElementException("Unable to parse value to integer.");
                }
                if (stat.value < 0)
                {
                    stat.value = stat.value * -1;
                }

                retval = stat;
            }
            break;

            case "item_cost":
                DomainObjects.Costs.Item item = new DomainObjects.Costs.Item();
                item.ikey = n.GetAttribute("ikey");
                if (!System.Int32.TryParse(n.GetAttribute("number_required"), out item.number_required))
                {
                    throw new InvalidXMLElementException("Unable to parse number_required to integer.");
                }
                retval = item;
                break;

            default:
                throw new UnexpectedXMLElementException("Invalid cost type, \"" + n.Name + "\"");
            }

            retval.ok     = (n.GetAttribute("ok") == "true");
            retval.reason = n.GetAttribute("reason");
            return(retval);
        }
Exemple #31
0
        /// <summary> Parses the beepd element in the configuration file and loads the
        /// classes for the specified profiles.
        /// 
        /// </summary>
        /// <param name="serverConfig">&ltbeepd&gt configuration element.
        /// </param>
        private Beepd(Element serverConfig)
        {
            reg = new ProfileRegistry();

            if (serverConfig.HasAttribute("port") == false)
            {
                throw new System.Exception("Invalid configuration, no port specified");
            }

            port = System.Int32.Parse(serverConfig.GetAttribute("port"));

            // Parse the list of profile elements.
            NodeList profiles = serverConfig.GetElementsByTagName("profile");
            for (int i = 0; i < profiles.Count; ++i)
            {
                if (profiles[i].NodeType != System.Xml.XmlNodeType.Element)
                {
                    continue;
                }

                Element profile = (Element) profiles[i];

                if (profile.Name.ToUpper().Equals("profile".ToUpper()) == false)
                {
                    continue;
                }

                string uri;
                string className;
                //string requiredProperites;
                //string tuningProperties;

                if (profile.HasAttribute("uri") == false)
                {
                    throw new System.Exception("Invalid configuration, no uri specified");
                }

                uri = profile.GetAttribute("uri");

                if (profile.HasAttribute("class") == false)
                {
                    throw new System.Exception("Invalid configuration, no class " + "specified for profile " + uri);
                }

                className = profile.GetAttribute("class");

                // parse the parameter elements into a ProfileConfiguration
                ProfileConfiguration profileConfig = parseProfileConfig(profile.GetElementsByTagName("parameter"));

                // load the profile class
                IProfile p;
                try
                {
                    p = (IProfile) new beepcore.beep.profile.echo.EchoProfile(); //SupportClass.CreateNewInstance(System.Type.GetType(className));
                    //p = (IProfile) Activator.CreateInstance(Type.GetType(className, true, true));
                }
                catch (System.InvalidCastException)
                {
                    throw new System.Exception("class " + className + " does not " + "implement the " + "beepcore.beep.profile.Profile " + "interface");
                }
                catch (System.Exception e)
                {
                    throw new System.Exception("Class " + className + " not found - " + e.ToString());
                }

                SessionTuningProperties tuning = null;

                if (profile.HasAttribute("tuning"))
                {
                    string tuningString = profile.GetAttribute("tuning");
                    System.Collections.Hashtable hash = new System.Collections.Hashtable();
                    string[] tokens = tuningString.Split(":=".ToCharArray());

                    for(int tki=0; tki+1<tokens.Length; tki+=2) {
                        string parameter = tokens[tki];
                        string paramvalue = tokens[tki+1];

                        hash[parameter] = paramvalue;
                    }

                    tuning = new SessionTuningProperties(hash);
                }

                // Initialize the profile and add it to the advertised profiles
                reg.addStartChannelListener(uri, p.Init(uri, profileConfig), tuning);
            }

            thread = new Thread(new ThreadStart(this.ThreadProc));
        }