예제 #1
0
 public static void StructQuickSort(ref GlobalStruct[] sourceArray, int left, int right)
 {
     if (left < right)
     {
         int index = StructPartition(sourceArray, left, right);
         StructQuickSort(ref sourceArray, left, index - 1);
         StructQuickSort(ref sourceArray, index + 1, right);
     }
 }
예제 #2
0
        public bool GetLinkerInfo(string strCategory)
        {
            bool          bResult = false;
            NotesView     pLinkerView;
            NotesDocument pLinkerDocument;

            try
            {
                if (this._strDataBase != "names.nsf")
                {
                    this.pNotesDatabase = this.pNotesSession.GetDatabase(this._strDomain, "names.nsf", false);
                }

                pLinkerView = this.pNotesDatabase.GetView(strCategory);

                pLinkerDocument = pLinkerView.GetFirstDocument();

                while (pLinkerDocument != null)
                {
                    GlobalStruct[] pLinkerStruct = new GlobalStruct[2];

                    pLinkerStruct[0].oFieldsName  = "Linker_Name";
                    pLinkerStruct[0].oFiledsTypes = "String";
                    pLinkerStruct[0].oFieldValues = pLinkerDocument.GetFirstItem("ListName").Text;

                    pLinkerStruct[1].oFieldsName  = "Linker_Content";
                    pLinkerStruct[1].oFiledsTypes = "String";
                    pLinkerStruct[1].oFieldValues = (pLinkerDocument.GetFirstItem("Members") == null) ? "N/A" : pLinkerDocument.GetFirstItem("Members").Text;

                    this.pInfoList.Add(pLinkerStruct);

                    pLinkerDocument = pLinkerView.GetNextDocument(pLinkerDocument);
                }

                bResult = true;
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;

                bResult = false;
                this.pInfoList.Clear();
            }
            finally
            {
                pLinkerDocument = null;
                pLinkerView     = null;
            }

            return(bResult);
        }
예제 #3
0
        protected void OutputOneGlobalStruct(GlobalStruct es)
        {
            if (!AppUtil.IsEmptyString(es.Desc))
            {
                cur_stream_.WriteComment(es.Desc, 0);
            }

            //enum defined
            cur_stream_.WriteString(String.Format("struct {0}", es.Name), 0);
            cur_stream_.WriteString("{", 0);

            foreach (StructMember it in es.Members)
            {
                if (!AppUtil.IsEmptyString(it.Desc))
                {
                    cur_stream_.WriteComment(it.Desc, 1);
                }

                if (it.IsBaseArray)
                {
                    string sname = "";
                    if (it.MacroLen != null)
                    {
                        sname = String.Format("{0}[{1}]", it.Name, it.MacroLen.Name);
                    }
                    else
                    {
                        sname = String.Format("{0}[{1}]", it.Name, it.ILen);
                    }

                    cur_stream_.WriteString(String.Format("{0}    {1};", DataType2CType(it), sname), 1);
                }
                else
                {
                    cur_stream_.WriteString(String.Format("{0} {1};", DataType2CType(it), it.Name), 1);
                }
            }

            cur_stream_.WriteString("};", 0);
        }
예제 #4
0
 private static void ResizeList(ref GlobalStruct[] dictionary)
 {
     int index = FindFirstNullElement(dictionary);
     if (index > 0)
     {
         Array.Resize(ref dictionary, index);
     }
 }
예제 #5
0
 private static int PositionInList(string word, GlobalStruct[] listOfStrings)
 {
     for (int i = 0; i < listOfStrings.Length; i++)
     {
         if (word == listOfStrings[i].stringField)
         {
             return i;
         }
     }
     return -1;
 }
예제 #6
0
 private static bool IsPreviousElementNeNull(GlobalStruct[] arrayToSearch, int middle)
 {
     if (((arrayToSearch[middle - 1].numericField != 0) && (arrayToSearch[middle - 1].stringField != null)))
     {
         return true;
     }
     return false;
 }
예제 #7
0
 public void TestBinarySearchMethod2()
 {
     GlobalStruct[] Words = new GlobalStruct[3];
     Words[0].stringField = "bina";
     Words[0].numericField = 22;
     Words[1].stringField = "bia";
     Words[1].numericField = 2;
     Words[2].stringField = "ba";
     Words[2].numericField = 32;
     Assert.AreEqual(-1, BinarySearchIndexOfFirstNullElement(Words, 0, Words.Length - 1));
 }
예제 #8
0
        public bool GetMailInfo()
        {
            bool          bResult = false;
            NotesView     pMailView;
            NotesDocument pMailDocument;

            try
            {
                if (this._strDataBase == "names.nsf")
                {
                    this.pNotesDatabase = this.pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false);
                }

                pMailView = this.pNotesDatabase.GetView("($inbox)");

                pMailDocument = pMailView.GetFirstDocument();

                while (pMailDocument != null)
                {
                    if (((object[])pMailDocument.GetItemValue("Reader"))[0].ToString() != "YES")
                    {
                        string strPUID        = string.Empty;
                        string strSupervisors = (((object[])pMailDocument.GetItemValue("CopyTo")).Length == 0) ? "N/A" : ((object[])pMailDocument.GetItemValue("CopyTo"))[0].ToString();

                        if (strSupervisors != "N/A")
                        {
                            for (int i = 1; i < ((object[])pMailDocument.GetItemValue("CopyTo")).Length; i++)
                            {
                                strSupervisors = strSupervisors + ";" + ((object[])pMailDocument.GetItemValue("CopyTo"))[i].ToString();
                            }
                        }

                        string strBody = ((object[])pMailDocument.GetItemValue("Body"))[0].ToString();

                        if (((object[])pMailDocument.GetItemValue("客服中心"))[0].ToString().Length != 0)
                        {
                            strPUID = ((object[])pMailDocument.GetItemValue("客服中心"))[0].ToString();
                        }
                        else if (((object[])pMailDocument.GetItemValue("客服中心"))[0].ToString().Length == 0 && pMailDocument.ParentDocumentUNID == null)
                        {
                            strPUID = "N/A";
                        }
                        else
                        {
                            strPUID = pMailDocument.ParentDocumentUNID;
                        }

                        /*
                         *      if (pMailDocument.HasItem("SMS Agent"))
                         *      {
                         *              strPUID = ((object[])pMailDocument.GetItemValue("SMS Agent"))[0].ToString();
                         *      }
                         *      else if (!pMailDocument.HasItem("SMS Agent") && pMailDocument.ParentDocumentUNID == null)
                         *      {
                         *              strPUID = "N/A";
                         *      }
                         *      else
                         *      {
                         *              strPUID = pMailDocument.ParentDocumentUNID;
                         *      }
                         */

                        GlobalStruct[] pMailStruct = new GlobalStruct[10];

                        pMailStruct[0].oFieldsName  = "Notes_UID";
                        pMailStruct[0].oFiledsTypes = "String";
                        pMailStruct[0].oFieldValues = pMailDocument.UniversalID;

                        pMailStruct[1].oFieldsName  = "Notes_PUID";
                        pMailStruct[1].oFiledsTypes = "String";
                        pMailStruct[1].oFieldValues = strPUID;                         // (pMailDocument.ParentDocumentUNID == null) ? "N/A" : pMailDocument.ParentDocumentUNID;

                        pMailStruct[2].oFieldsName  = "Notes_Subject";
                        pMailStruct[2].oFiledsTypes = "String";
                        pMailStruct[2].oFieldValues = (((object[])pMailDocument.ColumnValues)[5] == null) ? "N/A" : ((object[])pMailDocument.ColumnValues)[5].ToString();

                        pMailStruct[3].oFieldsName  = "Notes_From";
                        pMailStruct[3].oFiledsTypes = "String";
                        pMailStruct[3].oFieldValues = ((object[])pMailDocument.GetItemValue("Principal"))[0].ToString();                         //((object[])pMailDocument.ColumnValues)[1].ToString();

                        pMailStruct[4].oFieldsName  = "Notes_Date";
                        pMailStruct[4].oFiledsTypes = "String";
                        pMailStruct[4].oFieldValues = ((object[])pMailDocument.ColumnValues)[2].ToString();

                        pMailStruct[5].oFieldsName  = "Notes_Supervisors";
                        pMailStruct[5].oFiledsTypes = "String";
                        pMailStruct[5].oFieldValues = (strSupervisors == "") ? "N/A" : strSupervisors;

                        pMailStruct[6].oFieldsName  = "Notes_Content";
                        pMailStruct[6].oFiledsTypes = "String";
                        pMailStruct[6].oFieldValues = (strBody == "") ? "N/A" : System.Web.HttpUtility.HtmlDecode(strBody);

                        //System.Web.HttpUtility.HtmlDecode(strBody)

                        pMailStruct[7].oFieldsName  = "Notes_AttachmentCount";
                        pMailStruct[7].oFiledsTypes = "String";
                        pMailStruct[7].oFieldValues = (((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects == null) ? "0" : ((object[])((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects).Length.ToString();

                        pMailStruct[8].oFieldsName  = "Notes_Category";
                        pMailStruct[8].oFiledsTypes = "String";
                        pMailStruct[8].oFieldValues = (pMailStruct[2].oFieldValues.ToString().IndexOf("|") == -1)? "0" : pMailStruct[2].oFieldValues.ToString().Substring(pMailStruct[2].oFieldValues.ToString().IndexOf("|") + 1, 1);

                        pMailStruct[9].oFieldsName  = "Notes_Status";
                        pMailStruct[9].oFiledsTypes = "String";
                        pMailStruct[9].oFieldValues = (pMailStruct[2].oFieldValues.ToString().IndexOf("催") == -1)? 0 : 1;
                        this.pInfoList.Add(pMailStruct);

                        if (pMailDocument.HasItem("Reader"))
                        {
                            pMailDocument.ReplaceItemValue("Reader", "YES");
                        }
                        else
                        {
                            pMailDocument.AppendItemValue("Reader", "YES");
                        }

                        pMailDocument.Save(true, true, true);
                    }

                    pMailDocument = pMailView.GetNextDocument(pMailDocument);
                }

                bResult = true;
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;

                bResult = false;
                this.pInfoList.Clear();
            }
            finally
            {
                pMailDocument = null;
                pMailView     = null;
            }

            return(bResult);
        }
예제 #9
0
 private static void StructSwap(ref GlobalStruct firstValue, ref GlobalStruct secondValue)
 {
     var temporary = new GlobalStruct();
     temporary = firstValue;
     firstValue = secondValue;
     secondValue = temporary;
 }
예제 #10
0
 private static void CentralizingVotingLists(ref GlobalStruct[] centralVotingList, GlobalStruct[][] listOfVotes)
 {
     for (int i = 0; i < listOfVotes.Length; i++)
     {
         AddListFromOnePollingSection(listOfVotes[i], ref centralVotingList);
         StructQuickSort(ref centralVotingList, 0, centralVotingList.Length - 1);
         ReverseList(ref centralVotingList);
     }
 }
예제 #11
0
 private static GlobalStruct[] CentralizeAndSortVotes(string[] listOfCandidates, GlobalStruct[][] votingLists)
 {
     GlobalStruct[] centralVotingList = InitializingVotingList(listOfCandidates);
     CentralizingVotingLists(ref centralVotingList, votingLists);
     return centralVotingList;
 }
예제 #12
0
 private static int BinarySearchIndexOfFirstNullElement(GlobalStruct[] arrayToSearch, int begin, int end)
 {
     if (begin > end) return -1;
     int middle = begin + (end - begin) / 2;
     GlobalStruct middleElement = arrayToSearch[middle];
     if ((middleElement.numericField == 0) && (middleElement.stringField == null))
     {
         if (middle > 0)
         {
             if (IsPreviousElementNeNull(arrayToSearch, middle))
             {
                 return middle;
             }
             else
             {
                 return BinarySearchIndexOfFirstNullElement(arrayToSearch, begin, middle - 1);
             }
         }
         else
         {
             return 0;
         }
     }
     else
     {
         return BinarySearchIndexOfFirstNullElement(arrayToSearch, middle + 1, end);
     }
 }
예제 #13
0
 private static void AddWordInList(string word, ref GlobalStruct[] listOfString, int indexOfList)
 {
     GlobalStruct newElement = new GlobalStruct();
     newElement.numericField = 1;
     newElement.stringField = word;
     listOfString[indexOfList] = newElement;
 }
예제 #14
0
 private static void AddListFromOnePollingSection(GlobalStruct[] listFromVoteSection, ref GlobalStruct[] centralVotingList)
 {
     foreach (GlobalStruct candidate in listFromVoteSection)
     {
         int index = PositionInList(candidate.stringField, centralVotingList);
         if (index >= 0)
         {
             UpdateNumberOfVotesForOneCandidate(ref centralVotingList, index, candidate.numericField);
         }
     }
 }
예제 #15
0
 private static void ReverseList(ref GlobalStruct[] sourceList)
 {
     for (int i = 0; i < sourceList.Length / 2; i++)
     {
         StructSwap(ref sourceList[i], ref sourceList[sourceList.Length - i - 1]);
     }
 }
예제 #16
0
        private static int StructPartition(GlobalStruct[] sourceArray, int left, int right)
        {
            var pivot = sourceArray[right].numericField;
            var pivotName = sourceArray[right].stringField;
            int i = left;

            for (int j = left; j < right; j++)
            {
                if (sourceArray[j].numericField <= pivot)
                {
                    StructSwap(ref sourceArray[i], ref sourceArray[j]);
                    i++;
                }
            }

            sourceArray[right] = sourceArray[i];
            sourceArray[i].numericField = pivot;
            sourceArray[i].stringField = pivotName;
            return i;
        }
예제 #17
0
 private static GlobalStruct[] CreateListOfStrings(string textToOrder)
 {
     int indexOfList = 0;
     string[] Words = GetWords(textToOrder);
     GlobalStruct[] ListOfStrings = new GlobalStruct[Words.Length];
     string word;
     for (int i = 0; i < Words.Length; i++)
     {
         word = Words[i];
         int position = PositionInList(word, ListOfStrings);
         if (position >= 0)
         {
             IncreaseWordItterations(ref ListOfStrings, position);
         }
         else
         {
             AddWordInList(word, ref ListOfStrings, indexOfList);
             indexOfList++;
         }
     }
     ResizeList(ref ListOfStrings);
     return ListOfStrings;
 }
예제 #18
0
 private static void UpdateNumberOfVotesForOneCandidate(ref GlobalStruct[] canditatesPosition, int index, int number)
 {
     canditatesPosition[index].numericField += number;
 }
예제 #19
0
 private static int FindFirstNullElement(GlobalStruct[] dictionary)
 {
     int indexOffirstNullElement = BinarySearchIndexOfFirstNullElement(dictionary, 0, dictionary.Length - 1);
     return indexOffirstNullElement;
 }
예제 #20
0
        public bool GetMailAttachment(string strNotesUID)
        {
            bool          bResult = false;
            NotesView     pMailView;
            NotesDocument pMailDocument;

            try
            {
                if (this._strDataBase == "names.nsf")
                {
                    this.pNotesDatabase = this.pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false);
                }

                pMailView = this.pNotesDatabase.GetView("($inbox)");

                pMailDocument = pMailView.GetFirstDocument();

                while (pMailDocument != null)
                {
                    if (pMailDocument.UniversalID == strNotesUID)
                    {
                        object[] arrItemObject = (object[])((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects;

                        for (int i = 0; i < arrItemObject.Length; i++)
                        {
                            NotesEmbeddedObject pEmbeddedObject = (NotesEmbeddedObject)arrItemObject[i];

                            pEmbeddedObject.ExtractFile(System.AppDomain.CurrentDomain.BaseDirectory + "\\Attachment\\" + pEmbeddedObject.Source);

                            FileStream pAttachmentStream  = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + "\\Attachment\\" + pEmbeddedObject.Source, FileMode.Open, FileAccess.Read);
                            byte[]     pAttachmentContent = new byte[pAttachmentStream.Length];
                            pAttachmentStream.Read(pAttachmentContent, 0, pAttachmentContent.Length);
                            pAttachmentStream.Close();

                            File.Delete(System.AppDomain.CurrentDomain.BaseDirectory + "\\Attachment\\" + pEmbeddedObject.Source);

                            GlobalStruct[] pAttachmentStruct = new GlobalStruct[2];

                            pAttachmentStruct[0].oFieldsName  = "Notes_AttachmentName";
                            pAttachmentStruct[0].oFiledsTypes = "String";
                            pAttachmentStruct[0].oFieldValues = pEmbeddedObject.Source;

                            pAttachmentStruct[1].oFieldsName  = "Notes_Attachment";
                            pAttachmentStruct[1].oFiledsTypes = "Byte[]";
                            pAttachmentStruct[1].oFieldValues = pAttachmentContent;

                            pAttachmentContent = null;

                            this.pInfoList.Add(pAttachmentStruct);
                        }
                    }

                    pMailDocument = pMailView.GetNextDocument(pMailDocument);
                }

                bResult = true;
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;

                bResult = false;
                this.pInfoList.Clear();
            }
            finally
            {
                pMailDocument = null;
                pMailView     = null;
            }

            if (this.pInfoList.Count == 0)
            {
                return(false);
            }

            return(bResult);
        }
예제 #21
0
 private static void IncreaseWordItterations(ref GlobalStruct[] dictionary, int position)
 {
     dictionary[position].numericField++;
 }
예제 #22
0
 private static GlobalStruct[] InitializingVotingList(string[] listOfCandidates)
 {
     GlobalStruct[] temporaryList = new GlobalStruct[listOfCandidates.Length];
     for (int i = 0; i < listOfCandidates.Length; i++)
     {
         temporaryList[i].stringField = listOfCandidates[i];
     }
     return temporaryList;
 }
예제 #23
0
 public void TestBinarySearchMethod0()
 {
     GlobalStruct[] Words = new GlobalStruct[3];
     Assert.AreEqual(0, BinarySearchIndexOfFirstNullElement(Words, 0, Words.Length - 1));
 }