Example #1
0
        public Properties Properties(string teacher, string name, string start, string end, string Drive, string Path)
        {
            Properties ret = new Properties();

            Path = "/" + Path;
            hapConfig   config = hapConfig.Current;
            List <File> Items  = new List <File>();

            Homework.Homework i = Item(teacher, name, start, end);
            User user           = new User();

            if (config.AD.AuthenticationMode == Web.Configuration.AuthMode.Forms)
            {
                user.Authenticate(i.Teacher, TokenGenerator.ConvertToPlain(i.Token));
            }
            DriveMapping mapping;
            string       path = Converter.DriveToUNC(Path, Drive, out mapping, user);

            HAP.Data.SQL.WebEvents.Log(DateTime.Now, "MyFiles.Properties", user.UserName, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Browser.Platform, HttpContext.Current.Request.Browser.Browser + " " + HttpContext.Current.Request.Browser.Version, HttpContext.Current.Request.UserHostName, "Requesting properties of: " + path);
            user.ImpersonateContained();
            try
            {
                FileAttributes attr = System.IO.File.GetAttributes(path);
                //detect whether its a directory or file
                ret = ((attr & FileAttributes.Directory) == FileAttributes.Directory) ? new Properties(new DirectoryInfo(path), mapping, user) : new Properties(new FileInfo(path), mapping, user);
            }
            finally { user.EndContainedImpersonate(); }

            return(ret);
        }
Example #2
0
        public void Remove(Homework homework)
        {
            XmlNode teacher = _doc.SelectSingleNode("/homeworks/teacher[@user='******']");
            XmlNode node    = null;

            foreach (XmlNode n in teacher.SelectNodes("homework"))
            {
                if (n.Attributes["name"].Value == homework.Name && n.Attributes["start"].Value == homework.Start && n.Attributes["end"].Value == homework.End)
                {
                    node = n;
                }
            }
            teacher.RemoveChild(node);
            _doc.Save(HttpContext.Current.Server.MapPath("~/App_Data/Homework.xml"));
        }
Example #3
0
        public void Edit(string teacher, string name, string start, string end, string newname, string newstart, string newend, string description, string path, UserNode[] nodes)
        {
            Homeworks h = new Homeworks();

            Homework.Homework orig    = h.Homework.Single(hw => hw.Teacher == teacher && hw.Name == name && hw.Start == start.Replace('.', ':') && hw.End == end.Replace('.', ':'));
            Homework.Homework updated = orig;
            updated.Name        = name;
            updated.Start       = start;
            updated.End         = end;
            updated.Path        = path;
            updated.Description = HttpUtility.UrlDecode(description, System.Text.Encoding.Default);
            updated.UserNodes.Clear();
            updated.UserNodes.AddRange(nodes);
            User u = new User();

            u.Authenticate(updated.Teacher, TokenGenerator.ConvertToPlain(updated.Token));
            DriveMapping mapping;
            string       p = Converter.DriveToUNC(updated.Path.Remove(0, 1), updated.Path.Substring(0, 1), out mapping, u);

            u.ImpersonateContained();
            try
            {
                if (!Directory.Exists(p))
                {
                    Directory.CreateDirectory(p);
                }
                if (!Directory.Exists(Path.Combine(p, updated.Name)))
                {
                    Directory.CreateDirectory(Path.Combine(p, updated.Name));
                }
            }
            finally
            {
                u.EndContainedImpersonate();
            }
            h.Update(orig, updated);
        }