public async Task<string> GetPageItems(string sourceId, string set, string qexpr, string prevlast)
 {
     JavaScriptSerializer jser = new JavaScriptSerializer();
     dynamic sobj = jser.DeserializeObject(set) as dynamic;
     EntitySetType type;
     if (Enum.TryParse<EntitySetType>(sobj["set"], out type))
     {
         switch (type)
         {
             case EntitySetType.User:
                 {
                     DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion));
                     DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User));
                     var ser3 = new JavaScriptSerializer();
                     System.IO.MemoryStream strm = new System.IO.MemoryStream();
                     byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr);
                     strm.Write(sbf, 0, sbf.Length);
                     strm.Position = 0;
                     var _qexpr = ser1.ReadObject(strm) as QueryExpresion;
                     UserServiceProxy svc = new UserServiceProxy();
                     UserSet _set = new UserSet();
                     _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]);
                     _set.PageSize_ = int.Parse(sobj["pageSize"]);
                     if (sobj.ContainsKey("setFilter"))
                         _set.SetFilter = sobj["setFilter"];
                     User _prevlast = null;
                     if (!string.IsNullOrEmpty(prevlast))
                     {
                         strm = new System.IO.MemoryStream();
                         sbf = System.Text.Encoding.UTF8.GetBytes(prevlast);
                         strm.Write(sbf, 0, sbf.Length);
                         strm.Position = 0;
                         _prevlast = ser2.ReadObject(strm) as User;
                     }
                     var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast);
                     var ar = new List<dynamic>();
                     foreach (var e in result)
                     {
                         ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString });
                     }
                     string json = ser3.Serialize(ar);
                     return json;
                 }
             case EntitySetType.Role:
                 {
                     DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion));
                     DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Role));
                     var ser3 = new JavaScriptSerializer();
                     System.IO.MemoryStream strm = new System.IO.MemoryStream();
                     byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr);
                     strm.Write(sbf, 0, sbf.Length);
                     strm.Position = 0;
                     var _qexpr = ser1.ReadObject(strm) as QueryExpresion;
                     RoleServiceProxy svc = new RoleServiceProxy();
                     RoleSet _set = new RoleSet();
                     _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]);
                     _set.PageSize_ = int.Parse(sobj["pageSize"]);
                     if (sobj.ContainsKey("setFilter"))
                         _set.SetFilter = sobj["setFilter"];
                     Role _prevlast = null;
                     if (!string.IsNullOrEmpty(prevlast))
                     {
                         strm = new System.IO.MemoryStream();
                         sbf = System.Text.Encoding.UTF8.GetBytes(prevlast);
                         strm.Write(sbf, 0, sbf.Length);
                         strm.Position = 0;
                         _prevlast = ser2.ReadObject(strm) as Role;
                     }
                     var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast);
                     var ar = new List<dynamic>();
                     foreach (var e in result)
                     {
                         ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString });
                     }
                     string json = ser3.Serialize(ar);
                     return json;
                 }
             case EntitySetType.MemberNotification:
                 {
                     DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion));
                     DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(MemberNotification));
                     var ser3 = new JavaScriptSerializer();
                     System.IO.MemoryStream strm = new System.IO.MemoryStream();
                     byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr);
                     strm.Write(sbf, 0, sbf.Length);
                     strm.Position = 0;
                     var _qexpr = ser1.ReadObject(strm) as QueryExpresion;
                     MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy();
                     MemberNotificationSet _set = new MemberNotificationSet();
                     _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]);
                     _set.PageSize_ = int.Parse(sobj["pageSize"]);
                     if (sobj.ContainsKey("setFilter"))
                         _set.SetFilter = sobj["setFilter"];
                     MemberNotification _prevlast = null;
                     if (!string.IsNullOrEmpty(prevlast))
                     {
                         strm = new System.IO.MemoryStream();
                         sbf = System.Text.Encoding.UTF8.GetBytes(prevlast);
                         strm.Write(sbf, 0, sbf.Length);
                         strm.Position = 0;
                         _prevlast = ser2.ReadObject(strm) as MemberNotification;
                     }
                     var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast);
                     var ar = new List<dynamic>();
                     foreach (var e in result)
                     {
                         ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString });
                     }
                     string json = ser3.Serialize(ar);
                     return json;
                 }
         }
     }
     return null;
 }
 public static async Task<string> GetNotifications(string set, string qexpr, string prevlast)
 {
     var cntx = Cntx;
     JavaScriptSerializer jser = new JavaScriptSerializer();
     dynamic sobj = jser.DeserializeObject(set) as dynamic;
     DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion));
     DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(MemberNotification));
     var ser3 = new JavaScriptSerializer();
     System.IO.MemoryStream strm = new System.IO.MemoryStream();
     byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr);
     strm.Write(sbf, 0, sbf.Length);
     strm.Position = 0;
     var _qexpr = ser1.ReadObject(strm) as QueryExpresion;
     MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy();
     MemberNotificationSet _set = new MemberNotificationSet();
     _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]);
     _set.PageSize_ = int.Parse(sobj["pageSize"]);
      _set.SetFilter = sobj["setFilter"];
      string usrId = HttpContext.Current.User.Identity.GetUserId();
      if (_set.SetFilter.Contains(usrId))
      {
          // just in case the script was tempered with by clients.
          _set.SetFilter += " && UserRef.ID == \"" + usrId + "\"";
      }
     MemberNotification _prevlast = null;
     if (!string.IsNullOrEmpty(prevlast))
     {
         strm = new System.IO.MemoryStream();
         sbf = System.Text.Encoding.UTF8.GetBytes(prevlast);
         strm.Write(sbf, 0, sbf.Length);
         strm.Position = 0;
         _prevlast = ser2.ReadObject(strm) as MemberNotification;
     }
     var result = (await svc.GetPageItemsAsync(cntx, _set, _qexpr, _prevlast)).ToArray();
     List<dynamic> ar = new List<dynamic>();
     Dictionary<int, MemberNotificationType> dic = new Dictionary<int, MemberNotificationType>();
     foreach (var e in result)
     {
         MemberNotificationType c;
         if (!dic.TryGetValue(e.TypeID, out c))
         {
             c = await svc.MaterializeMemberNotificationTypeRefAsync(cntx, e);
             c.TypeName = MapCategoryName(c);
             dic.Add(e.TypeID, c);
         }
         ar.Add(new
         {
             categ = new { Id = c.ID, name = c.TypeName },
             data = e
         });
     }
     string json = ser3.Serialize(ar);
     return json;
 }
        public async Task <string> GetPageItems(string sourceId, string set, string qexpr, string prevlast)
        {
            JavaScriptSerializer jser = new JavaScriptSerializer();
            dynamic       sobj        = jser.DeserializeObject(set) as dynamic;
            EntitySetType type;

            if (Enum.TryParse <EntitySetType>(sobj["set"], out type))
            {
                switch (type)
                {
                case EntitySetType.User:
                {
                    DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion));
                    DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User));
                    var ser3 = new JavaScriptSerializer();
                    System.IO.MemoryStream strm = new System.IO.MemoryStream();
                    byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr);
                    strm.Write(sbf, 0, sbf.Length);
                    strm.Position = 0;
                    var _qexpr            = ser1.ReadObject(strm) as QueryExpresion;
                    UserServiceProxy svc  = new UserServiceProxy();
                    UserSet          _set = new UserSet();
                    _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]);
                    _set.PageSize_     = int.Parse(sobj["pageSize"]);
                    if (sobj.ContainsKey("setFilter"))
                    {
                        _set.SetFilter = sobj["setFilter"];
                    }
                    User _prevlast = null;
                    if (!string.IsNullOrEmpty(prevlast))
                    {
                        strm = new System.IO.MemoryStream();
                        sbf  = System.Text.Encoding.UTF8.GetBytes(prevlast);
                        strm.Write(sbf, 0, sbf.Length);
                        strm.Position = 0;
                        _prevlast     = ser2.ReadObject(strm) as User;
                    }
                    var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast);

                    var ar = new List <dynamic>();
                    foreach (var e in result)
                    {
                        ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString });
                    }
                    string json = ser3.Serialize(ar);
                    return(json);
                }

                case EntitySetType.Role:
                {
                    DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion));
                    DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Role));
                    var ser3 = new JavaScriptSerializer();
                    System.IO.MemoryStream strm = new System.IO.MemoryStream();
                    byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr);
                    strm.Write(sbf, 0, sbf.Length);
                    strm.Position = 0;
                    var _qexpr            = ser1.ReadObject(strm) as QueryExpresion;
                    RoleServiceProxy svc  = new RoleServiceProxy();
                    RoleSet          _set = new RoleSet();
                    _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]);
                    _set.PageSize_     = int.Parse(sobj["pageSize"]);
                    if (sobj.ContainsKey("setFilter"))
                    {
                        _set.SetFilter = sobj["setFilter"];
                    }
                    Role _prevlast = null;
                    if (!string.IsNullOrEmpty(prevlast))
                    {
                        strm = new System.IO.MemoryStream();
                        sbf  = System.Text.Encoding.UTF8.GetBytes(prevlast);
                        strm.Write(sbf, 0, sbf.Length);
                        strm.Position = 0;
                        _prevlast     = ser2.ReadObject(strm) as Role;
                    }
                    var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast);

                    var ar = new List <dynamic>();
                    foreach (var e in result)
                    {
                        ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString });
                    }
                    string json = ser3.Serialize(ar);
                    return(json);
                }

                case EntitySetType.MemberNotification:
                {
                    DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion));
                    DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(MemberNotification));
                    var ser3 = new JavaScriptSerializer();
                    System.IO.MemoryStream strm = new System.IO.MemoryStream();
                    byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr);
                    strm.Write(sbf, 0, sbf.Length);
                    strm.Position = 0;
                    var _qexpr = ser1.ReadObject(strm) as QueryExpresion;
                    MemberNotificationServiceProxy svc  = new MemberNotificationServiceProxy();
                    MemberNotificationSet          _set = new MemberNotificationSet();
                    _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]);
                    _set.PageSize_     = int.Parse(sobj["pageSize"]);
                    if (sobj.ContainsKey("setFilter"))
                    {
                        _set.SetFilter = sobj["setFilter"];
                    }
                    MemberNotification _prevlast = null;
                    if (!string.IsNullOrEmpty(prevlast))
                    {
                        strm = new System.IO.MemoryStream();
                        sbf  = System.Text.Encoding.UTF8.GetBytes(prevlast);
                        strm.Write(sbf, 0, sbf.Length);
                        strm.Position = 0;
                        _prevlast     = ser2.ReadObject(strm) as MemberNotification;
                    }
                    var result = await svc.GetPageItemsAsync(ApplicationContext.ClientContext, _set, _qexpr, _prevlast);

                    var ar = new List <dynamic>();
                    foreach (var e in result)
                    {
                        ar.Add(new { Id = e.ID.ToString(), DistinctString = e.DistinctString });
                    }
                    string json = ser3.Serialize(ar);
                    return(json);
                }
                }
            }
            return(null);
        }
Example #4
0
        public static async Task <string> GetNotifications(string set, string qexpr, string prevlast)
        {
            var cntx = Cntx;
            JavaScriptSerializer jser = new JavaScriptSerializer();
            dynamic sobj = jser.DeserializeObject(set) as dynamic;
            DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion));
            DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(MemberNotification));
            var ser3 = new JavaScriptSerializer();

            System.IO.MemoryStream strm = new System.IO.MemoryStream();
            byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr);
            strm.Write(sbf, 0, sbf.Length);
            strm.Position = 0;
            var _qexpr = ser1.ReadObject(strm) as QueryExpresion;
            MemberNotificationServiceProxy svc  = new MemberNotificationServiceProxy();
            MemberNotificationSet          _set = new MemberNotificationSet();

            _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]);
            _set.PageSize_     = int.Parse(sobj["pageSize"]);
            _set.SetFilter     = sobj["setFilter"];
            string usrId = HttpContext.Current.User.Identity.GetUserId();

            if (_set.SetFilter.Contains(usrId))
            {
                // just in case the script was tempered with by clients.
                _set.SetFilter += " && UserRef.ID == \"" + usrId + "\"";
            }
            MemberNotification _prevlast = null;

            if (!string.IsNullOrEmpty(prevlast))
            {
                strm = new System.IO.MemoryStream();
                sbf  = System.Text.Encoding.UTF8.GetBytes(prevlast);
                strm.Write(sbf, 0, sbf.Length);
                strm.Position = 0;
                _prevlast     = ser2.ReadObject(strm) as MemberNotification;
            }
            var            result = (await svc.GetPageItemsAsync(cntx, _set, _qexpr, _prevlast)).ToArray();
            List <dynamic> ar     = new List <dynamic>();
            Dictionary <int, MemberNotificationType> dic = new Dictionary <int, MemberNotificationType>();

            foreach (var e in result)
            {
                MemberNotificationType c;
                if (!dic.TryGetValue(e.TypeID, out c))
                {
                    c = await svc.MaterializeMemberNotificationTypeRefAsync(cntx, e);

                    c.TypeName = MapCategoryName(c);
                    dic.Add(e.TypeID, c);
                }
                ar.Add(new
                {
                    categ = new { Id = c.ID, name = c.TypeName },
                    data  = e
                });
            }
            string json = ser3.Serialize(ar);

            return(json);
        }