public CSDocument OpenDocument(string label) { CSDocument result = new CSDocument(); //result.Load(label); try { Document apiDoc = CodeSoftApi.Documents.Open(label, true); result.Load(apiDoc, label); apiDoc.Close(false); apiDoc.Dispose(); } catch (Exception err) { string sessionId = string.Empty; if (SessionManager.GetSession() != null) { sessionId = SessionManager.GetSession().ID; } APIEvent(this, new CSNetAppEventArgs() { DocFail = true, SessionId = sessionId }); _NetApp = null; log4net.LogManager.GetLogger("ERROR").Error(new Exception("Failed to open Document for label " + label + " : " + err.Message)); /*Can one really error handle a COM++ ?*/ } return(result); }
public void Dispose() { if (_CurrentDocument != null) { try { //_CurrentDocument.Close(false); _CurrentDocument = null; //log4net.LogManager.GetLogger("DEBUG").Error(new Exception("Document Dispose. Session ID:" + ID)); } catch (Exception err) { log4net.LogManager.GetLogger("DEBUG").Error(err); } } if (_CurrentLabel != null) { _CurrentLabel.CSVariables.Clear(); _CurrentLabel = null; } }
/// <summary> /// Sets an immutable reference to the current CSLabel /// </summary> /// <param name="label"></param> public void SetLabel(CSLabel label) { if (label == null) { Dispose(); } else { //prevent mutation CSLabel obj = CSLabelManager.GetLabel(label.Name, label.Path); obj.AddVariables(label.CSVariables); this._CurrentLabel = obj; //if (this._CurrentDocument != null) //this._CurrentDocument.Close(false); CSDocument Doc = SessionManager.Documents.Where(p => p.LabelPath == label.Path).FirstOrDefault(); this._CurrentDocument = Doc; if (Doc == null) { Doc = CSNetApp.Instance.OpenDocument(obj.Path); this._CurrentDocument = Doc; SessionManager.Documents.Add(Doc); } } }
public void CloseDocument() { //_CurrentDocument.Close(false); this._CurrentDocument = null; }