WikiCrawler/MediaWiki/Api.cs
/// <summary>
/// Checks for already-existing duplicate copies of the file.
/// </summary>
/// <returns>An array of key-value dictionaries describing the duplicate files(s)</returns>
Checks for already-existing duplicate copies of the file.
Checks for already - existing duplicate copies of the file .
public object[] GetDuplicateFiles(byte[] file, string prop = Prop.imageinfo)
        {
            SHA1 algo = SHA1.Create();
            byte[] shaData = algo.ComputeHash(file);
            StringBuilder shaHex = new StringBuilder();
            for (int i = 0; i < shaData.Length; i++)
                shaHex.Append(shaData[i].ToString("x2"));
			string baseQuery = "format=json"
				+ "&action=query"
				+ "&list=allimages"
				+ "&aisha1=" + shaHex;
			if (!string.IsNullOrEmpty(prop))
			{
				baseQuery += "&prop=" + prop;
			}
            HttpWebRequest request = CreateApiRequest(baseQuery);
			string json;
			using (StreamReader read = new StreamReader(EasyWeb.GetResponseStream(request)))
			{
				json = read.ReadToEnd();
			}
            Dictionary<string, object> deser = (Dictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json);
            Dictionary<string, object> query = (Dictionary<string, object>)deser["query"];
            if (query.ContainsKey("allimages"))
                return (object[])query["allimages"];
            else
                return null;
        }
public object [ ] GetDuplicateFiles ( byte [ ] file , string prop = Prop . imageinfo ) { SHA1 algo = SHA1 . Create ( ) ; byte [ ] shaData = algo . ComputeHash ( file ) ; StringBuilder shaHex = new StringBuilder ( ) ; for ( int i = 0 ; i < shaData . Length ; i ++ ) shaHex . Append ( shaData [ i ] . ToString ( " " ) ) ; string baseQuery = " " + " " + " " + " " + shaHex ; if ( ! string . IsNullOrEmpty ( prop ) ) { baseQuery += " " + prop ; } HttpWebRequest request = CreateApiRequest ( baseQuery ) ; string json ; using ( StreamReader read = new StreamReader ( EasyWeb . GetResponseStream ( request ) ) ) { json = read . ReadToEnd ( ) ; } Dictionary < string , object > deser = ( Dictionary < string , object > ) new JavaScriptSerializer ( ) . DeserializeObject ( json ) ; Dictionary < string , object > query = ( Dictionary < string , object > ) deser [ " " ] ; if ( query . ContainsKey ( " " ) ) return ( object [ ] ) query [ " " ] ; else return null ; }
Checks for already-existing duplicate copies of the file.
Checks for already - existing duplicate copies of the file .
//Download stream //Parse and read
An array of key-value dictionaries describing the duplicate files(s)
An array of key - value dictionaries describing the duplicate files ( s )
file
byte[]
prop
string