Пример #1
0
        /// <summary>
        /// load cfg file from ftp site or web site
        /// </summary>
        /// <param name="val"></param>
        /// <param name="DS"></param>
        private static void include(VAL val, Memory DS)
        {
            if (val.Size != 1 || val[0].VALTYPE != VALTYPE.stringcon)
            {
                cerr.WriteLine("required 1 parameters on function include(file), file can be local disk file, hyperlink, and ftp link");
                return;
            }

            string url = (string)val[0];

            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            var  link   = FileLink.CreateLink(url);
            bool exists = false;

            try
            {
                exists = link.Exists;
            }
            catch (Exception ex)
            {
                cerr.WriteLine($"configuration file {link} doesn't exist, {ex.Message}");
                return;
            }

            if (!exists)
            {
                cerr.WriteLine($"configuration file {link} doesn't exist");
                return;
            }

            string code = null;

            try
            {
                code = link.ReadAllText();
            }
            catch (Exception ex)
            {
                cerr.WriteLine($"failed to load configuration file {link}, {ex.Message}");
                return;
            }

            if (string.IsNullOrEmpty(code))
            {
                return;
            }

            try
            {
                Script.Execute(code, DS);
            }
            catch (Exception ex)
            {
                cerr.WriteLine($"configuration file format error in {link}, {ex.Message}");
            }
        }
Пример #2
0
 protected void CancelItem()
 {
     projectItem      = null;
     FileLinkSelected = null;
     modeItem         = Mode.None;
     HideManuals();
 }
        public IFileLinkInfo MoveFile(FileLink source, FileLink destination)
        {
            lock (Client)
                Client.MoveFile(source.FullName, destination.FullName);

            return(GetFileInfo(destination.FullName));
        }
Пример #4
0
        public List <File> AddFiles(int fieldId, int docId, IEnumerable <File> files)
        {
            List <File> result = new List <File>();

            using (var db = new CMSContext())
            {
                foreach (File file in files)
                {
                    db.Files.Add(file);
                    db.SaveChanges();

                    var fileLink = new FileLink()
                    {
                        FieldId = fieldId,
                        DocId   = docId,
                        FileId  = file.Id
                    };

                    db.FileLinks.Add(fileLink);
                    db.SaveChanges();

                    result.Add(file);
                }
            }
            return(result);
        }
Пример #5
0
        public void FileRepoCheck()
        {
            CleanUpDatabase();
            _db = CreateDBInstance();
            _db.Init();

            DatabaseService.RegisterInstance(_db);

            var file = FileLink.Create(@"C:\dummy_test_file.txt");

            DatabaseService.FileRepository.Write(file);

            var dbObject = (IPersistable)file;

            Assert.IsFalse(dbObject.Key.IsEmpty());

            var readed = DatabaseService.FileRepository.FindByKey(dbObject.Key);

            Assert.IsFalse(readed == default(FileLink));
            Assert.IsTrue(readed.FullName == file.FullName);

            DatabaseService.FileRepository.Remove(readed);
            readed = DatabaseService.FileRepository.FindByKey(dbObject.Key);
            Assert.IsTrue(readed == default(FileLink));

            CleanUpDatabase();
        }
Пример #6
0
        public async Task <IEnumerable <FileLink> > GetLinksToFilesInFolder(string folderPath)
        {
            var links = new List <FileLink>();

            try
            {
                var files = await foldersClient.GetFolderContent(folderPath);

                var retrievedLinks = await urlClient.GetAllLinks();

                var sharedLinkMetadatas = retrievedLinks.ToList();
                foreach (var file in files.Entries)
                {
                    var link = new FileLink
                    {
                        FileName = file.Name
                    };
                    var existingSharedFile = sharedLinkMetadatas.FirstOrDefault(x => x.PathLower == file.PathLower);
                    link.Url = TurnIntoSourceLink(
                        existingSharedFile != null
                            ? existingSharedFile.Url
                            : await urlClient.CreateLinkToFile(file.PathLower));
                    links.Add(link);
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "exception when retrieving links");
            }

            return(links);
        }
Пример #7
0
        /// <summary>
        /// Get the file names with link on it
        /// </summary>
        /// <returns>The file names with link</returns>
        public List <FileLink> GetFiles()
        {
            List <FileLink> files = new List <FileLink>();

            IFileStorage  storage   = FileStorageFactory.CreateFileStorage();
            List <string> fileNames = storage.GetFileNames();

            foreach (string fileName in fileNames)
            {
                FileLink fileLink = new FileLink();
                fileLink.Name = fileName;
                if (fileName == ".wopitest")
                {
                    fileLink.Url = string.Format("http://{0}/WopiValidator/Index/{1}",
                                                 ConfigurationManager.AppSettings["WOPIServerName"],
                                                 fileName);
                }

                else
                {
                    fileLink.Url = string.Format("http://{0}/wopiframe/Index/{1}",
                                                 ConfigurationManager.AppSettings["WOPIServerName"],
                                                 fileName);
                }

                files.Add(fileLink);
            }

            return(files);
        }
Пример #8
0
            // --

            public static Link ParseLink(JToken json)
            {
                if (json == null)
                {
                    return(null);
                }
                String  linkType = (string)json["type"];
                JObject value    = (JObject)json["value"];

                switch (linkType)
                {
                case "Link.web":
                    return(WebLink.Parse(value));

                case "Link.document":
                    return(DocumentLink.Parse(value));

                case "Link.file":
                    return(FileLink.Parse(value));

                case "Link.image":
                    return(ImageLink.Parse(value));
                }
                return(null);
            }
Пример #9
0
        public override int SelectData(SelectClause select, DataSet ds)
        {
            TableName tname = select.TableName;
            var       file  = fileLink.PathCombine(tname.DatabaseName.Name, tname.ShortName);

            file = string.Format("{0}.{1}", file, EXT);

            var link = FileLink.CreateLink(file, tname.Provider.UserId, tname.Provider.Password);

            if (!link.Exists)
            {
                throw new InvalidDataException($"table {tname.FormalName} data file \"{file}\" not exist");
            }

            link.ReadXml(ds);

            if (ds.Tables.Count > 0)
            {
                return(ds.Tables[0].Rows.Count);
            }
            else
            {
                return(-1);
            }
        }
Пример #10
0
        public TableResultPane AddTab(TableName tname, int top)
        {
            FileLink        link = FileLink.CreateLink(tname.FullPath);
            TableResultPane pane;

            if (panes.ContainsKey(link))
            {
                pane = (TableResultPane)panes[link];
                tabControl.SelectedItem = pane.TabItem;
                return(pane);
            }

            pane = new TableResultPane(this, tname, top)
            {
                Link = link
            };

            panes.Add(link, pane);

            TabItem newTab = new TabItem
            {
                Header  = NewLabelImage(pane, tname.Path, "Close_16x16.png"),
                Content = pane,
                ToolTip = link.ToString(),
            };

            pane.TabItem = newTab;
            tabControl.Items.Add(newTab);
            newTab.Focus();

            return(pane);
        }
        private void DownloadFile(FileLink fileLink, WebClient client)
        {
            Console.WriteLine("File {0} status - started.", fileLink.Name);
            var sppedInBps = _speedInKbps * 1024;

            _timer.Start();
            using (var stream = client.OpenRead(fileLink.HttpAddress))
            {
                var throttledStream = new ThrottledStream(stream, sppedInBps);

                var fileName = _outputPath + fileLink.Name;

                using (var file = File.Create(fileName))
                {
                    var buffer    = new byte[BufferSize];
                    var readCount = throttledStream.Read(buffer, 0, BufferSize);

                    while (readCount > 0)
                    {
                        file.Write(buffer, 0, readCount);
                        readCount = throttledStream.Read(buffer, 0, BufferSize);
                    }
                }
                throttledStream.Close();
            }
            _timer.Stop();
            Console.WriteLine("File {0} status - downloaded in {1} seconds.", fileLink.Name, _timer.ElapsedMilliseconds / 1000);
            _timer.Reset();
        }
        public IFileLinkInfo WriteFile(FileLink file, Stream stream)
        {
            lock (Client)
                Client.Upload(stream, file.FullName, FtpExists.Overwrite, true);

            return(GetFileInfo(file.FullName));
        }
Пример #13
0
        private void Deploy(FileLink zipLocation)
        {
            var zipFolder = new LocalFolder(zipLocation.Folder);

            var outputResource = FolderResource.From("_deploy_");
            var outputFolder   = zipFolder.Then(outputResource);

            try
            {
                Deploy(outputFolder);

                zipFolder.Delete(zipLocation.Name, strict: false);

                Log.Info("[deploy] Zipping to {Location:l}", zipLocation);

                ZipFile.CreateFromDirectory(
                    outputFolder.Link.ToString(),
                    zipLocation.ToString(),
                    default(CompressionLevel),
                    includeBaseDirectory: false);
            }
            finally
            {
                outputFolder.Delete(strict: false);

                Log.Info("[deploy] Deleted temporary folder {Output:l}", outputResource);
            }
        }
Пример #14
0
        public static void AppendProxyToTextFile(FileLink fileLink, Proxy proxy)
        {
            EmptyParamContract.Validate(fileLink);
            EmptyParamContract.Validate(proxy);

            TextIO.WriteAsync(fileLink.Path, proxy.ToString(), true);
        }
Пример #15
0
        private int LogLinkJoined(FileLink link, List <TrackedFile> memberFiles)
        {
            if (link == null || memberFiles == null || memberFiles.Count == 0)
            {
                return(0);
            }
            int nJoined = 0;

            foreach (var file in memberFiles)
            {
                Event ev = new Event();
                ev.EventTypeID = EventTypes.FileLinkJoinedGroup;
                ev.OccurredOn  = DateTime.Now;
                ev.LinkID      = link.LinkMemoID;
                ev.FileID      = file.FileID;
                ev.Description = $"{file.Filename}.{file.FileExtension} joined " +
                                 (string.IsNullOrEmpty(link.LinkMemo) ? "unnamed file group"  : $"file group: {link.LinkMemo}");
                bool wasJoined = Logger.Log(ev);
                if (wasJoined)
                {
                    nJoined++;
                }
            }
            return(nJoined);
        }
Пример #16
0
 public virtual void Delete(FileLink entityToDelete)
 {
     entityToDelete.Delete();
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
 }
Пример #17
0
        public void New()
        {
            FileLink link = FileLink.CreateLink(untitled);

            link.TemporaryLink = true;

            Display(link);
        }
 public void DeleteFile(FileLink file)
 {
     lock (File)
     {
         File.BeginUpdate();
         File.Delete(file.FullName);
         File.CommitUpdate();
     }
 }
Пример #19
0
        private void ScriptTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FileLink link = SelectedPane?.Link;

            if (link != null)
            {
                this.Title = $"{link} - sqlcon";
            }
        }
Пример #20
0
        /// <summary>
        /// The ReplaceLink helper method.
        /// </summary>
        /// <param name="link"></param>
        /// <param name="oPath"></param>
        private void ReplaceLink(FileLink link, string oPath)
        {
            string path = cfg.TargetDirectory + "\\";

            link.FilePath = oPath.Replace(path, "");
            logging.WriteLine(LogLevel.INFO,
                              string.Format("--> Link [action: 1, id: 0x{0:X8}, path: {1}]",
                                            link.InternalID.ToInt32(), link.FilePath));
        }
Пример #21
0
        public FileDbConnectionProvider(string name, string connectionString, DbFileType fileType)
            : base(name, ConnectionProviderType.DbFile, new SimpleDbConnectionStringBuilder(connectionString))
        {
            this.DbFileType       = fileType;
            this.FileLink         = FileLink.CreateLink(DataSource, this.UserId, this.Password);
            this.FileLink.Options = ConnectionBuilder;

            this.DataFile = DbFile.Create(DbFileType, FileLink);
        }
Пример #22
0
        private void btnAddFiles_Click(object sender, EventArgs e)
        {
            if (filesToAdd == null || filesToAdd.Count == 0)
            {
                return;
            }
            int nAdded = 0;
            List <TrackedFile> newFiles = new List <TrackedFile>();

            foreach (var file in filesToAdd)
            {
                FileInfo fi = new FileInfo(file);
                if (!fi.Exists)
                {
                    continue;
                }

                bool alreadyInSystem = FileManager.Exists(file);
                if (!alreadyInSystem)
                {
                    TrackedFile newFile = FileManager.AddFile(
                        Path.GetFileNameWithoutExtension(fi.Name),
                        fi.Extension.Substring(1), fi.DirectoryName,
                        (int)fi.Length, fi.CreationTime, fi.LastWriteTime);
                    if (newFile != null)
                    {
                        LogFileAdded(newFile);
                        newFiles.Add(newFile);
                        nAdded++;
                    }
                }
            }
            bool   wantsLink  = chkLinkFiles.Checked;
            string linkResult = null;

            if (wantsLink && nAdded > 1 && newFiles.Count > 1)
            {
                string memo    = txtMemo.Text.Trim();
                var    fileIDs = from file in newFiles
                                 select file.FileID;
                FileLink newLink = LinkManager.AddLink(fileIDs.ToList(), memo);
                if (newLink != null)
                {
                    // Log link creation and each file joined
                    LogLinkCreation(newLink.LinkMemoID, nAdded, memo);
                    LogLinkJoined(newLink, newLink.GetFiles());
                    linkResult = $"\n\nLinked {nAdded} files" +
                                 (string.IsNullOrEmpty(memo) ? "." : $" as '{memo}'.");
                }
            }
            string resultPrompt = $"Added {nAdded} file(s)." +
                                  linkResult;

            Messenger.Show(resultPrompt, caption);
            DialogResult = DialogResult.OK;
            Close();
        }
Пример #23
0
        public FileDbConnection(ConnectionProvider provider)
        {
            this.Provider         = provider;
            this.ConnectionString = Provider.ConnectionString;
            this.DataSource       = Provider.DataSource;
            this.database         = Provider.InitialCatalog;

            this.FileLink = (Provider as FileDbConnectionProvider).FileLink;
        }
Пример #24
0
            public static Fragment Parse(String type, JToken json)
            {
                switch (type)
                {
                case "StructuredText":
                    return(StructuredText.Parse(json));

                case "Image":
                    return(Image.Parse(json));

                case "Link.web":
                    return(WebLink.Parse(json));

                case "Link.document":
                    return(DocumentLink.Parse(json));

                case "Link.file":
                    return(FileLink.Parse(json));

                case "Link.image":
                    return(ImageLink.Parse(json));

                case "Text":
                    return(Text.Parse(json));

                case "Select":
                    return(Text.Parse(json));

                case "Date":
                    return(Date.Parse(json));

                case "Timestamp":
                    return(Timestamp.Parse(json));

                case "Number":
                    return(Number.Parse(json));

                case "Color":
                    return(Color.Parse(json));

                case "Embed":
                    return(Embed.Parse(json));

                case "GeoPoint":
                    return(GeoPoint.Parse(json));

                case "Group":
                    return(Group.Parse(json));

                case "SliceZone":
                    return(SliceZone.Parse(json));

                default:
                    return(json != null?Raw.Parse(json) : null);
                }
            }
Пример #25
0
        void AddFileLink(string fileName, bool keepSourceFile = true)
        {
            if (this.mySelectedNote == null)
            {
                return;
            }
            var noteAsLink = this.mySelectedNote as ILinkedItem;

            this.mySelectedDateilink = ModelManager.FileLinkService.AddFileLink(new FileInfo(fileName), noteAsLink, keepSourceFile);
        }
Пример #26
0
        public override int ExecuteNonQuery()
        {
            FileDbConnection connection = DbConnection as FileDbConnection;
            FileLink         link       = connection.FileLink;

            var       parser = new SqlClauseParser(connection.Provider, CommandText);
            SqlClause clause = parser.Parse();

            return(-1);
        }
Пример #27
0
 public void Add(FileLink fl)
 {
     foreach (FileLink fileLink in items)
     {
         if (fileLink.Name == fl.Name)
         {
             return;
         }
     }
     items.Add(fl);
 }
Пример #28
0
 public void Add(FileLink fl)
 {
     foreach (FileLink fileLink in items)
     {
         if (fileLink.Name == fl.Name)
         {
             return;
         }
     }
     items.Add(fl);
 }
Пример #29
0
        protected void EditItem(ProjectItem item)
        {
            projectItem = item;

            if (projectItem.FileLink != null)
            {
                FileLinkSelected = item.FileLink;
            }

            modeItem = Mode.Edit;
        }
Пример #30
0
        public FormFileAidViewFiles(int linkID)
        {
            InitializeComponent();

            myLink = LinkManager.GetLink(linkID);
            if (myLink == null)
            {
                return;
            }
            lblGroupName.Text = (string.IsNullOrEmpty(myLink.LinkMemo) ? "Unnamed Group" : myLink.LinkMemo);
        }
        public IFileLinkInfo MoveFile(FileLink source, FileLink destination, bool overwrite)
        {
            lock (File)
            {
                var stream = ReadFile(source);
                WriteFile(destination, stream, overwrite);
                DeleteFile(source);
            }

            return(GetFileInfo(destination.FullName));
        }
Пример #32
0
 public ActionResult FileLink(FileLink model)
 {
     var teacher = Academy.Current.GetTeacherById(SessionCache.CurrentUser.DbId);
      var resFile = Academy.Current.GetFileByTeacherId(teacher.Id, model.FileId);
      model.TeacherIds = new List<Guid> { teacher.Id };
      resFile.Links = model;
      Academy.Current.AddOrUpdate(teacher);
      //var file=teacher.Files.Where(f => f.Id == model.FileId).SingleOrDefault();
      return RedirectToAction("Files");
 }
		private IEnumerable<FileLink> SearchFileInFolder(FolderLink folderLink, string keyWord)
		{
			var fileList = new List<FileLink>();
			try
			{
				foreach (var subFolderPath in Directory.GetDirectories(folderLink.Path))
					if (!GlobalSettings.HiddenObjects.Any(item => subFolderPath.ToLower().Contains(item.ToLower())))
					{
						var subFolderLink = new FolderLink
						{
							RootId = folderLink.RootId,
							Path = subFolderPath
						};
						fileList.AddRange(SearchFileInFolder(subFolderLink, keyWord));
					}
			}
			catch { }
			try
			{
				foreach (var filePath in Directory.GetFiles(folderLink.Path, String.Format("*{0}*", keyWord)))
				{
					var lastWriteTime = File.GetLastWriteTime(filePath);
					if ((checkEditDateRange.Checked && (lastWriteTime < dateEditStartDate.DateTime || lastWriteTime > dateEditEndDate.DateTime)) ||
						GlobalSettings.HiddenObjects.Any(x => filePath.ToLower().Contains(x.ToLower())))
						continue;
					var fileLink = new FileLink
					{
						RootId = folderLink.RootId,
						Path = filePath
					};
					fileList.Add(fileLink);
				}
			}
			catch { }
			return fileList;
		}
		private void FillNode(TreeListNode node, bool showSubItems)
		{
			var folderLink = node.Tag as FolderLink;
			if (folderLink == null) return;
			if (node.Nodes.Count == 0)
			{
				try
				{
					TreeListNode childNode;
					try
					{
						var folders = new List<string>();
						folders.AddRange(Directory.GetDirectories(folderLink.Path));
						folders.Sort(WinAPIHelper.StrCmpLogicalW);
						foreach (var subFolder in folders)
						{
							if (!GlobalSettings.HiddenObjects.Any(x => subFolder.ToLower().Contains(x.ToLower())))
							{
								var subFolderLink = new FolderLink();
								subFolderLink.RootId = folderLink.RootId;
								subFolderLink.Path = subFolder;
								childNode = treeListAllFiles.AppendNode(new[] { subFolderLink.Name }, node, subFolderLink);
								childNode.StateImageIndex = 0;

								if (showSubItems)
									FillNode(childNode, showSubItems);
								if (showSubItems && childNode.Nodes.Count == 0)
									node.Nodes.Remove(childNode);
							}
						}
					}
					catch
					{
					}
					try
					{
						var files = new List<string>();
						files.AddRange(Directory.GetFiles(folderLink.Path));
						files.Sort(WinAPIHelper.StrCmpLogicalW);
						foreach (var file in Directory.GetFiles(folderLink.Path))
						{
							if (!GlobalSettings.HiddenObjects.Any(x => file.ToLower().Contains(x.ToLower())))
							{
								var fileLink = new FileLink();
								fileLink.RootId = folderLink.RootId;
								fileLink.Path = file;
								childNode =
									treeListAllFiles.AppendNode(
										new[] { String.Format("{0} ({1})", fileLink.Name, File.GetLastWriteTime(file).ToString("MM/dd/yy hh:mm tt")) },
										node, fileLink);
								childNode.StateImageIndex = GetImageindex(file);
							}
							Application.DoEvents();
						}
					}
					catch
					{
					}
				}
				catch
				{
				}
			}
			node.StateImageIndex = 1;
			node.Expanded = true;
		}
		private void ViewItem(FileLink file)
		{
			Utils.OpenFile(file.Path);
		}