Esempio n. 1
0
        /// <summary>
        /// Loads the document from the given input args.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        Document LoadFromMessage(ViewMessage message)
        {
            Contract.Requires <ArgumentNullException>(message != null);

            // load save data
            if (message.Save != null)
            {
                return(LoadFromSave(message.Save));
            }

            // load hash data
            if (message.Hash != null)
            {
                return(LoadFromHash(message.Hash));
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the commands packed in the arguments.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        void Execute(Document document, ViewMessage message)
        {
            Contract.Requires <ArgumentNullException>(message != null);
            Contract.Requires <InvalidOperationException>(document != null);

            if (message.Commands != null)
            {
                foreach (var command in message.Commands)
                {
                    if (command is Commands.Update)
                    {
                        var cmd = (Commands.Update)command;
                        ClientUpdate(document, cmd.NodeId, cmd.Interface, cmd.Property, cmd.Value);
                    }

                    if (command is Commands.Invoke)
                    {
                        var cmd = (Commands.Invoke)command;
                        ClientInvoke(document, cmd.NodeId, cmd.Interface, cmd.Method, cmd.Parameters);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Loads and executes the object.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public ViewMessage Load(ViewMessage message)
        {
            Contract.Requires <ArgumentNullException>(message != null);

            // load document from args
            var document = LoadFromMessage(message);

            if (document == null)
            {
                return(new ViewMessage(ViewMessageStatus.NotFound));
            }

            try
            {
                Execute(Load(() => document), message);
            }
            catch (Exception)
            {
                return(new ViewMessage(ViewMessageStatus.Error));
            }

            // save and return document
            return(Save(document, ViewMessageStatus.Good));
        }
Esempio n. 4
0
        /// <summary>
        /// Executes the commands packed in the arguments.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        void Execute(Document document, ViewMessage message)
        {
            Contract.Requires<ArgumentNullException>(message != null);
            Contract.Requires<InvalidOperationException>(document != null);

            if (message.Commands != null)
            {
                foreach (var command in message.Commands)
                {
                    if (command is Commands.Update)
                    {
                        var cmd = (Commands.Update)command;
                        ClientUpdate(document, cmd.NodeId, cmd.Interface, cmd.Property, cmd.Value);
                    }

                    if (command is Commands.Invoke)
                    {
                        var cmd = (Commands.Invoke)command;
                        ClientInvoke(document, cmd.NodeId, cmd.Interface, cmd.Method, cmd.Parameters);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Loads the document from the given input args.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        Document LoadFromMessage(ViewMessage message)
        {
            Contract.Requires<ArgumentNullException>(message != null);

            // load save data
            if (message.Save != null)
                return LoadFromSave(message.Save);

            // load hash data
            if (message.Hash != null)
                return LoadFromHash(message.Hash);

            return null;
        }
Esempio n. 6
0
        /// <summary>
        /// Loads and executes the object.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public ViewMessage Load(ViewMessage message)
        {
            Contract.Requires<ArgumentNullException>(message != null);

            // load document from args
            var document = LoadFromMessage(message);
            if (document == null)
                return new ViewMessage(ViewMessageStatus.NotFound);

            try
            {
                Execute(Load(() => document), message);
            }
            catch (Exception)
            {
                return new ViewMessage(ViewMessageStatus.Error);
            }

            // save and return document
            return Save(document, ViewMessageStatus.Good);
        }
Esempio n. 7
0
File: View.cs Progetto: nxkit/nxkit
 /// <summary>
 /// Loads view state information.
 /// </summary>
 /// <param name="savedState"></param>
 protected override void LoadViewState(object savedState)
 {
     var o = (object[])savedState;
     if ((string)o[0] != null)
         message = server.Load(JsonConvert.DeserializeObject<ViewMessage>(((string)o[0])));
     cssClass = (string)o[1];
     validationGroup = (string)o[2];
 }
Esempio n. 8
0
File: View.cs Progetto: nxkit/nxkit
        /// <summary>
        /// Loads the specified <see cref="Uri"/> into the view.
        /// </summary>
        /// <param name="uri"></param>
        public void Open(string uri)
        {
            Contract.Requires<ArgumentNullException>(uri != null);

            message = server.Load(uri);
        }
Esempio n. 9
0
File: View.cs Progetto: nxkit/nxkit
        /// <summary>
        /// Loads any view state from custom fields.
        /// </summary>
        /// <param name="postDataKey"></param>
        /// <param name="postCollection"></param>
        /// <returns></returns>
        bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            if (Page.IsCallback)
                return false;

            var text = postCollection[postDataKey];
            if (!string.IsNullOrWhiteSpace(text))
                message = server.Load(JsonConvert.DeserializeObject<ViewMessage>(text));

            return false;
        }
Esempio n. 10
0
File: View.cs Progetto: nxkit/nxkit
 /// <summary>
 /// Raised when a client callback is invoked.
 /// </summary>
 /// <param name="eventArgument"></param>
 void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
 {
     var jobj = JObject.Parse(eventArgument);
     if (jobj["Type"].Value<string>() == "Message")
         response = new { Type = "Message", Message = message = server.Load(jobj["Data"].ToObject<ViewMessage>()) };
 }