コード例 #1
0
 public object FilterResponce(object responce, ApiContext context)
 {
     if (responce != null && !context.FromCache)
     {
         ISmartList smartList = null;
         var type = responce.GetType();
         if (responce is ISmartList)
         {
             smartList = responce as ISmartList;
         }
         else if (Utils.Binder.IsCollection(type) && !typeof(IDictionary).IsAssignableFrom(type))
         {
             try
             {
                 var elementType = Utils.Binder.GetCollectionType(type);
                 var smartListType = SmartListFactory.GetSmartListType().MakeGenericType(elementType);
                 smartList = Activator.CreateInstance(smartListType, (IEnumerable)responce) as ISmartList;
             }
             catch (Exception)
             {
                 
             }
         }
         if (smartList != null)
         {
             return TransformList(context, smartList);
         }
     }
     return responce;
 }
コード例 #2
0
 public override void PreMethodCall(Api.Interfaces.IApiMethodCall method, ASC.Api.Impl.ApiContext context, System.Collections.Generic.IEnumerable <object> arguments)
 {
     //Log method call
     TryLog(LogEntry.Actions.BeforeCall, method, context, null);
     base.PreMethodCall(method, context, arguments);
     Sw.Start();
 }
コード例 #3
0
 public static EventMessage Create(ApiContext apiContext, string initiator, MessageAction action, params string[] description)
 {
     try
     {
         var request = apiContext.RequestContext.HttpContext.Request;
         return new EventMessage
             {
                 IP = request.Headers["X-Forwarded-For"] ?? request.UserHostAddress,
                 Initiator = initiator,
                 Browser = string.Format("{0} {1}", request.Browser.Browser, request.Browser.Version),
                 Mobile = request.Browser.IsMobileDevice,
                 Platform = request.Browser.Platform,
                 Date = DateTime.UtcNow,
                 TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId,
                 UserId = SecurityContext.CurrentAccount.ID,
                 Page = request.UrlReferrer == null
                            ? string.Empty :
                            request.UrlReferrer.ToString(),
                 Action = action,
                 Description = description
             };
     }
     catch(Exception ex)
     {
         log.Error(string.Format("Error while parse Api Context for \"{0}\" type of event: {1}", action, ex));
         return null;
     }
 }
コード例 #4
0
 public virtual string BuildCacheKeyForMethodCall(IApiMethodCall apiMethodCall, IEnumerable<object> callArgs, ApiContext context)
 {
     return string.Format("{0}.{1}({2}),{3}:{4}",
                          apiMethodCall.MethodCall.DeclaringType.FullName,
                          apiMethodCall.MethodCall.Name,
                          string.Join(",", callArgs.Select(x => x.GetHashCode().ToString()).ToArray()),
                          apiMethodCall.MethodCall.DeclaringType.Assembly.FullName,context);
 }
コード例 #5
0
 /// <summary>
 /// </summary>
 /// <param name="context"></param>
 /// <param name="fileStorageService"></param>
 public DocumentsApi(ApiContext context, IFileStorageService fileStorageService)
 {
     _context = context;
     _fileStorageService = fileStorageService;
     if (!FilesIntegration.IsRegisteredFileSecurityProvider("crm", "crm_common"))
     {
         FilesIntegration.RegisterFileSecurityProvider("crm", "crm_common", new FileSecurityProvider());
     }
 }
コード例 #6
0
 public override void PostMethodCall(IApiMethodCall method, ApiContext context, object methodResponce)
 {
     try
     {
         context.RequestContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", "*");
     }
     catch (Exception err)
     {
         log.Warn(err.ToString());
     }
 }
コード例 #7
0
        public override void PreMethodCall(IApiMethodCall method, ApiContext context, IEnumerable<object> arguments)
        {
            var header = context.RequestContext.HttpContext.Request.Headers["Payment-Info"];
            var flag = true;
            if (string.IsNullOrEmpty(header) || (bool.TryParse(header, out flag) && flag))
            {
                var tenant = CoreContext.TenantManager.GetCurrentTenant(false);
                if (tenant == null)
                {
                    var hostname = string.Empty;
                    try
                    {
                        hostname = HttpContext.Current.Request.GetUrlRewriter().Host;
                    }
                    catch { }
                    throw new System.Security.SecurityException(string.Format("Portal {0} not found.", hostname));
                }

                var tenantStatus = tenant.Status;
                if (tenantStatus == TenantStatus.Transfering)
                {
                    context.RequestContext.HttpContext.Response.StatusCode = 503;
                    context.RequestContext.HttpContext.Response.StatusDescription = "Service Unavailable";
                    log.Warn("Portal {0} is transfering to another region", context.RequestContext.HttpContext.Request.Url);
                }

                var tariff = CoreContext.PaymentManager.GetTariff(tenant.TenantId);
                if (tenantStatus != TenantStatus.Active || tariff.State == TariffState.NotPaid)
                {
                    context.RequestContext.HttpContext.Response.StatusCode = 402;
                    context.RequestContext.HttpContext.Response.StatusDescription = "Payment Required.";
                    log.Warn("Payment Required {0}.", context.RequestContext.HttpContext.Request.Url);
                }
            }

            if (!SecurityContext.IsAuthenticated) return;

            var pid = FindProduct(method);
            if (pid != Guid.Empty)
            {
                if (CallContext.GetData("asc.web.product_id") == null)
                {
                    CallContext.SetData("asc.web.product_id", pid);
                }
                if (!WebItemSecurity.IsAvailableForUser(pid.ToString(), SecurityContext.CurrentAccount.ID))
                {
                    context.RequestContext.HttpContext.Response.StatusCode = 403;
                    context.RequestContext.HttpContext.Response.StatusDescription = "Access denied.";
                    log.Warn("Product {0} denied for user {1}", method.Name, SecurityContext.CurrentAccount);
                }
            }
        }
コード例 #8
0
ファイル: DocumentsApi.cs プロジェクト: ridhouan/teamlab.v6.5
        /// <summary>
        /// </summary>
        /// <param name="context"></param>
        /// <param name="fileStorageService"></param>
        public DocumentsApi(ApiContext context, IFileStorageService fileStorageService)
        {
            _context = context;
            _fileStorageService = fileStorageService;
            //TODO: Why not to move this code to DAO???
            if (!DbRegistry.IsDatabaseRegistered(FileConstant.DatabaseId))
            {
                DbRegistry.RegisterDatabase(FileConstant.DatabaseId,
                                            WebConfigurationManager.ConnectionStrings[FileConstant.DatabaseId]);
            }

            if (!FilesIntegration.IsRegisteredFileSecurityProvider("crm", "crm_common"))
                FilesIntegration.RegisterFileSecurityProvider("crm", "crm_common", new FileSecurityProvider());

        }
コード例 #9
0
        public object InvokeMethod(IApiMethodCall methodToCall, ApiContext apicontext)
        {
            if (apicontext == null) throw new ArgumentNullException("apicontext");

            if (methodToCall != null)
            {
                var context = apicontext.RequestContext;

                Log.Debug("Method to call={0}", methodToCall);
                object instance = _container.Resolve(methodToCall.ApiClassType, new DependencyOverride(typeof(ApiContext), apicontext));

                //try convert params
                var callArg = ArgumentBuilder.BuildCallingArguments(context, methodToCall);
                if (_paramInspectors.Any())
                {
                    callArg = _paramInspectors.Aggregate(callArg,
                                                   (current, apiParamInspector) =>
                                                   apiParamInspector.InspectParams(current));
                }

                Log.Debug("Arguments count: {0}", callArg == null ? "empty" : callArg.Count().ToString());


                try
                {
                    //Pre call filter
                    methodToCall.Filters.ForEach(x => x.PreMethodCall(methodToCall, apicontext, callArg));
                    if (apicontext.RequestContext.HttpContext.Response.StatusCode != 200)
                    {
                        return new HttpException(apicontext.RequestContext.HttpContext.Response.StatusCode, apicontext.RequestContext.HttpContext.Response.StatusDescription);
                    }

                    object result = _invoker.InvokeMethod(methodToCall, instance, callArg, apicontext);
                    //Post call filter
                    methodToCall.Filters.ForEach(x => x.PostMethodCall(methodToCall, apicontext, result));
                    return result;
                }
                catch (Exception e)
                {
                    methodToCall.Filters.ForEach(x => x.ErrorMethodCall(methodToCall, apicontext, e));
                    throw;
                }
            }
            throw new ApiBadHttpMethodException();
        }
コード例 #10
0
 private static object TransformList(ApiContext context, ISmartList smartList)
 {
     if (context.Count<smartList.Count)
     {
         //We already get more than allowed, so data is not paged
         context.TotalCount = smartList.Count;
     }
     smartList.TakeCount = context.SpecifiedCount;
     smartList.StartIndex = context.StartIndex;
     smartList.IsDescending = context.SortDescending;
     smartList.SortBy = context.SortBy;
     smartList.FilterBy = context.FilterBy;
     smartList.FilterOp = context.FilterOp;
     smartList.FilterValue = context.FilterValues;
     smartList.UpdatedSince = context.UpdatedSince;
     smartList.FilterType = context.FilterToType;
     return smartList.Transform();
 }
コード例 #11
0
 private void TryLog(LogEntry.Actions action, IApiMethodCall method, ApiContext context, Exception exception)
 {
     try
     {
         ThreadContext.Properties["HostAddress"] = context.RequestContext.HttpContext.Request.UserHostAddress;
         ThreadContext.Properties["Referer"] = context.RequestContext.HttpContext.Request.UrlReferrer;
         ThreadContext.Properties["HttpMethod"] = method.HttpMethod;
         ThreadContext.Properties["ApiRoute"] = method.FullPath;
         ThreadContext.Properties["Url"] = context.RequestContext.HttpContext.Request.GetUrlRewriter();
         ThreadContext.Properties["TenantId"] = CoreContext.TenantManager.GetCurrentTenant(false).TenantId;
         ThreadContext.Properties["UserId"] = SecurityContext.CurrentAccount.ID;
         ThreadContext.Properties["ExecutionTime"] = Sw.ElapsedMilliseconds;
         ThreadContext.Properties["Error"] = exception;
         ThreadContext.Properties["Action"] = action;
         _loger.Debug("log");
     }
     catch
     {
     }
 }
コード例 #12
0
        public override void PreMethodCall(IApiMethodCall method, ApiContext context, IEnumerable<object> arguments)
        {
            if (!SecurityContext.IsAuthenticated) return;

            var pid = FindProduct(method.Name);
            if (pid != Guid.Empty)
            {
                if (CallContext.GetData("asc.web.product_id") == null)
                {
                    CallContext.SetData("asc.web.product_id", pid);
                }
                if (!WebItemSecurity.IsAvailableForUser(pid.ToString(), SecurityContext.CurrentAccount.ID))
                {
                    context.RequestContext.HttpContext.Response.StatusCode = 403;
                    context.RequestContext.HttpContext.Response.StatusDescription = "Access denied.";
                    context.RequestContext.HttpContext.Response.TrySkipIisCustomErrors = true;
                    throw new System.Security.SecurityException(string.Format("Product {0} denied for user {1}", method.Name, SecurityContext.CurrentAccount));
                }
            }
        }
コード例 #13
0
        private static object TransformList(ApiContext context, ISmartList smartList)
        {
            bool getTotalCount = context.SpecifiedCount < smartList.Count && !context.TotalCount.HasValue;/*We have already more items than needed and no one set totalcount*/

            smartList.TakeCount = context.SpecifiedCount;
            smartList.StartIndex = context.StartIndex;
            smartList.IsDescending = context.SortDescending;
            smartList.SortBy = context.SortBy;
            smartList.FilterBy = context.FilterBy;
            smartList.FilterOp = context.FilterOp;
            smartList.FilterValue = context.FilterValues;
            smartList.UpdatedSince = context.UpdatedSince;
            smartList.FilterType = context.FilterToType;
            var list= smartList.Transform(getTotalCount);
            if (getTotalCount)
            {
                context.TotalCount = smartList.TotalCount;
            }
            return list;
        }
コード例 #14
0
 public static void Send(ApiContext context, MessageAction action, string d1, string d2)
 {
     SendApiMessage(context, null, action, d1, d2);
 }
コード例 #15
0
 public static void Send(ApiContext context, string user, MessageAction action)
 {
     SendApiMessage(context, user, action);
 }
コード例 #16
0
 public static void Send(ApiContext context, MessageAction action)
 {
     SendApiMessage(context, null, action);
 }
コード例 #17
0
        private static void SendApiMessage(ApiContext context, string loginName, MessageAction action, params string[] description)
        {
            if (sender == null) return;

            if (context == null)
            {
                log.Debug(string.Format("Empty Api Context for \"{0}\" type of event", action));
                return;
            }

            var message = MessageFactory.Create(context, loginName, action, description);
            if (!MessagePolicy.Check(message)) return;

            sender.Send(message);
        }
コード例 #18
0
 public static void Send(ApiContext context, MessageAction action, string d1, string d2, IEnumerable<string> d3)
 {
     SendApiMessage(context, null, action, d1, d2, string.Join(", ", d3));
 }
コード例 #19
0
ファイル: PortalApi.cs プロジェクト: vipwan/CommunityServer
 public PortalApi(ApiContext context)
 {
     mobileAppRegistrator = new CachedMobileAppInstallRegistrator(new MobileAppInstallRegistrator());
 }
コード例 #20
0
        ///<summary>
        /// Constructor
        ///</summary>
        ///<param name="context"></param>
        ///<param name="documentsApi">Docs api</param>
        public ProjectApi(ApiContext context, DocumentsApi documentsApi)
        {
            this.documentsApi = documentsApi;

            _context = context;
        }
コード例 #21
0
        public EmployeeWraperFull(UserInfo userInfo, ApiContext context)
            : base(userInfo)
        {
            UserName = userInfo.UserName;
            IsVisitor = userInfo.IsVisitor();
            FirstName = userInfo.FirstName;
            LastName = userInfo.LastName;
            Birthday = (ApiDateTime)userInfo.BirthDate;

            if (userInfo.Sex.HasValue)
                Sex = userInfo.Sex.Value ? "male" : "female";

            Status = userInfo.Status;
            ActivationStatus = userInfo.ActivationStatus;
            Terminated = (ApiDateTime)userInfo.TerminatedDate;

            if (!string.IsNullOrEmpty(userInfo.Department))
                Department = userInfo.Department;

            WorkFrom = (ApiDateTime)userInfo.WorkFromDate;
            Email = userInfo.Email;

            if (!string.IsNullOrEmpty(userInfo.Location))
                Location = userInfo.Location;

            if (!string.IsNullOrEmpty(userInfo.Notes))
                Notes = userInfo.Notes;

            if (!string.IsNullOrEmpty(userInfo.MobilePhone))
                MobilePhone = userInfo.MobilePhone;

            MobilePhoneActivationStatus = userInfo.MobilePhoneActivationStatus;

            if (!string.IsNullOrEmpty(userInfo.CultureName))
                CultureName = userInfo.CultureName;

            FillConacts(userInfo);

            var groups = Core.CoreContext.UserManager.GetUserGroups(userInfo.ID).Select(x => new GroupWrapperSummary(x)).ToList();

            if (groups.Any())
                Groups = groups;

            try
            {
                if (CheckContext(context, "avatarSmall"))
                    AvatarSmall = UserPhotoManager.GetSmallPhotoURL(userInfo.ID);

                if (CheckContext(context, "avatarMedium"))
                    AvatarMedium = UserPhotoManager.GetMediumPhotoURL(userInfo.ID);

                if (CheckContext(context, "avatar"))
                    Avatar = UserPhotoManager.GetBigPhotoURL(userInfo.ID);
            }
            catch (Exception)
            {
            }

            try
            {
                IsOnline = false;
                IsAdmin = userInfo.IsAdmin();

                if (CheckContext(context, "listAdminModules"))
                {
                    var listAdminModules = userInfo.GetListAdminModules();

                    if (listAdminModules.Any())
                        ListAdminModules = listAdminModules;
                }

                IsOwner = userInfo.IsOwner();
            }
            catch (Exception)
            {
            }
        }
コード例 #22
0
ファイル: CRMApi.cs プロジェクト: vipwan/CommunityServer
 ///<summary>
 /// Constructor
 ///</summary>
 ///<param name="context"></param>
 public CRMApi(ApiContext context)
 {
     _context = context;
 }
コード例 #23
0
ファイル: BookmarkApi.cs プロジェクト: ridhouan/teamlab.v6.5
 ///<summary>
 ///</summary>
 ///<param name="context"></param>
 public BookmarkApi(ApiContext context)
 {
     _context = context;
 }
コード例 #24
0
        public void Process(HttpContextBase context)
        {
            //Resolve all here
            ApiResponce = Container.Resolve<IApiStandartResponce>();
            ApiManager = Container.Resolve<IApiManager>();
            RouteContext = new RequestContext(context,RouteData);
            ApiContext = new ApiContext(RouteContext);
            ApiResponce.ApiContext = ApiContext;

            //NOTE: Don't register anything it will be resolved when needed
            //Container.RegisterInstance(ApiContext, new HttpContextLifetimeManager2(context));//Regiter only api context

            Method = ApiManager.GetMethod(((Route)RouteData.Route).Url, context.Request.RequestType);//Set method

            DoProcess(context);
        }
コード例 #25
0
 ///<summary>
 /// Constructor
 ///</summary>
 ///<param name="context"></param>
 public CommunityApi(ApiContext context)
 {
     _context = context;
 }
コード例 #26
0
ファイル: MailApi.cs プロジェクト: Inzaghi2012/teamlab.v7.5
 ///<summary>
 /// Constructor
 ///</summary>
 ///<param name="context"></param>
 public MailApi(ApiContext context)
 {
     _context = context;
 }
コード例 #27
0
 public GroupsApi(ApiContext context)
 {
     _context = context;
 }
コード例 #28
0
ファイル: BlogApi.cs プロジェクト: ridhouan/teamlab.v6.5
 ///<summary>
 /// Constructor
 ///</summary>
 ///<param name="context"></param>
 public BlogApi(ApiContext context)
 {
     _context = context;
 }
コード例 #29
0
ファイル: ForumApi.cs プロジェクト: ridhouan/teamlab.v6.5
 public ForumApi(ApiContext context)
 {
     _context = context;
     ForumSettings.Configure("community");
 }
コード例 #30
0
 public override string BuildCacheKeyForMethodCall(IApiMethodCall apiMethodCall, IEnumerable<object> callArgs, ApiContext context)
 {
     return Core.CoreContext.TenantManager.GetCurrentTenant().TenantId + base.BuildCacheKeyForMethodCall(apiMethodCall,callArgs,context);
 }
コード例 #31
0
 public override void PostMethodCall(IApiMethodCall method, ASC.Api.Impl.ApiContext context, object methodResponce)
 {
     Sw.Stop();
     TryLog(LogEntry.Actions.AfterCall, method, context, null);
     base.PostMethodCall(method, context, methodResponce);
 }
コード例 #32
0
 private static bool CheckContext(ApiContext context, string field)
 {
     return context == null || context.Fields == null ||
            (context.Fields != null && context.Fields.Contains(field));
 }
コード例 #33
0
 public override void ErrorMethodCall(IApiMethodCall method, ASC.Api.Impl.ApiContext context, Exception e)
 {
     Sw.Stop();
     TryLog(LogEntry.Actions.ErrorCall, method, context, e);
     base.ErrorMethodCall(method, context, e);
 }