Ejemplo n.º 1
0
        //**************************************************************
        // GetDirectoryContents()
        // - Uses HTTP/DAV to get a list of directories
        //**************************************************************
        public static SortedList GetDirectoryContents(string url, bool deep)
        {
            //Retrieve the File
            HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(url);
            Request.Headers.Add("Translate: f");
            Request.Credentials = CredentialCache.DefaultCredentials;

            string requestString = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"+
                "<a:propfind xmlns:a=\"DAV:\">"+
                "<a:prop>"+
                "<a:displayname/>"+
                "<a:iscollection/>"+
                "<a:getlastmodified/>"+
                "</a:prop>"+
                "</a:propfind>";

            Request.Method = "PROPFIND";
            if (deep == true)
                Request.Headers.Add("Depth: infinity");
            else
                Request.Headers.Add("Depth: 1");
            Request.ContentLength = requestString.Length;
            Request.ContentType	= "text/xml";

            Stream requestStream = Request.GetRequestStream();
            requestStream.Write(Encoding.ASCII.GetBytes(requestString),0,Encoding.ASCII.GetBytes(requestString).Length);
            requestStream.Close();

            HttpWebResponse Response;
            StreamReader respStream;
            try
            {
                Response = (HttpWebResponse)Request.GetResponse();
                respStream = new StreamReader(Response.GetResponseStream());
            }
            catch (WebException e)
            {
                Debug.WriteLine("APPMANAGER:  Error accessing Url " + url);
                Exception ex = new Exception("Error accessing url "+url,e);
                throw ex;
            }

            StringBuilder SB = new StringBuilder();

            char[] respChar = new char[1024];
            int BytesRead = 0;

            BytesRead = respStream.Read(respChar,0,1024);

            while (BytesRead>0)
            {
                SB.Append(respChar,0,BytesRead);
                BytesRead = respStream.Read(respChar,0,1024);
            }
            respStream.Close();

            XmlDocument XmlDoc = new XmlDocument();
            XmlDoc.LoadXml(SB.ToString());

            //Create an XmlNamespaceManager for resolving namespaces.
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(XmlDoc.NameTable);
            nsmgr.AddNamespace("a", "DAV:");

            XmlNodeList NameList = XmlDoc.SelectNodes("//a:prop/a:displayname",nsmgr);
            XmlNodeList isFolderList = XmlDoc.SelectNodes("//a:prop/a:iscollection",nsmgr);
            XmlNodeList LastModList = XmlDoc.SelectNodes("//a:prop/a:getlastmodified",nsmgr);
            XmlNodeList HrefList = XmlDoc.SelectNodes("//a:href",nsmgr);

            SortedList ResourceList = new SortedList();
            Resource tempResource;

            for (int i=0; i < NameList.Count; i++)
            {
                //This check is needed because the PROPFIND request returns the contents of the folder
                //as well as the folder itself.  Exclude the folder.
                if (HrefList[i].InnerText.ToLower(new CultureInfo("en-US")).TrimEnd(new char[] {'/'}) != url.ToLower(new CultureInfo("en-US")).TrimEnd(new char[] {'/'}))
                {
                    tempResource = new Resource();
                    tempResource.Name = NameList[i].InnerText;
                    tempResource.IsFolder = Convert.ToBoolean(Convert.ToInt32(isFolderList[i].InnerText));
                    tempResource.Url = HrefList[i].InnerText;
                    tempResource.LastModified = Convert.ToDateTime(LastModList[i].InnerText);
                    ResourceList.Add(tempResource.Url,tempResource);
                }
            }

            return ResourceList;
        }
Ejemplo n.º 2
0
        //**************************************************************
        // EnableManifestGeneration()
        //**************************************************************
        private void EnableManifestGeneration()
        {
            //Register for Assembly Load events
            AppDomain App = AppDomain.CurrentDomain;
            App.AssemblyLoad += new AssemblyLoadEventHandler(OnAssemblyLoad);

            //Make sure the currently loaded assemblies are in the manifest
            //The assembly load event will catch any assemblies loaded later
            Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
            for (int i=0; i<loadedAssemblies.Length;i++)
            {
                if (IsLocalAssembly(loadedAssemblies[i]))
                {
                    Resource newResource = new Resource();
                    string[] AssemblyName = loadedAssemblies[i].Location.Split(new Char[] {'\\'});
                    int index = AssemblyName.Length-1;

                    newResource.FilePath = loadedAssemblies[i].Location;
                    newResource.Name = AssemblyName[index];
                    newResource.AddedAtRuntime = true;
                    Manifest.Resources.AddResource(newResource);
                    Manifest.Update();
                }
            }
        }
Ejemplo n.º 3
0
        //**************************************************************
        // OnAssemblyLoad()
        // - Generates a manifest of files when doing DirectFile check style
        //   update checks
        //**************************************************************
        private void OnAssemblyLoad(Object sender, AssemblyLoadEventArgs args)
        {
            string[] AssemblyNames = args.LoadedAssembly.Location.Split(new Char[] {'\\'});
            int index = AssemblyNames.Length-1;
            string AssemblyName= AssemblyNames[index];

            if (!Manifest.Resources.ResourceExists(AssemblyName) && IsLocalAssembly(args.LoadedAssembly))
            {
                Resource newResource = new Resource();
                newResource.FilePath = args.LoadedAssembly.Location;
                newResource.Name = AssemblyName;
                newResource.AddedAtRuntime = true;
                Manifest.Resources.AddResource(newResource);
                Manifest.Update();
            }
        }
Ejemplo n.º 4
0
 //**************************************************************
 // AddResource()
 //**************************************************************
 public void AddResource(Resource newResource)
 {
     Resource tempResource = (Resource)ResourceList[newResource.Name];
     if (tempResource == null)
         ResourceList.Add(newResource.Name,newResource);
 }