コード例 #1
0
 public TemplateVariablesHelper(List <TemplateVariable> templateVariables) : this()
 {
     templateVariables.ForEach(x =>
     {
         TemplateVariables.Add(x.Name, x.Value);
     });
 }
コード例 #2
0
ファイル: Template.cs プロジェクト: Mirilis/Process-Data
 public void AddTemplateVariable(TemplateVariable tv)
 {
     if (TemplateVariables.Any(x => x == tv))
     {
         throw new ArgumentException("Duplicate Value.");
     }
     ((List <TemplateVariable>)TemplateVariables).Add(tv);
 }
コード例 #3
0
ファイル: TemplateContext.cs プロジェクト: Creepsky/Nexus
        public SimpleType TemplateTypeToConcrete(string templateTypeName)
        {
            if (TemplateVariables.ContainsKey(templateTypeName))
            {
                return(TemplateVariables[templateTypeName]);
            }

            return(null);
        }
コード例 #4
0
        private void SendOperatorEmails()
        {
            AspSettings   settings = AspSettings.Load();
            IConfigurator config   = Configurator.Create();

            // Trial - One day before end
            foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneDayBeforeEnd, settings.OneDayBeforePeriod, true))
            {
                try
                {
                    if (!CManage.NotificationGet(cid, EmailType.TrialOneDayBefore))
                    {
                        if (string.IsNullOrEmpty(settings.OperatorEmail))
                        {
                            CManage.NotificationUpdate(cid, EmailType.TrialOneDayBefore, true);

                            TemplateVariables vars = CManage.CompanyGetVariables(cid);
                            CManage.SendEmail(settings.OperatorEmail, EmailType.TrialOneDayBefore, vars);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteError(ex.ToString());
                }
            }

            if (settings.UseTariffs)
            {
                // Billable - One day before end
                foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNdaysBefore, 1, false))
                {
                    // ensure that we send emails only once for a day
                    DateTime lastSpamDate = CManage.GetNotificationOperatorSpamDate(cid);
                    if (lastSpamDate > DateTime.Now.AddDays(-1))
                    {
                        continue;
                    }

                    try
                    {
                        if (string.IsNullOrEmpty(settings.OperatorEmail))
                        {
                            TemplateVariables vars = CManage.CompanyGetVariables(cid);
                            CManage.SendEmail(settings.OperatorEmail, EmailType.OperatorCompanyDeactivatedDayBefore, vars);
                            CManage.UpdateNotificationOperatorSpamDate(cid, DateTime.Now);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError(ex.ToString());
                    }
                }
            }
        }
コード例 #5
0
ファイル: TemplateContext.cs プロジェクト: Creepsky/Nexus
        /// <summary>
        /// Creates a template context instance.
        /// This will initialize the context properly and also create a concrete implementation of the template function.
        /// However, after creation, <see cref="Generate"/> has to be called to fill the freshly created function with life.
        /// </summary>
        /// <param name="templateContext">The context of the template element.</param>
        /// <param name="callerContext">The context of the caller of the template function.</param>
        /// <param name="template">The called template element.</param>
        public TemplateContext(Context templateContext, Context callerContext, IGenerationElementGenerator template)
            : base(templateContext.UpperContext, template.Generate(), new Dictionary <string, IGenerationElement>())
        {
            CallerContext = callerContext;
            _generator    = template;

            foreach (var i in template.TemplateList.Types)
            {
                TemplateVariables.Add(i.Name, null);
            }
        }
コード例 #6
0
        private void DeactivateExpiredCompanies()
        {
            AspSettings settings = AspSettings.Load();

            if (settings.AutoDeactivateExpired)
            {
                foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.Expired, 0, false))
                {
                    try
                    {
                        CManage.DeactivateCompany(cid);

                        // Send e-mail to operator
                        if (!string.IsNullOrEmpty(settings.OperatorEmail))
                        {
                            TemplateVariables vars = CManage.CompanyGetVariables(cid);
                            CManage.SendEmail(settings.OperatorEmail, EmailType.TrialDeactivated, vars);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError(ex.ToString());
                    }
                }
            }

            if (settings.AutoDeactivateUnpaid && settings.UseTariffs)
            {
                foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableForDeactivate, 0, false))
                {
                    try
                    {
                        CManage.DeactivateCompany(cid);

                        // Send e-mail to operator
                        if (!string.IsNullOrEmpty(settings.OperatorEmail))
                        {
                            TemplateVariables vars = CManage.CompanyGetVariables(cid);
                            CManage.SendEmail(settings.OperatorEmail, EmailType.OperatorCompanyDeactivated, vars);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError(ex.ToString());
                    }
                }
            }
        }
コード例 #7
0
        private void ParseTemplateVariables(string templateText)
        {
            TemplateVariables.Clear();

            var matches = Regex.Matches(templateText, TemplateFileVarRegexPattern);

            foreach (Match match in matches)
            {
                string name = match.Value.Substring(1, match.Value.Length - 2);
                if (!TemplateVariables.Select(v => v.Name).Contains(name) && !ReservedTemplateVariables.Contains(name.ToUpper()))
                {
                    TemplateVariables.Add(new TemplateFileVariable {
                        Name = name
                    });
                }
            }
        }
コード例 #8
0
        private void SendUserEmails()
        {
            AspSettings   settings = AspSettings.Load();
            IConfigurator config   = Configurator.Create();

            #region trial spam
            if (settings.SendSpam)
            {
                // One day after start
                if (settings.SendSpamOneDayAfter)
                {
                    foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneDayNoIM, settings.OneDayAfterPeriod, true))
                    {
                        try
                        {
                            string dbName = config.GetCompanyInfo(cid.ToString()).Database;
                            if (!CManage.NotificationGet(cid, EmailType.UserAfterOneDayIM))
                            {
                                CManage.NotificationUpdate(cid, EmailType.UserAfterOneDayIM, true);

                                if (!CManage.CheckImSessions(dbName))
                                {
                                    // Send e-mails to every active user
                                    TemplateVariables vars = CManage.CompanyGetVariables(cid);
                                    foreach (UserInfo ui in CManage.GetPortalUsers(dbName))
                                    {
                                        vars["Login"] = ui.Login;
                                        vars["Name"]  = ui.Name;
                                        try
                                        {
                                            CManage.SendEmail(ui.Email, EmailType.UserAfterOneDayIM, vars);
                                        }
                                        catch { }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError(ex.ToString());
                        }
                    }
                }

                // One week after start
                if (settings.SendSpamOneWeekAfter)
                {
                    foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneWeekAfterStart, settings.OneWeekAfterPeriod, true))
                    {
                        try
                        {
                            if (!CManage.NotificationGet(cid, EmailType.UserAfterOneWeek))
                            {
                                CManage.NotificationUpdate(cid, EmailType.UserAfterOneWeek, true);

                                // Send e-mail
                                TemplateVariables vars = CManage.CompanyGetVariables(cid);
                                if (!string.IsNullOrEmpty(vars["ContactEmail"]))
                                {
                                    CManage.SendEmail(vars["ContactEmail"], EmailType.UserAfterOneWeek, vars);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError(ex.ToString());
                        }
                    }
                }

                // One week before end
                if (settings.SendSpamOneWeekBefore)
                {
                    foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneWeekBeforeEnd, settings.OneWeekBeforePeriod, true))
                    {
                        try
                        {
                            if (!CManage.NotificationGet(cid, EmailType.UserOneWeekBefore))
                            {
                                CManage.NotificationUpdate(cid, EmailType.UserOneWeekBefore, true);

                                // Send e-mail
                                TemplateVariables vars = CManage.CompanyGetVariables(cid);
                                if (!string.IsNullOrEmpty(vars["ContactEmail"]))
                                {
                                    CManage.SendEmail(vars["ContactEmail"], EmailType.UserOneWeekBefore, vars);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError(ex.ToString());
                        }
                    }
                }

                // One day before end
                if (settings.SendSpamOneDayBefore)
                {
                    foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneDayBeforeEnd, settings.OneDayBeforePeriod, true))
                    {
                        try
                        {
                            if (!CManage.NotificationGet(cid, EmailType.UserOneDayBefore))
                            {
                                CManage.NotificationUpdate(cid, EmailType.UserOneDayBefore, true);

                                // Send e-mail
                                TemplateVariables vars = CManage.CompanyGetVariables(cid);
                                if (!string.IsNullOrEmpty(vars["ContactEmail"]))
                                {
                                    CManage.SendEmail(vars["ContactEmail"], EmailType.UserOneDayBefore, vars);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError(ex.ToString());
                        }
                    }
                }
            }
            #endregion

            #region billable spam
            if (settings.SendBillableSpam && settings.UseTariffs)
            {
                // 7 days before
                if (settings.SendBillableSpam7day)
                {
                    foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNdaysBefore, 7, true))
                    {
                        // ensure that we send emails only once for a day
                        DateTime lastSpamDate = CManage.GetNotificationClientSpamDate(cid);
                        if (lastSpamDate > DateTime.Now.AddDays(-1))
                        {
                            continue;
                        }

                        // Send e-mail
                        try
                        {
                            TemplateVariables vars = CManage.CompanyGetVariables(cid);
                            if (!string.IsNullOrEmpty(vars["ContactEmail"]))
                            {
                                CManage.SendEmail(vars["ContactEmail"], EmailType.Client7DayZeroBalance, vars);
                                CManage.UpdateNotificationClientSpamDate(cid, DateTime.Now);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError(ex.ToString());
                        }
                    }
                }

                // 3 days before
                if (settings.SendBillableSpam3day)
                {
                    foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNdaysBefore, 3, true))
                    {
                        // ensure that we send emails only once for a day
                        DateTime lastSpamDate = CManage.GetNotificationClientSpamDate(cid);
                        if (lastSpamDate > DateTime.Now.AddDays(-1))
                        {
                            continue;
                        }

                        // Send e-mail
                        try
                        {
                            TemplateVariables vars = CManage.CompanyGetVariables(cid);
                            if (!string.IsNullOrEmpty(vars["ContactEmail"]))
                            {
                                CManage.SendEmail(vars["ContactEmail"], EmailType.Client3DayZeroBalance, vars);
                                CManage.UpdateNotificationClientSpamDate(cid, DateTime.Now);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError(ex.ToString());
                        }
                    }
                }

                // 1 day before
                if (settings.SendBillableSpam1day)
                {
                    foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNdaysBefore, 1, true))
                    {
                        // ensure that we send emails only once for a day
                        DateTime lastSpamDate = CManage.GetNotificationClientSpamDate(cid);
                        if (lastSpamDate > DateTime.Now.AddDays(-1))
                        {
                            continue;
                        }

                        // Send e-mail
                        try
                        {
                            TemplateVariables vars = CManage.CompanyGetVariables(cid);
                            if (!string.IsNullOrEmpty(vars["ContactEmail"]))
                            {
                                CManage.SendEmail(vars["ContactEmail"], EmailType.Client1DayZeroBalance, vars);
                                CManage.UpdateNotificationClientSpamDate(cid, DateTime.Now);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError(ex.ToString());
                        }
                    }
                }

                // Negative balance
                if (settings.SendBillableSpamNegativeBalance)
                {
                    foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNegativeBalance, 0, true))
                    {
                        // ensure that we send emails only once for a day
                        DateTime lastSpamDate = CManage.GetNotificationClientSpamDate(cid);
                        if (lastSpamDate > DateTime.Now.AddDays(-1))
                        {
                            continue;
                        }

                        // Send e-mail
                        try
                        {
                            TemplateVariables vars = CManage.CompanyGetVariables(cid);
                            if (!string.IsNullOrEmpty(vars["ContactEmail"]))
                            {
                                CManage.SendEmail(vars["ContactEmail"], EmailType.ClientZeroBalance, vars);
                                CManage.UpdateNotificationClientSpamDate(cid, DateTime.Now);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError(ex.ToString());
                        }
                    }
                }
            }
            #endregion
        }
コード例 #9
0
ファイル: Trial.asmx.cs プロジェクト: alex765022/IBN
        private TrialResult RequestTrial(
            string companyName
            , string sizeOfGroup
            , string description
            , string domain
            , string firstName
            , string lastName
            , string email
            , string phone
            , string country
            , string login
            , string password
            , string resellerGuid
            , string xml
            , string locale
            , string referrer
            , out int requestId
            , out string requestGuid
            )
        {
            TrialResult retVal = TrialResult.Failed;

            requestId   = -1;
            requestGuid = string.Empty;

            AspSettings settings = AspSettings.Load();

            domain += "." + settings.DnsParentDomain;
            try
            {
                //if (CManage.IsUserRegistered(settings, email))
                //    retVal = TrialResult.UserRegistered;
                //else
                if (CManage.CompanyExists(domain))
                {
                    retVal = TrialResult.DomainExists;
                }
                else
                {
                    requestId = DBTrialRequest.Create(
                        companyName,
                        sizeOfGroup,
                        description,
                        domain,
                        firstName,
                        lastName,
                        email,
                        phone,
                        country,
                        login,
                        password,
                        new Guid(resellerGuid),
                        xml,
                        locale
                        , referrer
                        );

                    TemplateVariables vars = DBTrialRequest.GetVariables(requestId);
                    requestGuid = vars["RequestGUID"];
                    retVal      = TrialResult.WaitingForActivation;

//					if (!string.IsNullOrEmpty(settings.OperatorEmail))
//						CManage.SendEmail(settings.OperatorEmail, EmailType.TrialNewRequest, vars);
                }
            }
            finally
            {
                if (retVal != TrialResult.Success && retVal != TrialResult.WaitingForActivation && retVal != TrialResult.RequestPending)
                {
                    object obj = null;
                    try
                    {
                        obj = new Guid(resellerGuid);
                    }
                    catch (ArgumentNullException)
                    {
                    }
                    catch (FormatException)
                    {
                    }

                    DBTrialRequestFailed.Create(
                        companyName,
                        sizeOfGroup,
                        description,
                        domain,
                        firstName,
                        lastName,
                        email,
                        phone,
                        login,
                        login,
                        password,
                        obj
                        , locale
                        , referrer
                        , (int)retVal
                        );
                }
            }
            return(retVal);
        }
コード例 #10
0
ファイル: Trial.asmx.cs プロジェクト: alex765022/IBN
        public TrialResult ActivateTrialCompany2(
            int requestId
            , string requestGuid
            , out string portalUrl
            , out string login
            , out string password
            , out string companyId
            )
        {
            portalUrl = "";
            login     = "";
            password  = "";
            companyId = "";

            TrialResult ret  = TrialResult.InvalidRequest;
            Guid        guid = new Guid(requestGuid);

            if (DBTrialRequest.CheckGuid(requestId, guid))
            {
                bool isActive = false;
                using (IDataReader reader = DBTrialRequest.Get(requestId, true, false))
                {
                    if (reader.Read())
                    {
                        isActive = (bool)reader["IsActive"];
                        if (reader["Company_uid"] != DBNull.Value)
                        {
                            companyId = (string)reader["Company_uid"];
                        }
                    }
                }

                if (isActive)
                {
                    ret = TrialResult.AlreadyActivated;
                }
                else
                {
                    Guid companyUid = CManage.ASPCreateTrialCompany(requestId);
                    ret       = TrialResult.Success;
                    companyId = companyUid.ToString();

                    AspSettings       settings = AspSettings.Load();
                    TemplateVariables vars     = CManage.CompanyGetVariables(companyUid);
                    TemplateVariables varsR    = DBTrialRequest.GetVariables(requestId);
                    vars["Login"]          = varsR["Login"];
                    vars["Password"]       = varsR["Password"];
                    vars["TrialUsers"]     = settings.MaxUsers.ToString();
                    vars["TrialDiskSpace"] = settings.MaxHDD.ToString();
                    vars["TrialPeriod"]    = settings.TrialPeriod.ToString();

                    portalUrl = vars["PortalLink"];

                    if (!string.IsNullOrEmpty(vars["ContactEmail"]))
                    {
                        CManage.SendEmail(vars["ContactEmail"], EmailType.UserActivated, vars);
                    }
                    if (!string.IsNullOrEmpty(settings.OperatorEmail))
                    {
                        CManage.SendEmail(settings.OperatorEmail, EmailType.TrialActivated, vars);
                    }

                    login    = varsR["Login"];
                    password = varsR["Password"];
                }
            }
            return(ret);
        }
コード例 #11
0
ファイル: TemplateContext.cs プロジェクト: Creepsky/Nexus
 public SimpleType LookupTemplateType(SimpleType templateType) =>
 TemplateVariables.ContainsKey(templateType.Name)
         ? TemplateVariables[templateType.Name]
         : templateType;
コード例 #12
0
        public static string FilenameFromEpisode(Episode ep, Quality q, string template)
        {
            List <object>   vars = new List <object>();
            MatchCollection m    = _varRegex.Matches(template);
            int             cnt  = 0;

            foreach (Match match in m)
            {
                if (match.Success)
                {
                    string t   = match.Groups["variable"].Value.ToLower();
                    int    idx = t.IndexOf(":", StringComparison.InvariantCulture);
                    if (idx > 0)
                    {
                        t = t.Substring(0, idx);
                    }
                    if (Variables.Contains(t))
                    {
                        TemplateVariables tv = (TemplateVariables)Enum.Parse(typeof(TemplateVariables), t);
                        switch (tv)
                        {
                        case TemplateVariables.show:
                            vars.Add(ep.ShowName);
                            break;

                        case TemplateVariables.episodealpha:
                            vars.Add(ep.EpisodeAlpha ?? string.Empty);
                            break;

                        case TemplateVariables.episodenumeric:
                            vars.Add(ep.EpisodeNumeric);
                            break;

                        case TemplateVariables.seasonalpha:
                            vars.Add(ep.SeasonAlpha ?? string.Empty);
                            break;

                        case TemplateVariables.seasonalphaorshow:
                            if (string.IsNullOrEmpty(ep.SeasonAlpha))
                            {
                                vars.Add(ep.ShowName ?? string.Empty);
                            }
                            else
                            {
                                vars.Add(ep.SeasonAlpha);
                            }
                            break;

                        case TemplateVariables.seasonnumeric:
                            vars.Add(ep.SeasonNumeric);
                            break;

                        case TemplateVariables.index:
                            vars.Add(ep.Index);
                            break;

                        case TemplateVariables.plugin:
                            vars.Add(ep.PluginName);
                            break;

                        case TemplateVariables.resolution:
                            vars.Add(q.ToText());
                            break;
                        }
                        template = template.Replace("{" + t, "{" + cnt);
                        cnt++;
                    }
                }
            }
            string fname = string.Format(template, vars.ToArray());

            foreach (char c in System.IO.Path.GetInvalidFileNameChars())
            {
                fname = fname.Replace(c.ToString(), string.Empty);
            }
            return(fname);
        }