Пример #1
0
        public GalleryAccount(string name, string url, string username, string password, GalleryVersion version)
        {
            this.Name = name;
            this.username = username;
            this.password = password;
            this.Url = url;

            if (version != GalleryVersion.VersionUnknown)
                this.Version = version;
            else
                this.Version = Gallery.DetectGalleryVersion(Url);
        }
Пример #2
0
        private GalleryAccount ParseAccount(System.Xml.XmlNode node)
        {
            if (node.Name != "Account")
            {
                return(null);
            }

            string         name     = null;
            string         url      = null;
            string         username = null;
            string         password = null;
            GalleryVersion version  = GalleryVersion.VersionUnknown;

            foreach (System.Xml.XmlNode child in node.ChildNodes)
            {
                if (child.Name == "Name")
                {
                    name = child.ChildNodes [0].Value;
                }
                else if (child.Name == "Url")
                {
                    url = child.ChildNodes [0].Value;
                }
                else if (child.Name == "Password")
                {
                    password = child.ChildNodes [0].Value;
                }
                else if (child.Name == "Username")
                {
                    username = child.ChildNodes [0].Value;
                }
                else if (child.Name == "Version")
                {
                    string versionString = child.ChildNodes [0].Value;
                    if (versionString == "Version1")
                    {
                        version = GalleryVersion.Version1;
                    }
                    else if (versionString == "Version2")
                    {
                        version = GalleryVersion.Version2;
                    }
                    else
                    {
                        Log.Error("Unexpected versions string: " + versionString);
                    }
                }
            }
            return(new GalleryAccount(name, url, username, password, version));
        }
Пример #3
0
        public static GalleryVersion DetectGalleryVersion(string url)
        {
            //Figure out if the url is for G1 or G2
            Console.WriteLine("Detecting Gallery version");

            GalleryVersion version;

            if (url.EndsWith(Gallery1.script_name))
            {
                version = GalleryVersion.Version1;
            }
            else if (url.EndsWith(Gallery2.script_name))
            {
                version = GalleryVersion.Version2;
            }
            else
            {
                //check what script is available on the server

                FormClient client = new FormClient();

                try {
                    client.Submit(new Uri(Gallery.FixUrl(url, Gallery1.script_name)));
                    version = GalleryVersion.Version1;
                } catch (System.Net.WebException) {
                    try {
                        client.Submit(new Uri(Gallery.FixUrl(url, Gallery2.script_name)));
                        version = GalleryVersion.Version2;
                    } catch (System.Net.WebException) {
                        //Uh oh, neither version detected
                        version = GalleryVersion.VersionUnknown;
                    }
                }
            }

            Console.WriteLine("Detected: " + version.ToString());
            return(version);
        }
Пример #4
0
        public static void LoadMetaDatabases(List <GallerySource> sources)
        {
            foreach (GallerySource source in sources)
            {
                try
                {
                    RaiseStatusUpdatedEvent("Loading source (" + source.Path + ")...");
                    string databaseFileName = Path.ChangeExtension(source.ID, DATABASE_FILE_EXTENSION);
                    string databaseFilePath = Path.Combine(ObjectPool.CompleteDatabaseLocation, databaseFileName);
                    if (File.Exists(databaseFilePath))
                    {
                        using (ZipFile sourceDatabase = ZipFile.Read(databaseFilePath))
                        {
                            MemoryStream memoryStream = new MemoryStream();
                            ZipEntry     zipEntry     = sourceDatabase[Path.ChangeExtension(source.ID, METAFILE_FILE_EXTENSION)];
                            zipEntry.Extract(memoryStream);
                            memoryStream.Position = 0;
                            StreamReader reader = new StreamReader(memoryStream);

                            string   objectPrefix;
                            string[] deserializedObject = ObjectSerializer.Deserialize(reader.ReadLine(), out objectPrefix);
                            if (objectPrefix != "GV")
                            {
                                throw new Exception("Failed to deserialize source database; gallery version missing");
                            }
                            GalleryVersion version = new GalleryVersion(deserializedObject);

                            DeserializeSource(reader, source);

                            reader.Close();
                            memoryStream.Close();
                        }
                    }
                }
                catch { }
            }
        }
		public static GalleryVersion DetectGalleryVersion (string url)
		{
			//Figure out if the url is for G1 or G2
			Console.WriteLine ("Detecting Gallery version");

			GalleryVersion version;

			if (url.EndsWith (Gallery1.script_name)) {
				version = GalleryVersion.Version1;
			} else if (url.EndsWith (Gallery2.script_name)) {
				version = GalleryVersion.Version2;
			} else {
				//check what script is available on the server

				FormClient client = new FormClient ();

				try {
					client.Submit (new Uri (Gallery.FixUrl (url, Gallery1.script_name)));
					version =  GalleryVersion.Version1;

				} catch (System.Net.WebException) {
					try {
						client.Submit (new Uri (Gallery.FixUrl (url, Gallery2.script_name)));
						version =  GalleryVersion.Version2;

					} catch (System.Net.WebException) {
						//Uh oh, neither version detected
						version = GalleryVersion.VersionUnknown;
					}
				}
			}

			Console.WriteLine ("Detected: " + version.ToString());
			return version;
		}
Пример #6
0
        public Gallery Connect()
        {
            //System.Console.WriteLine ("GalleryAccount.Connect()");
            Gallery gal = null;

            if (version == GalleryVersion.VersionUnknown)
                this.version = Gallery.DetectGalleryVersion(Url);

            if (version == GalleryVersion.Version1) {
                gal = new Gallery1 (url, url);
            } else if (version == GalleryVersion.Version2) {
                gal = new Gallery2 (url, url);
            } else {
                throw new GalleryException (Catalog.GetString("Cannot connect to a Gallery for which the version is unknown.\nPlease check that you have Remote plugin 1.0.8 or later"));
            }

            System.Console.WriteLine ("Gallery created: " + gal);

            gal.Login (username, password);

            gallery = gal;
            connected = true;

            gallery.expect_continue = Preferences.Get<bool> (LIGHTTPD_WORKAROUND_KEY);

            return gallery;
        }
Пример #7
0
        public GalleryAccount(string name, string url, string username, string password, GalleryVersion version)
        {
            this.Name     = name;
            this.username = username;
            this.password = password;
            this.Url      = url;

            if (version != GalleryVersion.VersionUnknown)
            {
                this.Version = version;
            }
            else
            {
                this.Version = Gallery.DetectGalleryVersion(Url);
            }
        }