Exemplo n.º 1
0
        public int CompareTo(FacebookPhotoAlbum other)
        {
            if (other == null)
            {
                return(1);
            }

            // Albums by default should sort most recently updated first.
            return(-LastModified.CompareTo(other.LastModified));
        }
Exemplo n.º 2
0
 public bool Equals(IliasFile other)
 {
     if (other == null)
     {
         return(false);
     }
     return(Subfolders.SequenceEqual(other.Subfolders) &&
            Name == other.Name && Id == other.Id &&
            Url == other.Url && Date.CompareTo(other.Date) == 0 &&
            LastModified.CompareTo(other.LastModified) == 0);
 }
Exemplo n.º 3
0
        // This helps determin wether this is the first time the archive has been backed up to
        // it's so we can bypass the date checks as they will not be accurate anymore
        public void backup(ICollection <DetectedFile> files, bool disable_versioning, bool disable_date_check)
        {
            prepTemp();


            if (Exists)
            {
                if (!canWrite(ArchiveFile))
                {
                    throw new TranslateableException("WriteDenied", ArchiveFile.FullName);
                }
            }
            else
            {
                if (!canWrite(ArchiveFile.Directory))
                {
                    throw new TranslateableException("WriteDenied", ArchiveFile.DirectoryName);
                }

                // If this is the first time writing to the archive, we create the identifying XML
                XmlDocument write_me = new XmlDocument();
                if (File.Exists(Path.Combine(TempFolder, "masgau.xml")))
                {
                    File.Delete(Path.Combine(TempFolder, "masgau.xml"));
                }

                XmlTextWriter write_here = new XmlTextWriter(Path.Combine(TempFolder, "masgau.xml"), System.Text.Encoding.UTF8);
                write_here.Formatting = Formatting.Indented;
                write_here.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                write_here.WriteStartElement("masgau_archive");
                write_here.Close();
                write_me.Load(Path.Combine(TempFolder, "masgau.xml"));
                //XmlNode root = write_me.DocumentElement;

                id.AddElements(write_me);

                FileStream this_file = new FileStream(Path.Combine(TempFolder, "masgau.xml"), FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);

                write_me.Save(this_file);
                write_here.Close();
                this_file.Close();
            }
            bool files_added = false;

            foreach (DetectedFile file in files)
            {
                // Copies the particular file to a relative path inside the temp folder
                FileInfo source;
                FileInfo destination;
                if (file.Path == "" || file.Path == null)
                {
                    source      = new FileInfo(Path.Combine(file.AbsoluteRoot, file.Name));
                    destination = new FileInfo(Path.Combine(TempFolder, file.Name));
                }
                else
                {
                    source      = new FileInfo(Path.Combine(file.AbsoluteRoot, file.Path, file.Name));
                    destination = new FileInfo(Path.Combine(TempFolder, file.Path, file.Name));
                }

                if (!source.Exists)
                {
                    continue;
                }

                DateTime file_write_time = source.LastWriteTime;
                int      time_comparison = LastModified.CompareTo(source.LastWriteTime);

                if (Core.settings.IgnoreDateCheck || disable_date_check || time_comparison <= 0)
                {
                    try {
                        if (!destination.Directory.Exists)
                        {
                            destination.Directory.Create();
                        }
                    } catch (Exception e) {
                        TranslatingMessageHandler.SendError("CreateError", e, destination.DirectoryName);
                        continue;
                    }

                    if (source.Exists)
                    {
                        try {
                            source.CopyTo(destination.FullName, true);
                        } catch (Exception e) {
                            TranslatingMessageHandler.SendError("CopyError", e, source.FullName, destination.FullName);
                            continue;
                        }
                    }
                    else
                    {
                        TranslatingMessageHandler.SendError("FileToCopyNotFound", source.FullName);
                        continue;
                    }

                    if (destination.Exists)
                    {
                        try {
                            if ((destination.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                            {
                                File.SetAttributes(destination.FullName, FileAttributes.Normal);
                            }
                        } catch (Exception e) {
                            TranslatingMessageHandler.SendError("PermissionChangeError", e, destination.FullName);
                            continue;
                        }
                    }
                    else
                    {
                        TranslatingMessageHandler.SendError("FileCopiedNotFound", source.FullName, destination.FullName);
                        continue;
                    }
                    files_added = true;
                }
                //file_date = new FileInfo(file_name).LastWriteTime;
            }
            if (files_added)
            {
                add(TempFolder, disable_versioning);
            }

            purgeTemp();
        }
Exemplo n.º 4
0
        /// <summary> Save this template scheme to the Template XML file </summary>
        /// <param name="FileName"> Name of Template XML file </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public bool Save_Template_XML(string FileName)
        {
            try
            {
                StringBuilder resultBuilder = new StringBuilder();

                // Add header and the start main tag
                resultBuilder.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
                resultBuilder.Append("\r\n");
                resultBuilder.Append("<!-- Begin the XML for this input template -->\r\n");
                resultBuilder.Append("<input_template>\r\n");
                resultBuilder.Append("\r\n");

                // Add the administrative information about this template
                resultBuilder.Append("\t<!-- Define the information about this input template -->\r\n");

                // Write each of the titles for this page
                foreach (KeyValuePair <Template_Language, string> thisEntry in allTitles)
                {
                    // If this language is known, write it
                    if (thisEntry.Key != Template_Language.Unknown)
                    {
                        resultBuilder.Append("\t<name language=\"" + Template_Language_Convertor.ToCode(thisEntry.Key) + "\">" + thisEntry.Value + "</name>\r\n");
                    }
                }

                // Finish out the administrative section
                if (Notes.Length > 0)
                {
                    resultBuilder.Append("\t<notes>" + Notes + "</notes>\r\n");
                }
                resultBuilder.Append("\t<dateCreated>" + DateCreated.ToLongDateString() + "</dateCreated>\r\n");
                if (LastModified.CompareTo(DateCreated) > 0)
                {
                    resultBuilder.Append("\t<lastModified>" + LastModified.ToLongDateString() + "</lastModified>\r\n");
                }
                if (Creator.Length > 0)
                {
                    resultBuilder.Append("\t<creator>" + Creator + "</creator>\r\n");
                }
                resultBuilder.Append("\r\n");

                // Write the information which describes all the inputs
                resultBuilder.Append("\t<!-- This defines the inputs which are available for the user -->\r\n");
                resultBuilder.Append("\t<inputs>\r\n");
                resultBuilder.Append(inputs.To_Template_XML());
                resultBuilder.Append("\t</inputs>\r\n");
                resultBuilder.Append("\r\n");

                // Add all the constant information
                resultBuilder.Append("\t<!-- This defines the constants which can not be edited by the user -->\r\n");
                resultBuilder.Append("\t<constants>\r\n");
                resultBuilder.Append(constants.To_Template_XML("\t\t"));
                resultBuilder.Append("\t</constants>\r\n");
                resultBuilder.Append("\r\n");

                // Close the main tag
                resultBuilder.Append("</input_template>\r\n");
                resultBuilder.Append("<!-- End of input template XML -->\r\n");

                // Write this out to a file
                StreamWriter writer = new StreamWriter(FileName, false, Encoding.UTF8);
                writer.Write(resultBuilder.ToString());
                writer.Flush();
                writer.Close();

                // Return true
                return(true);
            }
            catch
            {
                return(false);
            }
        }