Exemplo n.º 1
0
        private void getTextFile()
        {
            string folderName = context.Request["folder"] ?? "";

            if (!folderName.StartsWith("/"))
            {
                folderName = "/" + folderName.Substring(1);
            }

            string path = InternalProvider.MapPath(folderName);

            if ((File.GetAttributes(path) & FileAttributes.Directory) != FileAttributes.Directory)
            {
                path = Path.GetDirectoryName(path);
            }
            if (!path.StartsWith(InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"])))
            {
                path = InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"]);
            }

            string fileNames = context.Request["name"];

            if (string.IsNullOrEmpty(fileNames) || fileNames.Trim() == "")
            {
                throw new Exception("Dosya seçiniz");
            }
            string fileName = fileNames.Split(new[] { "#NL#" }, StringSplitOptions.RemoveEmptyEntries)[0];

            string filePath = Path.Combine(path, fileName);

            if (File.Exists(filePath))
            {
                context.Response.Write(File.ReadAllText(filePath, Encoding.UTF8));
            }
        }
Exemplo n.º 2
0
        private void uploadFile()
        {
            try
            {
                string folderName = context.Request["folder"] ?? "";
                string path       = InternalProvider.MapPath(folderName);
                if (!path.StartsWith(InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"])))
                {
                    path = InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"]);
                }

                if ((File.GetAttributes(path) & FileAttributes.Directory) != FileAttributes.Directory)
                {
                    path = Path.GetDirectoryName(path);
                }

                for (int i = 0; i < context.Request.Files.Count; i++)
                {
                    string fileName = Path.GetFileName(context.Request.Files[i].FileName).MakeFileName();
                    string imgPath  = Path.Combine(path, fileName);
                    try
                    {
                        // eğer dosya resim ise resize edelim
                        Image bmp = Image.FromStream(context.Request.Files[i].InputStream);
                        if (bmp.Width > InternalProvider.Configuration.ImageUploadMaxWidth)
                        {
                            Image bmp2 = bmp.ScaleImage(InternalProvider.Configuration.ImageUploadMaxWidth, 0);
                            //imgUrl = imgUrl.Substring(0, imgUrl.LastIndexOf('.')) + ".jpg";
                            bmp2.SaveImage(imgPath, InternalProvider.Configuration.ThumbQuality);
                        }
                        else
                        {
                            context.Request.Files[i].SaveAs(imgPath);
                        }
                    }
                    catch
                    {
                        context.Request.Files[i].SaveAs(imgPath);
                    }

                    //context.Request.Files[i].SaveAs(Path.Combine(path, fileName));
                    context.Response.Write(@"<script>window.parent.fileBrowserUploadFeedback('Dosya yüklendi.', '" + folderName + "/" + fileName + "');</script>");
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(@"<script>window.parent.fileBrowserUploadFeedback('Yükleme başarısız. '+" + ex.Message.ToJS() + ");</script>");
            }
        }
Exemplo n.º 3
0
        private void saveTextFile()
        {
            string folderName = context.Request["folder"] ?? "";

            if (!folderName.StartsWith("/"))
            {
                folderName = "/" + folderName.Substring(1);
            }

            string path = InternalProvider.MapPath(folderName);

            if ((File.GetAttributes(path) & FileAttributes.Directory) != FileAttributes.Directory)
            {
                path = Path.GetDirectoryName(path);
            }
            if (!path.StartsWith(InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"])))
            {
                path = InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"]);
            }

            string fileNames = context.Request["name"];

            if (string.IsNullOrEmpty(fileNames) || fileNames.Trim() == "")
            {
                throw new Exception("Dosya seçiniz");
            }
            string fileName = fileNames.Split(new[] { "#NL#" }, StringSplitOptions.RemoveEmptyEntries)[0];

            string filePath = Path.Combine(path, fileName);

            if (File.Exists(filePath))
            {
                string backupFileName = "_old_" + fileName;
                string backupPath     = Path.Combine(path, backupFileName);

                if (File.Exists(backupPath))
                {
                    File.Delete(backupPath);
                }

                File.Move(filePath, backupPath);
                File.WriteAllText(filePath, context.Request["source"], Encoding.UTF8);

                context.Response.Write("ok");
                return;
            }
            context.Response.Write("ERR:File not found.");
        }
Exemplo n.º 4
0
        public IEnumerator <TOutput> GetEnumerator()
        {
            var result = (IEnumerable <TOutput>)InternalProvider.Execute(Expression);

            using (var enumerator = result.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    var item = enumerator.Current;
                    if (item is TEntity)
                    {
                        EntityProcessors.ProcessEntity((TEntity)(object)item);
                    }
                    yield return(item);
                }
            }
        }
Exemplo n.º 5
0
        private void renameFile()
        {
            string folderName = context.Request["folder"] ?? "";

            if (!folderName.StartsWith("/"))
            {
                folderName = "/" + folderName.Substring(1);
            }
            //else folderName = "~/" + folderName;
            string path = InternalProvider.MapPath(folderName);

            if ((File.GetAttributes(path) & FileAttributes.Directory) != FileAttributes.Directory)
            {
                path = Path.GetDirectoryName(path);
            }
            if (!path.StartsWith(InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"])))
            {
                path = InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"]);
            }

            string fileNames = context.Request["name"];

            if (string.IsNullOrEmpty(fileNames) || fileNames.Trim() == "")
            {
                throw new Exception("Dosya seçiniz");
            }
            string fileName = fileNames.Split(new[] { "#NL#" }, StringSplitOptions.RemoveEmptyEntries)[0];

            string newFileName = context.Request["newName"].MakeFileName();
            string newPath     = Path.Combine(path, newFileName);

            string filePath = Path.Combine(path, fileName);

            if (File.Exists(filePath))
            {
                File.Move(filePath, newPath);
            }
            else if (Directory.Exists(filePath))
            {
                Directory.Move(filePath, newPath);
            }

            context.Response.Write(@"<script>window.parent.fileBrowserUploadFeedback('Dosya adı değiştirildi');</script>");
        }
Exemplo n.º 6
0
        private void deleteFile()
        {
            string folderName = context.Request["folder"] ?? "";

            if (!folderName.StartsWith("/"))
            {
                folderName = "/" + folderName;
            }
            string path = InternalProvider.MapPath(folderName);

            if ((File.GetAttributes(path) & FileAttributes.Directory) != FileAttributes.Directory)
            {
                path = Path.GetDirectoryName(path);
            }
            if (!path.StartsWith(InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"])))
            {
                path = InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"]);
            }

            string fileNames = context.Request["name"];

            if (string.IsNullOrEmpty(fileNames) || fileNames.Trim() == "")
            {
                throw new Exception("Dosya seçiniz");
            }

            foreach (string fileName in fileNames.Split(new[] { "#NL#" }, StringSplitOptions.RemoveEmptyEntries))
            {
                string filePath = Path.Combine(path, fileName);
                if (File.Exists(filePath))
                {
                    File.SetAttributes(filePath, FileAttributes.Normal);
                    File.Delete(filePath);
                }
                else if (Directory.Exists(filePath))
                {
                    Directory.Delete(filePath, true);
                }
            }
            context.Response.Write(@"<script>window.parent.fileBrowserUploadFeedback('Dosya silindi');</script>");
        }
Exemplo n.º 7
0
        private void getFileList()
        {
            string folderName = context.Request["folder"] ?? "";
            string path       = InternalProvider.MapPath(folderName);

            if (!path.StartsWith(InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"])))
            {
                path = InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"]);
            }

            List <string> resList = new List <string>();

            string[] items = Directory.GetDirectories(path).OrderBy(s => s).ToArray();
            for (int i = 0; i < items.Length; i++)
            {
                bool isHidden = ((File.GetAttributes(items[i]) & FileAttributes.Hidden) == FileAttributes.Hidden);
                if (!isHidden)
                {
                    DirectoryInfo d = new DirectoryInfo(items[i]);
                    resList.Add("{name:" + d.Name.ToJS() + ", size:-1, date:" + d.LastWriteTime.ToJS() + "}");
                }
            }

            items = Directory.GetFiles(path).OrderBy(s => s).ToArray();

            for (int i = 0; i < items.Length; i++)
            {
                bool isHidden = ((File.GetAttributes(items[i]) & FileAttributes.Hidden) == FileAttributes.Hidden);
                if (!isHidden)
                {
                    FileInfo f = new FileInfo(items[i]);
                    resList.Add("{name:" + f.Name.ToJS() + ", size:" + f.Length.ToJS() + ", date:" + f.LastWriteTime.ToJS() + "}");
                }
            }

            context.Response.Write("{success:true, root:[" + String.Join(",", resList.ToArray()) + "]}");
        }
Exemplo n.º 8
0
        private void createFolder()
        {
            try
            {
                string folderName = context.Request["folder"] ?? "";
                string path       = InternalProvider.MapPath(folderName);
                if (!path.StartsWith(InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"])))
                {
                    path = InternalProvider.MapPath(InternalProvider.AppSettings["userFilesDir"]);
                    context.Response.Write(@"<script>window.parent.alert('Error. There is no such folder.');</script>");
                    return;
                }

                string newFolderName = context.Request["name"].MakeFileName();
                path = Path.Combine(path, newFolderName);
                Directory.CreateDirectory(path);

                context.Response.Write(@"<script>window.parent.fileBrowserUploadFeedback('Klasör oluşturuldu.');</script>");
            }
            catch
            {
                context.Response.Write(@"<script>window.parent.fileBrowserUploadFeedback('Hata');</script>");
            }
        }
Exemplo n.º 9
0
        public IEnumerator <TOutput> GetEnumerator()
        {
            var commandId = Guid.NewGuid();

            var errored = false;

            try
            {
                Connection.DiagnosticListener.OnNext(new ReadDiagnosticCommand
                {
                    CommandId    = commandId,
                    Source       = $"{nameof(MongoFrameworkQueryable<TEntity, TOutput>)}.{nameof(GetEnumerator)}",
                    CommandState = CommandState.Start,
                    EntityType   = typeof(TEntity),
                    Queryable    = this
                });

                IEnumerable <TOutput> result;
                try
                {
                    result = (IEnumerable <TOutput>)InternalProvider.Execute(Expression);
                    Connection.DiagnosticListener.OnNext(new ReadDiagnosticCommand
                    {
                        CommandId    = commandId,
                        Source       = $"{nameof(MongoFrameworkQueryable<TEntity, TOutput>)}.{nameof(GetEnumerator)}",
                        CommandState = CommandState.FirstResult,                         //Note: May need to move this around to actually be after the first "MoveNext" or something
                        EntityType   = typeof(TEntity),
                        Queryable    = this
                    });
                }
                catch (Exception ex)
                {
                    errored = true;
                    Connection.DiagnosticListener.OnNext(new ReadDiagnosticCommand
                    {
                        CommandId    = commandId,
                        Source       = $"{nameof(MongoFrameworkQueryable<TEntity, TOutput>)}.{nameof(GetEnumerator)}",
                        CommandState = CommandState.Error,
                        EntityType   = typeof(TEntity),
                        Queryable    = this
                    });
                    Connection.DiagnosticListener.OnError(ex);

                    throw;
                }

                using (var enumerator = result.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        var item = enumerator.Current;
                        if (item is TEntity)
                        {
                            EntityProcessors.ProcessEntity((TEntity)(object)item, Connection);
                        }
                        yield return(item);
                    }
                }
            }
            finally
            {
                if (!errored)
                {
                    Connection.DiagnosticListener.OnNext(new ReadDiagnosticCommand
                    {
                        CommandId    = commandId,
                        Source       = $"{nameof(MongoFrameworkQueryable<TEntity, TOutput>)}.{nameof(GetEnumerator)}",
                        CommandState = CommandState.End,
                        EntityType   = typeof(TEntity),
                        Queryable    = this
                    });
                }
            }
        }
 public string ToQuery()
 {
     return(InternalProvider.ToQuery(Expression));
 }
        public IEnumerator <TOutput> GetEnumerator()
        {
            var result = (IEnumerable <TOutput>)InternalProvider.Execute(Expression);

            return(result.GetEnumerator());
        }