/// <summary> /// Searches for target procedure below a specified material destination. /// </summary> /// <param name="searchTarget">The search target's procedure.</param> /// <param name="parentDestination">The material destination to begin searching from.</param> /// <returns>Details describing the requested procedure</returns> private SearchForTargetDetails SearchForTargetProcedure(ProcessingTarget searchTarget, MaterialDestination parentDestination) { // Is there a destination to search ? if (parentDestination == null || parentDestination.Target == null || !parentDestination.Target.HasProcedure()) { return(null); } // Search each procedure for a match for (Int32 i = 0; i < parentDestination.Target.Procedure.Length; i++) { // If this procedure matches then return it as the jump point if (String.Equals(parentDestination.Target.Procedure[i].Id, searchTarget.ProcedureRef)) { return(new SearchForTargetDetails(parentDestination, i)); } // Otherwise recursively search for the requested procedure List <MaterialDestination> destinations = parentDestination.Target.Procedure[i].GetDestinations(); foreach (MaterialDestination destination in destinations) { SearchForTargetDetails match = SearchForTargetProcedure(searchTarget, destination); if (match != null) { return(match); } } } return(null); }
/// <summary> /// Adds a new processing target /// </summary> /// <param name="target">The target point to add</param> public void Add(ProcessingTarget target) { Targets.Add(target); // If live, set up a subscription if (Live && !LiveData.ContainsKey(target.Symbol)) { var sourceList = new StockDataSet <StockDataSource>(target.Symbol, DateTime.Now, Session.SourceFile); var data = new StockDataSetDerived <StockDataSink, StockDataSource, StockProcessingState>(sourceList, Session.SinkFile, CreateSink, GetProcessingState); var sub = DataAccessor.Subscribe(target.Symbol, LiveInterval); sub.Notify += (DataAccessor.Subscription s) => { LiveData[s.Symbol].Item1.Add(StockDataSource.CreateFromPrice((float)s.Price)); LiveProcessingQueue.Add(target); }; LiveData[target.Symbol] = new Tuple <StockDataSetDerived <StockDataSink, StockDataSource, StockProcessingState>, DataAccessor.Subscription>(data, sub); } }
/// <summary> /// Removes a target from the processor /// </summary> /// <param name="target">The target to remove</param> public void Remove(ProcessingTarget target) { bool lastEntryForSymbol = true; foreach (var t in Targets) { if (t.Symbol.Equals(target.Symbol)) { lastEntryForSymbol = false; break; } } if (lastEntryForSymbol) { // Un-subscribe if this is the last instance of that symbol DataAccessor.Unsubscribe(LiveData[target.Symbol].Item2); LiveData.Remove(target.Symbol); } Targets.Remove(target); }
public ProcessingTarget(ProcessingTarget target) : base(target) { m_defaultProtocol = target.DefaultProtocol; m_defaultProcess = target.DefaultProcess; }
/// <summary> /// Searches for the protocol, process ,etc... that the target jumps to. /// </summary> /// <param name="searchTarget">The search target.</param> /// <returns>Details describing the target to jump to.</returns> private SearchForTargetDetails SearchForTarget(ProcessingTarget searchTarget) { // Are there any protocols, processes etc... to search ? if (searchTarget == null || this.Document == null || this.Document.Protocols == null || this.Document.Protocols.Protocol == null) { return(null); } // Does the seacrh target jump to a protcol ? Protocol searchProtocol = null; if (searchTarget.HasProtocol()) { // If so then find the protocol foreach (Protocol protocol in this.Document.Protocols.Protocol) { if (String.Equals(protocol.Id, searchTarget.ProtocolRef)) { searchProtocol = protocol; break; } } } // If not then use the first protocol in the ADX document else { searchProtocol = searchTarget.DefaultProtocol; if (searchProtocol == null && this.Document.Protocols.Protocol != null) { if (this.Document.Protocols.Protocol.Length > 0) { searchProtocol = this.Document.Protocols.Protocol[0]; } } } // Do we have a protocol to search ? if not then we must stop. if (searchProtocol == null) { return(null); } // Does the search target jump to a process within the current protocol Process searchProcess = null; if (searchTarget.HasProcessName()) { // Search for the specified process foreach (Process process in searchProtocol.Process) { if (String.Equals(process.Id, searchTarget.ProcessRef)) { searchProcess = process; break; } } } // If not then use the first process in the first protocol else { searchProcess = searchTarget.DefaultProcess; if (searchProcess == null) { if (this.Document.Protocols.Protocol.Length > 0 && this.Document.Protocols.Protocol[0].Process != null) { if (this.Document.Protocols.Protocol[0].Process.Length > 0) { searchProcess = this.Document.Protocols.Protocol[0].Process[0]; } } } } // Do we have a process to search ? if not then stop searching. if (searchProcess == null) { return(null); } // Do we start from the top of the current process (i.e. no ProcedureName was specified to jump to). if (!searchTarget.HasProcedureName()) { return(new SearchForTargetDetails(searchProtocol, searchProcess, searchProcess.Destination, 0)); } // Find the specified procedure in the current process and jump to that procedure SearchForTargetDetails match = SearchForTargetProcedure(searchTarget, searchProcess.Destination); if (match != null) { match.protocol = searchProtocol; match.process = searchProcess; } return(match); }
/// <summary> /// Expands all the processing (i.e. ProcessRefs, ProcedureRef, etc...) under this destination into procedures. By converting all processing into procedures, searching and tracing is considerably easier. /// </summary> /// <param name="parentDestination">The parent destination to convert into procedures.</param> /// <param name="startProcedureIndex">The start procedure within the material target on the parent destination from which to begin converting.</param> /// <param name="defaultTarget">The default target describing the current procotol and process.</param> /// <returns>The expanded list of procedures</returns> private List <Procedure> ExpandToProcedures(MaterialDestination parentDestination, Int32 startProcedureIndex, ProcessingTarget defaultTarget) { List <Procedure> procedures = new List <Procedure>(); // Does this destination have a target to expand ? if not then just return an empty procedure list if (parentDestination == null || !parentDestination.HasTarget) { return(procedures); } // Invalid target ? if (!parentDestination.IsValidTarget) { this.OnValidationEvent(new ValidationResult(ErrorCodes.SampleProcessingHistory, ErrorLevel.Error, String.Format(Languages.Strings.valResultInvalidMaterialTarget, parentDestination.Target == null ? "?" : parentDestination.Target.ToString()))); } // Does this destination have a list of procedures as its target ? if so then expand each procedure if (parentDestination.Target.HasProcedure()) { // Add each procedure in the target and expand the procedure's destinations for (Int32 i = startProcedureIndex; i < parentDestination.Target.Procedure.Length; i++) { procedures.Add(parentDestination.Target.Procedure[i]); // Expand each destination into procedures List <MaterialDestination> destinations = parentDestination.Target.Procedure[i].GetDestinations(); foreach (MaterialDestination destination in destinations) { MaterialTarget target = new MaterialTarget(); target.Procedure = this.ExpandToProcedures(destination, 0, defaultTarget).ToArray(); destination.Target = target; } } } // Does the destination have references to a protocol, process or procedure name instead? // if so then set the default target to the current protocol etc... and expand the reference else if (parentDestination.Target.IsSpecified) { ProcessingTarget searchTarget = new ProcessingTarget(defaultTarget); // Is there a protocol reference ? if (parentDestination.Target.HasProtocol()) { searchTarget.ProtocolRef = parentDestination.Target.ProtocolRef; } // Is there a process reference ? if (parentDestination.Target.HasProcessName()) { searchTarget.ProcessRef = parentDestination.Target.ProcessRef; } // Is there a procedure reference ? if (parentDestination.Target.HasProcedureName()) { searchTarget.ProcedureRef = parentDestination.Target.ProcedureRef; } // Is there a material source reference ? if (parentDestination.Target.HasMaterialSourceName()) { searchTarget.MaterialSourceRef = parentDestination.Target.MaterialSourceRef; } // Is the current target's references valid (i.e. is there a protocol or process that matches the specified protocol or process, etc...). SearchForTargetDetails match = this.SearchForTarget(searchTarget); // If the target is valid and points to another position in the ADX document then jump to that place and continue expanding into procedures if (match != null && match.destination != null) { searchTarget.DefaultProcess = match.process; searchTarget.DefaultProtocol = match.protocol; procedures.AddRange(this.ExpandToProcedures(match.destination.Clone(), match.procedureIndex, searchTarget)); } } return(procedures); }
public static void PreCacheSerializersStart(ProcessingTarget targets) { ThreadStart start = null; if (targets != ProcessingTarget.NoTargets) { if (start == null) { start = delegate { var fomsLogPrefix = FomsLogPrefix; FomsLogger.WriteLog( LogType.Local, string.Format("Предварительное кеширование классов сериализации: {0}", targets), fomsLogPrefix, LogErrorType.None); try { if ((targets & ProcessingTarget.XElement) == ProcessingTarget.XElement) { new XmlSerializer(typeof(XElement)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.Ack)) == (ProcessingTarget.NoTargets | ProcessingTarget.Ack)) { new XmlSerializer(typeof(Ack)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.RSP_ZK1)) == (ProcessingTarget.NoTargets | ProcessingTarget.RSP_ZK1)) { new XmlSerializer(typeof(RSP_ZK1)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.RSP_ZK2)) == (ProcessingTarget.NoTargets | ProcessingTarget.RSP_ZK2)) { new XmlSerializer(typeof(RSP_ZK2)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.RSP_ZK4)) == (ProcessingTarget.NoTargets | ProcessingTarget.RSP_ZK4)) { new XmlSerializer(typeof(RSP_ZK4)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.RSP_ZK5)) == (ProcessingTarget.NoTargets | ProcessingTarget.RSP_ZK5)) { new XmlSerializer(typeof(RSP_ZK5)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.ZPI_ZA1)) == (ProcessingTarget.NoTargets | ProcessingTarget.ZPI_ZA1)) { new XmlSerializer(typeof(ZPI_ZA1)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.ZPI_ZA7)) == (ProcessingTarget.NoTargets | ProcessingTarget.ZPI_ZA7)) { new XmlSerializer(typeof(ZPI_ZA7)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.ADT_A01)) == (ProcessingTarget.NoTargets | ProcessingTarget.ADT_A01)) { new XmlSerializer(typeof(ADT_A01)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.ADT_A03)) == (ProcessingTarget.NoTargets | ProcessingTarget.ADT_A03)) { new XmlSerializer(typeof(ADT_A03)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.ADT_A24)) == (ProcessingTarget.NoTargets | ProcessingTarget.ADT_A24)) { new XmlSerializer(typeof(ADT_A24)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.ADT_A37)) == (ProcessingTarget.NoTargets | ProcessingTarget.ADT_A37)) { new XmlSerializer(typeof(ADT_A37)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.QBP_ZP1)) == (ProcessingTarget.NoTargets | ProcessingTarget.QBP_ZP1)) { new XmlSerializer(typeof(QBP_ZP1)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.QBP_ZP2)) == (ProcessingTarget.NoTargets | ProcessingTarget.QBP_ZP2)) { new XmlSerializer(typeof(QBP_ZP2)); } if ((targets & (ProcessingTarget.NoTargets | ProcessingTarget.QBP_ZP4)) == (ProcessingTarget.NoTargets | ProcessingTarget.QBP_ZP4)) { new XmlSerializer(typeof(QBP_ZP4)); } if ((targets & ProcessingTarget.BHS) == ProcessingTarget.BHS) { new XmlSerializer(typeof(BHS)); } if ((targets & ProcessingTarget.BTS) == ProcessingTarget.BTS) { new XmlSerializer(typeof(BTS)); } if ((targets & ProcessingTarget.PersonErp) == ProcessingTarget.PersonErp) { new XmlSerializer(typeof(PersonErp)); } if ((targets & ProcessingTarget.PersonCard) == ProcessingTarget.PersonCard) { new XmlSerializer(typeof(PersonCard)); } var prefix = FomsLogPrefix; FomsLogger.WriteLog( LogType.Local, string.Format("Завершено кеширование классов сериализации: {0}", targets), prefix, LogErrorType.None); } catch (Exception exception) { var str3 = FomsLogPrefix; FomsLogger.WriteError( LogType.Local, string.Format( "Исключение при кешировании классов сериализации: {0}", exception.Message), str3); throw; } finally { lock (preCacheThreads) { preCacheThreads.Remove(Thread.CurrentThread); } } }; } var item = new Thread(start); lock (preCacheThreads) { preCacheThreads.Add(item); } item.Start(); } }