コード例 #1
0
ファイル: InboundInvoice.cs プロジェクト: SwarmCorp/Swarmops
        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;
        }
コード例 #2
0
ファイル: OfficerChain.cs プロジェクト: SwarmCorp/Swarmops
        public static OfficerChain FromOrganizationAndGeography (Organization org, Geography geo)
        {
            int[] concernedPeopleId = Roles.GetAllUpwardRoles(org.Identity, geo.Identity);
            People concernedPeople = People.FromIdentities(concernedPeopleId);

            return new OfficerChain(concernedPeople, org.Identity);
        }
コード例 #3
0
ファイル: PaperLetter.cs プロジェクト: SwarmCorp/Swarmops
 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);
 }
コード例 #4
0
ファイル: Accesses.cs プロジェクト: SwarmCorp/Swarmops
 public Access(Organization organization, Geography geography, AccessAspect aspect, AccessType type)
 {
     this.Organization = organization;
     this.Geography = geography;
     this.Aspect = aspect;
     this.Type = type;
 }
コード例 #5
0
ファイル: PaypalImporter.cs プロジェクト: SwarmCorp/Swarmops
        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);
        }
コード例 #6
0
ファイル: OutboundMail.cs プロジェクト: SwarmCorp/Swarmops
 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);
 }
コード例 #7
0
ファイル: PgpKey.cs プロジェクト: SwarmCorp/Swarmops
        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;
                }
            }

        }
コード例 #8
0
 public void LoadData(Stream dataStream, Organization organization)
 {
     using (TextReader reader = new StreamReader(dataStream))  // TODO: Is encoding necessary?
     {
         LoadData(reader, organization);
     }
 }
コード例 #9
0
ファイル: MeetingElection.cs プロジェクト: SwarmCorp/Swarmops
 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));
 }
コード例 #10
0
ファイル: PaymentGroup.cs プロジェクト: SwarmCorp/Swarmops
 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));
 }
コード例 #11
0
 public Org (Organization org)
     : base(org)
 {
     try
     {
         parentName = Organization.FromIdentity(ParentOrganizationId).Name;
     }
     catch
     {
         parentName = "N/A";
     }
     try
     {
         anchorName = Geography.FromIdentity(AnchorGeographyId).Name;
     }
     catch
     {
         anchorName = "N/A";
     }
     try
     {
         countryCode = base.DefaultCountry.Code;
     }
     catch
     {
         countryCode = "N/A";
     }
 }
コード例 #12
0
ファイル: ExpenseClaim.cs プロジェクト: SwarmCorp/Swarmops
        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;
        }
コード例 #13
0
ファイル: PaysonImporter.cs プロジェクト: SwarmCorp/Swarmops
        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);
        }
コード例 #14
0
 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));
 }
コード例 #15
0
ファイル: AutoMail.cs プロジェクト: SwarmCorp/Swarmops
 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);
 }
コード例 #16
0
ファイル: OutboundComm.cs プロジェクト: SwarmCorp/Swarmops
        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);
        }
コード例 #17
0
 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);
 }
コード例 #18
0
ファイル: OutboundMail.cs プロジェクト: SwarmCorp/Swarmops
 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));
 }
コード例 #19
0
ファイル: PaymentGroup.cs プロジェクト: SwarmCorp/Swarmops
        public static PaymentGroup FromTag (Organization organization, string tag)
        {
            BasicPaymentGroup basicGroup = SwarmDb.GetDatabaseForReading().GetPaymentGroupByTag(organization.Identity, tag);

            if (basicGroup == null)
            {
                return null;
            }

            return FromBasic(basicGroup);
        }
コード例 #20
0
ファイル: Parley.cs プロジェクト: SwarmCorp/Swarmops
        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;
        }
コード例 #21
0
ファイル: OutboundInvoice.cs プロジェクト: SwarmCorp/Swarmops
        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;
        }
コード例 #22
0
ファイル: Payment.cs プロジェクト: SwarmCorp/Swarmops
        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;
        }
コード例 #23
0
ファイル: CashAdvance.cs プロジェクト: SwarmCorp/Swarmops
        public static CashAdvance Create(Organization organization, Person forPerson, Person createdByPerson, Int64 amountCents, FinancialAccount budget, string description)
        {
            CashAdvance newAdvance = FromIdentityAggressive(SwarmDb.GetDatabaseForWriting().CreateCashAdvance(forPerson.Identity,
                                                                                          createdByPerson.Identity,
                                                                                          organization.Identity,
                                                                                          budget.Identity, amountCents,
                                                                                          description));

            OutboundComm.CreateNotificationAttestationNeeded(budget, forPerson, string.Empty, (double) amountCents/100.0, description, NotificationResource.CashAdvance_Requested); // Slightly misplaced logic, but failsafer here
            SwarmopsLogEntry.Create(forPerson,
                                    new CashAdvanceRequestedLogEntry(createdByPerson, forPerson, (double) amountCents/100.0, budget, description),
                                    newAdvance);

            return newAdvance;
        }
コード例 #24
0
ファイル: AutoMail.cs プロジェクト: SwarmCorp/Swarmops
        public static AutoMail FromTypeOrganizationAndGeography (AutoMailType type, Organization org, Geography geo)
        {
            BasicAutoMail basic = SwarmDb.GetDatabaseForReading().GetAutoMail (type, org.Identity, geo.Identity);

            if (basic == null)
            {
                return null;
            }

            if (basic.Body.Trim().Length < 3)
            {
                return null; // If there is no body, there is no mail
            }

            return FromBasic (basic);
        }
コード例 #25
0
ファイル: OutboundComm.cs プロジェクト: SwarmCorp/Swarmops
        public static OutboundComm Create(Person sender, Person from, Organization organization, CommResolverClass resolverClass, string recipientDataXml, CommTransmitterClass transmitterClass, string payloadXml, OutboundCommPriority priority)
        {
            string resolverClassString = string.Empty;
            if (resolverClass != CommResolverClass.Unknown)
            {
                resolverClassString = resolverClass.ToString();
            }

            string transmitterClassString = string.Empty;
            if (transmitterClass != CommTransmitterClass.Unknown)
            {
                transmitterClassString = "Swarmops.Utility.Communications." + transmitterClass.ToString();
            }

            return Create(sender, from, organization, resolverClassString, recipientDataXml, transmitterClassString,
                          payloadXml, priority);
        }
コード例 #26
0
        static public BasicMailTemplate GetBestMatch (string templateName, string language, string country, Organization org)
        {
            List<BasicMailTemplate> tmplList = GetCachedTemplates(templateName);

            Organizations orgLine = ( org != null) ? org.GetLine() : new Organizations();

            int[] lineIDs = orgLine.Identities;
            List<int> idlist = new List<int>(lineIDs);

            BasicMailTemplate templateDefault = null;
            BasicMailTemplate countryDefault = null;
            BasicMailTemplate bestSofar = null;
            int bestIndex = -1;

            foreach (BasicMailTemplate bmt in tmplList)
            {
                int thisIndex = idlist.IndexOf(bmt.OrganizationId);
                if (thisIndex > bestIndex)
                {
                    bestIndex = thisIndex;
                    bestSofar = bmt;
                }
                else if (bmt.CountryCode.ToUpper() == country && bmt.OrganizationId < 1)
                {
                    countryDefault = bmt;
                }
                else if (bmt.CountryCode == "" && bmt.OrganizationId < 1)
                {
                    templateDefault = bmt;
                }
            }
            if (bestSofar != null)
                return bestSofar;
            else if (countryDefault != null)
                return countryDefault;
            else if (templateDefault != null)
                return templateDefault;
            else
                return null;
        }
コード例 #27
0
ファイル: OutboundComm.cs プロジェクト: SwarmCorp/Swarmops
        public static OutboundComm CreateNotification (Organization organization, string notificationResourceString)
        {
            List<Person> recipients = People.FromSingle(Person.FromIdentity(1)); // Initial Admin recipient

            if (organization != null)
            {
                // TODO: Change to org admins
            }

            OutboundComm comm = OutboundComm.Create(null, null, organization, CommResolverClass.Unknown, null,
                                                    CommTransmitterClass.CommsTransmitterMail,
                                                    new PayloadEnvelope(new NotificationPayload(notificationResourceString)).ToXml(),
                                                    OutboundCommPriority.Low);

            foreach (Person person in recipients)
            {
                comm.AddRecipient(person);
            }

            comm.Resolved = true;

            return comm;
        }
コード例 #28
0
    public static void InitDatabase()
    {
        // Make sure we're uninitialized

        bool organizationOneExists = false;

        Swarmops.Logic.Structure.Organization organizationOne = null;

        try
        {
            organizationOne       = Swarmops.Logic.Structure.Organization.FromIdentity(1);
            organizationOneExists = true;
        }
        catch (Exception)
        {
            // We expect this to throw
        }

        if (organizationOneExists || organizationOne != null)
        {
            throw new InvalidOperationException("Cannot re-initialize database");
        }

        // Store database credentials

        SwarmDb.Configuration.Set(
            new SwarmDb.Configuration(
                _testReadCredentials,
                _testWriteCredentials,
                _testAdminCredentials));

        // Start an async thread that does all the work, then return

        Thread initThread = new Thread(InitDatabaseThread);

        initThread.Start();
    }
コード例 #29
0
ファイル: RoleLookup.cs プロジェクト: SwarmCorp/Swarmops
 public static RoleLookup FromOrganization (Organization organization)
 {
     return FromOrganization(organization.Identity);
 }
コード例 #30
0
ファイル: RoleLookup.cs プロジェクト: SwarmCorp/Swarmops
 public static RoleLookup FromGeographyAndOrganization (Geography geography, Organization organization)
 {
     return FromGeographyAndOrganization(geography.Identity, organization.Identity);
 }
コード例 #31
0
ファイル: Election.cs プロジェクト: SwarmCorp/Swarmops
 public void SetCandidateDocumented (Organization organization, Person candidate)
 {
     SwarmDb.GetDatabaseForWriting().SetCandidateDocumentationReceived(this.Identity, organization.Identity, candidate.Identity);
 }
コード例 #32
0
 public OrganizationParameters(Organization organization)
 {
     this.organization = organization;
     this.data         = ObjectOptionalData.ForObject(organization);
 }