Esempio n. 1
0
    public override NextCall Invoke(WorkflowMethod invoker)
    {
        _action = GetSecureInput<AddressAction>();

        var q = Session.CreateQuery();

        var alias = new AqlAliasContentBase();
        alias.IgnoreSessionCulture = true;
        var rNodeId = q.Select(alias.NodeId);
        var rLCID = q.Select(alias.LCID);
        q.Select(alias);
        q.Where(alias.IsDerived == false);
        q.Where(alias.TemplateId > 0);
        q.From(alias);
        AqlResultSet rs = q.Execute();

        int nn = 0;
        switch (_action) {
            case AddressAction.RegeneratingAutomaticAddresses: WFContext.Caption = "Regenerating automatic addresses..."; break;
            case AddressAction.SettingAddressesToAutomatic: WFContext.Caption = "Setting addresses to automatic..."; break;
            case AddressAction.EnsuringAddressesAreValid: WFContext.Caption = "Ensuring addresses are valid..."; break;
            default: break;
        }
        WFContext.InBackgroundMode = false;
        WFContext.EstimateProgress = true;
        while (rs.Read()) {
            nn++;
            var key = new CKeyNLR(rNodeId.Value, rLCID.Value, 0);
            WFContext.Description = "Updating " + nn + " of " + rs.RowCount + "...";
            WFContext.SetProgress(nn, rs.RowCount);
            var c = Session.GetContent(key);
            if (WFContext.BreakExecution) return null;
            try {
                switch (_action) {
                    case AddressAction.RegeneratingAutomaticAddresses:
                        if (c.Address.Length == 0) c.Address = "#";
                        if (c.Address.StartsWith("#")) c.UpdateChanges();
                        break;
                    case AddressAction.SettingAddressesToAutomatic:
                        Engine.SetNodeAddressesToAutomatic(new List<CKeyNLRC>(new CKeyNLRC[] { c.Key }));
                        break;
                    case AddressAction.EnsuringAddressesAreValid:
                        c.EnsureAddressUniqueness();
                        c.UpdateChanges(false, false, false);
                        break;
                    default:
                        break;
                }
            } catch (Exception errr) {
                WAFRuntime.Log(errr);
            }
        }
        Session.Engine.ClearCache();
        WFContext.Notify(Utils.GetFriendlyName(_action.ToString()) + " completed successfully");
        return null;
    }
Esempio n. 2
0
 public override NextCall Invoke(WorkflowMethod invoker)
 {
     _action = GetSecureInput<AddressAction>();
     List<int> nodeIds = new List<int>();
     List<int> lcids = new List<int>();
     {
         var q = Session.CreateQuery();
         var sql = new SqlQuery(Session.Engine.Dao);
         sql.From(Sql.Table.Content);
         var rNodeId = sql.Select(Sql.Field.Content.NodeId);
         var rLcid = sql.Select(Sql.Field.Content.LCID);
         sql.Where(Sql.Field.Content.Revision == 0);
         sql.Where(Sql.Field.Content.IsDerived == false);
         using (var rs = sql.ExecuteReader()) {
             while (rs.Read()) {
                 if (rNodeId.Value > 0) {
                     nodeIds.Add(rNodeId.Value);
                     lcids.Add(rLcid.Value);
                 }
             }
         }
     }
     switch (_action) {
         case AddressAction.RegeneratingAutomaticAddresses: WFContext.Caption = "Regenerating automatic addresses..."; break;
         case AddressAction.SettingAddressesToAutomatic: WFContext.Caption = "Setting addresses to automatic..."; break;
         case AddressAction.EnsuringAddressesAreValid: WFContext.Caption = "Ensuring addresses are valid..."; break;
         default: break;
     }
     WFContext.InBackgroundMode = false;
     WFContext.EstimateProgress = true;
     int pos = 0;
     int batchSize = 500;
     int count = 0;
     int changed = 0;
     while (pos < nodeIds.Count) {
         if (batchSize + pos > nodeIds.Count) batchSize = nodeIds.Count - pos;
         var keys = new List<CKeyNLR>();
         for (int i = pos; i < pos + batchSize; i++) keys.Add(new CKeyNLR(nodeIds[i], lcids[i], 0));
         try {
             fixAddress(keys, ref count, ref changed, nodeIds.Count);
         } catch {
             foreach (var k in keys) {
                 try { // do one by one...
                     fixAddress(new List<CKeyNLR>(new CKeyNLR[] { k }), ref count, ref changed, nodeIds.Count);
                 } catch { }
                 if (WFContext.BreakExecution) return null;
             }
         }
         foreach (var k in keys) { // to prevent cache from loading all contents
             Session.Engine.RemoveNodeFromCache(k.NodeId);
         }
         pos += batchSize;
         if (WFContext.BreakExecution) return null;
     }
     Session.Engine.ClearCache();
     WFContext.Notify(changed + (changed == 1 ? " content was changed. " : " contents were changed. "), Utils.GetFriendlyName(_action.ToString()) + " completed successfully");
     return null;
 }