コード例 #1
0
        string GetXml(T element)
        {
            if (element == null)
            {
                return(String.Empty);
            }
            MemoryStream stream;
            string       xml = String.Empty;

            if (XmlSerializerBase <T> .Write(element, out stream))
            {
                byte[] bytes = stream.ToArray();
                try {
                    xml = new String((new UTF8Encoding()).GetChars(stream.ToArray()));
                    xml = xml.Replace(" xmlns=\"http://www.PeerProject.com/schemas/Skin.xsd\"", String.Empty);
                    xml = xml.Replace("<?xml version=\"1.0\"?>\r\n", String.Empty);
                } catch { }
                stream.Close();
            }
            return(xml);
        }
コード例 #2
0
ファイル: StringPageViewImpl.cs プロジェクト: sahwar/Envy
        public override bool AutoSaveUpdates()
        {
            if (ElementIndex < 0 || !base.Dirty && String.IsNullOrEmpty(richUpdate.Text))             // can not be empty
            {
                return(true);
            }
            string     xml        = richUpdate.Xml;
            skinString currString = newEnList[ElementIndex];

            if (base.Dirty)
            {
                if (String.IsNullOrEmpty(xml))
                {
                    base.SetError(richUpdate.XmlError);
                    return(false);
                }
                else
                {
                    Exception exeption;
                    skin      testSkin = XmlSerializerBase <skin> .ReadString(String.Format(Envelope, xml),
                                                                              out exeption);

                    if (testSkin == null || exeption != null)
                    {
                        base.SetError(exeption.InnerException != null ? exeption.InnerException.Message :
                                      exeption.Message);
                        return(false);
                    }
                    else
                    {
                        if (testSkin.strings == null || testSkin.strings.Length == 0)
                        {
                            base.SetError(Settings.Default.InvalidXml);
                            return(false);
                        }
                        if (currString.id != testSkin.strings[0].id)
                        {
                            base.SetError(Settings.Default.InvalidId);
                            return(false);
                        }
                        if (testSkin.strings[0].Text != null)
                        {
                            base.SetError(Settings.Default.TextJunk);
                            return(false);
                        }
                        if (testSkin.strings[0].junk != null)
                        {
                            base.SetError(Settings.Default.ExtraText);
                            return(false);
                        }
                        base.Dirty = false;
                    }
                }
            }

            if (!updatedXmlDic.ContainsKey(currString.id))
            {
                updatedXmlDic.Add(currString.id, xml);
            }
            else
            {
                updatedXmlDic[currString.id] = xml;
            }
            return(true);
        }
コード例 #3
0
        public override bool AutoSaveUpdates()
        {
            if (ElementIndex < 0 || !base.Dirty && String.IsNullOrEmpty(richUpdate.Text)) // can not be empty
            {
                return(true);
            }
            string     xml        = richUpdate.Xml;
            skinDialog currDialog = newEnList[ElementIndex];

            if (base.Dirty)
            {
                if (String.IsNullOrEmpty(xml))
                {
                    base.SetError(richUpdate.XmlError);
                    return(false);
                }
                else
                {
                    Exception exeption;
                    skin      testSkin = XmlSerializerBase <skin> .ReadString(String.Format(Envelope, xml),
                                                                              out exeption);

                    if (testSkin == null || exeption != null)
                    {
                        base.SetError(exeption.InnerException != null ? exeption.InnerException.Message :
                                      exeption.Message);
                        return(false);
                    }
                    else
                    {
                        if (testSkin.dialogs == null || testSkin.dialogs.Length == 0)
                        {
                            base.SetError(Settings.Default.InvalidXml);
                            return(false);
                        }
                        if (currDialog.cookie != testSkin.dialogs[0].cookie)
                        {
                            base.SetError(Settings.Default.InvalidCookie);
                            return(false);
                        }
                        if (currDialog.name != testSkin.dialogs[0].name)
                        {
                            base.SetError(Settings.Default.InvalidDialogName);
                            return(false);
                        }
                        if (!String.IsNullOrEmpty(currDialog.caption) &&
                            String.IsNullOrEmpty(testSkin.dialogs[0].caption))
                        {
                            base.SetError(Settings.Default.MissingCaption);
                            return(false);
                        }
                        if (testSkin.dialogs[0].Text != null)
                        {
                            base.SetError(Settings.Default.TextJunk);
                            return(false);
                        }
                        if (testSkin.dialogs[0].junk != null)
                        {
                            base.SetError(Settings.Default.ExtraText);
                            return(false);
                        }
                        int count   = currDialog.controls == null ? 0 : currDialog.controls.Length;
                        int trCount = testSkin.dialogs[0].controls == null ? 0 : testSkin.dialogs[0].controls.Length;
                        if (trCount != count)
                        {
                            base.SetError(Settings.Default.InvalidControlCount);
                            return(false);
                        }
                        for (int i = 0; i < count; i++)
                        {
                            if (testSkin.dialogs[0].controls[i].junk != null)
                            {
                                base.SetError(String.Format(Settings.Default.ExtraControlAttributes, i + 1));
                                return(false);
                            }
                            if (currDialog.controls[i].caption == String.Empty &&
                                testSkin.dialogs[0].controls[i].caption != String.Empty ||
                                currDialog.controls[i].caption != String.Empty &&
                                testSkin.dialogs[0].controls[i].caption == String.Empty)
                            {
                                base.SetError(String.Format(Settings.Default.InvalidControl, i + 1));
                                return(false);
                            }
                        }
                        base.Dirty = false;
                    }
                }
            }

            if (!updatedXmlDic.ContainsKey(currDialog.name))
            {
                updatedXmlDic.Add(currDialog.name, xml);
            }
            else
            {
                updatedXmlDic[currDialog.name] = xml;
            }
            return(true);
        }
コード例 #4
0
        protected bool GetElementList(string filePath, FileType fileType, ref List <T> list, out skinManifest manifest)
        {
            if (String.IsNullOrEmpty(filePath) || !File.Exists(filePath))
            {
                manifest = null;
                return(false);
            }

            Exception exception;
            var       skin = XmlSerializerBase <skin> .Read(filePath, out exception);

            if (exception != null)
            {
                if (exception.InnerException != null)
                {
                    MessageBox.Show(exception.InnerException.Message, Settings.Default.Error,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(exception.Message, Settings.Default.Error,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                list = null;
            }
            else if (skin != null)
            {
                object[] elements = skin.GetElements(typeof(T));
                if (elements != null && elements.Length > 0)
                {
                    manifest = skin.manifest;
                    list     = elements.Cast <T>().OrderBy(s => s.Id).ToList();

                    XmlNameTable nameTable = skin.RootElement.OwnerDocument.NameTable;
                    var          nsmgr     = new XmlNamespaceManager(nameTable);
                    nsmgr.AddNamespace("ss", "http://www.PeerProject.com/schemas/Skin.xsd");
                    XmlElement root      = skin.RootElement;
                    string     nodeName  = skin.GetElementName(typeof(T));
                    string     childName = skin.GetElementChildName(typeof(T));

                    foreach (var element in list)
                    {
                        if (!(element is INamedElement))
                        {
                            continue;
                        }
                        INamedElement ne    = (INamedElement)element;
                        string        xpath = String.Format("/ss:skin/ss:{0}/ss:{1}[@{2}='{3}']",
                                                            nodeName, childName, element.IdName, element.Id);
                        XmlNodeList nl = root.SelectNodes(xpath, nsmgr);
                        if (nl.Count > 0)
                        {
                            var xe = nl[0] as XmlElement;
                            if (xe != null)
                            {
                                element.NodeList = xe.ChildNodes;
                            }
                        }
                    }

                    if (fileType == FileType.OldEnglish)
                    {
                        _oldFilePath = filePath;
                    }
                    else if (fileType == FileType.NewEnglish)
                    {
                        _newFilePath = filePath;
                    }
                    else if (fileType == FileType.Updated)
                    {
                        _updatedFilePath = filePath;
                    }
                    return(true);
                }
            }

            manifest = null;
            return(false);
        }