public void emdashnospace()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };

            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper                         = _TestSingleTon.Zipper;
            result.FancyCharacters                = true;
            result.RemoveTabs                     = false;
            result.SceneBreakHasTab               = true;
            result.OverrideStyleSheet             = @"C:\Users\Public\Documents\YourOtherMind\YourOtherMind\files\SendTextAwayControlFiles\stylesheet.css";
            result.NovelMode                      = true;
            result.ChapterTitleOffset             = -2;
            result.UnderlineShouldBeItalicInstead = true;
            result.ArealValidatorSafe_Align       = true;
            result.ConvertToEmDash                = true;
            result.Emdash_removespacesbeforeafter = true;


            PerformTest("emdashnospace.txt", result);
        }
        public void BetterAlign()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };

            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper                   = _TestSingleTon.Zipper;
            result.FancyCharacters          = true;
            result.RemoveTabs               = false;
            result.SceneBreakHasTab         = true;
            result.OverrideStyleSheet       = @"C:\Users\Public\Documents\YourOtherMind\YourOtherMind\files\SendTextAwayControlFiles\stylesheet.css";
            result.NovelMode                = true;
            result.ArealValidatorSafe_Align = true;

            PerformTest("betteralign.txt", result, "", "Chapter_1");
        }
        public void ChatMode()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };

            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper          = _TestSingleTon.Zipper;
            result.FancyCharacters = true;


            result.ChatMode = 0;
            PerformTest("chatmode.txt", result);
            result.ChatMode = 1;
            PerformTest("chatmode.txt", result, "chatmodeitalic.txt", "");
            result.ChatMode = 2;
            PerformTest("chatmode.txt", result, "chatmodebold.txt", "");
        }
        protected override void GivenThat()
        {
            base.GivenThat();

            Podcasts = new List <PodcastInfo>(10);

            ControlFile = GenerateMock <IReadOnlyControlFile>();
            ControlFile.Stub(ctrl => ctrl.GetSourceRoot()).Return("c:\\source");
            ControlFile.Stub(ctrl => ctrl.GetDestinationRoot()).Return("c:\\destination");
            ControlFile.Stub(ctrl => ctrl.GetPodcasts()).Return(Podcasts);
            ControlFile.Stub(ctrl => ctrl.GetPlaylistFileName()).Return("MyPodcasts.wpl");

            Finder        = GenerateMock <IFinder>();
            FileUtilities = GenerateMock <IFileUtilities>();
            PathUtilities = GenerateMock <IPathUtilities>();

            PathUtilities.Stub(utilities => utilities.GetFullPath("c:\\destination"))
            .Return("c:\\destination");

            PathUtilities.Stub(utilities => utilities.GetTempFileName())
            .Return("c:\\file.tmp");

            Playlist = GenerateMock <IPlaylist>();
            Factory  = GenerateMock <IPlaylistFactory>();
            Factory.Stub(factory => factory.CreatePlaylist(PlaylistFormat.WPL, null)).IgnoreArguments().Return(Playlist);

            PlaylistGenerator = new Generator(Finder, FileUtilities, PathUtilities, Factory);
        }
        public void fancysectionbreak()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };

            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper                   = _TestSingleTon.Zipper;
            result.FancyCharacters          = false;
            result.RemoveTabs               = false;
            result.SceneBreakHasTab         = true;
            result.OverrideStyleSheet       = @"C:\Users\Public\Documents\YourOtherMind\YourOtherMind\files\SendTextAwayControlFiles\stylesheet.css";
            result.NovelMode                = true;
            result.ArealValidatorSafe_Align = true;
            result.CustomEllip              = true;
            result.Overridesectionbreak     = "src=\".\\images\\fleuron.png\" height=\"39px\" width=\"100px\"";

            PerformTest("fancysectionbreak.txt", result);
        }
Example #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(ControlFile) ||
         String.IsNullOrEmpty(ControlFile.Split('.')[0]) ||
         !File.Exists(Widgethelper.GetDataControlPath(ControlFile)))
     {
         Response.Write("<p style='font-size:14px;color:red'>找不到控件的配置文件,请确认控件是否存在或控件标签格式是否正确!</p>");
         Response.End();
     }
 }
Example #7
0
 public void ItShouldReadTheGlobalInformation()
 {
     Assert.That(ControlFile.GetRetryWaitInSeconds(), Is.EqualTo(77));
     Assert.That(ControlFile.GetMaximumNumberOfConcurrentDownloads(), Is.EqualTo(10));
     Assert.That(ControlFile.GetSourceRoot(), Is.EqualTo(".\\profile\\iPodder\\downloads"));
     Assert.That(ControlFile.GetDestinationRoot(), Is.EqualTo("W:\\Podcasts"));
     Assert.That(ControlFile.GetPlaylistFileName(), Is.EqualTo("podcasts.wpl"));
     Assert.That(ControlFile.GetFreeSpaceToLeaveOnDestination(), Is.EqualTo(2000));
     Assert.That(ControlFile.GetFreeSpaceToLeaveOnDownload(), Is.EqualTo(3000));
     Assert.That(ControlFile.GetPlaylistFormat(), Is.EqualTo(PlaylistFormat.WPL));
 }
Example #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(ControlFile) ||
         String.IsNullOrEmpty(ControlFile.Split('.')[0]) || (
             !File.Exists(HttpContext.Current.Server.MapPath(ControlFile)) &&
             !File.Exists(Path.Combine(DataControlHelper.GetDataControlPath(ControlFile.Split('.')[0]), Constants.We7ControlConfigFile))))
     {
         Response.Write("<p style='font-size:14px;color:red'>找不到控件的配置文件,请确认控件是否存在或控件标签格式是否正确!</p>");
         Response.End();
     }
 }
 public void ItShouldReadPodcast1()
 {
     Assert.That(ControlFile.GetPodcasts().ElementAt(0).Feed, Is.Null);
     Assert.That(ControlFile.GetPodcasts().ElementAt(0).Folder, Is.EqualTo("Test Match Special"));
     Assert.That(ControlFile.GetPodcasts().ElementAt(0).MaximumNumberOfFiles.Value, Is.EqualTo(987));
     Assert.That(ControlFile.GetPodcasts().ElementAt(0).Pattern.Value, Is.EqualTo("*.xyz"));
     Assert.That(ControlFile.GetPodcasts().ElementAt(0).SortField.Value, Is.EqualTo(PodcastFileSortField.FileName));
     Assert.That(ControlFile.GetPodcasts().ElementAt(0).AscendingSort.Value, Is.True);
     Assert.That(ControlFile.GetPodcasts().ElementAt(0).PostDownloadCommand, Is.Null);
     Assert.That(ControlFile.GetPodcasts().ElementAt(0).DeleteEmptyFolder.Value, Is.False);
 }
        protected override void GivenThat()
        {
            base.GivenThat();

            var podcast1 = new PodcastInfo(ControlFile)
            {
                Folder = "pod1"
            };

            podcast1.Pattern.Value = "*.mp3";
            podcast1.MaximumNumberOfFiles.Value = 2;
            podcast1.AscendingSort.Value        = true;
            podcast1.DeleteEmptyFolder.Value    = true;
            podcast1.SortField.Value            = PodcastFileSortField.FileName;

            var podcast2 = new PodcastInfo(ControlFile)
            {
                Folder = "AnotherPodcast"
            };

            podcast2.Pattern.Value = "*.wma";
            podcast2.MaximumNumberOfFiles.Value = 3;
            podcast2.AscendingSort.Value        = false;
            podcast2.DeleteEmptyFolder.Value    = false;
            podcast2.SortField.Value            = PodcastFileSortField.CreationTime;

            PodcastFiles1 = new List <IFileInfo> {
                GenerateMock <IFileInfo>(), GenerateMock <IFileInfo>()
            };
            PodcastFiles2 = new List <IFileInfo> {
                GenerateMock <IFileInfo>(), GenerateMock <IFileInfo>(), GenerateMock <IFileInfo>()
            };

            ControlFile.Stub(c => c.GetPodcasts())
            .Return(new List <PodcastInfo> {
                podcast1, podcast2
            });

            ControlFile.Stub(c => c.GetSourceRoot())
            .Return(@"c:\media\blah");
            ControlFile.Stub(c => c.GetDestinationRoot())
            .Return(@"k:\podcasts");
            ControlFile.Stub(c => c.GetFreeSpaceToLeaveOnDestination())
            .Return(500);

            FileFinder.Stub(f => f.GetFiles(@"c:\media\blah\pod1", "*.mp3", 2, PodcastFileSortField.FileName, true))
            .Return(PodcastFiles1);
            FileFinder.Stub(f => f.GetFiles(@"c:\media\blah\AnotherPodcast", "*.wma", 3, PodcastFileSortField.CreationTime, false))
            .Return(PodcastFiles2);

            FileCopier.Stub(c => c.CopyFilesToTarget(null, null, null, 0, false))
            .IgnoreArguments()
            .WhenCalled(invocation => FilesToCopy = (List <FileSyncItem>)invocation.Arguments[0]);
        }
 public void ItShouldReadPodcast2()
 {
     Assert.That(ControlFile.GetPodcasts().ElementAt(1).Feed.Address.ToString(), Is.EqualTo("http://www.hanselminutes.com/hanselminutes_MP3Direct.xml"));
     Assert.That(ControlFile.GetPodcasts().ElementAt(1).Folder, Is.EqualTo("Hanselminutes"));
     Assert.That(ControlFile.GetPodcasts().ElementAt(1).MaximumNumberOfFiles.Value, Is.EqualTo(34));
     Assert.That(ControlFile.GetPodcasts().ElementAt(1).Pattern.Value, Is.EqualTo("*.mp3"));
     Assert.That(ControlFile.GetPodcasts().ElementAt(1).SortField.Value, Is.EqualTo(PodcastFileSortField.FileName));
     Assert.That(ControlFile.GetPodcasts().ElementAt(1).AscendingSort.Value, Is.False);
     Assert.That(ControlFile.GetPodcasts().ElementAt(1).PostDownloadCommand.Command.Value, Is.EqualTo("different command"));
     Assert.That(ControlFile.GetPodcasts().ElementAt(1).DeleteEmptyFolder.Value, Is.True);
 }
 protected override void When()
 {
     ThrownException = null;
     try
     {
         FreeSpaceToLeave = ControlFile.GetFreeSpaceToLeaveOnDestination();
     }
     catch (Exception exception)
     {
         ThrownException = exception;
     }
 }
        // each test should hapepn in its own otuput directory
        public ControlFile Setup(string uniquetestdirectory, ControlFile overrideControl)
        {
            // deletes contents of the output folder
            string path = Environment.CurrentDirectory;

            PathToSendAwayUnitTestingFIles = Path.Combine(path, "SendAwayUnitTestingFiles");
            PathToSendTextAwayFiles        = _TestSingleTon.PathToSendAwayEPUBTemplates;
            PathToOutput = Path.Combine(PathToSendAwayUnitTestingFIles, "output");

            string code = uniquetestdirectory;

            PathToOutput = Path.Combine(PathToOutput, code);
            PathToProper = Path.Combine(PathToSendAwayUnitTestingFIles, "proper");

            if (Directory.Exists(PathToOutput))
            {
                Directory.Delete(PathToOutput, true);
            }

            Directory.CreateDirectory(PathToOutput);

            if (Directory.Exists(PathToSendAwayUnitTestingFIles) == false || Directory.Exists(PathToSendTextAwayFiles) == false || Directory.Exists(PathToOutput) == false)
            {
                throw new Exception("not all paths defined");
            }
            //tests for existence of needed debug folders

            // Sets up a proper epub control file
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };
            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper = _TestSingleTon.Zipper;

            if (overrideControl != null)
            {
                result = overrideControl;
            }
            result.OutputDirectory   = PathToOutput;
            result.TemplateDirectory = PathToSendTextAwayFiles;
            return(result);
        }
Example #14
0
 private bool TryExportToCOMTRADE(string filePath, ControlFile controlFile, string identityString, List <ANLG_CHNL_NEW> analogChannels, List <EVNT_CHNL_NEW> digitalChannels)
 {
     try
     {
         ExportToCOMTRADE(filePath, controlFile, identityString, analogChannels, digitalChannels);
         return(true);
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         return(false);
     }
 }
Example #15
0
        /// <summary>
        /// Generate control file
        /// </summary>
        private void GenerateControlFile()
        {
            string strPageID;
            string strDefaultLayout;
            string strPageLayout;
            string strPageType;

            ArrayList objPages = new ArrayList();


            //1. Get the required data
            strDefaultLayout = lstDefaultLayout.SelectedValue;

            foreach (DataGridItem dgrItem in dgrPages.Items)
            {
                ListBox lstLayout   = (ListBox)dgrItem.FindControl("lstPageLayout");
                Literal litPageID   = (Literal)dgrItem.FindControl("litPageID");
                Literal litPageType = (Literal)dgrItem.FindControl("litPageType");

                // Get the page layout value
                strPageLayout = lstLayout.SelectedValue;
                strPageID     = litPageID.Text;
                strPageType   = litPageType.Text;

                // If layout contains the '-- Use Default--' stlye entry then use the page level entry
                if (strPageLayout == cm_strDefault)
                {
                    strPageLayout = strDefaultLayout;
                }

                objPages.Add(new ControlFilePage(strPageID, strPageLayout, strPageType));
            }

            //2. Populate the control file
            ControlFile objControlFile = new ControlFile(objPages);

            objControlFile.DefaultLayout = strDefaultLayout;
            objControlFile.Style         = lstStyle.SelectedValue;

            //3. Serialize the control class to Xml file
            XmlSerializer objSer        = new XmlSerializer(objControlFile.GetType());
            FileStream    fsControlFile = new FileStream(lblGeneratePath.Text + "\\Control.xml", FileMode.Create, FileAccess.Write, FileShare.ReadWrite);

            objSer.Serialize(fsControlFile, objControlFile);

            // Flush close and quit
            fsControlFile.Flush();
            fsControlFile.Close();
        }
Example #16
0
        private async void ReceiveSurveys()
        {
            SurveysServices S_S1        = new SurveysServices();
            ControlFile     controlFile = new ControlFile();
            string          username    = await controlFile.GetUserName();

            S_S1.Set_UrlApi("ReceiveSurveysShared/" + username);
            List <Survey> ReceivedSurveys = await S_S1.GetSurveysAsync();

            ExistenceCheckResult result = await folder.CheckExistsAsync("Receivedsurveys");

            if (result == ExistenceCheckResult.FolderExists)
            {
                folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists);

                file = await folder.CreateFileAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists);

                string Content = await file.ReadAllTextAsync();

                List <Survey> OldreceiveSurveys = Serializable_Survey.deserialize(Content).ToList();
                if (OldreceiveSurveys.Count < ReceivedSurveys.Count)
                {
                    var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
                    player.Load("NotificationReceive.mp3");
                    player.Play();

                    Plugin.LocalNotifications.CrossLocalNotifications.Current.Show(Lang.Resource.receivesurveys, Lang.Resource.BodyreceiveSurvey, 0);
                }
            }
            else if (result != ExistenceCheckResult.FolderExists && ReceivedSurveys.Count > 0)
            {
                var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
                player.Load("NotificationReceive.mp3");
                player.Play();

                Plugin.LocalNotifications.CrossLocalNotifications.Current.Show(Lang.Resource.receivesurveys, Lang.Resource.BodyreceiveSurvey, 0);
            }
            folder = FileSystem.Current.LocalStorage;
            folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.ReplaceExisting);

            file = await folder.CreateFileAsync("Receivedsurveys", CreationCollisionOption.ReplaceExisting);

            string content = Serializable_Survey.serialize(ReceivedSurveys);
            await file.WriteAllTextAsync(content);
        }
        void PerformTest(string simpletxt, ControlFile overrideControl, string overrideoutput, string overridepreface)
        {
            ControlFile Controller = Setup(simpletxt, overrideControl);
            string      Incoming   = simpletxt;



            string FileToTest = Path.Combine(PathToSendAwayUnitTestingFIles, Incoming);

            sendePub2 SendAwayIt = new sendePub2();

            SendAwayIt.SuppressMessages = true;
            SendAwayIt.WriteText(FileToTest, Controller, -1);


            string FileOutput = Path.Combine(PathToOutput, sendePub2.GetDateDirectory);

            FileOutput = Path.Combine(FileOutput, "oebps");
            if (overridepreface == "")
            {
                FileOutput = Path.Combine(FileOutput, "preface.xhtml");
            }
            else
            {
                FileOutput = Path.Combine(FileOutput, overridepreface + ".xhtml");
            }

            Assert.True(File.Exists(FileOutput), "NOt found " + FileOutput);

            if (overrideoutput != "")
            {
                Incoming = overrideoutput;
            }

            // now test the file for identicality
            string FileToCompareItTo = Path.Combine(PathToProper, Incoming);

            if (File.Exists(FileToCompareItTo) == false)
            {
                throw new Exception("The file does not exist : " + FileToCompareItTo);
            }
            int differences = CompareTwoFiles(FileToCompareItTo, FileOutput);

            Assert.AreEqual(0, differences, "Differences Found " + differences);
        }
        public void Fancy()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };
            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper          = _TestSingleTon.Zipper;
            result.FancyCharacters = true;
            PerformTest("fancycharacters.txt", result);
        }
        protected override void GivenThat()
        {
            base.GivenThat();

            ViewModel.Podcasts.Add(new PodcastViewModel(null));

            BrowseForFileService.Stub(s => s.BrowseForFileToOpen("Control Files|*.xml"))
            .Return(@"C:\blah\test.xml");

            ControlFileFactory.Stub(f => f.OpenControlFile(@"C:\blah\test.xml"))
            .Return(ControlFile);

            Podcasts = new List <PodcastInfo>
            {
                new PodcastInfo(ControlFile),
                new PodcastInfo(ControlFile),
                new PodcastInfo(ControlFile)
            };
            ControlFile.Stub(f => f.GetPodcasts())
            .Return(Podcasts);
        }
        public void ReplaceParagraphTags()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };
            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper                   = _TestSingleTon.Zipper;
            result.FancyCharacters          = false;
            result.ConvertToEmDash          = true;
            result.EpubRemoveDoublePageTags = true;
            PerformTest("replaceparagraphtags.txt", result);
        }
        public void Novel_factafterscene_WITHOUTCOMMA()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };

            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper          = _TestSingleTon.Zipper;
            result.FancyCharacters = true;
            result.NovelMode       = true;

            PerformTest("novel_factaftersceneWITHOUTCOMMA.txt", result);
        }
        public void novel_fact_endoflinehyphen()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };
            result.ConvertToEmDash  = true;
            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper          = _TestSingleTon.Zipper;
            result.FancyCharacters = true;
            result.NovelMode       = true;

            PerformTest("novel_fact_endoflinehyphen.txt", result);
        }
        public void Novel_Open_Blanklinke()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };

            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper          = _TestSingleTon.Zipper;
            result.FancyCharacters = true;
            result.NovelMode       = true;

            PerformTest("novel_open_blank_error.txt", result);
        }
        public void novel_inlinep()
        {
            ControlFile result = ControlFile.Default;



            result.ListOfTags = new string[1] {
                "game|''"
            };

            result.ConverterType    = ControlFile.convertertype.epub;
            result.MultiLineFormats = new string[1] {
                "past"
            };
            result.MultiLineFormatsValues = new string[1] {
                "blockquote2"
            };
            result.Zipper          = _TestSingleTon.Zipper;
            result.FancyCharacters = true;
            result.NovelMode       = true;

            PerformTest("novel_inlinep.txt", result, "", "Chapter_1");
        }
Example #25
0
 protected override void When()
 {
     PlaylistGenerator.GeneratePlaylist(ControlFile, ControlFile.GetSourceRoot(), true, null);
 }
Example #26
0
        private void ExportToCOMTRADE(string filePath, ControlFile controlFile, string identityString, List <ANLG_CHNL_NEW> analogChannels, List <EVNT_CHNL_NEW> digitalChannels)
        {
            string assetKey       = GetMeterKey(filePath, m_filePattern) ?? ThreadContext.Properties["Meter"].ToString();
            string rootFileName   = FilePath.GetFileNameWithoutExtension(filePath);
            string directoryPath  = Path.Combine(m_emaxSettings.COMTRADEExportDirectory, assetKey);
            string schemaFilePath = Path.Combine(directoryPath, $"{rootFileName}.cfg");
            string dataFilePath   = Path.Combine(directoryPath, $"{rootFileName}.dat");
            Schema comtradeSchema = new Schema();

            if (File.Exists(dataFilePath))
            {
                return;
            }

            comtradeSchema.StationName              = Regex.Replace(identityString, @"[\r\n]", "");
            comtradeSchema.Version                  = 2013;
            comtradeSchema.AnalogChannels           = new AnalogChannel[controlFile.AnalogChannelCount];
            comtradeSchema.DigitalChannels          = new DigitalChannel[controlFile.EventChannelSettings.Count];
            comtradeSchema.SampleRates              = new SampleRate[1];
            comtradeSchema.SampleRates[0].Rate      = controlFile.SystemParameters.samples_per_second;
            comtradeSchema.SampleRates[0].EndSample = controlFile.SystemParameters.rcd_sample_count - 1;
            comtradeSchema.StartTime                = new Timestamp()
            {
                Value = m_meterDataSet.DataSeries[1][0].Time
            };

            int triggerIndex = controlFile.SystemParameters.start_offset_samples + controlFile.SystemParameters.prefault_samples;

            comtradeSchema.TriggerTime = new Timestamp()
            {
                Value = m_meterDataSet.DataSeries[1][triggerIndex].Time
            };

            for (int i = 0; i < analogChannels.Count; i++)
            {
                ANLG_CHNL_NEW analogChannel  = analogChannels[i];
                AnalogChannel comtradeAnalog = new AnalogChannel();
                DataSeries    channelData    = m_meterDataSet.DataSeries[i + 1];

                double unitMultiplier = 1.0D;
                double max            = channelData.Maximum;
                double min            = channelData.Minimum;
                double num;

                comtradeAnalog.Index = i + 1;
                comtradeAnalog.Name  = analogChannel.title;

                comtradeAnalog.Units = new Func <string, string>(type =>
                {
                    switch (type)
                    {
                    case "V": return("kVAC");

                    case "A": return("kAAC");

                    case "v": return(" VDC");

                    default: return(type);
                    }
                })(analogChannel.type);

                if (analogChannel.type.All(char.IsUpper))
                {
                    unitMultiplier = 0.001D;
                    max           *= unitMultiplier;
                    min           *= unitMultiplier;
                }

                comtradeAnalog.Multiplier     = (max - min) / (2 * short.MaxValue);
                comtradeAnalog.Adder          = (max + min) / 2.0D;
                comtradeAnalog.PrimaryRatio   = double.TryParse(analogChannel.primary, out num) ? num * unitMultiplier : 0.0D;
                comtradeAnalog.SecondaryRatio = double.TryParse(analogChannel.secondary, out num) ? num * unitMultiplier : 0.0D;

                comtradeSchema.AnalogChannels[i] = comtradeAnalog;
            }

            for (int i = 0; i < digitalChannels.Count; i++)
            {
                EVNT_CHNL_NEW  digitalChannel  = digitalChannels[i];
                DigitalChannel comtradeDigital = new DigitalChannel();
                comtradeDigital.Index             = i + 1;
                comtradeDigital.ChannelName       = digitalChannel.e_title;
                comtradeSchema.DigitalChannels[i] = comtradeDigital;
            }

            Directory.CreateDirectory(directoryPath);
            File.WriteAllText(schemaFilePath, comtradeSchema.FileImage, Encoding.ASCII);

            using (FileStream stream = File.OpenWrite(dataFilePath))
            {
                const int DigitalSize = sizeof(ushort) * 8;

                IEnumerable <DataSeries> digitalWords = m_meterDataSet.Digitals.Skip(1)
                                                        .Select((dataSeries, index) => dataSeries.Multiply(Math.Pow(2.0D, DigitalSize - (index % DigitalSize) - 1)))
                                                        .Select((DataSeries, Index) => new { DataSeries, Index })
                                                        .GroupBy(obj => obj.Index / DigitalSize)
                                                        .Select(grouping => grouping.Select(obj => obj.DataSeries))
                                                        .Select(grouping => grouping.Aggregate((sum, series) => sum.Add(series)));

                List <DataSeries> allChannels = m_meterDataSet.DataSeries.Skip(1)
                                                .Select((dataSeries, index) => analogChannels[index].type.All(char.IsUpper) ? dataSeries.Multiply(0.001D) : dataSeries)
                                                .Concat(digitalWords)
                                                .ToList();

                for (int i = 0; i < m_meterDataSet.DataSeries[1].DataPoints.Count; i++)
                {
                    DateTime timestamp = m_meterDataSet.DataSeries[1][i].Time;

                    double[] values = allChannels
                                      .Select(dataSeries => dataSeries[i].Value)
                                      .ToArray();

                    Writer.WriteNextRecordBinary(stream, comtradeSchema, timestamp, values, (uint)i, false);
                }
            }
        }
Example #27
0
        public void Parse(string filePath)
        {
            ControlFile controlFile    = m_parser.ControlFile;
            string      identityString = controlFile.IdentityString.value;
            string      deviceName     = identityString.Substring(0, IndexOf(identityString, "\r\n", "\n", "\r"));

            Meter meter = new Meter();

            meter.Location  = new Location();
            meter.Channels  = new List <Channel>();
            meter.AssetKey  = deviceName;
            meter.Name      = deviceName;
            meter.ShortName = deviceName.Substring(0, Math.Min(deviceName.Length, 50));

            Location meterLocation = meter.Location;

            meterLocation.Meters = new List <Meter>()
            {
                meter
            };
            meterLocation.LocationKey = deviceName;
            meterLocation.Name        = deviceName;
            meterLocation.ShortName   = meter.ShortName;
            meterLocation.Description = deviceName;

            List <ANLG_CHNL_NEW> analogChannels = controlFile.AnalogChannelSettings
                                                  .OrderBy(kvp => kvp.Key)
                                                  .Select(kvp => kvp.Value)
                                                  .ToList();

            List <EVNT_CHNL_NEW> digitalChannels = controlFile.EventChannelSettings
                                                   .OrderBy(kvp => kvp.Key)
                                                   .Select(kvp => kvp.Value)
                                                   .ToList();

            // Add an empty data series for 1-based indexing
            m_meterDataSet.DataSeries.Add(new DataSeries());
            m_meterDataSet.Digitals.Add(new DataSeries());

            foreach (ANLG_CHNL_NEW analogChannel in analogChannels)
            {
                Channel channel = ParseSeries(analogChannel);
                channel.Meter = meter;
                channel.Series.Single().SourceIndexes = m_meterDataSet.DataSeries.Count.ToString();

                DataSeries dataSeries = new DataSeries();
                dataSeries.SeriesInfo = channel.Series[0];

                meter.Channels.Add(channel);

                m_meterDataSet.DataSeries.Add(dataSeries);
            }

            foreach (EVNT_CHNL_NEW digitalChannel in digitalChannels)
            {
                Channel channel = ParseSeries(digitalChannel);
                channel.Series.Single().SourceIndexes = m_meterDataSet.Digitals.Count.ToString();

                DataSeries series = new DataSeries();
                series.SeriesInfo = channel.Series[0];

                meter.Channels.Add(channel);

                m_meterDataSet.Digitals.Add(series);
            }

            while (m_parser.ReadNext())
            {
                DateTime timestamp = m_emaxSettings.ApplyTimestampCorrection ? m_parser.CalculatedTimestamp : m_parser.ParsedTimestamp;

                for (int i = 0; i < analogChannels.Count; i++)
                {
                    double value = m_emaxSettings.ApplyValueCorrection ? m_parser.CorrectedValues[i] : m_parser.Values[i];
                    m_meterDataSet.DataSeries[i + 1].DataPoints.Add(new DataPoint()
                    {
                        Time = timestamp, Value = value
                    });
                }

                for (int i = 0; i < digitalChannels.Count; i++)
                {
                    int    bitCount   = sizeof(ushort) * 8;
                    int    groupIndex = i / bitCount;
                    int    bitIndex   = i % bitCount;
                    ushort mask       = (ushort)~(0x8000u >> bitIndex);
                    double value      = m_parser.EventGroups[groupIndex] & mask;
                    m_meterDataSet.Digitals[i + 1].DataPoints.Add(new DataPoint()
                    {
                        Time = timestamp, Value = value
                    });
                }
            }

            if (!string.IsNullOrEmpty(m_emaxSettings.COMTRADEExportDirectory))
            {
                TryExportToCOMTRADE(filePath, controlFile, identityString, analogChannels, digitalChannels);
            }

            m_meterDataSet.Meter = meter;
        }
Example #28
0
        public void F_SaveLog()
        {
            //Read FILE LOG_Source
            v_FileInput = new DirectoryInfo(ConfigurationManager.AppSettings["PathInput"].ToString()).GetFiles().OrderByDescending(f => f.LastWriteTime).First();
            if (v_FileInput.Extension != ".csv")
            {
                return;
            }
            DataTable v_DT_Result = new DataTable();

            v_DT_Result.Columns.Add("Times", typeof(string));
            v_DT_Result.Columns.Add("Model", typeof(string));
            v_DT_Result.Columns.Add("Status", typeof(string));
            List <string> columns  = new List <string>();
            CsvFileReader v_Reader = WriteDatatableToFileCSV.ReadFile(v_FileInput.FullName);

            while (v_Reader.ReadRow(columns))
            {
                if (columns[0].Trim().Length > 0 && columns[1].Trim().Length > 0)
                {
                    DataRow v_Dr = v_DT_Result.NewRow();
                    v_Dr[0] = columns[1].Trim();
                    v_Dr[1] = columns[5].Trim();
                    v_Dr[2] = columns[3].Trim();
                    v_DT_Result.Rows.Add(v_Dr);
                }
            }
            v_Reader.Dispose();
            v_DT_Result.Rows.RemoveAt(0);
            v_DT_Result.Rows.RemoveAt(0);
            //Get PASS OR FAIL
            string v_Status  = "F";
            string v_Model   = string.Empty;
            string v_Serial  = string.Empty;
            string v_Station = string.Empty;

            //GET Model
            v_Model = v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][1].ToString().Trim().Split('_')[1];

            //GET Serial
            v_Serial = v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][1].ToString().Trim().Split('_')[0];

            //Get Status
            try
            {
                if (v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][2].ToString().Trim() == "OK")
                {
                    v_Status = "P";
                }
                else
                {
                    v_Status = "F";
                }
            }
            catch { v_Status = "F"; }

            //Get Station
            try
            {
                //v_Station = Cbx_Station.SelectedValue.ToString();
            }
            catch { }


            Tbx_BarCode.Text      = v_Serial + "_" + v_Model;
            Tbx_BarCode.ForeColor = Color.Green;
            string v_TimeCurrent = DateTime.Now.ToString("yyMMddHHmmss");
            string v_FileContent = v_Model + "|" + v_Serial + "_" + v_Model + "|" + v_TimeCurrent + "|" + v_Status + "|" + v_Station;

            //Delete OLD File log
            try
            {
                bool          v_StatusOld = false;
                List <string> v_ListPaths = Directory.GetFiles(ConfigurationManager.AppSettings["PathOutput"].ToString(), "*.txt", SearchOption.AllDirectories).ToList();
                string        v_PathPASS  = "";
                string        v_PathNG    = "";
                try
                {
                    v_PathPASS = v_ListPaths.Where(p => File.ReadAllLines(p).Any(line => line.IndexOf(v_Serial + "_" + v_Model) >= 0 && line.IndexOf("|P|") >= 0 && line.IndexOf(v_Station) >= 0)).First();
                }
                catch { }
                try
                {
                    v_PathNG = v_ListPaths.Where(p => File.ReadAllLines(p).Any(line => line.IndexOf(v_Serial + "_" + v_Model) >= 0 && line.IndexOf("|F|") >= 0 && line.IndexOf(v_Station) >= 0)).First();
                }
                catch { }
                if (v_PathPASS.Trim().Length > 0)
                {
                    ControlFile.F_DeleteFile(v_PathPASS);
                    v_Total = v_Total - 1;
                    if (v_Status == "P")
                    {
                        v_Pass = v_Pass - 1;
                    }
                    else if (v_Status == "F")
                    {
                        v_Pass = v_Pass - 1;
                        v_NG   = v_NG;
                    }
                    if (v_Total < 0)
                    {
                        v_Total = 0;
                    }
                    if (v_Pass < 0)
                    {
                        v_Pass = 0;
                    }
                    if (v_NG < 0)
                    {
                        v_NG = 0;
                    }
                }
                else if (v_PathNG.Trim().Length > 0)
                {
                    ControlFile.F_DeleteFile(v_PathNG);
                    v_Total = v_Total - 1;
                    if (v_Status == "P")
                    {
                        v_Pass = v_Pass;
                        v_NG   = v_NG - 1;
                    }
                    else if (v_Status == "F")
                    {
                        v_NG = v_NG - 1;
                    }
                    if (v_Total < 0)
                    {
                        v_Total = 0;
                    }
                    if (v_Pass < 0)
                    {
                        v_Pass = 0;
                    }
                    if (v_NG < 0)
                    {
                        v_NG = 0;
                    }
                }
            }
            catch { }
            //Create NEW File log
            ControlFile.F_CreateAndWriteFile(ConfigurationManager.AppSettings["PathOutput"].ToString() + "\\" + v_TimeCurrent + "_" + v_Model.Replace(" ", "").Substring(0, 9) + ".txt", v_FileContent);

            if (v_Status == "P")
            {
                Panel_Result.BackColor = System.Drawing.Color.Blue;
                Lbl_Result.BackColor   = System.Drawing.Color.Blue;
                Lbl_Result.Text        = "PASS";
            }
            else if (v_Status == "F")
            {
                Panel_Result.BackColor = System.Drawing.Color.Red;
                Lbl_Result.BackColor   = System.Drawing.Color.Red;
                Lbl_Result.Text        = "FAIL";
            }

            //Count PCS
            F_CountModelsChecked(v_Status);
            F_LoadTotalPCS();
        }
 public void ItShouldGetThePodcasts()
 {
     Assert.That(ControlFile.GetPodcasts().Count(), Is.EqualTo(3));
 }
 public void ItShouldReadPodcast3()
 {
     Assert.That(ControlFile.GetPodcasts().ElementAt(2).PostDownloadCommand.Command.Value, Is.EqualTo("command"));
 }