public WebResponse DeleteTaskRequest(ClientAuthStruct auth, int TaskID) { WebResponse response = new WebResponse(); using (ClientRequestHandler handler = new ClientRequestHandler()) { try { if (handler.Authorize(auth, null)) { if (handler.DeleteTask(TaskID)) { response.ErrorCode = (int)ResponseCode.OK; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.OK, System.Diagnostics.TraceEventType.Information, "DeleteTask - OK"); } else { response.ErrorCode = (int)ResponseCode.RequestedObjectNotFound; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.BusinessError, System.Diagnostics.TraceEventType.Error, "Nie udało się usunąć Taska o ID " + TaskID.ToString()); } } else { response.ErrorCode = (int)ResponseCode.AuthorizationFailed; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.AuthorizationFailed, System.Diagnostics.TraceEventType.Warning, "Autoryzacja nieudana - użytkownik " + auth.UserName); } } catch (Exception exc) { response.ErrorCode = (int)ResponseCode.ProxyServerError; response.ErrorDescription = exc.ToString(); } } return response; }
public bool Authorize(ClientAuthStruct auth, IMWRObject request) { DBUser dbUser = new DBUser(dataProvider); dbUser.Connection = connection; dbUser.Load(auth.UserName, auth.Password); if (dbUser.BusinessObject == null) { return false; } return true; }
public DictionaryResponse GetDictionaryEntries(ClientAuthStruct auth, int type, int state) { DictionaryResponse response = new DictionaryResponse(); ClientInterface.DictionaryResponse responseProxy = client.GetDictionaryEntries(GetAuthData(auth), type, state); response.ErrorCode = responseProxy.ErrorCode; response.ErrorDescription = responseProxy.ErrorDescription; if (responseProxy.DictionaryTable != null && responseProxy.DictionaryTable.Length > 0) { response.DictionaryTable = new DictionaryEntry[responseProxy.DictionaryTable.Length]; for (int i = 0; i < responseProxy.DictionaryTable.Length; i++) { response.DictionaryTable[i] = new DictionaryEntry(); response.DictionaryTable[i].Active = responseProxy.DictionaryTable[i].Active; response.DictionaryTable[i].Assembly = responseProxy.DictionaryTable[i].Assembly; response.DictionaryTable[i].Config = responseProxy.DictionaryTable[i].Config; response.DictionaryTable[i].Guid = responseProxy.DictionaryTable[i].Guid; response.DictionaryTable[i].Name = responseProxy.DictionaryTable[i].Name; response.DictionaryTable[i].Type = (MWRCommonTypes.Enum.ObjectType)(int)responseProxy.DictionaryTable[i].Type; response.DictionaryTable[i].TypeOf = responseProxy.DictionaryTable[i].TypeOf; } } return response; }
public TaskResponse CreateTaskRequest(ClientAuthStruct auth, MWRCommonTypes.TaskStruct task) { TaskResponse response = new TaskResponse(); using (ClientRequestHandler handler = new ClientRequestHandler()) { try { if (handler.Authorize(auth, null)) { int taskID = -1; if (handler.CreateTask(task, ref taskID)) { response.Task = task; response.TaskID = taskID; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.OK, System.Diagnostics.TraceEventType.Information, "CreateTaskRequest - OK"); response.ErrorCode = (int)ResponseCode.OK; } else { response.ErrorCode = (int)ResponseCode.IncorrectDataError; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.BusinessError, System.Diagnostics.TraceEventType.Error, string.Format("Nie udało się dodać Taska ({0})", task.Guid)); } } else { response.ErrorCode = (int)ResponseCode.AuthorizationFailed; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.AuthorizationFailed, System.Diagnostics.TraceEventType.Warning, "Autoryzacja nieudana - użytkownik " + auth.UserName); } } catch (Exception exc) { response.ErrorCode = (int)ResponseCode.ProxyServerError; response.ErrorDescription = exc.ToString(); } } return response; }
protected WebResponse CommonFunction(WebResponse emptyStructure, ClientAuthStruct auth, WebMethodInvoker method, object [] arguments) { WebResponse response = emptyStructure; using (ClientRequestHandler handler = new ClientRequestHandler()) { try { if (handler.Authorize(auth, null)) { response = method(handler, arguments); if (response.ErrorCode == (int)ResponseCode.OK) { LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.OK, System.Diagnostics.TraceEventType.Information, method.Method.Name); } else { LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.BusinessError, System.Diagnostics.TraceEventType.Error, method.Method.Name); } } else { response.ErrorCode = (int)ResponseCode.AuthorizationFailed; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.AuthorizationFailed, System.Diagnostics.TraceEventType.Error, method.Method.Name); } } catch (Exception exc) { response.ErrorCode = (int)ResponseCode.ProxyServerError; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.InternalError, System.Diagnostics.TraceEventType.Error, method.Method.Name + " błąd - " + exc.ToString()); } } return response; }
public WebResponse UpdateDictionary(ClientAuthStruct auth, string Guid, int newState, string Config) { return CommonFunction(new WebResponse(), auth, new WebMethodInvoker(UpdateDictionary), new object[] { Guid, newState, Config }); }
public UserDataResponse GetUserData(ClientAuthStruct auth) { return (UserDataResponse)CommonFunction(new UserDataResponse(), auth, new WebMethodInvoker(GetUserData), new object[] {auth.UserName, auth.Password}); }
public GroupTaskResponse GetTasks(ClientAuthStruct auth, DateTime dateFrom, DateTime dateTo, int[] states, string guid, int startIndex, int rowsCount) { return (GroupTaskResponse)CommonFunction(new GroupTaskResponse(), auth, new WebMethodInvoker(GetTasks), new object[] { auth.MachineGuid, dateFrom, dateTo, states, guid, startIndex, rowsCount }); }
public TaskResponse GetTaskRequest(ClientAuthStruct auth, int TaskID) { TaskResponse response = new TaskResponse(); using (ClientRequestHandler handler = new ClientRequestHandler()) { try { if (handler.Authorize(auth, null)) { response.Task = handler.GetTask(TaskID); if (response.Task == null) { response.ErrorCode = (int)ResponseCode.RequestedObjectNotFound; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.BusinessError, System.Diagnostics.TraceEventType.Warning, string.Format("GetTaskRequest - Task nie istnieje ({0})", TaskID)); } else { if (!response.Task.Active) { response.Task = null; response.ErrorCode = (int)ResponseCode.RequestedObjectIsDisabled; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.BusinessError, System.Diagnostics.TraceEventType.Warning, string.Format("GetTaskRequest - Task nie istnieje ({0})", TaskID)); } else { response.ErrorCode = (int)BusinessLayer.ResponseCode.OK; LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.OK, System.Diagnostics.TraceEventType.Information, "GetTaskRequest - OK"); } } } else { LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.AuthorizationFailed, System.Diagnostics.TraceEventType.Warning, string.Format("Autoryzacja nieudana! Użytkownik {0} hasło {1}", auth.UserName, auth.Password)); response.ErrorCode = (int)BusinessLayer.ResponseCode.AuthorizationFailed; } } catch (Exception exc) { response.ErrorCode = (int)ResponseCode.ProxyServerError; response.ErrorDescription = exc.ToString(); LoggerHelper.Log(LogCategories.ClientRequest, LogEventID.InternalError, System.Diagnostics.TraceEventType.Error, exc.ToString()); } } return response; }
public DictionaryResponse GetDictionaryEntries(ClientAuthStruct auth, int type, int state) { return (DictionaryResponse)CommonFunction(new DictionaryResponse(), auth, new WebMethodInvoker(GetDictionaries), new object[] { type, state }); }
protected ClientInterface.ClientAuthStruct GetAuthData(ClientAuthStruct baseAuth) { ClientInterface.ClientAuthStruct ret = new MWRClientLib.ClientInterface.ClientAuthStruct(); ret.MachineGuid = baseAuth.MachineGuid; ret.UserName = baseAuth.UserName; ret.Password = baseAuth.Password; return ret; }
public WebResponse UpdateDictionary(ClientAuthStruct auth, string Guid, int newState, string Config) { WebResponse response = new WebResponse(); ClientInterface.WebResponse proxyResponse = client.UpdateDictionary(GetAuthData(auth), Guid, newState, Config); response.ErrorCode = proxyResponse.ErrorCode; response.ErrorDescription = proxyResponse.ErrorDescription; return response; }
public UserDataResponse GetUserData(ClientAuthStruct auth) { UserDataResponse response = new UserDataResponse(); ClientInterface.UserDataResponse proxyResponse = client.GetUserData(GetAuthData(auth)); response.ErrorCode = proxyResponse.ErrorCode; response.ErrorDescription = proxyResponse.ErrorDescription; if (response.ErrorCode == 0) { if (proxyResponse.MachinesList != null && proxyResponse.MachinesList.Length > 0) { response.MachinesList = new MachineWithPrivilleges[proxyResponse.MachinesList.Length]; for (int i = 0; i < proxyResponse.MachinesList.Length; i++) { response.MachinesList[i] = new MachineWithPrivilleges(); response.MachinesList[i].Description = proxyResponse.MachinesList[i].Description; response.MachinesList[i].Guid = proxyResponse.MachinesList[i].Guid; response.MachinesList[i].IP = proxyResponse.MachinesList[i].IP; response.MachinesList[i].Name = proxyResponse.MachinesList[i].Name; response.MachinesList[i].Privilleges = proxyResponse.MachinesList[i].Privilleges.ToArray(); } } response.User = new User(); response.User.Group = proxyResponse.User.Group; response.User.ID = proxyResponse.User.ID; response.User.Name = proxyResponse.User.Name; response.User.Password = proxyResponse.User.Password; response.User.RegisterDate = proxyResponse.User.RegisterDate; } return response; }
public GroupTaskResponse GetTasks(ClientAuthStruct auth, DateTime dateFrom, DateTime dateTo, int[] states, string guid, int startIndex, int rowsCount) { GroupTaskResponse response = new GroupTaskResponse(); ClientInterface.ArrayOfInt arrayStates = new MWRClientLib.ClientInterface.ArrayOfInt(); arrayStates.AddRange(states); ClientInterface.GroupTaskResponse proxyResp = client.GetTasks(GetAuthData(auth), dateFrom, dateTo, arrayStates, guid, startIndex, rowsCount); response.ErrorCode = proxyResp.ErrorCode; response.ErrorDescription = proxyResp.ErrorDescription; if (proxyResp.Tasks != null && proxyResp.Tasks.Length > 0) { response.Tasks = new TaskStruct[proxyResp.Tasks.Length]; for (int i = 0; i < response.Tasks.Length; i++) { response.Tasks[i] = new TaskStruct(); response.Tasks[i].Active = proxyResp.Tasks[i].Active; response.Tasks[i].DateChecked = proxyResp.Tasks[i].DateChecked; response.Tasks[i].DateCompleted = proxyResp.Tasks[i].DateCompleted; response.Tasks[i].DateRegistered = proxyResp.Tasks[i].DateRegistered; response.Tasks[i].DateSended = proxyResp.Tasks[i].DateSended; response.Tasks[i].DateToExecute = proxyResp.Tasks[i].DateToExecute; response.Tasks[i].Guid = proxyResp.Tasks[i].Guid; response.Tasks[i].ID = proxyResp.Tasks[i].ID; response.Tasks[i].Machine = proxyResp.Tasks[i].Machine; response.Tasks[i].Name = proxyResp.Tasks[i].Name; response.Tasks[i].State = proxyResp.Tasks[i].State; response.Tasks[i].User = proxyResp.Tasks[i].User; response.Tasks[i].XmlRequest = proxyResp.Tasks[i].XmlRequest; response.Tasks[i].XmlResponse = proxyResp.Tasks[i].XmlResponse; response.Tasks[i].ErrorDetails = proxyResp.Tasks[i].ErrorDetails; } } response.TotalCount = proxyResp.TotalCount; return response; }