Пример #1
0
        public override void ApplyTemplateInfo(ActionTemplateInfo ati, BackgroundAction action)
        {
            // default implementation: do nothing
            ServiceDataObject sdo = GetServiceDataObjectByID(ati.ID);

            if (sdo == null)
            {
                Log.ErrorFormat("Unable to find object for ID {0}", ati.ID);
            }
            else
            {
                string expectedStartType = ati["StartTypeString"];
                string actualStartType   = sdo.StartTypeString;
                if (expectedStartType != actualStartType)
                {
                    Log.InfoFormat("=> StartType for {0} needs to change from {1} to {2}",
                                   ati,
                                   actualStartType,
                                   expectedStartType);

                    using (NativeSCManager scm = new NativeSCManager(MachineName))
                    {
                        SC_START_TYPE startType = ServicesLocalisation.ReverseLocalizedStartType(expectedStartType);
                        if (startType != SC_START_TYPE.SERVICE_NO_CHANGE)
                        {
                            sdo.ApplyStartupChanges(scm, startType);
                        }
                    }
                }
                else
                {
                    Log.InfoFormat("=> StartType for {0} identical, no need to change", ati);
                }
            }
        }
Пример #2
0
        public override void ApplyTemplateInfo(ActionTemplateInfo ati, BackgroundAction action)
        {
            // default implementation: do nothing
            ServiceDataObject sdo = GetServiceDataObjectByID(ati.ID);
            if (sdo == null)
            {
                Log.ErrorFormat("Unable to find object for ID {0}", ati.ID);
            }
            else
            {
                string expectedStartType = ati["StartTypeString"];
                string actualStartType = sdo.StartTypeString;
                if (expectedStartType != actualStartType)
                {
                    Log.InfoFormat("=> StartType for {0} needs to change from {1} to {2}",
                        ati,
                        actualStartType,
                        expectedStartType);

                    using (NativeSCManager scm = new NativeSCManager(MachineName))
                    {
                        SC_START_TYPE startType = ServicesLocalisation.ReverseLocalizedStartType(expectedStartType);
                        if( startType != SC_START_TYPE.SERVICE_NO_CHANGE )
                        {
                            sdo.ApplyStartupChanges(scm, startType);
                        }
                    }
                }
                else
                {
                    Log.InfoFormat("=> StartType for {0} identical, no need to change", ati);
                }
            }
        }
Пример #3
0
 public virtual void ApplyTemplateInfo(ActionTemplateInfo ati, BackgroundAction action)
 {
     // default implementation: do nothing
 }
Пример #4
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;

        }