Beispiel #1
0
		private void attach_Measures(Measure entity)
		{
			this.SendPropertyChanging();
			entity.Volume = this;
		}
Beispiel #2
0
		private void detach_Measures(Measure entity)
		{
			this.SendPropertyChanging();
			entity.Volume = null;
		}
Beispiel #3
0
 partial void DeleteMeasure(Measure instance);
Beispiel #4
0
 partial void UpdateMeasure(Measure instance);
Beispiel #5
0
 partial void InsertMeasure(Measure instance);
Beispiel #6
0
        public ActionResult Computers(string method, string id)
        {
            string token = Request["token"];
            string userid = APITokens.GetUserID(token);

            if (method == "get")
            {

            }
            else if (method == "list")
            {
                string username = Request["user"];

                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("computers");

                DBDataContext db = new DBDataContext();

                IEnumerable<Computers> comps = from c in db.Computers orderby c.ComputerName ascending select c;

                if (!string.IsNullOrEmpty(username))
                    comps = from c in comps
                            where c.UserID.ToString().Equals(username)
                            select c;

                foreach (Computers c in comps)
                {
                    jw.Class();
                    jw.Field("id", c.ID);
                    jw.Field("name", c.ComputerName);
                    if (c.CreatedDate.HasValue)
                        jw.Field("date", c.CreatedDate.Value.ToString("R"));
                    if (c.Users != null)
                    {
                        jw.Field("userid", c.Users.UserID.ToString());
                        jw.Field("username", c.Users.UserName);
                    }

                    //					int totalused = (from v in db.Volumes, m in v.Measures select v.MeasureUsed select ).Sum();

                    int? totalused2 = 0;
                    try
                    {
                        totalused2 = (
                            from v2 in db.Volumes
                            where v2.ComputerID.Equals(c.ID)
                            select (
                            from m in v2.Measures where m.VolumeID.Equals(v2.ID) orderby m.MeasureDate descending select m.MeasureUsed
                            ).First()
                            ).Sum();

                    }
                    catch (Exception)
                    {
                    }

                    int? totalsize2 = 0;
                    try
                    {
                        totalsize2 = (
                            from v2 in db.Volumes
                            where v2.ComputerID.Equals(c.ID)
                            select (
                            from m in v2.Measures where m.VolumeID.Equals(v2.ID) orderby m.MeasureDate descending select m.MeasureSize
                            ).First()
                            ).Sum();
                    }
                    catch (Exception)
                    {
                    }

                    if (totalsize2.HasValue)
                        jw.Field("totalsize", totalsize2.Value);
                    else
                        jw.Field("totalsize", 0);

                    if (totalused2.HasValue)
                        jw.Field("totalused", totalused2.Value);
                    else
                        jw.Field("totalused", 0);

                    jw.Array("volumes");

                    IEnumerable<Volume> vols = from v in c.Volumes orderby v.VolumeName select v;
                    foreach (Volume v in vols)
                    {
                        jw.Class();
                        jw.Field("id", v.ID);
                        if (v.VolumeName != null)
                            jw.Field("name", v.VolumeName);
                        else
                            jw.Field("name", "");
                        int? numsamples = null;
                        try
                        {
                            numsamples = (from m in v.Measures where m.VolumeID.Equals(v.ID) select m).Count();
                        }
                        catch (Exception)
                        {
                        }

                        DateTime? lastsample = null;
                        try
                        {
                            lastsample = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureDate).First();
                        }
                        catch (Exception)
                        {
                        }

                        int? totalused = 0;
                        try
                        {
                            totalused = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureUsed).First();
                        }
                        catch (Exception)
                        {
                        }

                        int? totalsize = 0;
                        try
                        {
                            totalsize = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureSize).First();
                        }
                        catch (Exception)
                        {
                        }

                        jw.Field("samples", numsamples.Value);
                        if (lastsample.HasValue)
                            jw.Field("last", lastsample.Value.ToString("R"));
                        jw.Field("used", totalused.Value);
                        jw.Field("size", totalsize.Value);
                        jw.End();
                    }
                    jw.End();
                    jw.End();

                }

                jw.End();
                jw.End();

                return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty));

            }
            else if (method == "add")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");

                string un = Request["username"];

                // int compid = 0;
                // int.TryParse(Request["computer"], out compid);

                int volid = 0;
                int.TryParse(Request["volume"], out volid);

                int ds = 0;
                int.TryParse(Request["disksize"], out ds);

                int du = 0;
                int.TryParse(Request["diskused"], out du);

                DBDataContext db = new DBDataContext();

                var user = from u in db.Users where u.UserName.Equals(un) select u;
                if (user != null)
                {

                    Measure m = new Measure();

                    m.MeasureSize = ds;
                    m.MeasureUsed = du;
                    m.VolumeID = volid;
                    m.MeasureDate = DateTime.Now;

                    db.Measures.InsertOnSubmit(m);
                    db.SubmitChanges();

                    return new JSONResponseResult("ok");
                }
            }
            else if (method == "remove")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");
            }

            return new JSONResponseResult("unknown computers-command; method=" + method + ", id=" + id);
        }
Beispiel #7
0
        public ActionResult Measures(string method, string id)
        {
            string token = Request["token"];
            string userid = APITokens.GetUserID(token);

            if (method == "get")
            {

            }
            else if (method == "list")
            {
                int volumeid = 0;
                if (!string.IsNullOrEmpty(Request["volume"]))
                    int.TryParse(Request["volume"], out volumeid);

                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("measurements");

                DBDataContext db = new DBDataContext();

                var measurements = from m in db.Measures select m;
                if (volumeid != 0)
                    measurements = from m in measurements where m.VolumeID.Equals(volumeid) select m;

                measurements = from m in measurements orderby m.MeasureDate descending select m;

                foreach (Measure m in measurements)
                {
                    jw.Class();
                    jw.Field("id", m.ID);
                    if (m.MeasureDate.HasValue)
                        jw.Field("date", m.MeasureDate.Value.ToString("R"));
                    jw.Field("size", m.MeasureSize.ToString());
                    jw.Field("used", m.MeasureUsed.ToString());
                    jw.End();
                }

                jw.End();
                jw.End();

                return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty));

            }
            else if (method == "add")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");

                string un = Request["username"];

                // int compid = 0;
                // int.TryParse(Request["computer"], out compid);

                int volid = 0;
                int.TryParse(Request["volume"], out volid);

                int ds = 0;
                int.TryParse(Request["disksize"], out ds);

                int du = 0;
                int.TryParse(Request["diskused"], out du);

                DBDataContext db = new DBDataContext();

                var user = from u in db.Users where u.UserName.Equals(un) select u;
                if (user != null)
                {

                    Measure m = new Measure();

                    m.MeasureSize = ds;
                    m.MeasureUsed = du;
                    m.VolumeID = volid;
                    m.MeasureDate = DateTime.Now;

                    db.Measures.InsertOnSubmit(m);
                    db.SubmitChanges();

                    return new JSONResponseResult("ok");
                }
            }
            else if (method == "remove")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");

            }

            return new JSONResponseResult("unknown measures-command; method=" + method + ", id=" + id);
        }