2002-02-21 Gaurav Vaish <gvaish@iitk.ac.in>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / AdRotator.cs
index c0cded5f909f735970e3031260f3aea310ba49b8..f93f710f37b096743a2371b2977cab487eea2019 100755 (executable)
@@ -42,13 +42,11 @@ namespace System.Web.UI.WebControls
                        public int         hits; // or impressions or clicks\r
                        public string      keyword;\r
 \r
-                       public AdRecord()\r
-                       {\r
-                       }\r
-                       \r
-                       public void Initialize(IDictionary adProps)\r
+                       public AdRecord(IDictionary adProps)\r
                        {\r
                                this.adProps = adProps;\r
+                               hits         = 0;\r
+                               keyword      = String.Empty;\r
                        }\r
                }\r
 \r
@@ -65,12 +63,12 @@ namespace System.Web.UI.WebControls
 \r
                private AdRecord[] LoadAdFile(string file)\r
                {\r
-                       Stream      fSream;\r
+                       Stream      fStream;\r
                        ArrayList   list;\r
                        XmlReader   reader;\r
                        XmlDocument document;\r
                        XmlNode     topNode, innerNode;\r
-                       IDictionary hybridDict;\r
+                       IDictionary hybridDict = null;\r
                        AdRecord[]  adsArray = null;\r
                        try\r
                        {\r
@@ -87,9 +85,9 @@ namespace System.Web.UI.WebControls
                                document.Load(reader);\r
                                if(document.DocumentElement!=null)\r
                                {\r
-                                       if(docuent.DocumentElement.LocalName=="Advertisements")\r
+                                       if(document.DocumentElement.LocalName=="Advertisements")\r
                                        {\r
-                                               topNode = documentElement.FirstChild;\r
+                                               topNode = document.DocumentElement.FirstChild;\r
                                                while(topNode!=null)\r
                                                {\r
                                                        if(topNode.LocalName=="Ad")\r
@@ -97,13 +95,13 @@ namespace System.Web.UI.WebControls
                                                                innerNode = topNode.FirstChild;\r
                                                                while(innerNode!=null)\r
                                                                {\r
-                                                                       if(innerNode.NodeType==NodeType.Element)\r
+                                                                       if(innerNode.NodeType==XmlNodeType.Element)\r
                                                                        {\r
-                                                                               if(hybridDic==null)\r
+                                                                               if(hybridDict==null)\r
                                                                                {\r
-                                                                                       hybirdDict = new HybridDictionary();\r
+                                                                                       hybridDict = new HybridDictionary();\r
                                                                                }\r
-                                                                               hybridDic.Add(innerNode.LocalName, innerNode.InnerText);\r
+                                                                               hybridDict.Add(innerNode.LocalName, innerNode.InnerText);\r
                                                                        }\r
                                                                        innerNode = innerNode.NextSibling;\r
                                                                }\r
@@ -119,15 +117,15 @@ namespace System.Web.UI.WebControls
                                        adsArray = new AdRecord[list.Count];\r
                                        for(int i=0; i < list.Count; i++)\r
                                        {\r
-                                               adsArray[i] = new AdRecord((IDictionary)list.Item[i]);\r
+                                               adsArray[i] = new AdRecord((IDictionary)list[i]);\r
                                        }\r
                                }\r
-                       } catch(Excetion e)\r
+                       } catch(Exception e)\r
                        {\r
                                throw new HttpException("AdRotator_Parse_Error" + file);\r
                        } finally\r
                        {\r
-                               fStream.close();\r
+                               fStream.Close();\r
                        }\r
                        if(adsArray == null)\r
                        {\r
@@ -141,23 +139,23 @@ namespace System.Web.UI.WebControls
                        string physPath = MapPathSecure(file);\r
                        string AdKey = "AdRotatorCache: " + physPath;\r
                        fileDirectory = UrlUtils.GetDirectory(UrlUtils.Combine(TemplateSourceDirectory, file));\r
-                       CacheInternal ci = HttpRuntime.CacheInternal;\r
-                       AdRecord[] records = (AdRecord[])ci[AdKey];\r
-                       if(!(records))\r
+                       Cache cache = HttpRuntime.Cache;\r
+                       AdRecord[] records = (AdRecord[])cache[AdKey];\r
+                       if(records==null)\r
                        {\r
                                records = LoadAdFile(physPath);\r
-                               if(!(records))\r
+                               if(records==null)\r
                                {\r
                                        return null;\r
                                }\r
-                               ci.Insert(AdKey, records, new CacheDependency(physPath));\r
+                               cache.Insert(AdKey, records, new CacheDependency(physPath));\r
                        }\r
                        return records;\r
                }\r
                \r
                private IDictionary SelectAd()\r
                {\r
-                       AdRecord[] records = GetFileData(AdvertisementFile);\r
+                       AdRecord[] records = GetData(AdvertisementFile);\r
                        if(records!=null && records.Length!=0)\r
                        {\r
                                int impressions = 0;\r
@@ -168,12 +166,12 @@ namespace System.Web.UI.WebControls
                                }\r
                                if(impressions!=0)\r
                                {\r
-                                       int rnd = Random.Next(impressions) + 1;\r
+                                       int rnd = (new Random()).Next(impressions) + 1;\r
                                        int counter = 0;\r
                                        int index = 0;\r
                                        for(int i=0; i < records.Length; i++)\r
                                        {\r
-                                               if(IsAdMaching(records[i]))\r
+                                               if(IsAdMatching(records[i]))\r
                                                {\r
                                                        if(rnd <= (counter + records[i].hits))\r
                                                        {\r
@@ -225,9 +223,8 @@ namespace System.Web.UI.WebControls
                        }\r
                }\r
                \r
-               public AdRotator()\r
+               public AdRotator(): base()\r
                {\r
-                       base();\r
                        advertisementFile = string.Empty;\r
                        fileDirectory     = null;\r
                }\r
@@ -307,7 +304,7 @@ namespace System.Web.UI.WebControls
                        Image adImage = new Image();\r
                        foreach(IEnumerable current in Attributes.Keys)\r
                        {\r
-                               hLink[(string)current] = Attributes[(string)current];\r
+                               hLink.Attributes[(string)current] = Attributes[(string)current];\r
                        }\r
                        if(ID != null && ID.Length > 0)\r
                                hLink.ID = ID;\r