示例#1
0
        public void Upload(string path)
        {
            if (!string.IsNullOrEmpty(path) && CanUpload)
            {
                var fi = new System.IO.FileInfo(path);
                int id = DataContext.CreateBlob(fi, fi.GetMimeType());

                File.Blob = DataContext.Find<Zetbox.App.Base.Blob>(id);
                File.Name = File.Blob.OriginalName;
            }
        }
示例#2
0
 public static void Upload(File obj)
 {
     // UI Code in Custom Actions!
     // ASP.NET would have a big Problem with that function
     string path = _factory.GetSourceFileNameFromUser();
     if (!string.IsNullOrEmpty(path))
     {
         var fi = new System.IO.FileInfo(path);
         int id = obj.Context.CreateBlob(fi, fi.GetMimeType());
         obj.Blob = obj.Context.Find<Zetbox.App.Base.Blob>(id);
         obj.Name = obj.Blob.OriginalName;
     }
 }
示例#3
0
        public static void Upload(Zetbox.App.GUI.Icon obj)
        {
            // UI Code in Custom Actions!
            // ASP.NET would have a big Problem with that function
            string path = _factory.GetSourceFileNameFromUser();

            if (!string.IsNullOrEmpty(path))
            {
                var fi = new System.IO.FileInfo(path);
                int id = obj.Context.CreateBlob(fi, fi.GetMimeType());
                obj.Blob     = obj.Context.Find <Zetbox.App.Base.Blob>(id);
                obj.IconFile = obj.Blob.OriginalName;
            }
        }
        public override bool OnDrop(object data)
        {
            var files = data as string[];
            if (files == null) return base.OnDrop(data);

            var newScope = ViewModelFactory.CreateNewScope();
            var newCtx = newScope.ViewModelFactory.CreateNewContext();
            var module = newCtx.Find<Module>(CurrentModule.ID);
            var objects = new List<IDataObject>();

            foreach (var file in files)
            {
                try
                {
                    var ext = System.IO.Path.GetExtension(file).ToLower();
                    switch(ext)
                    {
                        case ".png":
                        case ".jpg":
                        case ".bmp":
                        case ".tiff":
                        case ".gif":
                        case ".ico":
                            var obj = newCtx.Create<Icon>();
                            var fi = new System.IO.FileInfo(file);
                            int id = newCtx.CreateBlob(fi, fi.GetMimeType());
                            obj.Blob = newCtx.Find<Zetbox.App.Base.Blob>(id);
                            obj.IconFile = obj.Blob.OriginalName;
                            obj.Module = module;
                            objects.Add(obj);
                            break;
                    }
                }
                catch (Exception ex)
                {
                    // not an xml...
                    Zetbox.API.Utils.Logging.Client.Error("Unable to import icon.", ex);
                }
            }

            if (objects.Count > 0)
            {
                var newWorkspace = ObjectEditor.WorkspaceViewModel.Create(newScope.Scope, newCtx);
                newScope.ViewModelFactory.ShowModel(newWorkspace, true);

                foreach (var obj in objects)
                {
                    newWorkspace.ShowObject(obj, activate: false);
                }

                newScope.ViewModelFactory.CreateDelayedTask(newWorkspace, () =>
                {
                    newWorkspace.SelectedItem = newWorkspace.Items.FirstOrDefault();
                }).Trigger();
            }
            else
            {
                newScope.Dispose();
            }

            return true;
        }