Exemplo n.º 1
0
 private void FormatXmlGrammar()
 {
     foreach (XmlElement itemElement in RootDocument.GetElementsByTagName("item"))
     {
         String innerText = String.Empty;
         foreach (XmlNode node in itemElement.ChildNodes)
         {
             if (node.NodeType == XmlNodeType.Text)
             {
                 String   oldItem = node.InnerText.Trim();
                 String[] words   = oldItem.Split(' ');
                 String   newItem = String.Empty;
                 for (int i = 0; i < words.Length; i++)
                 {
                     int num;
                     if (Int32.TryParse(words[i], out num))
                     {
                         words[i] = ConvertIntegerToWords(num);
                     }
                     newItem += words[i] + " ";
                 }
                 newItem.Trim();
                 node.InnerText = newItem;
             }
         }
     }
 }
        public override void ConsoleDump(int tab)
        {
            System.Diagnostics.Trace.Write(new string( ' ', tab * 4 ));
            System.Diagnostics.Trace.WriteLine("FloatingDocumentWindow()");

            RootDocument.ConsoleDump(tab + 1);
        }
Exemplo n.º 3
0
        private void SetValue(SettingsPropertyValue propertyValue)
        {
            XmlNode targetNode = IsGlobal(propertyValue.Property)
               ? GlobalSettingsNode
               : LocalSettingsNode;

            XmlNode settingNode = targetNode.SelectSingleNode(string.Format("setting[@name='{0}']", propertyValue.Name));

            if (settingNode != null)
            {
                settingNode.InnerText = propertyValue.SerializedValue.ToString();
            }
            else
            {
                settingNode = RootDocument.CreateElement("setting");

                XmlAttribute nameAttribute = RootDocument.CreateAttribute("name");
                nameAttribute.Value = propertyValue.Name;

                settingNode.Attributes.Append(nameAttribute);
                settingNode.InnerText = propertyValue.SerializedValue.ToString();

                targetNode.AppendChild(settingNode);
            }
        }
Exemplo n.º 4
0
        public void InitialSerialization()
        {
            // check the document for controls and directives
            RootDocument.InitControlsAndDirectives();

            // init the designer context tags, and find the absolute path to the current project
            var view = editorHost.DesignerView as AspNetEdit.Editor.UI.RootDesignerView;

            view.InitProperties();

            // pass the freshly generated designer context to the html serializer
            serializer.SetDesignerContext(view.DesignerContext);

            // serialize the document for displaying in the designer
            SerializeDocument();

            // subscribe to changes in the component container
            container.ComponentChanged += new ComponentChangedEventHandler(OnComponentUpdated);

            // serialize when a transaction is closed
            TransactionClosed += new DesignerTransactionCloseEventHandler(this_OnTransactionClosed);

            // subscibe for undo or redo events
            RootDocument.UndoRedo += document_OnUndoRedo;
        }
Exemplo n.º 5
0
        public void SaveDocument(Stream file)
        {
            StreamWriter writer = new StreamWriter(file);

            writer.Write(RootDocument.PersistDocument());
            writer.Flush();
        }
Exemplo n.º 6
0
        private XmlNode GetSettingsNode(string name)
        {
            XmlNode settingsNode = RootNode.SelectSingleNode(name);

            if (settingsNode == null)
            {
                settingsNode = RootDocument.CreateElement(name);
                RootNode.AppendChild(settingsNode);
            }

            return(settingsNode);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Serializes the document with re-checking the components for updated tags.
        /// </summary>
        public void SerializeDocumentHard()
        {
            // unsubscribe for those events during the persisting of the document
            container.ComponentChanged -= OnComponentUpdated;
            TransactionClosed          -= this_OnTransactionClosed;

            RootDocument.PersistControls();
            string html = serializer.GetDesignableHtml();

            OnDocumentChanged(html);

            container.ComponentChanged += OnComponentUpdated;
            TransactionClosed          += this_OnTransactionClosed;
        }
Exemplo n.º 8
0
        public IComponent CreateComponent(Type componentClass, string name)
        {
            Console.WriteLine("Attempting to create component " + name);
            //check arguments
            if (componentClass == null)
            {
                throw new ArgumentNullException("componentClass");
            }
            if (!componentClass.IsSubclassOf(typeof(System.Web.UI.Control)) && componentClass != typeof(System.Web.UI.Control))
            {
                throw new ArgumentException("componentClass must be a subclass of System.Web.UI.Control, but is a " + componentClass.ToString(), "componentClass");
            }

            if (componentClass.IsSubclassOf(typeof(System.Web.UI.Page)))
            {
                throw new InvalidOperationException("You cannot directly add a page to the host. Use NewFile() instead");
            }

            //create the object
            IComponent component = (IComponent)Activator.CreateInstance(componentClass);

            //and add to container
            container.Add(component, name);

            //add to document, unless loading
            if (RootDocument != null)
            {
                ((Control)RootComponent).Controls.Add((Control)component);
                RootDocument.AddControl((Control)component);
            }

            //select it
            ISelectionService sel = this.GetService(typeof(ISelectionService)) as ISelectionService;

            if (sel != null)
            {
                sel.SetSelectedComponents(new IComponent[] { component });
            }


            return(component);
        }
Exemplo n.º 9
0
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            foreach (SettingsPropertyValue propertyValue in collection)
            {
                SetValue(propertyValue);
            }

            try
            {
                RootDocument.Save(FilePath);
            }
            catch (Exception)
            {
                /*
                 * If this is a portable application and the device has been
                 * removed then this will fail, so don't do anything. It's
                 * probably better for the application to stop saving settings
                 * rather than just crashing outright. Probably.
                 */
            }
        }
Exemplo n.º 10
0
        public void DestroyComponent(IComponent component)
        {
            //deselect it if selected
            ISelectionService sel = this.GetService(typeof(ISelectionService)) as ISelectionService;
            bool found            = false;

            if (sel != null)
            {
                foreach (IComponent c in sel.GetSelectedComponents())
                {
                    if (c == component)
                    {
                        found = true;
                        break;
                    }
                }
            }
            //can't modify selection in loop
            if (found)
            {
                sel.SetSelectedComponents(null);
            }

            if (component != RootComponent)
            {
                //remove from component and document
                ((Control)RootComponent).Controls.Remove((Control)component);
                RootDocument.RemoveControl((Control)component);
            }

            //remove from container if still sited
            if (component.Site != null)
            {
                container.Remove(component);
            }

            component.Dispose();
        }
 private static void SaveDocumentMap(IEnumerable<KeyValuePair<string, string>> documentMap)
 {
     if (documentMap != null)
     {
         string filePath = Path.Combine(s_SharepointMock, @"Documents.xml");
         RootDocument rootDocument = new RootDocument(documentMap);
         s_Mutex.WaitOne();
         try
         {
             using (StreamWriter writer = new StreamWriter(filePath))
             {
                 s_Serializer.Serialize(writer, rootDocument);
             }
         }
         finally
         {
             s_Mutex.ReleaseMutex();
         }
     }
 }
Exemplo n.º 12
0
        public async Task <EventStreamModel> WriteToEventStreamAsync(string streamId, EventModel[] events,
                                                                     object metaData      = null,
                                                                     long?expectedVersion = null, CancellationToken cancellationToken = default
                                                                     )
        {
            if (streamId.IsEmptyNullOrWhiteSpace())
            {
                throw new ArgumentException("A stream id is required.", nameof(streamId));
            }

            if (events is null || events.Length == 0)
            {
                throw new ArgumentException("You must supply events.", nameof(events));
            }

            var updating = expectedVersion.HasValue;

            var root = await ReadRootAsync(streamId, cancellationToken);

            if (root is null && expectedVersion.HasValue)
            {
                throw new EventStoreNotFoundException($"Stream '{streamId}' wasn't found.");
            }

            if (root is not null && !expectedVersion.HasValue)
            {
                throw new EventStoreConcurrencyException($"Stream '{streamId}' exists, therefore you must specify an expected version.");
            }

            var docs = new List <EventStoreDocument>();

            if (updating)
            {
                if (root.Version != expectedVersion)
                {
                    throw new EventStoreConcurrencyException(
                              $"Expected stream '{streamId}' to have version {expectedVersion.Value} but is {root.Version}."
                              );
                }

                root.TimeStamp = DateTimeOffset.Now.ToUnixTimeSeconds();

                if (metaData is not null)
                {
                    root.Data     = metaData;
                    root.DataType = metaData.GetType().AssemblyQualifiedName;
                }
            }
            else
            {
                root = new RootDocument
                {
                    StreamId  = streamId,
                    TimeStamp = DateTimeOffset.Now.ToUnixTimeSeconds(),
                    Data      = metaData,
                    DataType  = metaData?.GetType().AssemblyQualifiedName
                };

                docs.Add(root);
            }

            var curVersion = root.Version;

            root.Version += events.Length;

            var ret = new EventStreamModel
            {
                StreamId  = streamId,
                Version   = root.Version,
                TimeStamp = DateTimeOffset.FromUnixTimeSeconds(root.TimeStamp)
            };

            var lst = new List <EventModel>();

            for (long i = 0; i < events.Length; i++)
            {
                var eDoc = BuildEventDoc(events[i], streamId, root.TimeStamp, ++curVersion);
                docs.Add(eDoc);

                lst.Add(new EventModel
                {
                    Data     = events[i],
                    DataType = eDoc.DataType
                }
                        );
            }

            ret.Events = lst.ToArray();

            await Repository.AddAsync(docs.ToArray(), cancellationToken);

            if (updating)
            {
                await Repository.UpdateAsync(root, cancellationToken);
            }

            return(ret);
        }
Exemplo n.º 13
0
 public string PersistDocument()
 {
     return(RootDocument.PersistDocument());
 }