Пример #1
0
 public virtual void ApplyTemplateInfo(ActionTemplateInfo ati, BackgroundAction action)
 {
     // default implementation: do nothing
 }
Пример #2
0
        public bool LoadFromXml(string filename)
        {
            List <ActionTemplateInfo> result = new List <ActionTemplateInfo>();

            try
            {
                ActionTemplateInfo recording    = null;
                string             lastKnownKey = null;
                using (XmlReader reader = XmlReader.Create(filename))
                {
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            if (reader.Name == ControllerName)
                            {
                                // ok expected
                            }
                            else if (reader.Name == ItemName)
                            {
                                recording = new ActionTemplateInfo(reader.GetAttribute("id"));
                                result.Add(recording);
                            }
                            else if (recording != null)
                            {
                                lastKnownKey = reader.Name;
                            }
                            else
                            {
                                Log.WarnFormat("Warning: didn't expect element type {0}", reader.Name);
                            }
                            break;

                        case XmlNodeType.Text:
                            if (lastKnownKey != null)
                            {
                                if (recording != null)
                                {
                                    recording[lastKnownKey] = reader.Value;
                                }
                                else
                                {
                                    Log.WarnFormat("Warning: found key '{0}', but recording is null", lastKnownKey);
                                }
                            }
                            else
                            {
                                Log.WarnFormat("Warning: didn't expect text '{0}'", reader.Value);
                            }
                            break;

                        case XmlNodeType.EndElement:
                            if ((lastKnownKey != null) && (reader.Name == lastKnownKey))
                            {
                                lastKnownKey = null;
                            }
                            else if ((recording != null) && (reader.Name == ItemName))
                            {
                                recording = null;
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(string.Format("Exception caught loading '{0}'", filename), e);
                result = null;
            }

            if (result == null)
            {
                return(false);
            }

            new LongRunningFunctionWindow(new ApplyTemplate(this, result), Resources.IDS_LOADING_TEMPLATES).ShowDialog();
            return(true);
        }