Ejemplo n.º 1
0
        public static ApiRequestCommand GetCommand(IApplicationReader reader, String path)
        {
            var parts = path.Split('/');
            // dir/dir/dir/acton/{id};

            int len = parts.Length;

            if (len < 2)
            {
                throw new ApiV2Exception($"invalid path: {path}");
            }
            var p1 = String.Join("/", new ArraySegment <String>(parts, 0, len - 1));

            String id     = null;
            String action = null;

            String relPath  = $"_apiv2/{p1}";
            String filePath = reader.MakeFullPath(relPath, "model.json");

            if (!reader.FileExists(filePath))
            {
                // try to read with id
                if (len < 3)
                {
                    throw new ApiV2Exception($"invalid path: {path}");
                }
                p1       = String.Join("/", new ArraySegment <String>(parts, 0, len - 2));
                relPath  = $"_apiv2/{p1}";
                filePath = reader.MakeFullPath(relPath, "model.json");
                id       = parts[len - 1];
                if (!reader.FileExists(filePath))
                {
                    throw new ApiV2Exception($"path not found: {path}");
                }
                action = parts[len - 2];
            }
            else
            {
                action = parts[len - 1];
            }

            var json = reader.FileReadAllText(filePath);
            var rm   = JsonConvert.DeserializeObject <ApiV2RequestModel>(json, JsonHelpers.CamelCaseSerializerSettings);

            if (rm == null)
            {
                throw new ApiV2Exception($"invalid model.json");
            }
            rm.SetParent();
            if (rm.Commands.TryGetValue(action, out ApiRequestCommand cmd))
            {
                cmd.SetId(id);
                cmd.SetPath(relPath);
                return(cmd);
            }
            throw new ApiV2Exception($"command '{action}' not found");
        }
Ejemplo n.º 2
0
 public Stream GetStream(IApplicationReader reader)
 {
     if (!String.IsNullOrEmpty(ReportPath))
     {
         return(reader.FileStreamFullPathRO(ReportPath));
     }
     else if (ReportStream != null)
     {
         return(new MemoryStream(ReportStream));
     }
     throw new InvalidOperationException("Invalid report stream mode");
 }
Ejemplo n.º 3
0
        public void StartApplication(Boolean bAdmin)
        {
            var    file = ZipApplicationFile;
            String key  = bAdmin ? "admin" : AppKey;

            if (file != null)
            {
                _reader = new ZipApplicationReader(AppPath, key);
            }
            else
            {
                _reader = new FileApplicationReader(AppPath, key);
            }
        }
Ejemplo n.º 4
0
 public bool DeleteReader(IApplicationReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException();
     }
     if (ReaderExists(reader))
     {
         Readers.Remove(reader);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
 public bool AddReader(IApplicationReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException();
     }
     if (!ReaderExists(reader.Login))
     {
         Readers.Add(reader);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 6
0
        static void CreateReader()
        {
            var    file = ZipApplicationFileName(CurrentAppPath, CurrentAppKey);
            String key  = CurrentAppKey;

            if (file != null)
            {
                _reader = new ZipApplicationReader(CurrentAppPath, key);
            }
            else
            {
                _reader = new FileApplicationReader(CurrentAppPath, key)
                {
                    EmulateBox = true
                }
            };
        }
Ejemplo n.º 7
0
 IEnumerable <String> ReadLines(IApplicationReader reader, String path)
 {
     using (var stream = reader.FileStreamFullPathRO(path))
     {
         using (var rdr = new StreamReader(stream))
         {
             while (!rdr.EndOfStream)
             {
                 var s = rdr.ReadLine();
                 if (String.IsNullOrEmpty(s) || s.StartsWith(";"))
                 {
                     continue;
                 }
                 yield return(s);
             }
         }
     }
 }
Ejemplo n.º 8
0
        public void StartApplication(Boolean bAdmin)
        {
            var    file = ZipApplicationFile;
            String key  = bAdmin ? "admin" : AppKey;

            if (file != null)
            {
                _reader = new ZipApplicationReader(AppPath, key);
            }
            else if (AppPath.StartsWith("db:"))
            {
                throw new NotImplementedException("DbApplicationReader");
            }
            else
            {
                _reader = new FileApplicationReader(AppPath, key);
            }
        }
Ejemplo n.º 9
0
        public void AddBook(IApplicationReader user, string title, string author)
        {
            if (String.IsNullOrEmpty(title) || String.IsNullOrEmpty(author))
            {
                throw new ArgumentNullException();
            }
            if (title == null || author == null)
            {
                throw new ArgumentNullException();
            }
            if (!ReaderExists(user))
            {
                throw new Exception();
            }
            var newBook = new Book(user, title, author);

            user.BookCollection.Add(newBook);
            Books.Add(newBook);
        }
Ejemplo n.º 10
0
 public ExecuteJavaScriptCommand(IJavaScriptEngine engine, IApplicationReader reader)
 {
     _engine = engine;
     _reader = reader;
 }
Ejemplo n.º 11
0
 public void StartApplication(Boolean bAdmin)
 {
     _appReader = new FileApplicationReader(AppPath, AppKey);
 }
Ejemplo n.º 12
0
 public ApplicationsController(IApplicationWriter applicationWriter, IApplicationReader applicationReader)
 {
     writer = applicationWriter;
     reader = applicationReader;
 }
Ejemplo n.º 13
0
 public TypeChecker(IApplicationReader reader, String path)
 {
     _reader = reader;
     _path   = path;
 }
Ejemplo n.º 14
0
 public Book(IApplicationReader user, string title, string author)
 {
     Title  = title;
     Author = author;
 }
Ejemplo n.º 15
0
        public void Render(RenderInfo info)
        {
            if (String.IsNullOrEmpty(info.FileName))
            {
                throw new XamlException("No source for render");
            }
            IProfileRequest request  = _profile.CurrentRequest;
            String          fileName = String.Empty;
            UIElementBase   uiElem   = null;

            using (request.Start(ProfileAction.Render, $"load: {info.FileTitle}"))
            {
                try
                {
                    // XamlServices.Load sets IUriContext
                    if (!String.IsNullOrEmpty(info.FileName))
                    {
                        using (var fileStream = _host.ApplicationReader.FileStreamFullPath(info.FileName))
                        {
                            RootFileName      = info.FileName;
                            ApplicationReader = _host.ApplicationReader;
                            uiElem            = XamlServices.Load(fileStream) as UIElementBase;
                        }
                    }
                    else if (!String.IsNullOrEmpty(info.Text))
                    {
                        uiElem = XamlServices.Parse(info.Text) as UIElementBase;
                    }
                    else
                    {
                        throw new XamlException("Xaml. There must be either a 'FileName' or a 'Text' property");
                    }
                    if (uiElem == null)
                    {
                        throw new XamlException("Xaml. Root is not 'UIElement'");
                    }

                    using (var stylesStream = _host.ApplicationReader.FileStream(String.Empty, "styles.xaml"))
                    {
                        if (stylesStream != null)
                        {
                            if (!(XamlServices.Load(stylesStream) is Styles styles))
                            {
                                throw new XamlException("Xaml. Styles is not 'Styles'");
                            }
                            if (uiElem is RootContainer root)
                            {
                                root.Styles = styles;
                                root?.OnSetStyles();
                            }
                        }
                    }
                }
                finally
                {
                    RootFileName      = null;
                    ApplicationReader = null;
                }
            }

            using (request.Start(ProfileAction.Render, $"render: {info.FileTitle}"))
            {
                RenderContext ctx = new RenderContext(uiElem, info)
                {
                    RootId = info.RootId,
                    Path   = info.Path
                };

                if (info.SecondPhase)
                {
                    if (!(uiElem is ISupportTwoPhaseRendering twoPhaseRender))
                    {
                        throw new XamlException("The two-phase rendering is not available");
                    }
                    twoPhaseRender.RenderSecondPhase(ctx);
                }
                else
                {
                    uiElem.RenderElement(ctx);
                }

                Grid.ClearAttached();
                Splitter.ClearAttached();
                FullHeightPanel.ClearAttached();
                Toolbar.ClearAttached();
            }

            if (uiElem is IDisposable disp)
            {
                disp.Dispose();
            }
        }
Ejemplo n.º 16
0
 public TSDefParser(IApplicationReader reader, String path)
 {
     _reader = reader;
     _path   = path;
     _mm     = new ModelMetadata();
 }
Ejemplo n.º 17
0
 public AppVersions(String dbConnectionString, IApplicationReader reader)
 {
     _reader    = reader;
     _cnnString = dbConnectionString;
 }