Пример #1
0
        public void CreateAsync()
        {
            SendFunction("", true, e =>
            {
                if (e.Error != null)
                {
                    return;
                }

                var state = Create(e.Result);
                if (state != null)
                {
                    OnStateCreated?.Invoke(state, null);
                }

                return;
            });
        }
Пример #2
0
 private static void _base_OnStateCreated(object sender, EventArgs e)
 {
     OnStateCreated?.Invoke(sender, e);
 }
Пример #3
0
        /// <summary>
        /// Creates a vMix.State object from its xml representation.
        /// </summary>
        /// <param name="textstate">Xml representation of state object.</param>
        /// <returns></returns>
        public State Create(string textstate)
        {
            if (string.IsNullOrWhiteSpace(textstate))
            {
                return(null);
            }
            if (!textstate.StartsWith("<vmix>"))
            {
                _logger.Error("vMix state was not created, got not xml value.");
                return(null);
            }

            IsInitializing = true;
            _logger.Info("Creating vMix state form {0}.", textstate);



            try
            {
                XmlSerializer s = new XmlSerializer(typeof(State));
                using (var ms = new MemoryStream())
                {
                    XmlDocument doc = new XmlDocument();
                    if (!textstate.StartsWith("<?xml"))
                    {
                        textstate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + textstate;
                    }
                    textstate = textstate.
                                Replace(">False<", ">false<").
                                Replace(">True<", ">true<").
                                Replace("\"False\"", "\"false\"").
                                Replace("\"True\"", "\"true\"");
                    doc.LoadXml(textstate);
                    doc.Save(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    var state = (State)s.Deserialize(ms);
                    state._currentStateText = textstate;

                    state._changedinputs.Clear();
                    foreach (var item in state.Inputs)
                    {
                        state._changedinputs.Add(item.Key);
                    }

                    state.Inputs.Insert(0, new Input()
                    {
                        Key = "0", Title = "[Preview]"
                    });
                    state.Inputs.Insert(0, new Input()
                    {
                        Key = "-1", Title = "[Active]"
                    });



                    IsInitializing = false;
                    if (state != null)
                    {
                        _logger.Info("vMix state created.");
                    }
                    else
                    {
                        _logger.Error("vMix state not created.");
                    }

                    foreach (var item in state.Inputs)
                    {
                        item.ControlledState = state;
                    }
                    foreach (var item in state.Overlays)
                    {
                        item.ControlledState = state;
                    }

                    OnStateCreated?.Invoke(state, null);
                    state.Configure(_ip, _port);
                    return(state);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "vMix state was not created.");
                return(null);
            }
        }