示例#1
0
 void IServiceConnection.ReceiveState(ServiceStateInfo stateInfo)
 {
     if (StateChangedCallback != null)
     {
         StateChangedCallback(stateInfo);
     }
 }
        internal void SaveServiceInstance(
            ServiceExecutionHost host,
            Guid instanceID,
            Guid parentInstanceID,
            ServiceConfiguration config,
            ServiceStateInfo stateInfo,
            SchedulingInfo schedulingInfo
            )
        {
            // The first time we save write the configuration to XML. Otherwise ignore.
            string serializedConfig = null;

            if (stateInfo.State == ServiceState.Initializing)
            {
                var stringWriter = new StringWriter();
                using (var writer = new XmlTextWriter(stringWriter))
                    new NetDataContractSerializer().WriteObject(writer, config);
                serializedConfig = stringWriter.ToString();
            }

            var env = this.EnvironmentConfiguration;

            using (var connection = new SqlConnection(env.ConnectionString))
            {
                var command = new SqlCommand(env.SP_InstanceSave, connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@instanceID", instanceID.ToString("N"));
                command.Parameters.AddWithValue("@parentInstanceID", SqlUtility.SqlValue(parentInstanceID, Guid.Empty, () => parentInstanceID.ToString("N")));
                command.Parameters.AddWithValue("@profileID", SqlUtility.SqlValue(config.Profile, () => config.Profile.ProfileID.ToString("N")));
                command.Parameters.AddWithValue("@serviceName", config.ServiceName);
                command.Parameters.AddWithValue("@hostName", host.HostName);
                command.Parameters.AddWithValue("@hostGuid", host.HostGuid.ToString("N"));
                command.Parameters.AddWithValue("@progress", stateInfo.Progress);
                command.Parameters.AddWithValue("@state", stateInfo.State);
                command.Parameters.AddWithValue("@outcome", stateInfo.Outcome);
                command.Parameters.AddWithValue("@timeInitialized", SqlUtility.SqlValue(stateInfo.TimeInitialized, DateTime.MinValue));
                command.Parameters.AddWithValue("@timeStarted", SqlUtility.SqlValue(stateInfo.TimeStarted, DateTime.MinValue));
                command.Parameters.AddWithValue("@timeEnded", SqlUtility.SqlValue(stateInfo.TimeEnded, DateTime.MinValue));
                command.Parameters.AddWithValue("@timeLastPaused", SqlUtility.SqlValue(stateInfo.TimeLastPaused, DateTime.MinValue));
                command.Parameters.AddWithValue("@timeLastResumed", SqlUtility.SqlValue(stateInfo.TimeLastResumed, DateTime.MinValue));
                command.Parameters.AddWithValue("@resumeCount", stateInfo.ResumeCount);
                command.Parameters.AddWithValue("@configuration", SqlUtility.SqlValue(serializedConfig));
                command.Parameters.AddWithValue("@Scheduling_Status", SqlUtility.SqlValue(schedulingInfo, () => schedulingInfo.SchedulingStatus));
                command.Parameters.AddWithValue("@Scheduling_Scope", SqlUtility.SqlValue(schedulingInfo, () => schedulingInfo.SchedulingScope));
                command.Parameters.AddWithValue("@Scheduling_MaxDeviationBefore", SqlUtility.SqlValue(schedulingInfo, () => schedulingInfo.MaxDeviationBefore));
                command.Parameters.AddWithValue("@Scheduling_MaxDeviationAfter", SqlUtility.SqlValue(schedulingInfo, () => schedulingInfo.MaxDeviationAfter));
                command.Parameters.AddWithValue("@Scheduling_RequestedTime", SqlUtility.SqlValue(schedulingInfo, () => SqlUtility.SqlValue(schedulingInfo.RequestedTime, DateTime.MinValue)));
                command.Parameters.AddWithValue("@Scheduling_ExpectedStartTime", SqlUtility.SqlValue(schedulingInfo, () => SqlUtility.SqlValue(schedulingInfo.ExpectedStartTime, DateTime.MinValue)));
                command.Parameters.AddWithValue("@Scheduling_ExpectedEndTime", SqlUtility.SqlValue(schedulingInfo, () => SqlUtility.SqlValue(schedulingInfo.ExpectedEndTime, DateTime.MinValue)));

                connection.Open();
                command.ExecuteNonQuery();
            }
        }
示例#3
0
        private void OnStateChanged(ServiceStateInfo info)
        {
            StateInfo = info;
            if (StateChanged != null)
            {
                StateChanged(this, EventArgs.Empty);
            }

            if (_autostart && info.State == ServiceState.Ready)
            {
                this.Start();
            }
        }
        private void OnStateChanged(ServiceStateInfo info)
        {
            StateInfo = info;
            if (StateChanged != null)
            {
                StateChanged(this, EventArgs.Empty);
            }

            if (_autostart && info.State == ServiceState.Ready)
            {
                this.Start();
            }

            if (info.State == ServiceState.Ended && this.Connection != null)
            {
                this.Connection.Dispose();
            }
        }
        private ServiceInstance(SerializationInfo info, StreamingContext context)
        {
            this.InstanceID    = (Guid)info.GetValue("InstanceID", typeof(Guid));
            this.Configuration = (ServiceConfiguration)info.GetValue("Configuration", typeof(ServiceConfiguration));
            //this.ParentInstance = (ServiceInstance)info.GetValue("ParentInstance", typeof(ServiceInstance));
            this.StateInfo      = (ServiceStateInfo)info.GetValue("StateInfo", typeof(ServiceStateInfo));
            this.SchedulingInfo = (SchedulingInfo)info.GetValue("SchedulingInfo", typeof(SchedulingInfo));
            this.Environment    = context.Context as ServiceEnvironment;

            object pid = info.GetValue("ParentInstanceID", typeof(object));

            if (pid != null)
            {
                this.ParentInstance = this.Environment.GetServiceInstance((Guid)pid);
            }

            // Was locked before serialization? Lock 'em up and throw away the key!
            //if (info.GetBoolean("IsLocked"))
            //    ((ILockable)this).Lock();
        }