public static void Run(string data, Organization organization, Person runningPerson) { if (!data.StartsWith("\r\n<html>\r\n<head>\r\n <style>\r\n .tal")) { runningPerson.SendPhoneMessage("The file you uploaded does not appear to be a Payson export file. No processing done. The data has been discarded."); throw new ArgumentException("This does not appear to be a Payson file"); } if (organization.Identity != 1) { runningPerson.SendPhoneMessage("Payson import is currently only supported for PPSE. No processing done. The data has been discarded."); throw new Exception("Payson is only supported for PPSE at the moment."); } ImportResult result = ImportPayson(data); ImportStats stats = ProcessImportedData(result, organization, runningPerson); try { runningPerson.SendPhoneMessage("The Payson file was processed. See mail for more details."); } catch (Exception) { // Ignore error on SMS transmit } string mailBody = string.Empty; mailBody += String.Format("Rows processed: {0,9:N0}\r\n", stats.ProcessedTransactionCount); mailBody += String.Format("Tx imported: {0,9:N0}\r\n", stats.ImportedTransactionCount); mailBody += String.Format("Tx modified: {0,9:N0}\r\n", stats.ModifiedTransactionCount - stats.ImportedTransactionCount); runningPerson.SendNotice("Payson file imported", mailBody, organization.Identity); }
public static PaperLetter Create (Person creator, Organization organization, string fromName, string[] replyAddressLines, DateTime receivedDate, Person recipient, RoleType recipientRole, bool personal) { return Create(creator.Identity, organization.Identity, fromName, replyAddressLines, receivedDate, recipient.Identity, recipientRole, personal); }
static public void Generate (Person person, Organization organization) { GnuPG generatingInstance = new GnuPG(); generatingInstance.Timeout = 120000; generatingInstance.GenerateKeyPair(person.Name, person.PartyEmail, organization.Name, new DateTime(DateTime.Today.Year + 2, 12, 31)); GnuPGKeyCollection keys = new GnuPG().GetKeys(); foreach (GnuPGKey key in keys) { if (key.UserId == person.PartyEmail) { // Console.Write(" signing..."); generatingInstance.SignKey(key.Fingerprint, "*****@*****.**"); // Console.Write(" uploading..."); generatingInstance.UploadKey(key.Fingerprint.Replace(" ", "")); string armorSecret = new GnuPG().GetSecretKey(key.Fingerprint.Replace(" ", "")); string armorPublic = new GnuPG().GetPublicKey(key.Fingerprint.Replace(" ", "")); // Console.Write(" deleting..."); key.Delete(); person.CryptoPublicKey = armorPublic; person.CryptoSecretKey = armorSecret; person.CryptoFingerprint = key.Fingerprint; } } }
public static AutoMail Create (AutoMailType type, Organization org, Geography geo, Person author, string title, string body) { SwarmDb.GetDatabaseForWriting().SetAutoMail (type, org.Identity, geo.Identity, author == null ? 0 : author.Identity, title, body); return FromTypeOrganizationAndGeography (type, org, geo); }
public static OutboundMail Create (Person author, string title, string body, int mailPriority, int mailType, Organization organization, Geography geography) { return Create(author, title, body, mailPriority, mailType, organization, geography, DateTime.Now); }
public static MeetingElection Create (Person creator, Organization org, Geography geo, string name, InternalPollResultsType resultsType, int maxVoteLength, DateTime runningOpens, DateTime runningCloses, DateTime votingOpens, DateTime votingCloses) { return FromIdentity(SwarmDb.GetDatabaseForWriting().CreateInternalPoll(org.Identity, geo.Identity, name, maxVoteLength, resultsType, creator.Identity, runningOpens, runningCloses, votingOpens, votingCloses)); }
public static InboundInvoice Create (Organization organization, DateTime dueDate, Int64 amountCents, FinancialAccount budget, string supplier, string description, string payToAccount, string ocr, string invoiceReference, Person creatingPerson) { InboundInvoice newInvoice = FromIdentity(SwarmDb.GetDatabaseForWriting(). CreateInboundInvoice(organization.Identity, dueDate, budget.Identity, supplier, payToAccount, ocr, invoiceReference, amountCents, creatingPerson.Identity)); newInvoice.Description = description; // Not in original schema; not cause for schema update // Create a corresponding financial transaction with rows FinancialTransaction transaction = FinancialTransaction.Create(organization.Identity, DateTime.Now, "Invoice #" + newInvoice.Identity + " from " + supplier); transaction.AddRow(organization.FinancialAccounts.DebtsInboundInvoices, -amountCents, creatingPerson); transaction.AddRow(budget, amountCents, creatingPerson); // Make the transaction dependent on the inbound invoice transaction.Dependency = newInvoice; // Create notification (slightly misplaced logic, but this is failsafest place) OutboundComm.CreateNotificationAttestationNeeded(budget, creatingPerson, supplier, (double)amountCents / 100.0, description, NotificationResource.InboundInvoice_Created); // Slightly misplaced logic, but failsafer here SwarmopsLogEntry.Create(creatingPerson, new InboundInvoiceCreatedLogEntry(creatingPerson, supplier, description, (double)amountCents / 100.0, budget), newInvoice); return newInvoice; }
public static void Write (Person actingPerson, PWLogItem affectedItem, int affectedItemId, PWLogAction actionType, string actionDescription, string comment) { Write(DateTime.UtcNow, actingPerson.Identity, affectedItem, affectedItemId, actionType, actionDescription, comment, string.Empty, string.Empty, string.Empty); }
public static PaymentGroup Create (Organization organization, DateTime timestamp, Currency currency, Person createdByPerson) { return FromIdentity(SwarmDb.GetDatabaseForWriting().CreatePaymentGroup(organization.Identity, timestamp, currency.Identity, System.DateTime.Now, createdByPerson.Identity)); }
public static void Run(string data, Organization organization, Person runningPerson) { if (!data.StartsWith("Date\t Time\t Time Zone\t Name\t Type")) { runningPerson.SendPhoneMessage("The file you uploaded does not appear to be a PayPal tab-delimited file of all activity. No processing done. The data has been discarded."); throw new ArgumentException("This does not appear to be a PayPal file"); } ImportResult result = ImportPaypal(data); ImportStats stats = ProcessImportedData(result, organization, runningPerson); try { runningPerson.SendPhoneMessage("The PayPal file was processed. See mail for more details."); } catch (Exception) { // Ignore error on SMS transmit } string mailBody = string.Empty; mailBody += String.Format("Rows processed: {0,9:N0}\r\n", stats.ProcessedTransactionCount); mailBody += String.Format("Tx imported: {0,9:N0}\r\n", stats.ImportedTransactionCount); mailBody += String.Format("Tx modified: {0,9:N0}\r\n", stats.ModifiedTransactionCount - stats.ImportedTransactionCount); runningPerson.SendNotice("PayPal file imported", mailBody, organization.Identity); }
public static ExternalActivity Create (Organization organization, Geography geograpy, ExternalActivityType type, DateTime date, string description, Person createdByPerson) { return FromIdentity(SwarmDb.GetDatabaseForWriting().CreateExternalActivity(organization.Identity, geograpy.Identity, date, type, description, createdByPerson.Identity)); }
public static ExpenseClaim Create(Person claimer, Organization organization, FinancialAccount budget, DateTime expenseDate, string description, Int64 amountCents) { ExpenseClaim newClaim = FromIdentityAggressive (SwarmDb.GetDatabaseForWriting().CreateExpenseClaim (claimer.Identity, organization.Identity, budget.Identity, expenseDate, description, amountCents)); // Create the financial transaction with rows string transactionDescription = "Expense #" + newClaim.Identity + ": " + description; // TODO: Localize if (transactionDescription.Length > 64) { transactionDescription = transactionDescription.Substring(0, 61) + "..."; } FinancialTransaction transaction = FinancialTransaction.Create(organization.Identity, DateTime.Now, transactionDescription); transaction.AddRow(organization.FinancialAccounts.DebtsExpenseClaims, -amountCents, claimer); transaction.AddRow(budget, amountCents, claimer); // Make the transaction dependent on the expense claim transaction.Dependency = newClaim; // Create notifications OutboundComm.CreateNotificationAttestationNeeded(budget, claimer, string.Empty, (double)amountCents / 100.0, description, NotificationResource.ExpenseClaim_Created); // Slightly misplaced logic, but failsafer here OutboundComm.CreateNotificationFinancialValidationNeeded(organization, (double) amountCents/100.0, NotificationResource.Receipts_Filed); SwarmopsLogEntry.Create(claimer, new ExpenseClaimFiledLogEntry(claimer /*filing person*/, claimer /*beneficiary*/, (double) amountCents/100.0, budget, description), newClaim); return newClaim; }
public static void Write (Person actingPerson, PWLogItem affectedItem, int affectedItemId, PWLogAction actionType, string actionDescription, string comment, string changedField, string valueBefore, string valueAfter) { Write(DateTime.UtcNow, actingPerson.Identity, affectedItem, affectedItemId, actionType, actionDescription, comment, changedField, valueBefore, valueAfter); }
public void Deattest(Person deattester) { SwarmDb.GetDatabaseForWriting().CreateFinancialValidation(FinancialValidationType.Deattestation, FinancialDependencyType.CashAdvance, this.Identity, DateTime.Now, deattester.Identity, this.AmountCents / 100.0); SwarmDb.GetDatabaseForWriting().SetCashAdvanceAttested(this.Identity, false, Person.NobodyId); OutboundComm.CreateNotificationOfFinancialValidation(this.Budget, this.Person, (double)this.AmountCents / 100.0, this.Description, NotificationResource.CashAdvance_Deattested); }
public static Document Create (string serverFileName, string clientFileName, Int64 fileSize, string description, IHasIdentity identifiableObject, Person uploader) { int newDocumentId = SwarmDb.GetDatabaseForWriting(). CreateDocument(serverFileName, clientFileName, fileSize, description, GetDocumentTypeForObject(identifiableObject), identifiableObject == null? 0: identifiableObject.Identity, uploader.Identity); return FromIdentityAggressive(newDocumentId); }
public static OutboundComm Create(Person sender, Person from, Organization organization, string resolverClassString, string recipientDataXml, string transmitterClassString, string payloadXml, OutboundCommPriority priority) { int newId = SwarmDb.GetDatabaseForWriting().CreateOutboundComm(sender != null? sender.Identity: 0, from != null? from.Identity: 0, organization != null? organization.Identity: 0, resolverClassString, recipientDataXml ?? string.Empty, transmitterClassString, payloadXml, priority); return FromIdentityAggressive(newId); }
public static Person[] SelectStatic (Person[] personArray) { if (personArray == null) { return new Person[0]; } return personArray; }
public static OutboundMail Create (Person author, string title, string body, int mailPriority, int mailType, Organization organization, Geography geography, DateTime releaseDateTime) { return FromIdentity(SwarmDb.GetDatabaseForWriting().CreateOutboundMail(MailAuthorType.Person, author.Identity, title, body, mailPriority, mailType, geography.Identity, organization.Identity, releaseDateTime)); }
public PayoutCreatedLogEntry(Person payingPerson, Person beneficiaryPerson, Organization organization, Currency currency, double amount, string reason) { this.Amount = amount; this.Currency = currency.Code; this.OrganizationId = organization.Identity; this.DateTime = DateTime.UtcNow; this.Description = reason; this.ActingPersonId = payingPerson.Identity; // do not save name for data retention reasons this.BeneficiaryPersonId = (beneficiaryPerson != null ? beneficiaryPerson.Identity : 0); }
public void Transmit(PayloadEnvelope envelope, Person person) { if (envelope.PayloadClass != "Swarmops.Logic.Communications.Transmission.NotificationPayload") { throw new NotImplementedException(); } ICommsRenderer renderer = NotificationPayload.FromXml(envelope.PayloadXml); RenderedComm comm = renderer.RenderComm(person); MailMessage mail = new MailMessage(); // This is a rather simple mail (no images or stuff like that) mail.From = new MailAddress(comm[CommRenderPart.SenderMail], comm[CommRenderPart.SenderName], Encoding.UTF8); mail.To.Add(new MailAddress(person.Mail, person.Name)); mail.Subject = comm[CommRenderPart.Subject]; mail.Body = comm[CommRenderPart.BodyText]; mail.SubjectEncoding = Encoding.UTF8; mail.BodyEncoding = Encoding.UTF8; string smtpServer = _smtpServerCache; DateTime now = DateTime.Now; if (now > _cacheReloadTime) { smtpServer = _smtpServerCache = Persistence.Key ["SmtpServer"]; _cacheReloadTime = now.AddMinutes(5); } if (string.IsNullOrEmpty(smtpServer)) { smtpServer = "192.168.80.204"; // For development use only - invalidate cache instead of this, forcing re-reload _cacheReloadTime = DateTime.MinValue; } SmtpClient mailClient = new SmtpClient(smtpServer); // TODO: SMTP Server login credentials try { mailClient.Send(mail); } catch (Exception e) { _cacheReloadTime = DateTime.MinValue; throw new OutboundCommTransmitException("Cannot send mail to " + person.Mail, e); } }
public static Parley Create (Organization organization, Person person, FinancialAccount budgetInitial, string name, Geography geography, string description, string informationUrl, DateTime startDate, DateTime endDate, Int64 budgetCents, Int64 guaranteeCents, Int64 attendanceFeeCents) { Parley newParley = FromIdentity(SwarmDb.GetDatabaseForWriting().CreateParley(organization.Identity, person.Identity, -(budgetInitial.Identity), name, geography.Identity, description, informationUrl, startDate, endDate, budgetCents, guaranteeCents, attendanceFeeCents)); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ParleyCreated, person.Identity, organization.Identity, 0, 0, newParley.Identity, string.Empty); return newParley; }
public static void CreateActivistWithLogging (Geography geo, Person newActivist, string logMessage, EventSource evtSrc, bool isPublic, bool isConfirmed, int orgId) { PWEvents.CreateEvent(evtSrc, EventType.NewActivist, newActivist.Identity, orgId, geo.Identity, newActivist.Identity, 0, string.Empty); newActivist.CreateActivist(isPublic, isConfirmed); PWLog.Write(newActivist, PWLogItem.Person, newActivist.Identity, PWLogAction.ActivistJoin, "New activist joined.", logMessage); }
public bool CanSeePerson (Person person) { People initialList = People.FromArray(new[] { person }); People filteredList = Authorization.FilterPeopleToMatchAuthority(initialList, this); if (filteredList.Count == 0) { return false; } return true; }
public static Refund Create (Payment payment, Person creatingPerson, Int64 amountCents) { if (amountCents > payment.AmountCents) { throw new ArgumentException("Refund amount cannot exceed payment amount"); } Refund refund = FromIdentity(SwarmDb.GetDatabaseForWriting().CreateRefund(payment.Identity, creatingPerson.Identity, amountCents)); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.RefundCreated, 0, refund.Payment.OutboundInvoice.Organization.Identity, Geography.RootIdentity, 0, refund.Identity, string.Empty); return refund; }
public static OutboundInvoice Create (Organization organization, Person createdByPerson, DateTime dueDate, FinancialAccount budget, string customerName, string invoiceAddressMail, string invoiceAddressPaper, Currency currency, bool domestic, string theirReference) { OutboundInvoice invoice = FromIdentity (SwarmDb.GetDatabaseForWriting().CreateOutboundInvoice(organization.Identity, createdByPerson != null? createdByPerson.Identity : 0, dueDate, budget.Identity, customerName, invoiceAddressPaper, invoiceAddressMail, currency.Identity, string.Empty, domestic, Authentication.CreateRandomPassword(6), theirReference)); // Set reference invoice.Reference = Formatting.AddLuhnChecksum(Formatting.ReverseString(DateTime.Now.ToString("yyyyMMddHHmm")) + invoice.Identity.ToString()); return invoice; }
internal ExpensePayout(Person person, ExpenseClaims expenseClaims) { this.person = person; this.expenseClaims = expenseClaims; decimal total = 0.0m; foreach (ExpenseClaim expense in expenseClaims) { total += expense.Amount; } this.amount = total; }
public static SwarmopsLogEntry CreateEntry (Person person, IXmlPayload logEntry) { string logEntryClass = logEntry.GetType().ToString(); if (logEntryClass.StartsWith("Swarmops.Logic.Support.LogEntries.")) { logEntryClass = logEntryClass.Substring("Swarmops.Logic.Support.LogEntries.".Length); } int logEntryId = SwarmDb.GetDatabaseForWriting().CreateSwarmopsLogEntry( person != null ? person.Identity : 0, logEntryClass, logEntry.ToXml()); return SwarmopsLogEntry.FromIdentityAggressive(logEntryId); }
public ExpenseClaimFiledLogEntry(Person filingPerson, Person beneficiaryPerson, double amount, FinancialAccount budget, string reason) { this.Amount = amount; this.Currency = budget.Organization.Currency.Code; this.DateTime = DateTime.UtcNow; this.Description = reason; this.OrganizationId = budget.OrganizationId; this.FinancialAccountId = budget.Identity; this.FinancialAccountName = budget.Name; // redundancy in case of future name changes this.OwnerPersonId = budget.OwnerPersonId; this.OwnerPersonName = budget.OwnerPersonId != 0 ? budget.Owner.Name : string.Empty; this.ActingPersonId = filingPerson.Identity; // do not save name for data retention reasons this.BeneficiaryPersonId = beneficiaryPerson.Identity; }
public static void TerminateActivistWithLogging (Person p, EventSource eventSourceSignupPage) { int orgId = 1; PWEvents.CreateEvent(eventSourceSignupPage, EventType.LostActivist, p.Identity, orgId, p.Geography.Identity, p.Identity, 0, string.Empty); p.TerminateActivist(); PWLog.Write(PWLogItem.Person, p.Identity, PWLogAction.ActivistLost, "Lost as activist", string.Empty); }
public static Payment CreateSingle (Organization organization, DateTime dateTime, Currency currency, Int64 amountCents, OutboundInvoice invoice, Person createdByPerson) { // TODO: Verify that invoice is not already closed; if so, issue refund // TODO: Verify correct amount invoice.SetPaid(); PaymentGroup group = PaymentGroup.Create(organization, dateTime, currency, createdByPerson); Payment newPayment = FromIdentity(SwarmDb.GetDatabaseForWriting().CreatePayment(group.Identity, amountCents, string.Empty, string.Empty, string.Empty, false, invoice.Identity)); group.AmountCents = amountCents; return newPayment; }
public static void CreateFirstUser(string name, string mail, string password) { // Make sure that no first person exists already, as a security measure Swarmops.Logic.Swarm.Person personOne = null; bool personOneExists = false; try { personOne = Swarmops.Logic.Swarm.Person.FromIdentity(1); if (System.Diagnostics.Debugger.IsAttached) { if (personOne.CityName != "Duckville" || personOne.Mail != "*****@*****.**") // these values are returned in debug environments when no person is found { personOneExists = true; } else { personOne = null; } } else { personOneExists = true; } } catch (Exception) { // We expect this to throw. } if (personOneExists || personOne != null) { throw new InvalidOperationException("Cannot run initialization processes again when initialized."); } Swarmops.Logic.Swarm.Person newPerson = Swarmops.Logic.Swarm.Person.Create(HttpUtility.UrlDecode(name), HttpUtility.UrlDecode(mail), HttpUtility.UrlDecode(password), string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, DateTime.MinValue, PersonGender.Unknown); newPerson.AddMembership(1, DateTime.MaxValue); // Add membership in Sandbox newPerson.AddRole(RoleType.SystemAdmin, 0, 0); // Add role System Admin }
protected void ButtonLogin_Click(object sender, EventArgs args) { // Check the host names and addresses again as a security measure - after all, we can be called from outside our intended script if (!(VerifyHostName(this.TextServerName.Text) && VerifyHostAddress(this.TextServerAddress.Text))) { if (!System.Diagnostics.Debugger.IsAttached) { return; // Probable hack attempt - fail silently } } Swarmops.Logic.Swarm.Person expectedPersonOne = Swarmops.Logic.Security.Authentication.Authenticate("1", this.TextFirstUserPassword1.Text); if (expectedPersonOne != null) { FormsAuthentication.RedirectFromLoginPage("1,1", true); Response.Redirect("/", true); } }
static public Applicant Create(Person person, Organization organization) { return (FromIdentityAggressive(SwarmDb.GetDatabaseForWriting() .CreateApplicant(person.Identity, organization.Identity))); }