Skip to content

Commit 144099d

Browse files
committed
Bulk safety upload of 39 items
1 parent 529bd0d commit 144099d

39 files changed

Lines changed: 985 additions & 2100 deletions

OSAE.API/General/Common.cs

Lines changed: 5 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -187,165 +187,6 @@ public static string PatternParse(string pattern)
187187
}
188188
}
189189

190-
public static string MatchPattern(string str, string sUser)
191-
{
192-
string ScriptParameter = "";
193-
sUser = sUser.ToUpper();
194-
try
195-
{
196-
str = str.ToUpper();
197-
str = str.TrimEnd('?', '.', '!') + " ";
198-
str = str.Replace(" 'S", "'S");
199-
str = str.Replace("YOUR ", "SYSTEM'S ");
200-
str = str.Replace("YOU ARE ", "SYSTEM IS ");
201-
str = str.Replace("ARE YOU ", "IS SYSTEM ");
202-
str = str.Replace("MY ", sUser + "'S ");
203-
str = str.Replace(" ME ", " " + sUser + " ");
204-
str = str.Replace("AM I ", "IS " + sUser + " ");
205-
str = str.Replace("I AM ",sUser + " IS ");
206-
207-
DataSet dataset = new DataSet();
208-
//command.CommandText = "SELECT pattern FROM osae_v_pattern WHERE `match`=@Name";
209-
//command.Parameters.AddWithValue("@Name", str);
210-
dataset = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern_match WHERE UPPER(`match`)='" + str.Replace("'", "''") + "'");
211-
212-
if (dataset.Tables[0].Rows.Count > 0)
213-
{
214-
215-
//Since we have a match, lets execute the scripts
216-
OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), "", "SYSTEM");
217-
return dataset.Tables[0].Rows[0]["pattern"].ToString();
218-
}
219-
else
220-
{
221-
//Replace Words with place holders and retry the pattern match
222-
//example "Please turn the main light on" becomes "Please turn the [OBJECT] [STATE]"
223-
224-
//Step 1: Break the Input into an Array to Query the Words for DB matches
225-
226-
227-
string[] words = str.Split(' ');
228-
229-
DataSet dsObjects = new DataSet();
230-
foreach (String word in words)
231-
{
232-
dsObjects = OSAE.Common.ObjectNamesStartingWith(word.Replace("'S",""));
233-
foreach (DataRow dr in dsObjects.Tables[0].Rows)
234-
{
235-
if (str.IndexOf(dr["object_name"].ToString().ToUpper()) > -1)
236-
//return "Found " + dr["object_name"].ToString();
237-
{
238-
str = str.Replace(dr["object_name"].ToString().ToUpper(), "[OBJECT]");
239-
if (ScriptParameter.Length > 1)
240-
{
241-
ScriptParameter = ScriptParameter + ",";
242-
}
243-
ScriptParameter += dr["object_name"].ToString();
244-
//Determine if the Object is Possessive, which would be followed by a Property
245-
if (str.ToUpper().IndexOf("[OBJECT]'S") > -1)
246-
{
247-
//Here We have found our Possessive Object, so we need to look for an appropriate property afterwards
248-
//So we are going to retrieve a property list and compare it to the start of theremainder of the string
249-
250-
DataSet dsProperties = new DataSet();
251-
dsProperties = OSAEObjectPropertyManager.ObjectPropertyListGet(dr["object_name"].ToString());
252-
foreach (DataRow drProperty in dsProperties.Tables[0].Rows)
253-
{
254-
//Here we need to break the string into words to avoid partial matches
255-
int objectStartLoc = str.ToUpper().IndexOf("[OBJECT]'S");
256-
string strNewSearch = str.Substring(objectStartLoc + 11);
257-
if (strNewSearch.ToUpper().IndexOf(drProperty["property_name"].ToString().ToUpper()) > -1)
258-
{
259-
str = str.Replace("[OBJECT]'S " + drProperty["property_name"].ToString().ToUpper(), "[OBJECT]'S [PROPERTY]");
260-
//str = str.Replace(drState["state_label"].ToString().ToUpper(), "[STATE]");
261-
ScriptParameter += "," + drProperty["property_name"].ToString();
262-
}
263-
}
264-
}
265-
string replacementString = "";
266-
//Here We have found our Object, so we need to look for an appropriate Object Type afterwards
267-
//So we are going to retrieve a object type list and compare it to the remainder of the string
268-
DataSet dsObjectTypes = OSAESql.RunSQL("SELECT object_type FROM osae_v_object_type WHERE base_type NOT IN ('CONTROL','SCREEN') ORDER BY object_type");
269-
foreach (DataRow drObjectTypes in dsObjectTypes.Tables[0].Rows)
270-
{
271-
//Here we need to break the string into words to avoid partial matches
272-
273-
string[] wordArray = str.Split(new Char[] { ' ' });
274-
foreach (string w in wordArray)
275-
{
276-
if (replacementString.Length > 1)
277-
{
278-
replacementString = replacementString + " ";
279-
}
280-
if (drObjectTypes["object_type"].ToString().ToUpper() == w)
281-
{
282-
replacementString = replacementString + "[OBJECT TYPE]";
283-
//str = str.Replace(drState["state_label"].ToString().ToUpper(), "[STATE]");
284-
ScriptParameter += "," + drObjectTypes["object_type"].ToString();
285-
}
286-
else
287-
{
288-
replacementString = replacementString + w;
289-
}
290-
}
291-
}
292-
293-
//Here We have found our Object, so we need to look for an appropriate state afterwards
294-
//So we are going to retrieve a state list and compare it to the remainder of the string
295-
DataSet dsStates = new DataSet();
296-
dsStates = OSAEObjectStateManager.ObjectStateListGet(dr["object_name"].ToString());
297-
foreach (DataRow drState in dsStates.Tables[0].Rows)
298-
{
299-
//Here we need to break the string into words to avoid partial matches
300-
string[] wordArray = str.Split(new Char[] { ' ' });
301-
foreach (string w in wordArray)
302-
{
303-
if (replacementString.Length > 1)
304-
{
305-
replacementString = replacementString + " ";
306-
}
307-
if (drState["state_label"].ToString().ToUpper() == w || drState["state_name"].ToString().ToUpper() == w)
308-
{
309-
replacementString = replacementString + "[STATE]";
310-
//str = str.Replace(drState["state_label"].ToString().ToUpper(), "[STATE]");
311-
ScriptParameter += "," + drState["state_name"].ToString();
312-
}
313-
else
314-
{
315-
replacementString = replacementString + w;
316-
}
317-
}
318-
//Now that we have replaced the Object,Object Type, and State, Lets check for a match again
319-
//DataSet dataset = new DataSet();
320-
//command.CommandText = "SELECT pattern FROM osae_v_pattern WHERE `match`=@Name";
321-
//command.Parameters.AddWithValue("@Name", str);
322-
//dataset = OSAESql.RunQuery(command);
323-
replacementString = replacementString.Replace(" 'S", "'S");
324-
dataset = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern_match WHERE `match`='" + replacementString.Replace("'", "''") + "'");
325-
if (dataset.Tables[0].Rows.Count > 0)
326-
{
327-
//return dataset.Tables[0].Rows[0]["pattern"].ToString();
328-
//Since we have a match, lets execute the scripts
329-
OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), ScriptParameter, "Jabber");
330-
return dataset.Tables[0].Rows[0]["pattern"].ToString();
331-
}
332-
//break;
333-
}
334-
//break;
335-
}
336-
}
337-
}
338-
return string.Empty;
339-
}
340-
}
341-
catch (Exception ex)
342-
{
343-
Logging.GetLogger().AddToLog("API - MatchPattern error: " + ex.Message, true);
344-
return string.Empty;
345-
}
346-
347-
}
348-
349190
/// <summary>
350191
/// Get all object names that start with a single word
351192
/// </summary>
@@ -363,7 +204,7 @@ public static DataSet ObjectNamesStartingWith(string pattern)
363204
DataSet dataset = new DataSet();
364205
//command.CommandText = "SELECT object_name FROM osae_object WHERE UPPER(object_name) LIKE '@Pattern%' ORDER BY Length(object_name) DESC";
365206
//command.Parameters.AddWithValue("@Pattern", pattern.ToUpper());
366-
dataset = OSAESql.RunSQL("SELECT object_name FROM osae_object WHERE UPPER(object_name) LIKE '" + pattern.Replace("'", "''") + "%' ORDER BY Length(object_name) DESC");
207+
dataset = OSAESql.RunSQL("SELECT object_name FROM osae_object WHERE (UPPER(object_name) LIKE UPPER('" + pattern.Replace("'", "''") + "%') OR UPPER(object_alias) LIKE UPPER('" + pattern.Replace("'", "''") + "%')) ORDER BY Length(object_name) DESC");
367208
return dataset;
368209
}
369210
}
@@ -405,24 +246,24 @@ public static void CreateComputerObject(string sourceName)
405246
OSAEObject obj = OSAEObjectManager.GetObjectByAddress(computerIp);
406247
if (obj == null)
407248
{
408-
OSAEObjectManager.ObjectAdd(Common.ComputerName, Common.ComputerName, "COMPUTER", computerIp, string.Empty, true);
249+
OSAEObjectManager.ObjectAdd(Common.ComputerName, Common.ComputerName, Common.ComputerName, "COMPUTER", computerIp, string.Empty, true);
409250
OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName, "Host Name", Common.ComputerName, sourceName);
410251
}
411252
else if (obj.Type == "COMPUTER")
412253
{
413-
OSAEObjectManager.ObjectUpdate(obj.Name, Common.ComputerName, obj.Description, "COMPUTER", computerIp, obj.Container, obj.Enabled);
254+
OSAEObjectManager.ObjectUpdate(obj.Name, Common.ComputerName, obj.Alias, obj.Description, "COMPUTER", computerIp, obj.Container, obj.Enabled);
414255
OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName, "Host Name", Common.ComputerName, sourceName);
415256
}
416257
else
417258
{
418-
OSAEObjectManager.ObjectAdd(Common.ComputerName + "." + computerIp, Common.ComputerName, "COMPUTER", computerIp, string.Empty, true);
259+
OSAEObjectManager.ObjectAdd(Common.ComputerName + "." + computerIp, Common.ComputerName, Common.ComputerName, "COMPUTER", computerIp, string.Empty, true);
419260
OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName + "." + computerIp, "Host Name", Common.ComputerName, sourceName);
420261
}
421262
}
422263
else
423264
{
424265
OSAEObject obj = OSAEObjectManager.GetObjectByName(Common.ComputerName);
425-
OSAEObjectManager.ObjectUpdate(obj.Name, obj.Name, obj.Description, "COMPUTER", computerIp, obj.Container, obj.Enabled);
266+
OSAEObjectManager.ObjectUpdate(obj.Name, obj.Name, obj.Alias, obj.Description, "COMPUTER", computerIp, obj.Container, obj.Enabled);
426267
OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Host Name", Common.ComputerName, sourceName);
427268
}
428269
}

0 commit comments

Comments
 (0)