Example #1
0
 void btnTaskViewLog_Click(object sender, EventArgs e)
 {
     foreach (string v in lstTasks.GetSelectedValues()) {
         ScheduledTask t = WAFContext.Session.GetContent<ScheduledTask>(int.Parse(v));
         StringBuilder html = new StringBuilder();
         html.Append("<h2>Log:</h2><div style=\"height:40%; width:95%; overflow: auto; border:solid 1px #999999;\">");
         html.Append(HttpUtility.HtmlEncode(t.ShortLog).Replace(Environment.NewLine, "<br>"));
         html.Append("</div>");
         html.Append("<h2>Trace:</h2><div style=\"height:40%; width:95%; overflow: auto; border: solid 1px #999999;\">");
         html.Append(HttpUtility.HtmlEncode(t.Trace).Replace(Environment.NewLine, "<br>"));
         html.Append("</div>");
         WMHtmlDialogue d = new WMHtmlDialogue(DialogueIcon.Info, UIButtons.Ok, null, t.Name, 700, 400, html.ToString());
         WAFContext.Session.StartWorkflowMethod(d);
     }
 }
Example #2
0
    public override NextCall Invoke(WorkflowMethod invoker)
    {
        WFContext.Caption = "Examining unreferenced files";
        string path = WAFContext.PathFromRootToFolderContentFiles;
        Dictionary<int, UniqueList<int>> idsFileSys = new Dictionary<int, UniqueList<int>>();
        int n = 0;
        foreach (var contentIdFolder in WAFRuntime.FileSystem.GetDirectories(path)) {
            int contentId;
            if (int.TryParse(WAFRuntime.FileSystem.GetDirectoryInfo(contentIdFolder).Name, out contentId)) {
                foreach (var propIdFolder in WAFRuntime.FileSystem.GetDirectories(contentIdFolder)) {
                    int propId;
                    if (int.TryParse(WAFRuntime.FileSystem.GetDirectoryInfo(propIdFolder).Name, out propId)) {
                        if (!idsFileSys.ContainsKey(contentId)) idsFileSys.Add(contentId, new UniqueList<int>());
                        idsFileSys[contentId].Add(propId);
                        n++;
                    }
                }
            }
            if (WFContext.BreakExecution) return null;
            WFContext.Description = "Identifying files on disk: " + n;
        }
        WFContext.Description = "Identifying referenced files...";
        Dictionary<int, UniqueList<int>> idsDB = Engine.Dao.GetFilesPropIdsByContentIdInUse();

        Dictionary<int, UniqueList<int>> onDiskNotInDb = new Dictionary<int, UniqueList<int>>();
        foreach (var idCinF in idsFileSys.Keys) { // for content id folder in file sys
            if (!idsDB.ContainsKey(idCinF)) { // if db does not contain folder at all, add all props in folder
                if (!onDiskNotInDb.ContainsKey(idCinF)) onDiskNotInDb.Add(idCinF, new UniqueList<int>());
                foreach (var p in idsFileSys[idCinF]) onDiskNotInDb[idCinF].AddIfNew(p);
            } else { // if sb does contain folder, just add props missing in db
                var idPinF = idsFileSys[idCinF];
                if (!onDiskNotInDb.ContainsKey(idCinF)) onDiskNotInDb.Add(idCinF, new UniqueList<int>());
                foreach (var p in idsFileSys[idCinF]) { // for each prop in content folder in file sys
                    if (!idsDB[idCinF].Contains(p)) { // if db content id does not contain prop add it
                        if (!onDiskNotInDb.ContainsKey(idCinF)) onDiskNotInDb.Add(idCinF, new UniqueList<int>());
                        onDiskNotInDb[idCinF].AddIfNew(p);
                    }
                }
            }
        }

        _paths = new List<string>();
        foreach (var cid in onDiskNotInDb.Keys) {
            var contentFolderPath = WAFContext.PathFromRootToFolderContentFiles + cid;
            if (WAFRuntime.FileSystem.DirectoryExists(contentFolderPath)) {
                foreach (var pid in onDiskNotInDb[cid]) {
                    var contentPropFolder = Path.Combine(contentFolderPath, pid.ToString());
                    if (WAFRuntime.FileSystem.DirectoryExists(contentPropFolder)) {
                        foreach (var ef in WAFRuntime.FileSystem.GetDirectories(contentPropFolder)) { // each encrypt folder
                            foreach (var f in WAFRuntime.FileSystem.GetFiles(ef)) {
                                _paths.Add(f);
                            }
                        }
                        foreach (var f in WAFRuntime.FileSystem.GetFiles(contentPropFolder)) { // non encrypt folder // only old systems
                            _paths.Add(f);
                        }
                    }
                }
            }
        }

        if (_paths.Count == 0) {
            Session.Notify("There are no unreferenced files. ");
            return null;
        }

        StringBuilder html = new StringBuilder();
        foreach (string f in _paths) {
            html.Append(Path.GetFileName(f));
            html.Append("<br/>");
        }
        WMHtmlDialogue diag = new WMHtmlDialogue(DialogueIcon.Question, UIButtons.OkCancel, null, "Delete these " + _paths.Count + " unreferenced files?", 600, 500, html.ToString());

        return new NextCall(diag, onAnswer);
    }
Example #3
0
 NextCall onComplete(WorkflowMethod invoker)
 {
     WFContext.InBackgroundMode = false;
     WFContext.Caption = "Importing nodes";
     WMUploadFiles w = (WMUploadFiles)invoker;
     _path = Engine.FileTempPath + Guid.NewGuid();
     WAFRuntime.FileSystem.DirectoryCreate(_path);
     ArchiveExpander ex = new ArchiveExpander();
     WFContext.Description = "Expanding...";
     ex.Expand(w.GetUploadedFiles().First(), _path);
     var files = WAFRuntime.FileSystem.GetFiles(_path).Where(f => !f.EndsWith(".dat")).ToArray();
     var idFilepath = Path.Combine(_path, "GuidsAndClassNames.dat");
     string relFilepath = Path.Combine(_path, "Listorders.dat");
     Guid[] savedGuids;
     string[] savedClassNames;
     using (var f = WAFRuntime.FileSystem.FileOpenRead(idFilepath)) {
         var o = Utils.DeSerialize<object[]>(f);
         savedGuids = (Guid[])o[0];
         savedClassNames = (string[])o[1];
     }
     Dictionary<Guid, string> failed = new Dictionary<Guid, string>();
     for (int i = 0; i < savedGuids.Length; i++) {
         if (WFContext.BreakExecution) return null;
         WFContext.Description = "Initializing node " + i + " of " + savedGuids.Length;
         WFContext.SetProgress(i, files.Length);
         var guid = savedGuids[i];
         try {
             Session.EnsureNode(guid, savedClassNames[i]);
         } catch (Exception error) {
             if (!failed.ContainsKey(guid)) failed.Add(guid, error.Message);
         }
     }
     int n = 0;
     WFContext.EstimateProgress = true;
     List<int> nodeIds = new List<int>();
     foreach (var f in files) {
         n++;
         if (WFContext.BreakExecution) return null;
         WFContext.Description = "Installing content " + n + " of " + files.Length;
         WFContext.SetProgress(n, files.Length);
         using (var stream = WAFRuntime.FileSystem.FileOpenRead(f)) {
             int nodeId = 0;
             Guid guid = Guid.Empty;
             try {
                 Session.ReadGenericContentNode(stream, true, true, out nodeId, out guid);
                 nodeIds.Add(nodeId);
             } catch (Exception error) {
                 if (guid == Guid.Empty) throw new Exception("Corrupt data. Unable to continue. Operation aborted. ");
                 if (!failed.ContainsKey(guid)) failed.Add(guid, error.Message);
             }
         }
     }
     WFContext.SetProgress(-1);
     WFContext.Description = "Updating HTML references...";
     n = 0;
     foreach (var id in nodeIds) {
         foreach (var c in Session.GetContentAllLiveVersions(id)) {
             if (!c.IsDerived) {
                 try {
                     Session.ConvertAllReferencesToNative(c);
                 } catch (Exception error) {
                     if (!failed.ContainsKey(c.Guid)) failed.Add(c.Guid, error.Message);
                 }
                 if (c.Changed) c.UpdateChanges(false, false, true);
             }
         }
         n++;
         WFContext.Description = "Updaing references " + n + " of " + nodeIds.Count;
         WFContext.SetProgress(n, files.Length);
     }
     WFContext.SetProgress(-1);
     WFContext.Description = "Updating relation listorder...";
     using (var f = WAFRuntime.FileSystem.FileOpenRead(relFilepath)) {
         var o = Utils.DeSerialize<List<RelationListOrderData>>(f);
         Session.ApplyRelationListorderData(o, savedGuids);
     }
     StringBuilder html = new StringBuilder();
     string title;
     if (failed.Count == 0) {
         if (nodeIds.Count != 1) {
             html.Append("All " + nodeIds.Count + " nodes imported successfully. ");
         } else {
             html.Append("1 node imported successfully. ");
         }
         title = "Completed";
     } else {
         title = "Complete, but with errors:";
         html.Append((files.Length - failed.Count) + " nodes imported successfully. <br/><br/>");
         html.Append(failed.Count + " failed to import: <br/><br/>");
         html.Append("<table>");
         html.Append("<tr><td><b>Guid</b></td><td><b>Error</b></td></tr>");
         html.Append("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>");
         int nn = 0;
         foreach (var kv in failed) {
             nn++;
             html.Append("<tr><td style=\"font-size:10px;\">" + kv.Key + "</td><td>" + kv.Value + "</td></tr>");
             if (nn > 1000) break;
         }
         html.Append("</table>");
     }
     WMHtmlDialogue d = new WMHtmlDialogue(DialogueIcon.Info, UIButtons.Ok, null, title, 400, 200, html.ToString());
     return new NextCall(d);
 }
Example #4
0
    NextCall start()
    {
        _path = Engine.FileTempPath + Guid.NewGuid();
        WAFRuntime.FileSystem.DirectoryCreate(_path);
        WFContext.InBackgroundMode = false;
        WFContext.Caption = "Exporting nodes";
        List<Guid> savedGuids = new List<Guid>();
        List<int> savedClassNames = new List<int>();
        WFContext.EstimateProgress = true;
        var nodeIds = toNodeIDs(_nodeIds).Select(v => int.Parse(v)).ToList();
        Dictionary<int, string> failed = new Dictionary<int, string>();
        int n = 0;
        int batchCount = 0;
        foreach (var nodeId in nodeIds) {
            if (batchCount <= 0) { // priming cache
                try {
                    batchCount = 500;
                    Session.GetContents<ContentBase>(nodeIds.GetRange(n, batchCount));
                } catch { }
            }
            batchCount--;
            n++;
            if (WFContext.BreakExecution) return null;
            WFContext.Description = "Exporting " + n + " of " + nodeIds.Count();
            WFContext.SetProgress(n, nodeIds.Count());
            try {
                ContentBase content = Session.GetContent(nodeId);
                if (content.Guid == Guid.Empty) {
                    content = content.GetOriginal();
                    content.Guid = Guid.NewGuid();
                    content.UpdateChanges();
                }

                Guid g = Session.GetGuid(nodeId);
                using (var stream = WAFRuntime.FileSystem.FileOpenWrite(Path.Combine(_path, g.ToString()))) {
                    Session.WriteGenericContentNode(nodeId, stream);
                }
                savedGuids.Add(content.Guid);
                savedClassNames.Add(content.ClassId);
            } catch (Exception error) {
                failed.Add(nodeId, error.Message);
            }
        }
        string idFilepath = Path.Combine(_path, "GuidsAndClassNames.dat");
        using (var stream = WAFRuntime.FileSystem.FileOpenWrite(idFilepath)) {
            Utils.Serialize(new object[] { savedGuids.ToArray(), (savedClassNames.Select(s => Engine.Definition.ContentClass[s].TypeNameShort)).ToArray() }, stream);
        }
        string relFilepath = Path.Combine(_path, "Listorders.dat");
        using (var stream = WAFRuntime.FileSystem.FileOpenWrite(relFilepath)) {
            var data = Session.CollectRelationListorderData(nodeIds);
            Utils.Serialize(data, stream);
        }
        ArchiveSearcher a = new ArchiveSearcher();
        a.AddFolder(_path, null, null, false, null, null);
        a.Search();
        ArchiveCompressor c = new ArchiveCompressor(a.SourcePaths, a.ArchivePaths);
        WFContext.Description = "Compressing...";
        string afile = _path + ".kitfile";
        c.Compress(afile);
        foreach (var f in WAFRuntime.FileSystem.GetFiles(_path)) WAFRuntime.FileSystem.FileDelete(f);
        WFContext.Description = "Done.";
        StringBuilder html = new StringBuilder();
        if (failed.Count == 0) {
            html.Append("All " + _nodeIds.Count + " nodes exported successfully. ");
        } else {
            html.Append((_nodeIds.Count - failed.Count) + " nodes exported successfully. <br/><br/>");
            html.Append(failed.Count + " failed to export: <br/><br/>");
            html.Append("<table>");
            html.Append("<tr><td><b>ID</b></td><td><b>Error</b></td></tr>");
            html.Append("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>");
            int nn = 0;
            foreach (var kv in failed) {
                nn++;
                html.Append("<tr><td>" + kv.Key + "</td><td>" + kv.Value + "</td></tr>");
                if (nn > 1000) break;
            }
            html.Append("</table>");
        }
        WMHtmlDialogue d = new WMHtmlDialogue(DialogueIcon.Info, UIButtons.NextCancel, null, "Complete", 400, 200, html.ToString());
        return new NextCall(d, afterWrite);
    }