Exemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            using (var reader = new StreamReader(context.Request.InputStream))
            {
                var xml = XDocument.Parse(reader.ReadToEnd());
                reader.Close();

                var id = Guid.Parse(xml.Root.Elements().First(e => (string)e.Attribute("name") == "Id").Value);
                using (var db = new OrganizerEntities())
                {
                    var item = db.TreeItems.Find(id);
                    if (item == null)
                    {
                        throw new Exception("item is not found by ID = " + id);
                    }
                    CustomMembershipProvider.ValidateAccessToTreeItem_ReturnActiveAuthEntity(item, db, true);
                    ServerSideProcedures.XmlToItem(item, xml.Root, "LastModifiedUtc", "IsSelected", "Id", "ParentId", "NextSiblingId");
                    item.LastModifiedUtc = DateTime.UtcNow;
                    db.SaveChanges();
                }

                context.Response.ContentType = "text/plain";
                context.Response.Write("OK");
            }
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            var thisTreeItemId = Guid.Parse(context.Request["thisTreeItemId"]);

            using (var db = new OrganizerEntities())
            {
                var thisTreeItem = db.TreeItems.Find(thisTreeItemId);
                CustomMembershipProvider.ValidateAccessToTreeItem_ReturnActiveAuthEntity(thisTreeItem, db, true);
                var thisTreeItemChildren = new List <TreeItem>();
                GetTreeItems.GetChildTreeItemsReadonlyHtml(thisTreeItemId, db, thisTreeItemChildren);
                var newItem = new TreeItem
                {
                    CreatedUtc      = DateTime.UtcNow,
                    Id              = Guid.NewGuid(),
                    LastModifiedUtc = DateTime.UtcNow,
                    ParentId        = thisTreeItem.Id,
                    NextSiblingId   = thisTreeItemChildren.Count != 0 ? (Guid?)thisTreeItemChildren[0].Id : null,
                    AutoLoadNestedChildrenIfNotRoot = true
                };
                db.TreeItems.Add(newItem);
                db.SaveChanges();

                context.Response.Write(ServerSideProcedures.DataObjectToXml(newItem));
            }
        }
Exemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";

            var acceptEncoding = context.Request.Headers["Accept-Encoding"];

            if (!string.IsNullOrEmpty(acceptEncoding))
            {
                // The two common compression formats in web are GZip and Deflate
                if (acceptEncoding.IndexOf("gzip", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    // Read the response using a GZip compressor ,   and replace the output with compressed result
                    context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
                    // Tell the client the ouput they got is compressed in GZip
                    context.Response.AppendHeader("Content-Encoding", "gzip");
                }
                else if (acceptEncoding.IndexOf("deflate", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    // Read the response using a Deflate compressor ,   and replace the output with compressed result
                    context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
                    // Tell the client the ouput they got is compressed in Deflate
                    context.Response.AppendHeader("Content-Encoding", "deflate");
                }
            }


            var        rootTreeItemId = Guid.Parse(context.Request["rootTreeItemId"]);
            var        result         = new List <TreeItem>();
            AuthEntity user           = null;

            using (var db = new OrganizerEntities())
            {
                var item = db.TreeItems.FirstOrDefault(x => x.Id == rootTreeItemId);
                if (item != null)
                {
                    user = CustomMembershipProvider.ValidateAccessToTreeItem_ReturnActiveAuthEntity(item, db, false);
                    user.LastActiveAtUtc = DateTime.UtcNow;
                    db.SaveChanges();

                    result.Add(item);
                    GetChildTreeItemsReadonlyHtml(item.Id, db, result, true, true);
                }
            }
            if (result.Count != 0 && user != null)
            {
                context.Response.Write(ServerSideProcedures.ItemsListToXml(result[0], result,
                                                                           null// (x) => new Dictionary<string, string> {{"IsSelected", ((TreeItem)x).Id == user.SelectedTreeItemId ? "True" : "False"}}
                                                                           ));
            }
        }