示例#1
0
        internal string repairPage(string fileName, int page, string fileOut, EFileFormat format)
        {
            CiRepair repair = null;

            try
            {
                CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
                repair = ci.CreateRepair();
                repair.Image.Open(fileName, page);
                //  Demonstrates basic
                string s = "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
                repair.AutoDeskew(); s             = s + "AutoDeskew" + Environment.NewLine;
                repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
                //  Save results
                SavePage(ref s, repair.Image, fileOut, format);
                s = s + Environment.NewLine + "--------------" + Environment.NewLine;
                return(s);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                if (repair != null)
                {
                    repair.Image.Close();                  // ClearImage V9 and later.  Immediately free memory
                }
            }
        }
示例#2
0
        internal string repairStream(string fileName, string fileOut, EFileFormat format)
        {
            CiRepair repair = null;

            try
            {
                CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
                repair = ci.CreateRepair();
                using (MemoryStream ms = Utility.FileToStream(fileName))
                {
                    //  Read images from file
                    string s = "";
                    // Disable zone
                    int page = 1;
                    repair.Image.Open(ms, 1);
                    int cnt   = 0;
                    int pages = repair.Image.PageCount;
                    while (repair.Image.IsValid)
                    {
                        s = s + "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
                        repair.AutoDeskew(); s             = s + "AutoDeskew" + Environment.NewLine;
                        repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
#if false  // to write to multipage file
                        SavePage(ref s, repair.Image, fileOut, format);
#else      // save single page to file
                        MemoryStream msOut = repair.Image.SaveToStream(format);
                        if (msOut != null)
                        {
                            string pageOut =
                                Path.GetDirectoryName(fileOut) + @"\" +
                                Path.GetFileNameWithoutExtension(fileOut) +
                                ".page_" + page.ToString() +
                                Path.GetExtension(fileOut);
                            Utility.StreamToFile(msOut, pageOut);
                        }
#endif
                        page++;
                        if (page > pages)
                        {
                            break;
                        }
                        repair.Image.OpenPage(page);
                    }
                    s = s + Environment.NewLine;
                    return(s);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                if (repair != null)
                {
                    repair.Image.Close();                  // ClearImage V9 and later.  Immediately free memory
                }
            }
        }
示例#3
0
        internal string repairFile(string fileName, string fileOut, EFileFormat format)
        {
            CiRepair repair = null;

            try
            {
                CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
                repair = ci.CreateRepair();
                //  Read images from file
                string s = "";
                // Disable zone
                int page = 1;
                repair.Image.Open(fileName, 1);
                int cnt   = 0;
                int pages = repair.Image.PageCount;
                while (repair.Image.IsValid)
                {
                    s = s + "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
                    repair.AutoDeskew(); s             = s + "AutoDeskew" + Environment.NewLine;
                    repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
                    SavePage(ref s, repair.Image, fileOut, format);
                    page++;
                    if (page > pages)
                    {
                        break;
                    }
                    repair.Image.Open(fileName, page);
                }
                s = s + Environment.NewLine;
                return(s);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                if (repair != null)
                {
                    repair.Image.Close();                  // ClearImage V9 and later.  Immediately free memory
                }
            }
        }
示例#4
0
 private void SavePage(ref string s, CiImage image,
                       string fileOut, EFileFormat format)
 {
     // SaveAs and Append will change file name.
     //   OpenPage require original FileName.
     // To preserve  file name save Duplicate of the  image
     //       CiImage temp = image.Duplicate();
     if (fileOut != "")
     {
         if (File.Exists(fileOut))
         {
             image.Append(fileOut, format);
             s = s + "Append:" + fileOut + Environment.NewLine;
         }
         else
         {
             image.SaveAs(fileOut, format);
             s = s + "SaveAs:" + fileOut + Environment.NewLine;
         }
     }
     // temp.Close();
 }
        // Add a distribution in a graph to the database
        public async Task <List <Distribution> > AddDistribution(Graph g, int datasetId)
        {
            // Find the distribution subject uri
            IUriNode dcatDistribution = g.CreateUriNode("dcat:Distribution");

            String[]            distributionUris = findSubjectUri(g, dcatDistribution).Split(",");
            List <Distribution> distributions    = new List <Distribution>();

            foreach (String distributionUri in distributionUris)
            {
                Dictionary <string, string> attributes = getAttributesFromSubject(g, distributionUri);
                //Parse file format
                EFileFormat fileFormat       = EFileFormat.annet;
                String[]    fileFormatString = attributes.GetValueOrDefault("format", "annet").Split(",");
                try
                {
                    fileFormat = (EFileFormat)Enum.Parse(typeof(EFileFormat), fileFormatString[0], true);
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); }

                // Add relevant attributes to a new distribution
                Distribution distribution = new Distribution {
                    Title      = (string)attributes.GetValueOrDefault("title", attributes.GetValueOrDefault("description", "")),
                    Uri        = (string)attributes.GetValueOrDefault("accessURL", ""),
                    FileFormat = fileFormat,
                    DatasetId  = datasetId
                };

                // Add the dataset to the distribution
                await _distributionRepository.AddAsync(distribution);

                await _unitOfWork.CompleteAsync();

                distributions.Add(distribution);
            }
            return(distributions);
        }
示例#6
0
		/**
		set the workspace settings
		
		'workspaceRootPath_' specifies the file path of of the exported path of the workspace file which is configured in the workspace file(.workspace.xml), 
		it can be either an absolute path or relative to the current path.
		'format' specify the format to use, xml or bson, 
		
		the default format is xml.

		@return false if 'path' is not a valid path holding valid data
		*/
        public static bool SetWorkspaceSettings(string workspaceExportPath, EFileFormat format)
        {
            Debug.Check(!workspaceExportPath.EndsWith("\\"), "use '/' instead of '\\'");

			bool bFirstTime = string.IsNullOrEmpty(ms_workspaceExportPath);

            ms_workspaceExportPath = workspaceExportPath;

            if (!ms_workspaceExportPath.EndsWith("/"))
            {
                ms_workspaceExportPath += '/';
            }

            fileFormat_ = format;

            if (string.IsNullOrEmpty(ms_workspaceExportPath))
            {
                behaviac.Debug.LogError("No workspace file is specified!");
                behaviac.Debug.Check(false);

                return false;
            }

            LoadWorkspaceAbsolutePath();

            ms_deltaFrames = 1;

            //////////////////////////////////////////////////////////
			//only register metas and others at the 1st time
			if (bFirstTime)
			{
				behaviac.Details.RegisterCompareValue();
	            behaviac.Details.RegisterComputeValue();
	            behaviac.Workspace.RegisterBehaviorNode();
	            behaviac.Workspace.RegisterMetas();
			}

#if !BEHAVIAC_RELEASE
#if BEHAVIAC_HOTRELOAD
            // set the file watcher
            if (Config.IsDesktop)
            {
                if (FileFormat != EFileFormat.EFF_cs)
                {
                    if (ms_DirectoryMonitor == null)
                    {
                        ms_DirectoryMonitor = new DirectoryMonitor();
                        ms_DirectoryMonitor.Changed += new DirectoryMonitor.FileSystemEvent(OnFileChanged);
                    }

                    string filter = "*.*";
                    if (FileFormat == EFileFormat.EFF_xml)
                    {
                        filter = "*.xml";
                    }
                    else if (FileFormat == EFileFormat.EFF_bson)
                    {
                        filter = "*.bson.bytes";
                    }

                    ms_DirectoryMonitor.Start(workspaceExportPath, filter);
                }
            }
#endif//BEHAVIAC_HOTRELOAD

			
			SocketUtils.SendWorkspaceSettings();
#endif

            return true;
        }
示例#7
0
        public void HandleFileFormat(string fullPath, ref string ext, ref EFileFormat f)
        {
            if (f == EFileFormat.EFF_default)
            {
                // try to load the behavior in xml
                ext = ".xml";

                if (FileManager.Instance.FileExist(fullPath, ext))
                {
                    f = EFileFormat.EFF_xml;
                }
                else
                {
                    // try to load the behavior in bson
                    ext = ".bson";

                    if (FileManager.Instance.FileExist(fullPath, ext))
                    {
                        f = EFileFormat.EFF_bson;
                    }
                    else
                    {
                        // try to load the behavior in cs
                        f = EFileFormat.EFF_cs;
                    }
                }
            }
            else if (f == EFileFormat.EFF_xml || f == EFileFormat.EFF_cs)
            {
                ext = ".xml";
            }
            else if (f == EFileFormat.EFF_bson)
            {
                ext = ".bson";
            }

            //else if (f == EFileFormat.EFF_cs)
            //{
            //}
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ScreenSaveName"></param>
        /// <param name="ScreenTheme"></param>
        /// <param name="TraceName"></param>
        /// <param name="Filename"></param>
        public void MemoryHandling(string FolderLocation, bool enableFileSaving, string Filename,
                                   EFileFormat FileFormat, bool enableScreenSaving, string ScreenSaveName,
                                   EImageFormat ImageFormat, EScreenTheme ScreenTheme, bool enableTraceName,
                                   ETraceName TraceName, ETraceFormat TraceFormat, bool enableMarkerTable, bool enablePeakTable)
        {
            if (enableFileSaving)
            {
                string PathOfDataFile = FolderLocation + Filename + DateTime.Now.ToString("_yyyy-MM-dd_HH.mm.ss") + "." + FileFormat;
            }

            if (enableScreenSaving)
            {
                string PathOfScreenshot = FolderLocation + ScreenSaveName + DateTime.Now.ToString("_yyyy-MM-dd_HH.mm.ss") + "." + ImageFormat;
                ScpiCommand(":MMEMory:STORe:SCReen {0}", ScreenSaveName);
                ScpiCommand("*OPC");
                ScpiCommand(":MMEMory:STORe:SCReen:THEMe {0}", ScreenTheme);
                ScpiCommand("*OPC");
            }

            string PathOfTrace = "";

            if (enableTraceName)
            {
                if (TraceFormat == ETraceFormat.csv)
                {
                    switch (TraceName)
                    {
                    case ETraceName.TRACE1:
                    case ETraceName.TRACE2:
                    case ETraceName.TRACE3:
                    case ETraceName.TRACE4:
                    case ETraceName.TRACE5:
                    case ETraceName.TRACE6:
                        PathOfTrace = FolderLocation + TraceName + DateTime.Now.ToString("_yyyy-MM-dd_HH.mm.ss") + ".csv";
                        ScpiCommand(":MMEMory:STORe:TRACe:DATA {0},{1}", TraceName, Filename);
                        ScpiCommand("*OPC");
                        break;

                    case ETraceName.ALL:
                        for (var i = 1; i <= 6; i++)
                        {
                            PathOfTrace = FolderLocation + TraceName + DateTime.Now.ToString("_yyyy-MM-dd_HH.mm.ss") + ".csv";
                            ScpiCommand(":MMEMory:STORe:TRACe:DATA {0},{1}", TraceName, Filename);
                            ScpiCommand("*OPC");
                        }
                        break;
                    }
                }
                else if (TraceFormat == ETraceFormat.trace)
                {
                    PathOfTrace = FolderLocation + TraceName + DateTime.Now.ToString("_yyyy-MM-dd_HH.mm.ss") + ".trace";
                    ScpiCommand(":MMEMory:STORe:TRACe {0},{1}", TraceName, Filename);
                    ScpiCommand("*OPC");
                }
            }

            if (enableMarkerTable)
            {
                string FilePathName = FolderLocation + "Marker_Table" + DateTime.Now.ToString("_yyyy-MM-dd_HH.mm.ss") + ".csv";
                ScpiCommand(":MMEMory:STORe:RESults:MTABle {0}", FilePathName);
            }
            if (enablePeakTable)
            {
                string FilePathName = FolderLocation + "Peak_Table" + TraceName + DateTime.Now.ToString("_yyyy-MM-dd_HH.mm.ss") + ".csv";
                ScpiCommand(":MMEMory:STORe:RESults:PTABle {0}", FilePathName);
            }

            // ScpiCommand(":MMEMory:STORe:RESults:SPECtrogram {0}", Filename);
        }
        public static bool SetWorkspaceSettings(string workspaceExportPath, EFileFormat format)
        {
            Debug.Check(!workspaceExportPath.EndsWith("\\"), "use '/' instead of '\\'");

            bool bFirstTime = string.IsNullOrEmpty(ms_workspaceExportPath);

            ms_workspaceExportPath = workspaceExportPath;

            if (!ms_workspaceExportPath.EndsWith("/"))
            {
                ms_workspaceExportPath += '/';
            }

            fileFormat_ = format;

            if (string.IsNullOrEmpty(ms_workspaceExportPath))
            {
                behaviac.Debug.LogError("No workspace file is specified!");
                behaviac.Debug.Check(false);

                return false;
            }

            LoadWorkspaceAbsolutePath();

            ms_deltaFrames = 1;

            //////////////////////////////////////////////////////////
            //only register metas and others at the 1st time
            if (bFirstTime)
            {
                behaviac.Details.RegisterCompareValue();
                behaviac.Details.RegisterComputeValue();
                behaviac.Workspace.RegisterBehaviorNode();
                behaviac.Workspace.RegisterMetas();
            }

            return true;
        }
示例#10
0
 private void SavePage(ref string s, CiImage image,
     string fileOut, EFileFormat format)
 {
     // SaveAs and Appned will change file name.
         //   OpenPage require original FileName.
         // To preserve  file name save Duplicate of the  image
      //       CiImage temp = image.Duplicate();
     if (fileOut != "")
     {
         if (File.Exists(fileOut))
         {
             image.Append(fileOut, format);
             s = s + "Append:" + fileOut + Environment.NewLine;
         }
         else
         {
             image.SaveAs(fileOut, format);
             s = s + "SaveAs:" + fileOut + Environment.NewLine;
         }
     }
     // temp.Close();
 }
示例#11
0
        internal string Repair_Stream(string fileName, string fileOut, EFileFormat format)
        {
            MemoryStream ms = Utility.FileToStream(fileName);
            CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
            CiRepair repair = ci.CreateRepair();
            //  Read images from file
            string s = "";
            // Disable zone
            int page = 1;
            repair.Image.Open(ms, 1);
            int cnt = 0;
            int pages = repair.Image.PageCount;
            while (repair.Image.IsValid)
            {
                s = s + "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
                repair.AutoDeskew(); s = s + "AutoDeskew" + Environment.NewLine;
                repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
            #if false  // to write to multipage file
               SavePage(ref s, repair.Image, fileOut, format);
            #else       // save single page to file
                MemoryStream msOut = repair.Image.SaveToStream(format);
                if (msOut != null)
                    {
                        string pageOut =
                            Path.GetDirectoryName(fileOut) + @"\" +
                            Path.GetFileNameWithoutExtension(fileOut) +
                            ".page_" + page.ToString() +
                            Path.GetExtension(fileOut);

                    Utility.StreamToFile(msOut, pageOut);
                    }
            #endif
                page++;
                if (page > pages)
                    break;
                repair.Image.OpenPage(page);
            }
            s = s + Environment.NewLine;

               return s;
        }
示例#12
0
 internal string Repair_Page(string fileName, int page, string fileOut, EFileFormat format)
 {
     string s = "";
     CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
     CiRepair repair = ci.CreateRepair();
     repair.Image.Open(fileName, page);
     //  Demonstates basic
     s = s + "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
     repair.AutoDeskew(); s = s + "AutoDeskew" + Environment.NewLine;
     repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
     //  Save results
     SavePage(ref s, repair.Image, fileOut, format);
     s = s + Environment.NewLine + "--------------" + Environment.NewLine;
     return s;
 }
示例#13
0
 internal string Repair_File(string fileName, string fileOut, EFileFormat format)
 {
     CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
     CiRepair repair  = ci.CreateRepair();
     //  Read images from file
     string s = "";
     // Disable zone
     int page = 1;
     repair.Image.Open(fileName, 1);
     int cnt = 0;
     int  pages = repair.Image.PageCount;
     while (repair.Image.IsValid)
     {
         s = s + "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
         repair.AutoDeskew(); s = s + "AutoDeskew" + Environment.NewLine;
         repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
         SavePage(ref s, repair.Image, fileOut, format);
         page++;
         if (page > pages)
             break;
         repair.Image.Open(fileName, page);
     }
     s = s + Environment.NewLine;
     return s;
 }