Beispiel #1
0
        public void Load(XElement xElement)
        {
            if (xElement == null)
            {
                throw new ArgumentNullException(nameof(xElement));
            }
            if (xElement.Name.LocalName != ShareInstructionElementName)
            {
                throw new ArgumentException(
                          $"Wrong element name: {xElement.Name.LocalName} instead of {ShareInstructionElementName}");
            }

            _content.Clear();
            IEnumerable <XElement> xElements = xElement.Elements();

            foreach (var element in xElements)
            {
                if (element.Name.LocalName == PartShareInstructionType.PartElementName)
                {
                    PartShareInstructionType part = new PartShareInstructionType {
                        Namespace = _fileNameSpace
                    };
                    try
                    {
                        part.Load(element);
                        _content.Add(part);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"Error loading part type: {ex.Message}");
                    }
                }
                else if (element.Name.LocalName == OutPutDocumentType.OutputDocumentElementName)
                {
                    OutPutDocumentType doc = new OutPutDocumentType {
                        Namespace = _fileNameSpace
                    };
                    try
                    {
                        doc.Load(element);
                        _content.Add(doc);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"Error loading output document type: {ex.Message}");
                    }
                }
                else
                {
                    Debug.WriteLine($"Invalid element type encoutered {element.Name.LocalName}");
                }
            }

            XAttribute xSharedMode = xElement.Attribute("mode");

            if (xSharedMode == null || string.IsNullOrEmpty(xSharedMode.Value))
            {
                Debug.WriteLine("mode attribute is required attribute");
            }
            else
            {
                switch (xSharedMode.Value)
                {
                case "free":
                    SharedMode = ShareModeEnum.Free;
                    break;

                case "paid":
                    SharedMode = ShareModeEnum.Paid;
                    break;

                default:
                    Debug.WriteLine($"Invalid shared mode type : {xSharedMode.Value}");
                    break;
                }
            }


            XAttribute xIncludeAll = xElement.Attribute("include-all");

            if (xIncludeAll == null || string.IsNullOrEmpty(xIncludeAll.Value))
            {
                Debug.WriteLine("mode attribute is required attribute");
            }
            else
            {
                switch (xIncludeAll.Value)
                {
                case "require":
                    Instruction = GenerationInstructionEnum.Require;
                    break;

                case "allow":
                    Instruction = GenerationInstructionEnum.Allow;
                    break;

                case "deny":
                    Instruction = GenerationInstructionEnum.Deny;
                    break;

                default:
                    Debug.WriteLine($"Invalid instruction type : {xIncludeAll.Value}");
                    break;
                }
            }

            Price = null;
            XAttribute xPrice = xElement.Attribute("price");

            if ((xPrice != null) && !string.IsNullOrEmpty(xPrice.Value))
            {
                float val;
                if (float.TryParse(xPrice.Value, out val))
                {
                    Price = val;
                }
            }


            Currency = null;
            XAttribute xCurrency = xElement.Attribute("currency");

            if (xCurrency != null)
            {
                Currency = xCurrency.Value;
            }
        }
        public void Load(XElement xElement)
        {
            if (xElement == null)
            {
                throw new ArgumentNullException("xElement");
            }
            if (xElement.Name.LocalName != ShareInstructionElementName)
            {
                throw new ArgumentException(string.Format("Wrong element name: {0} instead of {1}",xElement.Name.LocalName,ShareInstructionElementName));
            }

            content.Clear();
            IEnumerable<XElement> xElements = xElement.Elements();
            foreach (var element in xElements)
            {   
                if (element.Name.LocalName == PartShareInstructionType.PartElementName)
                {
                    PartShareInstructionType part = new PartShareInstructionType{Namespace = fileNameSpace};
                    try
                    {
                        part.Load(element);
                        content.Add(part);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Error loading part type: {0}",ex.Message));
                    }
                }
                else if (element.Name.LocalName == OutPutDocumentType.OutputDocumentElementName)
                {
                    OutPutDocumentType doc = new OutPutDocumentType{Namespace = fileNameSpace};
                    try
                    {
                        doc.Load(element);
                        content.Add(doc);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Error loading output document type: {0}", ex.Message));
                    }
                }
                else
                {
                    Debug.Fail(string.Format("Invalid element type encoutered {0}", element.Name.LocalName));
                }
            }

            XAttribute xSharedMode = xElement.Attribute("mode");
            if ((xSharedMode == null) || string.IsNullOrEmpty(xSharedMode.Value) )
            {
                Debug.Fail("mode attribute is required attribute");
            }
            else
            {
                switch (xSharedMode.Value)
                {
                    case "free":
                        SharedMode = ShareModeEnum.Free;
                        break;
                    case "paid":
                        SharedMode = ShareModeEnum.Paid;
                        break;
                    default:
                        Debug.Fail(string.Format("Invalid shared mode type : {0}", xSharedMode.Value));
                        break;
                }
            }


            XAttribute xIncludeAll = xElement.Attribute("include-all");
            if ((xIncludeAll == null) || string.IsNullOrEmpty(xIncludeAll.Value))
            {
                Debug.Fail("mode attribute is required attribute");
            }
            else
            {
                switch (xIncludeAll.Value)
                {
                    case "require":
                        Instruction = GenerationInstructionEnum.Require;
                        break;
                    case "allow":
                        Instruction = GenerationInstructionEnum.Allow;
                        break;
                    case "deny":
                        Instruction = GenerationInstructionEnum.Deny;
                        break;
                    default:
                        Debug.Fail(string.Format("Invalid instruction type : {0}", xIncludeAll.Value));
                        break;
                }
            }

            Price = null;
            XAttribute xPrice = xElement.Attribute("price");
            if ((xPrice != null) && !string.IsNullOrEmpty(xPrice.Value))
            {
                float val;
                if (float.TryParse(xPrice.Value,out val))
                {
                    Price = val;
                }
            }


            Currency = null;
            XAttribute xCurrency = xElement.Attribute("currency");
            if (xCurrency != null) 
            {
                Currency = xCurrency.Value;
            }
        }