Ejemplo n.º 1
0
 /// <summary>
 /// Метод добавления новой строки в файл.
 /// </summary>
 public void NewLine()
 {
     //Добавление PDF-елемента на текущую страницу документа.
     pdfData.persistentPage.addElement(currentCharElem);
     //Создание нового елемента (абзаца).
     currentCharElem = new textElement(String.Empty, 14, currentPDFfont, 30, lastElemPostionY - 20);
     //Задание Y-координаты для новой строки на странице (отсчет координат с левого нижнего угла страницы).
     lastElemPostionY = lastElemPostionY - 20;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Конструктор конкретного продукта (документа) в формате PDF.
 /// </summary>
 public PDFText()
 {
     // Добавление новой страницы в PDF документ с разрешением 500х500px.
     pdfData.addPage(500, 500);
     //Устанавка шрифта документа по умолчанию.
     currentPDFfont = pdfData.getFontReference(pdfFont.getFontName(predefinedFont.csHelvetica));
     //Создание текстового елемента (в подключеной библиотеке sharpPDF это контейнер для символьных данных, аналогично блоку текста/f,pfwf).
     currentCharElem = new textElement(String.Empty, 14, currentPDFfont, 30, lastElemPostionY);
     //Устанавка Y-координаты последнего символа в документе.
     lastElemPostionY = currentCharElem.coordY;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Parse ADMX Files
        /// </summary>
        /// <param name="FilePath">Admx File Path</param>
        /// <param name="Language">Subfolder of the Admx File with the corresponding Adml File</param>
        public AdmxParse(string FilePath, string Language)
        {
            categories = new List <category>();
            policies   = new List <policy>();
            xPathMapping.LoadXml(Properties.Settings.Default.DevicePathMapping);

            FileInfo fiAdmx = new FileInfo(FilePath);

            if (fiAdmx.Exists)
            {
                FileInfo fiAdml = new FileInfo(Path.Combine(fiAdmx.DirectoryName, Language, fiAdmx.Name.Replace(".admx", ".adml")));
                if (fiAdml.Exists)
                {
                    xAdml.Load(fiAdml.FullName);
                }

                xAdmx.Load(FilePath);
                XmlNamespaceManager ns = new XmlNamespaceManager(xAdmx.NameTable);
                ns.AddNamespace("pd", xAdmx.DocumentElement.NamespaceURI);

                //Get categories
                foreach (XmlNode xCat in xAdmx.SelectNodes("/pd:policyDefinitions/pd:categories/pd:category", ns))
                {
                    try
                    {
                        var oRes = new category();
                        oRes.displayName = sResourceStringLookup(xCat.Attributes["displayName"].InnerText.Replace("$(string.", "").TrimEnd(')'));
                        oRes.name        = xCat.Attributes["name"].InnerText;
                        if (xCat["parentCategory"] == null)
                        {
                            //oRes.parent = oRes.name; ???
                            oRes.parent = "";

                            categories.Add(oRes);

                            continue;
                        }

                        oRes.parent = xCat["parentCategory"].Attributes["ref"].InnerText;
                        if (categories.FirstOrDefault(t => t.name == oRes.parent) == null)
                        {
                            var xParent = xPathMapping.SelectSingleNode("//*[@name='" + oRes.parent + "']");
                            if (xParent != null)
                            {
                                XmlNode xPar = xParent;
                                while (xPar != null)
                                {
                                    if (xPar.Name != "#document")
                                    {
                                        if (xPar.Attributes["name"] != null)
                                        {
                                            string sPar = "";
                                            if (xPar.ParentNode.Attributes["name"] != null)
                                            {
                                                sPar = xPar.ParentNode.Attributes["name"].Value;
                                            }
                                            categories.Add(new category()
                                            {
                                                name = xPar.Attributes["name"].Value, displayName = xPar.Attributes["displayname"].Value, parent = sPar
                                            });
                                        }
                                    }
                                    xPar = xPar.ParentNode;
                                }
                            }
                            else
                            {
                                string sDispName = oRes.parent;
                                categories.Add(new category()
                                {
                                    name = sDispName, displayName = sDispName, parent = ""
                                });
                            }
                        }

                        categories.Add(oRes);
                    }
                    catch (Exception ex)
                    {
                        ex.Message.ToString();
                    }
                }

                //Get Policies
                foreach (XmlNode xPol in xAdmx.SelectNodes("/pd:policyDefinitions/pd:policies/pd:policy", ns))
                {
                    var oRes = new policy();
                    oRes.elements    = new List <element>();
                    oRes.displayName = sResourceStringLookup(xPol.Attributes["displayName"].InnerText.Replace("$(string.", "").TrimEnd(')'));
                    oRes.name        = xPol.Attributes["name"].InnerText;
                    oRes.state       = policyState.NotConfigured;

                    if (string.IsNullOrEmpty(oRes.displayName))
                    {
                        oRes.displayName = oRes.name;
                    }

                    if (xPol.Attributes["explainText"] != null)
                    {
                        oRes.explainText = sResourceStringLookup(xPol.Attributes["explainText"].InnerText.Replace("$(string.", "").TrimEnd(')'));
                    }

                    oRes.parentCategory = categories.FirstOrDefault(t => t.name == xPol["parentCategory"].Attributes["ref"].InnerText);
                    catLookup(xPol["parentCategory"].Attributes["ref"].InnerText);
                    oRes.path = GetPath(xPol["parentCategory"].Attributes["ref"].InnerText);
                    var pCat = categories.FirstOrDefault(t => t.name == xPol["parentCategory"].Attributes["ref"].InnerText);
                    if (pCat != null)
                    {
                        oRes.displaypath = GetDisplayPath(pCat.displayName);
                    }
                    else
                    {
                        var xParent = xPathMapping.SelectSingleNode("//*[@name='" + xPol["parentCategory"].Attributes["ref"].InnerText + "']");
                        if (xParent != null)
                        {
                            string sDispName = xParent.Attributes["displayname"].Value;
                            string sName     = xParent.Attributes["name"].Value;
                            string sParent   = "";
                            if (xParent.ParentNode.Attributes["name"] != null)
                            {
                                sParent = xParent.ParentNode.Attributes["name"].Value;
                            }
                            categories.Add(new category()
                            {
                                name = sName, displayName = sDispName, parent = sParent
                            });
                            oRes.displaypath = GetDisplayPath(sDispName);
                        }
                    }

                    oRes.key = xPol.Attributes["key"].InnerText;
                    if (xPol.Attributes["presentation"] != null)
                    {
                        oRes.presentation = sPresentationStringLookup(xPol.Attributes["presentation"].InnerText.Replace("$(presentation.", "").TrimEnd(')'));
                    }
                    switch (xPol.Attributes["class"].InnerText)
                    {
                    case "Machine":
                        oRes.policyType = classType.Machine;
                        break;

                    case "User":
                        oRes.policyType = classType.User;
                        break;
                    }

                    //oRes.innerXML = xPol.InnerXml;

                    if (xPol.Attributes["valueName"] != null)
                    {
                        if (xPol["enabledValue"] != null)
                        {
                            polEnableElement oElem = new polEnableElement();
                            oElem.ValueName = xPol.Attributes["valueName"].InnerText;
                            oElem.ValueType = valueType.PolicyEnable;

                            if (xPol["enabledValue"]["decimal"] != null)
                            {
                                try
                                {
                                    oElem.enabledValue = uint.Parse(xPol["enabledValue"]["decimal"].Attributes["value"].Value);
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }
                            }

                            if (xPol["disabledValue"] != null)
                            {
                                if (xPol["disabledValue"]["decimal"] != null)
                                {
                                    try
                                    {
                                        oElem.disabledValue = uint.Parse(xPol["disabledValue"]["decimal"].Attributes["value"].Value);
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine(ex.Message);
                                    }
                                }
                            }

                            oRes.elements.Add(oElem);
                        }
                        else
                        {
                            polEnableElement oElem = new polEnableElement();
                            oElem.ValueName     = xPol.Attributes["valueName"].InnerText;
                            oElem.ValueType     = valueType.PolicyEnable;
                            oElem.enabledValue  = 1;
                            oElem.disabledValue = 0;

                            oRes.elements.Add(oElem);
                        }
                    }

                    if (xPol["elements"] != null)
                    {
                        foreach (XmlNode xElem in xPol["elements"].ChildNodes)
                        {
                            if (xElem.Name == "#comment")
                            {
                                continue;
                            }
                            if (xElem.Name == "#text")
                            {
                                continue;
                            }

                            element oElem = new element();

                            switch (xElem.Name.ToLower())
                            {
                            case "decimal":
                                oElem           = new decimalElement();
                                oElem.ValueType = valueType.Decimal;
                                if (xElem.Attributes["minValue"] != null)
                                {
                                    uint iRes = 0;
                                    if (uint.TryParse(xElem.Attributes["minValue"].InnerText, out iRes))
                                    {
                                        ((decimalElement)oElem).minValue = iRes;
                                    }
                                }
                                if (xElem.Attributes["maxValue"] != null)
                                {
                                    uint iRes = 0;
                                    if (uint.TryParse(xElem.Attributes["maxValue"].InnerText, out iRes))
                                    {
                                        ((decimalElement)oElem).maxValue = iRes;
                                    }
                                }
                                break;

                            case "enum":
                                oElem           = new enumElement();
                                oElem.ValueType = valueType.Enum;
                                ((enumElement)oElem).valueList = new Dictionary <string, string>();
                                foreach (XmlNode xElemItem in xElem.SelectNodes("pd:item", ns))
                                {
                                    try
                                    {
                                        string sDisplayName = sResourceStringLookup(xElemItem.Attributes["displayName"].Value.Replace("$(string.", "").TrimEnd(')'));
                                        if (string.IsNullOrEmpty(sDisplayName))
                                        {
                                            sDisplayName = xElemItem.Attributes["displayName"].Value.Replace("$(string.", "").TrimEnd(')');
                                        }
                                        if (xElemItem["value"].FirstChild.Name == "decimal")
                                        {
                                            if (xElemItem["value"].FirstChild.Attributes.Count > 0)
                                            {
                                                ((enumElement)oElem).valueList.Add(sDisplayName, xElemItem["value"].FirstChild.Attributes["value"].Value);
                                            }
                                            else
                                            {
                                                ((enumElement)oElem).valueList.Add(sDisplayName, xElemItem["value"].FirstChild.InnerText);
                                            }
                                        }
                                        if (xElemItem["value"].FirstChild.Name == "string")
                                        {
                                            ((enumElement)oElem).valueList.Add(sDisplayName, xElemItem["value"].FirstChild.InnerText);
                                        }
                                        string sDefault = oRes.sPresentationdefaultValue(xElem.Attributes["id"].Value);
                                        if (!string.IsNullOrEmpty(sDefault))
                                        {
                                            int iDef = 0;
                                            int.TryParse(sDefault, out iDef);

                                            ((enumElement)oElem).defaultItem = iDef;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine(ex.Message);
                                    }
                                }
                                break;

                            case "boolean":
                                oElem           = new decimalElement();
                                oElem.ValueType = valueType.Boolean;
                                ((decimalElement)oElem).minValue = 0;
                                ((decimalElement)oElem).maxValue = 1;
                                oElem.value = oRes.sPresentationdefaultValue(xElem.Attributes["id"].Value);
                                break;

                            case "list":
                                oElem           = new listElement();
                                oElem.ValueType = valueType.List;
                                ((listElement)oElem).valueList = new Dictionary <string, string>();
                                if (xElem.Attributes["additive"] != null)
                                {
                                    bool bRes = false;
                                    if (bool.TryParse(xElem.Attributes["additive"].Value, out bRes))
                                    {
                                        ((listElement)oElem).additive = bRes;
                                    }
                                    else
                                    {
                                        ((listElement)oElem).additive = null;
                                    }
                                }
                                if (xElem.Attributes["explicitValue"] != null)
                                {
                                    bool bRes = false;
                                    if (bool.TryParse(xElem.Attributes["explicitValue"].Value, out bRes))
                                    {
                                        ((listElement)oElem).explicitValue = bRes;
                                    }
                                    else
                                    {
                                        ((listElement)oElem).explicitValue = null;
                                    }
                                }
                                break;

                            case "text":
                                oElem           = new textElement();
                                oElem.ValueType = valueType.Text;
                                break;

                            default:
                                xElem.Name.ToString();
                                break;
                            }

                            oElem.value = oRes.sPresentationdefaultValue(xElem.Attributes["id"].InnerText);
                            //oElem.innerXML = xElem.OuterXml;

                            //List do not have a Value, they have List of Valuenames and Values
                            if (oElem.ValueType != valueType.List)
                            {
                                oElem.ValueName = xElem.Attributes["valueName"].InnerText;
                            }

                            if (xElem.Attributes["required"] != null)
                            {
                                bool bReq = false;
                                if (bool.TryParse(xElem.Attributes["required"].InnerText, out bReq))
                                {
                                    oElem.required = bReq;
                                }
                            }

                            if (xElem.Attributes["key"] != null)
                            {
                                oElem.key = xElem.Attributes["key"].Value;
                            }


                            oRes.elements.Add(oElem);
                        }
                    }

                    if (xPol["enabledList"] != null)
                    {
                        EnableListElement oElem = new EnableListElement();

                        oElem.ValueType        = valueType.Enum;
                        oElem.enabledValueList = new List <enabledList>();

                        foreach (XmlNode xElem in xPol["enabledList"].SelectNodes("pd:item", ns))
                        {
                            try
                            {
                                enabledList oResList = new enabledList();

                                if (xElem["value"].FirstChild.Name == "decimal")
                                {
                                    oResList.type      = valueType.Decimal;
                                    oResList.key       = xElem.Attributes["key"].Value;
                                    oResList.valueName = xElem.Attributes["valueName"].Value;
                                    oResList.value     = xElem["value"].FirstChild.Attributes["value"].Value;
                                }
                                if (xElem["value"].FirstChild.Name == "string")
                                {
                                    oResList.type      = valueType.Text;
                                    oResList.key       = xElem.Attributes["key"].Value;
                                    oResList.valueName = xElem.Attributes["valueName"].Value;
                                    if (xElem["value"].FirstChild.Attributes.Count > 0)
                                    {
                                        oResList.value = xElem["value"].FirstChild.Attributes["value"].Value;
                                    }
                                    else
                                    {
                                        oResList.value = xElem["value"].FirstChild.InnerText;
                                    }
                                }

                                oElem.enabledValueList.Add(oResList);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                        }


                        oRes.elements.Add(oElem);
                    }

                    if (xPol["disabledList"] != null)
                    {
                        EnableListElement oElem = new EnableListElement();

                        oElem.ValueType         = valueType.Enum;
                        oElem.disabledValueList = new List <enabledList>();

                        foreach (XmlNode xElem in xPol["disabledList"].SelectNodes("pd:item", ns))
                        {
                            try
                            {
                                enabledList oResList = new enabledList();

                                if (xElem["value"].FirstChild.Name == "decimal")
                                {
                                    oResList.type      = valueType.Decimal;
                                    oResList.key       = xElem.Attributes["key"].Value;
                                    oResList.valueName = xElem.Attributes["valueName"].Value;
                                    oResList.value     = xElem["value"].FirstChild.Attributes["value"].Value;
                                }
                                if (xElem["value"].FirstChild.Name == "string")
                                {
                                    oResList.type      = valueType.Text;
                                    oResList.key       = xElem.Attributes["key"].Value;
                                    oResList.valueName = xElem.Attributes["valueName"].Value;
                                    if (xElem["value"].FirstChild.Attributes.Count > 0)
                                    {
                                        oResList.value = xElem["value"].FirstChild.Attributes["value"].Value;
                                    }
                                    else
                                    {
                                        oResList.value = xElem["value"].FirstChild.InnerText;
                                    }
                                }

                                oElem.disabledValueList.Add(oResList);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                        }


                        oRes.elements.Add(oElem);
                    }

                    policies.Add(oRes);
                }
            }
        }