示例#1
0
 // 检测 dp2capo.exe 是否在运行状态
 static bool IsDp2CapoRunning()
 {
     try
     {
         IpcInfo ipc = BeginIpc();
         try
         {
             ServiceControlResult result = null;
             InstanceInfo         info   = null;
             // 获得一个实例的信息
             result = ipc.Server.GetInstanceInfo(".",
                                                 out info);
             if (result.Value == -1)
             {
                 return(false);
             }
             if (info != null)
             {
                 return(info.State == "running");
             }
             else
             {
                 return(true);
             }
         }
         finally
         {
             EndIpc(ipc);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#2
0
        internal override void InternalSerialize(PipWriter writer)
        {
            var hasProvenance = Provenance != null;

            writer.Write(hasProvenance);
            IpcInfo.Serialize(writer);
            writer.Write(MessageBody);
            writer.Write(OutputFile);
            writer.Write(ServicePipDependencies, (w, v) => ((PipWriter)w).Write(v));
            writer.Write(FileDependencies, (w, v) => w.Write(v));
            writer.Write(DirectoryDependencies, (w, v) => w.Write(v));
            writer.Write(LazilyMaterializedDependencies, (w, v) => w.Write(v));
            writer.Write(Tags, (w, v) => w.Write(v));
            writer.Write(IsServiceFinalization);
            writer.Write(MustRunOnMaster);
            if (hasProvenance)
            {
                writer.Write(Provenance);
            }
        }
示例#3
0
        static IpcInfo BeginIpc()
        {
            IpcInfo info = new IpcInfo();

            string strUrl = "ipc://dp2capo_ServiceControlChannel/dp2library_ServiceControlServer";

            info.Channel = new IpcClientChannel();

            ChannelServices.RegisterChannel(info.Channel, false);

            info.Server = (IServiceControl)Activator.GetObject(typeof(IServiceControl),
                                                               strUrl);
            if (info.Server == null)
            {
                string strError = "无法连接到 remoting 服务器 " + strUrl;
                throw new Exception(strError);
            }

            return(info);
        }
示例#4
0
        // parameters:
        //      strCommand  start/stop/getState
        // return:
        //      -1  出错
        //      0/1 strCommand 为 "getState" 时分别表示实例 不在运行/在运行 状态
        public static int dp2capo_serviceControl(
            string strCommand,
            string strInstanceName,
            out string strError)
        {
            strError = "";

            try
            {
                IpcInfo ipc = BeginIpc();
                try
                {
                    ServiceControlResult result = null;
                    if (strCommand == "start")
                    {
                        result = ipc.Server.StartInstance(strInstanceName);
                    }
                    else if (strCommand == "stop")
                    {
                        result = ipc.Server.StopInstance(strInstanceName);
                    }
                    else if (strCommand == "getState")
                    {
                        InstanceInfo info = null;
                        // 获得一个实例的信息
                        result = ipc.Server.GetInstanceInfo(strInstanceName,
                                                            out info);
                        if (result.Value == -1)
                        {
                            strError = result.ErrorInfo;
                            return(-1);
                        }
                        else
                        {
                            strError = info.State;
                        }
                        return(result.Value);
                    }
                    else
                    {
                        strError = "未知的命令 '" + strCommand + "'";
                        return(-1);
                    }
                    if (result.Value == -1)
                    {
                        strError = result.ErrorInfo;
                        return(-1);
                    }
                    strError = result.ErrorInfo;
                    return(0);
                }
                finally
                {
                    EndIpc(ipc);
                }
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                return(-1);
            }
        }
示例#5
0
 static void EndIpc(IpcInfo info)
 {
     ChannelServices.UnregisterChannel(info.Channel);
 }