Exemple #1
0
 public static Media Default()
 {
     Media result = new Media ();
     result._id = Guid.Empty;
     result._path = "/test";
     return result;
 }
Exemple #2
0
        public static Media Load(Guid id)
        {
            Media result;

            try
            {
                Hashtable item = (Hashtable)SNDK.Convert.FromXmlDocument (SNDK.Convert.XmlNodeToXmlDocument (Services.Datastore.Get<XmlDocument> (DatastoreAisle, id.ToString ()).SelectSingleNode ("(//sorentolib.media)[1]")));
                result = new Media ();

                result._id = new Guid ((string)item["id"]);

                if (item.ContainsKey ("createtimestamp"))
                {
                    result._createtimestamp = int.Parse ((string)item["createtimestamp"]);
                }

                if (item.ContainsKey ("updatetimestamp"))
                {
                    result._updatetimestamp = int.Parse ((string)item["updatetimestamp"]);
                }

                if (item.ContainsKey ("type"))
                {
                    result._type = SNDK.Convert.StringToEnum<SorentoLib.Enums.MediaType> ((string)item["type"]);
                    result._temptype = SNDK.Convert.StringToEnum<SorentoLib.Enums.MediaType> ((string)item["type"]);
                }

                if (item.ContainsKey ("path"))
                {
                    result._path = (string)item["path"];
                    result._temppath = (string)item["path"];
                }

                if (item.ContainsKey ("mimetype"))
                {
                    result._mimetype = (string)item["mimetype"];
                }

                if (item.ContainsKey ("size"))
                {
                    result._size = long.Parse ((string)item["size"]);
                }

                if (item.ContainsKey ("description"))
                {
                    result._description = (string)item["description"];
                }

                if (item.ContainsKey ("copyright"))
                {
                    result._copyright = (string)item["copyright"];
                }
            }
            catch (Exception exception)
            {
                // LOG: LogDebug.ExceptionUnknown
                Services.Logging.LogDebug (string.Format (Strings.LogDebug.ExceptionUnknown, "SORENTOLIB.MEDIA", exception.Message));

                // EXCEPTION: Excpetion.MediaLoad
                throw new Exception (string.Format (Strings.Exception.MediaLoad, id));
            }

            return result;
        }
Exemple #3
0
        public static Media FromAjaxItem(Hashtable Item)
        {
            Media result = null;

            Guid id = Guid.Empty;

            try
            {
                id = new Guid ((string)Item["id"]);
            }
            catch {}

            if (id != Guid.Empty)
            {
                try
                {
                    result = Media.Load (id);
                }
                catch
                {
                    result = new Media ();
                    result._id = id;

                    if (Item.ContainsKey ("createtimestamp"))
                    {
                        result._createtimestamp = int.Parse ((string)Item["createtimestamp"]);
                    }

                    if (Item.ContainsKey ("updatetimestamp"))
                    {
                        result._createtimestamp = int.Parse ((string)Item["updatetimestamp"]);
                    }
                }
            }
            else
            {
                result = new Media ();
            }

            if (Item.ContainsKey ("path"))
            {
                result._path = (string)Item["path"];
            }

            if (Item.ContainsKey ("size"))
            {
                try
                {
                    result._size = long.Parse ((string)Item["size"]);
                }
                catch {}
            }

            if (Item.ContainsKey ("mimetype"))
            {
                result._mimetype = (string)Item["mimetype"];
            }

            if (Item.ContainsKey ("accesslevel"))
            {
                result._accesslevel = SNDK.Convert.StringToEnum<SorentoLib.Enums.Accesslevel> ((string)Item["accesslevel"]);
            }

            if (Item.ContainsKey ("status"))
            {
                result._status = SNDK.Convert.StringToEnum<SorentoLib.Enums.MediaStatus> ((string)Item["status"]);
            }

            if (Item.ContainsKey ("description"))
            {
                result._description = (string)Item["description"];
            }

            if (Item.ContainsKey ("copyright"))
            {
                result._copyright = (string)Item["copyright"];
            }

            //			if (Item.ContainsKey ("accesslevel"))
            //			{
            //				}
            //			}

            return result;
        }
Exemple #4
0
        public Media Clone(string Path)
        {
            Media result = new Media (Path, this.DataPath, false);
            result.Status = this._currentstatus;
            result.Save ();

            return result;
        }
Exemple #5
0
        public bool Process(SorentoLib.Session Session, string Fullname, string Method)
        {
            bool result = false;

            switch (Fullname.ToLower ())
            {
                #region Session
                case "sorentolib.session":
                {
                    switch (Method.ToLower ())
                    {
                        case "login":
                        {
            //							return Session.Login (Session.Request.QueryJar.Get ("username").Value, SorentoLib.Tools.StringHelper.ASCIIBytesToString (SorentoLib.Services.Crypto.Decrypt (SorentoLib.Tools.StringHelper.HexStringToBytes (Session.Request.QueryJar.Get("password").Value))));
                            result = Session.Login (Session.Request.QueryJar.Get ("username").Value, Session.Request.QueryJar.Get("password").Value);
                            break;
                        }

                        case "logout":
                        {
                            result = Session.Logout ();
                            break;
                        }
                    }
                    break;
                }
                #endregion

                #region Media
                case "sorentolib.media":
                {
                    switch (Method.ToLower ())
                    {
                        case "upload":
                        {
                            try
                            {
                                string path = Session.Request.QueryJar.Get ("path").Value;

                                string filename = System.IO.Path.GetFileNameWithoutExtension (Session.Request.QueryJar.Get ("upload").Value).Replace ("%", "_");
                                string extension = System.IO.Path.GetExtension (Session.Request.QueryJar.Get ("upload").Value).ToLower ();

                                path = path.Replace ("%%GUID%%", Guid.NewGuid ().ToString ()).Replace ("%%FILENAME%%", filename).Replace ("%%EXTENSION%%", extension);

                                SorentoLib.Enums.MediaStatus status = SNDK.Convert.StringToEnum<SorentoLib.Enums.MediaStatus> (Session.Request.QueryJar.Get ("status").Value);
                                string mediatransformations = Session.Request.QueryJar.Get ("mediatransformations").Value;
                                string mimetypes = Session.Request.QueryJar.Get ("mimetypes").Value;
                                string postuploadscript = Session.Request.QueryJar.Get ("postuploadscript").Value;

                                if (mimetypes.Contains (Session.Request.QueryJar.Get ("upload").BinaryContentType))
                                {
                                    SorentoLib.Media media = new SorentoLib.Media (path, Session.Request.QueryJar.Get ("upload").BinaryData);
                                    media.Status = status;
                                    media.Save ();

                                    if (postuploadscript != string.Empty)
                                    {
                                        SorentoLib.MediaTransformation.Transform (media.DataPath, SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.core_pathscript) + postuploadscript);
                                    }

                                    if (mediatransformations != string.Empty)
                                    {
                                        foreach (string mediatransformationid in mediatransformations.Split (";".ToCharArray (), StringSplitOptions.RemoveEmptyEntries))
                                        {
                                            MediaTransformation mediatransformation = MediaTransformation.Load (new Guid (mediatransformationid));
                                            mediatransformation.Transform (media);
                                        }
                                    }

                                    Session.Page.Variables.Add ("mediaid", media.Id);
                                    Session.Page.Variables.Add ("mediasoftpath", media.Path);

                                    Console.WriteLine (media.Path);
                                    Session.Page.Variables.Add ("uploadsuccess", "true");
                                }
                                else
                                {
                                    Session.Page.Variables.Add ("uploadsuccess", "false");
                                    Session.Page.Variables.Add ("cmderrormessage", Strings.ErrorMessage.MediaUploadMimeType);
                                }

                                result = true;
                            }
                            catch (Exception exception)
                            {

                                Session.Page.Variables.Add ("uploadsuccess", "false");
                                Session.Page.Variables.Add ("cmderrormessage", Strings.ErrorMessage.MediaUploadUnknown);
                                SorentoLib.Services.Logging.LogDebug (string.Format (Strings.LogDebug.MediaUploadException, exception.ToString ()));
                            }
                        }
                        break;
                    }
                    break;
                }
                #endregion

                // TODO: Implement Function[SorentoLib.User]
                #region User
                case "sorentolib.user":
                    break;
                #endregion

                // TODO: Implement Function[SorentoLib.UserGroup]
                #region UserGroup
                case "sorentolib.usergroup":
                    break;
                #endregion

                #region SorentoLib.Services.Snapshot
                case "sorentolib.services.snapshot":
                {
                    switch (Method.ToLower ())
                    {
                        case "upload":
                        {
                            if (Session.Request.QueryJar.Get ("upload").BinaryContentType == "application/zip")
                            {
                                FileStream filestream = File.Create (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.snapshot_path) + Session.Request.QueryJar.Get ("upload").Value);
                                BinaryWriter binarywriter = new BinaryWriter(filestream);
                                binarywriter.Write(Session.Request.QueryJar.Get ("upload").BinaryData);
                                binarywriter.Close();
                                filestream.Close();

                                Session.Page.Variables.Add ("uploadsuccess", "true");
                            }
                            break;
                        }
                    }
                    break;
                }
                #endregion
            }

            return result;
        }
 public void Transform(Media Media)
 {
     SorentoLib.Services.Scripting.Parse (this._script, Media.DataPath, Media.DataPath);
 }
        public static void Transform(Media Media, string ScriptPath)
        {
            string xml = string.Empty;
            foreach (string line in SNDK.IO.ReadTextFile (ScriptPath, Encoding.UTF8))
            {
                xml += line;
            }

            MediaTransformation transformation = new MediaTransformation ();
            transformation.Script = xml;
            transformation.Transform (Media);
        }
Exemple #8
0
        public bool Process(SorentoLib.Session Session, string Fullname, string Method)
        {
            switch (Fullname.ToLower ())
            {
                #region Item
                case "didius.item":

                    switch (Method.ToLower ())
                    {
                        case "imageupload":
                            List<string> allowedfiletypes = new List<string> ();
                            allowedfiletypes.Add ("image/jpeg");
                            allowedfiletypes.Add ("image/png");
                            allowedfiletypes.Add ("image/gif");

            //							allowedfiletypes.Add ("application/pdf");
            //							allowedfiletypes.Add ("image/gif");

                            Console.WriteLine (Session.Request.QueryJar.Get ("image").BinaryContentType);

                            if (allowedfiletypes.Contains (Session.Request.QueryJar.Get ("image").BinaryContentType))
                            {

                                Console.WriteLine ("BLA");
                                SorentoLib.Media image = new SorentoLib.Media ("/media/didius/app/"+ Guid.NewGuid ().ToString (), Session.Request.QueryJar.Get ("image").BinaryData);
                                image.Path = image.Directory +"/"+ image.Id.ToString () +".jpg";
                                image.Type = SorentoLib.Enums.MediaType.Public;
                                image.Save ();

                                MediaTransformation.Transform (image, SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_script) + "didius/item_picture_resize.xml");

            //								Session.Page.Variables.Add ("mediaid", image.Id);
            //								Session.Page.Variables.Add ("mediasoftpath", image.Path);
            //								Session.Page.Variables.Add ("uploadsuccess", "true");

                                Session.Page.Lines.Add ("SUCCESS:"+ image.Id);

                                return true;
                            }

                            Session.Page.Lines.Add ("ERROR");
                            return true;

                        default:
                            return false;
                    }
                #endregion

                #region Invoice
            case "didius.invoice":
                switch (Method.ToLower ())
                {
                case "mailto":
                {
                            Console.WriteLine ("MAILTO");

                    try
                    {
                        Customer customer = Customer.Load (new Guid (Session.Request.QueryJar.Get ("customerid").Value));

                                Console.WriteLine (Session.Request.QueryJar.Get ("pdf").BinaryContentType);

                        List<SorentoLib.Tools.Helpers.SendMailAttatchment> attatchments = new List<SorentoLib.Tools.Helpers.SendMailAttatchment> ();
                        attatchments.Add (new SorentoLib.Tools.Helpers.SendMailAttatchment (Session.Request.QueryJar.Get ("pdf").BinaryData, "faktura.pdf", Session.Request.QueryJar.Get ("pdf").BinaryContentType));

                        SorentoLib.Tools.Helpers.SendMail ("*****@*****.**", customer.Email, "Faktura", "Her er din faktura!", false, attatchments);

                        Session.Page.Lines.Add ("SUCCESS:"+ "TRUE");
                    } catch (Exception e)
                    {
                                Console.WriteLine (e);

                        Session.Page.Lines.Add ("ERROR");
                        return true;
                    }

                    Console.WriteLine ("AllDone");
                    return true;
                }

                default:
                    return false;
                }

            #endregion

                #region Helpers
                case "didius.helpers":
                {
                    switch (Method.ToLower ())
                    {
                        case "mailfiletocustomer":
                        {
                            try
                            {
                                string filename = SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_temp) + "/"+ Guid.NewGuid ();
                                SNDK.IO.ByteArrayToFile (filename, Session.Request.QueryJar.Get ("file").BinaryData);

                                Helpers.MailFileToCustomer (Customer.Load (new Guid (Session.Request.QueryJar.Get ("customerid").Value)), filename, "Hej med dig!");

                                Session.Page.Lines.Add ("SUCCESS:"+ "TRUE");

                            }
                            catch (Exception e)
                            {
                                Console.WriteLine (e);
                                Session.Page.Lines.Add ("ERROR");
                                return true;
                            }
                            break;
                        }

                        case "mailinvoice":
                        {
                            try
                            {
                                string filename = SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_temp) + "/"+ Guid.NewGuid ();
                                SNDK.IO.ByteArrayToFile (filename, Session.Request.QueryJar.Get ("file").BinaryData);

                                try
                                {
                                    Helpers.MailInvoice (Invoice.Load (new Guid (Session.Request.QueryJar.Get ("invoiceid").Value)), filename);
                                }
                                catch
                                {
                                    // TODO: remove this.
            //									Invoice invoice = Invoice.Create (Auction.Load (new Guid (Session.Request.QueryJar.Get ("auctionid").Value)), Customer.Load (new Guid (Session.Request.QueryJar.Get ("customerid").Value)), true);
            //									Helpers.MailInvoice (invoice, filename);
                                }

                                Session.Page.Lines.Add ("SUCCESS:"+ "TRUE");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine (e);
                                Session.Page.Lines.Add ("ERROR");
                                return true;
                            }
                            break;
                        }

                    case "mailsettlement":
                        {
                            try
                            {
                                string filename = SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_temp) + "/"+ Guid.NewGuid ();
                                SNDK.IO.ByteArrayToFile (filename, Session.Request.QueryJar.Get ("file").BinaryData);

                                try
                                {
                                    Helpers.MailSettlement (Settlement.Load (new Guid (Session.Request.QueryJar.Get ("settlementid").Value)), filename);
                                }
                                catch
                                {
                                    // TODO: remove this.
            //									Invoice invoice = Invoice.Create (Auction.Load (new Guid (Session.Request.QueryJar.Get ("auctionid").Value)), Customer.Load (new Guid (Session.Request.QueryJar.Get ("customerid").Value)), true);
            //									Helpers.MailInvoice (invoice, filename);
                                }

                                Session.Page.Lines.Add ("SUCCESS:"+ "TRUE");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine (e);
                                Session.Page.Lines.Add ("ERROR");
                                return true;
                            }
                            break;
                        }

                case "mailcreditnote":
                        {
                            try
                            {
                                string filename = SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_temp) + "/"+ Guid.NewGuid ();
                                SNDK.IO.ByteArrayToFile (filename, Session.Request.QueryJar.Get ("file").BinaryData);

                                try
                                {
                                    Helpers.MailCreditnote (Creditnote.Load (new Guid (Session.Request.QueryJar.Get ("creditnoteid").Value)), filename);
                                }
                                catch
                                {
                                    // TODO: remove this.
            //									Invoice invoice = Invoice.Create (Auction.Load (new Guid (Session.Request.QueryJar.Get ("auctionid").Value)), Customer.Load (new Guid (Session.Request.QueryJar.Get ("customerid").Value)), true);
            //									Helpers.MailInvoice (invoice, filename);
                                }

                                Session.Page.Lines.Add ("SUCCESS:"+ "TRUE");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine (e);
                                Session.Page.Lines.Add ("ERROR");
                                return true;
                            }
                            break;
                        }

                        case "mailsalesagreement":
                        {
                            try
                            {
                                string filename = SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_temp) + "/"+ Guid.NewGuid ();
                                SNDK.IO.ByteArrayToFile (filename, Session.Request.QueryJar.Get ("file").BinaryData);

                                Helpers.MailSalesAgreement (Customer.Load (new Guid (Session.Request.QueryJar.Get ("customerid").Value)), filename);

                                Session.Page.Lines.Add ("SUCCESS:"+ "TRUE");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine (e);
                                Session.Page.Lines.Add ("ERROR");
                                return true;
                            }
                            break;
                        }

            //						case "mailsettlement":
            //						{
            //							try
            //							{
            //								string filename = SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_temp) + "/"+ Guid.NewGuid ();
            //								SNDK.IO.ByteArrayToFile (filename, Session.Request.QueryJar.Get ("file").BinaryData);
            //
            //								Helpers.MailSettlement (Customer.Load (new Guid (Session.Request.QueryJar.Get ("customerid").Value)), filename);
            //
            //								Session.Page.Lines.Add ("SUCCESS:"+ "TRUE");
            //							}
            //							catch (Exception e)
            //							{
            //								Console.WriteLine (e);
            //								Session.Page.Lines.Add ("ERROR");
            //								return true;
            //							}
            //							break;
            //						}
                    }
                    break;
                }
                    #endregion

                #region Settlement
            case "didius.settlement":
                switch (Method.ToLower ())
                {
                case "mailto":
                {
                    try
                    {
                        Customer customer = Customer.Load (new Guid (Session.Request.QueryJar.Get ("customerid").Value));

                        Console.WriteLine (Session.Request.QueryJar.Get ("pdf").BinaryContentType);

                        List<SorentoLib.Tools.Helpers.SendMailAttatchment> attatchments = new List<SorentoLib.Tools.Helpers.SendMailAttatchment> ();
                        attatchments.Add (new SorentoLib.Tools.Helpers.SendMailAttatchment (Session.Request.QueryJar.Get ("pdf").BinaryData, "afregning.pdf", Session.Request.QueryJar.Get ("pdf").BinaryContentType));

                        SorentoLib.Tools.Helpers.SendMail ("*****@*****.**", customer.Email, "Faktura", "Her er din afregning!", false, attatchments);

                        Session.Page.Lines.Add ("SUCCESS:"+ "TRUE");
                    } catch
                    {
                        Session.Page.Lines.Add ("ERROR");
                        return true;
                    }

                    return true;
                }

                default:
                    return false;
                }
            #endregion
            }

            return false;
        }
Exemple #9
0
        public bool Process(SorentoLib.Session Session, string Fullname, string Method)
        {
            switch (Fullname.ToLower ())
            {
                #region Page
                case "scms.page":

                    switch (Method.ToLower ())
                    {
                        case "imageupload":
                            List<string> allowedfiletypes = new List<string> ();
                            allowedfiletypes.Add ("image/jpeg");
                            allowedfiletypes.Add ("image/png");
                            allowedfiletypes.Add ("image/gif");

                            if (allowedfiletypes.Contains (Session.Request.QueryJar.Get ("UploadImage").BinaryContentType))
                            {
                                SorentoLib.Media image = new SorentoLib.Media ("/media/content/"+ Guid.NewGuid ().ToString () +".jpg", Session.Request.QueryJar.Get ("UploadImage").BinaryData);
                                image.Type = SorentoLib.Enums.MediaType.Public;
                                image.Save ();

            //								SNDK.IO.CopyFile (image.DataPath, SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_publicmedia) +"/administration/cache/thumbnails/"+ image.FileName);
            //
            //								SorentoLib.MediaTransformation.Transform (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_publicmedia) +"/administration/cache/thumbnails/"+ image.FileName, "data/scripts/media_image_thumbnail.xml");
            //
            //
            //								SorentoLib.MediaTransformation.Transform (image.DataPath, "data/scripts/test.xml");
            //								SorentoLib.MediaTransformation.Transform (image, "data/scripts/test.xml");

            //								SorentoLib.Media thumbnail = image.Clone ("administration/cache/thumbnails/"+ image.FileName);

            //								SorentoLib.MediaTransformation.TransformWithScript ("data/scripts/media_image_thumbnail.xml", thumbnail);

            //								MediaTransformation thumbnailer = new MediaTransformation (SorentoLib.Enums.MediaTransformationType.Image);

            //								string xml = string.Empty;
            //								foreach (string line in Toolbox.IO.ReadTextFile ("data/scripts/media_image_thumbnail.xml", Encoding.UTF8))
            //								{
            //									xml += line;
            //								}

            //								thumbnailer.Script = xml;
            //								thumbnailer.Transform (thumbnail);

            //								Media media2 = media1.Clone ("thumbs/"+ media1.FileName);
                                //			Media media2 = media1.Clone (media1.Path);
                                //			t1.Transform (media2);

            //								Console.WriteLine (thumbnail.Path);

            //								string script = SorentoLib.Services.Datastore.Get ("akvabase.graphics.profile.avatar", "resize");
            //								bool test = Toolbox.Graphics.ParseJob (script, image.HardPath, image.HardPath);
            //								Console.WriteLine (test);

            //								if (test)
            //								{
                                    Session.Page.Variables.Add ("mediaid", image.Id);
                                    Session.Page.Variables.Add ("mediasoftpath", image.Path);
                                    Session.Page.Variables.Add ("uploadsuccess", "true");
                                    return true;
            //								}
            //								else
            //								{
            //									Session.Page.Variables.Add ("uploadsuccess", "false");
            //									return false;
            //								}
                            }

                            Session.Page.Variables.Add ("uploadsuccess", "false");
                            return true;

                        default:
                            return false;
                    }
                #endregion
            }

            return false;
        }