コード例 #1
0
        public override void LoadFile(Stream stream)
        {
            var p = AnnotationPlugIn.GenerateDataRecordPath();
            // t|1|OrderDetails,_Annotation_Attachment20091219164153Z|10248|11
            var m        = Regex.Match(this.Value, "_Annotation_Attachment(\\w+)\\|");
            var fileName = Path.Combine(p, (m.Groups[1].Value + ".xml"));
            var nav      = new XPathDocument(fileName).CreateNavigator().SelectSingleNode("/*");

            fileName = Path.Combine(p, ((Path.GetFileNameWithoutExtension(fileName) + "_")
                                        + Path.GetExtension(nav.GetAttribute("fileName", string.Empty))));
            if (!(this.Value.StartsWith("t|")))
            {
                this.ContentType = nav.GetAttribute("contentLength", string.Empty);
                HttpContext.Current.Response.ContentType = this.ContentType;
            }
            this.FileName = nav.GetAttribute("fileName", string.Empty);
            var input = File.OpenRead(fileName);

            try
            {
                var buffer    = new byte[(1024 * 64)];
                var offset    = 0;
                var bytesRead = input.Read(buffer, 0, buffer.Length);
                while (bytesRead > 0)
                {
                    stream.Write(buffer, 0, Convert.ToInt32(bytesRead));
                    offset    = (offset + bytesRead);
                    bytesRead = input.Read(buffer, 0, buffer.Length);
                }
            }
            finally
            {
                input.Close();
            }
        }
コード例 #2
0
        void IPlugIn.ProcessArguments(ActionArgs args, ActionResult result, ViewPage page)
        {
            if (_annotations.Count == 0)
            {
                return;
            }
            var p = AnnotationPlugIn.GenerateDataRecordPath(args.Controller, page, args.Values, 0);

            if (!(Directory.Exists(p)))
            {
                Directory.CreateDirectory(p);
            }
            foreach (var v in _annotations)
            {
                var m = Regex.Match(v.Name, "^_Annotation_(Note)(New|\\w+)$");
                if (m.Success)
                {
                    if (m.Groups[1].Value == "Note")
                    {
                        var fileName = m.Groups[2].Value;
                        if (fileName == "New")
                        {
                            fileName = DateTime.Now.ToString("u");
                            fileName = Regex.Replace(fileName, "[\\W]", string.Empty);
                        }
                        fileName = Path.Combine(p, (fileName + ".xml"));
                        if (!(string.IsNullOrEmpty(Convert.ToString(v.NewValue))))
                        {
                            var settings = new XmlWriterSettings();
                            settings.CloseOutput = true;
                            var writer = XmlWriter.Create(new FileStream(fileName, FileMode.Create), settings);
                            try
                            {
                                writer.WriteStartElement("note");
                                writer.WriteAttributeString("timestamp", DateTime.Now.ToString("o"));
                                writer.WriteAttributeString("username", HttpContext.Current.User.Identity.Name);
                                writer.WriteAttributeString("email", AnnotationPlugIn.UserEmail);
                                writer.WriteString(Convert.ToString(v.NewValue));
                                writer.WriteEndElement();
                            }
                            finally
                            {
                                writer.Close();
                            }
                        }
                        else
                        {
                            File.Delete(fileName);
                            if (Directory.GetFiles(p).Length == 0)
                            {
                                Directory.Delete(p);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        public override bool SaveFile(HttpContext context, BlobAdapter ba, string keyValue)
        {
            if (context.Request.Files.Count != 1)
            {
                return(false);
            }
            var file = context.Request.Files[0];
            var p    = AnnotationPlugIn.GenerateDataRecordPath();

            if (!(Directory.Exists(p)))
            {
                Directory.CreateDirectory(p);
            }
            // u|OrderDetails,_Annotation_AttachmentNew|10248|11
            var m = Regex.Match(this.Value, "_Annotation_Attachment(\\w+)\\|");

            if (m.Success)
            {
                var fileName = m.Groups[1].Value;
                if (fileName == "New")
                {
                    fileName = DateTime.Now.ToString("u");
                    fileName = Regex.Replace(fileName, "[\\W]", string.Empty);
                    if (System.IO.File.Exists(Path.Combine(p, (fileName + ".xml"))))
                    {
                        fileName = (fileName + "_");
                    }
                }
                fileName = Path.Combine(p, (fileName + ".xml"));
                if (file.ContentLength == 0)
                {
                    foreach (var f in Directory.GetFiles(p, (Path.GetFileNameWithoutExtension(fileName) + "*.*")))
                    {
                        System.IO.File.Delete(f);
                    }
                }
                else
                {
                    var settings = new XmlWriterSettings();
                    settings.CloseOutput = true;
                    var writer = XmlWriter.Create(new FileStream(fileName, FileMode.Create), settings);
                    try
                    {
                        writer.WriteStartElement("attachment");
                        writer.WriteAttributeString("timestamp", DateTime.Now.ToString("o"));
                        writer.WriteAttributeString("username", HttpContext.Current.User.Identity.Name);
                        writer.WriteAttributeString("email", AnnotationPlugIn.UserEmail);
                        writer.WriteAttributeString("fileName", Path.GetFileName(file.FileName));
                        writer.WriteAttributeString("contentType", file.ContentType);
                        writer.WriteAttributeString("contentLength", file.ContentLength.ToString());
                        writer.WriteAttributeString("value", Regex.Replace(this.Value, "^.+?\\|([\\w,]+?)_Annotation_Attachment(New|\\w+)(.+)$", string.Format("1|$1_Annotation_Attachment{0}$3", Path.GetFileNameWithoutExtension(fileName))));
                        writer.WriteEndElement();
                        fileName = ((Path.GetFileNameWithoutExtension(fileName) + "_")
                                    + Path.GetExtension(file.FileName));
                        file.SaveAs(Path.Combine(p, fileName));
                    }
                    finally
                    {
                        writer.Close();
                    }
                }
            }
            return(true);
        }
コード例 #4
0
        void IPlugIn.ProcessPageRequest(PageRequest request, ViewPage page)
        {
            if (page.Rows.Count == 0)
            {
                page.Icons = new string[0];
                return;
            }
            if (!_requireProcessing)
            {
                var icons = new List <string>();
                for (var i = 0; (i < page.Rows.Count); i++)
                {
                    var rowDir = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, i);
                    if (Directory.Exists(rowDir))
                    {
                        icons.Add("Attachment");
                    }
                    else
                    {
                        icons.Add(null);
                    }
                }
                page.Icons = icons.ToArray();
                return;
            }
            var expressions = new List <DynamicExpression>(page.Expressions);
            var de          = new DynamicExpression();

            de.Target = "Annotations";
            de.Scope  = DynamicExpressionScope.CategoryVisibility;
            de.Type   = DynamicExpressionType.ClientScript;
            de.Test   = "!this.get_isInserting()";
            de.ViewId = page.View;
            expressions.Add(de);
            page.Expressions = expressions.ToArray();
            if (!_retrieveAnnotations)
            {
                return;
            }
            var field = page.FindField("_Annotation_AttachmentNew");

            if (field != null)
            {
                var fieldIndex = page.Fields.IndexOf(field);
                var newValue   = string.Format("{0},{1}|{2}", request.Controller, field.Name, Regex.Replace(((string)(page.Rows[0][fieldIndex])), "^\\w+\\|(.+)$", "$1"));
                if (field.Name == "_Annotation_AttachmentNew")
                {
                    newValue = ("null|" + newValue);
                }
                page.Rows[0][fieldIndex] = newValue;
            }
            var p = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, 0);

            if (Directory.Exists(p))
            {
                var files  = Directory.GetFiles(p, "*.xml");
                var values = new List <object>(page.Rows[0]);
                var i      = (files.Length - 1);
                while (i >= 0)
                {
                    var       filename = files[i];
                    var       doc      = new XPathDocument(filename);
                    var       nav      = doc.CreateNavigator().SelectSingleNode("/*");
                    DataField f        = null;
                    if (nav.Name == "note")
                    {
                        f            = new DataField();
                        f.Name       = "_Annotation_Note";
                        f.Type       = "String";
                        f.HeaderText = string.Format(Localizer.Replace("AnnotationNoteDynamicFieldHeaderText", "{0} written at {1}"), ReadNameAndEmail(nav), Convert.ToDateTime(nav.GetAttribute("timestamp", string.Empty)));
                        f.Columns    = 50;
                        f.Rows       = 7;
                        f.TextMode   = TextInputMode.Note;
                        values.Add(nav.Value);
                    }
                    else
                    if (nav.Name == "attachment")
                    {
                        f                 = new DataField();
                        f.Name            = "_Annotation_Attachment";
                        f.Type            = "Byte[]";
                        f.HeaderText      = string.Format(Localizer.Replace("AnnotationAttachmentDynamicFieldHeaderText", "{0} attached <b>{1}</b> at {2}"), ReadNameAndEmail(nav), nav.GetAttribute("fileName", string.Empty), Convert.ToDateTime(nav.GetAttribute("timestamp", string.Empty)));
                        f.OnDemand        = true;
                        f.OnDemandHandler = "AnnotationPlugIn";
                        f.OnDemandStyle   = OnDemandDisplayStyle.Link;
                        if (nav.GetAttribute("contentType", string.Empty).StartsWith("image/"))
                        {
                            f.OnDemandStyle = OnDemandDisplayStyle.Thumbnail;
                        }
                        f.CategoryIndex = (page.Categories.Count - 1);
                        values.Add(nav.GetAttribute("value", string.Empty));
                    }
                    if (f != null)
                    {
                        f.Name          = (f.Name + Path.GetFileNameWithoutExtension(filename));
                        f.AllowNulls    = true;
                        f.CategoryIndex = (page.Categories.Count - 1);
                        if (!(Controller.UserIsInRole("Administrators")))
                        {
                            f.ReadOnly = true;
                        }
                        page.Fields.Add(f);
                    }
                    i = (i - 1);
                }
                page.Rows[0] = values.ToArray();
                if (files.Length > 0)
                {
                    page.Categories[(page.Categories.Count - 1)].Tab = Localizer.Replace("AnnotationTab", "Notes & Attachments");
                    expressions.RemoveAt((expressions.Count - 1));
                    page.Expressions = expressions.ToArray();
                }
            }
            else
            {
                de.Test = "this.get_isEditing() && this.get_view()._displayAnnotations";
                var g = new ActionGroup();
                page.ActionGroups.Add(g);
                g.Scope = "ActionBar";
                g.Flat  = true;
                var a = new Action();
                g.Actions.Add(a);
                a.WhenLastCommandName = "Edit";
                a.WhenView            = page.View;
                a.CommandName         = "ClientScript";
                a.CommandArgument     = "this.get_view()._displayAnnotations=true;this._focusedFieldName = \'_Annotation_No" +
                                        "teNew\';this._raiseSelectedDelayed=false;";
                a.HeaderText       = Localizer.Replace("AnnotationActionHeaderText", "Annotate");
                a.CssClass         = "AttachIcon";
                a.WhenClientScript = "this.get_view()._displayAnnotations!=true;";
            }
        }