This commit is contained in:
Kathy Ruffing 2009-01-27 15:36:38 +00:00
parent 20783cc178
commit 4dbbcf0478
7 changed files with 872 additions and 319 deletions

View File

@ -131,7 +131,8 @@ namespace VEPROMS.CSLA.Library
{
_DocVersionConfig = null;
}
#endregion
#region MOVE TO DOCVERSION CONFIG
private string GetProfile(string grp, string nam)
{
return GetProfile(grp, nam, false);

View File

@ -271,7 +271,65 @@ namespace VEPROMS.CSLA.Library
tmp.FolderConfigRefresh();
}
}
public static FolderInfo GetTop()
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
FolderInfo tmp = DataPortal.Fetch<FolderInfo>(new TopCriteria());
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up FolderInfo
tmp = null;
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on FolderInfo.GetTop", ex);
}
}
private void DataPortal_Fetch(TopCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
ApplicationContext.LocalContext["cn"] = cn;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "getTopFolder";
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
if (!dr.Read())
{
_ErrorMessage = "No Record Found";
return;
}
ReadData(dr);
}
}
// removing of item only needed for local data portal
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
ApplicationContext.LocalContext.Remove("cn");
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("FolderInfo.DataPortal_Fetch", ex);
}
}
#endregion
[Serializable()]
protected class TopCriteria
{
public TopCriteria() { ;}
}
}
}

View File

@ -9,6 +9,7 @@ using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Drawing;
using System.Text.RegularExpressions;
namespace VEPROMS.CSLA.Library
{
@ -800,6 +801,88 @@ namespace VEPROMS.CSLA.Library
{
return (str == null ? def : str);
}
internal string _SearchDVPath;
public string SearchDVPath
{
get { return _SearchDVPath; }
}
internal string _SearchPath;
public string SearchPath
{
get { return _SearchPath; }
}
internal int _SearchAnnotationID;
public int SearchAnnotationID
{
get { return _SearchAnnotationID; }
}
internal string _SearchAnnotationText;
public string SearchAnnotationText
{
get { return _SearchAnnotationText; }
}
internal string _SearchAnnotationType;
public string SearchAnnotationType
{
get { return _SearchAnnotationType; }
}
public string DisplayText
{
get { return ConvertToDisplayText(MyContent.Text); }
}
private string ConvertToDisplayText(string txt)
{
string retval = txt;
retval = StripRtfFormatting(retval);
retval = StripLinks(retval);
retval = ReplaceSpecialCharacters(retval);
return retval;
}
private static string StripRtfFormatting(string rtf)
{
string retval = rtf;
retval = Regex.Replace(retval, @"\\b0 ?", "");
retval = Regex.Replace(retval, @"\\b ?", "");
retval = Regex.Replace(retval, @"\\ul0 ?", "");
retval = Regex.Replace(retval, @"\\ul ?", "");
retval = Regex.Replace(retval, @"\\i0 ?", "");
retval = Regex.Replace(retval, @"\\i ?", "");
retval = Regex.Replace(retval, @"\\super ?", "");
retval = Regex.Replace(retval, @"\\sub ?", "");
retval = Regex.Replace(retval, @"\\nosupersub ?", "");
return retval;
}
private static string StripLinks(string rtf)
{
string retval = rtf;
retval = Regex.Replace(retval, @"\\v.*?\\v0", "");
retval = retval.Replace("\u252C", "");// Unicode 9516 Transition
retval = retval.Replace("\u2566", "");// Unicode 9574 Transition
retval = retval.Replace("\u0015", "");// Unicode 21 RO
return retval;
}
private static string ReplaceSpecialCharacter(Match m)
{
StringBuilder sb = new StringBuilder();
int i = int.Parse(m.ToString().Substring(2,m.ToString().Length-3));
sb.Append((char)i);
return sb.ToString();
}
private static string ReplaceSpecialHexCharacter(Match m)
{
StringBuilder sb = new StringBuilder();
int i = int.Parse(m.ToString().Substring(2), System.Globalization.NumberStyles.HexNumber);
sb.Append((char)i);
return sb.ToString();
}
private static string ReplaceSpecialCharacters(string rtf)
{
string retval = rtf;
retval = retval.Replace("`", "\u00BA");// Degree
retval = Regex.Replace(retval, @"\\u[0-9]+[?]", new MatchEvaluator(ReplaceSpecialCharacter));
retval = Regex.Replace(retval, @"\\'[0-9A-Fa-f][0-9A-Fa-f]", new MatchEvaluator(ReplaceSpecialHexCharacter));
return retval;
}
public string Path
{
get
@ -1140,7 +1223,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ItemInfo.Constructor", ex);
}
}
private void AddContent(SafeDataReader dr)
internal void AddContent(SafeDataReader dr)
{
_MyContent = new ContentInfo(dr, true);
}
@ -1252,6 +1335,340 @@ namespace VEPROMS.CSLA.Library
this.Add(itemInfo);
IsReadOnly = true;
}
#region Text Search
public static ItemInfoList GetListFromTextSearch(string docVersionList, string stepTypeList, string searchString, bool caseSensitive, ItemSearchIncludeLinks includeLinks, bool includeRtfFormatting, bool includeSpecialCharacters)
{
try
{
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListSearchCriteria(docVersionList, stepTypeList, searchString, caseSensitive, includeLinks, includeRtfFormatting, includeSpecialCharacters));
ItemInfo.AddList(tmp);
tmp.AddEvents();
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
}
}
[Serializable()]
private class ItemListSearchCriteria
{
private string _DocVersionList;
public string DocVersionList
{
get { return _DocVersionList; }
set { _DocVersionList = value; }
}
private string _StepTypeList;
public string StepTypeList
{
get { return _StepTypeList; }
set { _StepTypeList = value; }
}
private string _SearchString;
public string SearchString
{
get { return _SearchString; }
set { _SearchString = value; }
}
private bool _CaseSensitive;
public bool CaseSensitive
{
get { return _CaseSensitive; }
set { _CaseSensitive = value; }
}
private ItemSearchIncludeLinks _IncludeLinks;
public ItemSearchIncludeLinks IncludeLinks
{
get { return _IncludeLinks; }
set { _IncludeLinks = value; }
}
private bool _IncludeRtfFormatting;
public bool IncludeRtfFormatting
{
get { return _IncludeRtfFormatting; }
set { _IncludeRtfFormatting = value; }
}
private bool _IncludeSpecialCharacters;
public bool IncludeSpecialCharacters
{
get { return _IncludeSpecialCharacters; }
set { _IncludeSpecialCharacters = value; }
}
public ItemListSearchCriteria(string docVersionList, string stepTypeList, string searchString,
bool caseSensitive, ItemSearchIncludeLinks includeLinks, bool includeRtfFormatting, bool includeSpecialCharacters)
{
_DocVersionList = docVersionList;
_StepTypeList = stepTypeList;
_SearchString = searchString;
_CaseSensitive = caseSensitive;
_IncludeLinks = includeLinks;
_IncludeRtfFormatting = includeRtfFormatting;
_IncludeSpecialCharacters = includeSpecialCharacters;
}
}
private void DataPortal_Fetch(ItemListSearchCriteria criteria)
{
this.RaiseListChangedEvents = false;
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "vesp_SearchItemAndChildren";
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
cm.Parameters.AddWithValue("@SearchString", criteria.SearchString);
cm.Parameters.AddWithValue("@CaseSensitive", criteria.CaseSensitive ? 1 : 0);
cm.Parameters.AddWithValue("@IncludeLinks", (int) criteria.IncludeLinks);
cm.Parameters.AddWithValue("@IncludeRtfFormatting", criteria.IncludeRtfFormatting ? 1 : 0);
cm.Parameters.AddWithValue("@IncludeSpecialCharacters", criteria.IncludeSpecialCharacters ? 1 : 0);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
ItemInfo itemInfo = null;
int itemType = dr.GetInt32("Type") / 10000;
switch (itemType)
{
case 0:
itemInfo = new ProcedureInfo(dr);
break;
case 1:
itemInfo = new SectionInfo(dr);
break;
default:
itemInfo = new StepInfo(dr);
break;
}
itemInfo.AddContent(dr);
itemInfo._SearchDVPath = dr.GetString("DVPath");
itemInfo._SearchPath = dr.GetString("Path");
IsReadOnly = false;
this.Add(itemInfo);
IsReadOnly = true;
}
}
}
}
}
catch (Exception ex)
{
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
}
#endregion
#region RO Search
public static ItemInfoList GetListFromROSearch(string docVersionList, string stepTypeList, string roSearchString)
{
try
{
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListROSearchCriteria(docVersionList, stepTypeList, roSearchString));
ItemInfo.AddList(tmp);
tmp.AddEvents();
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
}
}
[Serializable()]
private class ItemListROSearchCriteria
{
private string _DocVersionList;
public string DocVersionList
{
get { return _DocVersionList; }
set { _DocVersionList = value; }
}
private string _StepTypeList;
public string StepTypeList
{
get { return _StepTypeList; }
set { _StepTypeList = value; }
}
private string _ROSearchString;
public string ROSearchString
{
get { return _ROSearchString; }
set { _ROSearchString = value; }
}
public ItemListROSearchCriteria(string docVersionList, string stepTypeList, string roSearchString)
{
_DocVersionList = docVersionList;
_StepTypeList = stepTypeList;
_ROSearchString = roSearchString;
}
}
private void DataPortal_Fetch(ItemListROSearchCriteria criteria)
{
this.RaiseListChangedEvents = false;
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "vesp_SearchROItemAndChildren";
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
cm.Parameters.AddWithValue("@ROSearchString", criteria.ROSearchString);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
ItemInfo itemInfo = null;
int itemType = dr.GetInt32("Type") / 10000;
switch (itemType)
{
case 0:
itemInfo = new ProcedureInfo(dr);
break;
case 1:
itemInfo = new SectionInfo(dr);
break;
default:
itemInfo = new StepInfo(dr);
break;
}
itemInfo.AddContent(dr);
itemInfo._SearchDVPath = dr.GetString("DVPath");
itemInfo._SearchPath = dr.GetString("Path");
IsReadOnly = false;
this.Add(itemInfo);
IsReadOnly = true;
}
}
}
}
}
catch (Exception ex)
{
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
}
#endregion
#region Annotation Search
public static ItemInfoList GetListFromAnnotationSearch(string docVersionList, string stepTypeList, string annotationTypeList, string searchString, bool caseSensitive)
{
try
{
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListAnnotationSearchCriteria(docVersionList, stepTypeList, annotationTypeList, searchString, caseSensitive));
ItemInfo.AddList(tmp);
tmp.AddEvents();
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
}
}
[Serializable()]
private class ItemListAnnotationSearchCriteria
{
private string _DocVersionList;
public string DocVersionList
{
get { return _DocVersionList; }
set { _DocVersionList = value; }
}
private string _StepTypeList;
public string StepTypeList
{
get { return _StepTypeList; }
set { _StepTypeList = value; }
}
private string _AnnotationTypeList;
public string AnnotationTypeList
{
get { return _AnnotationTypeList; }
set { _AnnotationTypeList = value; }
}
private string _SearchString;
public string SearchString
{
get { return _SearchString; }
set { _SearchString = value; }
}
private bool _CaseSensitive;
public bool CaseSensitive
{
get { return _CaseSensitive; }
set { _CaseSensitive = value; }
}
public ItemListAnnotationSearchCriteria(string docVersionList, string stepTypeList, string annotationTypeList, string searchString, bool caseSensitive)
{
_DocVersionList = docVersionList;
_StepTypeList = stepTypeList;
_AnnotationTypeList = annotationTypeList;
_SearchString = searchString;
_CaseSensitive = caseSensitive;
}
}
private void DataPortal_Fetch(ItemListAnnotationSearchCriteria criteria)
{
this.RaiseListChangedEvents = false;
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "vesp_SearchAnnotationItemAndChildren";
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
cm.Parameters.AddWithValue("@AnnotationTypeList", criteria.StepTypeList);
cm.Parameters.AddWithValue("@SearchString", criteria.SearchString);
cm.Parameters.AddWithValue("@CaseSensitive", criteria.CaseSensitive ? 1 : 0);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
ItemInfo itemInfo = null;
int itemType = dr.GetInt32("Type") / 10000;
switch (itemType)
{
case 0:
itemInfo = new ProcedureInfo(dr);
break;
case 1:
itemInfo = new SectionInfo(dr);
break;
default:
itemInfo = new StepInfo(dr);
break;
}
itemInfo.AddContent(dr);
itemInfo._SearchDVPath = dr.GetString("DVPath");
itemInfo._SearchPath = dr.GetString("Path");
itemInfo._SearchAnnotationID = dr.GetInt32("SearchAnnotationID");
itemInfo._SearchAnnotationText = dr.GetString("SearchText");
itemInfo._SearchAnnotationType = dr.GetString("AnnotationType");
IsReadOnly = false;
this.Add(itemInfo);
IsReadOnly = true;
}
}
}
}
}
catch (Exception ex)
{
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
}
#endregion
}
#endregion
#region ProcedureInfo
@ -1596,4 +2013,10 @@ namespace VEPROMS.CSLA.Library
//#endregion
}
#endregion
public enum ItemSearchIncludeLinks
{
Nothing = 0,
Value = 1,
Everything =2
}
}

View File

@ -0,0 +1,63 @@
// ========================================================================
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
// ------------------------------------------------------------------------
// $Workfile: $ $Revision: $
// $Author: $ $Date: $
//
// $History: $
// ========================================================================
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.XPath;
namespace VEPROMS.CSLA.Library
{
public partial class RODbInfo
{
#region RODb Config
[NonSerialized]
private RODbConfig _RODbConfig;
public RODbConfig RODbConfig
{ get { return (_RODbConfig != null ? _RODbConfig : _RODbConfig = new RODbConfig(this)); } }
private void RODbConfigRefresh()
{
_RODbConfig = null;
}
#endregion
}
public partial class RODb
{
#region Log4Net
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region RODb Config
[NonSerialized]
private RODbConfig _RODbConfig;
public RODbConfig RODbConfig
{
get
{
if (_RODbConfig == null)
{
_RODbConfig = new RODbConfig(this);
_RODbConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_RODbConfig_PropertyChanged);
}
return _RODbConfig;
}
}
private void _RODbConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Config = _RODbConfig.ToString();
}
#endregion
}
}

View File

@ -16,347 +16,270 @@ using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.XPath;
using System.Text.RegularExpressions;
//using Config;
namespace VEPROMS.CSLA.Library
{
public partial class ROFST
public partial class ROFst
{
[NonSerialized]
private ROFSTLookup _ROFSTLookup;
public ROFSTLookup ROFSTLookup
{
get
{
if (_ROFSTLookup == null)
{
_ROFSTLookup = new ROFSTLookup(this);
}
return _ROFSTLookup;
}
}
}
public partial class ROFstInfo
{
#region Log4Net
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
[Serializable]
public struct roHdr
#region PropertiesAndData
private DocVersion _docVer;
public DocVersion docVer
{
public int hSize;
public int hYear;
public byte hMonth;
public byte hDay;
public int hcYear;
public byte hcMonth;
public byte hcDay;
public byte hcHour;
public byte hcMin;
public byte hcSec;
public byte hcHund;
public rodbi[] myDbs;
};
[Serializable]
public struct rodbi
{
public int dbiID;
public int dbiType;
public int dbiAW;
public string dbiTitle;
public string dbiAP;
public int ID;
public int ParentID;
public rochild[] children;
};
public struct rogrp
{
public int ID;
public int ParentID;
public rochild[] children;
public string value;
public string appid;
};
public struct rochild
{
public int ID;
public int ParentID;
public int type;
public string title;
public string roid;
public string appid;
public string value;
public rochild[] children;
};
public roHdr myHdr;
private int TableID;
private string fstPath;
private HybridDictionary dicRos;
private HybridDictionary dicRosIntIDs;
private DocVersionInfo docVerInfo = null;
public ROFST(string path, DocVersionInfo docverinfo)
{
docVerInfo = docverinfo;
fstPath = path;
if (!File.Exists(fstPath))
get
{
log.ErrorFormat("RO FST Does not exist: {0}", path);
return;
if (_docVer == null) _docVer = DocVersion.Get(this.ROFstAssociations[0].MyDocVersion.VersionID);
return _docVer;
}
dicRos = new HybridDictionary();
dicRosIntIDs = new HybridDictionary();
ParseIntoDictionary();
}
public void Close()
{
// remove the dictionary
dicRosIntIDs.Clear();
dicRosIntIDs = null;
dicRos.Clear();
dicRos = null;
}
// this only gets rochild values. Later we may want another
// dictionary to get groups.
public string GetRoValue(string ROID)
{
// Use the ROID to get the value from the dictionary
if (dicRos.Contains(ROID))
set
{
rochild rochld = (rochild)dicRos[ROID];
return rochld.value;
}
return null;
}
public rochild GetRoChild(string ROID)
{
// Use the ROID to get the value from the dictionary
if (dicRos.Contains(ROID))
{
rochild rochld = (rochild)dicRos[ROID];
return rochld;
}
rochild tmp = new rochild();
tmp.ID = -1;
return tmp;
}
public rochild GetRoChildFromID(int id)
{
// Use the id to get the value from the dictionary
if (dicRosIntIDs.Contains(id))
{
rochild rochld = (rochild)dicRosIntIDs[id];
return rochld;
}
rochild tmp = new rochild();
tmp.ID = -1;
return tmp;
}
public rodbi[] GetRODatabaseList()
{
return myHdr.myDbs;
}
private int StringLength(byte[] ab, int offset)
{
int i = 0;
while (ab[i + offset] != 0) i++;
return i;
}
private rogrp LoadGroup(byte[] ab, int offset)
{
rogrp myGrp = new rogrp();
myGrp.ID = BitConverter.ToInt32(ab, offset);
myGrp.ParentID = BitConverter.ToInt32(ab, offset + 4);
int howmany = BitConverter.ToInt16(ab, offset + 8);
if (howmany > 0)
{
myGrp.children = new rochild[howmany];
int myOffset = offset + 10;
for (int i = 0; i < myGrp.children.Length; i++)
{
int childOffset = BitConverter.ToInt32(ab, myOffset);
rochild tmp = new rochild();
//tmp.offset=BitConverter.ToInt32(ab,myOffset);
tmp.type = BitConverter.ToInt16(ab, myOffset + 4);
int slen = StringLength(ab, myOffset + 6);
tmp.title = Encoding.Default.GetString(ab, myOffset + 6, slen);
myOffset += (7 + slen);
rogrp tmpg = LoadGroup(ab, childOffset);
MultipleReturnValuesInheritType(ref tmpg, tmp.type);
tmp.ID = tmpg.ID;
tmp.ParentID = tmpg.ParentID;
tmp.children = tmpg.children;
tmp.value = tmpg.value;
tmp.appid = tmpg.appid;
tmp.roid = TableID.ToString("X4") + tmp.ID.ToString("X8");
dicRos.Add(tmp.roid, tmp);
if (!dicRosIntIDs.Contains(tmp.ID)) dicRosIntIDs.Add(tmp.ID, tmp);
int j;
for (j = i - 1; j >= 0 && tmp.ID < myGrp.children[j].ID; j--)
{
myGrp.children[j + 1] = myGrp.children[j];
}
myGrp.children[j + 1] = tmp;
}
}
else
{
int slen = StringLength(ab, offset + 12);
//myGrp.value = Encoding.Default.GetString(ab, offset + 12, slen);
ProcessROReturnValue(ref myGrp, Encoding.Default.GetString(ab, offset + 12, slen));
int slen2 = StringLength(ab, offset + 13 + slen);
myGrp.appid = Encoding.Default.GetString(ab, offset + 13 + slen, slen2);
}
return myGrp;
}
/// <summary>
/// This function will take the raw RO return value and resolve any macros, conditionals, and
/// generated the return value or a list of multiple return values.
/// </summary>
/// <param name="myGrp"></param>
/// <param name="rawvalue"></param>
private void ProcessROReturnValue(ref rogrp myGrp, string rawvalue)
{
List<string> lstROVals = GetROReturnValue(rawvalue);
if (lstROVals.Count > 1) // mulitple return values
{
myGrp.children = new rochild[lstROVals.Count];
for (int i = 0; i < lstROVals.Count; i++)
{
myGrp.children[i].value = lstROVals[i];
myGrp.children[i].roid = TableID.ToString("X4") + myGrp.ID.ToString("X8") + i.ToString("X4");
myGrp.children[i].type = -1; // Multiple return value inherit type from parent
myGrp.children[i].title = lstROVals[i];
}
}
else
myGrp.value = lstROVals[0];
return;
}
/// <summary>
/// Multiple return values need to get the type from the parent node.
/// </summary>
/// <param name="myGrp"></param>
/// <param name="parenttype"></param>
private void MultipleReturnValuesInheritType(ref rogrp myGrp, int parenttype)
{
if (myGrp.children != null)
{
for (int cnt = 0; cnt < myGrp.children.Length; cnt++ )
{
if (myGrp.children[cnt].type == -1)
{
myGrp.children[cnt].type = parenttype;
myGrp.children[cnt].appid = myGrp.appid;
}
}
}
}
private void ParseIntoDictionary()
{
FileStream fsIn = new FileStream(fstPath, FileMode.Open,FileAccess.Read, FileShare.Read);
// Create an instance of StreamReader that can read
// characters from the FileStream.
BinaryReader r = new BinaryReader(fsIn);
byte[] ab = r.ReadBytes((int)fsIn.Length);
r.Close();
myHdr.hSize = BitConverter.ToInt32(ab, 0);
myHdr.hYear = BitConverter.ToInt16(ab, 4);
myHdr.hMonth = ab[6];
myHdr.hDay = ab[7];
myHdr.hcYear = BitConverter.ToInt16(ab, 8);
myHdr.hcMonth = ab[10];
myHdr.hcDay = ab[11];
myHdr.hcHour = ab[12];
myHdr.hcMin = ab[13];
myHdr.hcSec = ab[14];
myHdr.hcHund = ab[15];
int hdrOffset = BitConverter.ToInt32(ab, 16);
int howbig = BitConverter.ToInt32(ab, hdrOffset);
int dbs = BitConverter.ToInt16(ab, hdrOffset + 4);
myHdr.myDbs = new rodbi[dbs];
for (int i = 0; i < dbs; i++)
{
int offset = hdrOffset + 6 + (i * 30);
myHdr.myDbs[i].dbiID = BitConverter.ToInt16(ab, offset + 0);
TableID = myHdr.myDbs[i].dbiID;
myHdr.myDbs[i].dbiType = BitConverter.ToInt16(ab, offset + 2);
myHdr.myDbs[i].dbiAW = BitConverter.ToInt16(ab, offset + 4);
rogrp tmp = LoadGroup(ab, BitConverter.ToInt32(ab, offset + 6));
myHdr.myDbs[i].ID = tmp.ID;
myHdr.myDbs[i].children = tmp.children;
int iPtr = BitConverter.ToInt32(ab, offset + 22) + hdrOffset + 6;
myHdr.myDbs[i].dbiTitle = Encoding.Default.GetString(ab, iPtr, StringLength(ab, iPtr));
iPtr = BitConverter.ToInt32(ab, offset + 26) + hdrOffset + 6;
myHdr.myDbs[i].dbiAP = Encoding.Default.GetString(ab, iPtr, StringLength(ab, iPtr));
}
}
public bool SaveToXml(string fname)
{
try
{
StreamWriter swxml = new StreamWriter(fname);
XmlSerializer mySer = new XmlSerializer(typeof(roHdr));
mySer.Serialize(swxml, myHdr);
swxml.Close();
_docVer = value;
}
catch (Exception ex)
}
[NonSerialized]
private ROFSTLookup _ROFSTLookup;
public ROFSTLookup ROFSTLookup
{
get
{
log.ErrorFormat("Error writing to file: {0}", ex.Message);
return false;
if (_ROFSTLookup == null)
{
_ROFSTLookup = new ROFSTLookup(this);
}
return _ROFSTLookup;
}
return true;
}
public XmlDocument GetXmlFromFile(string fname)
{
FileStream xmlIn = new FileStream(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlIn);
xmlIn.Close();
return xmlDoc;
}
public string GetValueFromXml(XmlDocument xmlDoc, string ROID)
{
// use roid as xpath to get data.
try
{
string xpath_roid = "//rochild[roid = \"" + ROID.Substring(0, 12) + "\"]/value";
XmlNode valnd = xmlDoc.SelectSingleNode(xpath_roid);
if (valnd == null) return null;
return valnd.InnerText;
}
catch (Exception ex)
{
log.ErrorFormat("Cannot find ro in XmlDocument ");
log.ErrorFormat("roid = {0}", ROID);
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
}
return null;
}
public string GetFstPath()
{
return fstPath;
}
public string GetDefaultGraphicExtension()
{
if (docVerInfo != null)
return docVerInfo.DocVersionConfig.Graphics_defaultext;
else
return "TIF"; // this is the Volian Default
}
#endregion
#region AppSupport
//public static ROImageInfo Get(RODbInfo rodbinfo, string filename)
//{
// if (rodbinfo.RODbROImageCount != 0)
// {
// foreach (ROImageInfo ri in rodbinfo.RODbROImages)
// {
// if (ri.FileName == filename) return ri;
// }
// }
// return null;
//}
public string GetDefaultROPrefix()
{
if (docVerInfo != null)
return docVerInfo.DocVersionConfig.RODefaults_setpointprefix;
if (docVer != null)
return docVer.DocVersionConfig.RODefaults_setpointprefix;
else
return "SP1"; // Not Sure about this...
}
public string GetDefaultGraphicsPrefix()
{
if (docVerInfo != null)
return docVerInfo.DocVersionConfig.RODefaults_graphicsprefix;
if (docVer != null)
return docVer.DocVersionConfig.RODefaults_graphicsprefix;
else
return "IG1"; // Not Sure about this...
}
#region Add New Ro Fst
/// <summary>
/// Adds an ro.fst into a sql database.
/// </summary>
/// <param name="rdi" - the Rodb to use as the path for updating the ro.fst, i.e.
/// import from there.
/// <param name="docver" - hook into this doc version></param>
/// <returns>ROFst: Returns the created rofst object</returns>
public static ROFst AddRoFst(RODbInfo rdi, DocVersion docver)
{
string rofstfilepath = rdi.FolderPath + @"\ro.fst";
DirectoryInfo di = new DirectoryInfo(rdi.FolderPath);
// check if this rofst has been loaded, i.e. dts on file versus dts in db...
// if so, just make association with docversion.
ROFst rofst = ROFst.GetByRODbID_DTS(rdi.RODbID, di.LastWriteTime);
if (rofst != null)
{
docver.DocVersionAssociations.Add(rofst);
docver.Save();
return rofst;
}
// Next read in the rofst & make the rofst record.
FileStream fsIn = new FileStream(rofstfilepath, FileMode.Open, FileAccess.Read, FileShare.Read);
// Create an instance of StreamReader that can read characters from the FileStream.
BinaryReader r = new BinaryReader(fsIn);
byte[] ab = r.ReadBytes((int)fsIn.Length);
fsIn.Close();
using (RODb rd = RODb.Get(rdi.RODbID))
{
rofst = ROFst.MakeROFst(rd, ab, null, di.LastWriteTime, rdi.UserID);
// Hook this into the current docversion by replacing the rofstid field in the doc version
// association object:
docver.DocVersionAssociations.Add(rofst);
docver.Save();
// Now load any images in... type 8 - integrated graphics ro type
for (int i = 0; i < rofst.ROFSTLookup.myHdr.myDbs.Length; i++)
{
// walk through the rofst 'database' searching for all nodes that are integrated graphics, type 8:
if (rofst.ROFSTLookup.myHdr.myDbs[i].children != null)
{
using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID))
{
rfi.MigrateRoFstGraphics(rdi, rofst.ROFSTLookup.myHdr.myDbs[i].children);
}
}
}
return rofst;
}
}
#endregion
#region Update Ro Values
/// <summary>
/// Updates an ro.fst into a sql database.
/// </summary>
/// <param name="rdi" - the Rodb to use as the path for updating the ro.fst, i.e.
/// import from there.
/// <param name="dva" - the association record to modify, i.e. make new rofst
/// the current one.
/// <param name="docver" - hook into this doc version></param>
/// <returns>ROFst: Returns the created rofst object</returns>
public static ROFst UpdateRoFst(RODbInfo rdi, DocVersionAssociation dva, DocVersion docver)
{
// file validity checks are done before getting here - just do the import
// here.
string rofstfilepath = rdi.FolderPath + @"\ro.fst";
DirectoryInfo di = new DirectoryInfo(rdi.FolderPath);
// There may be more than 1 'ro' as the 'ROName' field (ROName is derived from the ropath).
// Get new name be incrementing, if so.
string newname = NewROName(di.Name);
// Next read in the rofst & make the rofst record.
FileStream fsIn = new FileStream(rofstfilepath, FileMode.Open, FileAccess.Read, FileShare.Read);
// Create an instance of StreamReader that can read characters from the FileStream.
BinaryReader r = new BinaryReader(fsIn);
byte[] ab = r.ReadBytes((int)fsIn.Length);
fsIn.Close();
using (RODb rd = RODb.Get(rdi.RODbID))
{
ROFst rofst = ROFst.MakeROFst(rd, ab, null, di.LastWriteTime, rdi.UserID);
// Hook this into the current docversion by replacing the rofstid field in the doc version
// association object:
dva.MyROFst = rofst;
docver.Save();
// Now load any images in... type 8 - integrated graphics ro type
for (int i = 0; i < rofst.ROFSTLookup.myHdr.myDbs.Length; i++)
{
// walk through the rofst 'database' searching for all nodes that are integrated graphics, type 8:
if (rofst.ROFSTLookup.myHdr.myDbs[i].children != null)
{
using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID))
{
rfi.MigrateRoFstGraphics(rdi, rofst.ROFSTLookup.myHdr.myDbs[i].children);
}
}
}
return rofst;
}
}
private static string NewROName(string roName)
{
string retval = roName;
int iSuffix = -1;
RODbInfoList rodblist = RODbInfoList.Get();
foreach (RODbInfo rdi in rodblist)
{
if (rdi.ROName.StartsWith(roName))
{
if (rdi.ROName == roName)
iSuffix = 0;
else if (Regex.IsMatch(rdi.ROName, roName + "[_][0-9]+"))
{
int ii = int.Parse(rdi.ROName.Substring(1 + roName.Length));
if (ii > iSuffix) iSuffix = ii;
}
}
}
if (iSuffix >= 0)
retval = string.Format("{0}_{1}", roName, iSuffix + 1);
return retval;
}
private void MigrateRoFstGraphics(RODbInfo rdi, ROFSTLookup.rochild[] rochild)
{
for (int i = 0; i < rochild.Length; i++)
{
if (rochild[i].type == 8) this.AddGraphic(rdi, rochild[i].value);
if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children);
}
}
private void AddGraphic(RODbInfo rdi, string p)
{
if (p == null) return;
string imgname = p.Substring(0, p.IndexOf('\n'));
int thedot = imgname.LastIndexOf('.');
string fname = imgname;
if (thedot == -1 || (thedot != (imgname.Length - 4)))
{
RODbConfig roDbCfg = new RODbConfig(rdi.Config);
fname += string.Format(".{0}", roDbCfg.GetDefaultGraphicExtension());
}
string imgfile = rdi.FolderPath + @"\" + fname;
ROImage roImg = null;
if (File.Exists(imgfile))
{
FileInfo fi = new FileInfo(imgfile);
// if the roimage record exists, don't create a new one...
using (roImg = ROImage.GetByRODbID_FileName_DTS(rdi.RODbID, imgname,fi.LastWriteTime))
{
if (roImg == null)
{
FileStream fsIn = new FileStream(imgfile, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader r = new BinaryReader(fsIn);
byte[] ab = r.ReadBytes((int)fsIn.Length);
r.Close();
fsIn.Close();
using (RODb rodb = RODb.Get(rdi.RODbID))
{
roImg = ROImage.MakeROImage(rodb, imgname, ab, null, fi.LastWriteTime, "Migration");
}
}
Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID);
if (figure != null) return;
using (ROFst rofst = ROFst.Get(this.ROFstID))
{
figure = Figure.MakeFigure(rofst, roImg, null);
}
}
}
else
Console.WriteLine(string.Format("{0}", imgfile), "Cannot Find Image File");
}
#endregion
#endregion
}
}

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
namespace VEPROMS.CSLA.Library
{
public partial class ROImageInfo
{
public static ROImageInfo GetByROFstID_FileName(int rOFstID, string fileName)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a ROImage");
try
{
ROImageInfo tmp = DataPortal.Fetch<ROImageInfo>(new ROFstID_FileNameCriteria(rOFstID, fileName));
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up ROImage
tmp = null;
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ROImage.GetByROFstID_FileName", ex);
}
}
private void DataPortal_Fetch(ROFstID_FileNameCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
ApplicationContext.LocalContext["cn"] = cn;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "getROImageByROFstID_FileName";
cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID);
cm.Parameters.AddWithValue("@FileName", criteria.FileName);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
if (!dr.Read())
{
_ErrorMessage = "No Record Found";
return;
}
ReadData(dr);
}
}
// removing of item only needed for local data portal
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
ApplicationContext.LocalContext.Remove("cn");
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ROImageInfo.DataPortal_Fetch", ex);
}
}
[Serializable()]
private class ROFstID_FileNameCriteria
{
private int _ROFstID;
public int ROFstID
{ get { return _ROFstID; } }
private string _FileName;
public string FileName
{ get { return _FileName; } }
public ROFstID_FileNameCriteria(int rOFstID, string fileName)
{
_ROFstID = rOFstID;
_FileName = fileName;
}
}
}
}