protected VkMethodVisitor(T data, ExecuteEnvironment env) { this.Data = data; this.Environment = env; this.ObjectsVisitor = this.CreateVkObjectVisitor(); this.boardVisitor = this.CreateBoardMethodsVisitor(); this.friendVisitor = this.CreateFriendMethodsVisitor(); this.groupVisitor = this.CreateGroupMethodsVisitor(); this.messageVisitor = this.CreateMessageMethodsVisitor(); this.photoVisitor = this.CreatePhotoMethodsVisitor(); this.userVisitor = this.CreateUserMethodsVisitor(); }
protected override Dictionary <String, String> PrepareRequestParameters(IVkMethod method, ExecuteEnvironment environment) { var properties = method.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); var parameters = new Dictionary <String, String>(); foreach (var propertyInfo in properties) { var attr = propertyInfo.GetCustomAttributes(typeof(VkParamAttribute), true); if (attr.Length <= 0) { continue; } var mpa = (VkParamAttribute)attr[0]; if (propertyInfo.PropertyType == typeof(Boolean?)) { var boolValue = (bool?)propertyInfo.GetValue(method, null); if (boolValue.HasValue) { parameters.Add(mpa.Name, GetBoolValue(boolValue.Value)); } } if (propertyInfo.PropertyType == typeof(String)) { var stringValue = (String)propertyInfo.GetValue(method, null); if (stringValue != null) { parameters.Add(mpa.Name, stringValue); } } if (propertyInfo.PropertyType == typeof(List <String>)) { var listValue = (List <String>)propertyInfo.GetValue(method, null); if (listValue != null && listValue.Count > 0) { parameters.Add(mpa.Name, GetStringList(listValue)); } } if (propertyInfo.PropertyType == typeof(Int32?)) { var intValue = (Int32?)propertyInfo.GetValue(method, null); if (intValue.HasValue) { parameters.Add(mpa.Name, GetInt32(intValue.Value, environment.Culture)); } } if (propertyInfo.PropertyType == typeof(UInt32?)) { var intValue = (UInt32?)propertyInfo.GetValue(method, null); if (intValue.HasValue) { parameters.Add(mpa.Name, GetUInt32(intValue.Value, environment.Culture)); } } if (propertyInfo.PropertyType == typeof(DateTime?)) { var dateTimeValue = (DateTime?)propertyInfo.GetValue(method, null); if (dateTimeValue.HasValue) { parameters.Add(mpa.Name, GetDateTime(dateTimeValue.Value, environment.Culture)); } } if (propertyInfo.PropertyType == typeof(Guid?)) { var guidValue = (Guid?)propertyInfo.GetValue(method, null); if (guidValue.HasValue) { parameters.Add(mpa.Name, GetGuid(guidValue.Value, environment.Culture)); } } if (propertyInfo.PropertyType == typeof(Double?)) { var doubleValue = (Double?)propertyInfo.GetValue(method, null); if (doubleValue.HasValue) { parameters.Add(mpa.Name, GetDouble(doubleValue.Value, environment.Culture)); } } } if (environment.PrepareParametersExtension != null) { environment.PrepareParametersExtension(parameters); environment.PrepareParametersExtension = null; } return(parameters); }
protected abstract VkMethodVisitor <JToken> CreateMethodVisitor(TTransportData data, ExecuteEnvironment environment);
protected TOutput ParseResponse <TOutput>(TTransportData response, IVkMethod <TOutput> method, ExecuteEnvironment environment) { var methodVisitor = this.CreateMethodVisitor(response, environment); var error = methodVisitor.GetError(); if (error != null) { throw new Exception($"An error with code {error.ErrorCode} was occured during method {method.Name} execution. Error text: {error.ErrorMsg}"); } return(method.Accept(methodVisitor, methodVisitor.Data)); }
protected abstract TTransportData TransmitRequest(TTransportData request, ExecuteEnvironment ee);
protected abstract TTransportData CreateRequest(Dictionary <String, String> requestParameters, IVkMethod method, ExecuteEnvironment ee);
protected abstract Dictionary <String, String> PrepareRequestParameters(IVkMethod method, ExecuteEnvironment environment);