Ejemplo n.º 1
0
 internal static FlagCollection Single()
 {
     if (_flagCollection == null)
     {
         _flagCollection = new FlagCollection();
     }
     return(_flagCollection);
 }
Ejemplo n.º 2
0
 public override void DefaultFlags(FlagCollection flags)
 {
     flags.Add('v', "verbose", "Outputs additional information", false);
     flags.Add('w', "wait", "Waits for enter before closing the console", false);
     flags.Add('p', "progress", "Display a progress bar", false);
     flags.Add('r', "raw", "Disables auto-conversion of binary files", false);
     flags.Add('e', "excel", "Uses ; instead of , as csv delimiter", false);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Email objects will be marked as unread and moved to a different folder for the next iteration
 /// </summary>
 /// <param name="unread"></param>
 /// <param name="markAsUnreadFlag"></param>
 /// <param name="inbox"></param>
 private static void MarkAsUnread(int[] unread, FlagCollection markAsUnreadFlag, Mailbox inbox)
 {
     foreach (var item in unread)
     {
         markAsUnreadFlag.Add(OutlookConstant.OutlookSeenMessages);
         inbox.RemoveFlags(item, markAsUnreadFlag);
         inbox.MoveMessage(item, OutlookConstant.OutlookProcessedFolder);
     }
 }
Ejemplo n.º 4
0
        private void StoreMessageToImapSentFolder(MailBox mbox, Message mime_message)
        {
            if (mime_message == null || !mbox.Imap)
            {
                return;
            }

            var imap = MailClientBuilder.Imap();

            try
            {
                imap.AuthenticateImap(mbox, log);

                // reverse folders and order them to download tagged incoming messages first
                // gmail returns tagged letters in mailboxes & duplicate them in inbox
                // to retrieve tags - first we need to download files from "sub" mailboxes
                var sent_folder =
                    imap.GetImapMailboxes(mbox.Server, MailQueueItemSettings.SpecialDomainFolders,
                                          MailQueueItemSettings.SkipImapFlags, MailQueueItemSettings.ImapFlags)
                    .FirstOrDefault(m => m.folder_id == MailFolder.Ids.sent);

                if (sent_folder == null)
                {
                    throw new InvalidDataException(String.Format("Cannot find Sent folder over Imap. MailboxId={0}",
                                                                 mbox.MailBoxId));
                }

                var mb_obj = imap.SelectMailbox(sent_folder.name);

                var flags = new FlagCollection {
                    "Seen"
                };

                var response = mb_obj.Append(mime_message, flags);

                log.Info("StoreMessageToImapSentFolder() in MailboxId={0} successed! Returned: '{0}'", response);
            }
            catch (Exception ex)
            {
                log.Error("StoreMessageToSentFolder() in MailboxId={0} failed with exception:\r\n{1}",
                          mbox.MailBoxId, ex.ToString());
            }
            finally
            {
                try
                {
                    if (imap.IsConnected)
                    {
                        imap.Disconnect();
                    }
                }
                catch
                {
                }
            }
        }
        public void BitVectorTest()
        {
            FlagCollection <object, int> flagCollection = new FlagCollection <object, int>(converter);

            flagCollection.Add(new object(), -100);
            flagCollection.Add(new object(), 100);
            IList <int> list = new List <int>(flagCollection.Values);

            Assert.AreEqual(-1, list[0]);
            Assert.AreEqual(1, list[1]);
        }
        public void AddTest()
        {
            Random random = RandomManager.CreateRandom((int)DateTime.Now.Ticks);
            FlagCollection <object, int> flagCollection = new FlagCollection <object, int>(converter);

            for (int i = 0; i < ItemCount; i++)
            {
                flagCollection.Add(new object(), random.Next(-100, 100));
            }
            Assert.AreEqual(ItemCount, flagCollection.Count);

            FlagCollection <object, int> flagCollection1 = new FlagCollection <object, int>(converter, flagCollection);

            Assert.AreEqual(flagCollection, flagCollection1);
        }
Ejemplo n.º 7
0
        private void _bSetFlag_Click(object sender, EventArgs e)
        {
            try
            {
                int            index = int.Parse(_lvMessages.SelectedItems[0].Text);
                FlagCollection flags = new FlagCollection();
                flags.Add("Answered");
                inbox.SetFlags(1, flags);

                this.AddLogEntry(string.Format("Flat answered setted to the message with index {0}", index.ToString()));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
Ejemplo n.º 8
0
        static Servicer()
        {
            List <Pair <AsStep, Regex> > regexs = new List <Pair <AsStep, Regex> >();

            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_e4, new Regex(@"^[a-h][1-8]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_Rd7, new Regex(@"^[RNBQK][a-h][1-8]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_Rxa2, new Regex(@"^[RNBQK]x[a-h][1-8]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_Rbe1, new Regex(@"^[RNBQK][a-h][a-h][1-8]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_N1c3, new Regex(@"^[RNBQK][1-8][a-h][1-8]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_hxg6, new Regex(@"^[a-h]x[a-h][1-8]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_O_O, new Regex(@"^[O]-[O]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_O_O_O, new Regex(@"^[O]-[O]-[O]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_Ngxf6, new Regex(@"^[RNBQK][a-h]x[a-h][1-8]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_R8xf5, new Regex(@"^[RNBQK][1-8]x[a-h][1-8]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_e8_Q, new Regex(@"^[a-h][1-8]=[RNBQ]$", RegexOptions.Compiled)));
            regexs.Add(new Pair <AsStep, Regex>(AsStep.As_exf8_Q, new Regex(@"^[a-h]x[a-h][1-8]=[RNBQ]$", RegexOptions.Compiled)));
            StepRegex = regexs.ToArray();
            Flags     = FlagCollection.Single();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Deletes a set of E-Mails by their messageID from a given mailbox
        /// </summary>
        /// <param name="messages">The IDs of the messages to delete</param>
        /// <param name="mailBoxName">The mailbox to delete the messages from</param>
        public void DeleteMails(List <EMail> messages, string mailBoxName)
        {
            if (messages.Count < 1)
            {
                return;
            }
            // get the mailbox
            Mailbox mailBox = Client.SelectMailbox(mailBoxName);

            // create a collection of flags to set for the emails
            var flags = new FlagCollection();

            // set only the deleted flag
            flags.Add(new Flag("DELETED"));


            // set the flag for each email in the messageIds
            try
            {
                Logging.Log.Info($"Deleting {messages.Count} mails from '{mailBoxName}'");
                if (mailBoxName == "INBOX")
                {
                    foreach (var mail in messages)
                    {
                        mailBox.SetFlags(mail.InBoxID, flags);
                    }
                }
                else
                {
                    foreach (var mail in messages)
                    {
                        mailBox.SetFlags(mail.PayPalFolderID, flags);
                    }
                }
                Logging.Log.Info($"Finished deleting {messages.Count} mails from '{mailBoxName}'");
            }
            catch (Exception ex)
            {
                Logging.Log.Error($"{ex.Message}:{ex.StackTrace}");
            }

            Client.Expunge();
        }
Ejemplo n.º 10
0
        private static void CopyItemsFromSourceToTarget(Options options, IEnumerable <Item> targetItems)
        {
            Console.WriteLine("Copying items from the source to the target ...");
            Connect(options.TargetHost, options.TargetPort, options.TargetUsername, options.TargetPassword, options.TargetFolder, options.TargetUseSsl,
                    (targetServer, targetMailbox) =>
            {
                Connect(options.SourceHost, options.SourcePort, options.SourceUsername, options.SourcePassword, options.SourceFolder, options.SourceUseSsl,
                        (sourceServer, sourceMailbox) =>
                {
                    var count = sourceMailbox.MessageCount;
                    for (var i = options.StartCopyingAt; i <= count; i++)
                    {
                        var rawHeader    = sourceMailbox.Fetch.Header(i);
                        var parsedHeader = Parser.ParseHeader(rawHeader);

                        Console.WriteLine("\t Downloaded {0}/{1}: '[{2}] {3}'", i, count, parsedHeader.Date, parsedHeader.Subject);

                        if (targetItems.Any(x => x.Subject == parsedHeader.Subject && x.Date == parsedHeader.Date))
                        {
                            Console.WriteLine("\t\t Skipped.");
                        }
                        else
                        {
                            try
                            {
                                var rawMessage = sourceMailbox.Fetch.Message(i);

                                var flags = new FlagCollection {
                                    new Flag("\\Seen")
                                };
                                targetMailbox.Append(rawMessage, flags, parsedHeader.Date.ToUniversalTime());
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("\t\t Error: " + ex.Message);
                            }
                        }
                    }
                });
            });
        }
Ejemplo n.º 11
0
        public void MoveEmailRead(string SourceMailBox, string DestinationMailBox, string MessageId)
        {
            Mailbox mails = Client.SelectMailbox(SourceMailBox);

            int[] ids = mails.Search("ALL");

            if (ids.Length > 0)
            {
                for (var i = 0; i < ids.Length; i++)
                {
                    if (MessageId.Contains(Convert.ToString(ids[i])))
                    {
                        Client.Command("copy " + ids[i].ToString() + DestinationMailBox); //copy emails

                        FlagCollection flags = new FlagCollection();                      //delete emails
                        flags.Add("Deleted");
                        mails.AddFlags(ids[i], flags);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Method marks all READ mail as UNREAD MAIL.
        /// Method fetched the messageObject which automatically marks a message as read
        /// </summary>
        public void markMsgObjAsUnread()
        {
            Imap4Client    client           = new Imap4Client();
            FlagCollection markAsUnreadFlag = new FlagCollection();

            try
            {
                //Authenticate
                client.ConnectSsl(Constant.OutlookImapHost, Constant.ImapPort);
                client.Login(Constant.OutlookUserName, Constant.GenericPassword);

                //stage the enviornment
                Mailbox inbox       = client.SelectMailbox("inbox");
                int[]   allMessages = inbox.Search("ALL");

                Console.WriteLine("Message-Count: " + allMessages.Length);

                //Itearate and mark each mail object as unread
                foreach (var id in allMessages)
                {
                    Message msg = inbox.Fetch.MessageObject(id);
                    markAsUnreadFlag.Add("SEEN"); //adding all the read email objects to the flag collection
                    inbox.RemoveFlags(id, markAsUnreadFlag);
                    //then removing the flags, making each mail object as unread
                }
            }
            catch (Imap4Exception ie)
            {
                Console.WriteLine(string.Format("Imap4 Exception: {0}", ie.Message));
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("Unexpected Exception: {0}"), e.Message);
            }
            finally
            {
                client.Disconnect();
            }
        }
        public void EnsureMessagesCanBeMarkedAsUnread()
        {
            Imap4Client client = new Imap4Client();

            client.ConnectSsl("imap-mail.outlook.com", 993);
            client.Login("*****@*****.**", "secret");

            Mailbox        inbox = client.SelectMailbox("Test");
            FlagCollection markAsUnreadFlagCollection = new FlagCollection();

            int[] inboxMessages = inbox.Search("ALL");

            foreach (var msg in inboxMessages)
            {
                Message m = inbox.Fetch.MessageObject(msg);
                markAsUnreadFlagCollection.Add("SEEN");
                inbox.RemoveFlags(msg, markAsUnreadFlagCollection);
            }

            int[] unreadEmailMessages = inbox.Search("UNSEEN");

            Assert.AreEqual(12, unreadEmailMessages.Length);
        }
Ejemplo n.º 14
0
        public void AddRemoveTest()
        {
            Random random = RandomManager.CreateRandom((int)DateTime.Now.Ticks);
            List <KeyValuePair <object, int> > collection = new List <KeyValuePair <object, int> >();

            for (int i = 0; i < ItemCount; i++)
            {
                collection.Add(new KeyValuePair <object, int>(new object(), random.Next(-100, 100)));
            }
            FlagCollection <object, int> flagCollection = new FlagCollection <object, int>(converter, collection);

            for (int i = 0; i < ItemCount; i++)
            {
                KeyValuePair <object, int> pair = collection[i];
                Assert.AreEqual(pair.Key, flagCollection[i].Key);
                Assert.AreEqual(pair.Value >= 0, flagCollection[pair.Key] >= 0);
            }

            foreach (KeyValuePair <object, int> pair in collection)
            {
                flagCollection.Remove(pair.Key);
            }
            Assert.AreEqual(0, flagCollection.Count);
        }
Ejemplo n.º 15
0
    public void MoveTOProcessedFolder(string fromMailBox, string toMailBox, string strMsgId)
    {
        //Copy and delete from fromMailBox folder to toMailBox folder
        FlagCollection flags;
        Mailbox        mails = Client.SelectMailbox(fromMailBox);

        int[] ids = mails.Search("ALL");
        if (ids.Length > 0)
        {
            ActiveUp.Net.Mail.Message msg = null;
            for (var i = 0; i < ids.Length; i++)
            {
                msg = mails.Fetch.MessageObject(ids[i]);
                if (strMsgId.Contains(Convert.ToString(ids[i])))
                {
                    Client.Command("copy " + ids[i].ToString() + toMailBox); //copy emails

                    flags = new FlagCollection();                            //delete emails
                    flags.Add("Deleted");
                    mails.AddFlags(ids[i], flags);
                }
            }
        }
    }
Ejemplo n.º 16
0
 public override void DefaultFlags(FlagCollection flags)
 {
     flags.Add('v', "verbose", "Outputs additional information", false);
     flags.Add('w', "wait", "Waits for enter before closing the console", false);
 }
Ejemplo n.º 17
0
 public override void DefaultFlags(FlagCollection flags)
 {
     flags.Add('v', "verbose", "Outputs additional information", false);
     flags.Add('w', "wait", "Waits for enter before closing the console", false);
     flags.Add('e', "excel", "Uses ; instead of , as csv delimiter", false);
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Parses unread email objects, and creates user stories with attachments from the data provided in an email object
        /// </summary>
        /// <param name="workspace"></param>
        /// <param name="project"></param>
        public void SyncUserStories(string workspace, string project)
        {
            _unreadMsgCollection.Capacity      = 25;
            _toCreate[RallyConstant.WorkSpace] = workspace;
            _toCreate[RallyConstant.Project]   = project;

            try
            {
                LoginToOutlook();
                LoginToRally();

                _inbox            = _imap4Client.SelectMailbox(OutlookConstant.OutlookInboxFolder);
                _unreadMsg        = _inbox.Search(OutlookConstant.OutlookUnseenMessages);
                _markAsUnreadFlag = new FlagCollection();

                if (UnreadMessageLength(_unreadMsg) > 0)
                {
                    Console.WriteLine("Syncing: " + _unreadMsg.Length + " Unread Messages");
                    FetchUnreadMessages(_unreadMsg, _inbox);

                    for (int i = 0; i < _unreadMsgCollection.Count; i++)
                    {
                        if (string.IsNullOrWhiteSpace(_unreadMsgCollection[i].Subject))
                        {
                            _unreadMsgCollection[i].Subject = OutlookConstant.NoSubject;
                        }

                        _toCreate[RallyConstant.Name]          = (_unreadMsgCollection[i].Subject);
                        _toCreate[RallyConstant.Description]   = (_unreadMsgCollection[i].BodyText.Text);
                        _toCreate[RallyConstant.PortfolioItem] = RallyQueryConstant.FeatureShareProject;
                        _createUserStory = _rallyApi.Create(RallyConstant.HierarchicalRequirement, _toCreate);

                        if (_unreadMsgCollection[i].Attachments.Count > 0)
                        {
                            _unreadMsgCollection[i].Attachments.StoreToFolder(SyncConstant.AttachmentsDirectory);
                        }

                        #region inLineImage
                        if (_unreadMsgCollection[i].EmbeddedObjects.Count > 0)
                        {
                            foreach (MimePart embeddedImg in _unreadMsgCollection[i].EmbeddedObjects)
                            {
                                DownloadInlineAttachments(embeddedImg);
                                PopulateInlineAttachments();
                                PushAttachments(_attachmentsDictionary, _attachmentContent, _attachmentContainer, _createUserStory);
                                _attachmentsDictionary.Clear();
                            }
                        }
                        #endregion

                        PopulateAttachmentsDictionary();
                        PushAttachments(_attachmentsDictionary, _attachmentContent, _attachmentContainer, _createUserStory);
                        _attachmentsDictionary.Clear();
                    }

                    MarkAsUnread(_unreadMsg, _markAsUnreadFlag, _inbox);
                    Console.WriteLine("Created " + _unreadMsg.Length + " User Stories");
                }
                else
                {
                    Console.WriteLine("Inbox does not contain unread messages");
                }
            }
            catch (Imap4Exception imap)
            {
                Console.WriteLine(imap.Message);
            }
            catch (IOException io)
            {
                Console.WriteLine(io.Message);
            }
            catch (WebException we)
            {
                Console.WriteLine(we.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                _imap4Client.Disconnect();
            }
        }
Ejemplo n.º 19
0
 public override void DefaultFlags(FlagCollection flags)
 {
 }
Ejemplo n.º 20
0
 private void OnEnable()
 {
     gameState = this;
     flags     = new FlagCollection(state.flags);
 }
Ejemplo n.º 21
0
        private static Race LoadRace(PropertyBag raceProp, DropMacroCollection <Item> dropMacros, Content content,
                                     out int depth, out int rarity)
        {
            Character character = new Character('*', TermColor.Purple);

            PropertyBag art;

            if (raceProp.TryGetValue("art", out art))
            {
                //### bob: old style color and glyph combined
                character = Character.Parse(art.Value);
            }
            else
            {
                // separate glyph and color
                character = new Character(
                    Character.ParseGlyph(raceProp["glyph"].Value),
                    TermColors.FromName(raceProp["color"].Value));
            }

            // depth
            depth = raceProp["depth"].ToInt32();

            // speed
            int speed = raceProp.GetOrDefault("speed", 0) + Energy.NormalSpeed;

            // health
            Roller health = Roller.Parse(raceProp["health"].Value);

            // rarity
            rarity = raceProp.GetOrDefault("rarity", 1);

            // create the race
            Race race = new Race(content, raceProp.Name, depth, character, speed, health);

            // attacks
            PropertyBag attacks;

            if (raceProp.TryGetValue("attacks", out attacks))
            {
                foreach (PropertyBag attackProp in attacks)
                {
                    string[] attackParts = attackProp.Value.Split(' ');

                    // create the attack
                    Roller damage = Roller.Parse(attackParts[0]);

                    FlagCollection flags   = new FlagCollection();
                    Element        element = Element.Anima;

                    // add the flags or element
                    for (int i = 1; i < attackParts.Length; i++)
                    {
                        try
                        {
                            // see if the part is an element
                            element = (Element)Enum.Parse(typeof(Element), attackParts[i], true);
                        }
                        catch (ArgumentException)
                        {
                            // must be a flag
                            flags.Add(attackParts[i]);
                        }
                    }

                    //### bob: need to support different effect types
                    Attack attack = new Attack(damage, 0, 1.0f, element, attackProp.Name, EffectType.Hit, flags);

                    race.Attacks.Add(attack);
                }
            }

            // moves
            PropertyBag moves;

            if (raceProp.TryGetValue("moves", out moves))
            {
                foreach (PropertyBag moveProp in moves)
                {
                    string moveName = moveProp.Name;

                    // if an explicit move field is provided, then the prop name is not the name of the move itself
                    PropertyBag explicitMove;
                    if (moveProp.TryGetValue("move", out explicitMove))
                    {
                        moveName = explicitMove.Value;
                    }

                    // parse the specific move info
                    MoveInfo info = ParseMove(moveProp);

                    Move move;

                    // construct the move
                    switch (moveName)
                    {
                    case "haste self": move = new HasteSelfMove(); break;

                    case "ball self": move = new BallSelfMove(); break;

                    case "cone": move = new ElementConeMove(); break;

                    case "breathe": move = new BreatheMove(); break;

                    case "bolt": move = new BoltMove(); break;

                    case "message": move = new MessageMove(); break;

                    case "breed": move = new BreedMove(); break;

                    default:
                        throw new Exception("Unknown move \"" + moveName + "\".");
                    }

                    move.BindInfo(info);

                    race.Moves.Add(move);
                }
            }

            // flags
            foreach (PropertyBag childProp in raceProp)
            {
                if (childProp.Name.StartsWith("+ "))
                {
                    string flag = childProp.Name.Substring(2).Trim();

                    // handle the flags
                    switch (flag)
                    {
                    case "groups":              race.SetGroupSize(GroupSize.Group); break;

                    case "packs":               race.SetGroupSize(GroupSize.Pack); break;

                    case "swarms":              race.SetGroupSize(GroupSize.Swarm); break;

                    case "hordes":              race.SetGroupSize(GroupSize.Horde); break;

                    case "very-bright":         race.SetLightRadius(2); break;

                    case "bright":              race.SetLightRadius(1); break;

                    case "glows":               race.SetLightRadius(0); break;

                    case "unmoving":            race.SetPursue(Pursue.Unmoving); break;

                    case "slightly-erratic":    race.SetPursue(Pursue.SlightlyErratically); break;

                    case "erratic":             race.SetPursue(Pursue.Erratically); break;

                    case "very-erratic":        race.SetPursue(Pursue.VeryErratically); break;

                    case "unique":              race.SetFlag(RaceFlags.Unique); break;

                    case "boss":                race.SetFlag(RaceFlags.Boss); break;

                    case "opens-doors":         race.SetFlag(RaceFlags.OpensDoors); break;

                    default: Console.WriteLine("Unknown flag \"{0}\"", flag); break;
                    }
                }
            }

            // resists
            PropertyBag resists;

            if (raceProp.TryGetValue("resists", out resists))
            {
                ParseResists(resists.Value, race);
            }

            // drops
            PropertyBag drops;

            if (raceProp.TryGetValue("drops", out drops))
            {
                var          parser = new ItemDropParser(content);
                IDrop <Item> drop   = parser.ParseDefinition(drops, dropMacros);
                race.SetDrop(drop);
            }

            // description
            PropertyBag description;

            if (raceProp.TryGetValue("description", out description))
            {
                race.SetDescription(description.Value);
            }

            // groups
            PropertyBag groups;

            if (raceProp.TryGetValue("groups", out groups))
            {
                race.SetGroups(groups.Value.Split(' '));
            }

            return(race);
        }
Ejemplo n.º 22
0
 public PackTask(string[] arguments, FlagCollection flags) : base(arguments, flags)
 {
 }
Ejemplo n.º 23
0
 public override void DefaultFlags(FlagCollection flags)
 {
     flags.Add('v', "verbose", "Outputs additional information", false);
     flags.Add('w', "wait", "Waits for enter before closing the console", false);
     flags.Add('i', "init", "Initialize a new deployment resource");
 }
Ejemplo n.º 24
0
 public override void DefaultFlags(FlagCollection flags)
 {
     flags.Add('v', "verbose", "Enables logging of additional information", false);
 }