Ejemplo n.º 1
0
        public MetaWeblog.Post getPost(string postid, string username, string password)
        {
            if (ValidateUser(username, password))
            {
                VersionStoreCollection vsc = VersionStore.GetVersionHistory(Convert.ToInt32(postid));

                Graffiti.Core.Post p = new Graffiti.Core.Post();

                if (vsc != null && vsc.Count > 0)
                {
                    List <Graffiti.Core.Post> the_Posts = new List <Graffiti.Core.Post>();
                    foreach (VersionStore vs in vsc)
                    {
                        the_Posts.Add(ObjectManager.ConvertToObject <Graffiti.Core.Post>(vs.Data));
                    }

                    the_Posts.Sort(delegate(Graffiti.Core.Post p1, Graffiti.Core.Post p2) { return(Comparer <int> .Default.Compare(p2.Version, p1.Version)); });
                    p = the_Posts[0];
                }
                else
                {
                    p = new Graffiti.Core.Post(postid);
                }

                return(ConvertToPost(p));
            }

            throw new XmlRpcFaultException(0, "User does not exist");
        }
Ejemplo n.º 2
0
        public static void VersionPost(Post old_Post)
        {
            VersionStore vs = new VersionStore();

            vs.Type     = "post/xml";
            vs.ItemId   = old_Post.Id;
            vs.Name     = "Post:" + old_Post.Id;
            vs.UniqueId = Guid.NewGuid();
            vs.Data     = old_Post.ToXML();
            vs.Version  = old_Post.Version;
            vs.Save(GraffitiUsers.Current.Name);
        }
Ejemplo n.º 3
0
        public static int CurrentVersion(FileInfo fi)
        {
            Query q = CreateQuery();

            q.Top = "1";
            q.AndWhere(Columns.Name, fi.FullName);
            q.AndWhere(Columns.Type, Util.GetMapping(fi.FullName));
            q.OrderByDesc(Columns.Version);

            VersionStore vs = FetchByQuery(q);

            return(vs.Version);
        }
Ejemplo n.º 4
0
        private static void ProcessFolderNode(XmlNode node, string basePath, bool overwrite)
        {
            string        folderName = node.Attributes["name"].Value;
            string        newPath    = Path.Combine(basePath, folderName);
            DirectoryInfo di         = new DirectoryInfo(newPath);

            if (!di.Exists)
            {
                di.Create();
            }
            else if (!overwrite)
            {
                throw new Exception("Directory " + newPath + " already exists");
            }

            foreach (XmlNode fileNode in node.SelectNodes("files/file"))
            {
                string fileToCreateName = Path.Combine(newPath, fileNode.Attributes["name"].Value);
                if (!overwrite && File.Exists(fileToCreateName))
                {
                    throw new Exception("The file " + fileToCreateName + " already exists");
                }

                bool isText = fileNode.Attributes["type"] != null ? fileNode.Attributes["type"].Value == "text" : false;
                if (isText)
                {
                    using (StreamWriter sw = new StreamWriter(fileToCreateName))
                    {
                        sw.Write(fileNode.InnerText);
                        sw.Close();
                    }
                }
                else
                {
                    string base64 = fileNode.InnerText;
                    byte[] ba     = Convert.FromBase64String(base64);
                    using (FileStream fs = new FileStream(fileToCreateName, FileMode.Create, FileAccess.Write))
                    {
                        fs.Write(ba, 0, ba.Length);
                        fs.Close();
                    }
                }

                VersionStore.VersionFile(new FileInfo((fileToCreateName)));
            }

            foreach (XmlNode folderNode in node.SelectNodes("folders/folder"))
            {
                ProcessFolderNode(folderNode, newPath, overwrite);
            }
        }
Ejemplo n.º 5
0
        public static int VersionFile(FileInfo fi)
        {
            VersionStore vs = new VersionStore();
            vs.Name = fi.FullName;
            vs.Version =  CurrentVersion(fi) + 1;
            vs.Type = Util.GetMapping(fi.FullName);
            vs.UniqueId = Guid.NewGuid();

            using (StreamReader sr = new StreamReader(fi.FullName))
            {
                vs.Data = sr.ReadToEnd();
                sr.Close();
            }

            vs.Save(GraffitiUsers.Current.Name, SiteSettings.CurrentUserTime);

            return vs.Id;
        }
Ejemplo n.º 6
0
        public static int VersionFile(FileInfo fi)
        {
            VersionStore vs = new VersionStore();

            vs.Name     = fi.FullName;
            vs.Version  = CurrentVersion(fi) + 1;
            vs.Type     = Util.GetMapping(fi.FullName);
            vs.UniqueId = Guid.NewGuid();

            using (StreamReader sr = new StreamReader(fi.FullName))
            {
                vs.Data = sr.ReadToEnd();
                sr.Close();
            }

            vs.Save(GraffitiUsers.Current.Name, SiteSettings.CurrentUserTime);

            return(vs.Id);
        }
Ejemplo n.º 7
0
        private static void RemoveFilesAndFolders(Package p)
        {
            if (p.Files != null)
            {
                foreach (string file in p.Files)
                {
                    string fileName = HttpContext.Current.Server.MapPath(VirtualPathUtility.ToAbsolute("~" + file));

                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                    if (File.Exists(fileName + ".old"))
                    {
                        File.Move(fileName + ".old", fileName);
                    }
                    else
                    {
                        VersionStoreCollection vsc = VersionStore.GetVersionHistory(fileName, false);

                        if (vsc != null && vsc.Count > 0)
                        {
                            WriteFile(fileName, vsc[0].Data);

                            VersionStore.Destroy(VersionStore.Columns.UniqueId, vsc[0].UniqueId);
                        }
                    }
                }
            }

            if (p.Directories != null)
            {
                foreach (string dir in p.Directories)
                {
                    if (Directory.Exists(dir) && Directory.GetFiles(dir).Length == 0)
                    {
                        Directory.Delete(dir);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 public static int GetNextVersionId(int postid, int currentVersion)
 {
     if (postid <= 0)
     {
         return(1);
     }
     else
     {
         QueryCommand command = new QueryCommand("Select Max(v.Version) FROM graffiti_VersionStore as v where v.Name = " + DataService.Provider.SqlVariable("Name"));
         command.Parameters.Add(VersionStore.FindParameter("Name")).Value = "Post:" + postid.ToString();
         object obj = DataService.ExecuteScalar(command);
         if (obj == null || obj is System.DBNull)
         {
             return(2);
         }
         else
         {
             return(Math.Max(((int)obj), currentVersion) + 1);
         }
     }
 }
Ejemplo n.º 9
0
        private static void ProcessFolderNode(XmlNode node, string basePath, bool overwrite, Package pkg, bool root)
        {
            string unpackTo = HttpContext.Current.Server.MapPath(VirtualPathUtility.ToAbsolute("~" + basePath));

            if (!root && node.Attributes["name"] != null)
            {
                string folderName = node.Attributes["name"].Value;

                basePath = Path.Combine(basePath, folderName);
                unpackTo = Path.Combine(unpackTo, folderName);
            }

            DirectoryInfo di = new DirectoryInfo(unpackTo);

            if (!di.Exists)
            {
                di.Create();

                if (pkg.Directories == null)
                {
                    pkg.Directories = new List <String>();
                }

                pkg.Directories.Add(unpackTo);
            }

            foreach (XmlNode fileNode in node.SelectNodes("files/file"))
            {
                string fileToCreateName = Path.Combine(unpackTo, fileNode.Attributes["name"].Value);

                string pkgFileName = basePath.Replace("\\", "/") + "/" + fileNode.Attributes["name"].Value;
                pkgFileName = pkgFileName.Replace("//", "/");

                Package p = IsFileOkToInstall(pkgFileName);
                if (p != null)
                {
                    RemoveFilesAndFolders(pkg);
                    throw new Exception("Cannot install this package because the file " + fileNode.Attributes["name"].Value + " is in use by the package <strong>" + p.Name + "</strong>.");
                }

                if (!overwrite && File.Exists(fileToCreateName))
                {
                    RemoveFilesAndFolders(pkg);
                    throw new Exception("The file " + fileNode.Attributes["name"].Value + " already exists.");
                }

                if (overwrite && File.Exists(fileToCreateName))
                {
                    // if the file is a .dll, rename it. otherwise version it.
                    if (fileToCreateName.ToLower().EndsWith(".dll"))
                    {
                        File.Move(fileToCreateName, fileToCreateName + ".old");
                    }
                    else
                    {
                        VersionStore.VersionFile(new FileInfo(fileToCreateName));
                    }

                    File.Delete(fileToCreateName);
                }

                if (pkg.Files == null)
                {
                    pkg.Files = new List <String>();
                }

                pkg.Files.Add(pkgFileName);

                try
                {
                    WriteFile(fileToCreateName, fileNode.InnerText);
                }
                catch (Exception exc)
                {
                    throw new Exception("Could not create file " + fileNode.Attributes["name"].Value + ". " + exc.Message);
                }
            }

            foreach (XmlNode folderNode in node.SelectNodes("folders/folder"))
            {
                ProcessFolderNode(folderNode, basePath, overwrite, pkg, false);
            }
        }
Ejemplo n.º 10
0
 public static void VersionPost(Post old_Post)
 {
     VersionStore vs = new VersionStore();
     vs.Type = "post/xml";
     vs.ItemId = old_Post.Id;
     vs.Name = "Post:" + old_Post.Id;
     vs.UniqueId = Guid.NewGuid();
     vs.Data = old_Post.ToXML();
     vs.Version = old_Post.Version;
     vs.Save(GraffitiUsers.Current.Name);
 }