示例#1
0
        public override RpcReply Call(String clientString, RpcCall call, byte[] callParameters, UInt32 callOffset, UInt32 callMaxOffset, out ISerializer replyParameters)
        {
            String      nfsMethodName;
            ISerializer callData;
            Int32       extraPerfoamanceData = -1;

            Int64 beforeCall = Stopwatch.GetTimestamp();

            Boolean printCall = true, printReply = true;

            switch (call.procedure)
            {
            case (UInt32)Nfs3Command.NULL:
                nfsMethodName = "NULL";

                callData        = VoidSerializer.Instance;
                replyParameters = VoidSerializer.Instance;
                break;

            case (UInt32)Nfs3Command.GETATTR:
                nfsMethodName = "GETATTR";

                GetFileAttributesCall getFileAttributesCall = new GetFileAttributesCall(callParameters, callOffset, callMaxOffset);
                callData = getFileAttributesCall.CreateSerializer();

                replyParameters = GETATTR(getFileAttributesCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.SETATTR:
                nfsMethodName = "SETATTR";

                SetFileAttributesCall setFileAttributesCall = new SetFileAttributesCall(callParameters, callOffset, callMaxOffset);
                callData = setFileAttributesCall.CreateSerializer();

                replyParameters = SETATTR(setFileAttributesCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.LOOKUP:
                nfsMethodName = "LOOKUP";
                printReply    = false;

                LookupCall lookupCall = new LookupCall(callParameters, callOffset, callMaxOffset);
                callData = lookupCall.CreateSerializer();

                replyParameters = LOOKUP(lookupCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.ACCESS:
                nfsMethodName = "ACCESS";

                AccessCall accessCall = new AccessCall(callParameters, callOffset, callMaxOffset);
                callData = accessCall.CreateSerializer();

                replyParameters = ACCESS(accessCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.READ:
                nfsMethodName = "READ";
                printReply    = false;

                ReadCall readCall = new ReadCall(callParameters, callOffset, callMaxOffset);
                callData = readCall.CreateSerializer();

                replyParameters = READ(readCall).CreateSerializer();

                extraPerfoamanceData = (Int32)readCall.count;
                break;

            case (UInt32)Nfs3Command.WRITE:
                nfsMethodName = "WRITE";
                printCall     = false;

                WriteCall writeCall = new WriteCall(callParameters, callOffset, callMaxOffset);
                callData = writeCall.CreateSerializer();

                replyParameters = WRITE(writeCall).CreateSerializer();

                extraPerfoamanceData = (Int32)writeCall.count;
                break;

            case (UInt32)Nfs3Command.CREATE:
                nfsMethodName = "CREATE";

                CreateCall createCall = new CreateCall(callParameters, callOffset, callMaxOffset);
                callData = createCall.CreateSerializer();

                replyParameters = CREATE(createCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.MKDIR:
                nfsMethodName = "MKDIR";

                MkdirCall mkdirCall = new MkdirCall(callParameters, callOffset, callMaxOffset);
                callData = mkdirCall.CreateSerializer();

                replyParameters = MKDIR(mkdirCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.SYMLINK:
                nfsMethodName = "SYMLINK";

                SymLinkCall symLinkCall = new SymLinkCall(callParameters, callOffset, callMaxOffset);
                callData = symLinkCall.CreateSerializer();

                replyParameters = SYMLINK(symLinkCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.REMOVE:
            case (UInt32)Nfs3Command.RMDIR:
                nfsMethodName = "REMOVE/RMDIR";

                RemoveCall removeCall = new RemoveCall(callParameters, callOffset, callMaxOffset);
                callData = removeCall.CreateSerializer();

                replyParameters = REMOVE(removeCall).CreateSerializer();
                break;

            case (UInt32)Nfs3Command.RENAME:
                nfsMethodName = "RENAME";

                RenameCall renameCall = new RenameCall(callParameters, callOffset, callMaxOffset);
                callData = renameCall.CreateSerializer();

                replyParameters = RENAME(renameCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.READDIRPLUS:
                nfsMethodName = "READDIRPLUS";
                printReply    = false;

                ReadDirPlusCall readDirPlusCall = new ReadDirPlusCall(callParameters, callOffset, callMaxOffset);
                callData = readDirPlusCall.CreateSerializer();

                replyParameters = READDIRPLUS(readDirPlusCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.FSSTAT:
                nfsMethodName = "FSSTAT";

                FileSystemStatusCall fileSystemInfoCall = new FileSystemStatusCall(callParameters, callOffset, callMaxOffset);
                callData = fileSystemInfoCall.CreateSerializer();

                replyParameters = FSSTAT(fileSystemInfoCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.FSINFO:
                nfsMethodName = "FSINFO";

                //
                // Deserialize
                //
                FSInfoCall fsInfoCall = new FSInfoCall(callParameters, callOffset, callMaxOffset);
                callData = fsInfoCall.CreateSerializer();

                replyParameters = FSINFO(fsInfoCall).CreateSerializer();

                break;

            case (UInt32)Nfs3Command.COMMIT:
                nfsMethodName = "COMMIT";

                // Since this server does not perform unstable writes at the moment, this function is unnecessary
                CommitCall commitCall = new CommitCall(callParameters, callOffset, callMaxOffset);
                callData = commitCall.CreateSerializer();

                //replyParameters = Handle(commitCall).CreateSerializer();
                CommitReply commitReply = new CommitReply(BeforeAndAfterAttributes.None, null);
                replyParameters = commitReply.CreateSerializer();

                break;

            default:
                if (NfsServerLog.warningLogger != null)
                {
                    NfsServerLog.warningLogger.WriteLine("[{0}] [Warning] client '{1}' sent unknown procedure number {2}", serviceName, clientString, call.procedure);
                }
                replyParameters = VoidSerializer.Instance;
                return(new RpcReply(RpcVerifier.None, RpcAcceptStatus.ProcedureUnavailable));
            }

            Int64 afterCall          = Stopwatch.GetTimestamp();
            Int64 callStopwatchTicks = afterCall - beforeCall;

            if (NfsServerLog.rpcCallLogger != null)
            {
                NfsServerLog.rpcCallLogger.WriteLine(
#if WindowsCE
                    JediTimer.JediTimerPrefix() +
#endif
                    "[{0}] {1} {2} => {3} {4:0.00} milliseconds", serviceName, nfsMethodName,
                    printCall ? DataStringBuilder.DataSmallString(callData, NfsServerLog.sharedDataStringBuilder) : "[Call Ommited From Log]",
                    printReply ? DataStringBuilder.DataSmallString(replyParameters, NfsServerLog.sharedDataStringBuilder) : "[Reply Ommited From Log]",
                    callStopwatchTicks.StopwatchTicksAsDoubleMilliseconds());
            }
            else if (NfsServerLog.warningLogger != null)
            {
                Double callMilliseconds = callStopwatchTicks.StopwatchTicksAsDoubleMilliseconds();
                if (callMilliseconds >= 40)
                {
                    NfsServerLog.warningLogger.WriteLine(
#if WindowsCE
                        JediTimer.JediTimerPrefix() +
#endif
                        "[{0}] [Warning] {1} {2} => {3} {4:0.00} milliseconds", serviceName, nfsMethodName,
                        printCall ? DataStringBuilder.DataSmallString(callData, NfsServerLog.sharedDataStringBuilder) : "[Call Ommited From Log]",
                        printReply ? DataStringBuilder.DataSmallString(replyParameters, NfsServerLog.sharedDataStringBuilder) : "[Reply Ommited From Log]",
                        callMilliseconds);
                }
            }

            if (NfsServerLog.performanceLog != null)
            {
                NfsServerLog.performanceLog.Log((Nfs3Command)call.procedure,
                                                (UInt32)callStopwatchTicks.StopwatchTicksAsMicroseconds(), extraPerfoamanceData);
            }

            //servicesManager.PrintPerformance();
            return(new RpcReply(RpcVerifier.None));
        }
示例#2
0
        public CreateReply CREATE(CreateCall createCall)
        {
            if (createCall.mode == CreateModeEnum.Exclusive)
            {
                return(new CreateReply(Status.ErrorNotSupported, BeforeAndAfterAttributes.None));
            }

            ShareObject directoryShareObject;
            Status      status = sharedFileSystem.TryGetSharedObject(createCall.directoryHandle, out directoryShareObject);

            if (status != Status.Ok)
            {
                return(new CreateReply(status, BeforeAndAfterAttributes.None));
            }

            FileStream fileStream = null;

            try
            {
                String localPathAndName = PlatformPath.LocalCombine(directoryShareObject.localPathAndName, createCall.newFileName);

                ShareObject fileShareObject;
                status = sharedFileSystem.TryGetSharedObject(localPathAndName, createCall.newFileName, out fileShareObject);

                if (status == Nfs3Procedure.Status.Ok)
                {
                    fileShareObject.RefreshFileAttributes(sharedFileSystem.permissions);

                    // The file already exists
                    if (createCall.mode == CreateModeEnum.Guarded)
                    {
                        return(new CreateReply(Status.ErrorAlreadyExists, BeforeAndAfterAttributes.None));
                    }
                }
                else
                {
                    if (status != Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory)
                    {
                        return(new CreateReply(status, BeforeAndAfterAttributes.None));
                    }
                }

                directoryShareObject.RefreshFileAttributes(sharedFileSystem.permissions);
                SizeAndTimes directorySizeAndTimesBeforeCreate = AutoExtensions.CreateSizeAndTimes(directoryShareObject.fileAttributes);

                // Todo: handle exceptions
                fileStream = new FileStream(localPathAndName, FileMode.Create);
                fileStream.Dispose();

                status = sharedFileSystem.TryGetSharedObject(localPathAndName, createCall.newFileName, out fileShareObject);
                if (status != Nfs3Procedure.Status.Ok)
                {
                    return(new CreateReply(status, BeforeAndAfterAttributes.None));
                }

                fileShareObject.RefreshFileAttributes(sharedFileSystem.permissions);
                directoryShareObject.RefreshFileAttributes(sharedFileSystem.permissions);

                return(new CreateReply(fileShareObject.optionalFileHandleClass,
                                       fileShareObject.optionalFileAttributes,
                                       new BeforeAndAfterAttributes(directorySizeAndTimesBeforeCreate, directoryShareObject.fileAttributes)));
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                }
            }
        }
示例#3
0
        public void LoadView(ViewType typeView)
        {
            switch (typeView)
            {
            case ViewType.Main:
                //загружаем вьюшку, ее вьюмодель
                MainWindowVM mainWindowVM = new MainWindowVM(idUser);
                MainWindow   mainWindow   = new MainWindow();
                mainWindowVM.CodeBehind = mainWindow;
                mainWindow.DataContext  = mainWindowVM;
                MainControl   view = new MainControl();
                MainControlVM vm   = new MainControlVM(idUser);
                view.DataContext = vm;
                //отображаем
                this.ContentPresenterOutput.Content = view;
                break;

            case ViewType.AddBalance:
                //загружаем вьюшку, ее вьюмодель
                AddBalance   addBalanceView = new AddBalance();
                AddBalanceVM AddBalanceVm   = new AddBalanceVM(idUser);
                addBalanceView.DataContext = AddBalanceVm;
                //отображаем
                this.ContentPresenterOutput.Content = addBalanceView;
                break;

            case ViewType.CallAndSms:
                //загружаем вьюшку, ее вьюмодель
                CallAndSms   callAndSmsView = new CallAndSms();
                CallAndSmsVM callAndSmsVm   = new CallAndSmsVM(idUser, this);
                callAndSmsView.DataContext = callAndSmsVm;
                //отображаем
                this.ContentPresenterOutput.Content = callAndSmsView;
                break;

            case ViewType.Tariff:
                //загружаем вьюшку, ее вьюмодель
                Tariff   tariffview = new Tariff();
                TariffVM tariffVm   = new TariffVM(idUser);
                tariffview.DataContext = tariffVm;
                //отображаем
                this.ContentPresenterOutput.Content = tariffview;
                break;

            case ViewType.Service:
                //загружаем вьюшку, ее вьюмодель
                Service   serviceView = new Service();
                ServiceVM serviceVM   = new ServiceVM(idUser);
                serviceView.DataContext = serviceVM;
                //отображаем
                this.ContentPresenterOutput.Content = serviceView;
                break;

            case ViewType.CreateCall:
                //загружаем вьюшку, ее вьюмодель
                CreateCall   callView = new CreateCall();
                CreateCallVM callVM   = new CreateCallVM(idUser, this);
                callView.DataContext = callVM;
                //отображаем
                this.ContentPresenterOutput.Content = callView;
                break;

            case ViewType.CreateSms:
                //загружаем вьюшку, ее вьюмодель
                CreateSms   smsView = new CreateSms();
                CreateSmsVM smsVM   = new CreateSmsVM(idUser, this);
                smsView.DataContext = smsVM;
                //отображаем
                this.ContentPresenterOutput.Content = smsView;
                break;

                /*case ViewType.CheckListForPdf:
                 *  //загружаем вьюшку, ее вьюмодель
                 *  CheckListForPdf CheckListForPdfView = new CheckListForPdf();
                 *  CheckListForPdfVM checkListForPdfVM = new CheckListForPdfVM(idUser,Convert.ToDateTime("01.01.2000"), Convert.ToDateTime("01.01.2020"));
                 *  //checkListForPdfVM.CodeBehind = CheckListForPdfView;
                 *  CheckListForPdfView.DataContext = checkListForPdfVM;
                 *  CheckListForPdfView.Show();
                 *//*                    //отображаем
                 *                      this.ContentPresenterOutput.Content = CheckListForPdfView;*//*
                 *  break;*/
            }
        }