示例#1
0
        public override int GetHashCode()
        {
            int num = 0;
            StringCollection stringCollection = new StringCollection();

            for (int i = 0; i < Count; i++)
            {
                string key = GetKey(i);
                stringCollection.Add(key);
                string[] values = GetValues(i);
                if (values == null)
                {
                    continue;
                }
                string[] array = values;
                foreach (string text in array)
                {
                    if (text != null)
                    {
                        stringCollection.Add(text);
                    }
                }
            }
            StringEnumerator enumerator = stringCollection.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    num ^= current.GetHashCode();
                }
                return(num);
            }
            finally
            {
                (enumerator as IDisposable)?.Dispose();
            }
        }
示例#2
0
        public ReportRuntimeSetup(ReportRuntimeSetup originalSetup, AppDomain newAppDomain)
            : this(newAppDomain, originalSetup.m_exprHostEvidence, originalSetup.m_restrictCodeModulesInCurrentAppDomain, originalSetup.m_requireExpressionHostWithRefusedPermissions)
        {
            if (originalSetup.m_currentAppDomainTrustedCodeModules == null)
            {
                return;
            }
            StringEnumerator enumerator = originalSetup.m_currentAppDomainTrustedCodeModules.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    AddTrustedCodeModuleInCurrentAppDomain(current);
                }
            }
            finally
            {
                (enumerator as IDisposable)?.Dispose();
            }
        }
示例#3
0
        internal void AddReferencedAssembly(Assembly assembly)
        {
            string fileName = Path.GetFileName(assembly.Location);
            bool   flag     = false;

            using (StringEnumerator enumerator = this.compileUnit.ReferencedAssemblies.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (string.Compare(enumerator.Current, fileName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        flag = true;
                        goto Label_0054;
                    }
                }
            }
Label_0054:
            if (!flag)
            {
                this.compileUnit.ReferencedAssemblies.Add(fileName);
            }
        }
示例#4
0
        private void FindChanges(StringEnumerator changes)
        {
            do
            {
                string line = changes.Current.Trim();
                if (line == "")
                {
                    continue;
                }
                int    separatorPos = line.IndexOf(' ');
                string changeType   = line.Substring(0, separatorPos);
                string path         = line.Substring(separatorPos).TrimStart();

                switch (changeType)
                {
                case "A":
                    _added.Add(path);
                    break;

                case "U":
                    _modified.Add(path);
                    break;

                case "D":
                    _deleted.Add(path);
                    break;

                case "_U":
                case "UU":
                    _propertyChanges.Add(path);
                    break;

                default:
                    log.Warn("Unable to parse: " + line);
                    break;
                }
            } while(changes.MoveNext());
        }
示例#5
0
        /// <summary>
        /// Appends a .inv formatted StringCollection to the OrderedDictionary OD_MyInventory
        /// </summary>
        /// <param name="SC_inv">.inv formatted StringCollection</param>
        public static void ConvertToOD(StringCollection SC_inv)
        {
            //Reset the OD_MyInventory
            OD_MyInventory.Clear();
            int icount = 0;

            // Enumerates the elements in the StringCollection.
            StringEnumerator myEnumerator = SC_inv.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                if (myEnumerator.Current != "")
                {
                    if (GetInvType(myEnumerator.Current) == INV_TYPE.FOLDER)
                    {
                        ///Folder tempf = Folder.Create(myEnumerator.Current);
                        ///Convert to Folder and assign in MD
                        ///OD_MyInventory.Add(tempf.cat_id, Folder.Create(myEnumerator.Current));
                        OD_MyInventory.Add(icount, Folder.Create(myEnumerator.Current));
                    }
                    else if (GetInvType(myEnumerator.Current) == INV_TYPE.ITEM)
                    {
                        ///Item tempi = Item.Create(myEnumerator.Current);
                        if (icount == 16)
                        {
                            icount = icount + 0;
                        }
                        OD_MyInventory.Add(icount, Item.Create(myEnumerator.Current));
                    }
                    else
                    {
                        MessageBox.Show("ConvertToOD exception: " + myEnumerator.Current + " is INV_TYPE.NULL");
                    }
                }
                icount = icount + 1;
            }
        }
示例#6
0
        public void AddItem(NamedElement item)
        {
            ((IList)this.items).Add((object)item);
            StringEnumerator enumerator = this.fieldNames.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string    current   = enumerator.Current;
                    Hashtable hashtable = this.fieldsCache[current] as Hashtable;
                    if (hashtable != null)
                    {
                        PropertyInfo property = item.GetType().GetProperty("Item");
                        if (property != null)
                        {
                            object value = property.GetValue(item, new object[1]
                            {
                                current
                            });
                            if (value != null)
                            {
                                hashtable[value] = item;
                            }
                        }
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
示例#7
0
        private void findBestMatchWithinMemory()
        {
            int i = 0;

            bestMatchesList.Clear();
            if (matchedMemoryValues.Count > 0)
            {
                IDictionaryEnumerator de = matchedMemoryValues.GetEnumerator();
                while (de.MoveNext())
                {
                    if (i <= (int)de.Value)
                    {
                        i = (int)de.Value;
                        bestMatchesList.Add((string)de.Key);
//						writeToLogFile("value: ", Convert.ToString(i));
//						writeToLogFile("in matching string : ", de.Key.ToString());
                        if (bestMatchesList.Count > MAX_MATCHES_ALLOWED)
                        {
                            //writeToLogFile("deleting because to much in best list", "-----");
                            string tt = (string)bestMatchesList[0];
                            //writeToLogFile("string is: ", tt);
                            //writeToLogFile("its value lowest in list?: ", Convert.ToString((string)bestMatchesList[0]));
                            bestMatchesList.RemoveAt(0);
                        }
                    }
                }
            }
            matchedMemoryValues.Clear();
            StringEnumerator b = bestMatchesList.GetEnumerator();

            while (b.MoveNext())
            {
                string key = (string)b.Current;
                writeToLogFile("best list final string is : ", key);
            }
            return;
        }
示例#8
0
        static void Main(string[] args)
        {
            StringCollection sl = new StringCollection();

            sl.Add("Likitha");
            sl.Add("Jai");
            sl.Add("Tush");
            sl.Add("Aish");
            sl.Add("Hema");
            sl.Add("Ramya");
            StringEnumerator se = sl.GetEnumerator();

            while (se.MoveNext())
            {
                Console.WriteLine(se.Current);
            }
            Console.WriteLine("count = {0}", sl.Count);
            Console.WriteLine("count is: {0}", sl.Count);
            Console.WriteLine("Is it synchrozied  :{0}", sl.IsSynchronized);
            Console.WriteLine("Readonly :{0}", sl.IsReadOnly);
            Console.WriteLine("-----------------------using Remove method-----------------");
            String[] s1 = new String[] { "Likki", "Micky", "Lucky", "Chicky" };
            sl.Remove("apples");
            Console.WriteLine("After removing---------------");
            foreach (var v in sl)
            {
                Console.WriteLine(v);
            }
            String[] s2 = new String[] { "Likki", "Micky", "Lucky", "Chicky" };
            sl.AddRange(s2);
            foreach (Object obj in sl)
            {
                Console.WriteLine("{0}", obj);
            }
            Console.ReadLine();
        }
示例#9
0
        public NamedElement GetItemById(object itemID)
        {
            NamedElement namedElement = null;

            if (itemID is string)
            {
                namedElement = this.items.GetByName((string)itemID);
            }
            if (namedElement == null)
            {
                object           key        = Field.ConvertToSupportedValue(itemID);
                StringEnumerator enumerator = this.fieldNames.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string    current          = enumerator.Current;
                        Hashtable itemsByFiledName = this.GetItemsByFiledName(current);
                        namedElement = (itemsByFiledName[key] as NamedElement);
                        if (namedElement != null)
                        {
                            break;
                        }
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (namedElement == null && this.createNewItemForUnresoved)
            {
                namedElement = (NamedElement)Activator.CreateInstance(this.newItemsType);
                if (namedElement != null)
                {
                    if (itemID is string)
                    {
                        namedElement.Name = (string)itemID;
                    }
                    else
                    {
                        object           obj         = Field.ConvertToSupportedValue(itemID);
                        StringEnumerator enumerator2 = this.fieldNames.GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                string current2 = enumerator2.Current;
                                if (this.fields[current2].Type == obj.GetType())
                                {
                                    this.SetFieldValue(namedElement, current2, obj);
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            IDisposable disposable2 = enumerator2 as IDisposable;
                            if (disposable2 != null)
                            {
                                disposable2.Dispose();
                            }
                        }
                    }
                    this.AddItem(namedElement);
                }
            }
            return(namedElement);
        }
        public void Exportieren(string exportVerzeichnis, VerzeichnisVorherLeeren verzeichnisVorherLeeren, bool alleStarTagsInExtraDateiExportieren, bool exportFuerGaitoBotDePublizierung, out bool abgebrochen)
        {
            if (!Directory.Exists(exportVerzeichnis))
            {
                throw new ApplicationException(string.Format("Exportverzeichnis '{0}' nicht vorhanden!", exportVerzeichnis));
            }
            switch (verzeichnisVorherLeeren)
            {
            case VerzeichnisVorherLeeren.leerenUndVorherFragen:
            {
                DialogResult dialogResult = MessageBox.Show(string.Format(ResReader.Reader.GetString("ExportVerzeichnisWirklichLeeren"), exportVerzeichnis), ResReader.Reader.GetString("Export"), MessageBoxButtons.YesNo);
                if (dialogResult != DialogResult.Yes)
                {
                    abgebrochen = true;
                    return;
                }
                goto default;
            }

            default:
            {
                string[] directories = Directory.GetDirectories(exportVerzeichnis);
                string[] array       = directories;
                foreach (string text in array)
                {
                    try
                    {
                        Directory.Delete(text, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format(global::MultiLang.ml.ml_string(70, "Das Verzeichnis '{0}' konnte nicht gelöscht werden: {1}"), text, ex.Message));
                        abgebrochen = true;
                        return;
                    }
                }
                string[] files  = Directory.GetFiles(exportVerzeichnis);
                string[] array2 = files;
                foreach (string text2 in array2)
                {
                    try
                    {
                        File.Delete(text2);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(string.Format(global::MultiLang.ml.ml_string(71, "Die Datei '{0}' konnte nicht gelöscht werden: {1}"), text2, ex2.Message));
                        abgebrochen = true;
                        return;
                    }
                }
                break;
            }

            case VerzeichnisVorherLeeren.nichtLeeren:
                break;
            }
            if (alleStarTagsInExtraDateiExportieren)
            {
                StringCollection stringCollection = new StringCollection();
                foreach (IArbeitsbereichDatei item in this.GetZuExportierendeDateien(exportFuerGaitoBotDePublizierung))
                {
                    if (item is AIMLDatei)
                    {
                        AIMLDatei aIMLDatei  = (AIMLDatei)item;
                        AIMLDatei aIMLDatei2 = new AIMLDatei(this);
                        aIMLDatei2.LiesAusString(aIMLDatei.XML.OuterXml);
                        List <AIMLCategory> list = new List <AIMLCategory>();
                        foreach (AIMLCategory category in aIMLDatei2.RootTopic.Categories)
                        {
                            if (category.That == "" && category.Pattern == "*")
                            {
                                stringCollection.Add(category.Template);
                                list.Add(category);
                            }
                        }
                        foreach (AIMLCategory item2 in list)
                        {
                            aIMLDatei2.RootTopic.LoescheCategory(item2);
                        }
                        StringBuilder stringBuilder      = new StringBuilder();
                        string[]      unterverzeichnisse = aIMLDatei.Unterverzeichnisse;
                        foreach (string arg in unterverzeichnisse)
                        {
                            stringBuilder.AppendFormat("{0}_", arg);
                        }
                        string text4 = aIMLDatei2.Dateiname = string.Format("{0}\\{1}{2}.aiml", exportVerzeichnis, stringBuilder.ToString(), aIMLDatei.Titel);
                        bool   flag  = false;
                        aIMLDatei2.Save(out flag);
                    }
                }
                if (stringCollection.Count != 0)
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    stringBuilder2.Append("<pattern>*</pattern><template><random>");
                    StringEnumerator enumerator4 = stringCollection.GetEnumerator();
                    try
                    {
                        while (enumerator4.MoveNext())
                        {
                            string current4 = enumerator4.Current;
                            stringBuilder2.AppendFormat("<li>{0}</li>", current4);
                        }
                    }
                    finally
                    {
                        IDisposable disposable = enumerator4 as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                    stringBuilder2.Append("</random></template>");
                    AIMLDatei aIMLDatei3 = new AIMLDatei(this);
                    aIMLDatei3.LeerFuellen();
                    aIMLDatei3.Dateiname = string.Format("{0}\\_stars_.aiml", exportVerzeichnis);
                    AIMLCategory aIMLCategory = aIMLDatei3.RootTopic.AddNewCategory();
                    aIMLCategory.ContentNode.InnerXml = stringBuilder2.ToString();
                    bool flag2 = false;
                    if (File.Exists(aIMLDatei3.Dateiname))
                    {
                        File.Delete(aIMLDatei3.Dateiname);
                    }
                    aIMLDatei3.Save(out flag2);
                }
                foreach (IArbeitsbereichDatei item3 in this.GetZuExportierendeDateien(exportFuerGaitoBotDePublizierung))
                {
                    if (item3 is StartupDatei)
                    {
                        StartupDatei  startupDatei        = (StartupDatei)item3;
                        StringBuilder stringBuilder3      = new StringBuilder();
                        string[]      unterverzeichnisse2 = item3.Unterverzeichnisse;
                        foreach (string baustein in unterverzeichnisse2)
                        {
                            stringBuilder3.AppendFormat("{0}_", this.DateinameBausteinBereinigt(baustein));
                        }
                        string text5     = "startup";
                        string text6     = string.Format("{0}\\{1}{2}.{3}", exportVerzeichnis, stringBuilder3.ToString(), this.DateinameBausteinBereinigt(startupDatei.Titel), text5);
                        string dateiname = startupDatei.Dateiname;
                        if (string.IsNullOrEmpty(dateiname))
                        {
                            ToolboxStrings.String2File(startupDatei.XML.OuterXml, text6);
                        }
                        else
                        {
                            File.Copy(dateiname, text6, true);
                        }
                    }
                }
            }
            else
            {
                foreach (IArbeitsbereichDatei item4 in this.GetZuExportierendeDateien(exportFuerGaitoBotDePublizierung))
                {
                    StringBuilder stringBuilder4      = new StringBuilder();
                    string[]      unterverzeichnisse3 = item4.Unterverzeichnisse;
                    foreach (string baustein2 in unterverzeichnisse3)
                    {
                        stringBuilder4.AppendFormat("{0}_", this.DateinameBausteinBereinigt(baustein2));
                    }
                    string text7 = "";
                    if (item4 is AIMLDatei)
                    {
                        text7 = "aiml";
                        goto IL_05c3;
                    }
                    if (item4 is StartupDatei)
                    {
                        text7 = "startup";
                        goto IL_05c3;
                    }
                    throw new ApplicationException(string.Format("Datei '{0}' hat einen unbekannten Typ", item4.Titel));
IL_05c3:
                    string text8 = string.Format("{0}\\{1}{2}.{3}", exportVerzeichnis, stringBuilder4.ToString(), this.DateinameBausteinBereinigt(item4.Titel), text7);
                    string dateiname2 = item4.Dateiname;
                    if (string.IsNullOrEmpty(dateiname2))
                    {
                        ToolboxStrings.String2File(item4.XML.OuterXml, text8);
                    }
                    else
                    {
                        File.Copy(dateiname2, text8, true);
                    }
                }
            }
            abgebrochen = false;
        }
示例#11
0
 /// <summary>
 ///   Moves to the next item in the enumeration.
 /// </summary>
 /// <returns><lang langref="true" /> if there is another item; <lang langref="false" /> otherwise.</returns>
 public bool MoveNext()
 {
     return(m_senEnumerator.MoveNext());
 }
        public NamedElement GetItemById(object itemID)
        {
            NamedElement namedElement = null;

            if (itemID is string)
            {
                namedElement = items.GetByName((string)itemID);
            }
            if (namedElement == null)
            {
                object           key        = Field.ConvertToSupportedValue(itemID);
                StringEnumerator enumerator = fieldNames.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string current = enumerator.Current;
                        namedElement = (GetItemsByFiledName(current)[key] as NamedElement);
                        if (namedElement != null)
                        {
                            break;
                        }
                    }
                }
                finally
                {
                    (enumerator as IDisposable)?.Dispose();
                }
            }
            if (namedElement == null && createNewItemForUnresoved)
            {
                namedElement = (NamedElement)Activator.CreateInstance(newItemsType);
                if (namedElement != null)
                {
                    if (itemID is string)
                    {
                        namedElement.Name = (string)itemID;
                    }
                    else
                    {
                        object           obj        = Field.ConvertToSupportedValue(itemID);
                        StringEnumerator enumerator = fieldNames.GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                string current2 = enumerator.Current;
                                if (fields[current2].Type == obj.GetType())
                                {
                                    SetFieldValue(namedElement, current2, obj);
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            (enumerator as IDisposable)?.Dispose();
                        }
                    }
                    AddItem(namedElement);
                }
            }
            return(namedElement);
        }
示例#13
0
            // Returns null if the enumerator was at the end of the enumerable.
            // tagName is set if readStartTag is true.
            string Parse(StringEnumerator e, SubElementHandler subElementHandler, bool readStartTag, string expectedEndTag, out string outTagName)
            {
                if (!readStartTag && expectedEndTag == null)
                {
                    throw new ArgumentException("readStartTag is false and expectedEndTag is null.");
                }

                outTagName = null;
                if (readStartTag)
                {
                    // Skip to opening brace (there could be space between two top-level tags!)
                    // Or there could be none, in which case it's no problem, there just aren't any
                    // more top-level tags.
                    while (true)
                    {
                        if (!e.Valid)
                        {
                            return(null);
                        }
                        if (e.Current == '{')
                        {
                            break;
                        }
                        e.MoveNext();
                    }

                    StringBuilder tag = new StringBuilder();

                    bool closingBraceFound = false;
                    while (e.MoveNext())
                    {
                        if (e.Current == '}')
                        {
                            closingBraceFound = true;
                            e.MoveNext();
                            break;
                        }
                        tag.Append(e.Current);
                    }

                    if (!closingBraceFound)
                    {
                        throw new InvalidDataException("Expected: }, reached end of entry");
                    }

                    outTagName     = tag.ToString();
                    expectedEndTag = "/" + outTagName;
                }

                char last  = default(char);
                bool inTag = false;
                StringBuilder
                    textContent = new StringBuilder(),
                    tagName     = new StringBuilder();

                if (e.Current == '}')
                {
                    throw new InvalidDataException("Unexpected '}' in entry (no corresponding '{').");
                }

                while (true)
                {
                    char c = e.Current;
                    switch (last == '\\' ? '\0' : c)                       //Use default case if last was backslash
                    {
                    case '{':
                        inTag = true;
                        break;

                    case '}':
                        if (tagName.Length > 0 && tagName[0] == '/')
                        {
                            // This is a common error, it seems, and might be worth working around.
                            // Won't work yet. We need to be able to rewind to the {/ss} for the calling Parse.
                            //if (tagName.ToString() == "/ss" && expectedEndTag == "/ex")
                            //	return textContent.ToString();

                            if (tagName.ToString() != expectedEndTag)
                            {
                                throw new InvalidDataException("Expected: {" + expectedEndTag + "}, Found: {" + tagName + "}");
                            }



                            // Don't forget to consume the closing brace!
                            e.MoveNext();

                            return(textContent.ToString());
                        }

                        // In the days of old, this used to be a common occurance meaning that the parser
                        // was broken. However, it is more stable now, and some dictionaries do seem to
                        // contain this error.
                        if (tagName.Length == 0)
                        {
                            throw new InvalidDataException("Unexpected '}', no matching '{'.");
                        }

                        if (!e.MoveNext())
                        {
                            throw new InvalidDataException("Expected {/" + tagName.ToString() + ", found end of entry");
                        }

                        // subElementHandler is responsible for reading the {/tag} (or not, in
                        // the case of {hw/}, {img/} and {br/}
                        string replacement = subElementHandler(tagName.ToString());
                        if (!string.IsNullOrEmpty(replacement))
                        {
                            textContent.Append(replacement);
                        }
                        tagName.Length = 0;
                        inTag          = false;

                        // The child element met an end of stream. No problem, though.
                        if (!e.Valid)
                        {
                            return(textContent.ToString());
                        }
                        continue;                                 // Skip the MoveNext() call, subElementHandler did it

                    case '\\':
                        break;

                    default:
                        (inTag ? tagName : textContent).Append(c);
                        break;
                    }
                    last = c;

                    if (!e.MoveNext())
                    {
                        break;
                    }
                }

                // Some dictionaries seem to expect to be allowed to do "{s}{ss}translation".
                // I'm fine with that, I guess.
                //throw new InvalidDataException("Expected: {" + expectedEndTag + "}, reached end of entry");
                return(textContent.ToString());
            }
 private void frmCustomModules_Load(object sender, EventArgs e)
 {
     try
     {
         string strUserID = clsSuiteCRMHelper.GetUserId();
         if (strUserID == "")
         {
             Globals.ThisAddIn.SuiteCRMUserSession.Login();
         }
         if (Globals.ThisAddIn.SuiteCRMUserSession.id == "")
         {
             MessageBox.Show("Please enter SuiteCRM details in General tab and try again", "Invalid Authentication");
             base.Close();
             return;
         }
         eModuleList modules = clsSuiteCRMHelper.GetModules();
         this.lstViewAvailableModules.SubItemClicked += new SubItemEventHandler(this.listViewAvailableModules_SubItemClicked);
         if (this.settings.CustomModules != null)
         {
             StringEnumerator enumerator = this.settings.CustomModules.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 string[]     strArray = enumerator.Current.Split(new char[] { '|' });
                 ListViewItem item     = new ListViewItem
                 {
                     Text    = strArray[0],
                     Tag     = strArray[1],
                     Checked = true
                 };
                 item.SubItems.Add(strArray[1]);
                 if (strArray[0] != "None" || strArray[1] != "None")
                 {
                     this.lstViewAvailableModules.Items.Add(item);
                 }
             }
         }
         foreach (module_data objModuleData in modules.modules1)
         {
             string str2 = objModuleData.module_key;
             bool   flag = false;
             if (!this.IgnoreModules.Contains(str2))
             {
                 ListViewItem item2 = new ListViewItem
                 {
                     Text = str2,
                     Tag  = str2
                 };
                 item2.SubItems.Add(string.Empty);
                 foreach (ListViewItem item3 in this.lstViewAvailableModules.Items)
                 {
                     if (item3.Text == str2)
                     {
                         flag = true;
                     }
                 }
                 if (!flag)
                 {
                     this.lstViewAvailableModules.Items.Add(item2);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         base.Close();
         MessageBox.Show("Please check the Internet connection", "Network Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
         string strLog;
         strLog  = "------------------" + System.DateTime.Now.ToString() + "-----------------\n";
         strLog += "frmCustomModules_Load General Exception\n";
         strLog += "Message:" + ex.Message + "\n";
         strLog += "Source:" + ex.Source + "\n";
         strLog += "StackTrace:" + ex.StackTrace + "\n";
         strLog += "Data:" + ex.Data.ToString() + "\n";
         strLog += "HResult:" + ex.HResult.ToString() + "\n";
         strLog += "-------------------------------------------------------------------------\n";
         clsSuiteCRMHelper.WriteLog(strLog);
     }
 }
        /// <summary>
        /// Based on the provided string of a style attribute. Splits each of the items up into
        /// </summary>
        /// <param name="styleitems"></param>
        /// <returns></returns>
        private Dictionary <string, string> GetSplitStyleItems(string styleitems)
        {
            if (styleitems.StartsWith("'") || styleitems.StartsWith("\""))
            {
                styleitems = styleitems.Substring(1);
            }
            if (styleitems.EndsWith("'") || styleitems.EndsWith("\""))
            {
                styleitems = styleitems.Substring(0, styleitems.Length - 1);
            }

            if (styleitems.Length > 0)
            {
                Buffer.Clear();
                Dictionary <string, string> split     = new Dictionary <string, string>();
                StringEnumerator            enumerate = new StringEnumerator(styleitems);
                bool   inkey               = true;
                string keyname             = string.Empty;
                char   stylevaluegroupchar = '\0';
                while (enumerate.MoveNext())
                {
                    char cur = enumerate.Current;
                    if (cur == HTMLStyleItemTerminator)
                    {
                        if (inkey == false)
                        {
                            if (stylevaluegroupchar != '\0')
                            {
                                //Still in a value grouping so ignore the terminator and just add
                                Buffer.Append(cur);
                            }
                            //full value has been read - if we have a key, then set the value
                            else if (!string.IsNullOrEmpty(keyname))
                            {
                                split[keyname] = Buffer.ToString().Trim();
                                Buffer.Clear();
                                inkey = true;
                                stylevaluegroupchar = '\0';
                            }
                            else
                            {
                                //No key so ignore and move on
                                Buffer.Clear();
                                inkey = true;
                                stylevaluegroupchar = '\0';
                            }
                        }
                    }
                    else if (cur == stylevaluegroupchar)
                    {
                        Buffer.Append(cur);
                        stylevaluegroupchar = '\0';
                    }
                    else if (cur == HTMLStyleValuePairSeparator)
                    {
                        if (inkey)
                        {
                            keyname = Buffer.ToString().Trim();
                            Buffer.Clear();
                            inkey = false;
                        }
                        else if (stylevaluegroupchar != '\0')
                        {
                            Buffer.Append(cur);
                        }
                    }
                    else if (cur == '(' && Buffer.ToString() == "url")
                    {
                        stylevaluegroupchar = ')';
                        Buffer.Append(cur);
                    }
                    else if (cur == HTMLEntityStartMarker)
                    {
                        enumerate.MoveNext();
                        cur = ReadHtmlEscapedChar(enumerate);
                        Buffer.Append(cur);
                        enumerate.MovePrev();
                    }
                    else
                    {
                        Buffer.Append(cur);
                    }
                }

                if (inkey == false && Buffer.Length > 0 && keyname.Length > 0)
                {
                    split[keyname] = Buffer.ToString().Trim();
                }

                if (split.Count > 0)
                {
                    return(split);
                }
                else
                {
                    return(null);
                }
            }

            return(null);
        }
示例#16
0
        private static void ImportSchemasAsClasses(CodeDomProvider codeProvider, System.IO.Stream xsdStream, string ns, string uri, CodeGenerationOptions options, IList elements, StringCollection schemaImporterExtensions)
        {
            XmlSchemas userSchemas = new XmlSchemas();

            Hashtable uris   = new Hashtable();
            XmlSchema schema = ReadSchema(xsdStream);

            Uri uri2 = new Uri("http://www.w3.org/2001/XMLSchema/temp");

            uris.Add(schema, uri2);
            userSchemas.Add(schema, uri2);

            Hashtable includeSchemas = new Hashtable();

            Compile(userSchemas, uris, includeSchemas);
            try
            {
                CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
                CodeNamespace   namespace2      = new CodeNamespace(ns);
                codeCompileUnit.Namespaces.Add(namespace2);
                GenerateVersionComment(namespace2);
                XmlCodeExporter   codeExporter   = new XmlCodeExporter(namespace2, codeCompileUnit, codeProvider, options, null);
                XmlSchemaImporter schemaImporter = new XmlSchemaImporter(userSchemas, options, codeProvider, new ImportContext(new CodeIdentifiers(), false));
                schemaImporter.Extensions.Add(new System.Data.DataSetSchemaImporterExtension());

                {
                    StringEnumerator enumerator2 = schemaImporterExtensions.GetEnumerator();
                    {
                        while (enumerator2.MoveNext())
                        {
                            Type type = Type.GetType(enumerator2.Current.Trim(), true, false);
                            schemaImporter.Extensions.Add(type.FullName, type);
                        }
                    }
                }
                AddImports(namespace2, GetNamespacesForTypes(new Type[] { typeof(XmlAttributeAttribute) }));
                for (int i = 0; i < userSchemas.Count; i++)
                {
                    ImportSchemaAsClasses(userSchemas[i], uri, elements, schemaImporter, codeExporter);
                }
                foreach (XmlSchema schema2 in includeSchemas.Values)
                {
                    ImportSchemaAsClasses(schema2, uri, elements, schemaImporter, codeExporter);
                }

                CompilerParameters compilePrams   = new CompilerParameters();
                CompilerResults    compileResults = codeProvider.CompileAssemblyFromDom(compilePrams, codeCompileUnit);

                if (compileResults.Errors.Count > 0)
                {
                    throw new ArgumentException("Compile Error of " + compileResults.Errors[0].ToString());
                }
                // Feng.Windows.Utils.ReflectionHelper.CreateInstanceFromType(compileResults.CompiledAssembly.GetTypes()[0])

                //CodeTypeDeclarationCollection types = namespace2.Types;
                //CodeGenerator.ValidateIdentifiers(namespace2);
                //TextWriter writer = this.CreateOutputWriter(outputdir, fileName, fileExtension);
                //codeProvider.GenerateCodeFromCompileUnit(codeCompileUnit, writer, null);
                //writer.Close();
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Compile Xsd Error!", ex);
            }
        }
示例#17
0
        static void Main(string[] args)
        {
            //Creating a StringCollection named myCol.
            StringCollection myCol = new StringCollection();

            myCol.Add("A");
            myCol.Add("B");
            myCol.Add("C");
            myCol.Add("D");
            myCol.Add("E");
            myCol.Add("F");
            //Taking an enumerator and using GetEnumerator method.
            //Supports a simple iteration over a StringCollection.
            StringEnumerator myEnumeration = myCol.GetEnumerator();

            //If MoveNext passes the end of the collection, the enumerator is positioned
            //after the last element in the collection and MoveNext returns false.
            while (myEnumeration.MoveNext())
            {
                Console.WriteLine(myEnumeration.Current);
            }

            //StringDictionary collection enumeration.
            StringDictionary dict = new StringDictionary();

            dict.Add("A", "ABC");
            dict.Add("B", "AEC");
            dict.Add("C", "AVC");
            dict.Add("D", "ADC");
            dict.Add("E", "ARC");
            //IEnumerator interface supports a simple iteration over a non-generic collection.
            IEnumerator enumerator = dict.GetEnumerator();
            //Defines dictionary key/value pair that can be set or retrieved.
            DictionaryEntry dictEntry;

            while (enumerator.MoveNext())
            {
                dictEntry = (DictionaryEntry)enumerator.Current;
                Console.WriteLine(dictEntry.Key + ":" + dictEntry.Value);
            }

            //Creating a Hybrid dictionary
            HybridDictionary myHybridDict = new HybridDictionary();

            //Adding key/value pairs in hybrid dictionary.
            myHybridDict.Add("I", "first");
            myHybridDict.Add("II", "second");
            myHybridDict.Add("III", "third");
            myHybridDict.Add("IV", "fourth");
            myHybridDict.Add("V", "fifth");
            //To get an IDictionary enumerator for the hybrid dictionary.
            IDictionaryEnumerator iDictEnum = myHybridDict.GetEnumerator();

            while (iDictEnum.MoveNext())
            {
                Console.WriteLine(iDictEnum.Key + "-->" + iDictEnum.Value);
            }

            //Creating a HashTable.
            Hashtable myHash = new Hashtable();

            //Adding key/value pair for hash table.
            myHash.Add("A", "Apple");
            myHash.Add("B", "Banana");
            myHash.Add("C", "Custard Apple");
            myHash.Add("D", "Dry fruits");
            myHash.Add("E", "Eagle");

            //To get an IDictionaryEnumerator for Hashtable.
            IDictionaryEnumerator iDictHash = myHash.GetEnumerator();

            while (iDictHash.MoveNext())
            {
                Console.WriteLine(iDictHash.Key + "-->" + iDictHash.Value);
            }

            //Creating a ListDictionary
            ListDictionary myLstDict = new ListDictionary();

            myLstDict.Add("India", "New Delhi");
            myLstDict.Add("Australia", "Canberra");
            myLstDict.Add("Belgium", "Brussels");
            myLstDict.Add("Netherland", "Amsterdam");
            myLstDict.Add("China", "Beijing");
            myLstDict.Add("Russia", "Moscow");
            //To get an IDictionaryEnumerator for the ListDictionary.
            IDictionaryEnumerator iDictEnumLstDict = myLstDict.GetEnumerator();

            while (iDictEnumLstDict.MoveNext())
            {
                Console.WriteLine(iDictEnumLstDict.Key + "-->" + iDictEnumLstDict.Value);
            }
            //Creating a SortedDictionary.
            SortedDictionary <string, string> mySortedDict = new SortedDictionary <string, string>();

            mySortedDict.Add("India", "New Delhi");
            mySortedDict.Add("Australia", "Canberra");
            mySortedDict.Add("Belgium", "Brussels");
            mySortedDict.Add("Netherland", "Amsterdam");
            mySortedDict.Add("China", "Beijing");
            mySortedDict.Add("Russia", "Moscow");
            //To get an IDictionaryEnumerator for the SortedDictionary.
            IDictionaryEnumerator iDictEnumerator = mySortedDict.GetEnumerator();

            while (iDictEnumerator.MoveNext())
            {
                Console.WriteLine(iDictEnumerator.Key + "-->" + iDictEnumerator.Value);
            }
            //Creating a collection of string.
            Collection <string> myColl = new Collection <string>();

            myColl.Add("ABD");
            myColl.Add("DEF");
            myColl.Add("CFR");
            myColl.Add("EVF");
            myColl.Add("NBR");
            IEnumerator <string> enumColl = myColl.GetEnumerator();

            while (enumColl.MoveNext())
            {
                Console.WriteLine(enumColl.Current);
            }

            //Creating a Linked list of integers.
            LinkedList <int> myLinkedList = new LinkedList <int>();

            myLinkedList.AddLast(2);
            myLinkedList.AddLast(21);
            myLinkedList.AddLast(12);
            myLinkedList.AddLast(23);
            myLinkedList.AddLast(32);
            //To get an enumerator for the List.
            LinkedList <int> .Enumerator lnkListEnum = myLinkedList.GetEnumerator();
            Display(lnkListEnum);

            //Creating a Hashset<T> of strings.
            //Initialize a new instance of HashSet<string> class that is empty
            //and uses the default equality comparer for the set type.
            HashSet <string> hashset = new HashSet <string>();

            hashset.Add("C#");
            hashset.Add("Asp.Net");
            hashset.Add("SQL Server");
            hashset.Add("MVC");
            hashset.Add("Angular");
            //To get an enumerator for the HashSet<T>.
            HashSet <string> .Enumerator hashEnum = hashset.GetEnumerator();
            DisplayHashSet(hashEnum);
            Console.ReadKey();
        }
示例#18
0
        /// <summary>
        /// 获取所有权限
        /// </summary>
        /// <param name="innovator"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static List <string> getIdentityListByUserID(Innovator innovator, string userid)
        {
            //'===========================================================================================
            Innovator        inn = innovator;
            int              i;
            string           user_id          = userid;
            StringCollection identity_id_list = new StringCollection();

            //'================= ==========================================================================
            //'1.取出使用者的 User Identity ID
            #region 取出使用者的 User Identity ID
            Item a = inn.newItem("Alias", "get");
            a.setAttribute("select", "id, related_id(id, name)");
            a.setProperty("source_id", user_id);
            Item r_a = a.apply();
            if (r_a.isError())
            {
                return(null);
            }
            else
            {
                if (r_a.isCollection())
                {
                    for (i = 0; i < r_a.getItemCount() - 1; i++)
                    {
                        if (!identity_id_list.Contains(r_a.getItemByIndex(i).getRelatedItem().getProperty("id")))
                        {
                            identity_id_list.Add(r_a.getItemByIndex(i).getRelatedItem().getProperty("id"));
                        }
                    }
                }
                else
                {
                    identity_id_list.Add(r_a.getRelatedItem().getProperty("id"));
                }
            }
            #endregion
            //'===========================================================================================
            //'2.取得 World Identity ID
            #region 取得 World Identity ID
            Item ident = inn.newItem("Identity", "get");
            ident.setAttribute("select", "id, name");
            ident.setProperty("name", "World");
            Item r_ident = ident.apply();
            if (r_ident.isError())
            {
                return(null);
            }
            else
            {
                identity_id_list.Add(r_ident.getID());
            }
            ident   = null;
            r_ident = null;
            #endregion
            //'===========================================================================================
            //'3.取得 所屬的所有 Group Identity
            #region 取得 所屬的所有 Group Identity
            Item member;
            Item result;
            //'3-1.將 identity_id_list 從 StringCollection 轉成 String
            StringBuilder    builder    = new StringBuilder();
            StringEnumerator enumerator = identity_id_list.GetEnumerator();
            while (enumerator.MoveNext())
            {
                string current = enumerator.Current;
                if (current != null)
                {
                    builder.Append("'");
                    builder.Append(current.Replace("'", "''"));
                    builder.Append("',");
                }
            }
            StringBuilder new_builder = new StringBuilder(builder.ToString(0, (builder.Length - 1)));
            bool          flag        = true;

            #endregion
            //'3-2.取出所有 Identity 的父階
            #region 取出所有 Identity 的父階
            do
            {
                member = inn.newItem("Member", "get");
                member.setAttribute("select", "id, source_id(id, name)");
                member.setAttribute("where", "(related_id in (" + new_builder.ToString() + ")) and (source_id not in (" + new_builder.ToString() + "))");
                result = member.apply();
                if (result.isError())
                {
                    flag = false;
                }
                else
                {
                    if (result.isCollection())
                    {
                        for (i = 0; i < result.getItemCount() - 1; i++)
                        {
                            if (!identity_id_list.Contains(result.getItemByIndex(i).getPropertyItem("source_id").getProperty("id")))
                            {
                                identity_id_list.Add(result.getItemByIndex(i).getPropertyItem("source_id").getProperty("id"));
                            }
                        }
                    }
                    else
                    {
                        if (!identity_id_list.Contains(result.getPropertyItem("source_id").getID()))
                        {
                            identity_id_list.Add(result.getPropertyItem("source_id").getID());
                        }
                    }
                }
                builder     = null;
                new_builder = null;
                builder     = new System.Text.StringBuilder();
                enumerator  = identity_id_list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    if (current != null)
                    {
                        builder.Append("'");
                        builder.Append(current.Replace("'", "''"));
                        builder.Append("',");
                    }
                }
                new_builder = new StringBuilder(builder.ToString(0, (builder.Length - 1)));
                member      = null;
                result      = null;
            } while (flag);
            #endregion

            //'3-3.將 identity_id_list 從 StringCollection 轉成 String
            #region 將 identity_id_list 從 StringCollection 轉成 String
            builder     = null;
            new_builder = null;
            builder     = new StringBuilder();
            enumerator  = identity_id_list.GetEnumerator();
            while (enumerator.MoveNext())
            {
                string current = enumerator.Current;
                if (current != null)
                {
                    builder.Append("'");
                    builder.Append(current.Replace("'", "''"));
                    builder.Append("',");
                }
            }
            #endregion
            new_builder = new StringBuilder(builder.ToString(0, (builder.Length - 1)));

            List <string> roleList = new List <string>();
            if (!string.IsNullOrEmpty(new_builder.ToString()))
            {
                new_builder = new_builder.Replace("'", "");
                roleList    = new_builder.ToString().Split(',').ToList();
            }
            return(roleList);
        }
        /// <summary>
        /// Returns the character that has been escasped as the current position (just after the ampersand)
        /// </summary>
        /// <returns></returns>
        private char ReadHtmlEscapedChar(StringEnumerator src)
        {
            //Fall back if not found is just to output as is.
            //So we need to remember where we were.
            int curPos = src.Offset;

            int ampersandPos = curPos - 1;

            char cur = src.Current;

            bool terminated = true;

            while (cur != HTMLEntityEndMarker)
            {
                if (!src.MoveNext())
                {
                    terminated = false;
                    break;
                }
                if (src.Offset > curPos + 10) //Max limit of HTML Entities - we are missing a teminating ;
                {
                    terminated = false;
                    break;
                }

                cur = src.Current;
            }

            if (terminated)
            {
                int    length = 1 + src.Offset - ampersandPos;
                string entity = src.Substring(ampersandPos, length);
                char   found;

                if (entity.Length < 3)
                {
                    src.Offset = curPos;
                    return(HTMLEntityStartMarker);
                }
                else if (entity[1] == HTMLEntityNumberMarker) //we have the character number
                {
                    int charNum;

                    if (entity[2] == '#' && int.TryParse(entity.Substring(3, entity.Length - 4), System.Globalization.NumberStyles.HexNumber, null, out charNum))
                    {
                        //we are using the hex codes rather than decimal
                        found = (char)charNum;
                        src.MoveNext();
                        //TODO: Tests for parsing html numbers
                        return(found);
                    }
                    else if (int.TryParse(entity.Substring(2, entity.Length - 3), out charNum))
                    {
                        found = (char)charNum;
                        src.MoveNext();
                        return(found);
                    }
                    else //could not parse the number
                    {
                        src.Offset = curPos;
                        return(HTMLEntityStartMarker);
                    }
                }
                else if (this.Parser.Settings.HTMLEntityMappings.TryGetValue(entity, out found))
                {
                    src.MoveNext(); //past the ;
                    return(found);
                }
                else //Don't know this one so just go back to the orginal offset and return
                {
                    src.Offset = curPos;
                    return(HTMLEntityStartMarker);
                }
            }
            else //Hit End of String or character limit before terminator
            {
                src.Offset = curPos;
                return(HTMLEntityStartMarker);
            }
        }
示例#20
0
        private void _CreateNUnitProjectFile(string nunitProjectFileName, FileSet testFileSet, string appConfig, string appBase)
        {
            XmlTextWriter writer = null;

            try
            {
                if (File.Exists(nunitProjectFileName))
                {
                    File.Delete(nunitProjectFileName);
                }
                bool          flag = (appBase != null) && (appBase.Length > 0);
                DirectoryInfo info = null;
                if (flag)
                {
                    info = new DirectoryInfo(appBase);
                }
                writer = new XmlTextWriter(nunitProjectFileName, Encoding.Default)
                {
                    Formatting = Formatting.Indented
                };
                writer.WriteStartElement("NUnitProject");
                writer.WriteStartElement("Settings");
                writer.WriteAttributeString("activeConfig", "Debug");
                if (flag)
                {
                    writer.WriteAttributeString("appbase", appBase);
                }
                writer.WriteEndElement();
                writer.WriteStartElement("Config");
                writer.WriteAttributeString("name", "Debug");
                if ((appConfig != null) && (appConfig.Length > 0))
                {
                    writer.WriteAttributeString("configfile", appConfig);
                }
                writer.WriteAttributeString("binpathtype", "Auto");
#if (UNDECOMPILABLE)
                using (StringEnumerator enumerator = testFileSet.FileNames.GetEnumerator())
#else
                StringEnumerator enumerator = testFileSet.FileNames.GetEnumerator();
#endif
                {
                    while (enumerator.MoveNext())
                    {
                        FileInfo info2 = new FileInfo(enumerator.Current);
                        if (info2.Exists)
                        {
                            writer.WriteStartElement("assembly");
                            if (flag)
                            {
                                writer.WriteAttributeString("path", info2.FullName.Substring(info.FullName.Length + 1));
                            }
                            else
                            {
                                writer.WriteAttributeString("path", info2.Name);
                            }
                            writer.WriteEndElement();
                        }
                    }
                }
                writer.WriteEndElement();
                writer.WriteStartElement("Config");
                writer.WriteAttributeString("name", "Release");
                writer.WriteAttributeString("binpathtype", "Auto");
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            catch (Exception exception)
            {
                this.Log(Level.Error, exception.Message);
                throw new BuildException(string.Format(CultureInfo.InvariantCulture, "An error occurred while creating file: {0}", new object[] { nunitProjectFileName }), this.Location, exception);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Flush();
                    writer.Close();
                }
            }
        }
示例#21
0
        public OBDParameterValue getValue(OBDParameter param, bool bEnglishUnits)
        {
            if (param.PID.Length > 0)
            {
                m_commLog.AddItem("Requesting " + param.PID);
            }
            else
            {
                m_commLog.AddItem("Requesting " + param.OBDRequest);
            }

            if (param.Service == 0)
            {
                return(getSpecialValue(param, bEnglishUnits));
            }

            OBDResponseList responses = m_obdDevice.query(param);
            string          strItem1  = "Responses: ";
            int             index1    = 0;

            if (0 < responses.ResponseCount)
            {
                do
                {
                    strItem1 = strItem1 + string.Format("[{0}] ", responses.GetOBDResponse(index1).Data);
                    ++index1;
                }while (index1 < responses.ResponseCount);
            }
            m_commLog.AddItem(strItem1);
            OBDParameterValue obdParameterValue = OBDInterpretter.getValue(param, responses, bEnglishUnits);

            if (obdParameterValue.ErrorDetected)
            {
                m_commLog.AddItem("Error Detected!");
                return(obdParameterValue);
            }
            else
            {
                string strItem2 = "Values: ";
                if ((param.ValueTypes & 2) == 2)
                {
                    bool num = obdParameterValue.BoolValue;
                    strItem2 = strItem2 + string.Format("[Bool: {0}] ", num.ToString());
                }
                if ((param.ValueTypes & 1) == 1)
                {
                    double num = obdParameterValue.DoubleValue;
                    strItem2 = strItem2 + string.Format("[Double: {0}] ", num.ToString());
                }
                if ((param.ValueTypes & 4) == 4)
                {
                    strItem2 += string.Format("[String: {0} / {1}] ", obdParameterValue.StringValue, obdParameterValue.ShortStringValue);
                }
                if ((param.ValueTypes & 8) == 8)
                {
                    string           str        = strItem2 + "[StringCollection: ";
                    StringEnumerator enumerator = obdParameterValue.StringCollectionValue.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        do
                        {
                            str = str + enumerator.Current + ", ";
                        }while (enumerator.MoveNext());
                    }
                    strItem2 = str + "]";
                }
                if ((param.ValueTypes & 32) == 32)
                {
                    string str    = strItem2 + "[BitFlags: ";
                    int    index2 = 0;
                    do
                    {
                        str += obdParameterValue.getBitFlag(index2) ? "T" : "F";
                        ++index2;
                    }while (index2 < 32);
                    strItem2 = str + " ]";
                }
                m_commLog.AddItem(strItem2);
                return(obdParameterValue);
            }
        }
示例#22
0
        public static bool HasRealData(object dataSource)
        {
            StringCollection dataSourceDataMembers = GetDataSourceDataMembers(dataSource);

            if (dataSourceDataMembers.Count == 0)
            {
                bool          closeDataReader         = false;
                IDbConnection connection              = null;
                IEnumerable   dataSourceAsIEnumerable = GetDataSourceAsIEnumerable(dataSource, null, out closeDataReader, out connection);
                try
                {
                    IEnumerator enumerator = dataSourceAsIEnumerable.GetEnumerator();
                    try
                    {
                        if (enumerator.MoveNext())
                        {
                            _ = enumerator.Current;
                            return(true);
                        }
                    }
                    finally
                    {
                        IDisposable disposable = enumerator as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                finally
                {
                    if (closeDataReader)
                    {
                        ((IDataReader)dataSourceAsIEnumerable).Close();
                    }
                    connection?.Close();
                }
            }
            else
            {
                StringEnumerator enumerator2 = dataSourceDataMembers.GetEnumerator();
                try
                {
                    while (enumerator2.MoveNext())
                    {
                        string        current                  = enumerator2.Current;
                        bool          closeDataReader2         = false;
                        IDbConnection connection2              = null;
                        IEnumerable   dataSourceAsIEnumerable2 = GetDataSourceAsIEnumerable(dataSource, current, out closeDataReader2, out connection2);
                        try
                        {
                            IEnumerator enumerator = dataSourceAsIEnumerable2.GetEnumerator();
                            try
                            {
                                if (enumerator.MoveNext())
                                {
                                    _ = enumerator.Current;
                                    return(true);
                                }
                            }
                            finally
                            {
                                IDisposable disposable2 = enumerator as IDisposable;
                                if (disposable2 != null)
                                {
                                    disposable2.Dispose();
                                }
                            }
                        }
                        finally
                        {
                            if (closeDataReader2)
                            {
                                ((IDataReader)dataSourceAsIEnumerable2).Close();
                            }
                            connection2?.Close();
                        }
                    }
                }
                finally
                {
                    (enumerator2 as IDisposable)?.Dispose();
                }
            }
            return(false);
        }
示例#23
0
        static void Main(string[] args)
        {
            Console.WriteLine("============StringCollection===========");
            String[]         myArr = new String[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet" };
            StringCollection myCol = new StringCollection();

            myCol.Add("Apple");
            myCol.Add("Orange");
            myCol.Add("Mango");
            myCol.AddRange(myArr);
            foreach (var item2 in myCol)
            {
                Console.WriteLine(item2);
            }
            Console.WriteLine("count of string collection: " + myCol.Count);
            Console.WriteLine("CopyTo:=====");
            string[] str1 = new string[myCol.Count];
            myCol.CopyTo(str1, 0);
            foreach (var item1 in str1)
            {
                Console.WriteLine(item1);
            }
            Console.WriteLine("contains method");
            Console.WriteLine(myCol.Contains("Mango"));
            Console.WriteLine("Insert: dear");
            myCol.Insert(5, "dear");
            StringEnumerator myEnumerator = myCol.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                Console.WriteLine("{0}", myEnumerator.Current);
            }
            Console.WriteLine();

            Console.WriteLine("============StringDictionary===========");
            StringDictionary myCol1 = new StringDictionary();

            myCol1.Add("red", "rojo");
            myCol1.Add("green", "verde");
            myCol1.Add("blue", "azul");
            Console.WriteLine("contains key red :{0}", myCol1.ContainsKey("red"));

            Console.WriteLine("containe value 'azul': {0}", myCol1.ContainsValue("azul"));


            Console.WriteLine("remove key------");
            myCol1.Remove("red");
            IEnumerator myEnumerator1 = myCol1.GetEnumerator();

            foreach (DictionaryEntry de in myCol1)
            {
                Console.WriteLine("{0} {1}", de.Key, de.Value);
            }
            Console.WriteLine();

            Console.WriteLine("============ListDictionary===========");
            ListDictionary myCol2 = new ListDictionary();

            myCol2.Add("Braeburn Apples", "1.49");
            myCol2.Add("Fuji Apples", "1.29");
            myCol2.Add("Gala Apples", "1.49");
            myCol2.Add("Golden Delicious Apples", "1.29");
            myCol2.Add("Granny Smith Apples", "0.89");
            myCol2.Add("Red Delicious Apples", "0.99");
            Console.WriteLine("CopyTo===============");
            DictionaryEntry[] myArr1 = new DictionaryEntry[myCol2.Count];
            myCol2.CopyTo(myArr1, 0);
            foreach (var arr1 in myArr1)
            {
                Console.WriteLine("{0}-->{1}", arr1.Key, arr1.Value);
            }

            Console.WriteLine("Printing the element list using GetEnumerator method-----");
            IEnumerator myEnumerator2 = myCol2.GetEnumerator();

            foreach (DictionaryEntry de in myCol2)
            {
                Console.WriteLine("{0} {1}", de.Key, de.Value);
            }
            Console.WriteLine();
            Console.WriteLine("============HybridDictionary===========");
            HybridDictionary myCol3 = new HybridDictionary();

            myCol3.Add("Braeburn Apples", "1.49");
            myCol3.Add("Fuji Apples", "1.29");
            myCol3.Add("Gala Apples", "1.49");
            myCol3.Add("Golden Delicious Apples", "1.29");
            myCol3.Add("Granny Smith Apples", "0.89");
            myCol3.Add("Red Delicious Apples", "0.99");
            myCol3.Add("Plantain Bananas", "1.49");
            myCol3.Add("Yellow Bananas", "0.79");

            foreach (DictionaryEntry de in myCol3)
            {
                Console.WriteLine("   {0,-25} {1}", de.Key, de.Value);
            }
            Console.WriteLine();

            Console.WriteLine("Number of elements in myDict are :{0} ", myCol3.Count);
            Console.WriteLine("After Remove=======");
            myCol3.Remove("Gala Apples");
            foreach (DictionaryEntry de in myCol3)
            {
                Console.WriteLine("   {0,-25} {1}", de.Key, de.Value);
            }
        }
示例#24
0
 public bool MoveNext() => stringEnumerator.MoveNext();
示例#25
0
            List <Entry> ParseSenses(string definitions, string headWord)
            {
                List <Entry>     senses = new List <Entry>();
                StringEnumerator e      = new StringEnumerator(definitions);

                e.MoveNext();
                while (true)
                {
                    Entry  entry       = new Entry(headWord, new List <Translation>());
                    string topLevelTag = null;
                    string s           = Parse(e, tag => {
                        if (tag == "pr")
                        {
                            ParseStringElement(e, tag, headWord);
                            // Set sense pronunciation
                        }
                        else if (tag == "ps")
                        {
                            ParseStringElement(e, tag, headWord);
                            // Set sense part of speech
                        }
                        else if (tag == "ss")
                        {
                            foreach (Translation tr in ParseTranslation(e, headWord))
                            {
                                // Strings have been trimmed and normalized by ParseTranslation.
                                if (!entry.Translations.Contains(tr))
                                {
                                    entry.Translations.Add(tr);
                                }
                            }
                            return(null);
                        }
                        else
                        {
                            ParseStringElement(e, tag, headWord);
                        }
                        return(null);
                    }, true, null, out topLevelTag);

                    // Check if the enumeration was finished.
                    if (s == null)
                    {
                        break;
                    }

                    if (topLevelTag == "s")
                    {
                        // Combine senses when they're not substantially different.
                        // Senses with the same headword, part of speech and pronunciation are considered the same.
                        // TODO: update when Pr/PoS added to Entry
                        bool merged = false;
                        foreach (Entry other in senses)
                        {
                            if (other.Phrase == entry.Phrase)
                            {
                                merged = true;
                                foreach (Translation tr in entry.Translations)
                                {
                                    other.Translations.Add(tr);
                                }
                                break;
                            }
                        }

                        if (!merged)
                        {
                            senses.Add(entry);
                        }
                    }
                    else if (topLevelTag == "pr")
                    {
                        // Set sense pronunciation
                    }
                    else if (topLevelTag == "ps")
                    {
                        // Why would this be at the top level?
                    }
                }
                return(senses);
            }
示例#26
0
        private void DoCopyToServer(IAsyncResult result)
        {
            try
            {
                _dataServer.EndConnect(result); //modalita' attiva

                _transferType = "T";            //ipotizzo di trasferire un plain text, in caso negativo lo cambio

                object plainText    = null;
                object stringObject = null; // Used to store the return value
                var    thread       = new Thread(

                    () =>
                {
                    IDataObject dataObject = Clipboard.GetDataObject();
                    if (Clipboard.ContainsFileDropList())
                    {
                        plainText = false;
                        StringCollection strColl      = Clipboard.GetFileDropList();
                        StringEnumerator myEnumerator = strColl.GetEnumerator();
                        while (myEnumerator.MoveNext())
                        {
                            stringObject = myEnumerator.Current.ToString();
                        }
                    }
                    else
                    {
                        plainText    = true;
                        stringObject = Clipboard.GetText();
                    }
                });
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();

                long   size;
                string path          = null;
                string message       = null;
                string textClipboard = null;

                if ((bool)plainText)
                {
                    //message = DoRetrievePlainText((string)stringObject);
                    textClipboard = (string)stringObject;
                    size          = textClipboard.Length;
                    message       = size + "!Text";
                }
                else
                {
                    path    = (string)stringObject;
                    message = DoRetrieveFileOrDir(ref path);
                    FileInfo fInfo = new FileInfo(path);
                    size = fInfo.Length;
                }

                using (NetworkStream dataStream = _dataServer.GetStream())
                {
                    //stream per le comunicaz preliminari di controllo
                    //non mandate sul canale di controllo perche' verrebbero intercettate dal thread
                    //che esegue il dispatching dei comandi al server

                    StreamReader dataCtrlStreamR = new StreamReader(dataStream);
                    StreamWriter dataCtrlStreamW = new StreamWriter(dataStream);

                    dataCtrlStreamW.WriteLine(message);
                    dataCtrlStreamW.Flush();

                    //go
                    string answer = dataCtrlStreamR.ReadLine();

                    if (_transferType.Equals("T"))
                    {
                        CopyStreamPlainText(textClipboard, dataStream);
                    }
                    else
                    {
                        using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                        {
                            CopyStream(fs, dataStream, 4096);
                            //se ho inviato una cartella (compressa) devo eliminare lo zip creato
                            if (message.StartsWith("dir;"))
                            {
                                if (File.Exists(path))
                                {
                                    File.Delete(path);
                                }
                            }
                        }
                    }

                    dataCtrlStreamR.Close();
                    dataCtrlStreamW.Close();
                    dataStream.Close();
                }
                _dataServer.Close();
            }
            catch (Exception)
            {
                if (_dataServer != null)
                {
                    if (_dataServer.Connected)
                    {
                        _dataServer.Close();
                    }
                }
            }
        }
 public bool MoveNext()
 {
     return(_stringEnumerator.MoveNext());
 }
示例#28
0
        public static string UnEscapeHtmlString(string value)
        {
            int ampersandPos = value.IndexOf(HTMLEntityStartMarker);

            if (ampersandPos < 0)
            {
                return(value);
            }

            StringBuilder buffer = new StringBuilder();

            StringEnumerator src = new StringEnumerator(value);

            src.MoveNext();

            while (ampersandPos >= 0)
            {
                if (src.Offset < ampersandPos - 1)
                {
                    buffer.Append(value, src.Offset, ampersandPos - (src.Offset));
                }

                src.Offset = ampersandPos;
                bool terminated = true;

                while (src.Current != HTMLEntityEndMarker)
                {
                    if (!src.MoveNext())
                    {
                        terminated = false;
                        break;
                    }
                    else if (src.Offset > ampersandPos + 10)
                    {
                        terminated = false;
                        break;
                    }
                }

                if (terminated)
                {
                    int  len = 1 + src.Offset - ampersandPos;
                    char found;
                    if (len > 3)
                    {
                        string entity = src.Substring(ampersandPos, len);
                        if (entity[1] == HTMLEntityNumberMarker)
                        {
                            int charNum;
                            if (int.TryParse(entity.Substring(2, entity.Length - 3), out charNum))
                            {
                                found = (char)charNum;
                                src.MoveNext();
                                buffer.Append(found);
                            }
                        }
                        //else if (HTMLParserSettings.DefaultEscapedHTMLEntities.TryGetValue(entity, out found))
                        //{
                        //    buffer.Append(found);
                        //    src.MoveNext();
                        //}
                    }
                }

                ampersandPos = value.IndexOf(HTMLEntityStartMarker, src.Offset);
            }

            if (src.Offset < src.Length)
            {
                buffer.Append(src.Substring(src.Length - src.Offset));
            }

            return(buffer.ToString());
        }
示例#29
0
        private void frmCustomModules_Load(object sender, EventArgs e)
        {
            try
            {
                clsSuiteCRMHelper.EnsureLoggedIn(Globals.ThisAddIn.SuiteCRMUserSession);

                if (Globals.ThisAddIn.SuiteCRMUserSession.NotLoggedIn)
                {
                    MessageBox.Show("Please enter SuiteCRM details in General tab and try again", "Invalid Authentication");
                    base.Close();
                    return;
                }
                eModuleList modules = clsSuiteCRMHelper.GetModules();
                this.lstViewAvailableModules.SubItemClicked += new SubItemEventHandler(this.listViewAvailableModules_SubItemClicked);
                if (this.settings.CustomModules != null)
                {
                    StringEnumerator enumerator = this.settings.CustomModules.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        string[]     strArray = enumerator.Current.Split(new char[] { '|' });
                        ListViewItem item     = new ListViewItem
                        {
                            Text    = strArray[0],
                            Tag     = strArray[1],
                            Checked = true
                        };
                        item.SubItems.Add(strArray[1]);
                        if (strArray[0] != "None" || strArray[1] != "None")
                        {
                            this.lstViewAvailableModules.Items.Add(item);
                        }
                    }
                }
                foreach (module_data objModuleData in modules.modules1)
                {
                    string str2 = objModuleData.module_key;
                    bool   flag = false;
                    if (!this.IgnoreModules.Contains(str2))
                    {
                        ListViewItem item2 = new ListViewItem
                        {
                            Text = str2,
                            Tag  = str2
                        };
                        item2.SubItems.Add(string.Empty);
                        foreach (ListViewItem item3 in this.lstViewAvailableModules.Items)
                        {
                            if (item3.Text == str2)
                            {
                                flag = true;
                            }
                        }
                        if (!flag)
                        {
                            this.lstViewAvailableModules.Items.Add(item2);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warn("frmCustomModules_Load error", ex);
                base.Close();
                MessageBox.Show("Please check the Internet connection", "Network Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#30
0
        public virtual bool Send()
        {
            if (string.IsNullOrEmpty(From))
            {
                sendState = SendState.Error;
                message   = "没有发件人!";
                return(false);
            }
            if (string.IsNullOrEmpty(Subject))
            {
                sendState = SendState.Error;
                message   = "没有邮件标题!";
                return(false);
            }
            if (string.IsNullOrEmpty(Body))
            {
                sendState = SendState.Error;
                message   = "没有邮件正文!";
                return(false);
            }
            if (To.Count < 1)
            {
                sendState = SendState.Error;
                message   = "没有收件人!";
                return(false);
            }
            if (string.IsNullOrEmpty(Server))
            {
                sendState = SendState.Error;
                message   = "没有设置邮件服务器地址!";
                return(false);
            }
            if (string.IsNullOrEmpty(Password))
            {
                sendState = SendState.Error;
                message   = "没有设置邮件服务器账号密码!";
                return(false);
            }
            if (string.IsNullOrEmpty(UserName))
            {
                UserName = From;
            }
            MailMessage mailMessage = new MailMessage();

            mailMessage.From            = new MailAddress(From, FromName);
            mailMessage.Subject         = Subject.Trim();
            mailMessage.SubjectEncoding = SubjectEncoding;
            mailMessage.Body            = Body.Trim();
            mailMessage.BodyEncoding    = BodyEncoding;
            mailMessage.IsBodyHtml      = IsBodyHtml;
            foreach (string mailAttachment in mailAttachmentList)
            {
                mailMessage.Attachments.Add(new Attachment(mailAttachment));
            }
            StringEnumerator enumerator2 = To.GetEnumerator();

            try
            {
                while (enumerator2.MoveNext())
                {
                    string      current2    = enumerator2.Current;
                    string[]    array       = current2.Split(Delimiter);
                    MailAddress mailAddress = null;
                    mailAddress = ((array.Length <= 1) ? new MailAddress(array[0].Trim()) : new MailAddress(array[0].Trim(), array[1].Trim()));
                    mailMessage.To.Add(mailAddress);
                }
            }
            finally
            {
                (enumerator2 as IDisposable)?.Dispose();
            }
            if (Bcc.Count > 0)
            {
                enumerator2 = Bcc.GetEnumerator();
                try
                {
                    while (enumerator2.MoveNext())
                    {
                        string      current3    = enumerator2.Current;
                        string[]    array2      = current3.Split(Delimiter);
                        MailAddress mailAddress = null;
                        mailAddress = ((array2.Length <= 1) ? new MailAddress(array2[0].Trim()) : new MailAddress(array2[0].Trim(), array2[1].Trim()));
                        mailMessage.Bcc.Add(mailAddress);
                    }
                }
                finally
                {
                    (enumerator2 as IDisposable)?.Dispose();
                }
            }
            if (CC.Count > 0)
            {
                enumerator2 = CC.GetEnumerator();
                try
                {
                    while (enumerator2.MoveNext())
                    {
                        string      current3    = enumerator2.Current;
                        string[]    array3      = current3.Split(Delimiter);
                        MailAddress mailAddress = null;
                        mailAddress = ((array3.Length <= 1) ? new MailAddress(array3[0].Trim()) : new MailAddress(array3[0].Trim(), array3[1].Trim()));
                        mailMessage.CC.Add(mailAddress);
                    }
                }
                finally
                {
                    (enumerator2 as IDisposable)?.Dispose();
                }
            }
            try
            {
                SmtpClient smtpClient = new SmtpClient(Server, ServerPort);
                smtpClient.Credentials    = new NetworkCredential(UserName, Password);
                smtpClient.SendCompleted += SendCompletedCallback;
                string subject = Subject;
                smtpClient.Send(mailMessage);
            }
            catch (Exception ex)
            {
                sendState = SendState.Error;
                message   = ex.Message;
                return(false);
            }
            mailMessage.Dispose();
            return(true);
        }