Exemplo n.º 1
0
        public GumpAnimation(
            SuperGump gump,
            string name,
            int take,
            long delay,
            long duration,
            bool repeat,
            bool wait,
            object[] args,
            Action <GumpAnimation> handler)
        {
            Gump = gump;
            Name = name ?? String.Empty;

            UID = String.Format("{{{0} {1} {2}}}", Name, Gump.Serial, Gump.User.Serial.Value);

            take = Math.Max(-1, Math.Min(Gump.Entries.Count, take));

            Entries = new Stack <GumpEntry>(take == -1 ? Gump.Entries.Count : take);

            if (take == -1 || take > 0)
            {
                var count = Gump.Entries.Count;

                while (--count >= 0)
                {
                    if (count >= Gump.Entries.Count)
                    {
                        continue;
                    }

                    var e = Gump.Entries[count];

                    if (e == null || e == this || e is GumpAnimation)
                    {
                        continue;
                    }

                    if (e is GumpAnimationBreak)
                    {
                        break;
                    }

                    Entries.Push(e);

                    if (take != -1 && --take <= 0)
                    {
                        break;
                    }
                }
            }

            Handler = handler ?? _EmptyHandler;

            UID   = CryptoGenerator.GenString(CryptoHashType.MD5, UID);
            State = GumpAnimationState.Acquire(UID, delay, duration, repeat, wait);

            Args = args ?? new object[0];
        }
Exemplo n.º 2
0
        private VirtualAsset()
            : base(0, 0)
        {
            File = String.Empty;
            Name = String.Empty;
            Hash = CryptoGenerator.GenString(CryptoHashType.MD5, File);

            DefaultValue = Color.Transparent;
        }
Exemplo n.º 3
0
        private static bool Deserialize(XmlDocument doc)
        {
            VitaNexCore.TryCatch(
                () =>
            {
                if (doc.FirstChild == null || doc.FirstChild.Name != "messages")
                {
                    return;
                }

                XmlElement root = doc["messages"];

                if (root == null)
                {
                    return;
                }

                MOTDMessage message;
                TimeStamp date;
                bool published;
                string author, title, content, uid;

                foreach (XmlElement node in root)
                {
                    VitaNexCore.TryCatch(
                        () =>
                    {
                        date = node.HasAttribute("timestamp")
                                                                                   ? (TimeStamp)Double.Parse(node.GetAttribute("timestamp"))
                                                                                   : TimeStamp.UtcNow;
                        published = !node.HasAttribute("published") || Boolean.Parse(node.GetAttribute("published"));
                        author    = node.HasAttribute("author") ? node.GetAttribute("author") : "Anonymous";
                        title     = node.HasAttribute("title") ? node.GetAttribute("title") : "Update";
                        content   = node["content"] != null ? node["content"].InnerText.Replace(@"\r\n", "[br]") : String.Empty;

                        uid = node.HasAttribute("uid")
                                                                                  ? node.GetAttribute("uid")
                                                                                  : CryptoGenerator.GenString(CryptoHashType.MD5, String.Format("{0}", date.Stamp)).Replace("-", "");

                        message = new MOTDMessage(uid, date, title, content, author, published);

                        if (Messages.ContainsKey(uid))
                        {
                            Messages[uid] = message;
                        }
                        else
                        {
                            Messages.Add(uid, message);
                        }
                    },
                        CMOptions.ToConsole);
                }
            },
                CMOptions.ToConsole);

            return(true);
        }
Exemplo n.º 4
0
        private VirtualAsset(FileInfo file, Bitmap img)
            : base(img.Width, img.Height)
        {
            File = file.FullName;
            Name = Path.GetFileName(File);
            Hash = CryptoGenerator.GenString(CryptoHashType.MD5, File);

            DefaultValue = Color.Transparent;
            SetAllContent(img.GetPixel);
        }
Exemplo n.º 5
0
        public static VirtualAsset CreateInstance(FileInfo file, bool cache, bool reload)
        {
            if (file == null || !file.Exists)
            {
                return(Empty);
            }

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                var hash = CryptoGenerator.GenString(CryptoHashType.MD5, file.FullName);

                VirtualAsset a;

                lock (_CacheLock)
                {
                    if (!AssetCache.TryGetValue(hash, out a))
                    {
                        a = Empty;
                    }
                }

                if (reload || IsNullOrEmpty(a))
                {
                    using (var img = new Bitmap(file.FullName, true))
                    {
                        a = new VirtualAsset(file, img);
                    }
                }

                if (IsNullOrEmpty(a))
                {
                    return Empty;
                }

                lock (_CacheLock)
                {
                    if (cache)
                    {
                        AssetCache[a.Hash] = a;
                    }
                    else
                    {
                        AssetCache.Remove(a.Hash);
                    }

                    if (AssetCache.Count > CacheCapacity)
                    {
                        AssetCache.Pop();
                    }
                }

                return a;
            }));
        }
Exemplo n.º 6
0
 public BaseTrashHandler(
     bool enabled,
     TrashPriority priority     = TrashPriority.Normal,
     IEnumerable <Type> accepts = null,
     IEnumerable <Type> ignores = null)
 {
     UID      = CryptoGenerator.GenString(CryptoHashType.MD5, GetType().FullName);
     Enabled  = enabled;
     Priority = priority;
     Accepted = new List <Type>(accepts ?? DefaultAcceptList);
     Ignored  = new List <Type>(ignores ?? DefaultIgnoredList);
 }
Exemplo n.º 7
0
        protected virtual void OnConfirmCreateMessage(GumpButton button, string title)
        {
            TimeStamp date   = TimeStamp.UtcNow;
            string    author = User.RawName;

            const string content = "Content - BBCode supported:<br>[B]B, U, I, BIG, SMALL, URL, COLOR[/B]";

            string uid = CryptoGenerator.GenString(CryptoHashType.MD5, String.Format("{0}", date.Stamp)).Replace("-", "");

            Selected = new MOTDMessage(uid, date, title, content, author);

            if (MOTD.Messages.ContainsKey(uid))
            {
                MOTD.Messages[uid] = Selected;
            }
            else
            {
                MOTD.Messages.Add(uid, Selected);
            }

            MOTD.Messages.Export();

            Refresh(true);

            if (UseConfirmDialog)
            {
                Send(
                    new ConfirmDialogGump(
                        User,
                        this,
                        title: "View Message?",
                        html: "Your message has been created.\nDo you want to view it now?",
                        onAccept: subButton => Send(new MOTDMessageOverviewGump(User, this, Selected))));
            }
            else
            {
                Send(new MOTDMessageOverviewGump(User, this, Selected));
            }
        }
Exemplo n.º 8
0
        public static SuperGumpAsset CreateInstance(FileInfo file, bool cache, bool reload)
        {
            if (file == null || !file.Exists)
            {
                return(Empty);
            }

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                var hash = CryptoGenerator.GenString(CryptoHashType.MD5, file.FullName);

                SuperGumpAsset a;

                lock (_CacheLock)
                {
                    a = AssetCache.FirstOrDefault(ca => ca.Hash == hash);
                }

                if (a == null || reload)
                {
                    using (var img = new Bitmap(file.FullName, true))
                    {
                        a = new SuperGumpAsset(file, img);

                        if (cache)
                        {
                            lock (_CacheLock)
                            {
                                AssetCache.AddOrReplace(a);
                            }
                        }
                    }
                }

                if (IsNullOrEmpty(a))
                {
                    return Empty;
                }

                if (!cache || a.Capacity > 0x1000)
                {
                    lock (_CacheLock)
                    {
                        AssetCache.Remove(a);
                        AssetCache.Free(false);
                    }
                }

                lock (_CacheLock)
                {
                    if (AssetCache.Count > 100)
                    {
                        AssetCache.RemoveAt(0);
                    }

                    AssetCache.Free(false);
                }

                return a;
            },
                       VitaNexCore.ToConsole));
        }