internal override string Execute(string[] parameters) { int oldFolderID; int newFolderID; int userID; List <int> channelIDList; string error = Helper.GetIDsMove(_session, parameters, out userID, out oldFolderID, out newFolderID, out channelIDList); if (error != "1") { return(error); } BLClient client = null; try { client = new BLClient(); client.MovePCChannels(userID, oldFolderID, newFolderID, channelIDList); } catch (Exception ex) { return(ErrorWrapper.SendError(ex.Message)); } finally { client.Dispose(); } return("1"); }
internal override string Execute(System.Collections.Specialized.NameValueCollection commandParameters) { int userID; if (!Helper.TryGetUserID(_session, out userID)) { return(String.Empty); } BLClient client = null; List <ChannelSimple> channels = null; try { client = new BLClient(); channels = client.GetChannelsAll(userID); } catch (Exception exception) { return(ErrorWrapper.SendError(exception.Message)); } finally { if (client != null) { client.Dispose(); } } return(Flatten(channels)); }
internal override string Execute(NameValueCollection commandParameters) { int channelID; string error = ValidateIntParameter(commandParameters, "channelId", out channelID); if (error != string.Empty) { return(error); } Channel channel = null; BLClient client = null; try { client = new BLClient(); channel = client.GetChannelDetailsSimple(channelID); } catch (Exception exception) { return(ErrorWrapper.SendError(exception.Message)); } finally { if (client != null) { client.Dispose(); } } return(Flatten(channel)); }
internal override string Execute(NameValueCollection commandParameters) { int userID; if (!Helper.TryGetUserID(_session, out userID)) { return(String.Empty); } List <List <CreateContentGenericFolder> > folderList; BLClient client = null; try { client = new BLClient(); folderList = client.GetFolders(userID); } catch (Exception exception) { return(ErrorWrapper.SendError(exception.Message)); } finally { if (client != null) { client.Dispose(); } } return(Flatten(folderList)); }
internal override string Execute(string[] parameters) { int folderID; int userID; List <int> contentIDList; string error = Helper.GetIDs(_session, parameters, out userID, out folderID, out contentIDList); if (error != "1") { return(error); } BLClient client = null; try { client = new BLClient(); client.AddSlideContent(userID, folderID, contentIDList); } catch (Exception ex) { return(ErrorWrapper.SendError(ex.Message)); } finally { client.Dispose(); } return("1"); }
public async Task InvokeAsync(HttpContext httpContext) { ErrorWrapper Wrapper = new ErrorWrapper(); ErrorResponse errorResponse = new ErrorResponse(); Error error = new Error(); httpContext.Response.ContentType = MediaTypeNames.Application.Json; await _next(httpContext); switch (httpContext.Response.StatusCode) { case StatusCodes.Status415UnsupportedMediaType: error = new Error("415", "Hi I am a 415 HTTP Error :)"); errorResponse.errors.Add(error); Wrapper.response = errorResponse; await httpContext.Response.WriteAsync(Wrapper.ToString()); Wrapper.response.errors.Clear(); break; case StatusCodes.Status401Unauthorized: error = new Error("401", "Hi I am a 401 HTTP Error :)"); errorResponse.errors.Add(error); Wrapper.response = errorResponse; await httpContext.Response.WriteAsync(Wrapper.ToString()); Wrapper.response.errors.Clear(); break; } }
private void dgvErrors_SelectionChanged(object sender, EventArgs e) { if (dgvErrors.SelectedRows.Count == 1) { ErrorWrapper ew = (ErrorWrapper)dgvErrors.SelectedRows[0].DataBoundItem; string error = ew.Error.ErrorDescription + "\r\n" + "\r\n"; error = error + "User: "******" (" + ew.Error.User.FirstName + " " + ew.Error.User.LastName + ")" + "\r\n"; error = error + "Host: " + ew.Error.Host + "\r\n"; error = error + "OS: " + ew.Error.OS + "\r\n"; error = error + "Version: " + ew.Error.Version + "\r\n"; error = error + "Time: " + ew.Error.ErrorTime + "\r\n"; error = error + "Class: " + ew.Error.ClassName + "\r\n"; error = error + "Method: " + ew.Error.Method + "\r\n"; error = error + "Place: " + ew.Error.Place; error = error + "\r\n" + "\r\n"; error = error + "---------------------------ERROR---------------------------" + "\r\n"; error = error + ew.Error.LongError + "\r\n"; error = error + "\r\n" + "\r\n"; error = error + "------------------------STACK TRACE------------------------" + "\r\n"; error = error + ew.Error.StackInfo; txtErrorInfo.Text = error; } else { txtErrorInfo.Text = ""; } }
public async Task <ResponseBrands> GetBrandsCustomer(int iysCode, CancellationToken cancellationToken = default) { var brandModels = new List <BrandModel>(); var errorWrapper = new ErrorWrapper { List = new List <IysError>() }; var response = await RestClientRequest((List <BrandModel>) null, $"/sps/{iysCode}/brands", Method.GET, cancellationToken : cancellationToken); if (response.StatusCode == HttpStatusCode.OK) { brandModels = JsonConvert.DeserializeObject <List <BrandModel> >(response.Content); } else { await Console.Out.WriteLineAsync(response.Content); errorWrapper = JsonConvert.DeserializeObject <ErrorWrapper>(response.Content); } return(new ResponseBrands { List = brandModels, Errors = errorWrapper }); }
internal override string Execute(string[] parameters) { int userID; if (!Helper.TryGetUserID(_session, out userID)) { return(String.Empty); } if (parameters.Length < 2) { return(ErrorWrapper.SendError("Command parameters missing.")); } BLClient client = null; int pcID; try { client = new BLClient(); pcID = client.AddPC(userID, parameters[1]); } catch (Exception ex) { return(ErrorWrapper.SendError(ex.Message)); } finally { client.Dispose(); } return(pcID.ToString()); }
/// <summary> /// Gets the appropriate command processor with the specified type /// </summary> /// <param name="commandType">Type of the processor to instantiate</param> /// <param name="context">HttpContext object that requested this instantiation</param> /// <returns>a CommandProcessor that will perform the requested command action, null if instantiation failed.</returns> protected T GetCommandProcessor <T>(string commandType, HttpContext context) where T : CommandProcessor { Type type = null; T commandProcessor = null; try { type = Type.GetType(commandType); } catch (Exception ex) { context.Response.Write(ErrorWrapper.SendError(ex.Message)); return(null); } try { commandProcessor = (T)(Activator.CreateInstance(type, new object[] { context.Session })); } catch (Exception ex) { context.Response.Write(ErrorWrapper.SendError(ex.Message)); return(null); } return(commandProcessor); }
public void Test_Error_Is_Not_Convertible(Type targetType) { Assert.Throws <COMException>(() => { var err = new ErrorWrapper(1); VariantConverter.ChangeType(err, targetType); }); }
/// <summary> /// 生成自定义异常消息 /// </summary> /// <param name="ex">异常对象</param> /// <returns>异常字符串文本</returns> private static void ExceptionHandler(Exception ex) { string error = ErrorWrapper.GetExceptionDesc(ex); ErrorWrapper errorWrapper = ErrorWrapper.Instance; errorWrapper.AppendError(error); errorWrapper.ShowDialog(); }
public virtual void ProcessRequest(HttpContext context) { context.Response.Clear(); ChannelCommandConfigurationSection commandSection = (ChannelCommandConfigurationSection)System.Configuration.ConfigurationManager.GetSection("channelCommandSet"); // is this a GET request if (context.Request.QueryString["command"] != null) { string commandName = context.Request.QueryString["command"]; if (commandSection.ChannelCommands[commandName] == null) { context.Response.Write(ErrorWrapper.SendError("Invalid command.")); return; } string commandType = commandSection.ChannelCommands[commandName].Type; GetCommandProcessor getCommandProcessor = GetCommandProcessor <GetCommandProcessor>(commandType, context); if (getCommandProcessor != null) { context.Response.Write(getCommandProcessor.Execute(context.Request.QueryString)); } } // is this a POST request else if (context.Request.Form["command"] != null) { string[] postVars = context.Request.Form["command"].Split(new string[] { ",," }, StringSplitOptions.None); if (postVars.Length < 2) { context.Response.Write(ErrorWrapper.SendError("Not enough parameters.")); return; } if (commandSection.ChannelCommands[postVars[0]] == null) { context.Response.Write(ErrorWrapper.SendError("Invalid command.")); return; } string commandType = commandSection.ChannelCommands[postVars[0]].Type; PostCommandProcessor postCommandProcessor = GetCommandProcessor <PostCommandProcessor>(commandType, context); if (postCommandProcessor != null) { context.Response.Write(postCommandProcessor.Execute(postVars)); } } else { context.Response.Write(ErrorWrapper.SendError("Command parameter not specified.")); } }
public override void Delete() { if (dgvErrors.SelectedRows.Count == 1) { ErrorWrapper ew = (ErrorWrapper)dgvErrors.SelectedRows[0].DataBoundItem; Crud.Delete(ew.Error); RefreshData(); } }
/// <summary> /// Validates if a Query String parameter exists in the Query String /// </summary> /// <param name="commandParameters">the Query String to check</param> /// <param name="parameter">the parameter to validate</param> /// <returns>An empty string if the parameter exists, an error message otherwise</returns> protected string ValidateParameterExists(NameValueCollection commandParameters, string parameter) { if (commandParameters[parameter] == null) { return(ErrorWrapper.SendError("Parameter " + parameter + " not supplied")); } return(String.Empty); }
private void ErrorWrapper() { const int E_NOTIMPL = unchecked ((int)0X80004001); var val = new ErrorWrapper(E_NOTIMPL); // Get and set property obj.Variant_Property = val; Assert.AreEqual(val.ErrorCode, obj.Variant_Property); }
private static ErrorWrapper <TRes> WrapperFunc <T1, T2, TRes>(Func <T1, T2, TRes> f, T1 p1, T2 p2) { try { return(ErrorWrapper.New(f(p1, p2))); } catch (Exception e) { // Handle exceptions return(new ErrorWrapper <TRes>(e)); } }
private static ErrorWrapper <MyVoid> WrapperAction <T1, T2>(Action <T1, T2> f, T1 p1, T2 p2) { try { f(p1, p2); return(ErrorWrapper.New(default(MyVoid))); } catch (Exception e) { // Handle exceptions return(new ErrorWrapper <MyVoid>(e)); } }
public override void RefreshData() { IList <Models.Core.Error> mErrors = Crud.GetAll <Models.Core.Error>(); IList <ErrorWrapper> errors = new List <ErrorWrapper>(); foreach (Models.Core.Error error in mErrors) { ErrorWrapper err = new ErrorWrapper(); err.Error = error; errors.Add(err); } dgvErrors.DataSource = errors; }
private decimal?PartnerLoadInternal(PartnerWrapper item, ICollection <AddressBook> wmsaddresscol, List <ErrorWrapper> retMessage, IBaseManager <Partner> mgr, IUnitOfWork uow) { var partner = new Partner(); partner = MapTo(item, partner); if (string.IsNullOrEmpty(partner.PartnerName) && string.IsNullOrEmpty(partner.PartnerFullName)) { const string message = "Партнер не создан. Наименование партнера не может быть пустым."; retMessage.Add(new ErrorWrapper { ERRORCODE = MessageHelper.WarningCode.ToString(), ERRORMESSAGE = message }); Log.Info(message); return(null); } AddOrUpdatePartnerAddress(partner, wmsaddresscol, item.DONOTUPDATELEGALADDRESS > 0); SetXmlIgnore(partner, false); mgr.Insert(ref partner); Log.InfoFormat("Загружен партнер «{0}» с ID = {1}", item.PARTNERNAME, partner.PartnerId); var ewr = new ErrorWrapper { ERRORCODE = MessageHelper.SuccessCode.ToString(), ERRORMESSAGE = string.Format("Загружен партнер «{0}»", item.PARTNERNAME) }; retMessage.Add(ewr); if (item.GPVs != null) { using (var gpvMgr = IoC.Instance.Resolve <IBaseManager <PartnerGpv> >()) { gpvMgr.SetUnitOfWork(uow); foreach (var gpvObj in item.GPVs) { var gpv = new PartnerGpv(); gpv = MapTo(gpvObj, gpv); gpv.GParamValKey = partner.PartnerId.To <decimal>(); SetXmlIgnore(gpv, false); gpvMgr.Insert(ref gpv); Log.InfoFormat("Загружена GPV {0} (ID = {1})", gpv.GlobalParamCode_R, gpv.GParamID); } } } return(partner.PartnerId); }
internal override string Execute(string[] parameters) { int userID; int pcID; int channelID; int channelWeighting; if (!Helper.TryGetUserID(_session, out userID)) { return(String.Empty); } if (parameters.Length < 4) { return(ErrorWrapper.SendError("Command parameters missing.")); } if (!int.TryParse(parameters[1], out pcID)) { return(ErrorWrapper.SendError("Cannot parse PC ID.")); } if (!int.TryParse(parameters[2], out channelID)) { return(ErrorWrapper.SendError("Cannot parse Channel ID.")); } if (!int.TryParse(parameters[3], out channelWeighting)) { return(ErrorWrapper.SendError("Cannot parse Channel Weighting.")); } BLClient client = null; try { client = new BLClient(); client.EditChannelWeighting(userID, pcID, channelID, channelWeighting); } catch (Exception ex) { return(ErrorWrapper.SendError(ex.Message)); } finally { client.Dispose(); } return("1"); }
internal override string Execute(string[] parameters) { int slideFolderID; int slideID; int userID; if (!Helper.TryGetUserID(_session, out userID)) { return(String.Empty); } if (parameters.Length < 3) { return(ErrorWrapper.SendError("Command parameters missing.")); } if (!int.TryParse(parameters[1], out slideFolderID)) { return(ErrorWrapper.SendError("Cannot parse Slide Folder ID")); } if (!int.TryParse(parameters[2], out slideID)) { return(ErrorWrapper.SendError("Cannot parse Slide ID")); } BLClient client = null; bool bCanRemove = false; try { client = new BLClient(); bCanRemove = client.RemoveSlideContent(userID, slideFolderID, slideID); } catch (Exception ex) { return(ErrorWrapper.SendError(ex.Message)); } finally { client.Dispose(); } if (!bCanRemove) { return("-1"); } return("1"); }
internal override string Execute(string[] parameters) { int userID; int assetContentFolderID; int assetContentID; if (!Helper.TryGetUserID(_session, out userID)) { return(String.Empty); } if (parameters.Length < 3) { return(ErrorWrapper.SendError("Command parameters missing.")); } if (!int.TryParse(parameters[1], out assetContentFolderID)) { return(ErrorWrapper.SendError("Cannot parse raw content folder ID.")); } if (!int.TryParse(parameters[2], out assetContentID)) { return(ErrorWrapper.SendError("Cannot parse raw content ID.")); } BLClient client = null; int fileLength = -1; try { client = new BLClient(); fileLength = client.RemoveAssetContent(userID, assetContentFolderID, assetContentID); } catch (Exception ex) { return(ErrorWrapper.SendError(ex.Message)); } finally { client.Dispose(); } if (fileLength != -1) { ((User)_session["User"]).UsedBytes -= fileLength; } return("1"); }
private string GetSortChannelsByFromConfig(string sortByValue, out string sortByEnumString) { QueryStringParameterValueConfiguration queryStringParameterValueConfiguration = (QueryStringParameterValueConfiguration)System.Configuration.ConfigurationManager.GetSection("queryStringParameterGroup/enumQueryStringParameterSet"); if (queryStringParameterValueConfiguration.QueryStringParameters[sortByValue] == null) { sortByEnumString = String.Empty; return(ErrorWrapper.SendError("Enum parameter " + sortByValue + " does not exist.")); } sortByEnumString = queryStringParameterValueConfiguration.QueryStringParameters[sortByValue].Value; return(String.Empty); }
private string TryParseSortChannelsBy(Type type, string sortBy, out SortChannelsBy sortChannelBy) { try { sortChannelBy = (SortChannelsBy)Enum.Parse(type, sortBy); } catch { sortChannelBy = SortChannelsBy.Alphabetical; return(ErrorWrapper.SendError(sortBy + " cannot be parsed.")); } return(String.Empty); }
internal override string Execute(string[] parameters) { // is there a command name, username, password, firstname, lastname? if (parameters.Length < 5) { return(ErrorWrapper.SendError("Command parameters missing.")); } if (!emailPattern.IsMatch(parameters[1])) { return("-3"); } BLClient client = null; User user = null; foreach (string parameter in parameters) { if (parameter.Trim() == String.Empty) { return("-1"); } } // call WCF BLL layer try { client = new BLClient(); user = client.Signup(parameters[1], parameters[2], parameters[3], parameters[4]); } catch (Exception exception) { _logger.WriteMessage(exception.ToString()); return(ErrorWrapper.SendError(exception.Message)); } finally { client.Dispose(); } if (user == null) { return("-2"); } _session.Add("User", user); return("1"); }
/// <summary> /// Checks whether a given string is "0" or "1", else returns an error message /// </summary> /// <param name="intSwitchParam">the parameter to check</param> /// <returns>An empty string if the intSwitchParam is "0" or "1", an error message otherwise</returns> protected string ValidateIntSwitchParameter(string intSwitchParam) { switch (intSwitchParam) { case "1": goto case "0"; case "0": return(String.Empty); default: return(ErrorWrapper.SendError("Cannot parse int switch")); } }
internal override string Execute(string[] parameters) { // is there a command name, username, password and a "remember me" setting? if (parameters.Length < 3) { return(ErrorWrapper.SendError("Command parameters missing.")); } BLClient client = null; User user = null; // call WCF BLL layer try { client = new BLClient(); user = client.Login(parameters[1], parameters[2]); } catch (Exception exception) { return(ErrorWrapper.SendError(exception.Message)); } finally { client.Dispose(); } if (user != null) { _session.Add("User", user); // in case user was poking around the Download page while logged off, we need to clear // log-off PC Creation operation parameters _session.Remove("PcProfileToken"); if (string.IsNullOrEmpty(user.FirstName)) { return("-"); } return(user.FirstName); } return("0"); }
private string GetIDs(string[] parameters, out int pcID, out List <int> contentIDList) { contentIDList = null; pcID = -1; if (parameters.Length < 3) { return(ErrorWrapper.SendError("Command parameters missing.")); } if (!int.TryParse(parameters[1], out pcID)) { return(ErrorWrapper.SendError("Can't parse PC ID")); } return(Helper.GetContentIDs(parameters[2], out contentIDList)); }
/// <summary> /// Checks whether a given int exists in a Query string and then extracts it /// </summary> /// <param name="commandParameters">the Query String to check</param> /// <param name="parameter">the parameter to validate and extract</param> /// <param name="numerical">the reference of the int to extract the parameter to</param> /// <returns>An empty string if the parameter exists, an error message otherwise</returns> protected string ValidateIntParameter(NameValueCollection commandParameters, string parameter, out int numerical) { string error = ValidateParameterExists(commandParameters, parameter); if (error != String.Empty) { numerical = -1; return(error); } if (!int.TryParse(commandParameters[parameter], out numerical)) { return(ErrorWrapper.SendError("invalid parameter:" + parameter)); } return(String.Empty); }
// Test the ErrorWrapper class. public void TestErrorWrapper() { ErrorWrapper ew; // Test the (Exception) constructor, which will throw // "NotImplementedException" because we don't support COM. try { ew = new ErrorWrapper(new Exception()); Fail("ErrorWrapper (1)"); } catch(NotImplementedException) { // Success. } // Test the (int) constructor. ew = new ErrorWrapper(123); AssertEquals("ErrorWrapper (2)", 123, ew.ErrorCode); // Test the (Object) constructor. ew = new ErrorWrapper((Object)(6123)); AssertEquals("ErrorWrapper (3)", 6123, ew.ErrorCode); // Test the failure cases of the (Object) constructor. try { ew = new ErrorWrapper((Object)null); Fail("ErrorWrapper (4)"); } catch(ArgumentException) { // Success. } try { ew = new ErrorWrapper((Object)"foo"); Fail("ErrorWrapper (5)"); } catch(ArgumentException) { // Success. } }