Example #1
0
        /// <summary>
        /// add方法是每个class将自身的datahead merge进cache proxy中的datahead中
        /// </summary>
        /// <param name="serializedObj"></param>
        public void Add(SerializableBase serializedObj)
        {
            if (null == serializedObj)
            {
                CLRLogger.GetInstance().LogDevError("SerializableBase is null.");
            }

            foreach (DicomAttribute dicomAttr in serializedObj._dataHead)
            {
                if (!_dataHead.Contains(dicomAttr.Tag))
                {
                    _dataHead.AddDicomAttribute(dicomAttr);
                    continue;
                }

                for (int i = 0; i < dicomAttr.ValueCount; i++)
                {
                    string value = null;
                    if (dicomAttr.GetString(i, out value))
                    {
                        _dataHead[dicomAttr.Tag.Value].SetString(i, value);
                    }
                }
            }
        }
Example #2
0
        private void HandleRemoteInvoke(CommandContextEx cmdContext)
        {
            CLRLogger.GetInstance().LogDevInfo("Handle remote invoke, sender is " + cmdContext.sSender);
            byte[] request = cmdContext.sSerializeObject;
            _currentRemoteInvoker.Value = cmdContext.sSender;
            BinaryFormatter            formatter  = new BinaryFormatter();
            RemoteMethodInvokeArgument invokeArgs = null;

            using (MemoryStream inStream = new MemoryStream(request))
            {
                invokeArgs = formatter.Deserialize(inStream) as RemoteMethodInvokeArgument;
            }
            if (invokeArgs == null)
            {
                throw new Exception("Invalid remote argument");
            }
            object obj = NativeInvoke(invokeArgs.ObjectName, invokeArgs.Method, invokeArgs.Parameters);

            using (MemoryStream outStream = new MemoryStream())
            {
                formatter.Serialize(outStream, obj);
                byte[] response  = outStream.GetBuffer();
                int    errorCode = cmdContext.Reply(response);
                if (errorCode != 0)
                {
                    throw new CommunicationException(errorCode, "fail to reply to " + cmdContext.sSender);
                }
            }
        }
Example #3
0
        static Logger()
        {
            try
            {
                DebugHelper.Source        = "Filming";
                DebugHelper.ShowInConsole = true;
                DebugHelper.ShowInOutput  = true;

                _sourceName = "MCSF/Filming";
                _logUID     = 001035002;

                _logger = CLRLogger.GetInstance();


                //read configure file to create logger

                _logger.CreateLogger(mcsf_clr_systemenvironment_config.GetApplicationPath("FilmingConfigPath") + "McsfFilmingLog.xml");

                //_fileLogger = new StreamWriter(@"e:\LoadImageTimeStamps.txt", false);
            }
            catch (Exception ex)
            {
                DebugHelper.Trace(TraceLevel.Error, ex.StackTrace);
            }
        }
 public override int HandleCommand(CommandContext context, ISyncResult result)
 {
     try
     {
         SessionRequestCommand sRequestCommand = SessionRequestCommand.ParseFrom(context.sSerializeObject);
         if (!sRequestCommand.HasCommandId)
         {
             CLRLogger.GetInstance().LogDevError("commandID error.");
             result.SetSerializedString("commandID error.");
             return(-1);
         }
         byte[] invokeResult = _dicFunc[sRequestCommand.CommandId].Invoke(sRequestCommand);
         if (null == invokeResult)
         {
             return(-1);
         }
         result.SetSerializedObject(invokeResult);
         return(0);
     }
     catch (Exception ex)
     {
         CLRLogger.GetInstance().LogDevError("HandleCommand error:" + ex.Message);
         return(-1);
     }
 }
Example #5
0
        /// <summary>
        /// send command to sessionmanager to get the dataHead
        /// </summary>
        /// <returns></returns>
        public bool Refresh()
        {
            byte[]         buf     = SessionUtility.RequestCommandProtoBuffer(SessionManagerFuncID.QuerySessionDataID, new ByteString[] { });
            CommandContext context = SessionUtility.CreateCommandContext(CommunicationNode.SystemSessionManager, CommunicationCommandID.XA_SYSTEMSESSION_DATA_CACHE, buf);
            ISyncResult    result  = _systemCommunicationProxy.SyncSendCommand(context);

            CLRLogger.GetInstance().LogDevInfo(string.Format("Commit result:{0},proxyName:{1}", result.GetCallResult().ToString(), _systemCommunicationProxy.GetName()));
            _dataHead = SessionUtility.DeserializeDataHead(result.GetSerializedObject());
            return((0 == result.GetCallResult()) ? true : false);
        }
Example #6
0
 /// <summary>
 /// Init proxy
 /// </summary>
 /// <param name="processCommunicationProxy">proxy object</param>
 /// <returns></returns>
 public bool Initialize(ICommunicationProxy proxy)
 {
     if (null == proxy)
     {
         CLRLogger.GetInstance().LogDevError("proxy is null");
         return(false);
     }
     _systemCommunicationProxy = proxy;
     PreExecute();
     return(true);
 }
Example #7
0
        public void Commit()
        {
            byte[]         serilizedDataHead = SessionUtility.SerializeDataHead(_dataHead);
            byte[]         buf     = SessionUtility.RequestCommandProtoBuffer(SessionManagerFuncID.UpdateProcessStatusID, new ByteString[] { ByteString.CopyFromUtf8(_proxyName), ByteString.CopyFrom(serilizedDataHead) });
            CommandContext context = SessionUtility.CreateCommandContext(CommunicationNode.SystemSessionManager, CommunicationCommandID.XA_SYSTEMSESSION_PROCESS_CACHE, buf);
            ISyncResult    result  = _processCommunicationProxy.SyncSendCommand(context);

            if (result.GetCallResult() != 0)
            {
                CLRLogger.GetInstance().LogDevError(string.Format("ProcessCacheProxy Commit failed, proxyName is {0},GetCallResult is {1}.", _proxyName, result.GetCallResult()));
            }
        }
Example #8
0
 /// <summary>
 /// Init proxy
 /// </summary>
 /// <param name="processCommunicationProxy">proxy object</param>
 /// <returns></returns>
 public bool Initialize(ICommunicationProxy processCommunicationProxy)
 {
     if (null == processCommunicationProxy)
     {
         CLRLogger.GetInstance().LogDevError("ProcessCacheProxy is null.");
         return(false);
     }
     _processCommunicationProxy = processCommunicationProxy;
     _proxyName = _processCommunicationProxy.GetName();
     PreExecute();
     return(true);
 }
Example #9
0
 public bool IsReadyToEnter(object eventArgs)
 {
     foreach (IAction action in _actionsOnExit)
     {
         if (!action.CanExecute(eventArgs))
         {
             CLRLogger.GetInstance().LogSvcError(string.Format("Action {0} report itself cannot be executed", action.GetType().Name));
             return(false);
         }
     }
     return(true);
 }
Example #10
0
        private void LoadTransaction(TransitionDefinition def)
        {
            CLRLogger.GetInstance().LogDevInfo(string.Format("Load Transaction {0}:{1}->{2}", def.ID, def.From, def.To));
            Transition tran = new Transition();

            tran.ID   = def.ID;
            tran.From = GetStateById(def.From);
            if (tran.From == null)
            {
                if (def.From == "*")
                {
                    foreach (State state in States)
                    {
                        TransitionDefinition tranDef = new TransitionDefinition();
                        tranDef.ID      = def.ID;
                        tranDef.From    = state.ID;
                        tranDef.Actions = def.Actions;
                        tranDef.To      = def.To;
                        if (tranDef.To == "*")
                        {
                            tranDef.To = state.ID;
                        }
                        LoadTransaction(tranDef);
                    }
                }
                else
                {
                    throw new StateMachineException(string.Format("Invalid TransactionDefinition {0}:{1}->{2}, no such state from", def.ID, def.From, def.To));
                }
                return;
            }
            tran.From.RegisterTransition(tran);
            if (tran.To == null)
            {
                tran.To = GetStateById(def.To);
            }
            if (tran.To == null)
            {
                throw new StateMachineException(string.Format("Invalid TransactionDefinition {0}:{1}->{2}, no such state to", def.ID, def.From, def.To));
            }
            if (def.Actions == null)
            {
                return;
            }
            foreach (ActionDefinition actionDef in def.Actions)
            {
                CLRLogger.GetInstance().LogDevInfo(string.Format("Load action {0}", actionDef.Class));
                tran.Actions.Add(_actionBuilder.Build(actionDef));
            }
        }
Example #11
0
        /// <summary>
        /// Get datahead form session manager,this datahead is process's status
        /// </summary>
        public bool Refresh()
        {
            byte[]         buf     = SessionUtility.RequestCommandProtoBuffer(SessionManagerFuncID.QueryProcessStatusID, new ByteString[] { ByteString.CopyFromUtf8(_proxyName) });
            CommandContext context = SessionUtility.CreateCommandContext(CommunicationNode.SystemSessionManager, CommunicationCommandID.XA_SYSTEMSESSION_PROCESS_CACHE, buf);
            ISyncResult    result  = _processCommunicationProxy.SyncSendCommand(context);

            if (0 == result.GetCallResult())
            {
                _dataHead = DicomAttributeCollection.Deserialize(result.GetSerializedObject());
                return(true);
            }
            CLRLogger.GetInstance().LogDevError(string.Format("ProcessCacheProxy Refresh failed, proxyName is {0},GetCallResult is {1}.", _proxyName, result.GetCallResult()));
            return(false);
        }
Example #12
0
        private object NativeInvoke(string serviceObjectName, MethodBase method, object[] parameters)
        {
            Object obj = null;

            if (!_serviceObjects.ContainsKey(serviceObjectName))
            {
                obj = _serviceObjects.Values.FirstOrDefault(item => item.GetType().GetMethod(method.Name) != null);
                if (obj == null)
                {
                    throw new Exception(serviceObjectName + " is not registered and no service object has method " + method.Name);
                }
                CLRLogger.GetInstance().LogDevWarning(serviceObjectName + " is not reigstered, use " + obj.GetType().ToString() + " instead");
            }
            obj = _serviceObjects[serviceObjectName];
            return(method.Invoke(obj, parameters));
        }
Example #13
0
 public void Initialize(StateDefinition definition)
 {
     ID       = definition.ID;
     Category = definition.Category;
     if (definition.ActionsOnEntry == null)
     {
         return;
     }
     foreach (ActionDefinition actionDef in definition.ActionsOnEntry)
     {
         CLRLogger.GetInstance().LogDevInfo(string.Format("Load {0}", actionDef.Class));
         try
         {
             IAction action = _actionBuilder.Build(actionDef);
             _actionsOnEntry.Add(action);
         }
         catch (Exception ex)
         {
             CLRLogger.GetInstance().LogDevInfo(string.Format("Failed to load {0}", actionDef.Class));
             CLRLogger.GetInstance().LogDevError(ex.Message);
         }
     }
     if (definition.ActionsOnExit == null)
     {
         return;
     }
     foreach (ActionDefinition actionDef in definition.ActionsOnExit)
     {
         CLRLogger.GetInstance().LogDevInfo(string.Format("Load {0}", actionDef.Class));
         try
         {
             IAction action = _actionBuilder.Build(actionDef);
             _actionsOnExit.Add(action);
         }
         catch (Exception ex)
         {
             CLRLogger.GetInstance().LogDevInfo(string.Format("Failed to load {0}", actionDef.Class));
             CLRLogger.GetInstance().LogDevError(ex.Message);
         }
     }
 }
Example #14
0
        public void Transit(string transitionID, object args)
        {
            CLRLogger.GetInstance().LogDevInfo(string.Format("Begin transition {0}, state = {1}", transitionID, CurrentState.ID));
            if (transitionID == null)
            {
                CLRLogger.GetInstance().LogDevError("null event");
            }
            if (!CurrentState.IsTransitionRegistered(transitionID))
            {
                CLRLogger.GetInstance().LogDevWarning(string.Format("invalid transaction {0} for state {1}", transitionID, CurrentState.ID));
                return;
            }
            int i = ACTION_HEARBEAT_COUNT;

            while (!CurrentState.IsReadyToTransit(transitionID, args) && i > 0)
            {
                if (i == 0)
                {
                    return;
                }
                CLRLogger.GetInstance().LogSvcError("pause to transact");
                Thread.Sleep(ACTION_HEATBEAT_INTERVAL);
                i--;
            }
            IState nextState = CurrentState.Transit(transitionID, args);

            i = ACTION_HEARBEAT_COUNT;
            while (!nextState.IsReadyToEnter(args) && i > 0)
            {
                if (i == 0)
                {
                    return;
                }
                CLRLogger.GetInstance().LogSvcError("pause to enter " + nextState.ID);
                Thread.Sleep(ACTION_HEATBEAT_INTERVAL);
                i--;
            }
            CurrentState = nextState;
            CurrentState.Enter(args);
            CLRLogger.GetInstance().LogDevInfo(string.Format("End transition {0}, state = {1}", transitionID, CurrentState.ID));
        }
Example #15
0
 /// <summary>
 /// Initialize by StateMachineDefinition instance.
 /// </summary>
 /// <param name="def">StateMachineDefinition instance</param>
 /// <param name="logger">the logger used to</param>
 /// <param name="actionInitializer"></param>
 public void Initialize(StateMachineDefinition def, Func <IAction, IAction> actionInitializer)
 {
     _actionBuilder = new ActionBuilder(def.ActionPackage, actionInitializer);
     foreach (StateDefinition stateDef in def.States)
     {
         CLRLogger.GetInstance().LogDevInfo(string.Format("Load State {0}", stateDef.ID));
         State state = new State(_actionBuilder);
         state.Initialize(stateDef);
         if (States.Contains(state))
         {
             throw new StateMachineException(string.Format("try to add an existed state {0}", state.ID));
         }
         States.Add(state);
         if (state.Category == StateCategory.INITIAL)
         {
             CurrentState = state;
         }
     }
     foreach (TransitionDefinition tranDef in def.Transitions)
     {
         LoadTransaction(tranDef);
     }
 }
Example #16
0
        public bool IsReadyToTransit(string transitionID, object eventArgs)
        {
            ITransition transaction = FindTransition(transitionID);

            if (transaction == null)
            {
                CLRLogger.GetInstance().LogDevWarning(string.Format("Unknown event {0}", transitionID));
                return(false);
            }
            List <IAction> actions = new List <IAction>();

            actions.AddRange(_actionsOnExit);
            actions.AddRange(transaction.Actions);
            foreach (IAction action in actions)
            {
                if (!action.CanExecute(eventArgs))
                {
                    CLRLogger.GetInstance().LogSvcError(string.Format("Action {0} report itself cannot be executed", action.GetType().Name));
                    return(false);
                }
            }
            return(true);
        }
 /// <summary>
 /// handle command
 /// </summary>
 /// <param name="context">CommandContext</param>
 /// <param name="result">ISyncResult</param>
 /// <returns></returns>
 public override int HandleCommand(CommandContext context, ISyncResult result)
 {
     try
     {
         SessionRequestCommand sCommand = SessionRequestCommand.ParseFrom(context.sSerializeObject);
         if (!sCommand.HasCommandId || sCommand.ParametersCount < 1)
         {
             result.SetSerializedObject(new byte[] {});
             return(-1);
         }
         ByteString invokeResult = _funDic[sCommand.CommandId].Invoke(sCommand);
         if (null == invokeResult)
         {
             return(-1);
         }
         result.SetSerializedObject(invokeResult.ToByteArray());
         return(0);
     }
     catch (Exception ex)
     {
         CLRLogger.GetInstance().LogDevError("HandleCommand error:" + ex.Message);
         return(-1);
     }
 }
Example #18
0
 public bool LogSvcWarning(string description)
 {
     return(CLRLogger.GetInstance().LogSvcWarning(LogSource, LogUID, description));
 }
Example #19
0
 public bool LogDevError(string description)
 {
     return(CLRLogger.GetInstance().LogDevError(LogSource, LogUID, description));
 }
Example #20
0
 public void Log(string message, Category category, Priority priority)
 {
     CLRLogger.GetInstance().LogDevInfo(message);
 }
Example #21
0
 public bool LogTraceError(string description)
 {
     return(CLRLogger.GetInstance().LogTraceError(LogSource, description));
 }
Example #22
0
 public bool LogException(Exception ex)
 {
     return(CLRLogger.GetInstance().LogDevError(ex.Message + " " + ex.StackTrace.Replace("\r\n", "|").Replace("\n", "|")));
 }
Example #23
0
        private static int ChannelID       = 16;    //待systemmanager定义

        private void HandleAppReadyEvent(string sender, string content)
        {
            bool result = _appManager.Invoke("ready", new object());

            CLRLogger.GetInstance().LogDevInfo(string.Format("All apps are ready,Sender is {0}, Content = {1}, invoke result:{2},curretn procedure:{3}", sender, content, result, _appManager.CurrentProcedure));
        }
Example #24
0
 /// <summary>
 /// execute statemachine's Transit function, this function is registered for RMI
 /// </summary>
 /// <param name="transitionID">transition id</param>
 /// <param name="context">app's context</param>
 /// <returns>true:success
 ///          false:fail
 /// </returns>
 public bool Invoke(string transitionID, object context)
 {
     CLRLogger.GetInstance().LogDevInfo(string.Format("AppManager begin Invoke,transitionID:{0}", transitionID));
     _stateMachine.Transit(transitionID, context);
     return(true);
 }
Example #25
0
 public Logger()
 {
     this.clrLogger = CLRLogger.GetInstance();
 }