// ***************************************************************** // **** Public Methods **** // ***************************************************************** // // //string filePath = string.Format("{0}{1}", this.Info.UserConfigPath, configFileName); // // public static bool TryCreateFromFile(string filePath, LogHub aLog, out List <Strategy> strategyList) { strategyList = new List <Strategy>(); // place to put new strategies try { List <IStringifiable> iStringObjects; using (StringifiableReader reader = new StringifiableReader(filePath)) { iStringObjects = reader.ReadToEnd(); } if (aLog != null) { aLog.NewEntry(LogLevel.Major, "StrategyMaker: Created {0} iStringifiable objects from {1}", iStringObjects.Count, filePath.Substring(filePath.LastIndexOf("\\") + 1)); } foreach (IStringifiable iStrObj in iStringObjects) { if (iStrObj is Strategy) { strategyList.Add((Strategy)iStrObj); } } } catch (Exception e) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("Exception: {0}\r\nContinue? \r\n{1}", e.Message, e.StackTrace); System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(msg.ToString(), "StrategyMaker.TryCreateFromFile", System.Windows.Forms.MessageBoxButtons.OKCancel); if (aLog != null) { aLog.NewEntry(LogLevel.Major, "StrategyMaker: Exception {0}", e.Message); } return(result == System.Windows.Forms.DialogResult.OK); } return(true); }// TryCreateFromFile()
// // //************************************************************ //**** TryCreateFromFile **** //************************************************************ /// <returns>false if faled</returns> public static bool TryCreateFromFile(string filePath, out DataHub dataHub) { dataHub = null; //DatabaseInfo dbInfo = null; try { string fullFilePath = string.Format("{0}{1}", Application.AppServices.GetInstance().Info.UserConfigPath, filePath); List <IStringifiable> iStringObjects; using (StringifiableReader reader = new StringifiableReader(fullFilePath)) { iStringObjects = reader.ReadToEnd(); } foreach (IStringifiable iStrObj in iStringObjects) { if (iStrObj is DataHub) { dataHub = (DataHub)iStrObj; } } //else if (iStrObj is DatabaseInfo) // dbInfo = (DatabaseInfo)iStrObj; } catch (Exception e) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("Exception: {0}\r\nContinue?", e.Message); System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(msg.ToString(), "ProductRequest.TryCreateFromFile", System.Windows.Forms.MessageBoxButtons.OKCancel); return(result == System.Windows.Forms.DialogResult.OK); } //if(dbInfo != null) // dataHub.m_DataBaseInfo = dbInfo; return(true); }
// ***************************************************************** // **** Public Methods **** // ***************************************************************** // //************************************************************ //**** TryCreateFromFile **** //************************************************************ /// <summary> /// Attempt to create a product request from a file using Istringifiable interface. /// </summary> /// <param name="filePath"></param> /// <param name="prodRequestList"></param> /// <returns>false if faled</returns> public static bool TryCreateFromFile(string filePath, out List <ProductRequest> prodRequestList) { prodRequestList = new List <ProductRequest>(); try { string fullFilePath = string.Format("{0}{1}", Application.AppServices.GetInstance().Info.UserConfigPath, filePath); List <IStringifiable> iStringObjects; using (StringifiableReader reader = new StringifiableReader(fullFilePath)) { iStringObjects = reader.ReadToEnd(); } foreach (IStringifiable iStrObj in iStringObjects) { if (iStrObj is ProductRequest) { prodRequestList.Add((ProductRequest)iStrObj); } } } catch (Exception e) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("Exception: {0}\r\nContinue?", e.Message); System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(msg.ToString(), "ProductRequest.TryCreateFromFile", System.Windows.Forms.MessageBoxButtons.OKCancel); return(result == System.Windows.Forms.DialogResult.OK); } return(true); }
// // Constructors // public ReadXMLBlocks() { InitializeComponent(); m_AppInfo = UV.Lib.Application.AppInfo.GetInstance(); // Example of how to use string fileName = string.Format("{0}Test.txt", m_AppInfo.UserPath); m_Reader = new StringifiableReader(fileName); List <IStringifiable> newObject = m_Reader.ReadToEnd(true); m_Reader.Close(); }
} // LoadMostRecentlySavedFillBookLoad() // private List <IStringifiable> ReadNodes(string filePath) { if (!System.IO.File.Exists(filePath)) { return(new List <IStringifiable>()); // return empty list. } // 1. Read the file backwards until we find the last startTag for the FillBook XML. // Search for the last block for the object. List <string> lines = new List <string>(); string objectName = m_FillHub.GetType().FullName; string startTag = string.Format("<{0}", m_FillHub.GetType().FullName); // leave trailing parts off to allow for attributes. using (BackwardReader br = new BackwardReader(filePath)) { bool isContinuing = true; while (!br.SOF && isContinuing) { string aLine = br.Readline(); if (aLine.Contains(startTag)) { m_FillHub.Log.NewEntry(LogLevel.Major, "DropRules.Load: Loading fill hub {0}", aLine); isContinuing = false; // Keep everything after the startTag, dump everything on the line string[] truncatedLineParts = aLine.Split(new string[] { startTag }, StringSplitOptions.RemoveEmptyEntries); string truncatedLine = string.Format("{0}{1}", startTag, truncatedLineParts[truncatedLineParts.Length - 1]); lines.Add(truncatedLine); } else { lines.Add(aLine); } } //wend } //using reader lines.Reverse(); // since I read backwards, reverse the lines now. // 2. Now, create a string stream of the block, create nodes. StringBuilder msg = new StringBuilder(); foreach (string aLine in lines) { msg.Append(aLine); } byte[] byteBuffer = ASCIIEncoding.ASCII.GetBytes(msg.ToString()); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteBuffer); StringifiableReader reader = new StringifiableReader(stream); List <IStringifiable> nodeList = reader.ReadToEnd(true); return(nodeList); } // ReadNodes
}//ProcessServiceStateRequests() // // // ***************************************************************** // **** ProcessCreateStrategyRequest() **** // ***************************************************************** /// <summary> /// Process request to create new Engine. All the operations here /// are performed by the Hub thread. Once the Execution Strategy is /// ready to be launched, it is passed to its own thread, and then /// never again touched by the hub thread. /// </summary> /// <param name="eventArg">contains data</param> private void ProcessCreateStrategyRequest(EngineEventArgs eventArg) { // // Validate data in eventArg // if (eventArg.Status != EngineEventArgs.EventStatus.Request) { // I only respond to a request. return; } if (eventArg.DataObjectList == null || eventArg.DataObjectList.Count < 2) { Log.NewEntry(LogLevel.Warning, "ProcessCreateNewContainer: Failed to extract data."); return; } string xmlString = (string)eventArg.DataObjectList[0]; string strategyHubName = (string)eventArg.DataObjectList[1]; int engineCount = 0; if (!int.TryParse((string)eventArg.DataObjectList[2], out engineCount)) { engineCount = -1; } string containerTypeString = (string)eventArg.DataObjectList[3]; // // Obtain the EngineContainer // Dictionary <int, ThreadContainer> executionContainers = null; if (!m_ExecutionContainers.TryGetValue(strategyHubName, out executionContainers)) { // This is first container for this particular hub. Create a place for it. executionContainers = new Dictionary <int, ThreadContainer>(); if (string.IsNullOrEmpty(DefaultHubName)) { DefaultHubName = strategyHubName; } m_ExecutionContainers.Add(strategyHubName, executionContainers); } ThreadContainer container = null; if (!executionContainers.TryGetValue(eventArg.EngineContainerID, out container)) { Type containerType = (typeof(ThreadContainer).Assembly).GetType(containerTypeString); // convert string to exact type. container = (ThreadContainer)Activator.CreateInstance(containerType); // create instance container.EngineContainerID = eventArg.EngineContainerID; executionContainers.Add(container.EngineContainerID, container); if (engineCount >= 0) { container.TotalEngineCount = engineCount; } container.EngineContainerName = "need ContainerName"; // Locate the Strategy server this request came from IService iService; if (AppServices.GetInstance().TryGetService(strategyHubName, out iService) && iService is IEngineHub) { container.RemoteEngineHub = (IEngineHub)iService; } // TODO: Continue initializing the container } // // Create the Engine. // bool isSuccess = true; byte[] byteArray = Encoding.ASCII.GetBytes(xmlString); using (System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray)) { try { StringifiableReader stringReader = new StringifiableReader(stream); List <IStringifiable> objects = stringReader.ReadToEnd(); foreach (IStringifiable iObject in objects) { if (iObject is Engine) { if (container.TryAddEngine((Engine)iObject)) { //Engine engine = (Engine)iObject; //int engineID = engine.EngineID; // These are created via attributes (so they coincide with values set by StrategyHub). //((Engine)iObject).SetupInitialize(this, container, engineID); } else { isSuccess = false; Log.NewEntry(LogLevel.Warning, "ProcessCreateEngine: Failed to add {0} to container {1}.", iObject, container); } } } } catch (Exception ex) { isSuccess = false; Log.NewEntry(LogLevel.Warning, "ProcessCreateEngine: {0}", ex.Message); } }//using if (isSuccess == false) { return; } // Finalize if (engineCount == container.EngineList.Count && container.IOrderEngine != null) { SetupAndStartContainer(container); // finish initialization, add listener and start } else { } }//ProcessCreateEngine()
} // GetMostRecentDropFile() // // // // private List <IStringifiable> Load2(string filePath) { List <IStringifiable> objectList = null; // 1. Read the file backwards until we find the last startTag for the FillBook XML. // Search for the last block for the object. List <string> lines = new List <string>(); string objectName = m_FillHub.GetType().FullName; string startTag = string.Format("<{0}", m_FillHub.GetType().FullName); // leave trailing parts off to allow for attributes. using (BackwardReader br = new BackwardReader(filePath)) { bool isContinuing = true; while (!br.SOF && isContinuing) { string aLine = br.Readline(); if (aLine.Contains(startTag)) { m_FillHub.Log.NewEntry(LogLevel.Major, "DropRules.Load: Loading fill hub {0}", aLine); isContinuing = false; // Keep everything after the startTag, dump everything on the line string[] truncatedLineParts = aLine.Split(new string[] { startTag }, StringSplitOptions.RemoveEmptyEntries); string truncatedLine = string.Format("{0}{1}", startTag, truncatedLineParts[truncatedLineParts.Length - 1]); lines.Add(truncatedLine); } else { lines.Add(aLine); } } //wend } //using reader lines.Reverse(); // since I read backwards, reverse the lines now. // 2. Now, create a string stream of the block, create nodes. StringBuilder msg = new StringBuilder(); foreach (string aLine in lines) { msg.Append(aLine); } byte[] byteBuffer = ASCIIEncoding.ASCII.GetBytes(msg.ToString()); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteBuffer); StringifiableReader reader = new StringifiableReader(stream); List <IStringifiable> nodeList = reader.ReadToEnd(true); // 3. Now convert these nodes into real objects. objectList = new List <IStringifiable>(); foreach (IStringifiable iNode in nodeList) { Node node = (Node)iNode; if (node.Name.Contains("FillHub")) { // We need the sub elements of the FillHub foreach (IStringifiable subElem in node.SubElements) { IStringifiable obj = Stringifiable.DeStringify((Node)subElem); objectList.Add(obj); } } else { // These are fill events and other things. IStringifiable obj = Stringifiable.DeStringify((Node)iNode); objectList.Add(obj); } } return(objectList); }// Load2()
// ***************************************************************** // **** Constructors **** // ***************************************************************** public ReconcilerForm(string[] cmdLineArgs) { InitializeComponent(); AppInfo m_AppInfo = AppInfo.GetInstance("Breconcile", true); m_AppInfo.RequestShutdownAddHandler(new EventHandler(RequestShutDown)); // register my handler as the shutdown request handler. string filePath = string.Empty; if (cmdLineArgs != null && cmdLineArgs.Length > 0) { filePath = string.Format("{0}{1}", m_AppInfo.UserConfigPath, cmdLineArgs[0].Trim()); } else { filePath = string.Format("{0}ReconcilerConfig.txt", m_AppInfo.UserConfigPath); } // here is temp hard code config file address // filePath = "\\\\fileserver\\Users\\DV_Ambre\\AmbreUsers\\dvbre\\Config\\ReconcilerConfig.txt"; // Create the services defined in the config file. using (StringifiableReader reader = new StringifiableReader(filePath)) { List <IStringifiable> objectList = reader.ReadToEnd(); foreach (IStringifiable obj in objectList) { if (obj is ReconcilerTaskHub) { ReconcilerTaskHub newHub = (ReconcilerTaskHub)obj; m_ReconcilerTaskHubs.Add(newHub); if (Log == null) { Log = newHub.Log; // accept first Log as the form's log. } newHub.TaskCompleted += new EventHandler(Reconciler_RequestCompleted); newHub.Stopping += new EventHandler(Reconciler_Stopping); } } } // Log start up. if (Log != null) { Log.NewEntry(LogLevel.Minor, "ReconcilerForm: Running config file {0}", filePath); if (Log.BeginEntry(LogLevel.Minor, "ReconcilerForm: {0} TaskHubs: ", m_ReconcilerTaskHubs.Count)) { foreach (ReconcilerTaskHub hub in m_ReconcilerTaskHubs) { Log.AppendEntry("<{0}>", hub.GetAttributes()); } } } // Start hubs foreach (ReconcilerTaskHub hub in m_ReconcilerTaskHubs) { hub.Start(); } }