Exemple #1
0
        /// <summary> Given the 2 maps fills a document for 1 word.</summary>
        private static int Index(System.Collections.IDictionary word2Nums, System.Collections.IDictionary num2Words, System.String g, Document doc)
        {
            System.Collections.IList       keys = (System.Collections.IList)word2Nums[g];        // get list of key#'s
            System.Collections.IEnumerator i2   = keys.GetEnumerator();

            System.Collections.SortedList already = new System.Collections.SortedList();             // keep them sorted

            // pass 1: fill up 'already' with all words
            while (i2.MoveNext())                                                        // for each key#
            {
                foreach (object item in (System.Collections.IList)num2Words[i2.Current]) // get list of words
                {
                    if (already.Contains(item) == false)
                    {
                        already.Add(item, item);
                    }
                }
            }
            int num = 0;

            already.Remove(g);             // of course a word is it's own syn
            System.Collections.IDictionaryEnumerator it = already.GetEnumerator();
            while (it.MoveNext())
            {
                System.String cur = (System.String)it.Key;
                // don't store things like 'pit bull' -> 'american pit bull'
                if (!IsDecent(cur))
                {
                    continue;
                }
                num++;
                doc.Add(new Field(F_SYN, cur, Field.Store.YES, Field.Index.NO));
            }
            return(num);
        }
Exemple #2
0
        /// <summary> Check the hits for duplicates.</summary>
        /// <param name="hits">
        /// </param>
        private void  CheckHits(ScoreDoc[] hits, System.String prefix)
        {
            if (hits != null)
            {
                System.Collections.IDictionary idMap = new System.Collections.SortedList();
                for (int docnum = 0; docnum < hits.Length; ++docnum)
                {
                    System.Int32 luceneId;

                    luceneId = (System.Int32)hits[docnum].doc;
                    if (idMap.Contains(luceneId))
                    {
                        System.Text.StringBuilder message = new System.Text.StringBuilder(prefix);
                        message.Append("Duplicate key for hit index = ");
                        message.Append(docnum);
                        message.Append(", previous index = ");
                        message.Append(((System.Int32)idMap[luceneId]).ToString());
                        message.Append(", Lucene ID = ");
                        message.Append(luceneId);
                        Log(message.ToString());
                    }
                    else
                    {
                        idMap[luceneId] = (System.Int32)docnum;
                    }
                }
            }
        }
Exemple #3
0
        // make sure the documents returned by the search match the expected list
        private void  MatchHits(Searcher searcher, Sort sort)
        {
            // make a query without sorting first
            ScoreDoc[] hitsByRank = searcher.Search(query, null, 1000).scoreDocs;
            CheckHits(hitsByRank, "Sort by rank: ");             // check for duplicates
            System.Collections.IDictionary resultMap = new System.Collections.SortedList();
            // store hits in TreeMap - TreeMap does not allow duplicates; existing entries are silently overwritten
            for (int hitid = 0; hitid < hitsByRank.Length; ++hitid)
            {
                resultMap[(System.Int32)hitsByRank[hitid].doc] = (System.Int32)hitid;                   // Value: Hits-Objekt Index
            }

            // now make a query using the sort criteria
            ScoreDoc[] resultSort = searcher.Search(query, null, 1000, sort).scoreDocs;
            CheckHits(resultSort, "Sort by custom criteria: ");             // check for duplicates

            // besides the sorting both sets of hits must be identical
            for (int hitid = 0; hitid < resultSort.Length; ++hitid)
            {
                System.Int32 idHitDate = (System.Int32)resultSort[hitid].doc;                  // document ID from sorted search
                if (!resultMap.Contains(idHitDate))
                {
                    Log("ID " + idHitDate + " not found. Possibliy a duplicate.");
                }
                Assert.IsTrue(resultMap.Contains(idHitDate));                 // same ID must be in the Map from the rank-sorted search
                // every hit must appear once in both result sets --> remove it from the Map.
                // At the end the Map must be empty!
                resultMap.Remove(idHitDate);
            }
            if (resultMap.Count == 0)
            {
                // log("All hits matched");
            }
            else
            {
                Log("Couldn't match " + resultMap.Count + " hits.");
            }
            Assert.AreEqual(resultMap.Count, 0);
        }
        protected override bool bIntegridadeDados()
        {
            bool bRetorno = false;
            int  nNextIdOrdemCertificado = 0;

            // Produtos Certificado
            System.Collections.ArrayList arlProdutosCertificado = arlProdutosCertificadoOrigem();

            System.Collections.SortedList sortListClassificacao = new System.Collections.SortedList();
            for (int j = 0; j < arlProdutosCertificado.Count; j++)
            {
                mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow dtrwProdutoCertificado = (mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow)arlProdutosCertificado[j];
                if (dtrwProdutoCertificado.RowState != System.Data.DataRowState.Deleted)
                {
                    string strClassificacao = strRetornaClassificacao(dtrwProdutoCertificado.idOrdemProduto);
                    if (!sortListClassificacao.Contains(strClassificacao))
                    {
                        sortListClassificacao.Add(strClassificacao, strClassificacao);
                    }
                }
            }
            // Classificacao - Insercao
            for (int j = 0; j < sortListClassificacao.Count; j++)
            {
                string strClassificacao = sortListClassificacao.GetByIndex(j).ToString();
                string strUnidadeUltima = "";
                for (int k = 0; k < arlProdutosCertificado.Count; k++)
                {
                    mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow dtrwProdutoCertificado = (mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow)arlProdutosCertificado[k];
                    string strClassificacaoProduto = strRetornaClassificacao(dtrwProdutoCertificado.idOrdemProduto);
                    if ((dtrwProdutoCertificado.RowState != System.Data.DataRowState.Deleted) && (strClassificacao == strClassificacaoProduto))
                    {
                        string strUnidadeProduto = strRetornaUnidadeProduto(dtrwProdutoCertificado.idOrdemProduto);
                        if (strUnidadeUltima != strUnidadeProduto)
                        {
                            nNextIdOrdemCertificado++;
                            strUnidadeUltima = strUnidadeProduto;
                        }
                        dtrwProdutoCertificado.idOrdem = nNextIdOrdemCertificado;
                    }
                }
            }
            bRetorno = true;
            return(bRetorno);
        }
Exemple #5
0
 protected override string CarregaDataMultiplaDefault()
 {
     mdlDataBaseAccess.Tabelas.XsdTbREs    typDatSetREs    = GetTbREs();
     mdlDataBaseAccess.Tabelas.XsdTbREsPEs typDatSetREsPEs = GetTbREsPEs();
     mdlDataBaseAccess.Tabelas.XsdTbSDs    typDatSetSDs    = GetTbSDs();
     System.Text.StringBuilder             strbDefault     = new System.Text.StringBuilder();
     // Ordernando
     System.Collections.SortedList srtlstSD = new System.Collections.SortedList(new mdlComponentesColecoes.clsComparerNumbersTexts());
     for (int i = 0; i < typDatSetREsPEs.tbREsPEs.Rows.Count; i++)
     {
         mdlDataBaseAccess.Tabelas.XsdTbREsPEs.tbREsPEsRow dtrwREPE = (mdlDataBaseAccess.Tabelas.XsdTbREsPEs.tbREsPEsRow)typDatSetREsPEs.tbREsPEs.Rows[i];
         if ((dtrwREPE.nIdExportador == m_nIdExportador) && (dtrwREPE.strIdPE == m_strIdPE))
         {
             mdlDataBaseAccess.Tabelas.XsdTbREs.tbREsRow dtrwRE = typDatSetREs.tbREs.FindBynIdExportadornIdRe(m_nIdExportador, dtrwREPE.nIdRe);
             if ((dtrwRE != null) && (!dtrwRE.IsnIdSDNull()))
             {
                 mdlDataBaseAccess.Tabelas.XsdTbSDs.tbSDsRow dtrwSD = typDatSetSDs.tbSDs.FindBynIdExportadornIdSD(m_nIdExportador, dtrwRE.nIdSD);
                 if ((dtrwSD != null) && (!srtlstSD.Contains(dtrwSD.mstrNumero)))
                 {
                     srtlstSD.Add(dtrwSD.mstrNumero, dtrwSD);
                 }
             }
         }
     }
     // Inserindo
     for (int i = 0; i < srtlstSD.Count; i++)
     {
         mdlDataBaseAccess.Tabelas.XsdTbSDs.tbSDsRow dtrwSD = (mdlDataBaseAccess.Tabelas.XsdTbSDs.tbSDsRow)srtlstSD.GetByIndex(i);
         if (strbDefault.ToString() != "")
         {
             strbDefault.Append(" - ");
         }
         if (!dtrwSD.IsdtEmissaoNull())
         {
             strbDefault.Append(dtrwSD.dtEmissao.ToString(this.Formato));
         }
         else
         {
             strbDefault.Append(" ");
         }
     }
     return(strbDefault.ToString());
 }
Exemple #6
0
        /// <summary>
        /// renew all guids of xmlString
        /// </summary>
        /// <param name="xmlString"></param>
        /// <returns></returns>
        public string RefreshAllGuids(ref string xmlString)
        {
            System.Xml.XmlDocumentFragment fragdoc = xmlDoc.CreateDocumentFragment();
            fragdoc.InnerXml = xmlString;

            System.Collections.IEnumerator ie       = fragdoc.ChildNodes.GetEnumerator();
            System.Collections.SortedList  listGUID = new System.Collections.SortedList();

            string strFirstGUID = null;

            xmlString = "";
            while (ie.MoveNext())
            {
                System.Xml.XmlNode node = (System.Xml.XmlNode)ie.Current;

                string OldGUID    = GetAttributeByName(node, PazDocumentLegacy.TAG_GUID);
                string NewGUID    = Guid.NewGuid().ToString();
                string ParentGUID = GetAttributeByName(node, PazDocumentLegacy.TAG_PARENTGUID);

                if (strFirstGUID == null)
                {
                    strFirstGUID = NewGUID;
                }

                listGUID.Add(OldGUID, NewGUID);

                if (listGUID.Contains(ParentGUID))
                {
                    SetAttributeByName(node, PazDocumentLegacy.TAG_PARENTGUID, (string)listGUID.GetByIndex(listGUID.IndexOfKey(ParentGUID)));
                }

                SetAttributeByName(node, PazDocumentLegacy.TAG_GUID, NewGUID);
                SetAttributeByName(node, PazDocumentLegacy.TAG_TIMESTAMP, DateTime.Now.Ticks.ToString());
                xmlString += node.OuterXml;
            }

            return(strFirstGUID);
        }
 /// <summary> Check the hits for duplicates.</summary>
 /// <param name="hits">
 /// </param>
 private void  CheckHits(ScoreDoc[] hits, System.String prefix)
 {
     if (hits != null)
     {
         System.Collections.IDictionary idMap = new System.Collections.SortedList();
         for (int docnum = 0; docnum < hits.Length; ++docnum)
         {
             int luceneId;
             
             luceneId = hits[docnum].Doc;
             if (idMap.Contains(luceneId))
             {
                 System.Text.StringBuilder message = new System.Text.StringBuilder(prefix);
                 message.Append("Duplicate key for hit index = ");
                 message.Append(docnum);
                 message.Append(", previous index = ");
                 message.Append(((System.Int32) idMap[luceneId]).ToString());
                 message.Append(", Lucene ID = ");
                 message.Append(luceneId);
                 Log(message.ToString());
             }
             else
             {
                 idMap[luceneId] = docnum;
             }
         }
     }
 }
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            int UsedSlots = 0;
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");
            string[] Inv=new string[64];
            int maxlen = 4;

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            bool isinv = false,isinvmembers = false;
            if (CommandArray[0] == "#inv" || CommandArray[0] == "#i" || CommandArray[0] == "#inb" || CommandArray[0] == "#sell" || CommandArray[0] == "#selling" || CommandArray[0] == "#inventory")
                isinv = true;
            if (CommandArray[0] == "#invmembers" || CommandArray[0] == "#im" || CommandArray[0] == "#invmemvers" || CommandArray[0] == "#invmember" || CommandArray[0] == "#invmemver")
                isinvmembers = true;
            if (isinv || isinvmembers)
            {
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#inv", Settings.botid);

                string str1 = "", str2 = "";

                if (TheInventory.GettingInventoryItems == true)
                {
                    str2 = "I am building my inventory list, please try again in a few seconds";
                    str1 = str1.PadRight(str2.Length, '=');
                    str1 = "[" + str1;
                    str2 = "[" + str2;
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                    return;
                }

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                if (Settings.IsTradeBot == false)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!"));
                    return;
                }
                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);
                if (rank < TheMySqlManager.GetCommandRank("#inv", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if ((CommandArray[0] == "#im" || CommandArray[0] == "#invmembers" || CommandArray[0] == "#invmemvers" || CommandArray[0] == "#invmember" || CommandArray[0] == "#invmemver") && ((rank < TheMySqlManager.GetCommandRank("#invmembers", Settings.botid)) && TheMySqlManager.CheckIfBannedGuild( e.username, Settings.botid) < 1))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly."));
                    return;
                }

                if (CommandArray.Length < 1)
                    goto WrongArguments;

                char invFiller = TheMySqlManager.getInvFiller();

                System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList();
                System.Collections.Hashtable MySellingItemsList = TheMySqlManager.GetSellingItemList(0);

                // sum up all inventory items if the items are on sale
                System.Collections.SortedList TheInventoryList = new System.Collections.SortedList();

                foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                {
                    //adjust the number of slots used...
                    if (MyInventoryItem.pos < 36)
                    {
                        if (MyInventoryItem.is_stackable)
                            UsedSlots++;
                        else
                            UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity);
                    }
                    //adjust the amount

                    //only display if in selling list
                    if (MySellingItemsList.Contains(MyInventoryItem.SqlID))
                    {
                        //if already in inventory output (eg.., two slots) just sum the quantity
                        //otherwise add to inventory output
                        if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                        {
                            Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                            TempInventoryItem.quantity += MyInventoryItem.quantity;
                            TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                        }
                        else
                        {
                            if (MyInventoryItem.pos < 36)
                            {

                                TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                            }
                        }
                    }
                }

                //foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                //{
                //    if(maxlen<MyInventoryItem.name.Length && (MyInventoryItem.pos < 36))
                //        maxlen = MyInventoryItem.name.Length;
                //}
                //maxlen++;
                maxlen = 20 + 25 - Settings.Loginname.Length;
                // pm all summed up inventory items on sale
                int i = 0;
                for (i = 0; i < 64; i++)
                    Inv[i] = "ZZZZZZZZZZZZZZZZ";
                int c = 0;
                string str = "";
                str2 = "";
                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                bool Member = (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == true);

                str = "[name".PadRight(maxlen, ' ');
                str = str + "|qty".PadRight(7, ' ');
                str = str + "|price".PadRight(14, ' ');
                str = str + "|id".PadRight(6, ' ');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                string msg, msg2;

                foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                {
                    if (MyInventoryItem.pos < 36)
                    {
                        msg = ("[" + MyInventoryItem.name).PadRight(maxlen, i == 0 ? ' ' : invFiller);
                        {
                            uint tempAmount = 0;
                            if ((TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)) < MyInventoryItem.quantity)
                            {
                                tempAmount = MyInventoryItem.quantity;
                                tempAmount = tempAmount - (TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID));
                            }
                            else
                            {
                                continue;
                            }

                            msg2 = tempAmount.ToString();
                        }
                        msg2 = msg2.PadLeft(6, i == 0 ? ' ' : invFiller);
                        msg = msg + "|" + msg2;
                        TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]);
                        if(isinv)
                            msg2 = MySellingItem.pricesale.ToString();
                        else
                            msg2 = MySellingItem.pricesalemembers.ToString();
                        if (!msg2.Contains("."))
                            msg2 += ".00gc";
                        else if (msg2[msg2.Length - 2] == '.')
                            msg2 += "0gc";
                        else
                            msg2 += "gc";
                        msg2 = msg2.PadLeft(13, i == 0 ? ' ' : invFiller);
                        msg = msg + "|" + msg2;
                        msg2 = MyInventoryItem.SqlID.ToString().PadLeft(5, i == 0 ? ' ' : invFiller);
                        msg = msg + "|" + msg2;
                        Inv[c] = msg;
                        c++;
                        i = 1 - i;
                    }
                }
                int d;
            //                for (d = 0; d < c; d++)
            //                {
            //                    str = Inv[d].Substring(16) + Inv[d].Substring(0, 16);
            //                    Inv[d] = str;
            //                }
                Array.Sort(Inv);
                i = maxlen + 13;

                string filter = "";
                if (CommandArray.Length > 1)
                {
                    bool firstTime = true;
                    foreach (string filterPart in CommandArray)
                    {
                        if (firstTime)
                        {
                            firstTime = false;
                            continue;
                        }
                        filter += (" " + filterPart);
                    }
                    //filter = Message.Substring(CommandArray[0].Length);
                }
                else
                    filter = "";

                for (d = 0; d < c; d++)
                {
                    str = Inv[d];
                    //27 chars after the name....
                    if (filter == "" || Inv[d].ToLower().Contains(filter.ToLower().Trim()))
                    {
                        string[] outFields = Inv[d].Split('|');
                        string outString = Inv[d];
                        if (outFields[0].Length > maxlen)
                        {
                            outString = outFields[0].Substring(0, maxlen - 3) + "...";
                            outString = outString.PadRight(maxlen, ' ') + "|".PadRight(7, ' ') + "|".PadRight(14, ' ') + "|".PadRight(6, ' ');
                            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                            outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' ');
                            int count = 0;
                            foreach (string tempString in outFields)
                            {
                                if (count == 0)
                                {
                                    count++;
                                    continue;
                                }
                                outString += "|" + tempString;
                            }
                        }
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                    }
                    else
                    {
                        //for (i = 1; i < CommandArray.Length; i++)
                        {
                            //if (Inv[d].ToLower().Contains(CommandArray[i].ToLower().Trim()))
                            Console.WriteLine("inv(d): " + Inv[d] + " filter: " + filter);
                            if (Inv[d].ToLower().Contains(filter.ToLower().Trim()))
                            {
                                string[] outFields = Inv[d].Split('|');
                                string outString = Inv[d];
                                if (outFields[0].Length > maxlen)
                                {
                                    outString = outFields[0].Substring(0, maxlen - 3) + "...";
                                    outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' ');
                                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                                    outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' ');
                                    foreach (string tempString in outFields)
                                    {
                                        outString += "|" + tempString;
                                    }
                                }
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                                i = CommandArray.Length;
                            }
                        }
                    }
                }

                int Phys = TheMySqlManager.GetBotPhysqiue(Settings.botid);
                int Coord = TheMySqlManager.GetBotCoordination(Settings.botid);
                int carry = (Phys + Coord) * 10;
                //int UsedSpace = TheMySqlManager.GetBotUsedSpace(Settings.botid);
                //int UsedSlots = TheMySqlManager.GetBotUsedSlots(Settings.botid);
                int UsedSpace = TheStats.MyCurrentCarryingAmt;
                int FreeSpace = carry - UsedSpace;
                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                str = "[";
                str += FreeSpace.ToString() + " EMU Avail|";
                str += (36-UsedSlots).ToString() + " Open slot(s)";
                if (rank > 89)
                {
                    //str += TheMySqlManager.moneylevel(Settings.botid).ToString() + " gc";
                    str += "|"+TheInventory.GetMoneyAmount().ToString() + " gc";
                }

                str = str.PadRight(maxlen + 27, ' ');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                str = "[";
                if (Member)
                {
                    if ((CommandArray[0] != "#im" && CommandArray[0] != "#invmembers" && CommandArray[0] != "#invmemvers" && CommandArray[0] != "#invmember" && CommandArray[0] != "#invmemver"))
                    {
                        str = str.PadRight(maxlen + 27, '-');
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                        str = "[Use invmembers (im) to see member prices";
                        str = str.PadRight(maxlen + 27, ' ');
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    }
                    //if (isinv)
                    //{
                    //    str = "[to see member prices use invmembers or im";
                    //    str = str.PadRight(maxlen + 28, ' ');
                    //    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    //}
                }
                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                return;
            }
            return;

            WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #inv command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#inv                                  "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #inv                         "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #inv silver ore              "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            return;
        }
		/// <summary> Check the hits for duplicates.</summary>
		/// <param name="hits">
		/// </param>
		private void  CheckHits(Hits hits, System.String prefix)
		{
			if (hits != null)
			{
				System.Collections.IDictionary idMap = new System.Collections.SortedList();
				for (int docnum = 0; docnum < hits.Length(); ++docnum)
				{
					System.Int32 luceneId;
					try
					{
						luceneId = (System.Int32) hits.Id(docnum);
						if (idMap.Contains(luceneId))
						{
							System.Text.StringBuilder message = new System.Text.StringBuilder(prefix);
							message.Append("Duplicate key for hit index = ");
							message.Append(docnum);
							message.Append(", previous index = ");
							message.Append(((System.Int32) idMap[luceneId]).ToString());
							message.Append(", Lucene ID = ");
							message.Append(luceneId);
							Log(message.ToString());
						}
						else
						{
							idMap[luceneId] = (System.Int32) docnum;
						}
					}
					catch (System.IO.IOException ioe)
					{
						System.Text.StringBuilder message = new System.Text.StringBuilder(prefix);
						message.Append("Error occurred for hit index = ");
						message.Append(docnum);
						message.Append(" (");
						message.Append(ioe.Message);
						message.Append(")");
						Log(message.ToString());
					}
				}
			}
		}
Exemple #10
0
        private string GetPersonalizavel()
        {
            System.Text.StringBuilder strbPersonalizavel = new System.Text.StringBuilder();

            System.Collections.SortedList sortLstSD = new System.Collections.SortedList(new mdlComponentesColecoes.clsComparerNumbersTexts());

            // Ordenando
            for (int i = 0; i < m_typDatSetREsPEs.tbREsPEs.Rows.Count; i++)
            {
                mdlDataBaseAccess.Tabelas.XsdTbREsPEs.tbREsPEsRow dtrwREPE = (mdlDataBaseAccess.Tabelas.XsdTbREsPEs.tbREsPEsRow)m_typDatSetREsPEs.tbREsPEs.Rows[i];
                if ((dtrwREPE.RowState != System.Data.DataRowState.Deleted) && (dtrwREPE.strIdPE == m_strIdPE))
                {
                    mdlDataBaseAccess.Tabelas.XsdTbREs.tbREsRow dtrwRE = m_typDatSetREs.tbREs.FindBynIdExportadornIdRe(m_nIdExportador, dtrwREPE.nIdRe);
                    if ((dtrwRE != null) && (dtrwRE.RowState != System.Data.DataRowState.Deleted) && (!dtrwRE.IsnIdSDNull()))
                    {
                        mdlDataBaseAccess.Tabelas.XsdTbSDs.tbSDsRow dtrwSD = m_typDatSetSDs.tbSDs.FindBynIdExportadornIdSD(m_nIdExportador, dtrwRE.nIdSD);
                        if ((dtrwSD != null) && (dtrwSD.RowState != System.Data.DataRowState.Deleted) && (!sortLstSD.Contains(dtrwSD.mstrNumero)))
                        {
                            sortLstSD.Add(dtrwSD.mstrNumero, dtrwSD);
                        }
                    }
                }
            }

            if (sortLstSD.Count == 0)
            {
                return(null);
            }

            // Inserindo
            for (int i = 0; i < sortLstSD.Count; i++)
            {
                mdlDataBaseAccess.Tabelas.XsdTbSDs.tbSDsRow dtrwSD = (mdlDataBaseAccess.Tabelas.XsdTbSDs.tbSDsRow)sortLstSD.GetByIndex(i);
                if (strbPersonalizavel.ToString() != "")
                {
                    strbPersonalizavel.Append(" , ");
                }
                strbPersonalizavel.Append(dtrwSD.mstrNumero);
            }
            return(strbPersonalizavel.ToString());
        }
Exemple #11
0
        CCallStack AnalyzeMap(string bugtrapfile, string mapfile)
        {
            CCallStack callstack = new CCallStack();

            System.Collections.SortedList address_list      = new System.Collections.SortedList();
            System.Collections.SortedList find_address_list = new System.Collections.SortedList();

            System.IO.StreamReader reader = new System.IO.StreamReader(bugtrapfile);
            string xmlstring = reader.ReadToEnd();

            reader.Close();

            System.Xml.XmlDocument document = new System.Xml.XmlDocument();
            document.LoadXml(xmlstring);

            System.Xml.XPath.XPathNavigator    nav = document.CreateNavigator();
            System.Xml.XPath.XPathNodeIterator i;

            string what   = System.Convert.ToString(nav.SelectSingleNode("/report/error/what/text()"));
            string module = System.IO.Path.GetFileName(System.Convert.ToString(nav.SelectSingleNode("/report/error/module/text()")));
            string tmp    = System.Convert.ToString(nav.SelectSingleNode("/report/error/address/text()"));

            if (tmp == "" || tmp.Trim().Length < 1)
            {
                return(null);
            }

            UInt32 address = System.Convert.ToUInt32(tmp.Substring(tmp.Length - 8), 16);

            i = nav.Select("/report/threads/thread/status[text()='interrupted']/../stack/frame");

            System.Collections.ArrayList frame_list = new System.Collections.ArrayList();
            while (i.MoveNext() == true)
            {
                Frame frame = new Frame();

                frame.module = System.IO.Path.GetFileName(System.Convert.ToString(i.Current.SelectSingleNode("module/text()")));
                string frame_address = System.Convert.ToString(i.Current.SelectSingleNode("address/text()"));

                string function_name   = null;
                string function_offset = null;

                if (i.Current.SelectSingleNode("function/name/text()") != null)
                {
                    function_name = System.Convert.ToString(i.Current.SelectSingleNode("function/name/text()"));
                }

                if (i.Current.SelectSingleNode("function/offset/text()") != null)
                {
                    function_offset = System.Convert.ToString(i.Current.SelectSingleNode("function/offset/text()"));
                }

                frame.address = System.Convert.ToUInt32(frame_address.Substring(frame_address.Length - 8), 16);

                if (address_list.Contains(frame.address) == false &&
                    find_address_list.Contains(frame.address) == false)
                {
                    if (function_name == null)
                    {
                        address_list.Add(frame.address, null);
                    }
                    else
                    {
                        if (function_offset == null)
                        {
                            find_address_list.Add(frame.address, function_name);
                        }
                        else
                        {
                            find_address_list.Add(frame.address, string.Format("{0}+0x{1:x}", function_name, function_offset));
                        }
                    }
                }

                frame_list.Add(frame);
            }

            if (address_list.Contains(address) == false &&
                find_address_list.Contains(address) == false)
            {
                address_list.Add(address, null);
            }

            UInt32 baseaddress = 0;

            reader = new System.IO.StreamReader(mapfile);

            while (reader.EndOfStream == false)
            {
                string   line = reader.ReadLine();
                string[] e    = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (e.Length >= 5 && e[0] == "Preferred")
                {
                    baseaddress = System.Convert.ToUInt32(e[4], 16);
                    break;
                }
            }

            while (reader.EndOfStream == false)
            {
                string   line = reader.ReadLine();
                string[] e    = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (e.Length >= 5 && e[0] == "Address")
                {
                    break;
                }
            }

            string old_name    = "";
            UInt32 old_address = 0;

            while (reader.EndOfStream == false && address_list.Count > 0)
            {
                string   line = reader.ReadLine();
                string[] e    = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                UInt32 map_address  = System.Convert.ToUInt32(e[2], 16);
                UInt32 list_address = (UInt32)address_list.GetKey(0);
                if (list_address <= map_address)
                {
                    address_list.RemoveAt(0);
                    e[1] = ConvertUname(old_name);
                    find_address_list.Add(list_address, string.Format("{0}+0x{1:x}", e[1], list_address - old_address));
                }

                old_name    = e[1];
                old_address = map_address;
            }
            reader.Close();

            if (find_address_list.Contains(address) == true)
            {
                string fcs = find_address_list[address].ToString();
                int    pi  = fcs.IndexOf("+");
                if (pi > 0)
                {
                    callstack.FinalCallstack = String.Format("{0}!{1}", module.ToLower(), fcs.Substring(0, pi));
                }
                else
                {
                    callstack.FinalCallstack = String.Format("{0}!{1}", module.ToLower(), fcs);
                }
            }
            else
            {
                callstack.FinalCallstack = "Unknown Address";
            }


            foreach (Frame frame in frame_list)
            {
                if (find_address_list.Contains(frame.address) == true)
                {
                    callstack.CallStack += string.Format("{0:x8} {1} {2}\n", frame.address, frame.module.ToLower(), find_address_list[frame.address]);
                }
                else
                {
                    callstack.CallStack += string.Format("{0:x8} {1}\n", frame.address, frame.module.ToLower());
                }
            }

            return(callstack);
        }
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");

            string[] Inv          = new string[64];
            int      maxlen       = 4;
            bool     validCommand = false;

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            if (CommandArray[0] == "#reserve")
            {
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#reserve", Settings.botid);

                string str1 = "", str2 = "";

                if (TheInventory.GettingInventoryItems == true)
                {
                    str2 = "I am building my inventory list, please try again in a few seconds";
                    str1 = str1.PadRight(str2.Length, '=');
                    str1 = "[" + str1;
                    str2 = "[" + str2;
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                    return;
                }

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);
                if (rank < TheMySqlManager.GetCommandRank("#reserve", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly."));
                    return;
                }

                if (CommandArray.Length <= 1)
                {
                    goto WrongArguments;
                }

                if (CommandArray[1] == "withdraw")
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Still working on this function..."));
                    validCommand = true;
                }

                if (CommandArray[1] == "details")
                {
                    TheMySqlManager.reservedDetails(Settings.botid, e.username);
                    validCommand = true;
                }

                if (CommandArray[1] == "list")
                {
                    validCommand = true;
                    // list all of the inventory items that have reserved amounts

                    //set up the current inventory list
                    System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList();

                    //set up a sorted inventory list for output purposes
                    System.Collections.SortedList TheInventoryList = new System.Collections.SortedList();

                    //loop through the inventory finding reserved amounts
                    foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                    {
                        //find the largest name length for output purposes
                        if (maxlen < MyInventoryItem.name.Length && (MyInventoryItem.pos < 36))
                        {
                            maxlen = MyInventoryItem.name.Length;
                        }
                        //if it's not in the output array, put it there
                        if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                        {
                            //add the item quantities (these should be the unstackables...)
                            Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                            TempInventoryItem.quantity += MyInventoryItem.quantity;
                            TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                        }
                        else
                        {
                            if (MyInventoryItem.pos < 36)
                            {
                                TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                            }
                        }
                    }

                    //loop through the storage finding reserved amounts
                    System.Collections.ArrayList MyStorageList = TheStorage.GetStorageList();
                    foreach (Storage.StorageItem MyStorageItem in MyStorageList)
                    {
                        if (maxlen < MyStorageItem.name.Length)
                        {
                            maxlen = MyStorageItem.name.Length;
                        }
                        if (TheInventoryList.Contains(MyStorageItem.knownItemsID))
                        {
                            //already in the list, do nothing since storage quantity is already the total
                            //and it repeats, kinda like an unstackable item
                        }
                        else
                        {
                            Inventory.inventory_item MyInventoryItem = new Inventory.inventory_item();
                            MyInventoryItem.name             = MyStorageItem.name;
                            MyInventoryItem.SqlID            = MyStorageItem.knownItemsID;
                            MyInventoryItem.quantity         = MyStorageItem.quantity;
                            MyInventoryItem.reservedQuantity = MyStorageItem.reservedQuantity;
                            TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                        }
                    }
                    // pm the reserved items
                    string str = "";
                    string msg = "";
                    str = "[";
                    str = str.PadRight(maxlen + 27, '-');
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                    {
                        uint reservedQuantity = TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID);
                        if (MyInventoryItem.pos < 36 && reservedQuantity > 0)
                        {
                            msg  = "[";
                            msg += MyInventoryItem.name + " " + reservedQuantity + " of " + MyInventoryItem.quantity;
                            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, msg));
                        }
                    }
                    str = "[";
                    str = str.PadRight(maxlen + 27, '-');
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                }

                if (CommandArray.Length > 2)
                {
                    validCommand = true;
                    try
                    {
                        if (CommandArray[1] == "delete")
                        {
                            Int32 rowIndex = Int32.Parse(CommandArray[2]);
                            if (TheMySqlManager.reservedDelete(Settings.botid, e.username, rowIndex))
                            {
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Row Deleted."));
                            }
                            else
                            {
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Index not found."));
                            }
                        }
                        else
                        {
                            Int32  numberToReserve = Int32.Parse(CommandArray[1]);
                            int    i;
                            string itemName = "";
                            for (i = 2; i < CommandArray.Length; i++)
                            {
                                itemName += CommandArray[i] + " ";
                            }
                            int itemId = TheMySqlManager.GetItemID(itemName, false);
                            if (itemId > 0)
                            {
                                if (TheMySqlManager.reserveItem(itemId, (uint)numberToReserve, e.username) == true)
                                {
                                    TheTradeHandler.AddTrade(itemId, 0, (uint)numberToReserve, "reserved");
                                    TradeHandler.TradeLogItem myItem = new TradeHandler.TradeLogItem();
                                    myItem.KnownItemsSqlID = itemId;
                                    myItem.quantity        = (uint)numberToReserve;
                                    myItem.action          = "reserved by";
                                    TheMySqlManager.LogTrade(myItem, e.username, Settings.botid, true);
                                    TheInventory.requestInventory();
                                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[You just reserved " + myItem.quantity + " " + TheMySqlManager.GetKnownItemsname(myItem.KnownItemsSqlID)));
                                }
                                else //probably never get to this one...
                                {
                                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Item not found!"));
                                }
                            }
                            else
                            {
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Item not found!"));
                            }
                        }
                    }
                    catch
                    {
                        goto WrongArguments;
                    }
                }
                else
                {
                    if (!validCommand)
                    {
                        goto WrongArguments;
                    }
                }
            }
            return;

WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #reserve command:          "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#reserve <list>[withdraw] <amount item>             "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve list                              "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve amount item                       "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve details                           "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve delete <idx>*                     "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[*<idx> provided by #reserve details command.        "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------"));
            return;
        }
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            int UsedSlots = 0;
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");
            string[] Inv = new string[512];

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');

            if (CommandArray[0] == "#invlist" || CommandArray[0] == "#il")
            {
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#invlist", Settings.botid);

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);
                if (rank < TheMySqlManager.GetCommandRank("#invlist", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly."));
                    return;
                }

                char invFiller = TheMySqlManager.getInvFiller();

                string str1 = "", str2 = "";
                if (TheInventory.GettingInventoryItems == true)
                {
                    str2 = "I am building my inventory list, please try again in a few seconds";
                    str1 = str1.PadRight(str2.Length, '=');
                    str1 = "[" + str1;
                    str2 = "[" + str2;
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                    return;
                }
                if (CommandArray.Length < 1)
                    goto WrongArguments;

                System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList();
                System.Collections.Hashtable MySellingItemsList = TheMySqlManager.GetSellingItemList(0);

                // sum up all inventory items if the items are on sale
                int i = 0;
                for (i = 0; i < 512; i++)
                    Inv[i] = "ZZZZZZZZZZZZZZZZ";
                int c = 0;

                System.Collections.SortedList TheInventoryList = new System.Collections.SortedList();
                System.Collections.SortedList TheWornList = new System.Collections.SortedList();
                int ii = 0;
                foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                {
                    ii++;
                    if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                    {
            //                        if (MyInventoryItem.pos < 36)
                        {
                            Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                            TempInventoryItem.quantity += MyInventoryItem.quantity;
                            TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                        }
                    }
                    else
                    {
                        if (MyInventoryItem.pos < 36)
                        {
                            TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                        }
                    }
                    if (MyInventoryItem.pos > 35 && MyInventoryItem.pos < 44)
                    {
                        TheWornList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                    }
                }
                int maxlen = 4;
                foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                {
            //                    if (maxlen < MyInventoryItem.name.Length && MyInventoryItem.pos < 44)
                    if (maxlen < MyInventoryItem.name.Length && MyInventoryItem.pos < 36)
                    {
                        maxlen = MyInventoryItem.name.Length;
                    }
                }
                foreach (Inventory.inventory_item MyInventoryItem in TheWornList.Values)
                {
                    if (maxlen <= MyInventoryItem.name.Length + 3)
                        maxlen = MyInventoryItem.name.Length + 3;
                }
                str2 = "";
                str1= "[";
                str1= str1.PadRight(maxlen + 16, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                str1= "[ id |";
                str2 = "quantity";
                str2 = str2.PadRight(9, ' ')+"|";
                str1+= str2;
                str2 = "name";
                str2 = str2.PadRight(maxlen, ' ');
                str1= str1+ str2;
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                str1= "[";
                str1= str1.PadRight(maxlen + 16, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                // pm all summed up inventory items on sale
                c=0;
                i = 1;
                foreach (Inventory.inventory_item MyInventoryItem in TheWornList.Values)
                {
                    if (MyInventoryItem.pos < 44)
                    {
                        if (MyInventoryItem.pos < 36)
                        {
                            if (MyInventoryItem.is_stackable)
                                UsedSlots++;
                            else
                                UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity);
                        }
                        str1 = "";
                        str2 = "";
                        str2 += MyInventoryItem.SqlID.ToString();
                        str2 = str2.PadLeft(4, i == 0 ? ' ' : invFiller);
                        str2 = "[" + str2 + "|";
                        str1 = MyInventoryItem.quantity.ToString();
                        str1 = str1.PadLeft(9, i == 0 ? ' ' : invFiller);
                        str2 += str1 + "|";
                        if (MyInventoryItem.pos > 35)
                            str1 = "{E}" + MyInventoryItem.name;
                        else
                            str1 = MyInventoryItem.name;
                        str1 = str1.PadRight(maxlen, i == 0 ? ' ' : invFiller);
                        str1 = str2 + str1;
                        //TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]);
                        //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                        Inv[c++] = str1;
                        //i = 1 - i;
                    }
                }
                foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                {
                    if (MyInventoryItem.pos < 44)
                    {
                        if (MyInventoryItem.pos < 36)
                        {
                            if (MyInventoryItem.is_stackable)
                                UsedSlots++;
                            else
                                UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity);
                        }
                        str1 = "";
                        str2 = "";
                        str2 += MyInventoryItem.SqlID.ToString();
                        str2 = str2.PadLeft(4, i == 0 ? ' ' : invFiller);
                        str2 = "[" + str2 + "|";
                        str1 = MyInventoryItem.quantity.ToString();
                        str1 = str1.PadLeft(9, i == 0 ? ' ' : invFiller);
                        str2 += str1+"|";
                        if (MyInventoryItem.pos > 35)
                            str1 = "{E}" + MyInventoryItem.name;
                        else
                            str1 = MyInventoryItem.name;
                        str1 = str1.PadRight(maxlen, i == 0 ? ' ' : invFiller);
                        str1 = str2 + str1;
                        //TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]);
                        //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                        Inv[c++] = str1;
                        //i = 1 - i;
                    }
                }
                int d;
                string str;
                for (d = 0; d < c; d++)
                {
                    str = Inv[d].Substring(16) + Inv[d].Substring(0, 16);
                    Inv[d] = str;
                }
                Array.Sort(Inv);
                i = maxlen + 13;

                string filter = "";
                if (CommandArray.Length > 1)
                {
                    bool firstTime = true;
                    foreach (string filterPart in CommandArray)
                    {
                        if (firstTime)
                        {
                            firstTime = false;
                            continue;
                        }
                        filter += (" " + filterPart);
                    }
                    //filter = Message.Substring(CommandArray[0].Length);
                }
                else
                    filter = "";

                //for (d = c - 1; d >= 0; d--)
                for (d = 0; d <c; d++)
                {
                    i = Inv[d].Length - 16;
                    str = Inv[d].Substring(i);
                    str += Inv[d].Substring(0, i);
                    Inv[d] = str.Substring(str.Length - 16);
                    if (filter == "" || str.ToLower().Contains(filter.ToLower().Trim()))
                    {
                        //string[] outFields = Inv[d].Split('|');
                        //string outString = Inv[d];
                        //if (outFields[0].Length > maxlen)
                        //{
                        //    outString = outFields[0].Substring(0, maxlen - 3) + "...";
                        //    outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' ');
                        //    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                        //    outString = "[...".PadRight(maxlen, ' ');
                        //    foreach (string tempString in outFields)
                        //    {
                        //        outString += "|" + tempString;
                        //    }
                        //}
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    }
                    else
                    {
                        //for (i = 1; i < CommandArray.Length; i++)
                        {
                            if (str.ToLower().Contains(filter.ToLower().Trim()))
                            {
                                //string[] outFields = Inv[d].Split('|');
                                //string outString = Inv[d];
                                //if (outFields[0].Length > maxlen)
                                //{
                                //    outString = outFields[0].Substring(0, maxlen - 3) + "...";
                                //    outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' ');
                                //    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                                //    outString = "[...".PadRight(maxlen, ' ');
                                //    foreach (string tempString in outFields)
                                //    {
                                //        outString += "|" + tempString;
                                //    }
                                //}
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                                i = CommandArray.Length;
                            }
                        }
                    }
                }

                int Phys = TheMySqlManager.GetBotPhysqiue(Settings.botid);
                int Coord = TheMySqlManager.GetBotCoordination(Settings.botid);
                int carry = (Phys + Coord) * 10;
                int UsedSpace = TheStats.MyCurrentCarryingAmt;
                int FreeSpace = carry - UsedSpace;
                str1= "[";
                str1= str1.PadRight(maxlen + 16, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                str1 = "[";
                str1 += FreeSpace.ToString() + " EMU Avail|";
                str1 += (36 - UsedSlots).ToString() + " Open slot(s)";
                if (rank > 89)
                {
                    str1 += "|"+TheInventory.GetMoneyAmount().ToString() + " gc";
                }

                str1 = str1.PadRight(maxlen + 16, ' ');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                str1= "[";
                str1= str1.PadRight(maxlen + 16, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                return;
            }
            return;

            WrongArguments:
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username,"[Here is the usage of the #invlist command:"));
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username,"[#invlist                                  "));
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username,"[------------------------------------------"));
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username,"[Example: #invlist                         "));
                return;
        }
        private void ParseNode(System.Object parent, System.Object context, System.Xml.XmlNode node, System.Collections.Hashtable config, System.String prefix)
        {
            foreach (System.Xml.XmlNode item in node.ChildNodes)
            {
                if (item.NodeType.Equals(System.Xml.XmlNodeType.Element))
                {
                    System.String sectionname = System.String.Concat(prefix, "/", item.Name);;
                    switch (item.Name)
                    {
                    case "general":
                    case "login":
                    case "message":
                    case "inbox":
                        System.Configuration.SingleTagSectionHandler singlesection = new System.Configuration.SingleTagSectionHandler();
                        InitConfigSection(config, sectionname, singlesection.Create(parent, context, item) as System.Collections.Hashtable);
                        break;

                    case "read":
                    case "send":
                        if (item.HasChildNodes)
                        {
                            ParseNode(parent, context, item, config, sectionname);
                        }
                        break;

                    case "servers":
                        if (item.HasChildNodes)
                        {
                            config.Add(sectionname, ParseConfigServers(item.ChildNodes));
                        }
                        break;

                    case "addressbook":
                        if (!config.Contains(sectionname))
                        {
                            config.Add(sectionname, new System.Collections.SortedList());
                        }
                        System.Collections.SortedList addressbooks   = (System.Collections.SortedList)config[sectionname];
                        System.Collections.Hashtable  tmpaddressbook = (System.Collections.Hashtable)(new System.Configuration.SingleTagSectionHandler()).Create(parent, context, item);
                        System.Collections.Specialized.ListDictionary addressbook = new System.Collections.Specialized.ListDictionary(new System.Collections.CaseInsensitiveComparer());
                        foreach (System.String configitem in tmpaddressbook.Keys)
                        {
                            addressbook.Add(configitem, tmpaddressbook[configitem]);
                        }
                        tmpaddressbook = null;
                        if (addressbook.Contains("type") && !addressbook["type"].Equals("none") && addressbook.Contains("name") && !addressbooks.Contains(addressbook["name"]))
                        {
                            if (addressbook.Contains("pagesize"))
                            {
                                addressbook["pagesize"] = ParseConfigElement(addressbook["pagesize"].ToString(), 10);
                            }
                            else
                            {
                                addressbook["pagesize"] = 10;
                            }
                            addressbooks.Add(addressbook["name"], addressbook);
                            if (addressbook.Contains("allowupdate"))
                            {
                                addressbook["allowupdate"] = ParseConfigElement(addressbook["allowupdate"].ToString(), false);
                            }
                            else
                            {
                                addressbook["allowupdate"] = false;
                            }
                        }
                        break;
                    }
                }
            }
        }
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");
            string[] Inv=new string[64];
            int maxlen = 4;
            bool validCommand = false;

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            if (CommandArray[0] == "#reserve" )
            {
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#reserve", Settings.botid);

                string str1 = "", str2 = "";

                if (TheInventory.GettingInventoryItems == true)
                {
                    str2 = "I am building my inventory list, please try again in a few seconds";
                    str1 = str1.PadRight(str2.Length, '=');
                    str1 = "[" + str1;
                    str2 = "[" + str2;
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                    return;
                }

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);
                if (rank < TheMySqlManager.GetCommandRank("#reserve", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly."));
                    return;
                }

                if (CommandArray.Length <= 1)
                    goto WrongArguments;

                if (CommandArray[1] == "withdraw")
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Still working on this function..."));
                    validCommand = true;
                }

                if (CommandArray[1] == "details")
                {
                    TheMySqlManager.reservedDetails(Settings.botid, e.username);
                    validCommand = true;
                }

                if (CommandArray[1] == "list")
                {
                    validCommand = true;
                    // list all of the inventory items that have reserved amounts

                    //set up the current inventory list
                    System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList();

                    //set up a sorted inventory list for output purposes
                    System.Collections.SortedList TheInventoryList = new System.Collections.SortedList();

                    //loop through the inventory finding reserved amounts
                    foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                    {
                        //find the largest name length for output purposes
                        if (maxlen < MyInventoryItem.name.Length && (MyInventoryItem.pos < 36))
                            maxlen = MyInventoryItem.name.Length;
                        //if it's not in the output array, put it there
                        if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                        {
                            //add the item quantities (these should be the unstackables...)
                            Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                            TempInventoryItem.quantity += MyInventoryItem.quantity;
                            TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                        }
                        else
                        {
                            if (MyInventoryItem.pos < 36)
                            {
                                TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                            }
                        }
                    }

                    //loop through the storage finding reserved amounts
                    System.Collections.ArrayList MyStorageList = TheStorage.GetStorageList();
                    foreach (Storage.StorageItem MyStorageItem in MyStorageList)
                    {
                        if (maxlen < MyStorageItem.name.Length)
                        {
                            maxlen = MyStorageItem.name.Length;
                        }
                        if (TheInventoryList.Contains(MyStorageItem.knownItemsID))
                        {
                            //already in the list, do nothing since storage quantity is already the total
                            //and it repeats, kinda like an unstackable item
                        }
                        else
                        {
                            Inventory.inventory_item MyInventoryItem = new Inventory.inventory_item();
                            MyInventoryItem.name = MyStorageItem.name;
                            MyInventoryItem.SqlID = MyStorageItem.knownItemsID;
                            MyInventoryItem.quantity = MyStorageItem.quantity;
                            MyInventoryItem.reservedQuantity = MyStorageItem.reservedQuantity;
                            TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                        }
                    }
                    // pm the reserved items
                    string str = "";
                    string msg = "";
                    str = "[";
                    str = str.PadRight(maxlen + 27, '-');
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                    {
                        uint reservedQuantity = TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID);
                        if (MyInventoryItem.pos < 36 && reservedQuantity > 0)
                        {
                            msg = "[";
                            msg += MyInventoryItem.name + " " + reservedQuantity + " of " + MyInventoryItem.quantity;
                            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, msg));
                        }
                    }
                    str = "[";
                    str = str.PadRight(maxlen + 27, '-');
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                }

                if (CommandArray.Length > 2)
                {
                    validCommand = true;
                    try
                    {
                        if (CommandArray[1] == "delete")
                        {
                            Int32 rowIndex = Int32.Parse(CommandArray[2]);
                            if (TheMySqlManager.reservedDelete(Settings.botid, e.username, rowIndex))
                            {
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Row Deleted."));
                            }
                            else
                            {
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Index not found."));
                            }
                        }
                        else
                        {
                            Int32 numberToReserve = Int32.Parse(CommandArray[1]);
                            int i;
                            string itemName = "";
                            for (i = 2; i < CommandArray.Length; i++)
                            {
                                itemName += CommandArray[i] + " ";
                            }
                            int itemId = TheMySqlManager.GetItemID(itemName,false);
                            if (itemId > 0)
                            {
                                if (TheMySqlManager.reserveItem(itemId, (uint)numberToReserve, e.username) == true)
                                {
                                    TheTradeHandler.AddTrade(itemId, 0, (uint)numberToReserve, "reserved");
                                    TradeHandler.TradeLogItem myItem = new TradeHandler.TradeLogItem();
                                    myItem.KnownItemsSqlID = itemId;
                                    myItem.quantity = (uint)numberToReserve;
                                    myItem.action = "reserved by";
                                    TheMySqlManager.LogTrade(myItem, e.username, Settings.botid, true);
                                    TheInventory.requestInventory();
                                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[You just reserved " + myItem.quantity + " " + TheMySqlManager.GetKnownItemsname(myItem.KnownItemsSqlID)));
                                }
                                else //probably never get to this one...
                                {
                                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Item not found!"));
                                }
                            }
                            else
                            {
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Item not found!"));
                            }
                        }
                    }
                    catch
                    {
                        goto WrongArguments;
                    }
                }
                else
                {
                    if (!validCommand)
                    {
                        goto WrongArguments;
                    }
                }
            }
            return;

            WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #reserve command:          "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#reserve <list>[withdraw] <amount item>             "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve list                              "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve amount item                       "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve details                           "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve delete <idx>*                     "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[*<idx> provided by #reserve details command.        "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------"));
            return;
        }
Exemple #16
0
        private void AdvertTimer_Tick(object sender, ElapsedEventArgs e)
        {
            try
            {
                int i = 0;
                uint advertchannel = TheMySqlManager.advertchannel(Settings.botid);
                Random RandomClass = new Random();
                string advertstr = "", str2 = "", endm = TheMySqlManager.advertendmessage().Trim();
                if (TheTradeHandler.AmITrading() || (TheInventory.GettingInventoryItems == true))
                {
                    this.AdvertTimer.Interval = (1 * 1000);// +RandomClass.Next(0, (60 * 60 * 1000)); ;//m*s*us=1 hour
                    TheLogger.Debug("Advert delayed due to current trade\n");
                    return;
                }
                if (advertchannel != 99999999)
                {
                    //this.AdvertTimer.Interval = (15 * 60 * 1000) + RandomClass.Next(0, (60 * 60 * 1000)); ;//m*s*us=1 hour
                    //this.AdvertTimer.Interval=60*

                    i = TheMySqlManager.minadverttime() * 1000;
                    i += (RandomClass.Next(0, TheMySqlManager.randomadvertdelay()) * 1000);
                    if (i < 900000)
                        i = 900000;//minimum 15 minute delay
                    this.AdvertTimer.Interval = i;
                }
                else
                {
                    if (MainClass.serverName == "test")
                    {
                        this.AdvertTimer.Interval = 1000;
                    }
                }
                TheLogger.Debug("New AdvertTimer.Interval: " + this.AdvertTimer.Interval + "\n");

                if (advertchannel != 99999999 && TheMySqlManager.lastadverttime(Settings.botid) < TheMySqlManager.minadverttime() && MainClass.serverName != "test")
                    return;

                //Start the advertising here, if it's set to true...
                //Assumptions: 140 characters max length
                //Need to get advert_rates from the database for this bot to see how the weights are distributed
                if (TheMySqlManager.advertise())
                {
                    //decide if we should do a text message or a _goods_ message
                    //get the rate for text adverts, it's a number between 0 and 1
                    //then get a random number between 0 and one, if the random number is less than the advert rate, do the advert
                    //otherwise, do a _goods_ advert (buying and selling...)
                    double advertTextRate = TheMySqlManager.getAdvertTextRate();
                    double sellRate = TheMySqlManager.getSellRate();
                    Random randomDouble = new Random();
                    double randomRate = randomDouble.NextDouble();
                    if (randomRate < advertTextRate)
                    {
                        //do a text advert
                        //get a random row from the adverts table and use it as the advertisement
                        //select * from adverts where botid = 2 order by rand() LIMIT 1;
                        advertstr = TheMySqlManager.getTextAdvert();
                    }
                    else
                    {
                        //do a goods advert (buying and selling)
                        //get the selling rate, it's between 0 and 1
                        //get a random number between 0 and 1, if the rate is less than the selling rate, do a "selling" advert
                        //otherwise, do a "buying" advert
                        System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList();
                        System.Collections.ArrayList MySellingItemsList = TheMySqlManager.GetSellingList(1);

                        // sum up all inventory items if the items are on sale
                        System.Collections.SortedList TheInventoryList = new System.Collections.SortedList();
                        System.Collections.ArrayList MyWantedItemsList = TheMySqlManager.GetWantedList(1);

                        //add up the inventory stuff
                        foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                        {
                            if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                            {
                                Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                                TempInventoryItem.quantity += MyInventoryItem.quantity;
                                TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                            }
                            else
                            {
                                if (MyInventoryItem.pos < 36)
                                {
                                    TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                                }
                            }
                        }
                        randomRate = randomDouble.NextDouble();
                        if (randomRate < sellRate)
                        {
                            //selling
                            advertstr = "Selling:";
                            foreach (TradeHandler.SellingItem MySellingItem in MySellingItemsList)
                            {
                                if (TheInventoryList.Contains(MySellingItem.KnownItemsSqlID))
                                {
                                    Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)TheInventoryList[MySellingItem.KnownItemsSqlID];
                                    if (MySellingItem.pricesale > 0)
                                    {
                                        uint tempAmount = 0;
                                        if ((TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)) < MyInventoryItem.quantity)
                                        {
                                            tempAmount = MyInventoryItem.quantity;
                                            tempAmount = tempAmount - (TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID));
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                        str2 = tempAmount.ToString() + " " + MyInventoryItem.name + ":" + MySellingItem.pricesale.ToString() + "gc";
                                        if (advertstr.Length + str2.Length + endm.Length < 140)
                                        {
                                            if (advertstr.Length > 8)
                                                advertstr += ", ";
                                            advertstr += str2;
                                        }
                                    }
                                }
                            }
                            if (advertstr.Length > 8)
                            {
                                advertstr += "|" + endm;
                            }
                            else
                            {
                                advertstr = "";
                            }
                        }
                        else
                        {
                            //buying
                            advertstr = "Buying:";
                            foreach (TradeHandler.WantedItem MyWantedItem in MyWantedItemsList)
                            {
                                if (TheInventoryList.Contains(MyWantedItem.KnownItemsSqlID))
                                {
                                    Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)TheInventoryList[MyWantedItem.KnownItemsSqlID];
                                    if (MyWantedItem.pricepurchase > 0 && MyInventoryItem.quantity < MyWantedItem.maxquantity)
                                    {
                                        str2 = TheMySqlManager.GetKnownItemsname(MyWantedItem.KnownItemsSqlID) + ":" + MyWantedItem.pricepurchase.ToString() + "gc";
                                        if (advertstr.Length + str2.Length + endm.Length < 140)
                                        {
                                            if (advertstr.Length > 7)
                                                advertstr += ", ";
                                            advertstr += str2;
                                        }
                                    }
                                }
                                else
                                {
                                    if (MyWantedItem.pricepurchase > 0)
                                    {
                                        str2 = TheMySqlManager.GetKnownItemsname(MyWantedItem.KnownItemsSqlID) + ":" + MyWantedItem.pricepurchase.ToString() + "gc";
                                        if (advertstr.Length + str2.Length + endm.Length < 140)
                                        {
                                            if (advertstr.Length > 7)
                                                advertstr += ", ";
                                            advertstr += str2;
                                        }
                                    }
                                }
                            }
                            if (advertstr.Length > 7)
                            {
                                advertstr += "|" + endm;
                            }
                            else
                            {
                                advertstr = "";
                            }
                        }
                    }
                }
                if (advertstr != "")
                {
                    TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#jc " + advertchannel.ToString()));
                    TheTCPWrapper.Send(CommandCreator.RAW_TEXT("@" + advertstr));
                    TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#lc " + advertchannel.ToString()));
                    TheMySqlManager.advertlog("@@" + advertchannel.ToString() + " " + advertstr);
                    string sql = "UPDATE bots SET lastadverttime = NOW() WHERE botid = " + Settings.botid;
                    TheMySqlManager.raw_sql(sql);
                }
                advertstr = "";
            }
            catch (Exception exception)
            {
                TheErrorHandler.writeErrorMessage("Exception raised in the advert handler..." + exception);
            }
            finally
            {
            }
        }
Exemple #17
0
		/// <summary>
		/// Creates a matrix from three selected columns. This must be a x-column, a y-column, and a value column.
		/// </summary>
		/// <param name="xcol">Column of x-values.</param>
		/// <param name="ycol">Column of y-values.</param>
		/// <param name="vcol">Column of v-values.</param>
		/// <param name="originalTable">The source table. This is only needed to get the names of the columns.</param>
		/// <param name="newtable">On return, contains the newly created table matrix.</param>
		/// <returns>Null if no error occurs, or an error message.</returns>
		public static string XYVToMatrix(DataColumn xcol, DataColumn ycol, DataColumn vcol, DataTable originalTable, out DataTable newtable)
		{
			newtable = null;
			System.Collections.SortedList xx = new System.Collections.SortedList();
			System.Collections.SortedList yy = new System.Collections.SortedList();
			int len = xcol.Count;
			len = Math.Min(len, ycol.Count);
			len = Math.Min(len, vcol.Count);

			// Fill the xx and yy lists
			for (int i = 0; i < len; ++i)
			{
				if (!xx.Contains(xcol[i]))
					xx.Add(xcol[i], null);

				if (!yy.Contains(ycol[i]))
					yy.Add(ycol[i], null);
			}

			DataColumn xnew = (DataColumn)Activator.CreateInstance(xcol.GetType());
			DataColumn ynew = (DataColumn)Activator.CreateInstance(ycol.GetType());
			xnew.Clear();
			ynew.Clear();

			for (int i = xx.Count - 1; i >= 0; --i)
			{
				xnew[i] = (AltaxoVariant)xx.GetKey(i);
				xx[xx.GetKey(i)] = i;
			}

			for (int i = yy.Count - 1; i >= 0; --i)
			{
				ynew[1 + i] = (AltaxoVariant)yy.GetKey(i); // 1 + is because the table will get an additional x-column
				yy[yy.GetKey(i)] = i;
			}

			DataColumn vtemplate = (DataColumn)Activator.CreateInstance(vcol.GetType());

			// make a new table with yy.Count number of columns
			DataColumn[] vcols = new DataColumn[yy.Count];
			for (int i = yy.Count - 1; i >= 0; --i)
			{
				vcols[i] = (DataColumn)vtemplate.Clone();
			}

			// now fill the columns
			for (int i = 0; i < len; ++i)
			{
				int xidx = (int)xx[xcol[i]];
				int yidx = (int)yy[ycol[i]];

				vcols[yidx][xidx] = vcol[i];
			}

			// assemble all columns together in a table
			newtable = new DataTable();

			// add the x-column to the data collection
			string xname = null;
			if (null != originalTable)
				xname = originalTable.DataColumns.GetNameOfChildObject(xcol);
			if (string.IsNullOrEmpty(xname))
				xname = "X";
			newtable.DataColumns.Add(xnew, xname, ColumnKind.X, 0);

			// add the y-column to the property collection
			string yname = null;
			if (null != originalTable)
				yname = originalTable.DataColumns.GetNameOfChildObject(ycol);
			if (string.IsNullOrEmpty(yname))
				yname = "Y";
			newtable.PropertyColumns.Add(ynew, yname, ColumnKind.Y, 0);

			// add the v-columns to the data collection
			string vname = null;
			if (null != originalTable)
				vname = originalTable.DataColumns.GetNameOfChildObject(vcol);
			if (string.IsNullOrEmpty(vname))
				vname = "V";
			for (int i = 0; i < vcols.Length; ++i)
				newtable.DataColumns.Add(vcols[i], vname + i.ToString(), ColumnKind.V, 0);

			return null;
		}
Exemple #18
0
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            int    UsedSlots = 0;
            string Message   = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");

            string[] Inv    = new string[64];
            int      maxlen = 4;

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            bool     isinv = false, isinvmembers = false;

            if (CommandArray[0] == "#inv" || CommandArray[0] == "#i" || CommandArray[0] == "#inb" || CommandArray[0] == "#sell" || CommandArray[0] == "#selling" || CommandArray[0] == "#inventory")
            {
                isinv = true;
            }
            if (CommandArray[0] == "#invmembers" || CommandArray[0] == "#im" || CommandArray[0] == "#invmemvers" || CommandArray[0] == "#invmember" || CommandArray[0] == "#invmemver")
            {
                isinvmembers = true;
            }
            if (isinv || isinvmembers)
            {
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#inv", Settings.botid);

                string str1 = "", str2 = "";

                if (TheInventory.GettingInventoryItems == true)
                {
                    str2 = "I am building my inventory list, please try again in a few seconds";
                    str1 = str1.PadRight(str2.Length, '=');
                    str1 = "[" + str1;
                    str2 = "[" + str2;
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                    return;
                }

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                if (Settings.IsTradeBot == false)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!"));
                    return;
                }
                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);
                if (rank < TheMySqlManager.GetCommandRank("#inv", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if ((CommandArray[0] == "#im" || CommandArray[0] == "#invmembers" || CommandArray[0] == "#invmemvers" || CommandArray[0] == "#invmember" || CommandArray[0] == "#invmemver") && ((rank < TheMySqlManager.GetCommandRank("#invmembers", Settings.botid)) && TheMySqlManager.CheckIfBannedGuild(e.username, Settings.botid) < 1))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly."));
                    return;
                }

                if (CommandArray.Length < 1)
                {
                    goto WrongArguments;
                }

                char invFiller = TheMySqlManager.getInvFiller();

                System.Collections.ArrayList MyInventoryList    = TheInventory.GetInventoryList();
                System.Collections.Hashtable MySellingItemsList = TheMySqlManager.GetSellingItemList(0);

                // sum up all inventory items if the items are on sale
                System.Collections.SortedList TheInventoryList = new System.Collections.SortedList();

                foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                {
                    //adjust the number of slots used...
                    if (MyInventoryItem.pos < 36)
                    {
                        if (MyInventoryItem.is_stackable)
                        {
                            UsedSlots++;
                        }
                        else
                        {
                            UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity);
                        }
                    }
                    //adjust the amount

                    //only display if in selling list
                    if (MySellingItemsList.Contains(MyInventoryItem.SqlID))
                    {
                        //if already in inventory output (eg.., two slots) just sum the quantity
                        //otherwise add to inventory output
                        if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                        {
                            Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                            TempInventoryItem.quantity += MyInventoryItem.quantity;
                            TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                        }
                        else
                        {
                            if (MyInventoryItem.pos < 36)
                            {
                                TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                            }
                        }
                    }
                }

                //foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                //{
                //    if(maxlen<MyInventoryItem.name.Length && (MyInventoryItem.pos < 36))
                //        maxlen = MyInventoryItem.name.Length;
                //}
                //maxlen++;
                maxlen = 20 + 25 - Settings.Loginname.Length;
                // pm all summed up inventory items on sale
                int i = 0;
                for (i = 0; i < 64; i++)
                {
                    Inv[i] = "ZZZZZZZZZZZZZZZZ";
                }
                int    c   = 0;
                string str = "";
                str2 = "";
                str  = "[";
                str  = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                bool Member = (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == true);

                str = "[name".PadRight(maxlen, ' ');
                str = str + "|qty".PadRight(7, ' ');
                str = str + "|price".PadRight(14, ' ');
                str = str + "|id".PadRight(6, ' ');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                string msg, msg2;

                foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                {
                    if (MyInventoryItem.pos < 36)
                    {
                        msg = ("[" + MyInventoryItem.name).PadRight(maxlen, i == 0 ? ' ' : invFiller);
                        {
                            uint tempAmount = 0;
                            if ((TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)) < MyInventoryItem.quantity)
                            {
                                tempAmount = MyInventoryItem.quantity;
                                tempAmount = tempAmount - (TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID));
                            }
                            else
                            {
                                continue;
                            }

                            msg2 = tempAmount.ToString();
                        }
                        msg2 = msg2.PadLeft(6, i == 0 ? ' ' : invFiller);
                        msg  = msg + "|" + msg2;
                        TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]);
                        if (isinv)
                        {
                            msg2 = MySellingItem.pricesale.ToString();
                        }
                        else
                        {
                            msg2 = MySellingItem.pricesalemembers.ToString();
                        }
                        if (!msg2.Contains("."))
                        {
                            msg2 += ".00gc";
                        }
                        else if (msg2[msg2.Length - 2] == '.')
                        {
                            msg2 += "0gc";
                        }
                        else
                        {
                            msg2 += "gc";
                        }
                        msg2   = msg2.PadLeft(13, i == 0 ? ' ' : invFiller);
                        msg    = msg + "|" + msg2;
                        msg2   = MyInventoryItem.SqlID.ToString().PadLeft(5, i == 0 ? ' ' : invFiller);
                        msg    = msg + "|" + msg2;
                        Inv[c] = msg;
                        c++;
                        i = 1 - i;
                    }
                }
                int d;
//                for (d = 0; d < c; d++)
//                {
//                    str = Inv[d].Substring(16) + Inv[d].Substring(0, 16);
//                    Inv[d] = str;
//                }
                Array.Sort(Inv);
                i = maxlen + 13;

                string filter = "";
                if (CommandArray.Length > 1)
                {
                    bool firstTime = true;
                    foreach (string filterPart in CommandArray)
                    {
                        if (firstTime)
                        {
                            firstTime = false;
                            continue;
                        }
                        filter += (" " + filterPart);
                    }
                    //filter = Message.Substring(CommandArray[0].Length);
                }
                else
                {
                    filter = "";
                }

                for (d = 0; d < c; d++)
                {
                    str = Inv[d];
                    //27 chars after the name....
                    if (filter == "" || Inv[d].ToLower().Contains(filter.ToLower().Trim()))
                    {
                        string[] outFields = Inv[d].Split('|');
                        string   outString = Inv[d];
                        if (outFields[0].Length > maxlen)
                        {
                            outString = outFields[0].Substring(0, maxlen - 3) + "...";
                            outString = outString.PadRight(maxlen, ' ') + "|".PadRight(7, ' ') + "|".PadRight(14, ' ') + "|".PadRight(6, ' ');
                            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                            outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' ');
                            int count = 0;
                            foreach (string tempString in outFields)
                            {
                                if (count == 0)
                                {
                                    count++;
                                    continue;
                                }
                                outString += "|" + tempString;
                            }
                        }
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                    }
                    else
                    {
                        //for (i = 1; i < CommandArray.Length; i++)
                        {
                            //if (Inv[d].ToLower().Contains(CommandArray[i].ToLower().Trim()))
                            Console.WriteLine("inv(d): " + Inv[d] + " filter: " + filter);
                            if (Inv[d].ToLower().Contains(filter.ToLower().Trim()))
                            {
                                string[] outFields = Inv[d].Split('|');
                                string   outString = Inv[d];
                                if (outFields[0].Length > maxlen)
                                {
                                    outString = outFields[0].Substring(0, maxlen - 3) + "...";
                                    outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' ');
                                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                                    outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' ');
                                    foreach (string tempString in outFields)
                                    {
                                        outString += "|" + tempString;
                                    }
                                }
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                                i = CommandArray.Length;
                            }
                        }
                    }
                }

                int Phys  = TheMySqlManager.GetBotPhysqiue(Settings.botid);
                int Coord = TheMySqlManager.GetBotCoordination(Settings.botid);
                int carry = (Phys + Coord) * 10;
                //int UsedSpace = TheMySqlManager.GetBotUsedSpace(Settings.botid);
                //int UsedSlots = TheMySqlManager.GetBotUsedSlots(Settings.botid);
                int UsedSpace = TheStats.MyCurrentCarryingAmt;
                int FreeSpace = carry - UsedSpace;
                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                str  = "[";
                str += FreeSpace.ToString() + " EMU Avail|";
                str += (36 - UsedSlots).ToString() + " Open slot(s)";
                if (rank > 89)
                {
                    //str += TheMySqlManager.moneylevel(Settings.botid).ToString() + " gc";
                    str += "|" + TheInventory.GetMoneyAmount().ToString() + " gc";
                }

                str = str.PadRight(maxlen + 27, ' ');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                str = "[";
                if (Member)
                {
                    if ((CommandArray[0] != "#im" && CommandArray[0] != "#invmembers" && CommandArray[0] != "#invmemvers" && CommandArray[0] != "#invmember" && CommandArray[0] != "#invmemver"))
                    {
                        str = str.PadRight(maxlen + 27, '-');
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                        str = "[Use invmembers (im) to see member prices";
                        str = str.PadRight(maxlen + 27, ' ');
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    }
                    //if (isinv)
                    //{
                    //    str = "[to see member prices use invmembers or im";
                    //    str = str.PadRight(maxlen + 28, ' ');
                    //    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    //}
                }
                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                return;
            }
            return;

WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #inv command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#inv                                  "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #inv                         "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #inv silver ore              "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            return;
        }
        protected override bool bIntegridadeDados()
        {
            bool bRetorno = false;
            int  nNextIdOrdemCertificado = 0;

            // Produtos Certificado
            System.Collections.ArrayList arlProdutosCertificado = arlProdutosCertificadoOrigem();

            // Normas - Ordenamento
            System.Collections.SortedList sortListNormas = new System.Collections.SortedList();
            for (int i = 0; i < arlProdutosCertificado.Count; i++)
            {
                mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow dtrwProdutoCertificado = (mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow)arlProdutosCertificado[i];
                if (dtrwProdutoCertificado.RowState != System.Data.DataRowState.Deleted)
                {
                    string strNorma = "";
                    if (!dtrwProdutoCertificado.IsmstrNormaNull())
                    {
                        strNorma = dtrwProdutoCertificado.mstrNorma;
                    }
                    else
                    {
                        strNorma = strRetornaNorma(dtrwProdutoCertificado.idNorma);
                    }
                    if (!sortListNormas.ContainsKey(strNorma))
                    {
                        sortListNormas.Add(strNorma, dtrwProdutoCertificado.idNorma);
                    }
                }
            }

            // Normas - Insercao
            for (int i = 0; i < sortListNormas.Count; i++)
            {
                // Classificacao - Ordenamento
                int nIdNorma = Int32.Parse(sortListNormas.GetByIndex(i).ToString());
                System.Collections.SortedList sortListClassificacao = new System.Collections.SortedList();
                for (int j = 0; j < arlProdutosCertificado.Count; j++)
                {
                    mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow dtrwProdutoCertificado = (mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow)arlProdutosCertificado[j];
                    if ((dtrwProdutoCertificado.RowState != System.Data.DataRowState.Deleted) && (!dtrwProdutoCertificado.IsidNormaNull()) && (dtrwProdutoCertificado.idNorma == nIdNorma))
                    {
                        string strClassificacao = strRetornaClassificacao(dtrwProdutoCertificado.idOrdemProduto);
                        if (!sortListClassificacao.Contains(strClassificacao))
                        {
                            sortListClassificacao.Add(strClassificacao, strClassificacao);
                        }
                    }
                }
                // Classificacao - Insercao
                for (int j = 0; j < sortListClassificacao.Count; j++)
                {
                    string strClassificacao = sortListClassificacao.GetByIndex(j).ToString();
                    string strUnidadeUltima = "";
                    for (int k = 0; k < arlProdutosCertificado.Count; k++)
                    {
                        mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow dtrwProdutoCertificado = (mdlDataBaseAccess.Tabelas.XsdTbProdutosCertificadoOrigem.tbProdutosCertificadoOrigemRow)arlProdutosCertificado[k];
                        string strClassificacaoProduto = strRetornaClassificacao(dtrwProdutoCertificado.idOrdemProduto);
                        if ((dtrwProdutoCertificado.RowState != System.Data.DataRowState.Deleted) && (!dtrwProdutoCertificado.IsidNormaNull()) && (dtrwProdutoCertificado.idNorma == nIdNorma) && (strClassificacao == strClassificacaoProduto))
                        {
                            string strUnidadeProduto = strRetornaUnidadeProduto(dtrwProdutoCertificado.idOrdemProduto);
                            if (strUnidadeUltima != strUnidadeProduto)
                            {
                                nNextIdOrdemCertificado++;
                                strUnidadeUltima = strUnidadeProduto;
                            }
                            dtrwProdutoCertificado.idOrdem = nNextIdOrdemCertificado;
                        }
                    }
                }
            }
            bRetorno = true;
            return(bRetorno);
        }
Exemple #20
0
		/// <summary> 
		/// Given the 2 maps fills a document for 1 word.
		/// </summary>
		private static int Index(System.Collections.IDictionary word2Nums, System.Collections.IDictionary num2Words, System.String g, Document doc)
		{
			var keys = (System.Collections.IList) word2Nums[g]; // get list of key#'s
			var i2 = keys.GetEnumerator();
			
			var already = new System.Collections.SortedList(); // keep them sorted
			
			// pass 1: fill up 'already' with all words
			while (i2.MoveNext()) // for each key#
			{
				foreach (var item in
					((System.Collections.IList) num2Words[i2.Current]).Cast<object>().Where(item => already.Contains(item) == false))
				{
					already.Add(item, item);
				}
			}

			var num = 0;
			already.Remove(g); // of course a word is it's own syn
			var it = already.GetEnumerator();
			while (it.MoveNext())
			{
				var cur = (String) it.Key;
				// don't store things like 'pit bull' -> 'american pit bull'
				if (!IsDecent(cur))
				{
					continue;
				}
				num++;
				doc.Add(new Field(F_SYN, cur, Field.Store.YES, Field.Index.NO));
			}
			return num;
		}
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            int    UsedSlots = 0;
            string Message   = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");

            string[] Inv = new string[512];

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');

            if (CommandArray[0] == "#invlist" || CommandArray[0] == "#il")
            {
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#invlist", Settings.botid);

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);
                if (rank < TheMySqlManager.GetCommandRank("#invlist", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly."));
                    return;
                }

                char invFiller = TheMySqlManager.getInvFiller();

                string str1 = "", str2 = "";
                if (TheInventory.GettingInventoryItems == true)
                {
                    str2 = "I am building my inventory list, please try again in a few seconds";
                    str1 = str1.PadRight(str2.Length, '=');
                    str1 = "[" + str1;
                    str2 = "[" + str2;
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                    return;
                }
                if (CommandArray.Length < 1)
                {
                    goto WrongArguments;
                }

                System.Collections.ArrayList MyInventoryList    = TheInventory.GetInventoryList();
                System.Collections.Hashtable MySellingItemsList = TheMySqlManager.GetSellingItemList(0);

                // sum up all inventory items if the items are on sale
                int i = 0;
                for (i = 0; i < 512; i++)
                {
                    Inv[i] = "ZZZZZZZZZZZZZZZZ";
                }
                int c = 0;

                System.Collections.SortedList TheInventoryList = new System.Collections.SortedList();
                System.Collections.SortedList TheWornList      = new System.Collections.SortedList();
                int ii = 0;
                foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                {
                    ii++;
                    if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                    {
//                        if (MyInventoryItem.pos < 36)
                        {
                            Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                            TempInventoryItem.quantity += MyInventoryItem.quantity;
                            TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                        }
                    }
                    else
                    {
                        if (MyInventoryItem.pos < 36)
                        {
                            TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                        }
                    }
                    if (MyInventoryItem.pos > 35 && MyInventoryItem.pos < 44)
                    {
                        TheWornList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                    }
                }
                int maxlen = 4;
                foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                {
//                    if (maxlen < MyInventoryItem.name.Length && MyInventoryItem.pos < 44)
                    if (maxlen < MyInventoryItem.name.Length && MyInventoryItem.pos < 36)
                    {
                        maxlen = MyInventoryItem.name.Length;
                    }
                }
                foreach (Inventory.inventory_item MyInventoryItem in TheWornList.Values)
                {
                    if (maxlen <= MyInventoryItem.name.Length + 3)
                    {
                        maxlen = MyInventoryItem.name.Length + 3;
                    }
                }
                str2 = "";
                str1 = "[";
                str1 = str1.PadRight(maxlen + 16, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                str1  = "[ id |";
                str2  = "quantity";
                str2  = str2.PadRight(9, ' ') + "|";
                str1 += str2;
                str2  = "name";
                str2  = str2.PadRight(maxlen, ' ');
                str1  = str1 + str2;
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                str1 = "[";
                str1 = str1.PadRight(maxlen + 16, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                // pm all summed up inventory items on sale
                c = 0;
                i = 1;
                foreach (Inventory.inventory_item MyInventoryItem in TheWornList.Values)
                {
                    if (MyInventoryItem.pos < 44)
                    {
                        if (MyInventoryItem.pos < 36)
                        {
                            if (MyInventoryItem.is_stackable)
                            {
                                UsedSlots++;
                            }
                            else
                            {
                                UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity);
                            }
                        }
                        str1  = "";
                        str2  = "";
                        str2 += MyInventoryItem.SqlID.ToString();
                        str2  = str2.PadLeft(4, i == 0 ? ' ' : invFiller);
                        str2  = "[" + str2 + "|";
                        str1  = MyInventoryItem.quantity.ToString();
                        str1  = str1.PadLeft(9, i == 0 ? ' ' : invFiller);
                        str2 += str1 + "|";
                        if (MyInventoryItem.pos > 35)
                        {
                            str1 = "{E}" + MyInventoryItem.name;
                        }
                        else
                        {
                            str1 = MyInventoryItem.name;
                        }
                        str1 = str1.PadRight(maxlen, i == 0 ? ' ' : invFiller);
                        str1 = str2 + str1;
                        //TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]);
                        //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                        Inv[c++] = str1;
                        //i = 1 - i;
                    }
                }
                foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                {
                    if (MyInventoryItem.pos < 44)
                    {
                        if (MyInventoryItem.pos < 36)
                        {
                            if (MyInventoryItem.is_stackable)
                            {
                                UsedSlots++;
                            }
                            else
                            {
                                UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity);
                            }
                        }
                        str1  = "";
                        str2  = "";
                        str2 += MyInventoryItem.SqlID.ToString();
                        str2  = str2.PadLeft(4, i == 0 ? ' ' : invFiller);
                        str2  = "[" + str2 + "|";
                        str1  = MyInventoryItem.quantity.ToString();
                        str1  = str1.PadLeft(9, i == 0 ? ' ' : invFiller);
                        str2 += str1 + "|";
                        if (MyInventoryItem.pos > 35)
                        {
                            str1 = "{E}" + MyInventoryItem.name;
                        }
                        else
                        {
                            str1 = MyInventoryItem.name;
                        }
                        str1 = str1.PadRight(maxlen, i == 0 ? ' ' : invFiller);
                        str1 = str2 + str1;
                        //TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]);
                        //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                        Inv[c++] = str1;
                        //i = 1 - i;
                    }
                }
                int    d;
                string str;
                for (d = 0; d < c; d++)
                {
                    str    = Inv[d].Substring(16) + Inv[d].Substring(0, 16);
                    Inv[d] = str;
                }
                Array.Sort(Inv);
                i = maxlen + 13;

                string filter = "";
                if (CommandArray.Length > 1)
                {
                    bool firstTime = true;
                    foreach (string filterPart in CommandArray)
                    {
                        if (firstTime)
                        {
                            firstTime = false;
                            continue;
                        }
                        filter += (" " + filterPart);
                    }
                    //filter = Message.Substring(CommandArray[0].Length);
                }
                else
                {
                    filter = "";
                }

                //for (d = c - 1; d >= 0; d--)
                for (d = 0; d < c; d++)
                {
                    i      = Inv[d].Length - 16;
                    str    = Inv[d].Substring(i);
                    str   += Inv[d].Substring(0, i);
                    Inv[d] = str.Substring(str.Length - 16);
                    if (filter == "" || str.ToLower().Contains(filter.ToLower().Trim()))
                    {
                        //string[] outFields = Inv[d].Split('|');
                        //string outString = Inv[d];
                        //if (outFields[0].Length > maxlen)
                        //{
                        //    outString = outFields[0].Substring(0, maxlen - 3) + "...";
                        //    outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' ');
                        //    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                        //    outString = "[...".PadRight(maxlen, ' ');
                        //    foreach (string tempString in outFields)
                        //    {
                        //        outString += "|" + tempString;
                        //    }
                        //}
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    }
                    else
                    {
                        //for (i = 1; i < CommandArray.Length; i++)
                        {
                            if (str.ToLower().Contains(filter.ToLower().Trim()))
                            {
                                //string[] outFields = Inv[d].Split('|');
                                //string outString = Inv[d];
                                //if (outFields[0].Length > maxlen)
                                //{
                                //    outString = outFields[0].Substring(0, maxlen - 3) + "...";
                                //    outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' ');
                                //    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                                //    outString = "[...".PadRight(maxlen, ' ');
                                //    foreach (string tempString in outFields)
                                //    {
                                //        outString += "|" + tempString;
                                //    }
                                //}
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                                i = CommandArray.Length;
                            }
                        }
                    }
                }

                int Phys      = TheMySqlManager.GetBotPhysqiue(Settings.botid);
                int Coord     = TheMySqlManager.GetBotCoordination(Settings.botid);
                int carry     = (Phys + Coord) * 10;
                int UsedSpace = TheStats.MyCurrentCarryingAmt;
                int FreeSpace = carry - UsedSpace;
                str1 = "[";
                str1 = str1.PadRight(maxlen + 16, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                str1  = "[";
                str1 += FreeSpace.ToString() + " EMU Avail|";
                str1 += (36 - UsedSlots).ToString() + " Open slot(s)";
                if (rank > 89)
                {
                    str1 += "|" + TheInventory.GetMoneyAmount().ToString() + " gc";
                }

                str1 = str1.PadRight(maxlen + 16, ' ');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                str1 = "[";
                str1 = str1.PadRight(maxlen + 16, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                return;
            }
            return;

WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #invlist command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#invlist                                  "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #invlist                         "));
            return;
        }
Exemple #22
0
 private System.Collections.SortedList retornaConsignatariosOrdenado()
 {
     System.Collections.SortedList srlConsignatarios = new System.Collections.SortedList();
     try
     {
         foreach (mdlDataBaseAccess.Tabelas.XsdTbImportadoresConsignatarios.tbImportadoresConsignatariosRow dtrwRowTbImportadoresConsignatario in m_typDatSetTbImportadoresConsignatarios.tbImportadoresConsignatarios.Rows)
         {
             if ((dtrwRowTbImportadoresConsignatario.RowState != System.Data.DataRowState.Deleted) && (!srlConsignatarios.Contains(dtrwRowTbImportadoresConsignatario.strNome)))
             {
                 srlConsignatarios.Add(dtrwRowTbImportadoresConsignatario.strNome, dtrwRowTbImportadoresConsignatario);
             }
         }
     }
     catch (Exception err)
     {
         m_cls_ter_tratadorErro.trataErro(ref err);
     }
     return(srlConsignatarios);
 }
Exemple #23
0
        private void AdvertTimer_Tick(object sender, ElapsedEventArgs e)
        {
            try
            {
                int    i = 0;
                uint   advertchannel = TheMySqlManager.advertchannel(Settings.botid);
                Random RandomClass = new Random();
                string advertstr = "", str2 = "", endm = TheMySqlManager.advertendmessage().Trim();
                if (TheTradeHandler.AmITrading() || (TheInventory.GettingInventoryItems == true))
                {
                    this.AdvertTimer.Interval = (1 * 1000);// +RandomClass.Next(0, (60 * 60 * 1000)); ;//m*s*us=1 hour
                    TheLogger.Debug("Advert delayed due to current trade\n");
                    return;
                }
                if (advertchannel != 99999999)
                {
                    //this.AdvertTimer.Interval = (15 * 60 * 1000) + RandomClass.Next(0, (60 * 60 * 1000)); ;//m*s*us=1 hour
                    //this.AdvertTimer.Interval=60*

                    i  = TheMySqlManager.minadverttime() * 1000;
                    i += (RandomClass.Next(0, TheMySqlManager.randomadvertdelay()) * 1000);
                    if (i < 900000)
                    {
                        i = 900000;//minimum 15 minute delay
                    }
                    this.AdvertTimer.Interval = i;
                }
                else
                {
                    if (MainClass.serverName == "test")
                    {
                        this.AdvertTimer.Interval = 1000;
                    }
                }
                TheLogger.Debug("New AdvertTimer.Interval: " + this.AdvertTimer.Interval + "\n");

                if (advertchannel != 99999999 && TheMySqlManager.lastadverttime(Settings.botid) < TheMySqlManager.minadverttime() && MainClass.serverName != "test")
                {
                    return;
                }

                //Start the advertising here, if it's set to true...
                //Assumptions: 140 characters max length
                //Need to get advert_rates from the database for this bot to see how the weights are distributed
                if (TheMySqlManager.advertise())
                {
                    //decide if we should do a text message or a _goods_ message
                    //get the rate for text adverts, it's a number between 0 and 1
                    //then get a random number between 0 and one, if the random number is less than the advert rate, do the advert
                    //otherwise, do a _goods_ advert (buying and selling...)
                    double advertTextRate = TheMySqlManager.getAdvertTextRate();
                    double sellRate       = TheMySqlManager.getSellRate();
                    Random randomDouble   = new Random();
                    double randomRate     = randomDouble.NextDouble();
                    if (randomRate < advertTextRate)
                    {
                        //do a text advert
                        //get a random row from the adverts table and use it as the advertisement
                        //select * from adverts where botid = 2 order by rand() LIMIT 1;
                        advertstr = TheMySqlManager.getTextAdvert();
                    }
                    else
                    {
                        //do a goods advert (buying and selling)
                        //get the selling rate, it's between 0 and 1
                        //get a random number between 0 and 1, if the rate is less than the selling rate, do a "selling" advert
                        //otherwise, do a "buying" advert
                        System.Collections.ArrayList MyInventoryList    = TheInventory.GetInventoryList();
                        System.Collections.ArrayList MySellingItemsList = TheMySqlManager.GetSellingList(1);

                        // sum up all inventory items if the items are on sale
                        System.Collections.SortedList TheInventoryList  = new System.Collections.SortedList();
                        System.Collections.ArrayList  MyWantedItemsList = TheMySqlManager.GetWantedList(1);

                        //add up the inventory stuff
                        foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                        {
                            if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                            {
                                Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                                TempInventoryItem.quantity += MyInventoryItem.quantity;
                                TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                            }
                            else
                            {
                                if (MyInventoryItem.pos < 36)
                                {
                                    TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                                }
                            }
                        }
                        randomRate = randomDouble.NextDouble();
                        if (randomRate < sellRate)
                        {
                            //selling
                            advertstr = "Selling:";
                            foreach (TradeHandler.SellingItem MySellingItem in MySellingItemsList)
                            {
                                if (TheInventoryList.Contains(MySellingItem.KnownItemsSqlID))
                                {
                                    Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)TheInventoryList[MySellingItem.KnownItemsSqlID];
                                    if (MySellingItem.pricesale > 0)
                                    {
                                        uint tempAmount = 0;
                                        if ((TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)) < MyInventoryItem.quantity)
                                        {
                                            tempAmount = MyInventoryItem.quantity;
                                            tempAmount = tempAmount - (TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID));
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                        str2 = tempAmount.ToString() + " " + MyInventoryItem.name + ":" + MySellingItem.pricesale.ToString() + "gc";
                                        if (advertstr.Length + str2.Length + endm.Length < 140)
                                        {
                                            if (advertstr.Length > 8)
                                            {
                                                advertstr += ", ";
                                            }
                                            advertstr += str2;
                                        }
                                    }
                                }
                            }
                            if (advertstr.Length > 8)
                            {
                                advertstr += "|" + endm;
                            }
                            else
                            {
                                advertstr = "";
                            }
                        }
                        else
                        {
                            //buying
                            advertstr = "Buying:";
                            foreach (TradeHandler.WantedItem MyWantedItem in MyWantedItemsList)
                            {
                                if (TheInventoryList.Contains(MyWantedItem.KnownItemsSqlID))
                                {
                                    Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)TheInventoryList[MyWantedItem.KnownItemsSqlID];
                                    if (MyWantedItem.pricepurchase > 0 && MyInventoryItem.quantity < MyWantedItem.maxquantity)
                                    {
                                        str2 = TheMySqlManager.GetKnownItemsname(MyWantedItem.KnownItemsSqlID) + ":" + MyWantedItem.pricepurchase.ToString() + "gc";
                                        if (advertstr.Length + str2.Length + endm.Length < 140)
                                        {
                                            if (advertstr.Length > 7)
                                            {
                                                advertstr += ", ";
                                            }
                                            advertstr += str2;
                                        }
                                    }
                                }
                                else
                                {
                                    if (MyWantedItem.pricepurchase > 0)
                                    {
                                        str2 = TheMySqlManager.GetKnownItemsname(MyWantedItem.KnownItemsSqlID) + ":" + MyWantedItem.pricepurchase.ToString() + "gc";
                                        if (advertstr.Length + str2.Length + endm.Length < 140)
                                        {
                                            if (advertstr.Length > 7)
                                            {
                                                advertstr += ", ";
                                            }
                                            advertstr += str2;
                                        }
                                    }
                                }
                            }
                            if (advertstr.Length > 7)
                            {
                                advertstr += "|" + endm;
                            }
                            else
                            {
                                advertstr = "";
                            }
                        }
                    }
                }
                if (advertstr != "")
                {
                    TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#jc " + advertchannel.ToString()));
                    TheTCPWrapper.Send(CommandCreator.RAW_TEXT("@" + advertstr));
                    TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#lc " + advertchannel.ToString()));
                    TheMySqlManager.advertlog("@@" + advertchannel.ToString() + " " + advertstr);
                    string sql = "UPDATE bots SET lastadverttime = NOW() WHERE botid = " + Settings.botid;
                    TheMySqlManager.raw_sql(sql);
                }
                advertstr = "";
            }
            catch (Exception exception)
            {
                TheErrorHandler.writeErrorMessage("Exception raised in the advert handler..." + exception);
            }
            finally
            {
            }
        }
 // make sure the documents returned by the search match the expected list
 private void  MatchHits(Searcher searcher, Sort sort)
 {
     // make a query without sorting first
     ScoreDoc[] hitsByRank = searcher.Search(query, null, 1000).ScoreDocs;
     CheckHits(hitsByRank, "Sort by rank: "); // check for duplicates
     System.Collections.IDictionary resultMap = new System.Collections.SortedList();
     // store hits in TreeMap - TreeMap does not allow duplicates; existing entries are silently overwritten
     for (int hitid = 0; hitid < hitsByRank.Length; ++hitid)
     {
         resultMap[hitsByRank[hitid].Doc] = hitid; // Value: Hits-Objekt Index
     }
     
     // now make a query using the sort criteria
     ScoreDoc[] resultSort = searcher.Search(query, null, 1000, sort).ScoreDocs;
     CheckHits(resultSort, "Sort by custom criteria: "); // check for duplicates
     
     // besides the sorting both sets of hits must be identical
     for (int hitid = 0; hitid < resultSort.Length; ++hitid)
     {
         System.Int32 idHitDate = (System.Int32) resultSort[hitid].Doc; // document ID from sorted search
         if (!resultMap.Contains(idHitDate))
         {
             Log("ID " + idHitDate + " not found. Possibliy a duplicate.");
         }
         Assert.IsTrue(resultMap.Contains(idHitDate)); // same ID must be in the Map from the rank-sorted search
         // every hit must appear once in both result sets --> remove it from the Map.
         // At the end the Map must be empty!
         resultMap.Remove(idHitDate);
     }
     if (resultMap.Count == 0)
     {
         // log("All hits matched");
     }
     else
     {
         Log("Couldn't match " + resultMap.Count + " hits.");
     }
     Assert.AreEqual(resultMap.Count, 0);
 }
        void ExcuteWithKomlist()
        {
            if (System.IO.File.Exists(komlist) == false)
            {
                throw new BuildException("ES.Build.PackingKom Task Exception: " + komlist + " file not found");
            }

            System.Collections.Hashtable  komtable    = new System.Collections.Hashtable();
            System.Collections.Hashtable  dirtable    = new System.Collections.Hashtable();
            System.Collections.SortedList updatetable = new System.Collections.SortedList();

            Kom2.NET.XorEncrypt encrypt = new Kom2.NET.XorEncrypt();

            System.Xml.XmlDocument xml = new XmlDocument();
            xml.Load(komlist);

            XmlNodeList nodes;

            nodes = xml.SelectNodes("Packinginfo/Xors/Xor");
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes.Item(i);
                encrypt.AddKey(System.Convert.ToUInt32(node.Attributes["Value"].Value));
            }

            nodes = xml.SelectNodes("Packinginfo/Koms/kom");
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes.Item(i);
                komtable.Add(node.Attributes["Source"].Value, node.Attributes["Dest"].Value);
            }

            nodes = xml.SelectNodes("Packinginfo/Dirs/Dir");
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes.Item(i);
                dirtable.Add(node.Attributes["Source"].Value, node.Attributes["Dest"].Value);
            }

            if (oldrev == "0")
            {
                xml   = NoshellProcess.ExcuteXML("svn", string.Format("ls --xml -r {0} {1}", newrev, srcurl));
                nodes = xml.SelectNodes("lists/list/entry");

                foreach (string dirname in dirtable.Keys)
                {
                    xml   = NoshellProcess.ExcuteXML("svn", string.Format("ls --xml -r {0} {1}", newrev, srcurl + dirname.Replace("\\", "/")));
                    nodes = xml.SelectNodes("lists/list/entry");
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        XmlNode node = nodes.Item(i);
                        if (node.Attributes["kind"].Value == "file")
                        {
                            updatetable.Add(System.IO.Path.Combine(dirname, node.SelectSingleNode("name").InnerText), "added");
                        }
                    }
                }

                foreach (string komname in komtable.Keys)
                {
                    updatetable.Add(komname, "added");
                }
            }
            else
            {
                xml = NoshellProcess.ExcuteXML("svn",
                                               string.Format("diff -r {0}:{1} --summarize --xml {2}", oldrev, newrev, srcurl));

                nodes = xml.SelectNodes("/diff/paths/path");

                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode node = nodes.Item(i);

                    string kind  = node.Attributes["kind"].Value;
                    string props = node.Attributes["props"].Value;
                    string item  = node.Attributes["item"].Value;
                    string path  = node.InnerXml.Replace(srcurl, "").Replace("/", "\\");

                    if (item == "none" && props != "none")
                    {
                        item = props;
                    }

                    string komname = CheckDir(komtable, path);
                    string dirname = CheckDir(dirtable, path);

                    if (komtable.Contains(komname))
                    {
                        if (kind == "dir")
                        {
                            if (updatetable.Contains(komname) == false)
                            {
                                updatetable.Add(komname, item);
                            }
                            else
                            {
                                updatetable[komname] = item;
                            }
                        }
                        else if (updatetable.Contains(komname) == false)
                        {
                            updatetable.Add(komname, "modified");
                        }
                    }
                    else if (dirtable.Contains(dirname) && kind == "file")
                    {
                        if (updatetable.Contains(path) == false)
                        {
                            updatetable.Add(path, item);
                        }
                    }
                }
            }


            foreach (System.Collections.DictionaryEntry entry in updatetable)
            {
                string path       = entry.Key.ToString();
                string kind       = entry.Value.ToString();
                string srcfileurl = srcurl + path.Replace("\\", "/");

                string komname = CheckDir(komtable, path);
                string dirname = CheckDir(dirtable, path);

                if (komtable.Contains(komname))
                {
                    string destfilename = System.IO.Path.Combine(destdir, komtable[komname].ToString() + ".kom");
                    Console.WriteLine(String.Format("{0} {1}", kind, destfilename.Replace(destdir, "")));

                    if (kind == "deleted")
                    {
                        if (0 != NoshellProcess.Execute("svn", string.Format("delete {0}", destfilename)))
                        {
                            throw new Exception("Delete Error");
                        }
                    }
                    else
                    {
                        if (System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(destfilename)) == false)
                        {
                            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(destfilename));
                        }

                        string temppath = System.IO.Path.Combine(resdir, System.IO.Path.GetFileName(path));
                        if (System.IO.Directory.Exists(temppath))
                        {
                            System.IO.Directory.Delete(temppath, true);
                        }

                        if (0 != NoshellProcess.Execute("svn", string.Format("export -r {0} \"{1}\" \"{2}\"", newrev, srcfileurl, temppath)))
                        {
                            throw new Exception("Export Error");
                        }

                        foreach (string luafile in System.IO.Directory.GetFiles(temppath, "*.lua", SearchOption.AllDirectories))
                        {
                            if (luac == "true")
                            {
                                System.IO.StreamReader reader = new StreamReader(luafile);
                                System.Text.Encoding   encode = reader.CurrentEncoding;
                                reader.Close();

                                if (encode == System.Text.Encoding.UTF8)
                                {
                                    NoshellProcess.Execute("luac_utf8", string.Format("-o {0} {0}", luafile));
                                }
                                else
                                {
                                    NoshellProcess.Execute("luac", string.Format("-o {0} {0}", luafile));
                                }
                            }
                            if (xor == "true")
                            {
                                encrypt.Encrypt(luafile);
                            }
                        }
                        if (xor == "true")
                        {
                            foreach (string txtfile in System.IO.Directory.GetFiles(temppath, "*.txt", SearchOption.AllDirectories))
                            {
                                encrypt.Encrypt(txtfile);
                            }
                        }

                        Kom2.NET.Komfile.CompressKom(temppath, destfilename);
                        if (kind == "added")
                        {
                            if (0 != NoshellProcess.Execute("svn", string.Format("add --parents \"{0}\"", destfilename)))
                            {
                                throw new Exception("Add Error");
                            }
                        }
                    }
                }
                else if (dirtable.Contains(dirname))
                {
                    string destfilename = System.IO.Path.Combine(destdir, System.IO.Path.Combine(dirtable[dirname].ToString(), System.IO.Path.GetFileName(path)));
                    Console.WriteLine(String.Format("{0} {1}", kind, destfilename.Replace(destdir, "")));

                    if (kind == "deleted")
                    {
                        if (0 != NoshellProcess.Execute("svn", string.Format("delete \"{0}\"", destfilename)))
                        {
                            throw new Exception("Delete Error");
                        }
                    }
                    else
                    {
                        if (System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(destfilename)) == false)
                        {
                            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(destfilename));
                        }

                        if (0 != NoshellProcess.Execute("svn", string.Format("export --force -r {0} \"{1}\" \"{2}\"", newrev, srcfileurl, destfilename)))
                        {
                            throw new Exception("Export Error");
                        }

                        if (kind == "added")
                        {
                            if (0 != NoshellProcess.Execute("svn", string.Format("add --parents \"{0}\"", destfilename)))
                            {
                                throw new Exception("Add Error");
                            }
                        }
                    }
                }
            }
        }
Exemple #26
0
        /// <summary>
        /// Creates a matrix from three selected columns. This must be a x-column, a y-column, and a value column.
        /// </summary>
        /// <param name="xcol">Column of x-values.</param>
        /// <param name="ycol">Column of y-values.</param>
        /// <param name="vcol">Column of v-values.</param>
        /// <param name="newtable">On return, contains the newly created table matrix.</param>
        /// <returns>Null if no error occurs, or an error message.</returns>
        public static string XYVToMatrix(DataColumn xcol, DataColumn ycol, DataColumn vcol, out DataTable newtable)
        {
            newtable = null;
            System.Collections.SortedList xx = new System.Collections.SortedList();
            System.Collections.SortedList yy = new System.Collections.SortedList();
            int len = xcol.Count;

            len = Math.Min(len, ycol.Count);
            len = Math.Min(len, vcol.Count);

            // Fill the xx and yy lists
            for (int i = 0; i < len; ++i)
            {
                if (!xx.Contains(xcol[i]))
                {
                    xx.Add(xcol[i], null);
                }

                if (!yy.Contains(ycol[i]))
                {
                    yy.Add(ycol[i], null);
                }
            }

            DataColumn xnew = (DataColumn)Activator.CreateInstance(xcol.GetType());
            DataColumn ynew = (DataColumn)Activator.CreateInstance(ycol.GetType());

            xnew.Clear();
            ynew.Clear();

            for (int i = xx.Count - 1; i >= 0; --i)
            {
                xnew[i]          = (AltaxoVariant)xx.GetKey(i);
                xx[xx.GetKey(i)] = i;
            }

            for (int i = yy.Count - 1; i >= 0; --i)
            {
                ynew[1 + i]      = (AltaxoVariant)yy.GetKey(i); // 1 + is because the table will get an additional x-column
                yy[yy.GetKey(i)] = i;
            }

            DataColumn vtemplate = (DataColumn)Activator.CreateInstance(vcol.GetType());

            // make a new table with yy.Count number of columns
            DataColumn[] vcols = new DataColumn[yy.Count];
            for (int i = yy.Count - 1; i >= 0; --i)
            {
                vcols[i] = (DataColumn)vtemplate.Clone();
            }

            // now fill the columns
            for (int i = 0; i < len; ++i)
            {
                int xidx = (int)xx[xcol[i]];
                int yidx = (int)yy[ycol[i]];

                vcols[yidx][xidx] = vcol[i];
            }

            // assemble all columns together in a table
            newtable = new DataTable();
            newtable.DataColumns.Add(xnew, "X", ColumnKind.X, 0);
            newtable.PropertyColumns.Add(ynew, "Y", ColumnKind.Y, 0);

            for (int i = 0; i < vcols.Length; ++i)
            {
                newtable.DataColumns.Add(vcols[i], "V" + i.ToString(), ColumnKind.V, 0);
            }

            return(null);
        }
    /// <summary>
    /// This function will return the smallest possible group number, which is currently not in use.
    /// </summary>
    /// <returns>The smallest unused group number (starting at 0).</returns>
    public int GetUnusedColumnGroupNumber()
    {
      System.Collections.SortedList groupNums = new System.Collections.SortedList();
      for(int i=0;i<ColumnCount;i++)
      {
        int group = this.GetColumnGroup(i);
        if(!groupNums.ContainsKey(group))
          groupNums.Add(group,null);
      }

      for(int i=0;i<int.MaxValue;i++)
      {
        if(!groupNums.Contains(i))
          return i;
      }
      return 0;
    }