//randomally seed the sigma, pi, lambda ws etc... void component::initialize_bounds(double mu, segment * data , int K, double scale, double noise_w, double termination, double fp, double forward_bound, double reverse_bound){//random seeds... foot_print = fp; EXIT=false; if (noise_w>0){ noise = NOISE(data->minX, data->maxX, noise_w, 0.5); type = 0; }else{ int complexity=1; if (data->strand == "."){ complexity=3; }else{ complexity=2; } //==================================== random_device rd; mt19937 mt(rd()); double sigma,lambda, pi_EMG, w_EMG ; double b_forward, w_forward; double a_reverse, w_reverse; //==================================== //start sampling //for the bidirectional/EMG component uniform_real_distribution<double> dist_lambda_2(1, 250); uniform_real_distribution<double> dist_sigma_2(1, 250); gamma_distribution<double> dist_lengths(1,( (data->maxX-data->minX)/(K))); sigma = dist_sigma_2(mt)/scale; lambda = scale/dist_lambda_2(mt) ; double dist = (1.0/lambda); int j = get_nearest_position(data, mu, dist); int k = get_nearest_position(data, mu, forward_bound-mu); double pi = 0.5; if (data->strand == "+"){ pi = 1.0; }else if (data->strand=="-") { pi = 0.; } forward = UNI(mu+(1.0/lambda), data->maxX, 1.0 / (complexity*K), 1, j, pi); forward.j=j, forward.k=k; bidir = EMG(mu, sigma, lambda, 1.0 / (complexity*K), 0.5); bidir.foot_print = fp; dist = -(1.0/lambda); j = get_nearest_position( data, mu, dist); k = get_nearest_position(data, mu, reverse_bound-mu); reverse = UNI(data->minX, mu-(1.0/lambda), 1.0 / (complexity*K) , -1, j,1-pi); reverse.j=k, reverse.k=j; termination = (termination > 1); type = 1; } }
// Gets the count of emails in the folder "INBOX" if SelectFolder() has not been called before. int Imap::GetEmailCount() { try { return mpi_Imap->GetEmailCount(); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// Do not use this constructor "manually"! // Call Pop3.FetchEmailAt() to get an instance of EmailParser instead! EmailParser::EmailParser(IntPtr p_Internal) { try { mpi_Email = (cEmailParser*)(void*)p_Internal; } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// Gets the unique identifier that the server has assigned to this email. // Connects to the server (POP3 command UIDL) String* EmailParser::GetUID() { try { return new String(mpi_Email->GetUID().c_str()); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// Deletes the email on the server. // Connects to the server (POP3 command DELE) // ATTENTION: If Pop3.Close() is not called afterwards the email(s) will not be deleted! void EmailParser::Delete() { try { mpi_Email->Delete(); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
String* Imap::GetCurrentFolder() { try { return new String(mpi_Imap->GetCurrentFolder().c_str()); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// Disconect from the server void Imap::Close() { try { mpi_Imap->Close(); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// s_Path = "[Gmail]/Sent" // ATTENTION: s_Path is case sensitive! // If you never call this function the default folder is "INBOX". void Imap::SelectFolder(String* s_Path) { try { mpi_Imap->SelectFolder(StrW(s_Path)); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
EmailParser::eFlags EmailParser::GetFlags() { try { return (eFlags)mpi_Email->GetFlags(); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// Gets the zero-based index of this email in the server's folder (e.g. Inbox) UInt32 EmailParser::GetIndex() { try { return mpi_Email->GetIndex(); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
void Imap::SetAuthData(String* s_User, String* s_Password) { try { mpi_Imap->SetAuthData(StrW(s_User), StrW(s_Password)); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// s_Server = hostname of IMAP server // u16_Port = 0 to use the default port, otherwise the user defined port // e_Security = The encryption mode // If the server sends a certificate that is not signed with a root certificate: // b_AllowInvalidCerts = true -> only write an ERROR to the Trace output. // b_AllowInvalidCerts = false -> throw an exception and do not send the email. Imap::Imap(String* s_Server, UInt16 u16_Port, eSecurity e_Security, bool b_AllowInvalidCerts) { try { mpi_Imap = new cImap(StrW(s_Server), u16_Port, (cCommon::eSecurity)e_Security, b_AllowInvalidCerts, IDR_ROOT_CA); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
UInt32 EmailParser::GetEmbeddedObjectCount() { try { return mpi_Email->GetEmbeddedObjectCount(); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// Gets the emails in the folder "INBOX" if SelectFolder() has not been called before. // Fetches only the header of the email (command FETCH HEADER). // s32_Index is zero-based! // returns null if index invalid EmailParser* Imap::FetchEmailAt(int s32_Index) { try { cEmailParser* p_Email = mpi_Imap->FetchEmailAt(s32_Index); if (!p_Email) return NULL; return new EmailParser((IntPtr)p_Email); } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// For the email "John Miller <*****@*****.**>" // returns String[] with // String[0] = "*****@*****.**" and // String[1] = "John Miller" String* EmailParser::GetReplyTo() [] { try { wstring s_Name; wstring s_Email = mpi_Email->GetReplyTo(&s_Name); // The very awkward way of managed C++ to say "new String[2]" String* s_Array[] = static_cast<String*[]>(Array::CreateInstance(__typeof(String), 2)); s_Array[0] = new String(s_Email.c_str()); s_Array[1] = new String(s_Name .c_str()); return s_Array; } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
void EmailParser::GetCc(List<String*>* i_Emails, List<String*>* i_Names) { try { vector<wstring> i_VectMails; vector<wstring> i_VectNames; mpi_Email->GetCc(&i_VectMails, &i_VectNames); for (size_t i=0; i<i_VectMails.size(); i++) { i_Emails->Add(new String(i_VectMails.at(i).c_str())); i_Names ->Add(new String(i_VectNames.at(i).c_str())); } } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// Get all folders on the server String* Imap::EnumFolders() [] { try { vector<wstring> i_Folders; mpi_Imap->EnumFolders(i_Folders); // The very awkward way of managed C++ to say "new String[n]" String* s_Array[] = static_cast<String*[]>(Array::CreateInstance(__typeof(String), i_Folders.size())); for (size_t i=0; i<i_Folders.size(); i++) { s_Array[i] = new String(i_Folders.at(i).c_str()); } return s_Array; } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
// Get all folders on the server void cImap::EnumFolders(vector<wstring>& i_FolderList) { try { Connect(); vector<ref<net::folder>> i_Folders = mi_Store->getRootFolder()->getFolders(true); // recursive for (size_t i=0; i<i_Folders.size(); i++) { // The folder does not contain emails -> skip it if (i_Folders.at(i)->getType() & net::folder::TYPE_CONTAINS_MESSAGES) { net::folder::path i_Path = i_Folders.at(i)->getFullPath(); i_FolderList.push_back(UNI(i_Path.toString('/'))); } } } catch (...) { // http://stackoverflow.com/questions/21346400/destructors-not-executed-no-stack-unwinding-when-exception-is-thrown throw; } }
// returns local time and the timezone in minutes (+/-) deviation from GMT. // returns DateTime::MinValue (00:00 at January 1, 0001) if no DATE field in the header! DateTime EmailParser::GetDate(Int32* s32_Timezone) { try { DateTime i_Date = DateTime::MinValue; *s32_Timezone = 0; vmime::ref<const vmime::datetime> p_Date = mpi_Email->GetDate(); if (p_Date) { i_Date = DateTime(p_Date->getYear(), p_Date->getMonth(), p_Date->getDay(), p_Date->getHour(), p_Date->getMinute(), p_Date->getSecond()); *s32_Timezone = p_Date->getZone(); } return i_Date; } catch (std::exception& Ex) { throw new Exception(UNI(Ex.what()).c_str()); } }
static void TraceCallback(const char* s8_Trace) { if (gf_Callback) gf_Callback->Invoke(new String(UNI(s8_Trace).c_str())); }