//--------------------------------------
        //--------------------------------------
        public void NodeUpdate(ContentTransfer nodeXfer)
        {
            using (WebContentContext db = new WebContentContext())
            {
                Node nodeDb = null;

                try
                {
                    nodeDb = db.Nodes.Where(n => n.Id == nodeXfer.NodeId).Single();
                }
                catch (Exception ex)
                {
                    // Exception is thrown if the node does not exist.
                    // Replace this with a call to the logger.
                    Debug.Print(ex.Message);
                }

                if (nodeDb != null)
                {
                    nodeDb.Title   = nodeXfer.Title;
                    nodeDb.Summary = nodeXfer.Summary;
                    nodeDb.Content = nodeXfer.Content;
                    db.SaveChanges();
                }
            }
        }
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeCreate(ContentTransfer nodeNew)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = dbConnectionString;
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    string sql = "INSERT INTO Node(Path, Summary, Title, Content, DateCreated, ParentId)"
                                 + " VALUES(@pPath, @pSummary, @pTitle, @pContent, @pDateCreated, @pParentId)";
                    cmd.Connection  = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    cmd.Parameters.Add("@pPath", SqlDbType.VarChar).Value         = nodeNew.Path;
                    cmd.Parameters.Add("@pSummary", SqlDbType.VarChar).Value      = nodeNew.Summary;
                    cmd.Parameters.Add("@pTitle", SqlDbType.VarChar).Value        = nodeNew.Title;
                    cmd.Parameters.Add("@pContent", SqlDbType.VarChar).Value      = nodeNew.Content;
                    cmd.Parameters.Add("@pDateCreated", SqlDbType.DateTime).Value = nodeNew.DateCreated.ToString("yyyy-MM-dd HH:mm:ss");
                    cmd.Parameters.Add("@pParentId", SqlDbType.Int).Value         = nodeNew.ParentId;
                    cmd.ExecuteNonQuery();
                }
                conn.Close();
            }

            return(NodeGetByPath(nodeNew.Path));
        }
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeTypeMostRecentLeafGet(string nodeType)
        {
            ContentTransfer nodeXfer = null;

            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = dbConnectionString;
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    // Inner query: Select the children of the node in the outer query.
                    string sqln2 = "(SELECT * FROM Node n2 WHERE n1.Id = n2.ParentId)";

                    // Find the most recent record which is of the type and has no children.
                    string sqln1 = "SELECT MAX(n1.Id) FROM Node n1 WHERE ( (n1.Path LIKE '" + nodeType + "%') AND NOT EXISTS " + sqln2 + ")";

                    cmd.Connection  = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sqln1;

                    Object result = cmd.ExecuteScalar();
                    if (result != System.DBNull.Value)
                    {
                        nodeXfer = NodeGetById(Convert.ToInt32(result));
                    }
                }
                conn.Close();
            }

            return(nodeXfer);
        }
Ejemplo n.º 4
0
        //--------------------------------------
        //--------------------------------------
        public void NodeUpdate(ContentTransfer nodeXfer)
        {
            if (contentList == null)
            {
                return;     // no exception thrown: cannot get here if contentList is null.
            }
            lock (dataAccess)
            {
                ContentTransfer nodeExisting = null;

                try
                {
                    nodeExisting = contentList.Where(n => n.NodeId == nodeXfer.NodeId).Single();
                }
                catch (Exception ex)
                {
                    // Exception is thrown if the node does not exist.
                    // Replace this with a call to the logger.
                    Debug.Print(ex.Message);
                }

                if (nodeExisting != null)
                {
                    nodeExisting.Title   = nodeXfer.Title;
                    nodeExisting.Summary = nodeXfer.Summary;
                    nodeExisting.Content = nodeXfer.Content;
                    ContentListSave();
                }
            }
        }
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeGetByPath(string path)
        {
            ContentTransfer nodeXfer = null;

            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = dbConnectionString;
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    string sql = "SELECT " + COL_NAMES + " FROM Node WHERE (Path = @pPath)";
                    cmd.Connection  = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    cmd.Parameters.Add("@pPath", SqlDbType.VarChar).Value = path;
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            nodeXfer = NodeRecordUnpack(reader);
                        }
                    }
                }
                conn.Close();
            }

            return(nodeXfer);
        }
Ejemplo n.º 6
0
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeGetByPath(string path)
        {
            if (contentList == null)
            {
                return(null);
            }

            lock (dataAccess)
            {
                ContentTransfer nodeXfer = null;

                try
                {
                    nodeXfer = contentList.Where(n => n.Path == path).Single();
                }
                catch (Exception ex)
                {
                    // Exception is thrown if the node does not exist.
                    // Replace this with a call to the logger.
                    Debug.Print(ex.Message);
                }

                return(nodeXfer);
            }
        }
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeGetByPath(string path)
        {
            ContentTransfer nodeXfer = null;

            using (WebContentContext db = new WebContentContext())
            {
                Node nodeDb = null;

                try
                {
                    nodeDb = db.Nodes.Where(n => n.Path == path).Single();
                }
                catch (Exception ex)
                {
                    // Replace this with a call to the logger.
                    Debug.Print(ex.Message);
                }

                if (nodeDb != null)
                {
                    nodeXfer = DbNodeToContentXfer(nodeDb);
                }
            }

            return(nodeXfer);
        }
Ejemplo n.º 8
0
        //--------------------------------------
        //--------------------------------------
        public ContentNode ContentGetById(int id)
        {
            ContentTransfer nodeXfer = repository.NodeGetById(id);

            if (nodeXfer == null)
            {
                return(null);
            }

            nodeXfer.Content = ContentStorageUnpack(nodeXfer.Content);
            return(new BlogEntry(nodeXfer));
        }
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeCreate(ContentTransfer nodeNew)
        {
            Node nodeDb = ContentXferToDbNode(nodeNew);

            using (WebContentContext db = new WebContentContext())
            {
                db.Nodes.Add(nodeDb);
                db.SaveChanges();
            }

            return(NodeGetByPath(nodeNew.Path));
        }
Ejemplo n.º 10
0
        //--------------------------------------
        //--------------------------------------
        public BlogEntry BlogEntryCreate(string title, string summary, string content)
        {
            ContentTransfer contentXfer = new ContentTransfer
            {
                Content = content,
                Path    = BlogEntry.PathMake(),
                Summary = summary,
                Title   = title
            };

            return(new BlogEntry(NodeCreate(contentXfer)));
        }
Ejemplo n.º 11
0
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeGetById(int id)
        {
            ContentTransfer nodeXfer = null;

            using (ContentContext db = new ContentContext())
            {
                Node nodeDb = db.Nodes.Where(n => n.Id == id).Single();

                if (nodeDb != null)
                    nodeXfer = DbNodeToContentXfer(nodeDb);
            }

            return nodeXfer;
        }
Ejemplo n.º 12
0
        //--------------------------------------
        //--------------------------------------
        public void ContentUpdate(int id, string title, string summary, string content)
        {
            ContentTransfer contentXfer = new ContentTransfer
            {
                Content = ContentStoragePack(content),
                NodeId  = id,
                Summary = summary,
                Title   = title
            };

            ContentLengthVerify(ref contentXfer);

            repository.NodeUpdate(contentXfer);
        }
Ejemplo n.º 13
0
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeGetByPath(string path)
        {
            ContentTransfer nodeXfer = null;

            using (ContentContext db = new ContentContext())
            {
                Node nodeDb = db.Nodes.Where(n => n.Path == path).Single();

                if (nodeDb != null)
                    nodeXfer = DbNodeToContentXfer(nodeDb);
            }

            return nodeXfer;
        }
        //--------------------------------------
        //--------------------------------------
        private Node ContentXferToDbNode(ContentTransfer nodeXfer)
        {
            Node nodeDb = new Node()
            {
                Id          = nodeXfer.NodeId,
                Path        = nodeXfer.Path,
                Summary     = nodeXfer.Summary,
                Title       = nodeXfer.Title,
                Content     = nodeXfer.Content,
                DateCreated = nodeXfer.DateCreated,
                ParentId    = nodeXfer.ParentId
            };

            return(nodeDb);
        }
        //--------------------------------------
        //--------------------------------------
        private ContentTransfer DbNodeToContentXfer(Node nodeDb)
        {
            ContentTransfer nodeXfer = new ContentTransfer()
            {
                NodeId      = nodeDb.Id,
                Path        = nodeDb.Path,
                Summary     = nodeDb.Summary,
                Title       = nodeDb.Title,
                Content     = nodeDb.Content,
                DateCreated = nodeDb.DateCreated,
                ParentId    = nodeDb.ParentId
            };

            return(nodeXfer);
        }
Ejemplo n.º 16
0
        //--------------------------------------
        // Also copied from ContentRepositorySql
        //--------------------------------------
        private static ContentTransfer NodeRecordUnpack(SqlDataReader reader)
        {
            ContentTransfer nodeXfer = new ContentTransfer()
            {
                NodeId      = reader.GetInt32(COL_ID),
                Path        = reader.GetString(COL_PATH),
                Summary     = reader.GetString(COL_SUMMARY),
                Title       = reader.GetString(COL_TITLE),
                Content     = reader.GetString(COL_CONTENT),
                DateCreated = reader.GetDateTime(COL_DATE_CREATED),
                ParentId    = reader.GetInt32(COL_PARENT_ID)
            };

            return(nodeXfer);
        }
Ejemplo n.º 17
0
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeCreate(ContentTransfer nodeNew)
        {
            if (contentList == null)
            {
                return(null);
            }

            lock (dataAccess)
            {
                nodeNew.NodeId = nodeIdNext++;
                contentList.Add(nodeNew);
                ContentListSave();

                return(nodeNew);
            }
        }
Ejemplo n.º 18
0
        // Internal constructor, called by constructors in type manager classes.
        internal ContentNode(string typeArg, ContentTransfer ct)
        {
            type = typeArg;
            if (ct == null)
            {
                throw new Exception("Cannot create ContentNode from null ContentTransfer");
            }

            Content     = ct.Content;
            dateCreated = ct.DateCreated;
            nodeId      = ct.NodeId;
            parentId    = ct.ParentId;
            path        = ct.Path;
            Summary     = ct.Summary;
            Title       = ct.Title;
        }
Ejemplo n.º 19
0
        //--------------------------------------
        //--------------------------------------
        public ContentNode ContentGetByPath(string path)
        {
            if (path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }

            ContentTransfer nodeXfer = repository.NodeGetByPath(path);

            if (nodeXfer == null)
            {
                return(null);
            }

            nodeXfer.Content = ContentStorageUnpack(nodeXfer.Content);
            return(new BlogEntry(nodeXfer));
        }
        //--------------------------------------
        //--------------------------------------
        public List <ContentTransfer> NodeChildrenGet(int id)
        {
            List <ContentTransfer> children = new List <ContentTransfer>();

            using (WebContentContext db = new WebContentContext())
            {
                List <Node> childNodes = db.Nodes.Where(n => n.ParentId == id).ToList <Node>();

                foreach (Node nodeDb in childNodes)
                {
                    ContentTransfer nodeXfer = DbNodeToContentXfer(nodeDb);

                    children.Add(nodeXfer);
                }
            }

            return(children);
        }
Ejemplo n.º 21
0
        //--------------------------------------
        //--------------------------------------
        public ContentTransfer NodeTypeMostRecentLeafGet(string nodeType)
        {
            ContentTransfer nodeXfer = null;


            using (ContentContext db = new ContentContext())
            {
                Node nodeDb =
                    (
                    from n1 in db.Nodes.Query()
                    where (
                    ) 
                    
                    
                    
                    db.Nodes.Where( (n => n.Path.StartsWith(nodeType))                .Single();



                int childObjectIdToMatch = childObjectToMatch.ID;
                dbContext.Parents.Where(p => p.Children.Any(c => c.ID == childObjectIdToMatch));


                from m in uow.MeterReadingReadWriteRepository.Query()
                where !uow.MeterReadingReadWriteRepository.Query().Any(child => m.Id == child.LastMeterReadingId)
                select


                                    // Find the n1.Ids that have no children.
                                    string sqln2 = "((SELECT COUNT(*) FROM Node n2 WHERE n1.Id = n2.ParentId) = 0)";

                    // Find the most recent Id of the type that has no children.
                    string sqln1 = "SELECT MAX(n1.Id) FROM Node n1 WHERE ( (n1.Path LIKE '" + nodeType + "%') AND " + sqln2 + ")";

                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sqln1;

                    Object result = cmd.ExecuteScalar();
                    if (result != System.DBNull.Value)
                        node = NodeGetById(Convert.ToInt32(result));
                }
                conn.Close();
            }
Ejemplo n.º 22
0
        //--------------------------------------
        //--------------------------------------
        public BlogEntry BlogEntryMostRecentGet()
        {
            try
            {
                ContentTransfer nodeXfer = repository.NodeTypeMostRecentLeafGet("Blog");
                if (nodeXfer == null)
                {
                    return(null);
                }

                nodeXfer.Content = ContentStorageUnpack(nodeXfer.Content);
                return(new BlogEntry(nodeXfer));
            }
            catch (Exception ex)
            {
                // Replace this with a call to the logger.
                Debug.Print(ex.Message);
                return(null);
            }
        }
Ejemplo n.º 23
0
        //--------------------------------------
        //--------------------------------------
        private void ContentLengthVerify(ref ContentTransfer node)
        {
            // Content, Summary, and Title must meet length requirements.
            if (String.IsNullOrWhiteSpace(node.Content))
            {
                throw new Exception("Node Content is required");
            }

            if (String.IsNullOrWhiteSpace(node.Summary))
            {
                throw new Exception("Node Summary is required");
            }

            if (String.IsNullOrWhiteSpace(node.Title))
            {
                throw new Exception("Node Title is required");
            }


            int    stubLength = 80;
            string msg;
            string msgLength = " exceeds maximum length of {0} characters: {1}...";

            msg = "Content" + msgLength;
            if (node.Content.Length > ContentNode.contentLengthMax)
            {
                throw new Exception(String.Format(msg, ContentNode.contentLengthMax, node.Content.Substring(0, stubLength)));
            }

            msg = "Summary" + msgLength;
            if (node.Summary.Length > ContentNode.summaryLengthMax)
            {
                throw new Exception(String.Format(msg, ContentNode.summaryLengthMax, node.Summary.Substring(0, stubLength)));
            }

            msg = "Title" + msgLength;
            if (node.Title.Length > ContentNode.titleLengthMax)
            {
                throw new Exception(String.Format(msg, ContentNode.titleLengthMax, node.Title.Substring(0, stubLength)));
            }
        }
 //--------------------------------------
 //--------------------------------------
 public void NodeUpdate(ContentTransfer nodeXfer)
 {
     using (SqlConnection conn = new SqlConnection())
     {
         conn.ConnectionString = dbConnectionString;
         conn.Open();
         using (SqlCommand cmd = new SqlCommand())
         {
             string sql = "UPDATE Node SET Content = @pContent, Summary = @pSummary, Title = @pTitle WHERE (Id = @pId)";
             cmd.Connection  = conn;
             cmd.CommandType = CommandType.Text;
             cmd.CommandText = sql;
             cmd.Parameters.Add("@pContent", SqlDbType.VarChar).Value = nodeXfer.Content;
             cmd.Parameters.Add("@pSummary", SqlDbType.VarChar).Value = nodeXfer.Summary;
             cmd.Parameters.Add("@pTitle", SqlDbType.VarChar).Value   = nodeXfer.Title;
             cmd.Parameters.Add("@pId", SqlDbType.Int).Value          = nodeXfer.NodeId;
             cmd.ExecuteNonQuery();
         }
         conn.Close();
     }
 }
Ejemplo n.º 25
0
        //--------------------------------------
        //--------------------------------------
        private ContentTransfer NodeCreate(ContentTransfer nodeNew)
        {
            ContentTransfer nodeCurrent;
            int             parentId;
            string          pathCurrent;
            int             iterSegmentCurrent;
            int             iterSegmentParentCount;

            string[] segments;
            string   segmentCurrent;

            ContentLengthVerify(ref nodeNew);

            // Reject duplicate path.
            if (repository.NodeExistsTest(nodeNew.Path))
            {
                throw new Exception("Cannot create node with duplicate path: " + nodeNew.Path);
            }

            // Break the path into segments.
            segments = nodeNew.Path.Split(ContentNode.pathDividerChar);

            // Walk the path to the final parent node.
            // Create missing nodes as needed.
            parentId               = 0;
            pathCurrent            = "";
            iterSegmentParentCount = segments.Length - 1;
            for (iterSegmentCurrent = 0; iterSegmentCurrent < iterSegmentParentCount; iterSegmentCurrent++)
            {
                // Current segment string.
                segmentCurrent = segments[iterSegmentCurrent];

                // Path to the current segment.
                pathCurrent += segmentCurrent;

                // Node at the current segment.
                nodeCurrent = repository.NodeGetByPath(pathCurrent);
                if (nodeCurrent == null)
                {
                    // A node does not exist at the current segment.
                    // Create the node.
                    nodeCurrent = new ContentTransfer
                    {
                        Path        = pathCurrent,
                        DateCreated = DateTime.Now,
                        Content     = "...",
                        Summary     = "...",
                        Title       = segmentCurrent,
                        ParentId    = parentId
                    };

                    nodeCurrent = repository.NodeCreate(nodeCurrent);
                }   // end of creating intermediate node

                // Set up for next iteration.
                pathCurrent += ContentNode.pathDividerStr;
                parentId     = nodeCurrent.NodeId;
            }       // end of loop walking intermediate segments


            // Create the new node and return it, fully populated.
            nodeNew.Content     = ContentStoragePack(nodeNew.Content);
            nodeNew.DateCreated = DateTime.Now;
            nodeNew.ParentId    = parentId;
            return(repository.NodeCreate(nodeNew));
        }
Ejemplo n.º 26
0
 internal BlogEntry(ContentTransfer cn) : base("Blog", cn)
 {
 }
Ejemplo n.º 27
0
        /// <summary>
        ///		Interpreta la forma de transferencia
        /// </summary>
        private static ContentTransfer ParseTransferEncoding(Header objHeader)
        {
            ContentTransfer objTransfer = new ContentTransfer();

                // Asigna los datos
                    objTransfer.TransferEncodingDefinition = objHeader.Value;
                // Devuelve el modo de transferencia
                    return objTransfer;
        }