Esempio n. 1
0
        /// <exclude />
        public XElement Serialize()
        {
            using (var cultureInvariant = new ThreadCultureScope(CultureInfo.InvariantCulture))
            {
                IXmlSerializer xmlSerializer = new XmlSerializer(new IValueXmlSerializer[] {
                new SystemPrimitivValueXmlSerializer(),
                new SystemCollectionValueXmlSerializer(),
                new SystemTypesValueXmlSerializer(),
                new CompositeCollectionValueXmlSerializer(),
                new DataFieldDescriptorValueXmlSerializer(),
                new DataTypeDescriptorValueXmlSerializer(),
                new NamedFunctionCallValueXmlSerializer(),
                new SerializerHandlerValueXmlSerializer(),
                new SystemSerializableValueXmlSerializer() });


                XElement containerLabelElement = new XElement("ContainerLabel");
                if (this.ContainerLabel != null)
                {
                    containerLabelElement.Add(new XAttribute("value", this.ContainerLabel));
                }


                XElement formDefinitionElement = new XElement("FormDefinition");
                if (this.FormDefinition != null)
                {
                    formDefinitionElement.Add(new XAttribute("value", this.FormDefinition));
                }
                else
                {
                    using (XmlReader xmlReader = this.FormMarkupProvider.GetReader())
                    {
                        xmlReader.MoveToContent();
                        XElement element = (XElement)XDocument.ReadFrom(xmlReader);
                        XDocument document = new XDocument(element);
                        string content = document.GetDocumentAsString();
                        formDefinitionElement.Add(new XAttribute("value", content));
                    }
                }


                XElement customToolbarDefinitionElement = new XElement("CustomToolbarDefinition");
                if (this.CustomToolbarDefinition != null)
                {
                    customToolbarDefinitionElement.Add(new XAttribute("value", this.CustomToolbarDefinition));
                }
                else if (this.CustomToolbarMarkupProvider != null)
                {
                    using (XmlReader xmlReader = this.CustomToolbarMarkupProvider.GetReader())
                    {
                        xmlReader.MoveToContent();
                        XElement element = (XElement)XDocument.ReadFrom(xmlReader);
                        XDocument document = new XDocument(element);
                        string content = document.GetDocumentAsString();
                        customToolbarDefinitionElement.Add(new XAttribute("value", content));
                    }
                }


                XElement containerTypeElement = xmlSerializer.Serialize(typeof(IFlowUiContainerType), this.ContainerType);


                Dictionary<string, object> selectedBindings =
                    (from kvp in this.Bindings
                     where (kvp.Value != null &&
                            kvp.Value.GetType() != typeof(System.EventHandler)) ||
                            kvp.Value == null
                     select kvp).ToDictionary(f => f.Key, f => f.Value);
                XElement bindingsElement = xmlSerializer.Serialize(typeof(Dictionary<string, object>), selectedBindings);

                XElement bindingsValidationRulesElement = xmlSerializer.Serialize(typeof(Dictionary<string, List<ClientValidationRule>>), this.BindingsValidationRules);

                XElement excludedEventsElement = xmlSerializer.Serialize(typeof(List<string>), ExcludedEvents);

                XElement formDataElement = new XElement("FormData");
                formDataElement.Add(containerLabelElement);
                formDataElement.Add(formDefinitionElement);
                formDataElement.Add(customToolbarDefinitionElement);
                formDataElement.Add(new XElement("ContainerType", containerTypeElement));
                formDataElement.Add(new XElement("Bindings", bindingsElement));
                formDataElement.Add(new XElement("BindingsValidationRules", bindingsValidationRulesElement));
                if (excludedEventsElement != null) formDataElement.Add(new XElement("ExcludedEvents", excludedEventsElement));

                if (this.EventHandleFilterType != null)
                {
                    formDataElement.Add(new XElement("EventHandleFilterType", new XAttribute("type", TypeManager.SerializeType(this.EventHandleFilterType))));
                }

                return formDataElement;
            }
        }
        public Stream GetInstallFileStream(string packageFileDownloadUrl)
        {
            Initialize();

            PackageDescription packageDescription = null;
            ExtraInfo extraInfo = null;
            foreach (List<KeyValuePair<PackageDescription, ExtraInfo>> packageDescriptions in _packageDescriptions.Values)
            {
                KeyValuePair<PackageDescription, ExtraInfo>? q =
                    (from desc in packageDescriptions
                     where desc.Key.PackageFileDownloadUrl == packageFileDownloadUrl
                     select desc).FirstOrDefault();

                if (q != null)
                {
                    packageDescription = q.Value.Key;
                    extraInfo = q.Value.Value;
                    break;
                }
            }

            XElement rootElement =
                new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInstallerElementName),
                    new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageRequirementsElementName),
                        new XAttribute(PackageSystemSettings.MinimumCompositeVersionAttributeName, packageDescription.MinCompositeVersionSupported),
                        new XAttribute(PackageSystemSettings.MaximumCompositeVersionAttributeName, packageDescription.MaxCompositeVersionSupported)
                    ),
                    new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInformationElementName),
                        new XAttribute(PackageSystemSettings.IdAttributeName, packageDescription.Id),
                        new XAttribute(PackageSystemSettings.NameAttributeName, packageDescription.Name),
                        new XAttribute(PackageSystemSettings.GroupNameAttributeName, packageDescription.GroupName),
                        new XAttribute(PackageSystemSettings.AuthorAttributeName, packageDescription.Vendor),
                        new XAttribute(PackageSystemSettings.WebsiteAttributeName, packageDescription.ReadMoreUrl),
                        new XAttribute(PackageSystemSettings.VersionAttributeName, packageDescription.PackageVersion),
                        new XAttribute(PackageSystemSettings.CanBeUninstalledAttributeName, extraInfo.CanBeUninstalled),
                        new XAttribute(PackageSystemSettings.SystemLockingAttributeName, extraInfo.SystemLockingType.Serialize()),
                        new XAttribute(PackageSystemSettings.FlushOnCompletionAttributeName, extraInfo.FlushOnCompletion),
                        new XAttribute(PackageSystemSettings.ReloadConsoleOnCompletionAttributeName, extraInfo.ReloadConsoleOnCompletion),
                        packageDescription.Description
                    ),
                    new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageFragmentInstallersElementName))
                );

            XDocument doc = new XDocument(rootElement);
            string content = doc.GetDocumentAsString();

            UTF8Encoding encoding = new UTF8Encoding();
            byte[] buffer = encoding.GetBytes(content);

            MemoryStream outputStream = new MemoryStream();

            ZipOutputStream zipStream = new ZipOutputStream(outputStream);

            Crc32 crc = new Crc32();
            crc.Update(buffer);

            ZipEntry zipEntry = new ZipEntry("install.xml");
            zipEntry.Size = buffer.Length;
            zipEntry.Crc = crc.Value;
            zipEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(zipEntry);
            zipStream.Write(buffer, 0, buffer.Length);
            zipStream.Finish();

            outputStream.Seek(0, SeekOrigin.Begin);

            return outputStream;
        }