示例#1
0
文件: API.cs 项目: spotnet/fusenet
        internal static bool Slots(XmlWriter xR, Slots vSlots)
        {
            xR.WriteStartElement("queue");

            NNTPInfo vInfo = vSlots.Info;

            string sLeft    = "00:00:00";
            string ETA      = Common.FormatDate(DateTime.UtcNow);
            int    lSeconds = vInfo.SecondsLeft(vSlots.SpeedAverage, vSlots.TotalTime);

            if (lSeconds > 0)
            {
                sLeft = new TimeSpan(0, 0, 0, lSeconds, 0).ToString("c");
                ETA   = Common.FormatDate(DateTime.UtcNow.AddSeconds(lSeconds));
            }

            xR.WriteElementString("status", vSlots.Status);
            xR.WriteElementString("paused", Common.BoolToString(vSlots.Paused));
            xR.WriteElementString("mb", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Common.BytesToMegabytes(Math.Abs(vInfo.Expected))));
            xR.WriteElementString("mbleft", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Common.BytesToMegabytes(Math.Abs(vInfo.BytesLeft))));
            xR.WriteElementString("kbpersec", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", vSlots.Speed / (decimal)1000));

            xR.WriteElementString("eta", ETA);
            xR.WriteElementString("timeleft", sLeft);

            xR.WriteElementString("uptime", Common.FormatElapsed(vSlots.Uptime));
            xR.WriteElementString("start", "0");
            xR.WriteElementString("limit", "0");
            xR.WriteElementString("speedlimit", "0");
            xR.WriteElementString("noofslots", Convert.ToString(vSlots.Count));

            xR.WriteElementString("have_warnings", Convert.ToString(vSlots.Log.Count));

            if (vSlots.Log.Count > 0)
            {
                string sWarning = Common.ReadLog(vSlots.Log, 1).Replace(Environment.NewLine, "");
                xR.WriteElementString("last_warning", Common.CleanString(sWarning));
            }

            // TODO Server.Log
            foreach (VirtualSlot vSlot in vSlots.List())
            {
                if (!(Slot(xR, vSlot)))
                {
                    return(false);
                }
            }

            xR.WriteEndElement();
            xR.Flush();

            return(true);
        }
示例#2
0
        internal static NNTPInfo CountInfo(List<VirtualItem> cList)
        {
            long cA = 0, cT = 0, cE = 0,  cB = 0;

            foreach (VirtualItem zItem in cList)
            {
                if (zItem != null)
                {
                    NNTPInfo zInfo = zItem.Info;

                    cT += zInfo.Total;
                    cE += zInfo.Expected;
                    cA += zInfo.Available;
                    cB += zInfo.BytesDone;
                }
            }

            return new NNTPInfo(cA, cE, cT, cB);
        }
示例#3
0
文件: API.cs 项目: spotnet/fusenet
        internal static bool Slot(XmlWriter xR, VirtualSlot vSlot)
        {
            xR.WriteStartElement("slot");
            xR.WriteElementString("nzo_id", Convert.ToString(vSlot.ID));
            xR.WriteElementString("name", Common.CleanString(vSlot.Name));
            xR.WriteElementString("filename", Common.CleanString(vSlot.Name));
            xR.WriteElementString("status", Common.TranslateStatus((int)vSlot.Status));

            if (vSlot.Status == SlotStatus.Failed)
            {
                xR.WriteElementString("fail_message", Common.CleanString(vSlot.StatusLine));
            }

            if (!(vSlot.History))
            {
                NNTPInfo vInfo    = vSlot.Info;
                int      lSeconds = vInfo.SecondsLeft(vSlot.SpeedAverage, vSlot.TotalTime);

                string sLeft = "00:00:00";
                string ETA   = Common.FormatDate(DateTime.UtcNow);

                if (lSeconds > 0)
                {
                    sLeft = Common.FormatElapsed(new TimeSpan(0, 0, lSeconds));
                    ETA   = Common.FormatDate(DateTime.UtcNow.AddSeconds(lSeconds));
                }

                xR.WriteElementString("index", Convert.ToString(vSlot.Index));
                xR.WriteElementString("percentage", Convert.ToString(Math.Round(vInfo.Percentage, 0)));
                xR.WriteElementString("bytes", Convert.ToString(vInfo.Expected));
                xR.WriteElementString("kbpersec", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", vSlot.Speed / (decimal)1000));
                xR.WriteElementString("mb", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Common.BytesToMegabytes(vInfo.Expected)));
                xR.WriteElementString("mbleft", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Common.BytesToMegabytes(vInfo.BytesLeft)));
                xR.WriteElementString("size", String.Format(CultureInfo.InvariantCulture, "{0:0.0}", Common.BytesToMegabytes(vInfo.Expected)) + " MB");
                xR.WriteElementString("eta", ETA);
                xR.WriteElementString("timeleft", sLeft);
                xR.WriteElementString("priority", "Normal");
            }
            else
            {
                if (vSlot.Status == SlotStatus.Failed)
                {
                }
                else
                {
                    //<slot>
                    //    <loaded>False</loaded>
                    //    <id>605</id>
                    //    <size>778.1 MB</size>
                    //    <pp>D</pp>
                    //    <completeness>0</completeness>
                    //    <nzb_name>Ubuntu.nzb</nzb_name>
                    //    <storage>X:\Apps\Ubuntu</storage>
                    //    <completed>1236646078</completed>
                    //    <downloaded>815878352</downloaded>
                    //    <report>00000000</report>
                    //    <path>\Ubuntu</path>
                    //    <bytes>815878352</bytes>
                    //</slot>
                }
            }

            xR.WriteEndElement();
            xR.Flush();

            return(true);
        }